From 8401ba26a0fe9d4f8ab230663210a15feb52827f Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 21 Sep 2021 14:22:38 +0100 Subject: [PATCH] Fix DXBC container offsets/length properly when stripping debug DXIL --- renderdoc/driver/d3d12/d3d12_shader_feedback.cpp | 1 + renderdoc/driver/shaders/dxbc/dxbc_container.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp b/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp index 2510d649a..b4b66ff14 100644 --- a/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp +++ b/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp @@ -618,6 +618,7 @@ 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); if(!D3D12_Debug_FeedbackDumpDirPath().empty()) diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp index 2168661bd..6b3d7d351 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp @@ -676,15 +676,25 @@ void DXBCContainer::StripDXILDebugInfo(bytebuf &ByteCode) if(*fourcc == FOURCC_ILDB) { + // the size of the whole chunk that we're erasing is the chunk's size itself, plus 8 bytes for + // fourcc+size uint32_t size = 8 + *chunkSize; - // strip ILDB because it's valid code (with debug info) and who knows what might use it for(uint32_t c = chunkIdx; c < header->numChunks; c++) chunkOffsets[c] = chunkOffsets[c + 1] - size; header->numChunks--; header->fileLength -= size; + // all chunk offsets (before and after) and file size decrement by a uint32, because we're + // going to remove a chunkoffset as well which is before them all + for(uint32_t c = 0; c < header->numChunks; c++) + chunkOffsets[c] -= sizeof(uint32_t); + header->fileLength -= sizeof(uint32_t); + + // erase the chunk itself ByteCode.erase(offs, size); + // remove the chunk offset + ByteCode.erase(sizeof(FileHeader) + header->numChunks * sizeof(uint32_t), 4); break; }