[metal] Implement MULTI_DRAW_INDIRECT_COUNT via compute shader emulation#9659
[metal] Implement MULTI_DRAW_INDIRECT_COUNT via compute shader emulation#9659Bromles wants to merge 6 commits into
Conversation
|
How does this relate to #9640? Also CC @matthargett |
Thanks for pointing it out - I completely missed that PR After reviewing it, I can say that my PR is more akin to the old I think my PR can be used as a temporary implementation until we get a proper ICB-based solution for |
|
Thanks for explaining! I will have to spend more time thinking about it but I don't doubt you. |
|
Well, seems like I just waited too long to contribute - had this idea for a while, but didn't act on it No problem, it's even better if we are able to get a proper implementation without emulation |
|
@Bromles Thank you for the contribution anyway :) |
Connections
None
Description
Metal has no native support for
draw_indirect_count/draw_indexed_indirect_count. The featureMULTI_DRAW_INDIRECT_COUNTwas not advertised on Metal. This PR attempts to emulate it to support all native primary backends.The emulation runs a compute shader before the render pass. It reads the count buffer and copies the appropriate number of draw commands from the source indirect buffer into a temporary buffer, then calls regular
draw_indirect. Commands beyond the count are zeroed so those draw calls are no-ops.I was considering Indirect Command Buffers. But Metal ICB does not support providing the draw count from the GPU - the command count must be known at ICB encoding time on the CPU. This would require a GPU-CPU sync to read back the count buffer before encoding, which is too expensive per
multi_draw_indirect_countcall.Future interaction with
draw_index. wgpu already hasSHADER_DRAW_INDEXfor Vulkan and GLES, but Metal does not support it yet. When Metal support is added, the emulation would need to inject the draw index into each command in the temp buffer so that draw_indirect calls can expose it.I used
indirect_validationas a reference for the implementation: a device-levelMultiDrawEmulationowns the pipeline and a temp buffer pool, whileMultiDrawResourcesmanages per-command-buffer resources and returns buffers to the pool on drop.Testing
tests/tests/wgpu-gpu/draw_indirect.rsfor indexed/non-indexed and partial count casesmulti_draw_indirect_countSquash or Rebase?
Squash
Checklist
wgpumay be affected behaviorally.CHANGELOG.mdentries for the user-facing effects of this change are present.