-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[naga hlsl-out, glsl-out] Support atomicCompareExchangeWeak #7658
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?
[naga hlsl-out, glsl-out] Support atomicCompareExchangeWeak #7658
Conversation
I don't see DXC doing anything with the |
let fun_str = fun.to_hlsl_suffix(); | ||
let compare_expr = match *fun { | ||
crate::AtomicFunction::Exchange { compare: Some(cmp) } => Some(cmp), |
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.
We need to add cmp
to need_bake_expressions
to make sure that the expression chain doesn't get written multiple times. See crate::Statement::SubgroupCollectiveOperation
for an example.
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.
Inserted cmp immediately after but let me know if there's a better place to do it
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.
Same comment as the GLSL backend, this should go in update_expressions_to_bake
.
// we just wrote `InterlockedAdd`, so negate the argument | ||
write!(self.out, "-")?; | ||
crate::AtomicFunction::Exchange { | ||
compare: Some(compare_expr), |
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.
compare_expr
needs to be added to need_bake_expressions
.
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.
I added this logic directly here, but would it be better somewhere else like in update_expressions_to_bake
?
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.
Yeah it should go in update_expressions_to_bake
since it might be too late to register it here.
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
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.