Skip to content

Commit 5155b09

Browse files
authored
[Validator] Check content of PSV0 part in validation (#6859)
Replace the memcpy check for PSV0 part. Build DxilPipelineStateValidation object from data in PSV0 part. Then compare the content with information from input DxilModule. With this change, the order of signature elements and resources could be different between the container and the DxilModule. And the StringTable could be in different order as well. Second step for #6817
1 parent e1bb926 commit 5155b09

File tree

9 files changed

+2122
-153
lines changed

9 files changed

+2122
-153
lines changed

include/dxc/DxilContainer/DxilPipelineStateValidation.h

+39-5
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ struct PSVComponentMask {
260260
}
261261
return *this;
262262
}
263+
bool operator!=(const PSVComponentMask &other) const {
264+
if (NumVectors != other.NumVectors)
265+
return true;
266+
return memcmp(Mask, other.Mask,
267+
PSVComputeMaskDwordsFromVectors(NumVectors) *
268+
sizeof(uint32_t));
269+
}
263270
bool Get(uint32_t ComponentIndex) const {
264271
if (ComponentIndex < NumVectors * 4)
265272
return (bool)(Mask[ComponentIndex >> 5] & (1 << (ComponentIndex & 0x1F)));
@@ -295,6 +302,15 @@ struct PSVDependencyTable {
295302
const PSVComponentMask GetMaskForInput(uint32_t inputComponentIndex) const {
296303
return getMaskForInput(inputComponentIndex);
297304
}
305+
bool operator!=(const PSVDependencyTable &other) const {
306+
if (InputVectors != other.InputVectors ||
307+
OutputVectors != other.OutputVectors)
308+
return true;
309+
return memcmp(
310+
Table, other.Table,
311+
PSVComputeInputOutputTableDwords(InputVectors, OutputVectors) *
312+
sizeof(uint32_t));
313+
}
298314
bool IsValid() const { return Table != nullptr; }
299315
void Print(llvm::raw_ostream &, const char *, const char *) const;
300316

@@ -449,6 +465,8 @@ class PSVSignatureElement {
449465
return !m_pElement0 ? 0 : (uint32_t)m_pElement0->DynamicMaskAndStream & 0xF;
450466
}
451467
void Print(llvm::raw_ostream &O) const;
468+
void Print(llvm::raw_ostream &O, const char *Name,
469+
const uint32_t *SemanticIndexes) const;
452470
};
453471

454472
#define MAX_PSV_VERSION 3
@@ -595,6 +613,14 @@ class DxilPipelineStateValidation {
595613
return ReadOrWrite(pBuffer, pSize, Mode, initInfo);
596614
}
597615

616+
uint32_t GetRuntimeInfoSize() const { return m_uPSVRuntimeInfoSize; }
617+
uint32_t GetResourceBindInfoSize() const {
618+
return m_uPSVResourceBindInfoSize;
619+
}
620+
uint32_t GetSignatureElementSize() const {
621+
return m_uPSVSignatureElementSize;
622+
}
623+
598624
PSVRuntimeInfo0 *GetPSVRuntimeInfo0() const { return m_pPSVRuntimeInfo0; }
599625

600626
PSVRuntimeInfo1 *GetPSVRuntimeInfo1() const { return m_pPSVRuntimeInfo1; }
@@ -752,6 +778,7 @@ class DxilPipelineStateValidation {
752778
}
753779
void PrintPSVRuntimeInfo(llvm::raw_ostream &O, uint8_t ShaderKind,
754780
const char *Comment) const;
781+
void PrintViewIDState(llvm::raw_ostream &OS) const;
755782
void Print(llvm::raw_ostream &O, uint8_t ShaderKind) const;
756783
};
757784

@@ -1084,6 +1111,9 @@ class ViewIDValidator {
10841111
ViewIDValidator *NewViewIDValidator(unsigned viewIDCount,
10851112
unsigned gsRastStreamIndex);
10861113

1114+
uint32_t GetPSVVersion(uint32_t ValidatorMajorVersion,
1115+
uint32_t ValidatorMinorVersion);
1116+
10871117
void InitPSVResourceBinding(PSVResourceBindInfo0 *, PSVResourceBindInfo1 *,
10881118
DxilResourceBase *);
10891119

@@ -1093,11 +1123,15 @@ void InitPSVSignatureElement(PSVSignatureElement0 &E,
10931123
const DxilSignatureElement &SE,
10941124
bool i1ToUnknownCompat);
10951125

1096-
// Setup PSVRuntimeInfo* with DxilModule.
1097-
// Note that the EntryFunctionName is not done.
1098-
void InitPSVRuntimeInfo(PSVRuntimeInfo0 *pInfo, PSVRuntimeInfo1 *pInfo1,
1099-
PSVRuntimeInfo2 *pInfo2, PSVRuntimeInfo3 *pInfo3,
1100-
const DxilModule &DM);
1126+
// Setup shader properties for PSVRuntimeInfo* with DxilModule.
1127+
void SetShaderProps(PSVRuntimeInfo0 *pInfo, const DxilModule &DM);
1128+
void SetShaderProps(PSVRuntimeInfo1 *pInfo1, const DxilModule &DM);
1129+
void SetShaderProps(PSVRuntimeInfo2 *pInfo2, const DxilModule &DM);
1130+
1131+
void PrintPSVRuntimeInfo(llvm::raw_ostream &OS, PSVRuntimeInfo0 *pInfo0,
1132+
PSVRuntimeInfo1 *pInfo1, PSVRuntimeInfo2 *pInfo2,
1133+
PSVRuntimeInfo3 *pInfo3, uint8_t ShaderKind,
1134+
const char *EntryName, const char *Comment);
11011135

11021136
} // namespace hlsl
11031137

lib/DxilContainer/DxilContainerAssembler.cpp

+13-16
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ static_assert((unsigned)PSVShaderKind::Invalid ==
5050
(unsigned)DXIL::ShaderKind::Invalid,
5151
"otherwise, PSVShaderKind enum out of sync.");
5252

53-
static DxilProgramSigSemantic
54-
KindToSystemValue(Semantic::Kind kind, DXIL::TessellatorDomain domain) {
53+
DxilProgramSigSemantic
54+
hlsl::SemanticKindToSystemValue(Semantic::Kind kind,
55+
DXIL::TessellatorDomain domain) {
5556
switch (kind) {
5657
case Semantic::Kind::Arbitrary:
5758
return DxilProgramSigSemantic::Undefined;
@@ -291,7 +292,7 @@ class DxilProgramSignatureWriter : public DxilPartWriter {
291292
memset(&sig, 0, sizeof(DxilProgramSignatureElement));
292293
sig.Stream = pElement->GetOutputStream();
293294
sig.SemanticName = GetSemanticOffset(pElement);
294-
sig.SystemValue = KindToSystemValue(pElement->GetKind(), m_domain);
295+
sig.SystemValue = SemanticKindToSystemValue(pElement->GetKind(), m_domain);
295296
sig.CompType =
296297
CompTypeToSigCompType(pElement->GetCompType().GetKind(), m_bCompat_1_4);
297298
sig.Register = pElement->GetStartRow();
@@ -738,17 +739,9 @@ class DxilPSVWriter : public DxilPartWriter {
738739
: m_Module(mod), m_PSVInitInfo(PSVVersion) {
739740
m_Module.GetValidatorVersion(m_ValMajor, m_ValMinor);
740741
// Constraint PSVVersion based on validator version
741-
if (PSVVersion > 0 &&
742-
DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 1) < 0)
743-
m_PSVInitInfo.PSVVersion = 0;
744-
else if (PSVVersion > 1 &&
745-
DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 6) < 0)
746-
m_PSVInitInfo.PSVVersion = 1;
747-
else if (PSVVersion > 2 &&
748-
DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 8) < 0)
749-
m_PSVInitInfo.PSVVersion = 2;
750-
else if (PSVVersion > MAX_PSV_VERSION)
751-
m_PSVInitInfo.PSVVersion = MAX_PSV_VERSION;
742+
uint32_t PSVVersionConstraint = hlsl::GetPSVVersion(m_ValMajor, m_ValMinor);
743+
if (PSVVersion > PSVVersionConstraint)
744+
m_PSVInitInfo.PSVVersion = PSVVersionConstraint;
752745

753746
const ShaderModel *SM = m_Module.GetShaderModel();
754747
UINT uCBuffers = m_Module.GetCBuffers().size();
@@ -834,8 +827,12 @@ class DxilPSVWriter : public DxilPartWriter {
834827
PSVRuntimeInfo1 *pInfo1 = m_PSV.GetPSVRuntimeInfo1();
835828
PSVRuntimeInfo2 *pInfo2 = m_PSV.GetPSVRuntimeInfo2();
836829
PSVRuntimeInfo3 *pInfo3 = m_PSV.GetPSVRuntimeInfo3();
837-
838-
hlsl::InitPSVRuntimeInfo(pInfo, pInfo1, pInfo2, pInfo3, m_Module);
830+
if (pInfo)
831+
hlsl::SetShaderProps(pInfo, m_Module);
832+
if (pInfo1)
833+
hlsl::SetShaderProps(pInfo1, m_Module);
834+
if (pInfo2)
835+
hlsl::SetShaderProps(pInfo2, m_Module);
839836
if (pInfo3)
840837
pInfo3->EntryFunctionName = EntryFunctionName;
841838

0 commit comments

Comments
 (0)