-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add mesh shading info to naga IR #8104
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
base: trunk
Are you sure you want to change the base?
Conversation
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. |
Should be fixed with #8112, thanks @andyleiserson! |
Going to ping you again @jimblandy just to make sure that this doesn't get forgotten about until the next meeting :) |
@SupaMaggie70Incorporated I'll try to get to this tonight, but it may be Saturday. |
@SupaMaggie70Incorporated Are these comments at the top of
|
I've updated the top of |
(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 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. |
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a new Capabilities
flag for mesh shading, and the validator should reject mesh stages unless it is set. If that's in a subsequent PR, it needs to be pulled forward into this one; we can't have the stuff in the IR unless we forbid it when it's not enabled. I know the backends will just crash; but it's easiest to keep things coherent.
Please remove the TODO comments and file a follow-up issue for each one if appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entry point validation in Validator::validate_module_handles
needs to handle EntryPoint::mesh_info
and EntryPoint::task_payload
as well.
@jimblandy we don't currently do this for compute shaders either though - naga isn't the one who is validating the stage is valid, it's wgpu |
Compute shaders are a base WebGPU feature, though, whereas mesh shaders are not. |
Oh I was thinking about backends once we already know the stages involved, yes the validator needs to be validating out mesh entry points (and compute entry points too; but that doesn't have to be here) |
I have changed |
We only need to bump it once we actually hit 33 :) |
Ok, I'll revert that. |
Just put up #8370, which is the WGSL parsing PR. The WGSL parsing and validation passes there, so this PR's validation seems to not be disallowing valid shaders yet. |
@jimblandy Me and @cwfitzgerald agreed that mesh shader outputs should always be buffered, so I'm gonna remove references in the spec to having to call |
Does this mean we could also potentially have a design where the vertex and primitive arrays and counts are returned by the mesh shader? It seemed to me like much of this stuff would work just as well as new struct MeshOutput {
@builtin(vertex_count) num_vertices: u32,
@builtin(primitive_count) num_primitives: u32,
@builtin(vertices) vertices: array<Vertex, 10>,
@builtin(primitives) primitives: array<Primitive, 15>,
}
@mesh @workgroup_size(15, 1, 1)
fn mesh_shader(
@builtin(local_invocation_index) invocation: u32,
@builtin(task_payload) payload: Payload
) -> MeshOutput {
...
} |
Err, that's actually really clever. I do think that this isn't right though, since the thing output is per workgroup and this would have each thread return a giant structure, that would in theory be the same for all threads anyway. I'm not opposed to something closer to this though, like a global thread group variable that holds the buffered outputs and then the mesh shader can declare that it uses that global variable. |
Ok, I've thought about it some more. I think that we can't really avoid buffering for another reason: the output format isn't guaranteed to match whatever the naga struct is. SPIR-V for example has arcane rules on which values must be in different output arrays. HLSL is very similar. I still don't think we should have the task payload/mesh outputs be per-thread, but a small tweak to your proposal would be as follows: struct MeshOutput {
@builtin(vertex_count) num_vertices: u32,
@builtin(primitive_count) num_primitives: u32,
@builtin(vertices) vertices: array<Vertex, 10>,
@builtin(primitives) primitives: array<Primitive, 15>,
}
var<mesh_output> output: MeshOutput;
var<task_payload> task_payload: Payload;
@mesh(output) @workgroup_size(15, 1, 1)
fn mesh_shader(
@builtin(local_invocation_index) invocation: u32,
) {
...
} Then we would just need to allow these |
@inner-daemons Have the commits I've pushed been looking okay? |
@jimblandy They look great! I very much appreciate them. |
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
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.