Преглед изворни кода

Merged PR 59: Remove hl functions has body and always inline before DxilGeneration to avoid

Remove hl functions has body and always inline before DxilGeneration to avoid fail to find resource for update counter.
Xiang_Li (XBox) пре 7 година
родитељ
комит
1d91a0a5b1

+ 11 - 1
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -4001,10 +4001,14 @@ public:
     m_HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
     m_HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
 
 
     std::deque<Function *> WorkList;
     std::deque<Function *> WorkList;
+    std::vector<Function *> DeadHLFunctions;
     for (Function &F : M.functions()) {
     for (Function &F : M.functions()) {
       HLOpcodeGroup group = GetHLOpcodeGroup(&F);
       HLOpcodeGroup group = GetHLOpcodeGroup(&F);
       // Skip HL operations.
       // Skip HL operations.
-      if (group != HLOpcodeGroup::NotHL || group == HLOpcodeGroup::HLExtIntrinsic) {
+      if (group != HLOpcodeGroup::NotHL ||
+          group == HLOpcodeGroup::HLExtIntrinsic) {
+        if (F.user_empty())
+          DeadHLFunctions.emplace_back(&F);
         continue;
         continue;
       }
       }
 
 
@@ -4031,6 +4035,12 @@ public:
       WorkList.emplace_back(&F);
       WorkList.emplace_back(&F);
     }
     }
 
 
+    // Remove dead hl functions here.
+    // This is for hl functions which has body and always inline.
+    for (Function *F : DeadHLFunctions) {
+      F->eraseFromParent();
+    }
+
     // Preprocess aggregate function param used as function call arg.
     // Preprocess aggregate function param used as function call arg.
     for (Function *F : WorkList) {
     for (Function *F : WorkList) {
       preprocessArgUsedInCall(F);
       preprocessArgUsedInCall(F);

+ 18 - 0
tools/clang/test/CodeGenHLSL/quick-test/lib_append_buf.hlsl

@@ -0,0 +1,18 @@
+// RUN: %dxc -T lib_6_2 %s | FileCheck %s
+
+// Make sure append/consume works for lib.
+// CHECK: bufferUpdateCounter(i32 70, {{.*}}, i8 -1)
+// CHECK: bufferUpdateCounter(i32 70, {{.*}}, i8 1)
+
+// Append Structured Buffer (u3)
+AppendStructuredBuffer<float4> appendUAVResource : register(u3);
+
+// Consume Structured Buffer (u4) 
+ConsumeStructuredBuffer<float4> consumeUAVResource : register(u4);
+
+[shader("compute")]
+void test()
+{
+  float4 consumeResourceOutput = consumeUAVResource.Consume();
+  appendUAVResource.Append(consumeResourceOutput);
+}