Skip to content

Commit d0fa5e3

Browse files
authored
Not dup barrier in HL level. (#3181)
1 parent b0c029e commit d0fa5e3

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

lib/HLSL/HLOperations.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,23 @@ static void SetHLFunctionAttribute(Function *F, HLOpcodeGroup group,
455455
F->addFnAttr(Attribute::ReadNone);
456456
F->addFnAttr(Attribute::NoUnwind);
457457
} break;
458+
case HLOpcodeGroup::HLIntrinsic: {
459+
IntrinsicOp intrinsicOp = static_cast<IntrinsicOp>(opcode);
460+
switch (intrinsicOp) {
461+
default:
462+
break;
463+
case IntrinsicOp::IOP_DeviceMemoryBarrierWithGroupSync:
464+
case IntrinsicOp::IOP_DeviceMemoryBarrier:
465+
case IntrinsicOp::IOP_GroupMemoryBarrierWithGroupSync:
466+
case IntrinsicOp::IOP_GroupMemoryBarrier:
467+
case IntrinsicOp::IOP_AllMemoryBarrierWithGroupSync:
468+
case IntrinsicOp::IOP_AllMemoryBarrier:
469+
F->addFnAttr(Attribute::NoDuplicate);
470+
break;
471+
}
472+
} break;
458473
case HLOpcodeGroup::NotHL:
459474
case HLOpcodeGroup::HLExtIntrinsic:
460-
case HLOpcodeGroup::HLIntrinsic:
461475
case HLOpcodeGroup::HLSelect:
462476
case HLOpcodeGroup::NumOfHLOps:
463477
// No default attributes for these opcodes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %dxc -T cs_6_3 %s | FileCheck %s
2+
3+
// Make sure only 2 barrier.
4+
// CHECK: call void @dx.op.barrier(i32 80, i32 9)
5+
// CHECK: call void @dx.op.barrier(i32 80, i32 9)
6+
// CHECK-NOT: call void @dx.op.barrier(i32 80, i32 9)
7+
8+
RWStructuredBuffer<uint> _CoarseStencilBuffer;
9+
uint stencilBufferWidth;
10+
11+
groupshared uint g_GroupsharedValue;
12+
13+
[numthreads(8, 8, 1)]
14+
void main(uint3 groupId : SV_GroupID,
15+
uint threadIndex : SV_GroupIndex)
16+
{
17+
uint threadValue = 1 << (threadIndex/2);
18+
19+
bool isFirstThreadInGroup = threadIndex == 0;
20+
21+
if (isFirstThreadInGroup)
22+
g_GroupsharedValue = 0;
23+
24+
GroupMemoryBarrierWithGroupSync();
25+
InterlockedOr(g_GroupsharedValue, threadValue);
26+
GroupMemoryBarrierWithGroupSync();
27+
28+
if (isFirstThreadInGroup)
29+
{
30+
uint addressIndex = groupId.y * stencilBufferWidth + groupId.x;
31+
_CoarseStencilBuffer[addressIndex] = g_GroupsharedValue;
32+
}
33+
}

0 commit comments

Comments
 (0)