diff --git a/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp b/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp index d37f0b617..e33bd9abb 100644 --- a/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp +++ b/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp @@ -816,13 +816,13 @@ static void AddArraySlots(WrappedID3D12PipelineState::ShaderEntry *shad, uint32_ if(AnnotateDXILShader(shad->GetDXBC(), space, slots, editedBlob)) { // strip ILDB because it's valid code (with debug info) and who knows what might use it - DXBC::DXBCContainer::StripDXILDebugInfo(editedBlob); + DXBC::DXBCContainer::StripChunk(editedBlob, DXBC::FOURCC_ILDB); if(!D3D12_Debug_FeedbackDumpDirPath().empty()) { bytebuf orig = shad->GetDXBC()->GetShaderBlob(); - DXBC::DXBCContainer::StripDXILDebugInfo(orig); + DXBC::DXBCContainer::StripChunk(orig, DXBC::FOURCC_ILDB); FileIO::WriteAll(D3D12_Debug_FeedbackDumpDirPath() + "/before_dxil_" + ToStr(shad->GetDetails().stage).c_str() + ".dxbc", diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp index 6b3d7d351..ede1fdeb7 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp @@ -248,32 +248,6 @@ struct SIGNElement1 static const uint32_t STATSizeDX10 = 29 * 4; // either 29 uint32s static const uint32_t STATSizeDX11 = 37 * 4; // or 37 uint32s -static const uint32_t FOURCC_DXBC = MAKE_FOURCC('D', 'X', 'B', 'C'); -static const uint32_t FOURCC_RDEF = MAKE_FOURCC('R', 'D', 'E', 'F'); -static const uint32_t FOURCC_RD11 = MAKE_FOURCC('R', 'D', '1', '1'); -static const uint32_t FOURCC_STAT = MAKE_FOURCC('S', 'T', 'A', 'T'); -static const uint32_t FOURCC_SHEX = MAKE_FOURCC('S', 'H', 'E', 'X'); -static const uint32_t FOURCC_SHDR = MAKE_FOURCC('S', 'H', 'D', 'R'); -static const uint32_t FOURCC_SDBG = MAKE_FOURCC('S', 'D', 'B', 'G'); -static const uint32_t FOURCC_SPDB = MAKE_FOURCC('S', 'P', 'D', 'B'); -static const uint32_t FOURCC_ISGN = MAKE_FOURCC('I', 'S', 'G', 'N'); -static const uint32_t FOURCC_OSGN = MAKE_FOURCC('O', 'S', 'G', 'N'); -static const uint32_t FOURCC_ISG1 = MAKE_FOURCC('I', 'S', 'G', '1'); -static const uint32_t FOURCC_OSG1 = MAKE_FOURCC('O', 'S', 'G', '1'); -static const uint32_t FOURCC_OSG5 = MAKE_FOURCC('O', 'S', 'G', '5'); -static const uint32_t FOURCC_PCSG = MAKE_FOURCC('P', 'C', 'S', 'G'); -static const uint32_t FOURCC_PSG1 = MAKE_FOURCC('P', 'S', 'G', '1'); -static const uint32_t FOURCC_Aon9 = MAKE_FOURCC('A', 'o', 'n', '9'); -static const uint32_t FOURCC_PRIV = MAKE_FOURCC('P', 'R', 'I', 'V'); -static const uint32_t FOURCC_DXIL = MAKE_FOURCC('D', 'X', 'I', 'L'); -static const uint32_t FOURCC_ILDB = MAKE_FOURCC('I', 'L', 'D', 'B'); -static const uint32_t FOURCC_ILDN = MAKE_FOURCC('I', 'L', 'D', 'N'); -static const uint32_t FOURCC_HASH = MAKE_FOURCC('H', 'A', 'S', 'H'); -static const uint32_t FOURCC_SFI0 = MAKE_FOURCC('S', 'F', 'I', '0'); -static const uint32_t FOURCC_PSV0 = MAKE_FOURCC('P', 'S', 'V', '0'); -static const uint32_t FOURCC_RTS0 = MAKE_FOURCC('R', 'T', 'S', '0'); -static const uint32_t FOURCC_RDAT = MAKE_FOURCC('R', 'D', 'A', 'T'); - ShaderBuiltin GetSystemValue(SVSemantic systemValue) { switch(systemValue) @@ -654,7 +628,7 @@ void DXBCContainer::FillStateInstructionInfo(ShaderDebugState &state) const } } -void DXBCContainer::StripDXILDebugInfo(bytebuf &ByteCode) +void DXBCContainer::StripChunk(bytebuf &ByteCode, uint32_t fourcc) { FileHeader *header = (FileHeader *)ByteCode.data(); @@ -671,10 +645,10 @@ void DXBCContainer::StripDXILDebugInfo(bytebuf &ByteCode) { uint32_t offs = chunkOffsets[chunkIdx]; - uint32_t *fourcc = (uint32_t *)(ByteCode.data() + offs); - uint32_t *chunkSize = (uint32_t *)(fourcc + 1); + uint32_t *chunkFourcc = (uint32_t *)(ByteCode.data() + offs); + uint32_t *chunkSize = (uint32_t *)(chunkFourcc + 1); - if(*fourcc == FOURCC_ILDB) + if(*chunkFourcc == fourcc) { // the size of the whole chunk that we're erasing is the chunk's size itself, plus 8 bytes for // fourcc+size diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.h b/renderdoc/driver/shaders/dxbc/dxbc_container.h index bcb1b64a1..25be00da2 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.h +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.h @@ -130,6 +130,32 @@ enum class GlobalShaderFlags : int64_t BITMASK_OPERATORS(GlobalShaderFlags); +static const uint32_t FOURCC_DXBC = MAKE_FOURCC('D', 'X', 'B', 'C'); +static const uint32_t FOURCC_RDEF = MAKE_FOURCC('R', 'D', 'E', 'F'); +static const uint32_t FOURCC_RD11 = MAKE_FOURCC('R', 'D', '1', '1'); +static const uint32_t FOURCC_STAT = MAKE_FOURCC('S', 'T', 'A', 'T'); +static const uint32_t FOURCC_SHEX = MAKE_FOURCC('S', 'H', 'E', 'X'); +static const uint32_t FOURCC_SHDR = MAKE_FOURCC('S', 'H', 'D', 'R'); +static const uint32_t FOURCC_SDBG = MAKE_FOURCC('S', 'D', 'B', 'G'); +static const uint32_t FOURCC_SPDB = MAKE_FOURCC('S', 'P', 'D', 'B'); +static const uint32_t FOURCC_ISGN = MAKE_FOURCC('I', 'S', 'G', 'N'); +static const uint32_t FOURCC_OSGN = MAKE_FOURCC('O', 'S', 'G', 'N'); +static const uint32_t FOURCC_ISG1 = MAKE_FOURCC('I', 'S', 'G', '1'); +static const uint32_t FOURCC_OSG1 = MAKE_FOURCC('O', 'S', 'G', '1'); +static const uint32_t FOURCC_OSG5 = MAKE_FOURCC('O', 'S', 'G', '5'); +static const uint32_t FOURCC_PCSG = MAKE_FOURCC('P', 'C', 'S', 'G'); +static const uint32_t FOURCC_PSG1 = MAKE_FOURCC('P', 'S', 'G', '1'); +static const uint32_t FOURCC_Aon9 = MAKE_FOURCC('A', 'o', 'n', '9'); +static const uint32_t FOURCC_PRIV = MAKE_FOURCC('P', 'R', 'I', 'V'); +static const uint32_t FOURCC_DXIL = MAKE_FOURCC('D', 'X', 'I', 'L'); +static const uint32_t FOURCC_ILDB = MAKE_FOURCC('I', 'L', 'D', 'B'); +static const uint32_t FOURCC_ILDN = MAKE_FOURCC('I', 'L', 'D', 'N'); +static const uint32_t FOURCC_HASH = MAKE_FOURCC('H', 'A', 'S', 'H'); +static const uint32_t FOURCC_SFI0 = MAKE_FOURCC('S', 'F', 'I', '0'); +static const uint32_t FOURCC_PSV0 = MAKE_FOURCC('P', 'S', 'V', '0'); +static const uint32_t FOURCC_RTS0 = MAKE_FOURCC('R', 'T', 'S', '0'); +static const uint32_t FOURCC_RDAT = MAKE_FOURCC('R', 'D', 'A', 'T'); + struct RDEFHeader; uint32_t DecodeFlags(const ShaderCompileFlags &compileFlags); @@ -163,7 +189,7 @@ public: void FillTraceLineInfo(ShaderDebugTrace &trace) const; void FillStateInstructionInfo(ShaderDebugState &state) const; - static void StripDXILDebugInfo(bytebuf &ByteCode); + static void StripChunk(bytebuf &ByteCode, uint32_t fourcc); static void ReplaceChunk(bytebuf &ByteCode, uint32_t fourcc, const byte *replacement, size_t size); template diff --git a/renderdoc/driver/shaders/dxbc/dxbc_sdbg.cpp b/renderdoc/driver/shaders/dxbc/dxbc_sdbg.cpp index dbdbb4dbe..d1827e530 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_sdbg.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_sdbg.cpp @@ -30,8 +30,6 @@ namespace DXBC { -static const uint32_t FOURCC_SDBG = MAKE_FOURCC('S', 'D', 'B', 'G'); - SDBGChunk::SDBGChunk(void *data) { m_HasDebugInfo = false; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp b/renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp index e97ce1563..1f132c88a 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_spdb.cpp @@ -40,9 +40,6 @@ namespace DXBC { -static const uint32_t FOURCC_SPDB = MAKE_FOURCC('S', 'P', 'D', 'B'); -static const uint32_t FOURCC_DXBC = MAKE_FOURCC('D', 'X', 'B', 'C'); - bool IsPDBFile(void *data, size_t length) { FileHeaderPage *header = (FileHeaderPage *)data; diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp b/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp index 21ccee9fc..9f9ad93be 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.cpp @@ -471,7 +471,7 @@ ProgramEditor::~ProgramEditor() GetInt32Type(); // replace the DXIL bytecode in the container with - DXBC::DXBCContainer::ReplaceChunk(m_OutBlob, MAKE_FOURCC('D', 'X', 'I', 'L'), EncodeProgram()); + DXBC::DXBCContainer::ReplaceChunk(m_OutBlob, DXBC::FOURCC_DXIL, EncodeProgram()); #if ENABLED(RDOC_DEVEL) // on debug builds, run through dxil for "validation" if it's available. @@ -1884,7 +1884,7 @@ bytebuf ProgramEditor::EncodeProgram() const header.ProgramVersion = ((m_Major & 0xf) << 4) | (m_Minor & 0xf); header.ProgramType = (uint16_t)m_Type; - header.DxilMagic = MAKE_FOURCC('D', 'X', 'I', 'L'); + header.DxilMagic = DXBC::FOURCC_DXIL; header.DxilVersion = m_DXILVersion; header.BitcodeOffset = sizeof(ProgramHeader) - offsetof(ProgramHeader, DxilMagic); header.BitcodeSize = (uint32_t)ret.size(); @@ -1917,7 +1917,7 @@ void ProgramEditor::RegisterUAV(DXILResourceType type, uint32_t space, uint32_t uint32_t regEnd, ResourceKind kind) { size_t sz = 0; - const byte *psv0 = DXBC::DXBCContainer::FindChunk(m_OutBlob, MAKE_FOURCC('P', 'S', 'V', '0'), sz); + const byte *psv0 = DXBC::DXBCContainer::FindChunk(m_OutBlob, DXBC::FOURCC_PSV0, sz); ResourceBind1 bind = {}; bind.type = type; @@ -1974,15 +1974,15 @@ void ProgramEditor::RegisterUAV(DXILResourceType type, uint32_t space, uint32_t return; } - DXBC::DXBCContainer::ReplaceChunk(m_OutBlob, MAKE_FOURCC('P', 'S', 'V', '0'), psv0blob); + DXBC::DXBCContainer::ReplaceChunk(m_OutBlob, DXBC::FOURCC_PSV0, psv0blob); } // patch SFI0 here for non-CS non-PS shaders if(m_Type != DXBC::ShaderType::Compute && m_Type != DXBC::ShaderType::Pixel) { // cheekily cast away const since this returns the blob in-place - DXBC::GlobalShaderFlags *flags = (DXBC::GlobalShaderFlags *)DXBC::DXBCContainer::FindChunk( - m_OutBlob, MAKE_FOURCC('S', 'F', 'I', '0'), sz); + DXBC::GlobalShaderFlags *flags = + (DXBC::GlobalShaderFlags *)DXBC::DXBCContainer::FindChunk(m_OutBlob, DXBC::FOURCC_SFI0, sz); // this *should* always be present, so we can just add our flag if(flags) @@ -1990,6 +1990,9 @@ void ProgramEditor::RegisterUAV(DXILResourceType type, uint32_t space, uint32_t else RDCWARN("Feature flags chunk not present"); } + + // strip the root signature, we shouldn't need it and it may no longer match and fail validation + DXBC::DXBCContainer::StripChunk(m_OutBlob, DXBC::FOURCC_RTS0); } void ProgramEditor::EncodeConstants(LLVMBC::BitcodeWriter &writer, const rdcarray &values,