Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WGSL intrinsics for synchronization #5114

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need workgroupBarrier here?

}
}

__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
Loading