fix: Support for PrimitiveOffsetInfo in render pipeline draw...Indirect methods#2337
fix: Support for PrimitiveOffsetInfo in render pipeline draw...Indirect methods#2337cieplypolar wants to merge 13 commits intomainfrom
PrimitiveOffsetInfo in render pipeline draw...Indirect methods#2337Conversation
|
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
This PR addresses missing support for PrimitiveOffsetInfo-based offsets in render pipeline indirect draw methods, and extends indirect dispatch to accept raw GPUBuffers (aligning compute + render indirect APIs and adding runtime validation/warnings).
Changes:
- Add
PrimitiveOffsetInfo | numberoffset support (and stricterIndirectFlagtyping) fordrawIndirect/drawIndexedIndirect. - Allow
dispatchWorkgroupsIndirectto accept rawGPUBuffers, with consistent validation/warning behavior. - Centralize indirect offset/size validation into a new
resolveIndirectOffsetutility and add/extend tests + mocks.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/typegpu/src/core/pipeline/renderPipeline.ts | Updates indirect draw APIs to accept `PrimitiveOffsetInfo |
| packages/typegpu/src/core/pipeline/computePipeline.ts | Extends dispatchWorkgroupsIndirect to accept GPUBuffer and delegates offset validation to shared utility. |
| packages/typegpu/src/core/pipeline/pipelineUtils.ts | New shared helper for indirect offset resolution, alignment/size validation, and padding-contiguity warnings. |
| packages/typegpu/tests/renderPipeline.test.ts | Adds coverage for indirect draw buffer usage/offset validation and padding warnings. |
| packages/typegpu/tests/computePipeline.test.ts | Adds coverage for raw GPUBuffer indirect dispatch validation and warning behaviors. |
| packages/typegpu-testing-utility/src/extendedIt.ts | Extends render pass encoder mocks with indirect draw methods for new tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PrimitiveOffsetInfo in render pipeline draw...Indirect methodsPrimitiveOffsetInfo in render pipeline draw...Indirect methods
aleksanderkatan
left a comment
There was a problem hiding this comment.
Neat! 🐛🌊 I would just reconsider these warns, maybe they can just be a part of JSDocs?
| console.warn( | ||
| `${operation}: Using raw GPUBuffer. Offset validation is limited. Wrap the GPUBuffer with \`root.createBuffer(...)\` for safe validation.`, | ||
| ); |
There was a problem hiding this comment.
I would actually move away from this - if someone for some reason has to use a raw buffer I would not harass them. Either remove this or add an explicit way to silence the warning
| return offset; | ||
| } | ||
|
|
||
| let offsetInfo = start ?? memoryLayoutOf(indirectBuffer.dataType); |
There was a problem hiding this comment.
Original message:
Even without the accessor this is an expensive thing to do (in case of the struct) potentially every frame with no obvious way for the user to opt out of. I think this is one of the APIs that is used in use cases where every 0.1ms of the cpu time matters so we have to be mindful of that.
Update:
I run some benchmarks and the cost of memoryLayoutOf (especially without the accessor) seems to be very low to the point where we are talking sub-microsecond so maybe it's fine
| if (offsetInfo === 0) { | ||
| offsetInfo = memoryLayoutOf(indirectBuffer.dataType); | ||
| } else { | ||
| console.warn( |
There was a problem hiding this comment.
Again someone can just not care about this (knows the layout well and has no need for additional api calls) - I think we should respect that (I know this is my code - I changed my mind
)
Closes #2336.
Also I added
GPUBuffertodispatchWorkgroupsIndirectsignature.TODO: