Skip to content

(queue …)

Defines queue operations for writing data to buffers and copying images to textures.

(queue :name writeUniforms
(write-buffer :buffer uniforms :offset 0 :data pngine-inputs))
(queue :name loadTexture
(copy-external-image-to-texture
(source :image photo)
(destination :texture albedo)))

A (queue …) holds its actions as positional sub-forms, run in document order when the frame reaches the queue. The eight actions are:

Action Purpose
write-buffer Write bytes into a buffer
write-texture Upload raw texel bytes into a texture
copy-buffer-to-buffer GPU buffer → buffer copy
copy-buffer-to-texture Copy a buffer into a texture subresource
copy-texture-to-buffer Copy a texture subresource into a buffer, optionally for readback
copy-texture-to-texture GPU texture → texture copy
copy-external-image-to-texture Upload a decoded image into a texture
resolve-query-set Copy resolved query results into a buffer
(queue :name readback
(resolve-query-set :query-set occ :first-query 0 :query-count 6
:destination resolveBuf :destination-offset 0)
(copy-buffer-to-buffer :source resolveBuf :source-offset 0
:destination readbackBuf :destination-offset 0 :size 48))
Key Type Required Description
:name symbol Yes Unique name (referenced from (frame …))
actions sub-forms No Positional action sub-forms, run in the order written

Writes data to a GPU buffer.

Key Type Required Description
:buffer reference Yes Target buffer (needs copy-dst usage)
:offset number No Byte offset, a multiple of 4 (default: 0)
:data reference/symbol Yes Where the bytes come from

:data is one key for the three things a source can be: a built-in runtime source, a (data …) name, or a (wasm-call …) name. Which one it is follows from what that name was declared as, so there is no second key to choose between them.

Data sources:

Static data reference (from (data …)):

(data :name vertexData :float32 [0 0.5 -0.5 -0.5 0.5 -0.5])
(write-buffer :buffer vertices :data vertexData)

Runtime uniform data (built-in):

(write-buffer :buffer uniforms :offset 0 :data pngine-inputs)

The pngine-inputs symbol, the built-in source of time and canvas size, provides 16 bytes of runtime data written each frame by the executor (the small WASM interpreter embedded in each payload, which turns bytecode into GPU commands). The other built-in sources are scene-time-inputs (12 bytes) and pointer-inputs (48 bytes).

WASM result (from a (wasm-call …), a WebAssembly module the executor calls once per frame):

(wasm-call :name mvp :file "matrices.wasm" :func rotatingMVP :returns "mat4x4"
:args [time-total canvas-width canvas-height])
(write-buffer :buffer mvpBuffer :offset 0 :data mvp)

Naming a (wasm-call …) there calls it at frame time and writes its result into the buffer.

Copies a decoded image (an (image-bitmap …)) into a texture. Each end of a copy is a dictionary in WebGPU, so each is a child form: exactly one (source …) and exactly one (destination …).

(source …):

Key Type Required Description
:image reference Yes The (image-bitmap …) to upload

(destination …):

Key Type Required Default Description
:texture reference Yes - Target texture (needs copy-dst usage)
:mip-level number No 0 Destination mip level
:origin array No [0 0 0] [x y z] in texels; z picks the array layer or depth slice

:mip-level and :origin belong to the destination, not to the copy: they say which subresource receives the pixels, which is how a cubemap’s six faces load into one texture.

(copy-external-image-to-texture
(source :image photo)
(destination :texture albedo :mip-level 0 :origin [0 0 0]))

Copies between GPU textures without a CPU round trip, which is how a frame keeps a copy of itself for feedback. Both ends are child forms here too, and each takes one key:

Sub-form Key Type Required Description
(source …) :texture reference Yes Source texture, or context-current-texture
(destination …) :texture reference Yes Destination texture, or context-current-texture

context-current-texture names the canvas’s current texture; any other value is a (texture …) name. With no endpoint subresource keys and no :size, the operation keeps its legacy whole-texture meaning. Adding :size, or :mip-level, :origin, :aspect on an endpoint, selects the explicit subresource copy. Buffer↔texture copies use the same endpoint model and add WebGPU’s aligned-buffer layout rules.

Copies bytes between two GPU buffers without a CPU round trip.

Key Type Required Default Description
:source reference Yes - Source buffer (needs copy-src usage)
:source-offset number No 0 Byte offset into the source
:destination reference Yes - Destination buffer (needs copy-dst usage)
:destination-offset number No 0 Byte offset into the destination
:size number Yes - Bytes to copy

All three of :source-offset, :destination-offset and :size must be multiples of 4.

(queue :name stage
(copy-buffer-to-buffer :source resolveBuf :source-offset 0
:destination readbackBuf :destination-offset 0 :size 48))

Copies resolved GPU query results into a buffer, 8 bytes per query.

Key Type Required Default Description
:query-set reference Yes - The (query-set …) to resolve
:first-query number No 0 Index of the first query to resolve
:query-count number Yes - Number of queries to resolve
:destination reference Yes - Destination buffer (needs query-resolve usage)
:destination-offset number No 0 Byte offset into the destination

WebGPU requires :destination-offset to be a multiple of 256 here.

(queue :name resolve
(resolve-query-set :query-set occ :first-query 0 :query-count 6
:destination resolveBuf :destination-offset 0))

Reserved symbols name runtime data the player fills in each frame. They are valid write-buffer :data values and cannot be declared as form names:

Symbol Size Contents
pngine-inputs 16 bytes time, canvasWidth, canvasHeight, aspect (all f32)
scene-time-inputs 12 bytes the first 12 bytes of pngine-inputs
pngine-frame-inputs 20 bytes pngine-inputs, then frameIndex as u32
pointer-inputs 48 bytes x, y, clickX, clickY, dx, dy, buttons, pressure, modifiers, scrollX, scrollY, _pad
control-inputs 4 bytes per declared control Host-set controls in declaration order, all f32

The pngine-inputs symbol provides runtime data that updates every frame. It writes 16 bytes:

Field Type Offset Description
time f32 0 Elapsed seconds since start
width f32 4 Canvas width in pixels
height f32 8 Canvas height in pixels
aspect f32 12 width / height

Your uniform buffer must be at least 16 bytes when using pngine-inputs.

Your WGSL struct must match this layout:

struct PngineInputs {
time: f32,
canvasWidth: f32,
canvasHeight: f32,
aspect: f32,
}
@group(0) @binding(0) var<uniform> inputs: PngineInputs;
(buffer :name uniforms :size 16 :usage [uniform copy-dst])
(queue :name writeTime
(write-buffer :buffer uniforms :offset 0 :data pngine-inputs))
(frame :name main :perform [writeTime renderPass])
(data :name vertexData :float32 [0 0.5 -0.5 -0.5 0.5 -0.5])
(buffer :name vertices :size 24 :usage [vertex copy-dst])
(queue :name initVertices
(write-buffer :buffer vertices :data vertexData))
(data :name imageFile :file "texture.png" :mime "image/png")
(image-bitmap :name textureBitmap :data imageFile)
(texture :name colorMap :size textureBitmap
:format rgba8unorm
:usage [texture-binding copy-dst render-attachment])
(queue :name loadTexture
(copy-external-image-to-texture
(source :image textureBitmap)
(destination :texture colorMap)))
(frame :name main :perform [loadTexture renderPass])
(wasm-call :name mvp :file "matrices.wasm" :func rotatingMVP
:args [time-total canvas-width canvas-height] :returns "mat4x4")
(buffer :name mvpBuffer :size 64 :usage [uniform copy-dst])
(queue :name writeMVP
(write-buffer :buffer mvpBuffer :offset 0 :data mvp))
(texture :name sourceTexture :size canvas :format rgba8unorm
:usage [render-attachment copy-src])
(texture :name targetTexture :size canvas :format rgba8unorm
:usage [texture-binding copy-dst])
(queue :name copyResult
(copy-texture-to-texture
(source :texture sourceTexture)
(destination :texture targetTexture)))

Queue operations run when a (frame …) names them, in :perform alongside the passes:

(frame :name main :perform [writeUniforms renderPass])

or in :before, which runs its queues ahead of every frame’s passes:

(frame :name main :before [writeUniforms] :perform [renderPass])

A frame’s :init list is for one-shot compute steps: it takes (compute-pass …) and (init …) names only, so a queue named there is a not_cross_ref. A queue op runs every frame, which for an image upload is wasteful but correct.

Rule Error
A name is unique across every form kind duplicate_cross_ref_target
Referenced buffers, textures, query sets and data must exist not_cross_ref
write-buffer’s :data names a built-in, a (data …) or a (wasm-call …) union_no_branch_matched
write-buffer’s :offset, and copy-buffer-to-buffer’s offsets and :size, are multiples of 4 number_not_multiple
resolve-query-set’s :destination-offset is a multiple of 256 number_not_multiple
An action head the form does not accept not_head_member
Exactly one (source …) and one (destination …) per copy positional_missing / positional_too_many

Usage is the compiler’s rule rather than the schema’s, because a buffer’s usage is fixed when it is created. It reports on the (buffer …):

buffer 'src' is the :source of a copy but its :usage has no copy-src

Maps to queue operations:

// write-buffer (static data)
device.queue.writeBuffer(buffer, offset, data);
// write-buffer (pngine-inputs) - runtime provides data
device.queue.writeBuffer(buffer, offset,
new Float32Array([time, width, height, aspect]));
// copy-external-image-to-texture: (source …) and (destination …) are the
// two dictionaries this call already takes
device.queue.copyExternalImageToTexture(
{ source: imageBitmap },
{ texture: gpuTexture, mipLevel: 0, origin: [0, 0, 0] },
[width, height]
);

Every key and value on this page traced to the WebGPU name it stands for, with a link to the definition. How the tracing is made, and what keeps it from rotting, is the subject of Where the Words Come From.

(queue …) is PNGine’s own. A named list of queue and encoder operations the frame runs in order. WebGPU has the operations (the positional children below), not the list.

Key WebGPU Note
:name PNGine’s own the name a (frame :before [...]) refers to

A (queue …) is PNGine’s own: a named list of queue and encoder operations the frame runs in order. WebGPU has the operations, not the list.

(write-buffer …) is a call to GPUQueue.writeBuffer() (MDN); each key is one argument.

Key Argument Note
:buffer buffer
:offset bufferOffset
:data data the bytes come from a (data …), a (wasm-call …) or a runtime input source; dataOffset and size are not exposed, the whole source is written

(write-texture …) mirrors GPUTexelCopyTextureInfo (MDN) and GPUTexelCopyBufferLayout.

Key WebGPU Note
:texture GPUTexelCopyTextureInfo.texture
:data GPUQueue.writeTexture() the method’s data argument, flattened into this form; no texel-copy dictionary declares it
:offset GPUTexelCopyBufferLayout.offset
:bytes-per-row GPUTexelCopyBufferLayout.bytesPerRow
:rows-per-image GPUTexelCopyBufferLayout.rowsPerImage
:origin GPUTexelCopyTextureInfo.origin
:mip-level GPUTexelCopyTextureInfo.mipLevel
:aspect GPUTexelCopyTextureInfo.aspect
:size GPUQueue.writeTexture() the method’s size argument; omitted means the remaining physical extent at the selected origin

(copy-buffer-to-buffer …) is a call to GPUCommandEncoder.copyBufferToBuffer() (MDN); each key is one argument.

Key Argument Note
:source source
:source-offset sourceOffset
:destination destination
:destination-offset destinationOffset
:size size

(copy-buffer-to-texture …) is a call to GPUCommandEncoder.copyBufferToTexture() (MDN); each key is one argument.

Key Argument Note
:size copySize
(source …) source a positional child, not a key
(destination …) destination a positional child, not a key

copySize is optional in PNGine: omission copies the remaining physical extent at the destination origin.

(source …) mirrors GPUTexelCopyBufferInfo and GPUTexelCopyBufferLayout.

Key WebGPU Note
:buffer GPUTexelCopyBufferInfo.buffer
:offset GPUTexelCopyBufferLayout.offset
:bytes-per-row GPUTexelCopyBufferLayout.bytesPerRow
:rows-per-image GPUTexelCopyBufferLayout.rowsPerImage

(destination …) mirrors GPUTexelCopyTextureInfo (MDN).

Key WebGPU Note
:texture GPUTexelCopyTextureInfo.texture
:mip-level GPUTexelCopyTextureInfo.mipLevel
:origin GPUTexelCopyTextureInfo.origin
:aspect GPUTexelCopyTextureInfo.aspect

(copy-texture-to-buffer …) is a call to GPUCommandEncoder.copyTextureToBuffer() (MDN); each key is one argument.

Key Argument Note
:size copySize
(source …) source a positional child, not a key
(destination …) destination a positional child, not a key

copySize is optional in PNGine: omission copies the remaining physical extent at the source origin.

(source …) mirrors GPUTexelCopyTextureInfo (MDN).

Key WebGPU Note
:texture GPUTexelCopyTextureInfo.texture
:mip-level GPUTexelCopyTextureInfo.mipLevel
:origin GPUTexelCopyTextureInfo.origin
:aspect GPUTexelCopyTextureInfo.aspect

(destination …) mirrors GPUTexelCopyBufferInfo and GPUTexelCopyBufferLayout.

Key WebGPU Note
:buffer GPUTexelCopyBufferInfo.buffer
:offset GPUTexelCopyBufferLayout.offset
:bytes-per-row GPUTexelCopyBufferLayout.bytesPerRow
:rows-per-image GPUTexelCopyBufferLayout.rowsPerImage

(copy-texture-to-texture …) is a call to GPUCommandEncoder.copyTextureToTexture() (MDN); each key is one argument.

Key Argument Note
:size copySize
(source …) source a positional child, not a key
(destination …) destination a positional child, not a key

The no-subresource-key spelling retains the legacy whole-texture operation; any subresource key selects the explicit copy form.

(source …) mirrors GPUTexelCopyTextureInfo (MDN).

Key WebGPU Note
:texture GPUTexelCopyTextureInfo.texture
:mip-level GPUTexelCopyTextureInfo.mipLevel
:origin GPUTexelCopyTextureInfo.origin
:aspect GPUTexelCopyTextureInfo.aspect

(destination …) mirrors GPUTexelCopyTextureInfo (MDN).

Key WebGPU Note
:texture GPUTexelCopyTextureInfo.texture
:mip-level GPUTexelCopyTextureInfo.mipLevel
:origin GPUTexelCopyTextureInfo.origin
:aspect GPUTexelCopyTextureInfo.aspect

(copy-external-image-to-texture …) is a call to GPUQueue.copyExternalImageToTexture() (MDN); each key is one argument.

Key Argument Note
(source …) source a positional child, not a key
(destination …) destination a positional child, not a key

copySize is not exposed: PNGine copies the whole image.

(source …) mirrors GPUCopyExternalImageSourceInfo (MDN).

Key WebGPU Note
:image GPUCopyExternalImageSourceInfo.source the source member, under PNGine’s name for it

Not expressible in PNGine yet: GPUCopyExternalImageSourceInfo.origin, GPUCopyExternalImageSourceInfo.flipY.

(destination …) mirrors GPUCopyExternalImageDestInfo (MDN) and GPUTexelCopyTextureInfo (MDN).

Key WebGPU Note
:texture GPUTexelCopyTextureInfo.texture
:mip-level GPUTexelCopyTextureInfo.mipLevel
:origin GPUTexelCopyTextureInfo.origin

Not expressible in PNGine yet: GPUCopyExternalImageDestInfo.colorSpace, GPUCopyExternalImageDestInfo.premultipliedAlpha, GPUTexelCopyTextureInfo.aspect.

(resolve-query-set …) is a call to GPUCommandEncoder.resolveQuerySet() (MDN); each key is one argument.

Key Argument Note
:query-set querySet
:first-query firstQuery
:query-count queryCount
:destination destination
:destination-offset destinationOffset

texture-aspect (:aspect on (write-texture …), :aspect on (destination …), :aspect on (source …), :aspect on (source …), :aspect on (destination …)) spells the GPUTextureAspect enum.

Value WebGPU Note
all "all"
stencil-only "stencil-only"
depth-only "depth-only"

Checked against the WebGPU specification at revision d178d91; the links go to the current draft.