[metal] Implement MULTI_DRAW_INDIRECT_COUNT via compute shader emulation#9659
Open
Bromles wants to merge 6 commits into
Open
[metal] Implement MULTI_DRAW_INDIRECT_COUNT via compute shader emulation#9659Bromles wants to merge 6 commits into
Bromles wants to merge 6 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.