From 6101569b808e1e72b3db1d216a70198890d675fb Mon Sep 17 00:00:00 2001 From: Hannes Vernooij Date: Mon, 18 Oct 2021 17:02:31 +0200 Subject: [PATCH 1/6] added memory barrier intrinsics to spirv-std --- crates/spirv-std/src/arch/barrier.rs | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/crates/spirv-std/src/arch/barrier.rs b/crates/spirv-std/src/arch/barrier.rs index 6420dc80f0..bbc25d6208 100644 --- a/crates/spirv-std/src/arch/barrier.rs +++ b/crates/spirv-std/src/arch/barrier.rs @@ -1,3 +1,5 @@ +use crate::memory::{Scope, Semantics}; + /// Wait for other invocations of this module to reach the current point /// of execution. /// @@ -78,3 +80,72 @@ pub unsafe fn memory_barrier< semantics = const SEMANTICS, } } + +pub unsafe fn workgroup_memory_barrier() { + // Exact implementation of GroupMemoryBarrier(); + memory_barrier::< + { Scope::Workgroup as u32 }, + { Semantics::WORKGROUP_MEMORY.bits() | Semantics::ACQUIRE_RELEASE.bits() }, + >(); +} + +pub unsafe fn workgroup_memory_barrier_with_group_sync() { + // Exact implementation of GroupMemoryBarrierWithGroupSync(); + control_barrier::< + { Scope::Workgroup as u32 }, + { Scope::Workgroup as u32 }, + { Semantics::WORKGROUP_MEMORY.bits() | Semantics::ACQUIRE_RELEASE.bits() }, + >(); +} + +pub unsafe fn device_memory_barrier() { + // Exact implementation of DeviceMemoryBarrier() + memory_barrier::< + { Scope::Device as u32 }, + { + Semantics::IMAGE_MEMORY.bits() + | Semantics::UNIFORM_MEMORY.bits() + | Semantics::ACQUIRE_RELEASE.bits() + }, + >(); +} + +pub unsafe fn device_memory_barrier_with_group_sync() { + // Exact implementation of DeviceMemoryBarrierWithGroupSync() + control_barrier::< + { Scope::Workgroup as u32 }, + { Scope::Device as u32 }, + { + Semantics::IMAGE_MEMORY.bits() + | Semantics::UNIFORM_MEMORY.bits() + | Semantics::ACQUIRE_RELEASE.bits() + }, + >(); +} + +pub unsafe fn all_memory_barrier() { + // Exact implementation of AllMemoryBarrier() + memory_barrier::< + { Scope::Device as u32 }, + { + Semantics::WORKGROUP_MEMORY.bits() + | Semantics::IMAGE_MEMORY.bits() + | Semantics::UNIFORM_MEMORY.bits() + | Semantics::ACQUIRE_RELEASE.bits() + }, + >(); +} + +pub unsafe fn all_memory_barrier_with_group_sync() { + // Exact implementation of AllMemoryBarrierWithGroupSync() + control_barrier::< + { Scope::Workgroup as u32 }, + { Scope::Device as u32 }, + { + Semantics::WORKGROUP_MEMORY.bits() + | Semantics::IMAGE_MEMORY.bits() + | Semantics::UNIFORM_MEMORY.bits() + | Semantics::ACQUIRE_RELEASE.bits() + }, + >(); +} From f7fd8d0530c872fe24948240f0e4702fdd93fbbf Mon Sep 17 00:00:00 2001 From: Hannes Vernooij Date: Mon, 18 Oct 2021 19:18:57 +0200 Subject: [PATCH 2/6] added function-level docs --- crates/spirv-std/src/arch/barrier.rs | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/spirv-std/src/arch/barrier.rs b/crates/spirv-std/src/arch/barrier.rs index bbc25d6208..7d16da6c87 100644 --- a/crates/spirv-std/src/arch/barrier.rs +++ b/crates/spirv-std/src/arch/barrier.rs @@ -81,16 +81,22 @@ pub unsafe fn memory_barrier< } } +/// An exact implementation of GroupMemoryBarrier(). +/// This blocks execution of all threads in a group until all group shared accesses have been completed. +/// +/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrier pub unsafe fn workgroup_memory_barrier() { - // Exact implementation of GroupMemoryBarrier(); memory_barrier::< { Scope::Workgroup as u32 }, { Semantics::WORKGROUP_MEMORY.bits() | Semantics::ACQUIRE_RELEASE.bits() }, >(); } +/// An exact implementation of GroupMemoryBarrierWithGroupSync(). +/// This blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call. +/// +/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrierwithgroupsync pub unsafe fn workgroup_memory_barrier_with_group_sync() { - // Exact implementation of GroupMemoryBarrierWithGroupSync(); control_barrier::< { Scope::Workgroup as u32 }, { Scope::Workgroup as u32 }, @@ -98,8 +104,11 @@ pub unsafe fn workgroup_memory_barrier_with_group_sync() { >(); } +/// An exact implementation of DeviceMemoryBarrier(). +/// This blocks execution of all threads in a group until all device memory accesses have been completed. +/// +/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/devicememorybarrier pub unsafe fn device_memory_barrier() { - // Exact implementation of DeviceMemoryBarrier() memory_barrier::< { Scope::Device as u32 }, { @@ -110,8 +119,11 @@ pub unsafe fn device_memory_barrier() { >(); } +/// An exact implementation of DeviceMemoryBarrierWithGroupSync(). +/// This blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call. +/// +/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/devicememorybarrierwithgroupsync pub unsafe fn device_memory_barrier_with_group_sync() { - // Exact implementation of DeviceMemoryBarrierWithGroupSync() control_barrier::< { Scope::Workgroup as u32 }, { Scope::Device as u32 }, @@ -123,8 +135,11 @@ pub unsafe fn device_memory_barrier_with_group_sync() { >(); } +/// An exact implementation of AllMemoryBarrier(). +/// This blocks execution of all threads in a group until all memory accesses have been completed. +/// +/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/allmemorybarrier pub unsafe fn all_memory_barrier() { - // Exact implementation of AllMemoryBarrier() memory_barrier::< { Scope::Device as u32 }, { @@ -136,8 +151,11 @@ pub unsafe fn all_memory_barrier() { >(); } +/// An exact implementation of AllMemoryBarrierWithGroupSync(). +/// This blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call. +/// +/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/allmemorybarrierwithgroupsync pub unsafe fn all_memory_barrier_with_group_sync() { - // Exact implementation of AllMemoryBarrierWithGroupSync() control_barrier::< { Scope::Workgroup as u32 }, { Scope::Device as u32 }, From 55614c471e4be817c29407d4b2d80c55da293268 Mon Sep 17 00:00:00 2001 From: Hannes Vernooij Date: Tue, 19 Oct 2021 11:52:19 +0200 Subject: [PATCH 3/6] added unit-tests constants could not be validated in tests because of the limited output --- crates/spirv-std/src/arch/barrier.rs | 6 ++++++ tests/ui/arch/all_memory_barrier.rs | 15 +++++++++++++++ tests/ui/arch/all_memory_barrier.stderr | 7 +++++++ .../ui/arch/all_memory_barrier_with_group_sync.rs | 15 +++++++++++++++ .../all_memory_barrier_with_group_sync.stderr | 7 +++++++ tests/ui/arch/device_memory_barrier.rs | 15 +++++++++++++++ tests/ui/arch/device_memory_barrier.stderr | 7 +++++++ .../arch/device_memory_barrier_with_group_sync.rs | 15 +++++++++++++++ .../device_memory_barrier_with_group_sync.stderr | 7 +++++++ tests/ui/arch/workgroup_memory_barrier.rs | 15 +++++++++++++++ tests/ui/arch/workgroup_memory_barrier.stderr | 7 +++++++ .../workgroup_memory_barrier_with_group_sync.rs | 15 +++++++++++++++ ...orkgroup_memory_barrier_with_group_sync.stderr | 7 +++++++ 13 files changed, 138 insertions(+) create mode 100644 tests/ui/arch/all_memory_barrier.rs create mode 100644 tests/ui/arch/all_memory_barrier.stderr create mode 100644 tests/ui/arch/all_memory_barrier_with_group_sync.rs create mode 100644 tests/ui/arch/all_memory_barrier_with_group_sync.stderr create mode 100644 tests/ui/arch/device_memory_barrier.rs create mode 100644 tests/ui/arch/device_memory_barrier.stderr create mode 100644 tests/ui/arch/device_memory_barrier_with_group_sync.rs create mode 100644 tests/ui/arch/device_memory_barrier_with_group_sync.stderr create mode 100644 tests/ui/arch/workgroup_memory_barrier.rs create mode 100644 tests/ui/arch/workgroup_memory_barrier.stderr create mode 100644 tests/ui/arch/workgroup_memory_barrier_with_group_sync.rs create mode 100644 tests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr diff --git a/crates/spirv-std/src/arch/barrier.rs b/crates/spirv-std/src/arch/barrier.rs index 7d16da6c87..fe87b2059b 100644 --- a/crates/spirv-std/src/arch/barrier.rs +++ b/crates/spirv-std/src/arch/barrier.rs @@ -85,6 +85,7 @@ pub unsafe fn memory_barrier< /// This blocks execution of all threads in a group until all group shared accesses have been completed. /// /// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrier +#[inline] pub unsafe fn workgroup_memory_barrier() { memory_barrier::< { Scope::Workgroup as u32 }, @@ -96,6 +97,7 @@ pub unsafe fn workgroup_memory_barrier() { /// This blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call. /// /// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrierwithgroupsync +#[inline] pub unsafe fn workgroup_memory_barrier_with_group_sync() { control_barrier::< { Scope::Workgroup as u32 }, @@ -108,6 +110,7 @@ pub unsafe fn workgroup_memory_barrier_with_group_sync() { /// This blocks execution of all threads in a group until all device memory accesses have been completed. /// /// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/devicememorybarrier +#[inline] pub unsafe fn device_memory_barrier() { memory_barrier::< { Scope::Device as u32 }, @@ -123,6 +126,7 @@ pub unsafe fn device_memory_barrier() { /// This blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call. /// /// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/devicememorybarrierwithgroupsync +#[inline] pub unsafe fn device_memory_barrier_with_group_sync() { control_barrier::< { Scope::Workgroup as u32 }, @@ -139,6 +143,7 @@ pub unsafe fn device_memory_barrier_with_group_sync() { /// This blocks execution of all threads in a group until all memory accesses have been completed. /// /// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/allmemorybarrier +#[inline] pub unsafe fn all_memory_barrier() { memory_barrier::< { Scope::Device as u32 }, @@ -155,6 +160,7 @@ pub unsafe fn all_memory_barrier() { /// This blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call. /// /// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/allmemorybarrierwithgroupsync +#[inline] pub unsafe fn all_memory_barrier_with_group_sync() { control_barrier::< { Scope::Workgroup as u32 }, diff --git a/tests/ui/arch/all_memory_barrier.rs b/tests/ui/arch/all_memory_barrier.rs new file mode 100644 index 0000000000..666bfc1ef1 --- /dev/null +++ b/tests/ui/arch/all_memory_barrier.rs @@ -0,0 +1,15 @@ +// build-pass +// compile-flags: -C llvm-args=--disassemble-fn=all_memory_barrier::all_memory_barrier + +use spirv_std as _; + +unsafe fn all_memory_barrier() { + spirv_std::arch::all_memory_barrier(); +} + +#[spirv(compute(threads(1, 1, 1)))] +pub fn main() { + unsafe { + all_memory_barrier(); + } +} diff --git a/tests/ui/arch/all_memory_barrier.stderr b/tests/ui/arch/all_memory_barrier.stderr new file mode 100644 index 0000000000..7a02a9c320 --- /dev/null +++ b/tests/ui/arch/all_memory_barrier.stderr @@ -0,0 +1,7 @@ +%1 = OpFunction %2 None %3 +%4 = OpLabel +OpLine %5 74 4 +OpMemoryBarrier %6 %7 +OpLine %8 8 1 +OpReturn +OpFunctionEnd diff --git a/tests/ui/arch/all_memory_barrier_with_group_sync.rs b/tests/ui/arch/all_memory_barrier_with_group_sync.rs new file mode 100644 index 0000000000..cb315e0613 --- /dev/null +++ b/tests/ui/arch/all_memory_barrier_with_group_sync.rs @@ -0,0 +1,15 @@ +// build-pass +// compile-flags: -C llvm-args=--disassemble-fn=all_memory_barrier_with_group_sync::all_memory_barrier_with_group_sync + +use spirv_std as _; + +unsafe fn all_memory_barrier_with_group_sync() { + spirv_std::arch::all_memory_barrier_with_group_sync(); +} + +#[spirv(compute(threads(1, 1, 1)))] +pub fn main() { + unsafe { + all_memory_barrier_with_group_sync(); + } +} diff --git a/tests/ui/arch/all_memory_barrier_with_group_sync.stderr b/tests/ui/arch/all_memory_barrier_with_group_sync.stderr new file mode 100644 index 0000000000..10f280d253 --- /dev/null +++ b/tests/ui/arch/all_memory_barrier_with_group_sync.stderr @@ -0,0 +1,7 @@ +%1 = OpFunction %2 None %3 +%4 = OpLabel +OpLine %5 40 4 +OpControlBarrier %6 %7 %8 +OpLine %9 8 1 +OpReturn +OpFunctionEnd diff --git a/tests/ui/arch/device_memory_barrier.rs b/tests/ui/arch/device_memory_barrier.rs new file mode 100644 index 0000000000..03a334cd64 --- /dev/null +++ b/tests/ui/arch/device_memory_barrier.rs @@ -0,0 +1,15 @@ +// build-pass +// compile-flags: -C llvm-args=--disassemble-fn=device_memory_barrier::device_memory_barrier + +use spirv_std as _; + +unsafe fn device_memory_barrier() { + spirv_std::arch::device_memory_barrier(); +} + +#[spirv(compute(threads(1, 1, 1)))] +pub fn main() { + unsafe { + device_memory_barrier(); + } +} diff --git a/tests/ui/arch/device_memory_barrier.stderr b/tests/ui/arch/device_memory_barrier.stderr new file mode 100644 index 0000000000..7a02a9c320 --- /dev/null +++ b/tests/ui/arch/device_memory_barrier.stderr @@ -0,0 +1,7 @@ +%1 = OpFunction %2 None %3 +%4 = OpLabel +OpLine %5 74 4 +OpMemoryBarrier %6 %7 +OpLine %8 8 1 +OpReturn +OpFunctionEnd diff --git a/tests/ui/arch/device_memory_barrier_with_group_sync.rs b/tests/ui/arch/device_memory_barrier_with_group_sync.rs new file mode 100644 index 0000000000..4174563e4d --- /dev/null +++ b/tests/ui/arch/device_memory_barrier_with_group_sync.rs @@ -0,0 +1,15 @@ +// build-pass +// compile-flags: -C llvm-args=--disassemble-fn=device_memory_barrier_with_group_sync::device_memory_barrier_with_group_sync + +use spirv_std as _; + +unsafe fn device_memory_barrier_with_group_sync() { + spirv_std::arch::device_memory_barrier_with_group_sync(); +} + +#[spirv(compute(threads(1, 1, 1)))] +pub fn main() { + unsafe { + device_memory_barrier_with_group_sync(); + } +} diff --git a/tests/ui/arch/device_memory_barrier_with_group_sync.stderr b/tests/ui/arch/device_memory_barrier_with_group_sync.stderr new file mode 100644 index 0000000000..10f280d253 --- /dev/null +++ b/tests/ui/arch/device_memory_barrier_with_group_sync.stderr @@ -0,0 +1,7 @@ +%1 = OpFunction %2 None %3 +%4 = OpLabel +OpLine %5 40 4 +OpControlBarrier %6 %7 %8 +OpLine %9 8 1 +OpReturn +OpFunctionEnd diff --git a/tests/ui/arch/workgroup_memory_barrier.rs b/tests/ui/arch/workgroup_memory_barrier.rs new file mode 100644 index 0000000000..13216ab093 --- /dev/null +++ b/tests/ui/arch/workgroup_memory_barrier.rs @@ -0,0 +1,15 @@ +// build-pass +// compile-flags: -C llvm-args=--disassemble-fn=workgroup_memory_barrier::workgroup_memory_barrier + +use spirv_std as _; + +unsafe fn workgroup_memory_barrier() { + spirv_std::arch::workgroup_memory_barrier(); +} + +#[spirv(compute(threads(1, 1, 1)))] +pub fn main() { + unsafe { + workgroup_memory_barrier(); + } +} diff --git a/tests/ui/arch/workgroup_memory_barrier.stderr b/tests/ui/arch/workgroup_memory_barrier.stderr new file mode 100644 index 0000000000..7a02a9c320 --- /dev/null +++ b/tests/ui/arch/workgroup_memory_barrier.stderr @@ -0,0 +1,7 @@ +%1 = OpFunction %2 None %3 +%4 = OpLabel +OpLine %5 74 4 +OpMemoryBarrier %6 %7 +OpLine %8 8 1 +OpReturn +OpFunctionEnd diff --git a/tests/ui/arch/workgroup_memory_barrier_with_group_sync.rs b/tests/ui/arch/workgroup_memory_barrier_with_group_sync.rs new file mode 100644 index 0000000000..0e16fbd8bc --- /dev/null +++ b/tests/ui/arch/workgroup_memory_barrier_with_group_sync.rs @@ -0,0 +1,15 @@ +// build-pass +// compile-flags: -C llvm-args=--disassemble-fn=workgroup_memory_barrier_with_group_sync::workgroup_memory_barrier_with_group_sync + +use spirv_std as _; + +unsafe fn workgroup_memory_barrier_with_group_sync() { + spirv_std::arch::workgroup_memory_barrier_with_group_sync(); +} + +#[spirv(compute(threads(1, 1, 1)))] +pub fn main() { + unsafe { + workgroup_memory_barrier_with_group_sync(); + } +} diff --git a/tests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr b/tests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr new file mode 100644 index 0000000000..bbb36ebad7 --- /dev/null +++ b/tests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr @@ -0,0 +1,7 @@ +%1 = OpFunction %2 None %3 +%4 = OpLabel +OpLine %5 40 4 +OpControlBarrier %6 %6 %7 +OpLine %8 8 1 +OpReturn +OpFunctionEnd From 5bf768341912bc8f5b9d6cf67d2f172d76537b48 Mon Sep 17 00:00:00 2001 From: Hannes Vernooij Date: Wed, 20 Oct 2021 10:52:07 +0200 Subject: [PATCH 4/6] clippy fixes --- crates/spirv-std/src/arch/barrier.rs | 88 +++++++++++-------- tests/ui/arch/all_memory_barrier.stderr | 2 +- .../all_memory_barrier_with_group_sync.stderr | 2 +- tests/ui/arch/device_memory_barrier.stderr | 2 +- ...vice_memory_barrier_with_group_sync.stderr | 2 +- tests/ui/arch/workgroup_memory_barrier.stderr | 2 +- ...roup_memory_barrier_with_group_sync.stderr | 2 +- 7 files changed, 55 insertions(+), 45 deletions(-) diff --git a/crates/spirv-std/src/arch/barrier.rs b/crates/spirv-std/src/arch/barrier.rs index fe87b2059b..ce89a47cf9 100644 --- a/crates/spirv-std/src/arch/barrier.rs +++ b/crates/spirv-std/src/arch/barrier.rs @@ -1,5 +1,3 @@ -use crate::memory::{Scope, Semantics}; - /// Wait for other invocations of this module to reach the current point /// of execution. /// @@ -81,95 +79,107 @@ pub unsafe fn memory_barrier< } } -/// An exact implementation of GroupMemoryBarrier(). +/// An exact implementation of `GroupMemoryBarrier()`. /// This blocks execution of all threads in a group until all group shared accesses have been completed. /// -/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrier +/// From +#[spirv_std_macros::gpu_only] #[inline] pub unsafe fn workgroup_memory_barrier() { memory_barrier::< - { Scope::Workgroup as u32 }, - { Semantics::WORKGROUP_MEMORY.bits() | Semantics::ACQUIRE_RELEASE.bits() }, + { crate::memory::Scope::Workgroup as u32 }, + { + crate::memory::Semantics::WORKGROUP_MEMORY.bits() + | crate::memory::Semantics::ACQUIRE_RELEASE.bits() + }, >(); } -/// An exact implementation of GroupMemoryBarrierWithGroupSync(). +/// An exact implementation of `GroupMemoryBarrierWithGroupSync()`. /// This blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call. /// -/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrierwithgroupsync +/// From +#[spirv_std_macros::gpu_only] #[inline] pub unsafe fn workgroup_memory_barrier_with_group_sync() { control_barrier::< - { Scope::Workgroup as u32 }, - { Scope::Workgroup as u32 }, - { Semantics::WORKGROUP_MEMORY.bits() | Semantics::ACQUIRE_RELEASE.bits() }, + { crate::memory::Scope::Workgroup as u32 }, + { crate::memory::Scope::Workgroup as u32 }, + { + crate::memory::Semantics::WORKGROUP_MEMORY.bits() + | crate::memory::Semantics::ACQUIRE_RELEASE.bits() + }, >(); } -/// An exact implementation of DeviceMemoryBarrier(). +/// An exact implementation of `DeviceMemoryBarrier()`. /// This blocks execution of all threads in a group until all device memory accesses have been completed. /// -/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/devicememorybarrier +/// From +#[spirv_std_macros::gpu_only] #[inline] pub unsafe fn device_memory_barrier() { memory_barrier::< - { Scope::Device as u32 }, + { crate::memory::Scope::Device as u32 }, { - Semantics::IMAGE_MEMORY.bits() - | Semantics::UNIFORM_MEMORY.bits() - | Semantics::ACQUIRE_RELEASE.bits() + crate::memory::Semantics::IMAGE_MEMORY.bits() + | crate::memory::Semantics::UNIFORM_MEMORY.bits() + | crate::memory::Semantics::ACQUIRE_RELEASE.bits() }, >(); } -/// An exact implementation of DeviceMemoryBarrierWithGroupSync(). +/// An exact implementation of `DeviceMemoryBarrierWithGroupSync()`. /// This blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call. /// -/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/devicememorybarrierwithgroupsync +/// From +#[spirv_std_macros::gpu_only] #[inline] pub unsafe fn device_memory_barrier_with_group_sync() { control_barrier::< - { Scope::Workgroup as u32 }, - { Scope::Device as u32 }, + { crate::memory::Scope::Workgroup as u32 }, + { crate::memory::Scope::Device as u32 }, { - Semantics::IMAGE_MEMORY.bits() - | Semantics::UNIFORM_MEMORY.bits() - | Semantics::ACQUIRE_RELEASE.bits() + crate::memory::Semantics::IMAGE_MEMORY.bits() + | crate::memory::Semantics::UNIFORM_MEMORY.bits() + | crate::memory::Semantics::ACQUIRE_RELEASE.bits() }, >(); } -/// An exact implementation of AllMemoryBarrier(). +/// An exact implementation of `AllMemoryBarrier()`. /// This blocks execution of all threads in a group until all memory accesses have been completed. /// -/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/allmemorybarrier +/// From +#[spirv_std_macros::gpu_only] #[inline] pub unsafe fn all_memory_barrier() { memory_barrier::< - { Scope::Device as u32 }, + { crate::memory::Scope::Device as u32 }, { - Semantics::WORKGROUP_MEMORY.bits() - | Semantics::IMAGE_MEMORY.bits() - | Semantics::UNIFORM_MEMORY.bits() - | Semantics::ACQUIRE_RELEASE.bits() + crate::memory::Semantics::WORKGROUP_MEMORY.bits() + | crate::memory::Semantics::IMAGE_MEMORY.bits() + | crate::memory::Semantics::UNIFORM_MEMORY.bits() + | crate::memory::Semantics::ACQUIRE_RELEASE.bits() }, >(); } -/// An exact implementation of AllMemoryBarrierWithGroupSync(). +/// An exact implementation of `AllMemoryBarrierWithGroupSync()`. /// This blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call. /// -/// From https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/allmemorybarrierwithgroupsync +/// From +#[spirv_std_macros::gpu_only] #[inline] pub unsafe fn all_memory_barrier_with_group_sync() { control_barrier::< - { Scope::Workgroup as u32 }, - { Scope::Device as u32 }, + { crate::memory::Scope::Workgroup as u32 }, + { crate::memory::Scope::Device as u32 }, { - Semantics::WORKGROUP_MEMORY.bits() - | Semantics::IMAGE_MEMORY.bits() - | Semantics::UNIFORM_MEMORY.bits() - | Semantics::ACQUIRE_RELEASE.bits() + crate::memory::Semantics::WORKGROUP_MEMORY.bits() + | crate::memory::Semantics::IMAGE_MEMORY.bits() + | crate::memory::Semantics::UNIFORM_MEMORY.bits() + | crate::memory::Semantics::ACQUIRE_RELEASE.bits() }, >(); } diff --git a/tests/ui/arch/all_memory_barrier.stderr b/tests/ui/arch/all_memory_barrier.stderr index 7a02a9c320..6dc7539441 100644 --- a/tests/ui/arch/all_memory_barrier.stderr +++ b/tests/ui/arch/all_memory_barrier.stderr @@ -1,6 +1,6 @@ %1 = OpFunction %2 None %3 %4 = OpLabel -OpLine %5 74 4 +OpLine %5 72 4 OpMemoryBarrier %6 %7 OpLine %8 8 1 OpReturn diff --git a/tests/ui/arch/all_memory_barrier_with_group_sync.stderr b/tests/ui/arch/all_memory_barrier_with_group_sync.stderr index 10f280d253..72aa519ddb 100644 --- a/tests/ui/arch/all_memory_barrier_with_group_sync.stderr +++ b/tests/ui/arch/all_memory_barrier_with_group_sync.stderr @@ -1,6 +1,6 @@ %1 = OpFunction %2 None %3 %4 = OpLabel -OpLine %5 40 4 +OpLine %5 38 4 OpControlBarrier %6 %7 %8 OpLine %9 8 1 OpReturn diff --git a/tests/ui/arch/device_memory_barrier.stderr b/tests/ui/arch/device_memory_barrier.stderr index 7a02a9c320..6dc7539441 100644 --- a/tests/ui/arch/device_memory_barrier.stderr +++ b/tests/ui/arch/device_memory_barrier.stderr @@ -1,6 +1,6 @@ %1 = OpFunction %2 None %3 %4 = OpLabel -OpLine %5 74 4 +OpLine %5 72 4 OpMemoryBarrier %6 %7 OpLine %8 8 1 OpReturn diff --git a/tests/ui/arch/device_memory_barrier_with_group_sync.stderr b/tests/ui/arch/device_memory_barrier_with_group_sync.stderr index 10f280d253..72aa519ddb 100644 --- a/tests/ui/arch/device_memory_barrier_with_group_sync.stderr +++ b/tests/ui/arch/device_memory_barrier_with_group_sync.stderr @@ -1,6 +1,6 @@ %1 = OpFunction %2 None %3 %4 = OpLabel -OpLine %5 40 4 +OpLine %5 38 4 OpControlBarrier %6 %7 %8 OpLine %9 8 1 OpReturn diff --git a/tests/ui/arch/workgroup_memory_barrier.stderr b/tests/ui/arch/workgroup_memory_barrier.stderr index 7a02a9c320..6dc7539441 100644 --- a/tests/ui/arch/workgroup_memory_barrier.stderr +++ b/tests/ui/arch/workgroup_memory_barrier.stderr @@ -1,6 +1,6 @@ %1 = OpFunction %2 None %3 %4 = OpLabel -OpLine %5 74 4 +OpLine %5 72 4 OpMemoryBarrier %6 %7 OpLine %8 8 1 OpReturn diff --git a/tests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr b/tests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr index bbb36ebad7..d3fa886ff8 100644 --- a/tests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr +++ b/tests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr @@ -1,6 +1,6 @@ %1 = OpFunction %2 None %3 %4 = OpLabel -OpLine %5 40 4 +OpLine %5 38 4 OpControlBarrier %6 %6 %7 OpLine %8 8 1 OpReturn From 3fbff93077f372b7da0dfc358331a1c3261f4738 Mon Sep 17 00:00:00 2001 From: Hannes Vernooij Date: Thu, 21 Oct 2021 10:55:56 +0200 Subject: [PATCH 5/6] improved documentation --- crates/spirv-std/src/arch/barrier.rs | 30 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/crates/spirv-std/src/arch/barrier.rs b/crates/spirv-std/src/arch/barrier.rs index ce89a47cf9..19b8fc1bf8 100644 --- a/crates/spirv-std/src/arch/barrier.rs +++ b/crates/spirv-std/src/arch/barrier.rs @@ -79,8 +79,9 @@ pub unsafe fn memory_barrier< } } -/// An exact implementation of `GroupMemoryBarrier()`. -/// This blocks execution of all threads in a group until all group shared accesses have been completed. +/// Blocks execution of all threads in a group until all group shared accesses have been completed. +/// +/// This is an exact implementation of `GroupMemoryBarrier()`. /// /// From #[spirv_std_macros::gpu_only] @@ -95,8 +96,9 @@ pub unsafe fn workgroup_memory_barrier() { >(); } -/// An exact implementation of `GroupMemoryBarrierWithGroupSync()`. -/// This blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call. +/// Blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call. +/// +/// This is an exact implementation of `GroupMemoryBarrierWithGroupSync()`. /// /// From #[spirv_std_macros::gpu_only] @@ -112,8 +114,9 @@ pub unsafe fn workgroup_memory_barrier_with_group_sync() { >(); } -/// An exact implementation of `DeviceMemoryBarrier()`. -/// This blocks execution of all threads in a group until all device memory accesses have been completed. +/// Blocks execution of all threads in a group until all device memory accesses have been completed. +/// +/// This is an exact implementation of `DeviceMemoryBarrier()`. /// /// From #[spirv_std_macros::gpu_only] @@ -129,8 +132,9 @@ pub unsafe fn device_memory_barrier() { >(); } -/// An exact implementation of `DeviceMemoryBarrierWithGroupSync()`. -/// This blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call. +/// Blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call. +/// +/// This is an exact implementation of `DeviceMemoryBarrierWithGroupSync()`. /// /// From #[spirv_std_macros::gpu_only] @@ -147,8 +151,9 @@ pub unsafe fn device_memory_barrier_with_group_sync() { >(); } -/// An exact implementation of `AllMemoryBarrier()`. -/// This blocks execution of all threads in a group until all memory accesses have been completed. +/// Blocks execution of all threads in a group until all memory accesses have been completed. +/// +/// This is an exact implementation of `AllMemoryBarrier()`. /// /// From #[spirv_std_macros::gpu_only] @@ -165,8 +170,9 @@ pub unsafe fn all_memory_barrier() { >(); } -/// An exact implementation of `AllMemoryBarrierWithGroupSync()`. -/// This blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call. +/// Blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call. +/// +/// This is an exact implementation of `AllMemoryBarrierWithGroupSync()`. /// /// From #[spirv_std_macros::gpu_only] From 2699d0a785d804def8d5f3903c763a041ac93d4d Mon Sep 17 00:00:00 2001 From: Hannes Vernooij Date: Thu, 21 Oct 2021 14:27:18 +0200 Subject: [PATCH 6/6] Added missing features to device_memory and all_memory barrier intrinsics. --- tests/ui/arch/all_memory_barrier.rs | 1 + tests/ui/arch/all_memory_barrier.stderr | 2 +- tests/ui/arch/all_memory_barrier_with_group_sync.rs | 1 + tests/ui/arch/all_memory_barrier_with_group_sync.stderr | 2 +- tests/ui/arch/device_memory_barrier.rs | 1 + tests/ui/arch/device_memory_barrier.stderr | 2 +- tests/ui/arch/device_memory_barrier_with_group_sync.rs | 1 + tests/ui/arch/device_memory_barrier_with_group_sync.stderr | 2 +- 8 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/ui/arch/all_memory_barrier.rs b/tests/ui/arch/all_memory_barrier.rs index 666bfc1ef1..95f00ed306 100644 --- a/tests/ui/arch/all_memory_barrier.rs +++ b/tests/ui/arch/all_memory_barrier.rs @@ -1,4 +1,5 @@ // build-pass +// compile-flags: -C target-feature=+VulkanMemoryModelDeviceScopeKHR,+ext:SPV_KHR_vulkan_memory_model // compile-flags: -C llvm-args=--disassemble-fn=all_memory_barrier::all_memory_barrier use spirv_std as _; diff --git a/tests/ui/arch/all_memory_barrier.stderr b/tests/ui/arch/all_memory_barrier.stderr index 6dc7539441..6c47c8a8ff 100644 --- a/tests/ui/arch/all_memory_barrier.stderr +++ b/tests/ui/arch/all_memory_barrier.stderr @@ -2,6 +2,6 @@ %4 = OpLabel OpLine %5 72 4 OpMemoryBarrier %6 %7 -OpLine %8 8 1 +OpLine %8 9 1 OpReturn OpFunctionEnd diff --git a/tests/ui/arch/all_memory_barrier_with_group_sync.rs b/tests/ui/arch/all_memory_barrier_with_group_sync.rs index cb315e0613..ba05ad8ee6 100644 --- a/tests/ui/arch/all_memory_barrier_with_group_sync.rs +++ b/tests/ui/arch/all_memory_barrier_with_group_sync.rs @@ -1,4 +1,5 @@ // build-pass +// compile-flags: -C target-feature=+VulkanMemoryModelDeviceScopeKHR,+ext:SPV_KHR_vulkan_memory_model // compile-flags: -C llvm-args=--disassemble-fn=all_memory_barrier_with_group_sync::all_memory_barrier_with_group_sync use spirv_std as _; diff --git a/tests/ui/arch/all_memory_barrier_with_group_sync.stderr b/tests/ui/arch/all_memory_barrier_with_group_sync.stderr index 72aa519ddb..5661430745 100644 --- a/tests/ui/arch/all_memory_barrier_with_group_sync.stderr +++ b/tests/ui/arch/all_memory_barrier_with_group_sync.stderr @@ -2,6 +2,6 @@ %4 = OpLabel OpLine %5 38 4 OpControlBarrier %6 %7 %8 -OpLine %9 8 1 +OpLine %9 9 1 OpReturn OpFunctionEnd diff --git a/tests/ui/arch/device_memory_barrier.rs b/tests/ui/arch/device_memory_barrier.rs index 03a334cd64..0ffe4cfb29 100644 --- a/tests/ui/arch/device_memory_barrier.rs +++ b/tests/ui/arch/device_memory_barrier.rs @@ -1,4 +1,5 @@ // build-pass +// compile-flags: -C target-feature=+VulkanMemoryModelDeviceScopeKHR,+ext:SPV_KHR_vulkan_memory_model // compile-flags: -C llvm-args=--disassemble-fn=device_memory_barrier::device_memory_barrier use spirv_std as _; diff --git a/tests/ui/arch/device_memory_barrier.stderr b/tests/ui/arch/device_memory_barrier.stderr index 6dc7539441..6c47c8a8ff 100644 --- a/tests/ui/arch/device_memory_barrier.stderr +++ b/tests/ui/arch/device_memory_barrier.stderr @@ -2,6 +2,6 @@ %4 = OpLabel OpLine %5 72 4 OpMemoryBarrier %6 %7 -OpLine %8 8 1 +OpLine %8 9 1 OpReturn OpFunctionEnd diff --git a/tests/ui/arch/device_memory_barrier_with_group_sync.rs b/tests/ui/arch/device_memory_barrier_with_group_sync.rs index 4174563e4d..cc17b78937 100644 --- a/tests/ui/arch/device_memory_barrier_with_group_sync.rs +++ b/tests/ui/arch/device_memory_barrier_with_group_sync.rs @@ -1,4 +1,5 @@ // build-pass +// compile-flags: -C target-feature=+VulkanMemoryModelDeviceScopeKHR,+ext:SPV_KHR_vulkan_memory_model // compile-flags: -C llvm-args=--disassemble-fn=device_memory_barrier_with_group_sync::device_memory_barrier_with_group_sync use spirv_std as _; diff --git a/tests/ui/arch/device_memory_barrier_with_group_sync.stderr b/tests/ui/arch/device_memory_barrier_with_group_sync.stderr index 72aa519ddb..5661430745 100644 --- a/tests/ui/arch/device_memory_barrier_with_group_sync.stderr +++ b/tests/ui/arch/device_memory_barrier_with_group_sync.stderr @@ -2,6 +2,6 @@ %4 = OpLabel OpLine %5 38 4 OpControlBarrier %6 %7 %8 -OpLine %9 8 1 +OpLine %9 9 1 OpReturn OpFunctionEnd