Skip to content

Conversation

@inner-daemons
Copy link
Collaborator

@inner-daemons inner-daemons commented Oct 17, 2025

Connections
#7197

Description
Adds WGSL parsing for mesh shaders to naga.

This PR is quite a bit smaller than it looks, just a few hundred lines. The rest of the "changes" come from snapshots.

Testing
There are mesh shader tests (that don't actually write to any backend)

Also, #8456 proves that this is enough information to write proper SPIR-V shaders

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.

inner-daemons and others added 30 commits August 14, 2025 12:53
@inner-daemons inner-daemons mentioned this pull request Oct 30, 2025
37 tasks
@inner-daemons inner-daemons marked this pull request as ready for review October 30, 2025 21:48
@inner-daemons inner-daemons marked this pull request as draft October 30, 2025 22:19
@inner-daemons inner-daemons marked this pull request as ready for review October 31, 2025 00:50
@inner-daemons
Copy link
Collaborator Author

@cwfitzgerald This PR still needs some cleanup, in terms of making the code easier to read and updating the spec, but I think this represents what I imagine the approach to mesh shaders & WGSL would look like (see naga/tests/in/wgsl/mesh-shader.wgsl). So if I could get a preliminary overview kind of review soon-ish that would be appreciated, but of course not 100% necessary :)

@cwfitzgerald
Copy link
Member

No promises before the 12th ofc but I should be able to get to it before then

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

I'm encouraged by the way this concentrates almost all the validation work in valid/interface.rs, the other valid submodules have lots of delicious deletions.

@cwfitzgerald cwfitzgerald requested a review from Copilot November 7, 2025 02:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds WGSL parsing support for mesh shaders to Naga, implementing a new approach where mesh shader outputs are written to workgroup variables rather than through function calls. The changes enable parsing of @task and @mesh entry points, new builtins (@builtin(vertices), @builtin(primitives), etc.), the task_payload address space, and the @per_primitive attribute.

Key changes:

  • New mesh shader builtins (VertexCount, Vertices, PrimitiveCount, Primitives) for workgroup variable fields
  • New TaskPayload address space for inter-stage communication
  • Removal of MeshFunction statement type in favor of direct workgroup variable access
  • Updated validation to analyze mesh output variable structure
  • Frontend support for @task, @mesh, and @payload attributes

Reviewed Changes

Copilot reviewed 31 out of 39 changed files in this pull request and generated no comments.

Show a summary per file
File Description
naga/src/ir/mod.rs Adds new BuiltIn variants and modifies MeshStageInfo to include output_variable field
naga/src/valid/interface.rs Adds validation for mesh output variables and capability checks for new builtins
naga/src/proc/mod.rs Adds analyze_mesh_shader_info function to extract mesh info from workgroup variables
naga/src/front/wgsl/parse/mod.rs Adds parsing for @task, @mesh, @payload attributes and @per_primitive decorator
naga/src/front/wgsl/parse/directive/enable_extension.rs Adds MeshShader enable extension
naga/src/valid/analyzer.rs Removes FunctionMeshShaderInfo and related mesh function analysis
naga/tests/in/wgsl/mesh-shader.wgsl Adds test input for mesh shader parsing
docs/api-specs/mesh_shading.md Updates specification to reflect workgroup variable-based approach
Multiple backend files Updates to handle new builtins with unreachable!() for unsupported cases
Comments suppressed due to low confidence (1)

naga/src/ir/mod.rs:2587

  • Corrected spelling: 'renderedas' should be 'rendered as' in the doc comment.
    Lines,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

4 participants