Skip to content

Commit c2f1928

Browse files
davidjwoosys_zuul
authored andcommitted
Multirate shading improvements and fixes
Fixed bug where r1 would be overwritten in the perpixel phase of a multirate shader Fixed bug where the perpixel phase of a multirate shader was treated as the entry function Fixed bug where the PixelShaderAddMask pass would be run on the perpixel phase of a multirate shader more than once Fixed bug where phi nodes were added to a basic block with only one predecessor Fixed bug where PurgeMetaDataUtils deleted the coarse phase when compiling the perpixel phase. Allowed phase inputs and outputs to use all floating point types Change-Id: I8079552c08efea31cc8d6ed1cc6207b06c37b66f
1 parent cf21612 commit c2f1928

13 files changed

+297
-46
lines changed

IGC/Compiler/CISACodeGen/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ set(IGC_BUILD__SRC__CISACodeGen_Common
8383
"${CMAKE_CURRENT_SOURCE_DIR}/WIAnalysis.cpp"
8484
"${CMAKE_CURRENT_SOURCE_DIR}/SLMConstProp.cpp"
8585
"${CMAKE_CURRENT_SOURCE_DIR}/POSH_RemoveNonPositionOutput.cpp"
86+
"${CMAKE_CURRENT_SOURCE_DIR}/CrossPhaseConstProp.cpp"
8687
)
8788

8889

@@ -173,6 +174,7 @@ set(IGC_BUILD__HDR__CISACodeGen_Common
173174
"${CMAKE_CURRENT_SOURCE_DIR}/WIAnalysis.hpp"
174175
"${CMAKE_CURRENT_SOURCE_DIR}/SLMConstProp.hpp"
175176
"${CMAKE_CURRENT_SOURCE_DIR}/POSH_RemoveNonPositionOutput.h"
177+
"${CMAKE_CURRENT_SOURCE_DIR}/CrossPhaseConstProp.hpp"
176178
)
177179

178180

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void CShader::CreateImplicitArgs()
335335

336336
// Push Args are only for entry function
337337
unsigned numPushArgsEntry = m_ModuleMetadata->pushInfo.pushAnalysisWIInfos.size();
338-
unsigned numPushArgs = (isEntryFunc(m_pMdUtils, entry) ? numPushArgsEntry : 0);
338+
unsigned numPushArgs = (isEntryFunc(m_pMdUtils, entry) && !isPixelPhaseFunction(entry) ? numPushArgsEntry : 0);
339339
unsigned numFuncArgs = IGCLLVM::GetFuncArgSize(entry) - numImplicitArgs - numPushArgs;
340340

341341
// Create symbol for every arguments [5/2019]
@@ -2072,7 +2072,7 @@ CVariable* CShader::getOrCreateArgumentSymbol(
20722072
ImplicitArgs implicitArgs(*F, m_pMdUtils);
20732073
unsigned numImplicitArgs = implicitArgs.size();
20742074
unsigned numPushArgsEntry = m_ModuleMetadata->pushInfo.pushAnalysisWIInfos.size();
2075-
unsigned numPushArgs = (isEntryFunc(m_pMdUtils, F) ? numPushArgsEntry : 0);
2075+
unsigned numPushArgs = (isEntryFunc(m_pMdUtils, F) && !isPixelPhaseFunction(F) ? numPushArgsEntry : 0);
20762076
unsigned numFuncArgs = IGCLLVM::GetFuncArgSize(F) - numImplicitArgs - numPushArgs;
20772077

20782078
CVariable* var = nullptr;
@@ -2107,7 +2107,7 @@ CVariable* CShader::getOrCreateArgumentSymbol(
21072107
uint32_t nIAs = (uint32_t)IAs.size();
21082108
uint32_t iArgIx = IAs.getArgIndex(ArgType);
21092109
uint32_t argIx = (uint32_t)IGCLLVM::GetFuncArgSize(K) - nIAs + iArgIx;
2110-
if (isEntryFunc(m_pMdUtils, &K)) {
2110+
if (isEntryFunc(m_pMdUtils, &K) && !isPixelPhaseFunction(&K)) {
21112111
argIx = argIx - numPushArgsEntry;
21122112
}
21132113
Function::arg_iterator arg = K.arg_begin();
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*===================== begin_copyright_notice ==================================
2+
3+
Copyright (c) 2017 Intel Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
25+
======================= end_copyright_notice ==================================*/
26+
27+
#include "Compiler/CISACodeGen/CrossPhaseConstProp.hpp"
28+
#include "LLVMWarningsPush.hpp"
29+
#include "llvm/Pass.h"
30+
#include "LLVMWarningsPop.hpp"
31+
#include "Compiler/CISACodeGen/PixelShaderCodeGen.hpp"
32+
#include "Compiler/CISACodeGen/helper.h"
33+
#include "Compiler/MetaDataUtilsWrapper.h"
34+
using namespace llvm;
35+
namespace
36+
{
37+
class CrossPhaseConstProp : public FunctionPass
38+
{
39+
public:
40+
static char ID; // Pass identification, replacement for typeid
41+
42+
CrossPhaseConstProp(IGC::PSSignature* signature=nullptr);
43+
44+
bool runOnFunction(Function& F) override;
45+
46+
void getAnalysisUsage(AnalysisUsage& AU) const override
47+
{
48+
AU.addRequired<IGC::MetaDataUtilsWrapper>();
49+
AU.setPreservesCFG();
50+
}
51+
private:
52+
IGC::PSSignature* m_signature;
53+
};
54+
} // namespace
55+
56+
57+
#define PASS_FLAG "igc-crossphaseconstprop"
58+
#define PASS_DESCRIPTION "Special const prop for multirate shading"
59+
#define PASS_CFG_ONLY false
60+
#define PASS_ANALYSIS false
61+
IGC_INITIALIZE_PASS_BEGIN(CrossPhaseConstProp, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
62+
IGC_INITIALIZE_PASS_DEPENDENCY(MetaDataUtilsWrapper)
63+
IGC_INITIALIZE_PASS_END(CrossPhaseConstProp, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
64+
65+
CrossPhaseConstProp::CrossPhaseConstProp(IGC::PSSignature* signature) : FunctionPass(ID), m_signature(signature)
66+
{
67+
initializeCrossPhaseConstPropPass(*PassRegistry::getPassRegistry());
68+
}
69+
70+
char CrossPhaseConstProp::ID = 0;
71+
72+
FunctionPass* IGC::createCrossPhaseConstPropPass(IGC::PSSignature* signature)
73+
{
74+
return new CrossPhaseConstProp(signature);
75+
}
76+
77+
bool CrossPhaseConstProp::runOnFunction(Function& F)
78+
{
79+
IGC::IGCMD::MetaDataUtils* pMdUtils = getAnalysis<IGC::MetaDataUtilsWrapper>().getMetaDataUtils();
80+
if (!IGC::isEntryFunc(pMdUtils, &F) || m_signature == nullptr)
81+
{
82+
return false;
83+
}
84+
85+
std::vector<Instruction*> instructionsToRemove;
86+
bool isCoarse = IGC::isCoarsePhaseFunction(&F);
87+
bool isPerPixel = IGC::isPixelPhaseFunction(&F);
88+
if (isCoarse || isPerPixel)
89+
{
90+
for (auto& BB : F)
91+
{
92+
for (auto& I : BB)
93+
{
94+
if (GenIntrinsicInst * inst = dyn_cast<GenIntrinsicInst>(&I))
95+
{
96+
GenISAIntrinsic::ID IID = inst->getIntrinsicID();
97+
if (isPerPixel && IID == GenISAIntrinsic::GenISA_PHASE_INPUT)
98+
{
99+
unsigned int index = (unsigned int)cast<llvm::ConstantInt>(inst->getOperand(0))->getZExtValue();
100+
auto constantOutput = m_signature->PSConstantOutput.find(index);
101+
if (constantOutput != m_signature->PSConstantOutput.end())
102+
{
103+
inst->replaceAllUsesWith(
104+
ConstantFP::get(inst->getType(),
105+
APFloat(inst->getType()->getFltSemantics(), APInt(inst->getType()->getScalarSizeInBits(), constantOutput->second))));
106+
instructionsToRemove.push_back(inst);
107+
}
108+
}
109+
else if (isCoarse && IID == GenISAIntrinsic::GenISA_PHASE_OUTPUT)
110+
{
111+
if (auto fpValue = dyn_cast<ConstantFP>(inst->getArgOperand(0)))
112+
{
113+
unsigned int index = (unsigned int)cast<llvm::ConstantInt>(inst->getArgOperand(1))->getZExtValue();
114+
m_signature->PSConstantOutput[index] = fpValue->getValueAPF().bitcastToAPInt().getLimitedValue();
115+
instructionsToRemove.push_back(inst);
116+
}
117+
}
118+
}
119+
}
120+
}
121+
122+
for (auto inst : instructionsToRemove)
123+
{
124+
inst->eraseFromParent();
125+
}
126+
}
127+
128+
return instructionsToRemove.size() > 0;
129+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*===================== begin_copyright_notice ==================================
2+
3+
Copyright (c) 2017 Intel Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
25+
======================= end_copyright_notice ==================================*/
26+
27+
#pragma once
28+
29+
namespace llvm
30+
{
31+
class FunctionPass;
32+
}
33+
34+
namespace IGC
35+
{
36+
struct PSSignature;
37+
llvm::FunctionPass* createCrossPhaseConstPropPass(PSSignature* signature);
38+
} // namespace IGC

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7017,7 +7017,8 @@ void EmitPass::getCoarsePixelSize(CVariable* destination, const uint component)
70177017
assert(component < 2);
70187018

70197019
CPixelShader* const psProgram = static_cast<CPixelShader*>(m_currShader);
7020-
CVariable* const coarsePixelSize = m_currShader->BitCast(psProgram->GetR1(), ISA_TYPE_UB);
7020+
CVariable* r1 = psProgram->GetPhase() == PSPHASE_PIXEL ? psProgram->GetCoarseR1() : psProgram->GetR1();
7021+
CVariable* const coarsePixelSize = m_currShader->BitCast(r1, ISA_TYPE_UB);
70217022
m_encoder->SetSrcRegion(0, 0, 1, 0);
70227023
m_encoder->SetSrcSubReg(0, (component == 0) ? 0 : 1);
70237024
m_encoder->Cast(destination, coarsePixelSize);
@@ -13103,7 +13104,7 @@ void EmitPass::emitPhaseInput(llvm::GenIntrinsicInst* inst)
1310313104
assert(psProgram->GetPhase() == PSPHASE_PIXEL);
1310413105

1310513106
unsigned int inputIndex = (unsigned int)cast<llvm::ConstantInt>(inst->getOperand(0))->getZExtValue();
13106-
CVariable* input = psProgram->GetCoarseInput(inputIndex);
13107+
CVariable* input = psProgram->GetCoarseInput(inputIndex, m_destination->GetType());
1310713108

1310813109
// address variable represents register a0
1310913110
CVariable* pDstArrElm = m_currShader->GetNewAddressVariable(
@@ -13115,7 +13116,8 @@ void EmitPass::emitPhaseInput(llvm::GenIntrinsicInst* inst)
1311513116
// we add offsets to the base that is the beginning of the vector variable
1311613117
CVariable* index = psProgram->GetCoarseParentIndex();
1311713118
CVariable* byteAddress = psProgram->GetNewVariable(numLanes(m_SimdMode), ISA_TYPE_UW, EALIGN_OWORD);
13118-
m_encoder->Shl(byteAddress, index, psProgram->ImmToVariable(2, ISA_TYPE_UW));
13119+
DWORD shiftAmount = iSTD::Log2(CEncoder::GetCISADataTypeSize(input->GetType()));
13120+
m_encoder->Shl(byteAddress, index, psProgram->ImmToVariable(shiftAmount, ISA_TYPE_UW));
1311913121
m_encoder->Push();
1312013122

1312113123
m_encoder->AddrAdd(pDstArrElm, input, byteAddress);

IGC/Compiler/CISACodeGen/PixelShaderCodeGen.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ namespace IGC
5252
return m_R1;
5353
}
5454

55+
CVariable* CPixelShader::GetCoarseR1()
56+
{
57+
assert(m_phase == PSPHASE_PIXEL);
58+
return m_CoarseR1;
59+
}
60+
5561
void CPixelShader::AllocatePayload()
5662
{
5763
if (m_phase == PSPHASE_COARSE)
@@ -74,6 +80,8 @@ namespace IGC
7480

7581
void CPixelShader::AllocatePixelPhasePayload()
7682
{
83+
unsigned int r1Offset = GetDispatchSignature().r1;
84+
AllocateInput(m_CoarseR1, r1Offset);
7785
for (uint i = 0; i < setup.size(); i++)
7886
{
7987
if (setup[i])
@@ -126,6 +134,10 @@ namespace IGC
126134
offset += getGRFSize();
127135

128136
assert(m_R1);
137+
if (m_Signature)
138+
{
139+
GetDispatchSignature().r1 = offset;
140+
}
129141
for (uint i = 0; i < m_R1->GetNumberInstance(); i++)
130142
{
131143
AllocateInput(m_R1, offset, i);
@@ -651,6 +663,7 @@ namespace IGC
651663
m_NeedPSSync = false;
652664
m_CoarseoMask = nullptr;
653665
m_CoarseMaskInput = nullptr;
666+
m_CoarseR1 = nullptr;
654667

655668
m_CoarseOutput.clear();
656669
m_CoarseInput.clear();
@@ -980,6 +993,7 @@ namespace IGC
980993
if (m_phase == PSPHASE_PIXEL)
981994
{
982995
uint responseLength = 2;
996+
m_CoarseR1 = m_R1;
983997
m_PixelPhasePayload = GetNewVariable(responseLength * (getGRFSize() >> 2), ISA_TYPE_D, EALIGN_GRF);
984998
m_PixelPhaseCounter = GetNewAlias(m_PixelPhasePayload, ISA_TYPE_UW, 0, 1);
985999
m_CoarseParentIndex = GetNewAlias(m_PixelPhasePayload, ISA_TYPE_UW, getGRFSize(), numLanes(m_SIMDSize));
@@ -1015,7 +1029,6 @@ namespace IGC
10151029
encoder.Push();
10161030
}
10171031
encoder.SetPredicate(m_KillPixelMask);
1018-
encoder.SetInversePredicate(true);
10191032
encoder.Copy(m_CoarseoMask, ImmToVariable(0x0, ISA_TYPE_UD));
10201033
encoder.Push();
10211034
}
@@ -1044,13 +1057,13 @@ namespace IGC
10441057
m_CoarseOutput[index] = output;
10451058
}
10461059

1047-
CVariable* CPixelShader::GetCoarseInput(unsigned int index)
1060+
CVariable* CPixelShader::GetCoarseInput(unsigned int index, VISA_Type type)
10481061
{
10491062
auto it = m_CoarseInput.find(index);
10501063
CVariable* coarseInput = nullptr;
10511064
if (it == m_CoarseInput.end())
10521065
{
1053-
coarseInput = GetNewVariable(numLanes(m_SIMDSize), ISA_TYPE_F, EALIGN_GRF);
1066+
coarseInput = GetNewVariable(numLanes(m_SIMDSize), type, EALIGN_GRF);
10541067
m_CoarseInput[index] = coarseInput;
10551068
}
10561069
else
@@ -1362,6 +1375,7 @@ namespace IGC
13621375
// if there is no pixel phase we have nothing to do
13631376
return;
13641377
}
1378+
encoder.MarkAsOutput(m_R1);
13651379
Function* pixelPhase = mdconst::dyn_extract<Function>(pixelNode->getOperand(0)->getOperand(0));
13661380
for (auto BB = pixelPhase->begin(), BE = pixelPhase->end(); BB != BE; ++BB)
13671381
{

IGC/Compiler/CISACodeGen/PixelShaderCodeGen.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ namespace IGC
3939
unsigned int pixelOffset;
4040
unsigned int ZWDelta;
4141
unsigned int oMaskOffset;
42+
unsigned int r1;
4243
bool CoarseMask;
4344
DispatchSignature() : CoarseMask(false) {}
4445
};
4546
DispatchSignature dispatchSign[3];
47+
std::map<unsigned int, uint64_t> PSConstantOutput;
4648
};
4749

4850

@@ -52,6 +54,7 @@ namespace IGC
5254
CPixelShader(llvm::Function* pFunc, CShaderProgram* pProgram);
5355
~CPixelShader();
5456
CVariable* GetR1();
57+
CVariable* GetCoarseR1();
5558
CVariable* GetBaryReg(e_interpolation mode);
5659
CVariable* GetBaryRegLowered(e_interpolation mode);
5760
CVariable* GetInputDelta(uint index, bool loweredInput = false);
@@ -91,7 +94,7 @@ namespace IGC
9194
void PullPixelPhasePayload();
9295

9396
void AddCoarseOutput(CVariable* var, unsigned int index);
94-
CVariable* GetCoarseInput(unsigned int index);
97+
CVariable* GetCoarseInput(unsigned int index, VISA_Type type);
9598
void SetCoarseoMask(CVariable* var);
9699
CVariable* GetCoarseMask();
97100
void OutputDepth() { m_HasoDepth = true; };
@@ -128,6 +131,7 @@ namespace IGC
128131

129132
PSSignature::DispatchSignature& GetDispatchSignature();
130133
CVariable* m_R1;
134+
CVariable* m_CoarseR1;
131135
CVariable* m_PerspectivePixel;
132136
CVariable* m_PerspectiveCentroid;
133137
CVariable* m_PerspectiveSample;

0 commit comments

Comments
 (0)