From 08b2572554667a874e591f6a857d3f8e661b8ebd Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 16 Jan 2020 13:52:48 +0000 Subject: [PATCH] Fix precision loss when downcasting to HDR/EXR identified by @iOrange * When outputting to a format supporting more than 8-bit data, we don't want to lose precision by downcasting e.g. D32S8 to RGBA8, instead use RGBA32. --- renderdoc/replay/replay_controller.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/renderdoc/replay/replay_controller.cpp b/renderdoc/replay/replay_controller.cpp index 3fed08294..7c145c44e 100644 --- a/renderdoc/replay/replay_controller.cpp +++ b/renderdoc/replay/replay_controller.cpp @@ -748,9 +748,21 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path if(downcast) { - // if the source and destination are more than 1 byte per component, remap to RGBA32 - if(td.format.compByteWidth > 1 && (sd.destType == FileType::DDS || - sd.destType == FileType::HDR || sd.destType == FileType::EXR)) + const bool destHDR = (sd.destType == FileType::DDS || sd.destType == FileType::HDR || + sd.destType == FileType::EXR); + + const bool sourceHDR = + td.format.compByteWidth > 1 || td.format.type == ResourceFormatType::D16S8 || + td.format.type == ResourceFormatType::D24S8 || td.format.type == ResourceFormatType::D32S8 || + td.format.type == ResourceFormatType::R11G11B10 || + td.format.type == ResourceFormatType::R10G10B10A2 || + td.format.type == ResourceFormatType::R9G9B9E5 || td.format.type == ResourceFormatType::BC6 || + td.format.type == ResourceFormatType::BC7 || td.format.type == ResourceFormatType::YUV10 || + td.format.type == ResourceFormatType::YUV12 || td.format.type == ResourceFormatType::YUV16; + + // if the source and destination have more than 1 byte per component, remap to RGBA32 to avoid + // precision loss + if(sourceHDR && destHDR) { remap = RemapTexture::RGBA32; td.format.compByteWidth = 4;