Skip to content

[naga hlsl-out, glsl-out] Support atomicCompareExchangeWeak#7658

Merged
teoxoy merged 20 commits intogfx-rs:trunkfrom
cryvosh:support_atomicCompareExchangeWeak_hlsl_glsl
Jun 2, 2025
Merged

[naga hlsl-out, glsl-out] Support atomicCompareExchangeWeak#7658
teoxoy merged 20 commits intogfx-rs:trunkfrom
cryvosh:support_atomicCompareExchangeWeak_hlsl_glsl

Conversation

@cryvosh
Copy link
Copy Markdown
Contributor

@cryvosh cryvosh commented May 2, 2025

Connections
Fixes #7578
Fixes #4364

Description
Adds support for atomicCompareExchangeWeak translation to hlsl and glsl.

Note this does not implement the [allow_uav_condition] loop attribute mentioned here and here.
Not sure the best way to check if the loop termination is based off a UAV read.
Maybe can later borrow logic from the uniformity analyzer?
Dawn doesn't seem to do this either, though maybe it should?
There is a test with a while loop that depends on .exchanged which seems to pass hlsl validation.

Testing
Added / enabled some basic atomicCompareExchangeWeak tests to Naga.
My personal project using atomicCompareExchangeWeak runs fine now on Windows/Nvidia/DX12.
GL backend is untested outside the Naga tests / validation.

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.

@cryvosh cryvosh marked this pull request as draft May 2, 2025 04:46
@cryvosh cryvosh marked this pull request as ready for review May 2, 2025 05:43
@teoxoy
Copy link
Copy Markdown
Member

teoxoy commented May 21, 2025

Note this does not implement the [allow_uav_condition] loop attribute mentioned here and here.
Not sure the best way to check if the loop termination is based off a UAV read.
Maybe can later borrow logic from the uniformity analyzer?
Dawn doesn't seem to do this either, though maybe it should?
There is a test with a while loop that depends on .exchanged which seems to pass hlsl validation.

I don't see DXC doing anything with the [allow_uav_condition] attribute https://github.com/search?q=repo%3Amicrosoft%2FDirectXShaderCompiler%20HLSLAllowUAVCondition&type=code, maybe it's legacy.

Comment thread naga/src/back/hlsl/writer.rs
Comment thread naga/src/back/hlsl/writer.rs Outdated
Comment thread naga/src/back/hlsl/writer.rs
Comment thread naga/src/back/glsl/mod.rs Outdated
Comment thread naga/src/back/glsl/mod.rs Outdated
Comment thread naga/src/back/glsl/mod.rs
Comment thread naga/src/back/glsl/mod.rs
@teoxoy
Copy link
Copy Markdown
Member

teoxoy commented Jun 2, 2025

Thanks for addressing the comments, PR looks good - let's land it!

@teoxoy teoxoy merged commit bb46a7f into gfx-rs:trunk Jun 2, 2025
38 checks passed
sharmajai pushed a commit to sharmajai/wgpu that referenced this pull request Oct 12, 2025
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.

Internal error in writing type when atomicCompareExchangeWeak is used in compute shader, on GL backend Implement atomicCompareExchangeWeak

2 participants