From 600845821653e637bf486ed4ec06988009444f5c Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 19 Aug 2016 15:25:48 +0200 Subject: [PATCH] Fix LZ4 compression for replay proxy texture data transfer * The compression bound was just a hacked 'uncompressed size + 512' which might not be enough for true worst case. * Worse, the serialisation was transferring size_ts so it would break if proxying between 32-bit and 64-bit executables. --- renderdoc/core/replay_proxy.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/renderdoc/core/replay_proxy.cpp b/renderdoc/core/replay_proxy.cpp index 6921a9cb9..b30c56794 100644 --- a/renderdoc/core/replay_proxy.cpp +++ b/renderdoc/core/replay_proxy.cpp @@ -2293,14 +2293,15 @@ byte *ReplayProxy::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mi byte *data = m_Remote->GetTextureData(tex, arrayIdx, mip, typeHint, resolve, forceRGBA8unorm, blackPoint, whitePoint, dataSize); - byte *compressed = new byte[dataSize + 512]; + byte *compressed = new byte[LZ4_COMPRESSBOUND(dataSize)]; - size_t compressedSize = - (size_t)LZ4_compress((const char *)data, (char *)compressed, (int)dataSize); + uint32_t uncompressedSize = (uint32_t)dataSize; + uint32_t compressedSize = + (uint32_t)LZ4_compress((const char *)data, (char *)compressed, (int)uncompressedSize); - m_FromReplaySerialiser->Serialise("", dataSize); + m_FromReplaySerialiser->Serialise("", uncompressedSize); m_FromReplaySerialiser->Serialise("", compressedSize); - m_FromReplaySerialiser->RawWriteBytes(compressed, compressedSize); + m_FromReplaySerialiser->RawWriteBytes(compressed, (size_t)compressedSize); delete[] data; delete[] compressed; @@ -2310,14 +2311,17 @@ byte *ReplayProxy::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mi if(!SendReplayCommand(eReplayProxy_GetTextureData)) return NULL; - size_t compressedSize; + uint32_t uncompressedSize = 0; + uint32_t compressedSize = 0; - m_FromReplaySerialiser->Serialise("", dataSize); + m_FromReplaySerialiser->Serialise("", uncompressedSize); m_FromReplaySerialiser->Serialise("", compressedSize); + dataSize = (size_t)uncompressedSize; + byte *ret = new byte[dataSize + 512]; - byte *compressed = (byte *)m_FromReplaySerialiser->RawReadBytes(compressedSize); + byte *compressed = (byte *)m_FromReplaySerialiser->RawReadBytes((size_t)compressedSize); LZ4_decompress_fast((const char *)compressed, (char *)ret, (int)dataSize);