From 8ffe33767c292d776cd6fe15896d0c591b0497a6 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 23 Apr 2019 16:30:04 +0100 Subject: [PATCH] Handle UNormSRGB in some places that were missing handling --- qrenderdoc/Code/FormatElement.cpp | 8 ++++---- qrenderdoc/Code/QRDUtils.cpp | 2 +- .../Windows/PipelineState/PipelineStateViewer.cpp | 8 ++++---- renderdoc/common/dds_readwrite.cpp | 3 ++- renderdoc/driver/d3d11/d3d11_pixelhistory.cpp | 2 +- renderdoc/driver/d3d11/d3d11_shaderdebug.cpp | 4 ++-- renderdoc/driver/shaders/dxbc/dxbc_debug.cpp | 4 ++-- renderdoc/driver/vulkan/vk_resources.cpp | 12 ++++++------ renderdoc/replay/replay_controller.cpp | 9 +++++---- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/qrenderdoc/Code/FormatElement.cpp b/qrenderdoc/Code/FormatElement.cpp index 91f8d1a96..dae46e821 100644 --- a/qrenderdoc/Code/FormatElement.cpp +++ b/qrenderdoc/Code/FormatElement.cpp @@ -48,7 +48,7 @@ static QVariant interpret(const ResourceFormat &f, uint16_t comp) { return (float)comp; } - else if(f.compType == CompType::UNorm) + else if(f.compType == CompType::UNorm || f.compType == CompType::UNormSRGB) { return (float)comp / (float)0xffff; } @@ -90,7 +90,7 @@ static QVariant interpret(const ResourceFormat &f, byte comp) { return (float)comp; } - else if(f.compType == CompType::UNorm) + else if(f.compType == CompType::UNorm || f.compType == CompType::UNormSRGB) { return ((float)comp) / 255.0f; } @@ -583,7 +583,7 @@ QString FormatElement::GenerateTextureBufferFormat(const TextureDescription &tex { if(tex.format.compByteWidth == 1) { - if(tex.format.compType == CompType::UNorm) + if(tex.format.compType == CompType::UNorm || tex.format.compType == CompType::UNormSRGB) baseType = lit("unormb"); else if(tex.format.compType == CompType::SNorm) baseType = lit("snormb"); @@ -594,7 +594,7 @@ QString FormatElement::GenerateTextureBufferFormat(const TextureDescription &tex } else if(tex.format.compByteWidth == 2) { - if(tex.format.compType == CompType::UNorm) + if(tex.format.compType == CompType::UNorm || tex.format.compType == CompType::UNormSRGB) baseType = lit("unormh"); else if(tex.format.compType == CompType::SNorm) baseType = lit("snormh"); diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index 76ebe63d7..69b205abd 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -817,7 +817,7 @@ QString TypeString(const SigParameter &sig) ret += lit("uint"); else if(sig.compType == CompType::SInt || sig.compType == CompType::SScaled) ret += lit("int"); - else if(sig.compType == CompType::UNorm) + else if(sig.compType == CompType::UNorm || sig.compType == CompType::UNormSRGB) ret += lit("unorm float"); else if(sig.compType == CompType::SNorm) ret += lit("snorm float"); diff --git a/qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp index 08b8e8c96..3bf73f149 100644 --- a/qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp @@ -806,7 +806,7 @@ QString PipelineStateViewer::GenerateBufferFormatter(const ShaderResource &res, { case 1: { - if(viewFormat.compType == CompType::UNorm) + if(viewFormat.compType == CompType::UNorm || viewFormat.compType == CompType::UNormSRGB) format = lit("unormb"); if(viewFormat.compType == CompType::SNorm) format = lit("snormb"); @@ -818,7 +818,7 @@ QString PipelineStateViewer::GenerateBufferFormatter(const ShaderResource &res, } case 2: { - if(viewFormat.compType == CompType::UNorm) + if(viewFormat.compType == CompType::UNorm || viewFormat.compType == CompType::UNormSRGB) format = lit("unormh"); if(viewFormat.compType == CompType::SNorm) format = lit("snormh"); @@ -832,7 +832,7 @@ QString PipelineStateViewer::GenerateBufferFormatter(const ShaderResource &res, } case 4: { - if(viewFormat.compType == CompType::UNorm) + if(viewFormat.compType == CompType::UNorm || viewFormat.compType == CompType::UNormSRGB) format = lit("unormf"); if(viewFormat.compType == CompType::SNorm) format = lit("snormf"); @@ -1322,7 +1322,7 @@ QString PipelineStateViewer::GetVBufferFormatString(uint32_t slot) QLatin1Char('?'), QLatin1Char('b'), QLatin1Char('h'), QLatin1Char('?'), QLatin1Char('f'), }; - if(fmt.compType == CompType::UNorm) + if(fmt.compType == CompType::UNorm || fmt.compType == CompType::UNormSRGB) { format += lit("unorm%1").arg(widthchar[fmt.compByteWidth]); } diff --git a/renderdoc/common/dds_readwrite.cpp b/renderdoc/common/dds_readwrite.cpp index 0a5839403..61d253074 100644 --- a/renderdoc/common/dds_readwrite.cpp +++ b/renderdoc/common/dds_readwrite.cpp @@ -521,6 +521,7 @@ DXGI_FORMAT ResourceFormat2DXGIFormat(ResourceFormat format) case CompType::SNorm: return DXGI_FORMAT_R8G8B8A8_SNORM; default: case CompType::UNorm: + case CompType::UNormSRGB: if(format.SRGBCorrected()) { if(format.BGRAOrder()) @@ -758,7 +759,7 @@ bool write_dds_to_file(FILE *f, const dds_data &data) // special case a couple of formats to write out non-DX10 style, for // backwards compatibility if(data.format.compByteWidth == 1 && data.format.compCount == 4 && - data.format.compType == CompType::UNorm) + (data.format.compType == CompType::UNorm || data.format.compType == CompType::UNormSRGB)) { header.ddspf.dwFlags = DDPF_RGBA; header.ddspf.dwRGBBitCount = 32; diff --git a/renderdoc/driver/d3d11/d3d11_pixelhistory.cpp b/renderdoc/driver/d3d11/d3d11_pixelhistory.cpp index 185b63517..ae8617a3d 100644 --- a/renderdoc/driver/d3d11/d3d11_pixelhistory.cpp +++ b/renderdoc/driver/d3d11/d3d11_pixelhistory.cpp @@ -2572,7 +2572,7 @@ vector D3D11Replay::PixelHistory(vector events, R mod.postMod.col.floatValue[c] = ConvertFromHalf(uint16_t(mod.postMod.col.uintValue[c])); } } - else if(fmt.compType == CompType::UNorm && fmt.compByteWidth == 1 && fmt.SRGBCorrected()) + else if(fmt.compType == CompType::UNormSRGB && fmt.compByteWidth == 1 && fmt.SRGBCorrected()) { RDCASSERT(fmt.compByteWidth == 1); diff --git a/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp b/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp index e51c3d16e..ac50db0f4 100644 --- a/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp +++ b/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp @@ -996,7 +996,7 @@ ShaderDebugTrace D3D11Replay::DebugVertex(uint32_t eventId, uint32_t vertid, uin ret.inputs[i].value.uv[c] = *src; else if(fmt.compType == CompType::SInt) ret.inputs[i].value.iv[c] = *((int8_t *)src); - else if(fmt.compType == CompType::UNorm) + else if(fmt.compType == CompType::UNorm || fmt.compType == CompType::UNormSRGB) ret.inputs[i].value.fv[c] = float(*src) / 255.0f; else if(fmt.compType == CompType::SNorm) { @@ -1021,7 +1021,7 @@ ShaderDebugTrace D3D11Replay::DebugVertex(uint32_t eventId, uint32_t vertid, uin ret.inputs[i].value.uv[c] = *src; else if(fmt.compType == CompType::SInt) ret.inputs[i].value.iv[c] = *((int16_t *)src); - else if(fmt.compType == CompType::UNorm) + else if(fmt.compType == CompType::UNorm || fmt.compType == CompType::UNormSRGB) ret.inputs[i].value.fv[c] = float(*src) / float(UINT16_MAX); else if(fmt.compType == CompType::SNorm) { diff --git a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp index b7a37d0b3..d6e36b384 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp @@ -3835,7 +3835,7 @@ State State::GetNext(GlobalState &global, State quad[4]) const for(int c = 0; c < fmt.numComps; c++) result.value.iv[c] = in[c]; } - else if(fmt.fmt == CompType::UNorm) + else if(fmt.fmt == CompType::UNorm || fmt.fmt == CompType::UNormSRGB) { uint16_t *u = (uint16_t *)d; @@ -3876,7 +3876,7 @@ State State::GetNext(GlobalState &global, State quad[4]) const for(int c = 0; c < fmt.numComps; c++) result.value.iv[c] = in[c]; } - else if(fmt.fmt == CompType::UNorm) + else if(fmt.fmt == CompType::UNorm || fmt.fmt == CompType::UNormSRGB) { uint8_t *u = (uint8_t *)d; diff --git a/renderdoc/driver/vulkan/vk_resources.cpp b/renderdoc/driver/vulkan/vk_resources.cpp index 6272ec3bd..8c2a50cc2 100644 --- a/renderdoc/driver/vulkan/vk_resources.cpp +++ b/renderdoc/driver/vulkan/vk_resources.cpp @@ -752,7 +752,7 @@ VkFormat GetViewCastedFormat(VkFormat f, CompType typeHint) case VK_FORMAT_R16G16B16A16_SINT: case VK_FORMAT_R16G16B16A16_SFLOAT: { - if(typeHint == CompType::UNorm) + if(typeHint == CompType::UNorm || typeHint == CompType::UNormSRGB) return VK_FORMAT_R16G16B16A16_UNORM; else if(typeHint == CompType::SNorm) return VK_FORMAT_R16G16B16A16_SNORM; @@ -775,7 +775,7 @@ VkFormat GetViewCastedFormat(VkFormat f, CompType typeHint) case VK_FORMAT_R16G16B16_SINT: case VK_FORMAT_R16G16B16_SFLOAT: { - if(typeHint == CompType::UNorm) + if(typeHint == CompType::UNorm || typeHint == CompType::UNormSRGB) return VK_FORMAT_R16G16B16_UNORM; else if(typeHint == CompType::SNorm) return VK_FORMAT_R16G16B16_SNORM; @@ -798,7 +798,7 @@ VkFormat GetViewCastedFormat(VkFormat f, CompType typeHint) case VK_FORMAT_R16G16_SINT: case VK_FORMAT_R16G16_SFLOAT: { - if(typeHint == CompType::UNorm) + if(typeHint == CompType::UNorm || typeHint == CompType::UNormSRGB) return VK_FORMAT_R16G16_UNORM; else if(typeHint == CompType::SNorm) return VK_FORMAT_R16G16_SNORM; @@ -822,7 +822,7 @@ VkFormat GetViewCastedFormat(VkFormat f, CompType typeHint) case VK_FORMAT_R16_SFLOAT: case VK_FORMAT_D16_UNORM: { - if(typeHint == CompType::UNorm) + if(typeHint == CompType::UNorm || typeHint == CompType::UNormSRGB) return VK_FORMAT_R16_UNORM; else if(typeHint == CompType::SNorm) return VK_FORMAT_R16_SNORM; @@ -1024,7 +1024,7 @@ VkFormat GetViewCastedFormat(VkFormat f, CompType typeHint) case VK_FORMAT_A2B10G10R10_UINT_PACK32: case VK_FORMAT_A2B10G10R10_SINT_PACK32: { - if(typeHint == CompType::UNorm) + if(typeHint == CompType::UNorm || typeHint == CompType::UNormSRGB) return VK_FORMAT_A2B10G10R10_UNORM_PACK32; else if(typeHint == CompType::SNorm) return VK_FORMAT_A2B10G10R10_SNORM_PACK32; @@ -1046,7 +1046,7 @@ VkFormat GetViewCastedFormat(VkFormat f, CompType typeHint) case VK_FORMAT_A2R10G10B10_UINT_PACK32: case VK_FORMAT_A2R10G10B10_SINT_PACK32: { - if(typeHint == CompType::UNorm) + if(typeHint == CompType::UNorm || typeHint == CompType::UNormSRGB) return VK_FORMAT_A2R10G10B10_UNORM_PACK32; else if(typeHint == CompType::SNorm) return VK_FORMAT_A2R10G10B10_SNORM_PACK32; diff --git a/renderdoc/replay/replay_controller.cpp b/renderdoc/replay/replay_controller.cpp index bb5e32cd3..7bce11e74 100644 --- a/renderdoc/replay/replay_controller.cpp +++ b/renderdoc/replay/replay_controller.cpp @@ -138,12 +138,13 @@ float ConvertComponent(const ResourceFormat &fmt, const byte *data) { return float(*i8); } + else if(fmt.compType == CompType::UNormSRGB) + { + return SRGB8_lookuptable[*u8]; + } else if(fmt.compType == CompType::UNorm) { - if(fmt.SRGBCorrected()) - return SRGB8_lookuptable[*u8]; - else - return float(*u8) / 255.0f; + return float(*u8) / 255.0f; } else if(fmt.compType == CompType::SNorm) {