Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Validator] Check content of PSV0 part in validation #6859

Merged
merged 23 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions include/dxc/DxilContainer/DxilPipelineStateValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ struct PSVComponentMask {
}
return *this;
}
bool operator!=(const PSVComponentMask &other) const {
if (NumVectors != other.NumVectors)
return true;
return memcmp(Mask, other.Mask,
PSVComputeMaskDwordsFromVectors(NumVectors) *
sizeof(uint32_t));
}
bool Get(uint32_t ComponentIndex) const {
if (ComponentIndex < NumVectors * 4)
return (bool)(Mask[ComponentIndex >> 5] & (1 << (ComponentIndex & 0x1F)));
Expand Down Expand Up @@ -295,6 +302,15 @@ struct PSVDependencyTable {
const PSVComponentMask GetMaskForInput(uint32_t inputComponentIndex) const {
return getMaskForInput(inputComponentIndex);
}
bool operator!=(const PSVDependencyTable &other) const {
if (InputVectors != other.InputVectors ||
OutputVectors != other.OutputVectors)
return true;
return memcmp(
Table, other.Table,
PSVComputeInputOutputTableDwords(InputVectors, OutputVectors) *
sizeof(uint32_t));
}
bool IsValid() const { return Table != nullptr; }
void Print(llvm::raw_ostream &, const char *, const char *) const;

Expand Down Expand Up @@ -449,6 +465,8 @@ class PSVSignatureElement {
return !m_pElement0 ? 0 : (uint32_t)m_pElement0->DynamicMaskAndStream & 0xF;
}
void Print(llvm::raw_ostream &O) const;
void Print(llvm::raw_ostream &O, const char *Name,
const uint32_t *SemanticIndexes) const;
};

#define MAX_PSV_VERSION 3
Expand Down Expand Up @@ -595,6 +613,14 @@ class DxilPipelineStateValidation {
return ReadOrWrite(pBuffer, pSize, Mode, initInfo);
}

uint32_t GetRuntimeInfoSize() const { return m_uPSVRuntimeInfoSize; }
uint32_t GetResourceBindInfoSize() const {
return m_uPSVResourceBindInfoSize;
}
uint32_t GetSignatureElementSize() const {
return m_uPSVSignatureElementSize;
}

PSVRuntimeInfo0 *GetPSVRuntimeInfo0() const { return m_pPSVRuntimeInfo0; }

PSVRuntimeInfo1 *GetPSVRuntimeInfo1() const { return m_pPSVRuntimeInfo1; }
Expand Down Expand Up @@ -752,6 +778,7 @@ class DxilPipelineStateValidation {
}
void PrintPSVRuntimeInfo(llvm::raw_ostream &O, uint8_t ShaderKind,
const char *Comment) const;
void PrintViewIDState(llvm::raw_ostream &OS) const;
void Print(llvm::raw_ostream &O, uint8_t ShaderKind) const;
};

Expand Down Expand Up @@ -1084,6 +1111,9 @@ class ViewIDValidator {
ViewIDValidator *NewViewIDValidator(unsigned viewIDCount,
unsigned gsRastStreamIndex);

uint32_t GetPSVVersion(uint32_t ValidatorMajorVersion,
uint32_t ValidatorMinorVersion);

void InitPSVResourceBinding(PSVResourceBindInfo0 *, PSVResourceBindInfo1 *,
DxilResourceBase *);

Expand All @@ -1099,6 +1129,11 @@ void InitPSVRuntimeInfo(PSVRuntimeInfo0 *pInfo, PSVRuntimeInfo1 *pInfo1,
PSVRuntimeInfo2 *pInfo2, PSVRuntimeInfo3 *pInfo3,
const DxilModule &DM);

void PrintPSVRuntimeInfo(llvm::raw_ostream &OS, PSVRuntimeInfo0 *pInfo0,
PSVRuntimeInfo1 *pInfo1, PSVRuntimeInfo2 *pInfo2,
PSVRuntimeInfo3 *pInfo3, uint8_t ShaderKind,
const char *EntryName, const char *Comment);

} // namespace hlsl

#undef PSV_RETB
Expand Down
21 changes: 7 additions & 14 deletions lib/DxilContainer/DxilContainerAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ static_assert((unsigned)PSVShaderKind::Invalid ==
(unsigned)DXIL::ShaderKind::Invalid,
"otherwise, PSVShaderKind enum out of sync.");

static DxilProgramSigSemantic
KindToSystemValue(Semantic::Kind kind, DXIL::TessellatorDomain domain) {
DxilProgramSigSemantic
hlsl::SemanticKindToSystemValue(Semantic::Kind kind,
DXIL::TessellatorDomain domain) {
switch (kind) {
case Semantic::Kind::Arbitrary:
return DxilProgramSigSemantic::Undefined;
Expand Down Expand Up @@ -291,7 +292,7 @@ class DxilProgramSignatureWriter : public DxilPartWriter {
memset(&sig, 0, sizeof(DxilProgramSignatureElement));
sig.Stream = pElement->GetOutputStream();
sig.SemanticName = GetSemanticOffset(pElement);
sig.SystemValue = KindToSystemValue(pElement->GetKind(), m_domain);
sig.SystemValue = SemanticKindToSystemValue(pElement->GetKind(), m_domain);
sig.CompType =
CompTypeToSigCompType(pElement->GetCompType().GetKind(), m_bCompat_1_4);
sig.Register = pElement->GetStartRow();
Expand Down Expand Up @@ -738,17 +739,9 @@ class DxilPSVWriter : public DxilPartWriter {
: m_Module(mod), m_PSVInitInfo(PSVVersion) {
m_Module.GetValidatorVersion(m_ValMajor, m_ValMinor);
// Constraint PSVVersion based on validator version
if (PSVVersion > 0 &&
DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 1) < 0)
m_PSVInitInfo.PSVVersion = 0;
else if (PSVVersion > 1 &&
DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 6) < 0)
m_PSVInitInfo.PSVVersion = 1;
else if (PSVVersion > 2 &&
DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 8) < 0)
m_PSVInitInfo.PSVVersion = 2;
else if (PSVVersion > MAX_PSV_VERSION)
m_PSVInitInfo.PSVVersion = MAX_PSV_VERSION;
uint32_t PSVVersionConstraint = hlsl::GetPSVVersion(m_ValMajor, m_ValMinor);
if (PSVVersion > PSVVersionConstraint)
m_PSVInitInfo.PSVVersion = PSVVersionConstraint;

const ShaderModel *SM = m_Module.GetShaderModel();
UINT uCBuffers = m_Module.GetCBuffers().size();
Expand Down
155 changes: 91 additions & 64 deletions lib/DxilContainer/DxilPipelineStateValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
using namespace hlsl;
using namespace llvm;

uint32_t hlsl::GetPSVVersion(uint32_t ValMajor, uint32_t ValMinor) {
unsigned PSVVersion = MAX_PSV_VERSION;
// Constraint PSVVersion based on validator version
if (DXIL::CompareVersions(ValMajor, ValMinor, 1, 1) < 0)
PSVVersion = 0;
else if (DXIL::CompareVersions(ValMajor, ValMinor, 1, 6) < 0)
PSVVersion = 1;
else if (DXIL::CompareVersions(ValMajor, ValMinor, 1, 8) < 0)
PSVVersion = 2;
return PSVVersion;
}

void hlsl::InitPSVResourceBinding(PSVResourceBindInfo0 *Bind0,
PSVResourceBindInfo1 *Bind1,
DxilResourceBase *Res) {
Expand Down Expand Up @@ -360,10 +372,14 @@ void PSVResourceBindInfo1::Print(raw_ostream &OS) const {
}

void PSVSignatureElement::Print(raw_ostream &OS) const {
Print(OS, GetSemanticName(), GetSemanticIndexes());
}

void PSVSignatureElement::Print(raw_ostream &OS, const char *Name,
const uint32_t *SemanticIndexes) const {
OS << "PSVSignatureElement:\n";
OS << " SemanticName: " << GetSemanticName() << "\n";
OS << " SemanticName: " << Name << "\n";
OS << " SemanticIndex: ";
const uint32_t *SemanticIndexes = GetSemanticIndexes();
for (unsigned i = 0; i < GetRows(); ++i) {
OS << *(SemanticIndexes + i) << " ";
}
Expand Down Expand Up @@ -518,13 +534,10 @@ void PSVDependencyTable::Print(raw_ostream &OS, const char *InputSetName,
}
}

void DxilPipelineStateValidation::PrintPSVRuntimeInfo(
raw_ostream &OS, uint8_t ShaderKind, const char *Comment) const {
PSVRuntimeInfo0 *pInfo0 = m_pPSVRuntimeInfo0;
PSVRuntimeInfo1 *pInfo1 = m_pPSVRuntimeInfo1;
PSVRuntimeInfo2 *pInfo2 = m_pPSVRuntimeInfo2;
PSVRuntimeInfo3 *pInfo3 = m_pPSVRuntimeInfo3;

void hlsl::PrintPSVRuntimeInfo(llvm::raw_ostream &OS, PSVRuntimeInfo0 *pInfo0,
PSVRuntimeInfo1 *pInfo1, PSVRuntimeInfo2 *pInfo2,
PSVRuntimeInfo3 *pInfo3, uint8_t ShaderKind,
const char *EntryName, const char *Comment) {
if (pInfo1 && pInfo1->ShaderStage != ShaderKind)
ShaderKind = pInfo1->ShaderStage;
OS << Comment << "PSVRuntimeInfo:\n";
Expand Down Expand Up @@ -817,9 +830,74 @@ void DxilPipelineStateValidation::PrintPSVRuntimeInfo(
}
}
if (pInfo3)
OS << Comment
<< " EntryFunctionName: " << m_StringTable.Get(pInfo3->EntryFunctionName)
<< "\n";
OS << Comment << " EntryFunctionName: " << EntryName << "\n";
}

void DxilPipelineStateValidation::PrintPSVRuntimeInfo(
raw_ostream &OS, uint8_t ShaderKind, const char *Comment) const {
PSVRuntimeInfo0 *pInfo0 = m_pPSVRuntimeInfo0;
PSVRuntimeInfo1 *pInfo1 = m_pPSVRuntimeInfo1;
PSVRuntimeInfo2 *pInfo2 = m_pPSVRuntimeInfo2;
PSVRuntimeInfo3 *pInfo3 = m_pPSVRuntimeInfo3;

hlsl::PrintPSVRuntimeInfo(
OS, pInfo0, pInfo1, pInfo2, pInfo3, ShaderKind,
m_pPSVRuntimeInfo3 ? m_StringTable.Get(pInfo3->EntryFunctionName) : "",
Comment);
}

void DxilPipelineStateValidation::PrintViewIDState(raw_ostream &OS) const {
pow2clk marked this conversation as resolved.
Show resolved Hide resolved
unsigned NumStreams = IsGS() ? PSV_GS_MAX_STREAMS : 1;

if (m_pPSVRuntimeInfo1->UsesViewID) {
for (unsigned i = 0; i < NumStreams; ++i) {
OS << "Outputs affected by ViewID as a bitmask for stream " << i
<< ":\n ";
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigOutputVectors[i];
const PSVComponentMask ViewIDMask(m_pViewIDOutputMask[i], OutputVectors);
std::string OutputSetName = "Outputs";
OutputSetName += "[" + std::to_string(i) + "]";
ViewIDMask.Print(OS, "ViewID", OutputSetName.c_str());
}

if (IsHS() || IsMS()) {
OS << "PCOutputs affected by ViewID as a bitmask:\n";
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigPatchConstOrPrimVectors;
const PSVComponentMask ViewIDMask(m_pViewIDPCOrPrimOutputMask,
OutputVectors);
ViewIDMask.Print(OS, "ViewID", "PCOutputs");
}
}

for (unsigned i = 0; i < NumStreams; ++i) {
OS << "Outputs affected by inputs as a table of bitmasks for stream " << i
<< ":\n";
uint8_t InputVectors = m_pPSVRuntimeInfo1->SigInputVectors;
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigOutputVectors[i];
const PSVDependencyTable Table(m_pInputToOutputTable[i], InputVectors,
OutputVectors);
std::string OutputSetName = "Outputs";
OutputSetName += "[" + std::to_string(i) + "]";
Table.Print(OS, "Inputs", OutputSetName.c_str());
}

if (IsHS()) {
OS << "Patch constant outputs affected by inputs as a table of "
"bitmasks:\n";
uint8_t InputVectors = m_pPSVRuntimeInfo1->SigInputVectors;
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigPatchConstOrPrimVectors;
const PSVDependencyTable Table(m_pInputToPCOutputTable, InputVectors,
OutputVectors);
Table.Print(OS, "Inputs", "PatchConstantOutputs");
} else if (IsDS()) {
OS << "Outputs affected by patch constant inputs as a table of "
"bitmasks:\n";
uint8_t InputVectors = m_pPSVRuntimeInfo1->SigPatchConstOrPrimVectors;
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigOutputVectors[0];
const PSVDependencyTable Table(m_pPCInputToOutputTable, InputVectors,
OutputVectors);
Table.Print(OS, "PatchConstantInputs", "Outputs");
}
}

void DxilPipelineStateValidation::Print(raw_ostream &OS,
Expand Down Expand Up @@ -866,57 +944,6 @@ void DxilPipelineStateValidation::Print(raw_ostream &OS,
PSVSE.Print(OS);
}

unsigned NumStreams = IsGS() ? PSV_GS_MAX_STREAMS : 1;

if (m_pPSVRuntimeInfo1->UsesViewID) {
for (unsigned i = 0; i < NumStreams; ++i) {
OS << "Outputs affected by ViewID as a bitmask for stream " << i
<< ":\n ";
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigOutputVectors[i];
const PSVComponentMask ViewIDMask(m_pViewIDOutputMask[i],
OutputVectors);
std::string OutputSetName = "Outputs";
OutputSetName += "[" + std::to_string(i) + "]";
ViewIDMask.Print(OS, "ViewID", OutputSetName.c_str());
}

if (IsHS() || IsMS()) {
OS << "PCOutputs affected by ViewID as a bitmask:\n";
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigPatchConstOrPrimVectors;
const PSVComponentMask ViewIDMask(m_pViewIDPCOrPrimOutputMask,
OutputVectors);
ViewIDMask.Print(OS, "ViewID", "PCOutputs");
}
}

for (unsigned i = 0; i < NumStreams; ++i) {
OS << "Outputs affected by inputs as a table of bitmasks for stream " << i
<< ":\n";
uint8_t InputVectors = m_pPSVRuntimeInfo1->SigInputVectors;
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigOutputVectors[i];
const PSVDependencyTable Table(m_pInputToOutputTable[i], InputVectors,
OutputVectors);
std::string OutputSetName = "Outputs";
OutputSetName += "[" + std::to_string(i) + "]";
Table.Print(OS, "Inputs", OutputSetName.c_str());
}

if (IsHS()) {
OS << "Patch constant outputs affected by inputs as a table of "
"bitmasks:\n";
uint8_t InputVectors = m_pPSVRuntimeInfo1->SigInputVectors;
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigPatchConstOrPrimVectors;
const PSVDependencyTable Table(m_pInputToPCOutputTable, InputVectors,
OutputVectors);
Table.Print(OS, "Inputs", "PatchConstantOutputs");
} else if (IsDS()) {
OS << "Outputs affected by patch constant inputs as a table of "
"bitmasks:\n";
uint8_t InputVectors = m_pPSVRuntimeInfo1->SigPatchConstOrPrimVectors;
uint8_t OutputVectors = m_pPSVRuntimeInfo1->SigOutputVectors[0];
const PSVDependencyTable Table(m_pPCInputToOutputTable, InputVectors,
OutputVectors);
Table.Print(OS, "PatchConstantInputs", "Outputs");
}
PrintViewIDState(OS);
}
}
Loading
Loading