fix: Atomic and decorated types for SoA and write fast path#2329
fix: Atomic and decorated types for SoA and write fast path#2329
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (349 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
There was a problem hiding this comment.
Pull request overview
Adds better support for writing data into buffers/SoA layouts when schemas include atomics and/or WGSL decorations (align/size), and verifies behavior via new tests.
Changes:
- Extend
TypedArrayFor<>to supportatomic<i32/u32>and decorated schemas by delegating to the inner type. - Update
writeSoApacking logic to treat decorated/atomic schemas as their “packed” equivalents when computing sizes/layout. - Add tests covering fast-path writes for decorated buffers, typed-view writes for atomic arrays, and SoA writes involving atomics/decorated fields.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/typegpu/tests/buffer.test.ts | Adds tests for decorated-buffer raw fast-path, atomic-array typed views, and SoA writes for atomics/decorated fields. |
| packages/typegpu/src/data/wgslTypes.ts | Expands TypedArrayFor<> to recognize Atomic<I32/U32> and unwrap Decorated<>. |
| packages/typegpu/src/common/writeSoA.ts | Introduces “packed schema” handling (undecorate + unwrap atomic) for SoA packing computations/writes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -130,7 +142,7 @@ function writePackedValue( | |||
| return; | |||
| } | |||
|
|
|||
| target.set(srcBytes.subarray(srcOffset, srcOffset + sizeOf(schema)), dstOffset); | |||
| target.set(srcBytes.subarray(srcOffset, srcOffset + sizeOf(packedSchema)), dstOffset); | |||
There was a problem hiding this comment.
writePackedValue only enters the array-packing branch when both packedSchema and the original schema satisfy isWgslArray(...). For a decorated array field (e.g. d.align(16, d.arrayOf(d.vec3f, 2))), packedSchemaOf(schema) returns the inner array but isWgslArray(schema) is false (schema.type === 'decorated'). This makes the function fall through to the raw target.set(...) copy, which writes packed bytes contiguously and produces an incorrect GPU layout (it won’t insert per-element stride/padding). Consider keying the array logic off the undecorated schema (or otherwise handling Decorated<array<...>>) so decorated arrays are packed via the per-element stride loop, and add a regression test with an element type that requires padding (e.g. vec3f).
No description provided.