From f20a3c07fb785e6debaa1f16fe4b9c523ae41fb6 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 17 Jan 2020 17:41:58 +0100 Subject: [PATCH] [d3d9] Don't create sRGB views for non-sRGB compatible textures Otherwise we end up creating views with VK_IMAGE_FORMAT_UNDEFINED. --- src/d3d9/d3d9_common_texture.cpp | 4 +++- src/d3d9/d3d9_common_texture.h | 10 +++++++++- src/d3d9/d3d9_subresource.h | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp index fac10888..63c208f7 100644 --- a/src/d3d9/d3d9_common_texture.cpp +++ b/src/d3d9/d3d9_common_texture.cpp @@ -455,7 +455,9 @@ namespace dxvk { return; m_sampleView.Color = CreateView(AllLayers, Lod, VK_IMAGE_USAGE_SAMPLED_BIT, false); - m_sampleView.Srgb = CreateView(AllLayers, Lod, VK_IMAGE_USAGE_SAMPLED_BIT, true); + + if (IsSrgbCompatible()) + m_sampleView.Srgb = CreateView(AllLayers, Lod, VK_IMAGE_USAGE_SAMPLED_BIT, true); } diff --git a/src/d3d9/d3d9_common_texture.h b/src/d3d9/d3d9_common_texture.h index a815b16a..bad2e9ee 100644 --- a/src/d3d9/d3d9_common_texture.h +++ b/src/d3d9/d3d9_common_texture.h @@ -292,6 +292,14 @@ namespace dxvk { return m_desc.Usage & D3DUSAGE_AUTOGENMIPMAP; } + /** + * \brief Checks whether sRGB views can be created + * \returns Whether the format is sRGB compatible. + */ + bool IsSrgbCompatible() const { + return m_mapping.FormatSrgb; + } + /** * \brief Recreate main image view * Recreates the main view of the sampler w/ a specific LOD. @@ -332,7 +340,7 @@ namespace dxvk { void MarkAllDirty() { for (uint32_t i = 0; i < m_dirty.size(); i++) m_dirty[i] = true; } const Rc& GetSampleView(bool srgb) const { - return m_sampleView.Pick(srgb); + return m_sampleView.Pick(srgb && IsSrgbCompatible()); } VkImageLayout DetermineRenderTargetLayout() const { diff --git a/src/d3d9/d3d9_subresource.h b/src/d3d9/d3d9_subresource.h index 7ef87185..a76a0ac6 100644 --- a/src/d3d9/d3d9_subresource.h +++ b/src/d3d9/d3d9_subresource.h @@ -20,7 +20,8 @@ namespace dxvk { , m_container ( pContainer ) , m_texture ( pTexture ) , m_face ( Face ) - , m_mipLevel ( MipLevel ) { } + , m_mipLevel ( MipLevel ) + , m_isSrgbCompatible ( pTexture->IsSrgbCompatible() ) { } ~D3D9Subresource() { // We own the texture! @@ -66,6 +67,7 @@ namespace dxvk { } Rc GetImageView(bool Srgb) { + Srgb &= m_isSrgbCompatible; Rc& view = m_sampleView.Pick(Srgb); if (unlikely(view == nullptr && !IsNull())) @@ -75,6 +77,7 @@ namespace dxvk { } Rc GetRenderTargetView(bool Srgb) { + Srgb &= m_isSrgbCompatible; Rc& view = m_renderTargetView.Pick(Srgb); if (unlikely(view == nullptr && !IsNull())) @@ -116,6 +119,7 @@ namespace dxvk { UINT m_face; UINT m_mipLevel; + bool m_isSrgbCompatible; D3D9ColorView m_sampleView; D3D9ColorView m_renderTargetView; Rc m_depthStencilView;