From 4ebbf093642a460f3e89167a093edc02f3986326 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 15 Oct 2015 13:05:04 +0200 Subject: [PATCH] Get replay to display textures in gamma-correct fashion --- ReleaseNotes.md | 2 +- renderdoc/data/spv/texdisplay.frag | 5 +++ renderdoc/driver/vulkan/vk_replay.cpp | 26 +++++++++++++-- renderdoc/driver/vulkan/vk_resources.cpp | 40 ++++++++++++++++++++++++ renderdoc/driver/vulkan/vk_resources.h | 1 + 5 files changed, 71 insertions(+), 3 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 7944cdabb..185bbea2a 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -42,9 +42,9 @@ On replay: * Only 2D non-array non-integer textures can currently be displayed. * Pixel values aren't fetched. +* Thumbnail images aren't rendered (causes crashes/halts on nvidia's driver). * Auto texture range-fit or histogram display is not implemented. * Debug overlays aren't implemented. -* The display pipeline is not yet gamma correct. * Saving textures is not supported. * Queue-level API events are not properly listed. API calls between draw-type vkCmd... are listed. * Meshes are not rendered as a preview. diff --git a/renderdoc/data/spv/texdisplay.frag b/renderdoc/data/spv/texdisplay.frag index e13982081..665c8a2f3 100644 --- a/renderdoc/data/spv/texdisplay.frag +++ b/renderdoc/data/spv/texdisplay.frag @@ -102,6 +102,11 @@ void main(void) col = vec4(dot(col.rgb, 1.0f.xxx).xxx, 1.0f); } } + + if(texdisplay.OutputDisplayFormat > 0) + { + col.rgb = pow(clamp(col.rgb, 0.0f.xxx, 1.0f.xxx), 2.2f.xxx); + } color_out = (texdisplay.RawOutput != 0 ? rawcol : col); } diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index a13d8a750..c2dc3e7cd 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -193,9 +193,26 @@ void VulkanReplay::OutputWindow::Create(WrappedVulkan *driver, VkDevice device, } else { - // since we don't care, if the driver has a preference just pick the first - imformat = formats[0].format; + // try and find a format with SRGB correction + imformat = VK_FORMAT_UNDEFINED; imcolspace = formats[0].colorSpace; + + for(uint32_t i=0; i < numFormats; i++) + { + if(IsSRGBFormat(formats[i].format)) + { + imformat = formats[i].format; + imcolspace = formats[i].colorSpace; + RDCASSERT(imcolspace == VK_COLORSPACE_SRGB_NONLINEAR_KHR); + break; + } + } + + if(imformat == VK_FORMAT_UNDEFINED) + { + RDCWARN("Couldn't find SRGB correcting output swapchain format"); + imformat = formats[0].format; + } } SAFE_DELETE_ARRAY(formats); @@ -748,6 +765,11 @@ bool VulkanReplay::RenderTexture(TextureDisplay cfg) // VKTODOMED handle different texture types/displays data->OutputDisplayFormat = 0; + if(!IsSRGBFormat(iminfo.format) && cfg.linearDisplayAsGamma) + { + data->OutputDisplayFormat |= 1; // VKTODOMED constants TEXDISPLAY_GAMMA_CURVE; + } + data->RawOutput = cfg.rawoutput ? 1 : 0; GetDebugManager()->m_TexDisplayUBO.Unmap(vt, dev); diff --git a/renderdoc/driver/vulkan/vk_resources.cpp b/renderdoc/driver/vulkan/vk_resources.cpp index 88e74bb1b..a8c4c7e5f 100644 --- a/renderdoc/driver/vulkan/vk_resources.cpp +++ b/renderdoc/driver/vulkan/vk_resources.cpp @@ -178,3 +178,43 @@ bool IsDepthStencilFormat(VkFormat f) return false; } + +bool IsSRGBFormat(VkFormat f) +{ + switch(f) + { + case VK_FORMAT_R8_SRGB: + case VK_FORMAT_R8G8_SRGB: + case VK_FORMAT_R8G8B8_SRGB: + case VK_FORMAT_R8G8B8A8_SRGB: + case VK_FORMAT_BC1_RGB_SRGB: + case VK_FORMAT_BC1_RGBA_SRGB: + case VK_FORMAT_BC2_SRGB: + case VK_FORMAT_BC3_SRGB: + case VK_FORMAT_BC7_SRGB: + case VK_FORMAT_ETC2_R8G8B8_SRGB: + case VK_FORMAT_ETC2_R8G8B8A1_SRGB: + case VK_FORMAT_ETC2_R8G8B8A8_SRGB: + case VK_FORMAT_ASTC_4x4_SRGB: + case VK_FORMAT_ASTC_5x4_SRGB: + case VK_FORMAT_ASTC_5x5_SRGB: + case VK_FORMAT_ASTC_6x5_SRGB: + case VK_FORMAT_ASTC_6x6_SRGB: + case VK_FORMAT_ASTC_8x5_SRGB: + case VK_FORMAT_ASTC_8x6_SRGB: + case VK_FORMAT_ASTC_8x8_SRGB: + case VK_FORMAT_ASTC_10x5_SRGB: + case VK_FORMAT_ASTC_10x6_SRGB: + case VK_FORMAT_ASTC_10x8_SRGB: + case VK_FORMAT_ASTC_10x10_SRGB: + case VK_FORMAT_ASTC_12x10_SRGB: + case VK_FORMAT_ASTC_12x12_SRGB: + case VK_FORMAT_B8G8R8_SRGB: + case VK_FORMAT_B8G8R8A8_SRGB: + return true; + default: + break; + } + + return false; +} \ No newline at end of file diff --git a/renderdoc/driver/vulkan/vk_resources.h b/renderdoc/driver/vulkan/vk_resources.h index 8b7f99a62..d5b2f2241 100644 --- a/renderdoc/driver/vulkan/vk_resources.h +++ b/renderdoc/driver/vulkan/vk_resources.h @@ -698,3 +698,4 @@ struct ImgState bool IsBlockFormat(VkFormat f); bool IsDepthStencilFormat(VkFormat f); +bool IsSRGBFormat(VkFormat f);