forked from gfx-rs/wgpu
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add 32-bit floating-point atomics
* Current supported platforms: Metal * Platforms to support in the future: Vulkan Related issues or PRs: * gfx-rs#1020
- Loading branch information
1 parent
9b36a3e
commit bc058fd
Showing
16 changed files
with
318 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
( | ||
god_mode: true, | ||
msl: ( | ||
lang_version: (3, 0), | ||
per_entry_point_map: {}, | ||
inline_samplers: [], | ||
spirv_cross_compatibility: false, | ||
fake_missing_bindings: true, | ||
zero_initialize_workgroup_memory: false, | ||
), | ||
) |
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,54 @@ | ||
struct Struct { | ||
atomic_scalar: atomic<f32>, | ||
atomic_arr: array<atomic<f32>, 2>, | ||
} | ||
|
||
@group(0) @binding(0) | ||
var<storage, read_write> storage_atomic_scalar: atomic<f32>; | ||
@group(0) @binding(1) | ||
var<storage, read_write> storage_atomic_arr: array<atomic<f32>, 2>; | ||
@group(0) @binding(2) | ||
var<storage, read_write> storage_struct: Struct; | ||
|
||
@compute | ||
@workgroup_size(2) | ||
fn cs_main(@builtin(local_invocation_id) id: vec3<u32>) { | ||
atomicStore(&storage_atomic_scalar, 1.0); | ||
atomicStore(&storage_atomic_arr[1], 1.0); | ||
atomicStore(&storage_struct.atomic_scalar, 1.0); | ||
atomicStore(&storage_struct.atomic_arr[1], 1.0); | ||
|
||
workgroupBarrier(); | ||
|
||
let l0 = atomicLoad(&storage_atomic_scalar); | ||
let l1 = atomicLoad(&storage_atomic_arr[1]); | ||
let l2 = atomicLoad(&storage_struct.atomic_scalar); | ||
let l3 = atomicLoad(&storage_struct.atomic_arr[1]); | ||
|
||
workgroupBarrier(); | ||
|
||
atomicAdd(&storage_atomic_scalar, 1.0); | ||
atomicAdd(&storage_atomic_arr[1], 1.0); | ||
atomicAdd(&storage_struct.atomic_scalar, 1.0); | ||
atomicAdd(&storage_struct.atomic_arr[1], 1.0); | ||
|
||
workgroupBarrier(); | ||
|
||
atomicSub(&storage_atomic_scalar, 1.0); | ||
atomicSub(&storage_atomic_arr[1], 1.0); | ||
atomicSub(&storage_struct.atomic_scalar, 1.0); | ||
atomicSub(&storage_struct.atomic_arr[1], 1.0); | ||
|
||
workgroupBarrier(); | ||
|
||
atomicExchange(&storage_atomic_scalar, 1.0); | ||
atomicExchange(&storage_atomic_arr[1], 1.0); | ||
atomicExchange(&storage_struct.atomic_scalar, 1.0); | ||
atomicExchange(&storage_struct.atomic_arr[1], 1.0); | ||
|
||
// // TODO: https://github.com/gpuweb/gpuweb/issues/2021 | ||
// atomicCompareExchangeWeak(&storage_atomic_scalar, 1.0); | ||
// atomicCompareExchangeWeak(&storage_atomic_arr[1], 1.0); | ||
// atomicCompareExchangeWeak(&storage_struct.atomic_scalar, 1.0); | ||
// atomicCompareExchangeWeak(&storage_struct.atomic_arr[1], 1.0); | ||
} |
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,48 @@ | ||
// language: metal3.0 | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using metal::uint; | ||
|
||
struct type_1 { | ||
metal::atomic_float inner[2]; | ||
}; | ||
struct Struct { | ||
metal::atomic_float atomic_scalar; | ||
type_1 atomic_arr; | ||
}; | ||
|
||
struct cs_mainInput { | ||
}; | ||
kernel void cs_main( | ||
metal::uint3 id [[thread_position_in_threadgroup]] | ||
, device metal::atomic_float& storage_atomic_scalar [[user(fake0)]] | ||
, device type_1& storage_atomic_arr [[user(fake0)]] | ||
, device Struct& storage_struct [[user(fake0)]] | ||
) { | ||
metal::atomic_store_explicit(&storage_atomic_scalar, 1.0, metal::memory_order_relaxed); | ||
metal::atomic_store_explicit(&storage_atomic_arr.inner[1], 1.0, metal::memory_order_relaxed); | ||
metal::atomic_store_explicit(&storage_struct.atomic_scalar, 1.0, metal::memory_order_relaxed); | ||
metal::atomic_store_explicit(&storage_struct.atomic_arr.inner[1], 1.0, metal::memory_order_relaxed); | ||
metal::threadgroup_barrier(metal::mem_flags::mem_threadgroup); | ||
float l0_ = metal::atomic_load_explicit(&storage_atomic_scalar, metal::memory_order_relaxed); | ||
float l1_ = metal::atomic_load_explicit(&storage_atomic_arr.inner[1], metal::memory_order_relaxed); | ||
float l2_ = metal::atomic_load_explicit(&storage_struct.atomic_scalar, metal::memory_order_relaxed); | ||
float l3_ = metal::atomic_load_explicit(&storage_struct.atomic_arr.inner[1], metal::memory_order_relaxed); | ||
metal::threadgroup_barrier(metal::mem_flags::mem_threadgroup); | ||
float _e27 = metal::atomic_fetch_add_explicit(&storage_atomic_scalar, 1.0, metal::memory_order_relaxed); | ||
float _e31 = metal::atomic_fetch_add_explicit(&storage_atomic_arr.inner[1], 1.0, metal::memory_order_relaxed); | ||
float _e35 = metal::atomic_fetch_add_explicit(&storage_struct.atomic_scalar, 1.0, metal::memory_order_relaxed); | ||
float _e40 = metal::atomic_fetch_add_explicit(&storage_struct.atomic_arr.inner[1], 1.0, metal::memory_order_relaxed); | ||
metal::threadgroup_barrier(metal::mem_flags::mem_threadgroup); | ||
float _e43 = metal::atomic_fetch_sub_explicit(&storage_atomic_scalar, 1.0, metal::memory_order_relaxed); | ||
float _e47 = metal::atomic_fetch_sub_explicit(&storage_atomic_arr.inner[1], 1.0, metal::memory_order_relaxed); | ||
float _e51 = metal::atomic_fetch_sub_explicit(&storage_struct.atomic_scalar, 1.0, metal::memory_order_relaxed); | ||
float _e56 = metal::atomic_fetch_sub_explicit(&storage_struct.atomic_arr.inner[1], 1.0, metal::memory_order_relaxed); | ||
metal::threadgroup_barrier(metal::mem_flags::mem_threadgroup); | ||
float _e59 = metal::atomic_exchange_explicit(&storage_atomic_scalar, 1.0, metal::memory_order_relaxed); | ||
float _e63 = metal::atomic_exchange_explicit(&storage_atomic_arr.inner[1], 1.0, metal::memory_order_relaxed); | ||
float _e67 = metal::atomic_exchange_explicit(&storage_struct.atomic_scalar, 1.0, metal::memory_order_relaxed); | ||
float _e72 = metal::atomic_exchange_explicit(&storage_struct.atomic_arr.inner[1], 1.0, metal::memory_order_relaxed); | ||
return; | ||
} |
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,40 @@ | ||
struct Struct { | ||
atomic_scalar: atomic<f32>, | ||
atomic_arr: array<atomic<f32>, 2>, | ||
} | ||
|
||
@group(0) @binding(0) | ||
var<storage, read_write> storage_atomic_scalar: atomic<f32>; | ||
@group(0) @binding(1) | ||
var<storage, read_write> storage_atomic_arr: array<atomic<f32>, 2>; | ||
@group(0) @binding(2) | ||
var<storage, read_write> storage_struct: Struct; | ||
|
||
@compute @workgroup_size(2, 1, 1) | ||
fn cs_main(@builtin(local_invocation_id) id: vec3<u32>) { | ||
atomicStore((&storage_atomic_scalar), 1f); | ||
atomicStore((&storage_atomic_arr[1]), 1f); | ||
atomicStore((&storage_struct.atomic_scalar), 1f); | ||
atomicStore((&storage_struct.atomic_arr[1]), 1f); | ||
workgroupBarrier(); | ||
let l0_ = atomicLoad((&storage_atomic_scalar)); | ||
let l1_ = atomicLoad((&storage_atomic_arr[1])); | ||
let l2_ = atomicLoad((&storage_struct.atomic_scalar)); | ||
let l3_ = atomicLoad((&storage_struct.atomic_arr[1])); | ||
workgroupBarrier(); | ||
let _e27 = atomicAdd((&storage_atomic_scalar), 1f); | ||
let _e31 = atomicAdd((&storage_atomic_arr[1]), 1f); | ||
let _e35 = atomicAdd((&storage_struct.atomic_scalar), 1f); | ||
let _e40 = atomicAdd((&storage_struct.atomic_arr[1]), 1f); | ||
workgroupBarrier(); | ||
let _e43 = atomicSub((&storage_atomic_scalar), 1f); | ||
let _e47 = atomicSub((&storage_atomic_arr[1]), 1f); | ||
let _e51 = atomicSub((&storage_struct.atomic_scalar), 1f); | ||
let _e56 = atomicSub((&storage_struct.atomic_arr[1]), 1f); | ||
workgroupBarrier(); | ||
let _e59 = atomicExchange((&storage_atomic_scalar), 1f); | ||
let _e63 = atomicExchange((&storage_atomic_arr[1]), 1f); | ||
let _e67 = atomicExchange((&storage_struct.atomic_scalar), 1f); | ||
let _e72 = atomicExchange((&storage_struct.atomic_arr[1]), 1f); | ||
return; | ||
} |
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
Oops, something went wrong.