Commit d5ab3ee8 authored by Filipkowski, Lukasz's avatar Filipkowski, Lukasz Committed by gbsbuild

Tessellation factors padding in URB header

Change-Id: I1ad0d93457edd4365b35eddf32daa7e454d456e5
parent 6580e172
......@@ -52,7 +52,8 @@ public:
private:
void LowerIntrinsicInputOutput(llvm::Function &F);
unsigned int GetDomainType(llvm::BasicBlock * bb, unsigned & numTEFactorsInDomain);
unsigned int GetDomainType();
bool IsTEFactorsPaddingAllowed(llvm::BasicBlock * bb);
llvm::GenIntrinsicInst* AddURBWriteControlPointOutputs(
Value* mask,
......@@ -117,7 +118,7 @@ bool HullShaderLowering::runOnFunction(llvm::Function &F)
m_hullShaderInfo->gatherInformation(&F);
m_module = F.getParent();
LowerIntrinsicInputOutput(F);
return false;
}
......@@ -126,16 +127,15 @@ void HullShaderLowering::LowerIntrinsicInputOutput(Function& F)
{
SmallVector<Instruction*, 10> instructionToRemove;
IRBuilder<> builder(F.getContext());
IRBuilder<> builder(F.getContext());
IGC::CodeGenContext* ctx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
for(auto BI = F.begin(), BE = F.end(); BI != BE; BI++)
{
m_pControlPointOutputs.clear();
bool isTEFactorURBMsgPadded = false;
unsigned int numTEFactorsInDomain = 0;
bool checkedForTEFactorsPadding = false;
for(auto II = BI->begin(), IE = BI->end(); II!=IE; II++)
{
......@@ -241,43 +241,29 @@ void HullShaderLowering::LowerIntrinsicInputOutput(Function& F)
instructionToRemove.push_back(inst);
}
// Apply URB padding for TE factors.
if (IGC_IS_FLAG_ENABLED(EnableTEFactorsPadding) &&
ctx->platform.applyTEFactorsPadding() &&
((IID == GenISAIntrinsic::GenISA_OuterScalarTessFactors) ||
(IID == GenISAIntrinsic::GenISA_InnerScalarTessFactors)))
if ((IID == GenISAIntrinsic::GenISA_OuterScalarTessFactors) ||
(IID == GenISAIntrinsic::GenISA_InnerScalarTessFactors))
{
if (!isTEFactorURBMsgPadded)
// Apply URB padding for TE factors.
if (IGC_IS_FLAG_ENABLED(EnableTEFactorsPadding) && ctx->platform.applyTEFactorsPadding())
{
// Parse all instructions within BB and count the Inner,Outer ScalarTessFactors factors
// and get the domain type.
BasicBlock* bb = dyn_cast<BasicBlock>(BI);
uint32_t tessShaderDomain = GetDomainType(bb, numTEFactorsInDomain);
if ((numTEFactorsInDomain == 2 && tessShaderDomain == USC::TESSELLATOR_DOMAIN_ISOLINE) ||
(numTEFactorsInDomain == 4 && tessShaderDomain == USC::TESSELLATOR_DOMAIN_TRI) ||
(numTEFactorsInDomain == 6 && tessShaderDomain == USC::TESSELLATOR_DOMAIN_QUAD))
if (!checkedForTEFactorsPadding)
{
checkedForTEFactorsPadding = true;
// Adjust the mask value based on the TE factors number.
unsigned int mask = (1 << (8 - numTEFactorsInDomain)) - 1;
Value* undef = llvm::UndefValue::get(Type::getFloatTy(F.getContext()));
Value* data[8] = { undef,undef,undef,undef,undef,undef,undef,undef };
AddURBWrite(
builder.getInt32(0), // offset
builder.getInt32(mask),
data,
inst);
isTEFactorURBMsgPadded = true;
BasicBlock* bb = dyn_cast<BasicBlock>(BI);
if (IsTEFactorsPaddingAllowed(bb))
{
Value* undef = llvm::UndefValue::get(Type::getFloatTy(F.getContext()));
Value* data[8] = { undef,undef,undef,undef,undef,undef,undef,undef };
// Add padding at offset 0
AddURBWrite(builder.getInt32(0), builder.getInt32(0xF), data, inst);
// Add padding at offset 1
AddURBWrite(builder.getInt32(1), builder.getInt32(0xF), data, inst);
}
}
}
}
if ((IID == GenISAIntrinsic::GenISA_OuterScalarTessFactors) ||
(IID == GenISAIntrinsic::GenISA_InnerScalarTessFactors))
{
// The URB Location for tessellation factors spans the first two offsets
// offset 0 and 1. The tessellation factors occupy the two offsets as mentioned below
// Quad domain has 4 outer and 2 inner tessellation factors
......@@ -303,17 +289,7 @@ void HullShaderLowering::LowerIntrinsicInputOutput(Function& F)
//| | | | |
//------------------------------------------------------------------------------------
uint32_t tessShaderDomain = USC::TESSELLATOR_DOMAIN_ISOLINE;
llvm::NamedMDNode *pMetaData = m_module->getOrInsertNamedMetadata("TessellationShaderDomain");
if (pMetaData && (pMetaData->getNumOperands() == 1))
{
llvm::MDNode* pTessShaderDomain = pMetaData->getOperand(0);
if (pTessShaderDomain)
{
tessShaderDomain = int_cast<uint32_t>(
mdconst::dyn_extract<ConstantInt>(pTessShaderDomain->getOperand(0))->getZExtValue());
}
}
unsigned int tessShaderDomain = GetDomainType();
// offset into URB is 1 for outerScalarTessFactors and
// 1 if its triangle domain and inner scalar tessellation factor
......@@ -401,9 +377,25 @@ void HullShaderLowering::LowerIntrinsicInputOutput(Function& F)
}
}
unsigned int HullShaderLowering::GetDomainType(llvm::BasicBlock* bb, unsigned &numTEFactorsInDomain)
unsigned int HullShaderLowering::GetDomainType()
{
unsigned int tessShaderDomain = USC::TESSELLATOR_DOMAIN_ISOLINE;
llvm::NamedMDNode *pMetaData = m_module->getOrInsertNamedMetadata("TessellationShaderDomain");
if (pMetaData && (pMetaData->getNumOperands() == 1))
{
llvm::MDNode* pTessShaderDomain = pMetaData->getOperand(0);
if (pTessShaderDomain)
{
tessShaderDomain = int_cast<uint32_t>(
mdconst::dyn_extract<ConstantInt>(pTessShaderDomain->getOperand(0))->getZExtValue());
}
}
return tessShaderDomain;
}
bool HullShaderLowering::IsTEFactorsPaddingAllowed(llvm::BasicBlock * bb)
{
bool paddingAllowed = false;
for (auto II = bb->begin(), IE = bb->end(); II != IE; II++)
{
if (GenIntrinsicInst* inst = dyn_cast<GenIntrinsicInst>(II))
......@@ -412,21 +404,19 @@ unsigned int HullShaderLowering::GetDomainType(llvm::BasicBlock* bb, unsigned &n
if ((IID == GenISAIntrinsic::GenISA_OuterScalarTessFactors) ||
(IID == GenISAIntrinsic::GenISA_InnerScalarTessFactors))
{
llvm::NamedMDNode *pMetaData = m_module->getOrInsertNamedMetadata("TessellationShaderDomain");
if (pMetaData && (pMetaData->getNumOperands() == 1))
if (llvm::isa<ConstantInt>(inst->getOperand(0)))
{
llvm::MDNode* pTessShaderDomain = pMetaData->getOperand(0);
if (pTessShaderDomain)
{
tessShaderDomain = int_cast<uint32_t>(
mdconst::dyn_extract<ConstantInt>(pTessShaderDomain->getOperand(0))->getZExtValue());
}
// Padding can be applied in case basic block contains at least one TE factor intrinsic
// indexed with immediate value. Such intrinsic will be converted to URBWrite instruction
// with both immediate offset and immediate mask and later on will be merged with padding
// URBWrite instruction
paddingAllowed = true;
break;
}
numTEFactorsInDomain++;
}
}
}
return tessShaderDomain;
return paddingAllowed;
}
llvm::GenIntrinsicInst* HullShaderLowering::AddURBWriteControlPointOutputs(Value* mask, Value* data[8], Instruction* prev)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment