-
Notifications
You must be signed in to change notification settings - Fork 960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WGSL built-in similar to gl_DrawID
(for Multi Draw Indirect)
#6823
Comments
I have also needed this for sometime and just used a fork. Currently it is just one line: jannik4@dce431a (But of course I would have no problem if that would be supported here:)) |
Yeah, vulkan isn't the problem lol - we could support this on vulkan fairly easily, but metal and dx12 are significantly more work. |
Sure, I just restricted my app to Vulkan and called it a day😄. |
If we can support versions of D3D12 with incrementing constant, then it shouldn't be too difficult to implement this, assuming we save a variable in the root signature somewhere for it. Metal will be more complicated since it will require a buffer; I don't think you can set immediate data from an indirect command buffer. |
Well currently we don't use Indirect Command Buffers at all on metal, so MDI is actually just an single indirect call in a loop in the backend. That does actually make it slightly easier to do, as we can just set the immediate data. |
I've thought for a while we should have our own concept of an indirect command buffer in the shader to deal with these differences. |
I also need this. I want to use multi draw indirect and need per draw position offset (a vec3i). If I use a vertex attribute, it would double my memory usage. |
Could you use instancing, and an instance-rate data stream? |
I use an instance buffer to represent a face of a voxel cube (draws 6 vertexes). My instance buffer has all my chunks in a single buffer. I use an indirect buffer to partially render my chunks. I store my chunk buffer data in a separate buffer that I want to index via the draw index (each draw call draws one chunk). |
Im not super familiar with graphics APIs so I'm not sure what a instance-rate data stream is. Thanks for your help! |
Why not combine all your chunks into one giant indirect draw call using a compute shader? I don't see the need for multi-draw here. |
I could try that, thank you |
Is your feature request related to a problem? Please describe.
When using Multi Draw Indirect, there is no way for the shader to know what draw it is a part of.
GLSL in OpenGL provides the
gl_DrawID
built-in for this purpose. WGSL does not have an equivalent.(AFAIK, the WebGPU spec does not have MDI at all? I am not sure. That would explain the lack of such builtin in WGSL.)
Describe the solution you'd like
Naga could add support for a
draw_index
built-in, similar tovertex_index
andinstance_index
. Even though this is not part of the upstream WGSL spec.Describe alternatives you've considered
Depending on the use case, it may be possible to work around this by using the instance IDs instead.
The text was updated successfully, but these errors were encountered: