-
Notifications
You must be signed in to change notification settings - Fork 909
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
[naga] [msl-out] Add support for metal's atomic_compare_exchange_weak #5675
Conversation
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.
This needs to be rebased after #5383.
writeln!( | ||
self.out, | ||
r#" | ||
template<typename R, typename T, typename A> R __make_atomic_cas_result(device A* ptr, T cmp_, T v) {{ | ||
T cmp = cmp_; | ||
bool exchanged = {NAMESPACE}::atomic_compare_exchange_weak_explicit(ptr, &cmp, v, {NAMESPACE}::memory_order_relaxed, {NAMESPACE}::memory_order_relaxed); | ||
return R{{cmp, exchanged}}; | ||
}} | ||
"# | ||
)?; | ||
|
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.
Please don't just write this definition into every shader whether it's needed or not. We should only generate this code if we actually use it.
You can easily determine whether the module needs this definition by checking whether PredeclaredType::AtomicCompareExchangeWeakResult
is present in module.special_types.predeclared_types
, since that will always be there, since the AtomicResult
expression uses 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.
Coolio, I didn't know that existed, I'll look into that once I get a chance!
write!(self.out, ", ")?; | ||
self.put_expression(value, context, true)?; | ||
write!(self.out, ", {NAMESPACE}::memory_order_relaxed)")?; | ||
fn get_msl_non_weak_exchange_name( |
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.
There's no reason this needs to be inlined here, where the details are a distraction.
#5383 already moves the function out of msl/mod.rs
. I think this PR should leave it where it landed.
Need this feature, any hope for this PR? |
Thanks for the reminder, I put it on my calendar, i'll take a crack at it again soon. |
Connections
Fixes wgpu/wgpu#5257 and wgpu/wgpu#4364
Description
Adds an implementation of
naga::Statement::Atomic {fun: naga::AtomicFunction::Exchange { compare: Some(expr) } }
to the msl-out backend.Testing
Passes tests given by
cargo xtask validate msl
in filenaga/tests/out/msl/atomicCompareExchange.msl
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.