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.
This commit is contained in:
Родитель
85063375b3
Коммит
18c0c08032
|
@ -357,11 +357,10 @@ public:
|
|||
void SetShaderProperties(DxilFunctionProps *props);
|
||||
|
||||
// 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 {
|
||||
llvm::Constant *ResRangeID;
|
||||
llvm::Constant *ResIndex;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
@ -460,7 +460,6 @@ void DxilCondenseResources::PatchCreateHandleForLib(DxilModule &DM) {
|
|||
Function *createHandle = DM.GetOP()->GetOpFunc(DXIL::OpCode::CreateHandle,
|
||||
Type::getVoidTy(DM.GetCtx()));
|
||||
DM.CreateResourceLinkInfo();
|
||||
Value *zeroIndex = ConstantInt::get(Type::getInt32Ty(DM.GetCtx()), 0);
|
||||
for (User *U : createHandle->users()) {
|
||||
CallInst *handle = cast<CallInst>(U);
|
||||
DxilInst_CreateHandle createHandle(handle);
|
||||
|
@ -484,20 +483,6 @@ void DxilCondenseResources::PatchCreateHandleForLib(DxilModule &DM) {
|
|||
// Update rangeID to linkinfo rangeID.
|
||||
handle->setArgOperand(DXIL::OperandIndex::kCreateHandleResIDOpIdx,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1468,6 +1468,7 @@ public:
|
|||
|
||||
bool runOnModule(Module &M) override {
|
||||
if (M.HasDxilModule()) {
|
||||
DxilModule &DM = M.GetDxilModule();
|
||||
// Remove store undef output.
|
||||
hlsl::OP *hlslOP = M.GetDxilModule().GetOP();
|
||||
unsigned ValMajor = 0;
|
||||
|
@ -1511,9 +1512,17 @@ public:
|
|||
}
|
||||
}
|
||||
// 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;
|
||||
for (iplist<Function>::iterator F : M.getFunctionList()) {
|
||||
if (F->isDeclaration()) {
|
||||
if (&(*F) == EntryFunc || &(*F) == PatchConstantFunc)
|
||||
continue;
|
||||
if (F->isDeclaration() || !IsLib) {
|
||||
if (F->user_empty())
|
||||
deadList.emplace_back(F);
|
||||
}
|
||||
|
@ -1563,11 +1572,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
DxilModule &DM = M.GetDxilModule();
|
||||
DenseMap<const Function *, DISubprogram *> FunctionDIs =
|
||||
makeSubprogramMap(M);
|
||||
// Strip parameters of entry function.
|
||||
if (!DM.GetShaderModel()->IsLib()) {
|
||||
if (!IsLib) {
|
||||
if (Function *PatchConstantFunc = DM.GetPatchConstantFunction()) {
|
||||
PatchConstantFunc =
|
||||
StripFunctionParameter(PatchConstantFunc, DM, FunctionDIs);
|
||||
|
|
|
@ -930,6 +930,8 @@ Function *DxilMDHelper::LoadDxilFunctionProps(MDTuple *pProps,
|
|||
(DXIL::InputPrimitive)ConstMDToUint32(pProps->getOperand(idx++));
|
||||
props->ShaderProps.GS.maxVertexCount =
|
||||
ConstMDToUint32(pProps->getOperand(idx++));
|
||||
props->ShaderProps.GS.instanceCount =
|
||||
ConstMDToUint32(pProps->getOperand(idx++));
|
||||
for (size_t i = 0;
|
||||
i < _countof(props->ShaderProps.GS.streamPrimitiveTopologies); ++i)
|
||||
props->ShaderProps.GS.streamPrimitiveTopologies[i] =
|
||||
|
@ -985,6 +987,7 @@ DxilMDHelper::EmitDxilFunctionProps(const hlsl::DxilFunctionProps *props,
|
|||
MDVals[valIdx++] =
|
||||
Uint8ToConstMD((uint8_t)props->ShaderProps.GS.inputPrimitive);
|
||||
MDVals[valIdx++] = Uint32ToConstMD(props->ShaderProps.GS.maxVertexCount);
|
||||
MDVals[valIdx++] = Uint32ToConstMD(props->ShaderProps.GS.instanceCount);
|
||||
for (size_t i = 0;
|
||||
i < _countof(props->ShaderProps.GS.streamPrimitiveTopologies); ++i)
|
||||
MDVals[valIdx++] = Uint8ToConstMD(
|
||||
|
|
|
@ -860,11 +860,8 @@ static void CreateResourceLinkConstant(Module &M, DxilResourceBase *pRes,
|
|||
GlobalVariable *rangeID = new GlobalVariable(
|
||||
M, i32Ty, IsConstantTrue, llvm::GlobalValue::ExternalLinkage, NullInitVal,
|
||||
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() {
|
||||
|
@ -1402,7 +1399,6 @@ static MDTuple *CreateResourcesLinkInfo(std::vector<DxilModule::ResourceLinkInfo
|
|||
vector<Metadata *> MDVals;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
MDVals.emplace_back(ValueAsMetadata::get(LinkInfoList[i].ResRangeID));
|
||||
MDVals.emplace_back(ValueAsMetadata::get(LinkInfoList[i].ResIndex));
|
||||
}
|
||||
return MDNode::get(Ctx, MDVals);
|
||||
}
|
||||
|
@ -1440,13 +1436,11 @@ LoadResourcesLinkInfo(const llvm::MDTuple *pMD,
|
|||
return;
|
||||
}
|
||||
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 =
|
||||
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,14 +2,12 @@
|
|||
|
||||
// Make sure globals for link info exist.
|
||||
// CHECK: g_txDiffuse_rangeID
|
||||
// CHECK: g_txDiffuse_index
|
||||
// CHECK: g_samLinear_rangeID
|
||||
// CHECK: g_samLinear_index
|
||||
|
||||
// Make sure link info metadata exist.
|
||||
// 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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче