Bladeren bron

1. Remove ResIndex from ResourceLinkInfo.
2. For none library profile, remove unused functions except entry and patchconstant function.
3. Fix issue caused by lost instanceCount for GS function props.

Xiang Li 8 jaren geleden
bovenliggende
commit
18c0c08032

+ 2 - 3
include/dxc/HLSL/DxilModule.h

@@ -357,11 +357,10 @@ public:
   void SetShaderProperties(DxilFunctionProps *props);
   void SetShaderProperties(DxilFunctionProps *props);
 
 
   // Shader resource information only needed before linking.
   // Shader resource information only needed before linking.
-  // Use constant as rangeID and index for resource in a library.
-  // When link the library, replace these constants with real rangeID and index.
+  // Use constant as rangeID for resource in a library.
+  // When link the library, replace these constants with real rangeID.
   struct ResourceLinkInfo {
   struct ResourceLinkInfo {
     llvm::Constant *ResRangeID;
     llvm::Constant *ResRangeID;
-    llvm::Constant *ResIndex;
   };
   };
 
 
 private:
 private:

+ 0 - 15
lib/HLSL/DxilCondenseResources.cpp

@@ -460,7 +460,6 @@ void DxilCondenseResources::PatchCreateHandleForLib(DxilModule &DM) {
   Function *createHandle = DM.GetOP()->GetOpFunc(DXIL::OpCode::CreateHandle,
   Function *createHandle = DM.GetOP()->GetOpFunc(DXIL::OpCode::CreateHandle,
                                                  Type::getVoidTy(DM.GetCtx()));
                                                  Type::getVoidTy(DM.GetCtx()));
   DM.CreateResourceLinkInfo();
   DM.CreateResourceLinkInfo();
-  Value *zeroIndex = ConstantInt::get(Type::getInt32Ty(DM.GetCtx()), 0);
   for (User *U : createHandle->users()) {
   for (User *U : createHandle->users()) {
     CallInst *handle = cast<CallInst>(U);
     CallInst *handle = cast<CallInst>(U);
     DxilInst_CreateHandle createHandle(handle);
     DxilInst_CreateHandle createHandle(handle);
@@ -484,20 +483,6 @@ void DxilCondenseResources::PatchCreateHandleForLib(DxilModule &DM) {
     // Update rangeID to linkinfo rangeID.
     // Update rangeID to linkinfo rangeID.
     handle->setArgOperand(DXIL::OperandIndex::kCreateHandleResIDOpIdx,
     handle->setArgOperand(DXIL::OperandIndex::kCreateHandleResIDOpIdx,
                           linkRangeID);
                           linkRangeID);
-
-    Value *Index = createHandle.get_index();
-    Value *linkIndex = Builder.CreateLoad(linkInfo.ResIndex);
-
-    if (Index == zeroIndex) {
-      // Update index to linkinfo index.
-      handle->setArgOperand(DXIL::OperandIndex::kCreateHandleResIndexOpIdx,
-                            linkIndex);
-    } else {
-      // Add linkinfo index to index.
-      Value *newIdx = Builder.CreateAdd(Index, linkIndex);
-      handle->setArgOperand(DXIL::OperandIndex::kCreateHandleResIndexOpIdx,
-                            newIdx);
-    }
   }
   }
 }
 }
 
 

+ 11 - 3
lib/HLSL/DxilGenerationPass.cpp

@@ -1468,6 +1468,7 @@ public:
 
 
   bool runOnModule(Module &M) override {
   bool runOnModule(Module &M) override {
     if (M.HasDxilModule()) {
     if (M.HasDxilModule()) {
+      DxilModule &DM = M.GetDxilModule();
       // Remove store undef output.
       // Remove store undef output.
       hlsl::OP *hlslOP = M.GetDxilModule().GetOP();
       hlsl::OP *hlslOP = M.GetDxilModule().GetOP();
       unsigned ValMajor = 0;
       unsigned ValMajor = 0;
@@ -1511,9 +1512,17 @@ public:
         }
         }
       }
       }
       // Remove unused external functions.
       // Remove unused external functions.
+      // For none library profile, remove unused functions except entry and
+      // patchconstant function.
+      Function *EntryFunc = DM.GetEntryFunction();
+      Function *PatchConstantFunc = DM.GetPatchConstantFunction();
+      bool IsLib = DM.GetShaderModel()->IsLib();
+
       std::vector<Function *> deadList;
       std::vector<Function *> deadList;
       for (iplist<Function>::iterator F : M.getFunctionList()) {
       for (iplist<Function>::iterator F : M.getFunctionList()) {
-        if (F->isDeclaration()) {
+        if (&(*F) == EntryFunc || &(*F) == PatchConstantFunc)
+          continue;
+        if (F->isDeclaration() || !IsLib) {
           if (F->user_empty())
           if (F->user_empty())
             deadList.emplace_back(F);
             deadList.emplace_back(F);
         }
         }
@@ -1563,11 +1572,10 @@ public:
         }
         }
       }
       }
 
 
-      DxilModule &DM = M.GetDxilModule();
       DenseMap<const Function *, DISubprogram *> FunctionDIs =
       DenseMap<const Function *, DISubprogram *> FunctionDIs =
           makeSubprogramMap(M);
           makeSubprogramMap(M);
       // Strip parameters of entry function.
       // Strip parameters of entry function.
-      if (!DM.GetShaderModel()->IsLib()) {
+      if (!IsLib) {
         if (Function *PatchConstantFunc = DM.GetPatchConstantFunction()) {
         if (Function *PatchConstantFunc = DM.GetPatchConstantFunction()) {
           PatchConstantFunc =
           PatchConstantFunc =
               StripFunctionParameter(PatchConstantFunc, DM, FunctionDIs);
               StripFunctionParameter(PatchConstantFunc, DM, FunctionDIs);

+ 3 - 0
lib/HLSL/DxilMetadataHelper.cpp

@@ -930,6 +930,8 @@ Function *DxilMDHelper::LoadDxilFunctionProps(MDTuple *pProps,
         (DXIL::InputPrimitive)ConstMDToUint32(pProps->getOperand(idx++));
         (DXIL::InputPrimitive)ConstMDToUint32(pProps->getOperand(idx++));
     props->ShaderProps.GS.maxVertexCount =
     props->ShaderProps.GS.maxVertexCount =
         ConstMDToUint32(pProps->getOperand(idx++));
         ConstMDToUint32(pProps->getOperand(idx++));
+    props->ShaderProps.GS.instanceCount =
+        ConstMDToUint32(pProps->getOperand(idx++));
     for (size_t i = 0;
     for (size_t i = 0;
          i < _countof(props->ShaderProps.GS.streamPrimitiveTopologies); ++i)
          i < _countof(props->ShaderProps.GS.streamPrimitiveTopologies); ++i)
       props->ShaderProps.GS.streamPrimitiveTopologies[i] =
       props->ShaderProps.GS.streamPrimitiveTopologies[i] =
@@ -985,6 +987,7 @@ DxilMDHelper::EmitDxilFunctionProps(const hlsl::DxilFunctionProps *props,
     MDVals[valIdx++] =
     MDVals[valIdx++] =
         Uint8ToConstMD((uint8_t)props->ShaderProps.GS.inputPrimitive);
         Uint8ToConstMD((uint8_t)props->ShaderProps.GS.inputPrimitive);
     MDVals[valIdx++] = Uint32ToConstMD(props->ShaderProps.GS.maxVertexCount);
     MDVals[valIdx++] = Uint32ToConstMD(props->ShaderProps.GS.maxVertexCount);
+    MDVals[valIdx++] = Uint32ToConstMD(props->ShaderProps.GS.instanceCount);
     for (size_t i = 0;
     for (size_t i = 0;
          i < _countof(props->ShaderProps.GS.streamPrimitiveTopologies); ++i)
          i < _countof(props->ShaderProps.GS.streamPrimitiveTopologies); ++i)
       MDVals[valIdx++] = Uint8ToConstMD(
       MDVals[valIdx++] = Uint8ToConstMD(

+ 4 - 10
lib/HLSL/DxilModule.cpp

@@ -860,11 +860,8 @@ static void CreateResourceLinkConstant(Module &M, DxilResourceBase *pRes,
   GlobalVariable *rangeID = new GlobalVariable(
   GlobalVariable *rangeID = new GlobalVariable(
       M, i32Ty, IsConstantTrue, llvm::GlobalValue::ExternalLinkage, NullInitVal,
       M, i32Ty, IsConstantTrue, llvm::GlobalValue::ExternalLinkage, NullInitVal,
       pRes->GetGlobalName() + "_rangeID");
       pRes->GetGlobalName() + "_rangeID");
-  GlobalVariable *index = new GlobalVariable(
-      M, i32Ty, IsConstantTrue, llvm::GlobalValue::ExternalLinkage, NullInitVal,
-      pRes->GetGlobalName() + "_index");
 
 
-  resLinkInfo.emplace_back(DxilModule::ResourceLinkInfo{rangeID, index});
+  resLinkInfo.emplace_back(DxilModule::ResourceLinkInfo{rangeID});
 }
 }
 
 
 void DxilModule::CreateResourceLinkInfo() {
 void DxilModule::CreateResourceLinkInfo() {
@@ -1402,7 +1399,6 @@ static MDTuple *CreateResourcesLinkInfo(std::vector<DxilModule::ResourceLinkInfo
   vector<Metadata *> MDVals;
   vector<Metadata *> MDVals;
   for (size_t i = 0; i < size; i++) {
   for (size_t i = 0; i < size; i++) {
     MDVals.emplace_back(ValueAsMetadata::get(LinkInfoList[i].ResRangeID));
     MDVals.emplace_back(ValueAsMetadata::get(LinkInfoList[i].ResRangeID));
-    MDVals.emplace_back(ValueAsMetadata::get(LinkInfoList[i].ResIndex));
   }
   }
   return MDNode::get(Ctx, MDVals);
   return MDNode::get(Ctx, MDVals);
 }
 }
@@ -1440,13 +1436,11 @@ LoadResourcesLinkInfo(const llvm::MDTuple *pMD,
     return;
     return;
   }
   }
   unsigned operandSize = pMD->getNumOperands();
   unsigned operandSize = pMD->getNumOperands();
-  IFTBOOL(operandSize == (2 * size), DXC_E_INCORRECT_DXIL_METADATA);
-  for (unsigned i = 0; i < operandSize; i += 2) {
+  IFTBOOL(operandSize == size, DXC_E_INCORRECT_DXIL_METADATA);
+  for (unsigned i = 0; i < operandSize; i++) {
     Constant *rangeID =
     Constant *rangeID =
         dyn_cast<Constant>(pMDHelper->ValueMDToValue(pMD->getOperand(i)));
         dyn_cast<Constant>(pMDHelper->ValueMDToValue(pMD->getOperand(i)));
-    Constant *index =
-        dyn_cast<Constant>(pMDHelper->ValueMDToValue(pMD->getOperand(i + 1)));
-    LinkInfoList.emplace_back(DxilModule::ResourceLinkInfo{rangeID, index});
+    LinkInfoList.emplace_back(DxilModule::ResourceLinkInfo{rangeID});
   }
   }
 }
 }
 
 

+ 2 - 4
tools/clang/test/CodeGenHLSL/lib_resource.hlsl

@@ -2,14 +2,12 @@
 
 
 // Make sure globals for link info exist.
 // Make sure globals for link info exist.
 // CHECK: g_txDiffuse_rangeID
 // CHECK: g_txDiffuse_rangeID
-// CHECK: g_txDiffuse_index
 // CHECK: g_samLinear_rangeID
 // CHECK: g_samLinear_rangeID
-// CHECK: g_samLinear_index
 
 
 // Make sure link info metadata exist.
 // Make sure link info metadata exist.
 // CHECK: dx.resources.link.info
 // CHECK: dx.resources.link.info
-// CHECK: !{i32* @g_txDiffuse_rangeID, i32* @g_txDiffuse_index}
-// CHECK: !{i32* @g_samLinear_rangeID, i32* @g_samLinear_index}
+// CHECK: !{i32* @g_txDiffuse_rangeID}
+// CHECK: !{i32* @g_samLinear_rangeID}
 
 
 
 
 Texture2D    g_txDiffuse;
 Texture2D    g_txDiffuse;