Skip to content

Commit 465bd12

Browse files
authored
Handles SpirvIntrinsicInstruction barriers in CapabilityVisitor. (microsoft#7711)
Fixes microsoft#7671.
1 parent 717e014 commit 465bd12

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

tools/clang/lib/SPIRV/CapabilityVisitor.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,13 @@ bool CapabilityVisitor::visitInstruction(SpirvInstruction *instr) {
615615
}
616616
case spv::Op::OpControlBarrier:
617617
case spv::Op::OpMemoryBarrier: {
618-
auto barrier = cast<SpirvBarrier>(instr);
619-
if ((bool)(barrier->getMemorySemantics() &
620-
spv::MemorySemanticsMask::OutputMemoryKHR)) {
618+
auto barrier = dyn_cast<SpirvBarrier>(instr);
619+
// barrier will be null if the instruction was generated from inline spir-v.
620+
// In that case, it is the user's responsibility to ensure the correct
621+
// capabilities are added.
622+
if (barrier && (barrier->getMemorySemantics() &
623+
spv::MemorySemanticsMask::OutputMemoryKHR) ==
624+
spv::MemorySemanticsMask::OutputMemoryKHR) {
621625
featureManager.requestTargetEnv(SPV_ENV_VULKAN_1_3, "NODE_OUTPUT_MEMORY",
622626
loc);
623627
addCapability(spv::Capability::VulkanMemoryModel, loc);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %dxc -T lib_6_8 -spirv -fspv-target-env=vulkan1.3 -HV 202x -fvk-use-scalar-layout -E main %s | FileCheck %s
2+
3+
#define MemorySemanticsAcquireReleaseMask 0x00000008
4+
#define MemorySemanticsWorkgroupMemoryMask 0x00000100
5+
#define ScopeWorkgroup 2
6+
#define OpControlBarrier 224
7+
8+
[[vk::ext_instruction( OpControlBarrier )]]
9+
void controlBarrier(uint32_t executionScope, uint32_t memoryScope, uint32_t memorySemantics);
10+
11+
[numthreads(64,1,1)]
12+
[shader("compute")]
13+
void main(uint32_t3 ID : SV_DispatchThreadID)
14+
{
15+
controlBarrier(ScopeWorkgroup, ScopeWorkgroup, MemorySemanticsAcquireReleaseMask | MemorySemanticsWorkgroupMemoryMask);
16+
}
17+
18+
// CHECK: [[UINT:%[^ ]*]] = OpTypeInt 32 0
19+
// CHECK-DAG: [[U2:%[^ ]*]] = OpConstant [[UINT]] 2
20+
// CHECK-DAG: [[U264:%[^ ]*]] = OpConstant [[UINT]] 264
21+
// CHECK: OpControlBarrier [[U2]] [[U2]] [[U264]]
22+

0 commit comments

Comments
 (0)