From f5db9fd19dafbc4f9122b64ab2bc43baa393c777 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 12 Jul 2021 17:39:44 +0100 Subject: [PATCH] Remove direct access to DXBC container blob --- renderdoc/driver/d3d11/d3d11_postvs.cpp | 4 ++-- renderdoc/driver/shaders/dxbc/dxbc_container.cpp | 12 ++++++------ renderdoc/driver/shaders/dxbc/dxbc_container.h | 6 +++--- renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_postvs.cpp b/renderdoc/driver/d3d11/d3d11_postvs.cpp index 3260cb671..ae42da875 100644 --- a/renderdoc/driver/d3d11/d3d11_postvs.cpp +++ b/renderdoc/driver/d3d11/d3d11_postvs.cpp @@ -290,7 +290,7 @@ void D3D11Replay::InitPostVSBuffers(uint32_t eventId) } HRESULT hr = m_pDevice->CreateGeometryShaderWithStreamOutput( - (void *)&dxbcVS->m_ShaderBlob[0], dxbcVS->m_ShaderBlob.size(), &sodecls[0], + (void *)dxbcVS->GetShaderBlob().data(), dxbcVS->GetShaderBlob().size(), &sodecls[0], (UINT)sodecls.size(), &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &streamoutGS); if(FAILED(hr)) @@ -688,7 +688,7 @@ void D3D11Replay::InitPostVSBuffers(uint32_t eventId) streamoutGS = NULL; HRESULT hr = m_pDevice->CreateGeometryShaderWithStreamOutput( - (void *)&lastShader->m_ShaderBlob[0], lastShader->m_ShaderBlob.size(), &sodecls[0], + (void *)lastShader->GetShaderBlob().data(), lastShader->GetShaderBlob().size(), &sodecls[0], (UINT)sodecls.size(), &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &streamoutGS); if(FAILED(hr)) diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp index 2d455cc9e..0ed016955 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp @@ -1145,15 +1145,15 @@ void DXBCContainer::TryFetchSeparateDebugInfo(bytebuf &byteCode, const rdcstr &d } } -DXBCContainer::DXBCContainer(bytebuf &ByteCode, const rdcstr &debugInfoPath, GraphicsAPI api, +DXBCContainer::DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPath, GraphicsAPI api, uint32_t shaderExtReg, uint32_t shaderExtSpace) { RDCEraseEl(m_ShaderStats); - TryFetchSeparateDebugInfo(ByteCode, debugInfoPath); - m_ShaderBlob = ByteCode; + TryFetchSeparateDebugInfo(m_ShaderBlob, debugInfoPath); + // just for convenience char *data = (char *)m_ShaderBlob.data(); char *debugData = (char *)m_DebugShaderBlob.data(); @@ -1164,7 +1164,7 @@ DXBCContainer::DXBCContainer(bytebuf &ByteCode, const rdcstr &debugInfoPath, Gra if(header->fourcc != FOURCC_DXBC) return; - if(header->fileLength != (uint32_t)ByteCode.size()) + if(header->fileLength != (uint32_t)m_ShaderBlob.size()) return; if(debugHeader && debugHeader->fourcc != FOURCC_DXBC) @@ -1370,7 +1370,7 @@ DXBCContainer::DXBCContainer(bytebuf &ByteCode, const rdcstr &debugInfoPath, Gra RDEFCBufferVariable *var = (RDEFCBufferVariable *)(chunkContents + cbuf->variables.offset + varStride); - if(var->nameOffset > ByteCode.size()) + if(var->nameOffset > m_ShaderBlob.size()) { varStride += extraData; } @@ -1382,7 +1382,7 @@ DXBCContainer::DXBCContainer(bytebuf &ByteCode, const rdcstr &debugInfoPath, Gra RDEFCBufferVariable *var = (RDEFCBufferVariable *)(chunkContents + cbuf->variables.offset + vi * varStride); - RDCASSERT(var->nameOffset < ByteCode.size()); + RDCASSERT(var->nameOffset < m_ShaderBlob.size()); CBufferVariable v; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.h b/renderdoc/driver/shaders/dxbc/dxbc_container.h index f4431e808..7bb700854 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.h +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.h @@ -143,7 +143,7 @@ ShaderCompileFlags EncodeFlags(const uint32_t flags, const rdcstr &profile); class DXBCContainer { public: - DXBCContainer(bytebuf &ByteCode, const rdcstr &debugInfoPath, GraphicsAPI api, + DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPath, GraphicsAPI api, uint32_t shaderExtReg, uint32_t shaderExtSpace); ~DXBCContainer(); DXBCContainer(const DXBCContainer &o) = delete; @@ -156,8 +156,7 @@ public: uint32_t Major = 0, Minor = 0; } m_Version; - bytebuf m_ShaderBlob; - + const bytebuf &GetShaderBlob() const { return m_ShaderBlob; } const IDebugInfo *GetDebugInfo() const { return m_DebugInfo; } const Reflection *GetReflection() const { return m_Reflection; } D3D_PRIMITIVE_TOPOLOGY GetOutputTopology(); @@ -187,6 +186,7 @@ private: void TryFetchSeparateDebugInfo(bytebuf &byteCode, const rdcstr &debugInfoPath); bytebuf m_DebugShaderBlob; + bytebuf m_ShaderBlob; rdcstr m_Disassembly; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp b/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp index 729255ad3..ef3d2c642 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp @@ -299,7 +299,7 @@ void MakeShaderReflection(DXBC::DXBCContainer *dxbc, ShaderReflection *refl, } refl->encoding = ShaderEncoding::DXBC; - refl->rawBytes = dxbc->m_ShaderBlob; + refl->rawBytes = dxbc->GetShaderBlob(); refl->dispatchThreadsDimension[0] = dxbc->GetReflection()->DispatchThreadsDimension[0]; refl->dispatchThreadsDimension[1] = dxbc->GetReflection()->DispatchThreadsDimension[1];