Skip to content

Commit

Permalink
added memory barrier intrinsics to spirv-std
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-vernooij committed Oct 18, 2021
1 parent e2db97f commit 6101569
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions crates/spirv-std/src/arch/barrier.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::memory::{Scope, Semantics};

/// Wait for other invocations of this module to reach the current point
/// of execution.
///
Expand Down Expand Up @@ -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()
},
>();
}

0 comments on commit 6101569

Please sign in to comment.