Skip to content

Commit

Permalink
Add WGSL intrinsics for synchronization
Browse files Browse the repository at this point in the history
This closes issue #5085.
  • Loading branch information
aleino-nv committed Sep 19, 2024
1 parent 1781c29 commit e426f73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 12 additions & 6 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -5775,7 +5775,7 @@ bool all(matrix<T,N,M> x)

// Barrier for writes to all memory spaces (HLSL SM 5.0)
__glsl_extension(GL_KHR_memory_scope_semantics)
[require(cuda_glsl_hlsl_metal_spirv, memorybarrier)]
[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]
void AllMemoryBarrier()
{
__target_switch
Expand All @@ -5788,12 +5788,13 @@ void AllMemoryBarrier()
{
OpMemoryBarrier Device AcquireRelease|UniformMemory|WorkgroupMemory|ImageMemory;
};
case wgsl: __intrinsic_asm "storageBarrier(); textureBarrier(); workgroupBarrier();";
}
}

// Thread-group sync and barrier for writes to all memory spaces (HLSL SM 5.0)
__glsl_extension(GL_KHR_memory_scope_semantics)
[require(cuda_glsl_hlsl_metal_spirv, memorybarrier)]
[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]
void AllMemoryBarrierWithGroupSync()
{
__target_switch
Expand All @@ -5806,6 +5807,7 @@ void AllMemoryBarrierWithGroupSync()
{
OpControlBarrier Workgroup Device AcquireRelease|UniformMemory|WorkgroupMemory|ImageMemory;
};
case wgsl: __intrinsic_asm "storageBarrier(); textureBarrier(); workgroupBarrier();";
}
}

Expand Down Expand Up @@ -7540,7 +7542,7 @@ T determinant(matrix<T,N,N> m)

// Barrier for device memory
__glsl_extension(GL_KHR_memory_scope_semantics)
[require(cuda_glsl_hlsl_metal_spirv, memorybarrier)]
[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]
void DeviceMemoryBarrier()
{
__target_switch
Expand All @@ -7553,11 +7555,12 @@ void DeviceMemoryBarrier()
{
OpMemoryBarrier Device AcquireRelease|UniformMemory|ImageMemory;
};
case wgsl: __intrinsic_asm "storageBarrier(); textureBarrier(); workgroupBarrier();";
}
}

__glsl_extension(GL_KHR_memory_scope_semantics)
[require(cuda_glsl_hlsl_metal_spirv, memorybarrier)]
[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]
void DeviceMemoryBarrierWithGroupSync()
{
__target_switch
Expand All @@ -7570,6 +7573,7 @@ void DeviceMemoryBarrierWithGroupSync()
{
OpControlBarrier Workgroup Device AcquireRelease|UniformMemory|ImageMemory;
};
case wgsl: __intrinsic_asm "storageBarrier(); textureBarrier(); workgroupBarrier();";
}
}

Expand Down Expand Up @@ -8932,7 +8936,7 @@ float2 GetRenderTargetSamplePosition(int Index)

// Group memory barrier
__glsl_extension(GL_KHR_memory_scope_semantics)
[require(cuda_glsl_hlsl_metal_spirv, memorybarrier)]
[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]
void GroupMemoryBarrier()
{
__target_switch
Expand All @@ -8946,6 +8950,7 @@ void GroupMemoryBarrier()
{
OpMemoryBarrier Workgroup AcquireRelease|WorkgroupMemory
};
case wgsl: __intrinsic_asm "workgroupBarrier";
}
}

Expand All @@ -8967,7 +8972,7 @@ void __subgroupBarrier()
}

__glsl_extension(GL_KHR_memory_scope_semantics)
[require(cuda_glsl_hlsl_metal_spirv, memorybarrier)]
[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]
void GroupMemoryBarrierWithGroupSync()
{
__target_switch
Expand All @@ -8981,6 +8986,7 @@ void GroupMemoryBarrierWithGroupSync()
{
OpControlBarrier Workgroup Workgroup AcquireRelease|WorkgroupMemory
};
case wgsl: __intrinsic_asm "workgroupBarrier";
}
}

Expand Down
4 changes: 4 additions & 0 deletions source/slang/slang-capabilities.capdef
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ alias cuda_glsl_hlsl_spirv = cuda | glsl | hlsl | spirv;
/// [Compound]
alias cuda_glsl_hlsl_metal_spirv = cuda | glsl | hlsl | metal | spirv;

/// CUDA, GLSL, HLSL, Metal, SPIRV and WGSL code-gen targets
/// [Compound]
alias cuda_glsl_hlsl_metal_spirv_wgsl = cuda | glsl | hlsl | metal | spirv | wgsl;

/// CUDA, GLSL, and SPIRV code-gen targets
/// [Compound]
alias cuda_glsl_spirv = cuda | glsl | spirv;
Expand Down

0 comments on commit e426f73

Please sign in to comment.