GPU-side data is stored in GPUBuffers created with size and usage flags, then populated via device.queue.writeBuffer
GPU memory is managed through GPUBuffer objects. Create one with device.createBuffer({ label, size, usage }) where size is in bytes and usage is a bitfield of GPUBufferUsage flags (e.g. VERTEX | COPY_DST for vertex data, UNIFORM | COPY_DST for uniforms, STORAGE | COPY_DST for storage). After creation, the buffer is zero-initialized and its size and usage flags are immutable. To write data from JavaScript, call device.queue.writeBuffer(buffer, offset, typedArray). The buffer’s contents are opaque — you cannot read them back from JavaScript.
Examples
const vertexBuffer = device.createBuffer({
label: 'Cell vertices',
size: vertices.byteLength,
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
});
device.queue.writeBuffer(vertexBuffer, 0, vertices);
Assessment
List three things that become immutable once a GPUBuffer is created. What usage flag pair is needed for a buffer that holds vertex data written from JavaScript?