Skip to content

Commit a32d7ef

Browse files
mmereckigfxbot
authored andcommitted
In CPS mode source depth and source w have to be interpolated. HW intrpolated values annot be used with CPS
Change-Id: I32e122a2d832089a612761e9b66935e854efaead
1 parent 144be7e commit a32d7ef

File tree

5 files changed

+117
-60
lines changed

5 files changed

+117
-60
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6664,13 +6664,76 @@ void EmitPass::emitPSSGV(GenIntrinsicInst* inst)
66646664
{
66656665
if (psProgram->GetPhase() == PSPHASE_PIXEL || psProgram->GetPhase() == PSPHASE_COARSE)
66666666
{
6667-
e_interpolation mode = EINTERPOLATION_LINEAR;
6668-
CVariable* bary = psProgram->GetBaryReg(mode);
6669-
CVariable* delta =
6670-
(usage == POSITION_Z) ? psProgram->GetZDelta() : psProgram->GetWDelta();
6671-
m_encoder->SetSrcRegion(0, 0, 4, 1);
6672-
m_encoder->Pln(m_destination, delta, bary);
6667+
// source depth:
6668+
// src_z = (x - xstart)*z_cx + (y - ystart)*z_cy + z_c0
6669+
// source w:
6670+
// src_w = 1/((x - xstart)*1w_cx + (y - ystart)*1w_cy + 1w_c0)
6671+
CVariable* delta = psProgram->GetZWDelta();
6672+
6673+
CVariable* floatR1 = psProgram->BitCast(psProgram->GetR1(), ISA_TYPE_F);
6674+
6675+
// Returns (x - xstart) or (y - ystart) in float.
6676+
auto getPixelPositionDelta = [this, psProgram, delta, floatR1](const uint component)->CVariable*
6677+
{
6678+
assert(component < 2);
6679+
CVariable* uintPixelPosition =
6680+
m_currShader->GetNewVariable(numLanes(m_currShader->m_SIMDSize), ISA_TYPE_UW, EALIGN_GRF);
6681+
getPixelPosition(uintPixelPosition, component);
6682+
6683+
CVariable* floatPixelPosition =
6684+
m_currShader->GetNewVariable(numLanes(m_currShader->m_SIMDSize), ISA_TYPE_F, EALIGN_GRF);
6685+
m_encoder->Cast(floatPixelPosition, uintPixelPosition);
6686+
m_encoder->Push();
6687+
6688+
CVariable* floatPixelPositionDelta = floatPixelPosition; //reuse the same variable for the final delta
6689+
6690+
m_encoder->SetSrcRegion(1, 0, 1, 0);
6691+
CVariable* startCoordinate = floatR1;
6692+
uint topLeftVertexStartSubReg = (component == 0 ? 1 : 6); // R1.1 for XStart and R1.6 for YStart
6693+
if (psProgram->m_Platform->hasStartCoordinatesDeliveredWithDeltas())
6694+
{
6695+
startCoordinate = delta;
6696+
topLeftVertexStartSubReg = (component == 0 ? 2 : 6);
6697+
}
6698+
6699+
m_encoder->SetSrcSubReg(1, topLeftVertexStartSubReg);
6700+
m_encoder->SetSrcModifier(1, EMOD_NEG);
6701+
m_encoder->Add(floatPixelPositionDelta, floatPixelPosition, startCoordinate);
6702+
m_encoder->Push();
6703+
6704+
return floatPixelPositionDelta;
6705+
};
6706+
const uint componentX = 0;
6707+
const uint componentY = 1;
6708+
// (x - xstart)
6709+
CVariable* floatPixelPositionDeltaX = getPixelPositionDelta(componentX);
6710+
// (y - ystart)
6711+
CVariable* floatPixelPositionDeltaY = getPixelPositionDelta(componentY);
6712+
6713+
// (y - ystart)*z_cy + z_c0
6714+
{
6715+
m_encoder->SetSrcRegion(1, 0, 1, 0);
6716+
m_encoder->SetSrcRegion(2, 0, 1, 0);
6717+
}
6718+
m_encoder->SetSrcSubReg(1, usage == POSITION_Z ? 0 : 4);
6719+
m_encoder->SetSrcSubReg(2, usage == POSITION_Z ? 3 : 7);
6720+
m_encoder->Mad(floatPixelPositionDeltaY, floatPixelPositionDeltaY, delta, delta);
66736721
m_encoder->Push();
6722+
6723+
// (x - xstart)*z_cx + (y - ystart)*z_cy + z_c0
6724+
{
6725+
m_encoder->SetSrcRegion(1, 0, 1, 0);
6726+
}
6727+
m_encoder->SetSrcSubReg(1, usage == POSITION_Z ? 1 : 5);
6728+
m_encoder->Mad(m_destination, floatPixelPositionDeltaX, delta, floatPixelPositionDeltaY);
6729+
m_encoder->Push();
6730+
6731+
if (usage == POSITION_W)
6732+
{
6733+
// 1/w -> w
6734+
m_encoder->Inv(m_destination, m_destination);
6735+
m_encoder->Push();
6736+
}
66746737
}
66756738
else
66766739
{
@@ -6897,20 +6960,27 @@ void EmitPass::emitHSSGV(llvm::GenIntrinsicInst* pInst)
68976960
}
68986961
}
68996962

6900-
void EmitPass::emitPixelPosition(llvm::GenIntrinsicInst* inst)
6963+
6964+
// Store integer pixel position in the destination variable.
6965+
// Only X and Y components are handled here!
6966+
void EmitPass::getPixelPosition(CVariable* destination, const uint component)
69016967
{
6968+
assert(component < 2);
6969+
assert(destination && m_encoder->IsIntegerType(destination->GetType()));
6970+
6971+
const bool getX = (component == 0);
6972+
69026973
CPixelShader* psProgram = static_cast<CPixelShader*>(m_currShader);
6903-
GenISAIntrinsic::ID IID = inst->getIntrinsicID();
69046974
CVariable* imm = m_currShader->ImmToVariable(
6905-
IID == GenISAIntrinsic::GenISA_PixelPositionX ? 0x10101010 : 0x11001100, ISA_TYPE_V);
6975+
getX ? 0x10101010 : 0x11001100, ISA_TYPE_V);
69066976
CVariable* pixelSize = nullptr;
69076977
if (psProgram->GetPhase() == PSPHASE_COARSE)
69086978
{
69096979
CVariable* CPSize = m_currShader->BitCast(psProgram->GetR1(), ISA_TYPE_UB);
69106980
pixelSize =
69116981
m_currShader->GetNewVariable(numLanes(m_currShader->m_SIMDSize), ISA_TYPE_UW, EALIGN_GRF);
69126982
m_encoder->SetSrcRegion(0, 0, 1, 0);
6913-
m_encoder->SetSrcSubReg(0, IID == GenISAIntrinsic::GenISA_PixelPositionX ? 0 : 1);
6983+
m_encoder->SetSrcSubReg(0, getX ? 0 : 1);
69146984
m_encoder->Mul(pixelSize, CPSize, imm);
69156985
m_encoder->Push();
69166986
}
@@ -6921,11 +6991,19 @@ void EmitPass::emitPixelPosition(llvm::GenIntrinsicInst* inst)
69216991
CVariable* position = m_currShader->BitCast(psProgram->GetR1(), ISA_TYPE_UW);
69226992
m_encoder->SetSrcRegion(0, 2, 4, 0);
69236993
// subreg 4 as position_x and subreg 5 as position_y
6924-
m_encoder->SetSrcSubReg(0, IID == GenISAIntrinsic::GenISA_PixelPositionX ? 4 : 5);
6925-
m_encoder->Add(m_destination, position, pixelSize);
6994+
m_encoder->SetSrcSubReg(0, getX ? 4 : 5);
6995+
m_encoder->Add(destination, position, pixelSize);
69266996
m_encoder->Push();
69276997
}
69286998

6999+
7000+
void EmitPass::emitPixelPosition(llvm::GenIntrinsicInst* inst)
7001+
{
7002+
const GenISAIntrinsic::ID IID = inst->getIntrinsicID();
7003+
const uint component = IID == GenISAIntrinsic::GenISA_PixelPositionX ? 0 : 1;
7004+
getPixelPosition(m_destination, component);
7005+
}
7006+
69297007
void EmitPass::emitSGV(SGVIntrinsic* inst)
69307008
{
69317009
switch (m_currShader->GetShaderType())

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ class EmitPass : public llvm::FunctionPass
304304
void emitSGV(llvm::SGVIntrinsic* inst);
305305
void emitPSSGV(llvm::GenIntrinsicInst* inst);
306306
void emitCSSGV(llvm::GenIntrinsicInst* inst);
307+
void getPixelPosition(CVariable* destination, const uint component);
307308
void emitPixelPosition(llvm::GenIntrinsicInst* inst);
308309
void emitPhaseOutput(llvm::GenIntrinsicInst* inst);
309310
void emitPhaseInput(llvm::GenIntrinsicInst* inst);

IGC/Compiler/CISACodeGen/PixelShaderCodeGen.cpp

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,11 @@ namespace IGC
8888
AllocateInput(setup[i], offset + subRegOffset);
8989
}
9090
}
91-
if (m_ZDelta || m_WDelta)
91+
if (m_ZWDelta)
9292
{
9393
unsigned int offset = GetDispatchSignature().ZWDelta;
94-
if (m_ZDelta)
95-
{
96-
AllocateInput(m_ZDelta, offset);
97-
}
98-
if (m_WDelta)
99-
{
100-
AllocateInput(m_WDelta, offset + SIZE_OWORD);
101-
}
102-
}
94+
AllocateInput(m_ZWDelta, offset);
95+
}
10396
if (m_SampleOffsetX || m_SampleOffsetY)
10497
{
10598
unsigned int offset = GetDispatchSignature().pixelOffset;
@@ -212,16 +205,9 @@ namespace IGC
212205
}
213206
offset += getGRFSize();
214207
}
215-
if (m_ZDelta || m_WDelta)
208+
if (m_ZWDelta)
216209
{
217-
if (m_ZDelta)
218-
{
219-
AllocateInput(m_ZDelta, offset, i);
220-
}
221-
if (m_WDelta)
222-
{
223-
AllocateInput(m_WDelta, offset + SIZE_OWORD, i);
224-
}
210+
AllocateInput(m_ZWDelta, offset, i);
225211
if (m_Signature)
226212
{
227213
GetDispatchSignature().ZWDelta = offset;
@@ -484,26 +470,19 @@ namespace IGC
484470
return inputVar;
485471
}
486472

487-
CVariable* CPixelShader::GetZDelta()
473+
CVariable* CPixelShader::GetZWDelta()
488474
{
489-
if (!m_ZDelta)
475+
if (!m_ZWDelta)
490476
{
491-
m_ZDelta =
492-
GetNewVariable(4, ISA_TYPE_F, EALIGN_OWORD, false, m_numberInstance);
493-
}
494-
return m_ZDelta;
495-
}
477+
uint numLanes = 8; // single GRF
496478

497-
CVariable* CPixelShader::GetWDelta()
498-
{
499-
if (!m_WDelta)
500-
{
501-
m_WDelta =
502-
GetNewVariable(4, ISA_TYPE_F, EALIGN_OWORD, false, m_numberInstance);
479+
m_ZWDelta =
480+
GetNewVariable(numLanes, ISA_TYPE_F, EALIGN_GRF, false, m_numberInstance);
503481
}
504-
return m_WDelta;
482+
return m_ZWDelta;
505483
}
506484

485+
507486
CVariable* CPixelShader::GetPositionZ()
508487
{
509488
if (!m_pPositionZPixel)
@@ -666,8 +645,7 @@ namespace IGC
666645
m_PixelPhaseCounter = nullptr;
667646
m_SampleOffsetX = nullptr;
668647
m_SampleOffsetY = nullptr;
669-
m_ZDelta = nullptr;
670-
m_WDelta = nullptr;
648+
m_ZWDelta = nullptr;
671649
m_hasEOT = false;
672650
m_NeedPSSync = false;
673651
m_CoarseoMask = nullptr;
@@ -733,7 +711,7 @@ namespace IGC
733711
pKernelProgram->isCoarsePS = m_phase == PSPHASE_COARSE;
734712
pKernelProgram->hasCoarsePixelSize = m_HasCoarseSize;
735713
pKernelProgram->hasSampleOffset = m_SampleOffsetX || m_SampleOffsetY;
736-
pKernelProgram->hasZWDelta = m_ZDelta || m_WDelta;
714+
pKernelProgram->hasZWDelta = m_ZWDelta;
737715
pKernelProgram->ConstantBufferLoaded = m_constantBufferLoaded;
738716
pKernelProgram->hasControlFlow = m_numBlocks > 1 ? true : false;
739717
pKernelProgram->MaxNumberOfThreads = m_Platform->getMaxPixelShaderThreads();
@@ -1370,15 +1348,10 @@ namespace IGC
13701348
else if (IID == GenISAIntrinsic::GenISA_DCL_SystemValue)
13711349
{
13721350
SGVUsage usage = (SGVUsage)llvm::cast<llvm::ConstantInt>(intr->getOperand(0))->getZExtValue();
1373-
if (usage == POSITION_Z)
1374-
{
1375-
CVariable* offset = GetZDelta();
1376-
encoder.MarkAsOutput(offset);
1377-
}
1378-
if (usage == POSITION_W)
1351+
if (usage == POSITION_Z || usage == POSITION_W)
13791352
{
1380-
CVariable* offset = GetWDelta();
1381-
encoder.MarkAsOutput(offset);
1353+
CVariable* deltas = GetZWDelta();
1354+
encoder.MarkAsOutput(deltas);
13821355
}
13831356
}
13841357
}

IGC/Compiler/CISACodeGen/PixelShaderCodeGen.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class CPixelShader : public CShader
5656
CVariable* GetBaryRegLowered(e_interpolation mode);
5757
CVariable* GetInputDelta(uint index, bool loweredInput = false);
5858
CVariable* GetInputDeltaLowered(uint index);
59-
CVariable* GetZDelta();
60-
CVariable* GetWDelta();
59+
CVariable* GetZWDelta();
6160
CVariable* GetPositionZ();
6261
CVariable* GetPositionW();
6362
CVariable* GetPositionXYOffset();
@@ -145,8 +144,7 @@ class CPixelShader : public CShader
145144
CVariable* m_pPositionZPixel;
146145
CVariable* m_pPositionWPixel;
147146
CVariable* m_pPositionXYOffset;
148-
CVariable* m_ZDelta;
149-
CVariable* m_WDelta;
147+
CVariable* m_ZWDelta;
150148
CVariable* m_pInputCoverageMask;
151149
CVariable* m_pCPSRequestedSizeX;
152150
CVariable* m_pCPSRequestedSizeY;

IGC/Compiler/CISACodeGen/Platform.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ class CPlatform
334334
return 32;
335335
}
336336

337+
// If true then screen space coordinates for upper-left vertex of a triangle
338+
// being rasterized are delivered together with source depth or W deltas.
339+
bool hasStartCoordinatesDeliveredWithDeltas() const
340+
{
341+
return false;
342+
}
343+
337344
uint32_t maxPerThreadScratchSpace() const
338345
{
339346
return 0x200000;

0 commit comments

Comments
 (0)