Skip to content

Comments

Add per-vertex attribute support to vulkan, spir-v and wgsl.#8821

Merged
cwfitzgerald merged 12 commits intogfx-rs:trunkfrom
atlv24:ad/per-vertex-vk
Jan 16, 2026
Merged

Add per-vertex attribute support to vulkan, spir-v and wgsl.#8821
cwfitzgerald merged 12 commits intogfx-rs:trunkfrom
atlv24:ad/per-vertex-vk

Conversation

@atlv24
Copy link
Collaborator

@atlv24 atlv24 commented Jan 6, 2026

Connections
#8591

Description
HLSL and MSL support are possible, but hard. I want to land Vulkan support and worry about the rest later.

Testing
wgpu-gpu test and naga test.

Squash or Rebase?

squish

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
Copy link
Collaborator

I may work on the HLSL and MSL support myself at a later date. I'll be reviewing this PR, since I've examined the spec and talked about this briefly with @atlv24.

@inner-daemons inner-daemons self-assigned this Jan 7, 2026
@cwfitzgerald cwfitzgerald self-assigned this Jan 7, 2026
Copy link
Collaborator

@inner-daemons inner-daemons left a comment

Choose a reason for hiding this comment

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

Broadly looks good. Some comments for now, plus I want to think through the validation later to make sure you didn't miss anything.

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 support for per-vertex attributes in fragment shaders, enabling access to raw per-vertex values within a triangle. The feature leverages Vulkan's VK_KHR_fragment_shader_barycentric extension and is implemented for WGSL input and SPIR-V/WGSL output only, with HLSL and MSL support deferred for future work.

Key Changes:

  • Added SHADER_PER_VERTEX feature flag to wgpu-types
  • Integrated the feature with Vulkan's fragment shader barycentric extension in wgpu-hal
  • Extended naga's IR with PerVertex interpolation mode and added validation for per-vertex fragment inputs (must be array of length 3)

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
wgpu-types/src/features.rs Added SHADER_PER_VERTEX feature flag with Vulkan-only support annotation
wgpu-hal/src/vulkan/adapter.rs Connected feature flag to VK_KHR_fragment_shader_barycentric extension and FragmentBarycentricKHR capability
wgpu-core/src/device/mod.rs Mapped wgpu feature to naga validator capability
naga/src/ir/mod.rs Added PerVertex variant to Interpolation enum
naga/src/front/wgsl/parse/conv.rs Added WGSL parser support for per_vertex interpolation keyword
naga/src/front/spv/mod.rs Added SPIR-V frontend support for PerVertexKHR decoration
naga/src/common/wgsl/to_wgsl.rs Added WGSL output support for per_vertex interpolation
naga/src/back/spv/writer.rs Added SPIR-V backend support with PerVertexKHR decoration and capability requirement
naga/src/back/hlsl/conv.rs Added unreachable case for PerVertex (HLSL not yet supported)
naga/src/back/glsl/conv.rs Added unreachable case for PerVertex (GLSL not yet supported)
naga/src/valid/mod.rs Added PER_VERTEX capability flag
naga/src/valid/interface.rs Added validation logic ensuring per-vertex inputs are fragment-only, array of length 3, and require proper capability
naga/tests/naga/validation.rs Updated interpolation validation tests to include PerVertex
naga/tests/in/wgsl/per-vertex.wgsl Added naga test shader for per-vertex feature
naga/tests/in/wgsl/per-vertex.toml Test configuration restricting to WGSL and SPIRV targets
naga/tests/out/wgsl/wgsl-per-vertex.wgsl Expected WGSL output for naga test
naga/tests/out/spv/wgsl-per-vertex.spvasm Expected SPIR-V output for naga test
tests/tests/wgpu-gpu/per_vertex/per_vertex.wgsl Integration test shader demonstrating per-vertex attributes
tests/tests/wgpu-gpu/per_vertex/mod.rs Integration test rendering triangle strip and validating per-vertex values
tests/tests/wgpu-gpu/main.rs Registered per_vertex test module
CHANGELOG.md Added changelog entry for the new feature

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

Copy link
Collaborator

@inner-daemons inner-daemons left a comment

Choose a reason for hiding this comment

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

Pretty much good I think! Thanks for working on this. A few more questions, nothing major

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we make the texture a little bit bigger just to be perfectly clear with whats going on? Maybe just like 16x16 or something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe the point of the other tests using a small texture is to be able to reason about it pixel by pixel mentally. With that many pixels, you'd be having to reason about 256 fragment shader invocations mentally which is a bit much. It would also make the assert huge and unreadable with 1024 byte literals

Copy link
Member

Choose a reason for hiding this comment

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

I agree that this size is perfect, the diagram really helps!

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Code looks good!

Some smaller nits, plus could we add a test in wgsl_error to make sure that any per_vertex stuff gets properly validated out if the feature isn't there (very important for firefox). This would also be a good place to test the other validation, but this is less important.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that this size is perfect, the diagram really helps!

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

I like to merge it merge it

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) January 16, 2026 00:45
@cwfitzgerald cwfitzgerald merged commit 4a3526a into gfx-rs:trunk Jan 16, 2026
53 checks passed
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