Skip to content

Commit

Permalink
[ViewID] build viewid mask for primitive output
Browse files Browse the repository at this point in the history
Currently, viewid mask for primitive output is always empty.
This change will fix it by treat entry as PC entry.

For #6817
  • Loading branch information
python3kgae committed Aug 28, 2024
1 parent b766b43 commit 57ad149
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions lib/HLSL/ComputeViewIdStateBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ class DxilViewIdStateBuilder {
// Contributing instructions per output.
std::unordered_map<unsigned, InstructionSetType>
ContributingInstructions[kNumStreams];

bool IsForPatchConstantOrPrimitive;
EntryInfo(bool ForPC) : IsForPatchConstantOrPrimitive(ForPC) {}
void Clear();
};

EntryInfo m_Entry;
EntryInfo m_PCEntry;
EntryInfo m_Entry = EntryInfo{false};
EntryInfo m_PCEntry = EntryInfo{true};

// Information per function.
using FunctionReturnSet = std::unordered_set<llvm::ReturnInst *>;
Expand Down Expand Up @@ -190,9 +191,12 @@ void DxilViewIdStateBuilder::Compute() {
CallGraph CG = CGA.run(m_pModule->GetModule());
m_Entry.pEntryFunc = m_pModule->GetEntryFunction();
m_PCEntry.pEntryFunc = m_pModule->GetPatchConstantFunction();
// For MS, use main entry as PC entry to collect primitive outputs.
if (pSM->IsMS())
m_PCEntry.pEntryFunc = m_pModule->GetEntryFunction();
ComputeReachableFunctionsRec(CG, CG[m_Entry.pEntryFunc], m_Entry.Functions);
if (m_PCEntry.pEntryFunc) {
DXASSERT_NOMSG(pSM->IsHS());
DXASSERT_NOMSG(pSM->IsHS() || pSM->IsMS());
ComputeReachableFunctionsRec(CG, CG[m_PCEntry.pEntryFunc],
m_PCEntry.Functions);
}
Expand Down Expand Up @@ -461,6 +465,7 @@ void DxilViewIdStateBuilder::CollectValuesContributingToOutputs(
unsigned id = (unsigned)-1;
int startRow = Semantic::kUndefinedRow, endRow = Semantic::kUndefinedRow;
unsigned col = (unsigned)-1;
bool IsForPatchConstantOrPrimitive = false;
if (DxilInst_StoreOutput SO = DxilInst_StoreOutput(CI)) {
pDxilSig = &m_pModule->GetOutputSignature();
pContributingValue = SO.get_value();
Expand All @@ -481,17 +486,23 @@ void DxilViewIdStateBuilder::CollectValuesContributingToOutputs(
GetUnsignedVal(SPO.get_outputSigId(), &id);
GetUnsignedVal(SPO.get_colIndex(), &col);
GetUnsignedVal(SPO.get_rowIndex(), (uint32_t *)&startRow);
IsForPatchConstantOrPrimitive = true;
} else if (DxilInst_StorePatchConstant SPC =
DxilInst_StorePatchConstant(CI)) {
pDxilSig = &m_pModule->GetPatchConstOrPrimSignature();
pContributingValue = SPC.get_value();
GetUnsignedVal(SPC.get_outputSigID(), &id);
GetUnsignedVal(SPC.get_row(), (uint32_t *)&startRow);
GetUnsignedVal(SPC.get_col(), &col);
IsForPatchConstantOrPrimitive = true;
} else {
IFT(DXC_E_GENERAL_INTERNAL_ERROR);
}

// Skip vertex outputs for MS when check primitive outputs.
if (IsForPatchConstantOrPrimitive != Entry.IsForPatchConstantOrPrimitive)
continue;

DxilSignatureElement &SigElem = pDxilSig->GetElement(id);
if (!SigElem.IsAllocated())
continue;
Expand Down
4 changes: 2 additions & 2 deletions tools/clang/test/DXC/dumpPSV_MS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
// CHECK-NEXT: Outputs affected by ViewID as a bitmask for stream 0:
// CHECK-NEXT: ViewID influencing Outputs[0] : 0 1 2 3 4 8 12 16
// CHECK-NEXT: PCOutputs affected by ViewID as a bitmask:
// CHECK-NEXT: ViewID influencing PCOutputs : None
// CHECK-NEXT: ViewID influencing PCOutputs : 3
// CHECK-NEXT: Outputs affected by inputs as a table of bitmasks for stream 0:
// CHECK-NEXT: Inputs contributing to computation of Outputs[0]: None

Expand Down Expand Up @@ -189,7 +189,7 @@ void main(
op.normal = mpl.normal;
op.malnor = gsMem[tig / 3 + 1];
op.alnorm = mpl.alnorm;
op.ormaln = mpl.ormaln;
op.ormaln = mpl.ormaln + vid;
op.layer[0] = mpl.layer[0];
op.layer[1] = mpl.layer[1];
op.layer[2] = mpl.layer[2];
Expand Down

0 comments on commit 57ad149

Please sign in to comment.