1 of 11

Shu-yu Guo for Surma

2 of 11

Motivation: ImageData

// ctx is a CanvasRenderingContext2D

const imageData =

ctx.getImageData(0, 0,

ctx.canvas.width,

ctx.canvas.height);

// imageData.data is a Uint8ClampedArray

// containing data in the scheme

// [ r0, g0, b0, a0, r1, g1, b1, a1, ... ]

3 of 11

What If I Want to Access Just the Alpha Values?

4 of 11

I Mean, I can...

const getAlpha = (u8,idx) => u8[idx*4+3];

5 of 11

But Wouldn’t It Be Nice

const alphas =

new Uint8ClampedArray(

imageData.buffer,

3 * Uint8Array.BYTES_PER_ELEMENT,

imageData.width * imageData.height,

/* stride */ 4);

6 of 11

N-Dimensional Data in Many Places

  • Bitmaps
  • Vertices
  • Tensors (used in a budding new field called “Machine Learning”)

7 of 11

Proposed API

  • length is the strided length (e.g. 64 bytes viewed with a stride of 4 uint8s is 64/4=16)
  • stride is a multiple of element size, throws otherwise
  • stride is lower bounded by and defaulted to 1, throws otherwise

new TypedArray(buffer[, byteOffset[, length[, stride]]]);

8 of 11

Feature Detection

"stride" in new TypedArray()

9 of 11

No Options Bag

  • Pros: Allow defining stride without defining offset and length.
  • Cons: Too invasive.
  • Strawperson: length=-1?

10 of 11

No Unaligned Access

  • TAs are all aligned today
  • Easier codegen
  • Easier shared memory and atomics

11 of 11

Stage 1?