mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-23 16:01:04 +01:00
[wgsl-in/spv-out] Add support for WGSL's atomicCompareExchangeWeak (#2165)
* Add support for WGSL's `atomicCompareExchangeWeak` with the `__atomic_compare_exchange_result` struct, and add SPIR-V codegen for it. Partially addresses https://github.com/gpuweb/gpuweb/pull/2113, #1755. * Add tests for `atomicCompareExchangeWeak`, and support both u32 and i32 atomics with it. * More thorough typechecking of the struct returned by `atomicCompareExchangeWeak`.
This commit is contained in:
1 parent
8f1d82f0d2
commit
5d8fc3fdcf
11 files changed
+472
-44
No files matched your search
+23
-6
@@ -2,6 +2,9 @@
|
||||
use crate::arena::{Arena, UniqueArena};
|
||||
use crate::arena::{BadHandle, Handle};
|
||||
|
||||
#[cfg(feature = "validate")]
|
||||
use super::validate_atomic_compare_exchange_struct;
|
||||
|
||||
use super::{
|
||||
analyzer::{UniformityDisruptor, UniformityRequirements},
|
||||
ExpressionError, FunctionInfo, ModuleInfo,
|
||||
@@ -363,12 +366,26 @@ impl super::Validator {
|
||||
.into_other());
|
||||
}
|
||||
match context.expressions[result] {
|
||||
//TODO: support atomic result with comparison
|
||||
crate::Expression::AtomicResult {
|
||||
kind,
|
||||
width,
|
||||
comparison: false,
|
||||
} if kind == ptr_kind && width == ptr_width => {}
|
||||
crate::Expression::AtomicResult { ty, comparison }
|
||||
if {
|
||||
let scalar_predicate = |ty: &crate::TypeInner| {
|
||||
*ty == crate::TypeInner::Scalar {
|
||||
kind: ptr_kind,
|
||||
width: ptr_width,
|
||||
}
|
||||
};
|
||||
match &context.types[ty].inner {
|
||||
ty if !comparison => scalar_predicate(ty),
|
||||
&crate::TypeInner::Struct { ref members, .. } if comparison => {
|
||||
validate_atomic_compare_exchange_struct(
|
||||
context.types,
|
||||
members,
|
||||
scalar_predicate,
|
||||
)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
} => {}
|
||||
_ => {
|
||||
return Err(AtomicError::ResultTypeMismatch(result)
|
||||
.with_span_handle(result, context.expressions)
|
||||
|
||||
Reference in new issue
Block a user