-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 gpuweb/gpuweb#2113, #1755. * Add tests for `atomicCompareExchangeWeak`, and support both u32 and i32 atomics with it. * More thorough typechecking of the struct returned by `atomicCompareExchangeWeak`.
- Loading branch information
1 parent
8f1d82f
commit 5d8fc3f
Showing
11 changed files
with
472 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
let SIZE: u32 = 128u; | ||
|
||
@group(0) @binding(0) | ||
var<storage,read_write> arr_i32: array<atomic<i32>, SIZE>; | ||
@group(0) @binding(1) | ||
var<storage,read_write> arr_u32: array<atomic<u32>, SIZE>; | ||
|
||
@compute @workgroup_size(1) | ||
fn test_atomic_compare_exchange_i32() { | ||
for(var i = 0u; i < SIZE; i++) { | ||
var old = atomicLoad(&arr_i32[i]); | ||
var exchanged = false; | ||
while(!exchanged) { | ||
let new_ = bitcast<i32>(bitcast<f32>(old) + 1.0); | ||
let result = atomicCompareExchangeWeak(&arr_i32[i], old, new_); | ||
old = result.old_value; | ||
exchanged = result.exchanged; | ||
} | ||
} | ||
} | ||
|
||
@compute @workgroup_size(1) | ||
fn test_atomic_compare_exchange_u32() { | ||
for(var i = 0u; i < SIZE; i++) { | ||
var old = atomicLoad(&arr_u32[i]); | ||
var exchanged = false; | ||
while(!exchanged) { | ||
let new_ = bitcast<u32>(bitcast<f32>(old) + 1.0); | ||
let result = atomicCompareExchangeWeak(&arr_u32[i], old, new_); | ||
old = result.old_value; | ||
exchanged = result.exchanged; | ||
} | ||
} | ||
} |
Oops, something went wrong.