Skip to content

WriteGPUBuffer and populateWith: one upload path, and documented ordering - #85

Merged
jowens merged 2 commits into
mainfrom
write-gpu-buffer
Oct 27, 2026
Merged

jowens merged 2 commits into
mainfrom
write-gpu-buffer

Conversation

@jowens

@jowens jowens commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Follow-up from the declared-buffers work: WriteGPUBuffer and AllocateBuffer's populateWith.

The trap, now documented

Both are queue writes (queue.writeBuffer). They happen while execute() is still recording the encoder, so they land before any of that execute()'s GPU work, wherever they appear in the action list:

[ new Kernel(A), new WriteGPUBuffer({ label: "x", cpuSource }), new Kernel(B) ]
// runs as: write x, then A, then B

Kernel, ClearBuffer, CopyBufferToBuffer and ExecutePrimitive, by contrast, are encoder commands and run in list order. None of this was written down anywhere. It's now in primitive.mjs (one note, plus doc comments on each action class) and in a new "Actions, and when they take effect" section of docs/architecture.md.

Changes

  • One upload path for both, BasePrimitive.__writeBuffer(label, data, offset). This settles the todo in __allocateBuffer.
    • WriteGPUBuffer now also skips uploading unchanged data into a uniform buffer, tracked per offset.
    • Writing to an unknown buffer is now an error. It used to be a warning followed by a crash.
  • test_wgsl_functions: the input is now written with real data, once whole and then at an offset, and a new test reads it back. Before, it wrote zeros into an already-zero buffer.
  • Types: WriteGPUBuffer's offset is now in the type declarations.

Checked

  • WGSL function tests: the new test passes with and without subgroups. The same three subgroup tests fail as on main (lavapipe's 8 lanes).
  • Regression suite on lavapipe: everything passes except the existing 8-lane sort failures.
  • Package test: passes.

Independent of #84.


Generated by Claude Code

…ring

- Both are queue writes (queue.writeBuffer): they land before any of the
  execute()'s GPU work, wherever they appear in the action list, unlike
  Kernel, ClearBuffer and CopyBufferToBuffer, which are encoder commands and
  run in order. This was undocumented; primitive.mjs, the action classes and
  docs/architecture.md now say so.
- One upload path, BasePrimitive.__writeBuffer(label, data, offset), used by
  both (settles the todo in __allocateBuffer). WriteGPUBuffer now also skips
  uploading unchanged data into a uniform buffer (tracked per offset), and
  an unknown buffer is an error instead of a warning followed by a crash.
- Doc comments for AllocateBuffer, WriteGPUBuffer, ClearBuffer and
  CopyBufferToBuffer; WriteGPUBuffer's offset in the types.
- test_wgsl_functions: the input is written with real data, whole and then
  at an offset, and a new test reads it back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015kfNC6id65zEHzuAAH4jtJ
Conflict in docs/architecture.md: both sides added a section before
"Composing primitives". Kept both: "WGSL helpers" (#84), then "Actions, and
when they take effect" (this PR).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015kfNC6id65zEHzuAAH4jtJ
@jowens
jowens merged commit 30660b3 into main Oct 27, 2026
4 checks passed
@jowens
jowens deleted the write-gpu-buffer branch October 27, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants