Skip to content
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

Open
inodentry opened this issue Dec 24, 2024 · 6 comments
Open

WGSL built-in similar to gl_DrawID (for Multi Draw Indirect) #6823

inodentry opened this issue Dec 24, 2024 · 6 comments
Labels
api: dx12 Issues with DX12 or DXGI api: metal Issues with Metal api: vulkan Issues with Vulkan area: api Issues related to API surface area: naga back-end Outputs of naga shader conversion area: naga front-end lang: HLSL D3D Shading Language lang: Metal Metal Shading Language lang: SPIR-V Vulkan's Shading Language lang: WGSL WebGPU Shading Language naga Shader Translator type: enhancement New feature or request

Comments

@inodentry
Copy link

inodentry commented Dec 24, 2024

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 to vertex_index and instance_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.

@cwfitzgerald cwfitzgerald added type: enhancement New feature or request area: api Issues related to API surface api: dx12 Issues with DX12 or DXGI api: metal Issues with Metal api: vulkan Issues with Vulkan area: naga back-end Outputs of naga shader conversion naga Shader Translator lang: SPIR-V Vulkan's Shading Language area: naga front-end lang: Metal Metal Shading Language lang: WGSL WebGPU Shading Language lang: HLSL D3D Shading Language labels Dec 24, 2024
@jannik4
Copy link

jannik4 commented Dec 24, 2024

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:))

@cwfitzgerald
Copy link
Member

Yeah, vulkan isn't the problem lol - we could support this on vulkan fairly easily, but metal and dx12 are significantly more work.

@jannik4
Copy link

jannik4 commented Dec 25, 2024

Sure, I just restricted my app to Vulkan and called it a day😄.

@magcius
Copy link
Contributor

magcius commented Dec 25, 2024

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.

@cwfitzgerald
Copy link
Member

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.

@cwfitzgerald
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dx12 Issues with DX12 or DXGI api: metal Issues with Metal api: vulkan Issues with Vulkan area: api Issues related to API surface area: naga back-end Outputs of naga shader conversion area: naga front-end lang: HLSL D3D Shading Language lang: Metal Metal Shading Language lang: SPIR-V Vulkan's Shading Language lang: WGSL WebGPU Shading Language naga Shader Translator type: enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

4 participants