소스 검색

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
2개의 변경된 파일29개의 추가작업 그리고 1개의 파일을 삭제
  1. 11 1
      lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp
  2. 18 0
      tools/clang/test/CodeGenHLSL/quick-test/lib_append_buf.hlsl

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

@@ -4001,10 +4001,14 @@ public:
     m_HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
 
     std::deque<Function *> WorkList;
+    std::vector<Function *> DeadHLFunctions;
     for (Function &F : M.functions()) {
       HLOpcodeGroup group = GetHLOpcodeGroup(&F);
       // 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;
       }
 
@@ -4031,6 +4035,12 @@ public:
       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.
     for (Function *F : WorkList) {
       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);
+}