Skip to content

[naga spv-in] Add support for memory barriers#7630

Merged
teoxoy merged 3 commits intogfx-rs:trunkfrom
PhenaOfMari:spv-memory-barriers
Jun 16, 2025
Merged

[naga spv-in] Add support for memory barriers#7630
teoxoy merged 3 commits intogfx-rs:trunkfrom
PhenaOfMari:spv-memory-barriers

Conversation

@PhenaOfMari
Copy link
Copy Markdown
Contributor

@PhenaOfMari PhenaOfMari commented Apr 25, 2025

Description
Naga's SpirV ingest currently has support for control barriers, but not memory-only barriers. This PR endeavors to add this support for SpirV in as well as any language out that may make proper use of them. Languages that don't support memory barriers without an execution barrier will follow the existing Control Barrier path.

Additionally, Control Barriers for SpirV in and out have no distinction between workgroup and subgroup memory scopes. Support for that has been added as a separate commit, which can easily be pulled out into a separate pull request if desired.

Testing
I've compiled a simple shader with rust-gpu that utilizes their memory_barrier function. These changes allow the compiled shader to be parsed and executed, where previously the validator would panic that OpMemoryBarrier was unsupported. I've also added a spvasm file to naga/tests/in/spv that compiles to all backends.

Squash or Rebase
Both commits should be able to stand on their own if whoever does the merge prefers to rebase. Either way is fine.

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.

@PhenaOfMari PhenaOfMari force-pushed the spv-memory-barriers branch 3 times, most recently from c867f55 to cf1d916 Compare April 26, 2025 02:15
@PhenaOfMari PhenaOfMari marked this pull request as ready for review April 26, 2025 02:30
@PhenaOfMari PhenaOfMari force-pushed the spv-memory-barriers branch 2 times, most recently from de56a4a to d1ec6c8 Compare May 8, 2025 04:02
@LegNeato
Copy link
Copy Markdown
Contributor

This looks great, can't wait for it to land!

@PhenaOfMari PhenaOfMari force-pushed the spv-memory-barriers branch from d1ec6c8 to 20d22a5 Compare May 26, 2025 19:42
@jimblandy jimblandy requested a review from teoxoy June 4, 2025 15:14
@teoxoy teoxoy self-assigned this Jun 4, 2025
@PhenaOfMari PhenaOfMari force-pushed the spv-memory-barriers branch from 20d22a5 to 15fb018 Compare June 5, 2025 00:57
Copy link
Copy Markdown
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

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

Looks good overall!

@PhenaOfMari PhenaOfMari force-pushed the spv-memory-barriers branch from 15fb018 to 6eed94b Compare June 11, 2025 01:29
@teoxoy teoxoy merged commit 486a77d into gfx-rs:trunk Jun 16, 2025
40 checks passed
@PhenaOfMari PhenaOfMari deleted the spv-memory-barriers branch June 16, 2025 22:35
robtfm added a commit to bevyengine/naga_oil that referenced this pull request Jan 22, 2026
This is a working naga 28 update. I noticed some tests haven't passed
(specifically cargo test --all-features) since before 0.14, so this PR
doesn't attempt to make them pass.

## enumerate_adaptors

`instance.enumerate_adapters` is async now (and available on webgpu):
gfx-rs/wgpu#8230 . more details in the wgpu
release notes.

## ControlBarrier & MemoryBarrier

Barrier was split in two to support MemoryBarriers:
gfx-rs/wgpu#7630

From the PR, it seems like falling back to ControlBarrier is fine so
that's what I did.

## Ray Query enable

ray queries require `enable wgpu_ray_query;`:
gfx-rs/wgpu#8545

This doesn't currently seem to make it through, and the relevant test
fails.

## ImageAtomic

Image atomics were added in gfx-rs/wgpu#6706

## Mesh Shaders

Mesh shaders are a major feature of wgpu 28, ~~but I've set their fields
to None here in the interest of doing an upgrade and not a feature add
at the same time~~

https://github.com/gfx-rs/wgpu/releases/tag/v28.0.0

update: I found some time and built a wgpu mesh/task shader demo and
used that to validate some of the mesh shader functionality. I've used
this to successfully compile a task shader with naga-oil and run it, but
there's still something missing from the mesh shader module output here.

---------

Co-authored-by: robtfm <50659922+robtfm@users.noreply.github.com>
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