Skip to content

Conversation

SupaMaggie70Incorporated
Copy link
Contributor

@SupaMaggie70Incorporated SupaMaggie70Incorporated commented Aug 14, 2025

Connections
Mostly split off from #7930
Works towards #7197

Description
This PR adds mesh shading info to naga IR so that parsers and writers have an interface to use.

Testing
No testing yet (coming in later PRs, the code here has been tested in #7930)

Squash or Rebase?

Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@SupaMaggie70Incorporated
Copy link
Contributor Author

I'm unsure why the MSRV minimal versions thing is failing, it doesn't look related to this PR since it happens in another crate and this PR doesn't touch anything cargo.

@cwfitzgerald
Copy link
Member

cwfitzgerald commented Aug 17, 2025

Should be fixed with #8112, thanks @andyleiserson!

@@ -966,6 +984,7 @@ pub enum Binding {
/// Optional `blend_src` index used for dual source blending.
/// See <https://www.w3.org/TR/WGSL/#attribute-blend_src>
blend_src: Option<u32>,
per_primitive: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have some docs for this? The Location variant's docs talk about passing values from the vertex stage to the fragment stage; we should make sure the story told here makes sense for readers working on mesh shaders too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to write some docs. Let me know if you have further comments.

@SupaMaggie70Incorporated
Copy link
Contributor Author

Going to ping you again @jimblandy just to make sure that this doesn't get forgotten about until the next meeting :)

@jimblandy
Copy link
Member

@SupaMaggie70Incorporated I'll try to get to this tonight, but it may be Saturday.

@jimblandy
Copy link
Member

@SupaMaggie70Incorporated Are these comments at the top of mesh_shading.md still accurate?

Currently naga has no support for mesh shaders beyond recognizing the additional shader stages. For this reason, all shaders must be created with Device::create_shader_module_passthrough.

@SupaMaggie70Incorporated
Copy link
Contributor Author

@SupaMaggie70Incorporated Are these comments at the top of mesh_shading.md still accurate?

Currently naga has no support for mesh shaders beyond recognizing the additional shader stages. For this reason, all shaders must be created with Device::create_shader_module_passthrough.

I've updated the top of mesh_shading.md. Until further PRs it remains true that you will need to use passthrough shaders but it now has more "processing" ability so the statement wasn't strictly true.

@jimblandy
Copy link
Member

jimblandy commented Aug 25, 2025

(This is not a review comment on this PR, and not directed at SupaMaggie, just commenting on the pre-existing state of the docs.)

This is not a thorough explanation of mesh shading and how it works. Those wishing to understand mesh shading more broadly should look elsewhere first.

This is just not adequate. If we're going to add syntax to Naga that is not covered by the WGSL specification, we need to document that syntax. Knowing how mesh shading works in Vulkan does not magically explain the syntax for mesh shaders in WGSL, or how to invoke them in wgpu.

@SupaMaggie70Incorporated
Copy link
Contributor Author

(This is not a review comment on this PR, and not directed at SupaMaggie, just commenting on the pre-existing state of the docs.)

This is not a thorough explanation of mesh shading and how it works. Those wishing to understand mesh shading more broadly should look elsewhere first.

This is just not adequate. If we're going to add syntax to Naga that is not covered by the WGSL specification, we need to document that syntax. Knowing how mesh shading works in Vulkan does not magically explain the syntax for mesh shaders in WGSL, or how to invoke them in wgpu.

It wouldn't be part of this PR, but if you think that having a writeup somewhere to describe mesh shaders would be useful, I'm happy to do that separately. However, I have never written a comprehensive GPU API spec before, so I don't exactly think it would be of comparable quality to e.g. the webgpu spec :)

Also, that specific disclaimer was copy-pasted directly from the RT spec.

@jimblandy
Copy link
Member

It wouldn't be part of this PR, but if you think that having a writeup somewhere to describe mesh shaders would be useful, I'm happy to do that separately. However, I have never written a comprehensive GPU API spec before, so I don't exactly think it would be of comparable quality to e.g. the webgpu spec :)

Well, the alternative is just saying "read the code and the examples and figure it out". You want people to actually use your work, right?

I just pushed some docs; do they look correct?

@jimblandy
Copy link
Member

More later - sorry to take so long.

@SupaMaggie70Incorporated
Copy link
Contributor Author

It wouldn't be part of this PR, but if you think that having a writeup somewhere to describe mesh shaders would be useful, I'm happy to do that separately. However, I have never written a comprehensive GPU API spec before, so I don't exactly think it would be of comparable quality to e.g. the webgpu spec :)

Well, the alternative is just saying "read the code and the examples and figure it out". You want people to actually use your work, right?

I just pushed some docs; do they look correct?

I'd like to make a few edits, at least around the section about task shader returns, just to clarify some things. Overall I think this is a step in the right direction. I'll try to get to this tonight or tomorrow

@jimblandy
Copy link
Member

We don't need to have everything fully documented before we land. I just end up writing docs (or trying to) in the process of figuring out what's going on in a PR.

@jimblandy
Copy link
Member

Also, that specific disclaimer was copy-pasted directly from the RT spec.

Fair.

@jimblandy
Copy link
Member

I'd like to make a few edits, at least around the section about task shader returns, just to clarify some things. Overall I think this is a step in the right direction. I'll try to get to this tonight or tomorrow

Sounds great. Just go ahead and push your changes to the branch, and I'll check them out. I'm curious to see what changes, but I'm not possessive about the text.

@SupaMaggie70Incorporated
Copy link
Contributor Author

SupaMaggie70Incorporated commented Aug 25, 2025

@jimblandy You mention invocations a lot in your docs, is this a mistake or is this how wgpu docs are commonly written? Task and mesh shaders all function in units of workgroups (like compute shaders) and all outputs are shared across the workgroups.

The workgroup size is also constant and part of the shader. The group size arguments you pass to draw_mesh_tasks or that a task shader outputs correspond to the number of workgroups and not the size of a single workgroup.

@SupaMaggie70Incorporated
Copy link
Contributor Author

I'm going to work on the spec a little more to try to clarify what mesh shaders are, not just how the new API works.

@jimblandy
Copy link
Member

@jimblandy You mention invocations a lot in your docs, is this a mistake or is this how wgpu docs are commonly written?

My mistake.

The workgroup size is also constant and part of the shader. The group size arguments you pass to draw_mesh_tasks or that a task shader outputs correspond to the number of workgroups and not the size of a single workgroup.

Mistake. This one I should have known - thanks for catching it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants