2
0
Эх сурвалжийг харах

Fix atomic offset for case element type of structure buffer is not structure type. (#349) (#360)

Xiang Li 8 жил өмнө
parent
commit
4ba401c364

+ 3 - 0
lib/HLSL/HLOperationLower.cpp

@@ -5713,6 +5713,9 @@ void TranslateStructBufSubscriptUser(Instruction *user, Value *handle,
     HLOpcodeGroup group =
         hlsl::GetHLOpcodeGroupByName(userCall->getCalledFunction());
     unsigned opcode = GetHLOpcode(userCall);
+    // For case element type of structure buffer is not structure type.
+    if (baseOffset == nullptr)
+      baseOffset = OP->GetU32Const(0);
     if (group == HLOpcodeGroup::HLIntrinsic) {
       IntrinsicOp IOP = static_cast<IntrinsicOp>(opcode);
       switch (IOP) {

+ 17 - 0
tools/clang/test/CodeGenHLSL/atomic2.hlsl

@@ -0,0 +1,17 @@
+// RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
+
+// Make sure offset is 0
+// CHECK: dx.op.atomicBinOp.i32(i32 78, {{.*}}, i32 0, i32 undef, i32 1)
+
+// Make sure offset is 0
+// CHECK: dx.op.atomicBinOp.i32(i32 78, {{.*}}, i32 0, i32 undef, i32 %
+
+RWStructuredBuffer<uint> structBuf1 : register( u1 );
+
+[numthreads( 8, 8, 1 )]
+void main( uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID )
+{
+    uint v;
+    InterlockedAdd( structBuf1[DTid.z], 1, v);
+    InterlockedAdd( structBuf1[DTid.z], v);
+}

+ 5 - 0
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -373,6 +373,7 @@ public:
   TEST_METHOD(CodeGenAsUint)
   TEST_METHOD(CodeGenAsUint2)
   TEST_METHOD(CodeGenAtomic)
+  TEST_METHOD(CodeGenAtomic2)
   TEST_METHOD(CodeGenAttributeAtVertex)
   TEST_METHOD(CodeGenBarycentrics)
   TEST_METHOD(CodeGenBarycentrics1)
@@ -2241,6 +2242,10 @@ TEST_F(CompilerTest, CodeGenAtomic) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\atomic.hlsl");
 }
 
+TEST_F(CompilerTest, CodeGenAtomic2) {
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\atomic2.hlsl");
+}
+
 TEST_F(CompilerTest, CodeGenAttributeAtVertex) {
   if (m_ver.SkipDxil_1_1_Test()) return;
   CodeGenTestCheck(L"..\\CodeGenHLSL\\attributeAtVertex.hlsl");