Sitelet https://github.com/gpuweb/gpuweb/pull/50/files
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions design/buffer-mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Buffer Mapping

For each Buffer with MAP_READ or MAP_WRITE usage, an IPC implemention maintains
a parallel shared-memory buffer for use with immediate (non-round-trip) mapping.
However, this mapping is only accessible at well-defined times.

## Transition to MAP_READ or MAP_WRITE

When an app wants to map a buffer for read or write, it submits a command buffer
containing a transition of the buffer's usage to MAP_READ or MAP_WRITE, and
inserts a fence into the queue. (either immediately, or coalescing later)

## WebGPUFence

Fences are one-shot, where the CPU waits for the GPU/server/API to 'signal'
a fence as passed. They are created with WebGPUQueue.insertFence().

Apps can establish whether a buffer has completed its transition to
MAP_READ/MAP_WRITE by using `.promise.then()`.

## WebGPUBuffer.mapping and unmap()

Once the app has established that the transition to MAP_READ/MAP_WRITE is
complete, `mapping` is changed from `null` to an `ArrayBuffer` backed by the
mapped data.

When done with the mapping, the app relinquishes control of the mapped bytes
with `WebGPUBuffer.unmap()`, which neuters the ArrayBuffer, and nulls `mapping`.
17 changes: 10 additions & 7 deletions design/sketch.webidl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
typedef long u32;
typedef unsigned long u32;
typedef unsigned long long u64;

// ****************************************************************************
// SHADER RESOURCES (buffer, textures, texture views, samples)
Expand All @@ -24,8 +25,8 @@ dictionary WebGPUBufferDescriptor {
};

interface WebGPUBuffer {
void setSubData(ArrayBuffer data, u32 offset);
Promise<ArrayBuffer> readbackAsync(u32 offset, u32 size);
readonly attribute ArrayBuffer? mapping;
void unmap();
};

// Texture view
Expand Down Expand Up @@ -156,7 +157,7 @@ dictionary WebGPUBinding {

dictionary WebGPUBindGroupDescriptor {
WebGPUBindGroupLayout layout;
sequence<WebGPUBinding> bindings;
sequence<WebGPUBinding> bindings;
};

interface WebGPUBindGroup {
Expand Down Expand Up @@ -257,7 +258,7 @@ dictionary WebGPUDepthStencilStateDescriptor {

WebGPUStencilStateFaceDescriptor front;
WebGPUStencilStateFaceDescriptor back;

u32 stencilReadMask;
u32 stencilWriteMask;
};
Expand Down Expand Up @@ -419,6 +420,8 @@ interface WebGPUCommandEncoder {
void copyTextureToTexture();
void blit();

void transitionBuffer(WebGPUBuffer b, WebGPUBufferUsageFlags f);

// Allowed in both compute and render passes
void setPushConstants(WebGPUShaderStageFlags stage,
u32 offset,
Expand Down Expand Up @@ -453,13 +456,13 @@ interface WebGPUCommandEncoder {

// Fence
interface WebGPUFence {
u32 getValue();
readonly attribute Promise<void> promise;
};

// Queue
interface WebGPUQueue {
void submit(sequence<WebGPUCommandBuffer> buffers);
void updateFence(WebGPUFence fence, u32 value);
WebGPUFence insertFence();
};

// SwapChain / RenderingContext
Expand Down