From 7a986d731b55acd2249d10b2f2264c1f61b69208 Mon Sep 17 00:00:00 2001
From: Squall-Leonhart <danialhorton@hotmail.com>
Date: Sun, 15 Oct 2023 20:43:48 +1100
Subject: [PATCH 01/11] Implement missing formats for Bravely Default 2

---
 src/video_core/host_shaders/CMakeLists.txt        |  1 +
 .../host_shaders/convert_d32f_to_bgra8.frag       | 15 +++++++++++++++
 src/video_core/renderer_vulkan/blit_image.cpp     |  9 +++++++++
 src/video_core/renderer_vulkan/blit_image.h       |  4 ++++
 .../renderer_vulkan/vk_texture_cache.cpp          | 15 +++++++++++++++
 5 files changed, 44 insertions(+)
 create mode 100644 src/video_core/host_shaders/convert_d32f_to_bgra8.frag

diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt
index 8bb4295784..cf20f39f0a 100644
--- a/src/video_core/host_shaders/CMakeLists.txt
+++ b/src/video_core/host_shaders/CMakeLists.txt
@@ -20,6 +20,7 @@ set(SHADER_FILES
     block_linear_unswizzle_3d.comp
     convert_abgr8_to_d24s8.frag
     convert_d32f_to_abgr8.frag
+    convert_d32f_to_bgra8.frag
     convert_d24s8_to_abgr8.frag
     convert_depth_to_float.frag
     convert_float_to_depth.frag
diff --git a/src/video_core/host_shaders/convert_d32f_to_bgra8.frag b/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
new file mode 100644
index 0000000000..c0d8ff36bf
--- /dev/null
+++ b/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
@@ -0,0 +1,15 @@
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#version 450
+
+layout(binding = 0) uniform sampler2D depth_tex;
+
+layout(location = 0) out vec4 color;
+
+void main() {
+    ivec2 coord = ivec2(gl_FragCoord.xy);
+    float depth = textureLod(depth_tex, coord, 0).r;
+    color = vec4(depth, depth, depth, 1.0);
+    color = color.bgra; // Swap color channels for BGRA format
+}
\ No newline at end of file
diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 4778ac4c59..830c8aba3c 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -13,6 +13,7 @@
 #include "video_core/host_shaders/convert_depth_to_float_frag_spv.h"
 #include "video_core/host_shaders/convert_float_to_depth_frag_spv.h"
 #include "video_core/host_shaders/convert_s8d24_to_abgr8_frag_spv.h"
+#include "video_core/host_shaders/convert_d32f_to_bgra8_frag_spv.h"
 #include "video_core/host_shaders/full_screen_triangle_vert_spv.h"
 #include "video_core/host_shaders/vulkan_blit_depth_stencil_frag_spv.h"
 #include "video_core/host_shaders/vulkan_color_clear_frag_spv.h"
@@ -437,6 +438,7 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
       convert_d32f_to_abgr8_frag(BuildShader(device, CONVERT_D32F_TO_ABGR8_FRAG_SPV)),
       convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)),
       convert_s8d24_to_abgr8_frag(BuildShader(device, CONVERT_S8D24_TO_ABGR8_FRAG_SPV)),
+      convert_d32f_to_bgra8_frag(BuildShader(device, CONVERT_D32F_TO_BGRA8_FRAG_SPV)),
       linear_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_LINEAR>)),
       nearest_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_NEAREST>)) {}
 
@@ -580,6 +582,13 @@ void BlitImageHelper::ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer,
     ConvertDepthStencil(*convert_s8d24_to_abgr8_pipeline, dst_framebuffer, src_image_view);
 }
 
+void BlitImageHelper::ConvertD32FToBGRA8(const Framebuffer* dst_framebuffer,
+                                         ImageView& src_image_view) {
+    ConvertPipelineColorTargetEx(convert_d32f_to_bgra8_pipeline, dst_framebuffer->RenderPass(),
+                                 convert_d32f_to_bgra8_frag);
+    ConvertDepthStencil(*convert_d32f_to_abgr8_pipeline, dst_framebuffer, src_image_view);
+}
+
 void BlitImageHelper::ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,
                                  const std::array<f32, 4>& clear_color,
                                  const Region2D& dst_region) {
diff --git a/src/video_core/renderer_vulkan/blit_image.h b/src/video_core/renderer_vulkan/blit_image.h
index a032c71fb5..d083b46803 100644
--- a/src/video_core/renderer_vulkan/blit_image.h
+++ b/src/video_core/renderer_vulkan/blit_image.h
@@ -73,6 +73,8 @@ public:
 
     void ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
 
+    void ConvertD32FToBGRA8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
+
     void ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,
                     const std::array<f32, 4>& clear_color, const Region2D& dst_region);
 
@@ -133,6 +135,7 @@ private:
     vk::ShaderModule convert_d32f_to_abgr8_frag;
     vk::ShaderModule convert_d24s8_to_abgr8_frag;
     vk::ShaderModule convert_s8d24_to_abgr8_frag;
+    vk::ShaderModule convert_d32f_to_bgra8_frag;
     vk::Sampler linear_sampler;
     vk::Sampler nearest_sampler;
 
@@ -152,6 +155,7 @@ private:
     vk::Pipeline convert_d32f_to_abgr8_pipeline;
     vk::Pipeline convert_d24s8_to_abgr8_pipeline;
     vk::Pipeline convert_s8d24_to_abgr8_pipeline;
+    vk::Pipeline convert_d32f_to_bgra8_pipeline;
 };
 
 } // namespace Vulkan
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index f02d3e8b88..3ad144dab1 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -1193,6 +1193,11 @@ void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, Im
             return blit_image_helper.ConvertD16ToR16(dst, src_view);
         }
         break;
+    case PixelFormat::A8B8G8R8_SRGB:
+        if (src_view.format == PixelFormat::D32_FLOAT) {
+            return blit_image_helper.ConvertD32FToABGR8(dst, src_view);
+        }
+        break;
     case PixelFormat::A8B8G8R8_UNORM:
         if (src_view.format == PixelFormat::S8_UINT_D24_UNORM) {
             return blit_image_helper.ConvertD24S8ToABGR8(dst, src_view);
@@ -1204,6 +1209,16 @@ void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, Im
             return blit_image_helper.ConvertD32FToABGR8(dst, src_view);
         }
         break;
+    case PixelFormat::B8G8R8A8_SRGB:
+        if (src_view.format == PixelFormat::D32_FLOAT) {
+            return blit_image_helper.ConvertD32FToBGRA8(dst, src_view);
+        }
+        break;
+    case PixelFormat::B8G8R8A8_UNORM:
+        if (src_view.format == PixelFormat::D32_FLOAT) {
+            return blit_image_helper.ConvertD32FToBGRA8(dst, src_view);
+        }
+        break;
     case PixelFormat::R32_FLOAT:
         if (src_view.format == PixelFormat::D32_FLOAT) {
             return blit_image_helper.ConvertD32ToR32(dst, src_view);

From 66f41da365f9445059f334a03dafd5f85ae416d3 Mon Sep 17 00:00:00 2001
From: Squall-Leonhart <danialhorton@hotmail.com>
Date: Sun, 15 Oct 2023 20:54:25 +1100
Subject: [PATCH 02/11] moved line to appease the format gods

---
 src/video_core/renderer_vulkan/blit_image.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 830c8aba3c..9f783d4d68 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -10,10 +10,10 @@
 #include "video_core/host_shaders/convert_abgr8_to_d24s8_frag_spv.h"
 #include "video_core/host_shaders/convert_d24s8_to_abgr8_frag_spv.h"
 #include "video_core/host_shaders/convert_d32f_to_abgr8_frag_spv.h"
+#include "video_core/host_shaders/convert_d32f_to_bgra8_frag_spv.h"
 #include "video_core/host_shaders/convert_depth_to_float_frag_spv.h"
 #include "video_core/host_shaders/convert_float_to_depth_frag_spv.h"
 #include "video_core/host_shaders/convert_s8d24_to_abgr8_frag_spv.h"
-#include "video_core/host_shaders/convert_d32f_to_bgra8_frag_spv.h"
 #include "video_core/host_shaders/full_screen_triangle_vert_spv.h"
 #include "video_core/host_shaders/vulkan_blit_depth_stencil_frag_spv.h"
 #include "video_core/host_shaders/vulkan_color_clear_frag_spv.h"

From 03c3f936cfc09b8e7fa38e1ec2551dcecd2c64d3 Mon Sep 17 00:00:00 2001
From: Squall-Leonhart <danialhorton@hotmail.com>
Date: Sun, 15 Oct 2023 20:58:50 +1100
Subject: [PATCH 03/11] missed this line when editing the copypasta

---
 src/video_core/renderer_vulkan/blit_image.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 9f783d4d68..18f51a3274 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -586,7 +586,7 @@ void BlitImageHelper::ConvertD32FToBGRA8(const Framebuffer* dst_framebuffer,
                                          ImageView& src_image_view) {
     ConvertPipelineColorTargetEx(convert_d32f_to_bgra8_pipeline, dst_framebuffer->RenderPass(),
                                  convert_d32f_to_bgra8_frag);
-    ConvertDepthStencil(*convert_d32f_to_abgr8_pipeline, dst_framebuffer, src_image_view);
+    ConvertDepthStencil(*convert_d32f_to_bgra8_pipeline, dst_framebuffer, src_image_view);
 }
 
 void BlitImageHelper::ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,

From f40f65f5d2123c79ffa4c8587d20dada624b5047 Mon Sep 17 00:00:00 2001
From: Squall-Leonhart <danialhorton@hotmail.com>
Date: Mon, 16 Oct 2023 03:17:53 +1100
Subject: [PATCH 04/11] Another missing copy connected to Bravely Default II

adds blit_image_helper.ConvertABGR8ToD32F and fragment shader for performing ABGR and BGRA to D32F copies
---
 src/video_core/host_shaders/CMakeLists.txt     |  1 +
 .../host_shaders/convert_abgr8_to_d32f.frag    | 18 ++++++++++++++++++
 src/video_core/renderer_vulkan/blit_image.cpp  |  8 ++++++++
 src/video_core/renderer_vulkan/blit_image.h    |  4 ++++
 .../renderer_vulkan/vk_texture_cache.cpp       |  4 ++++
 5 files changed, 35 insertions(+)
 create mode 100644 src/video_core/host_shaders/convert_abgr8_to_d32f.frag

diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt
index cf20f39f0a..cff8e38d68 100644
--- a/src/video_core/host_shaders/CMakeLists.txt
+++ b/src/video_core/host_shaders/CMakeLists.txt
@@ -19,6 +19,7 @@ set(SHADER_FILES
     block_linear_unswizzle_2d.comp
     block_linear_unswizzle_3d.comp
     convert_abgr8_to_d24s8.frag
+    convert_abgr8_to_d32f.frag
     convert_d32f_to_abgr8.frag
     convert_d32f_to_bgra8.frag
     convert_d24s8_to_abgr8.frag
diff --git a/src/video_core/host_shaders/convert_abgr8_to_d32f.frag b/src/video_core/host_shaders/convert_abgr8_to_d32f.frag
new file mode 100644
index 0000000000..a1880b9163
--- /dev/null
+++ b/src/video_core/host_shaders/convert_abgr8_to_d32f.frag
@@ -0,0 +1,18 @@
+// SPDX-FileCopyrightText: Copyright 2023 Your Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#version 450
+
+layout(binding = 0) uniform sampler2D color_texture;
+
+void main() {
+    ivec2 coord = ivec2(gl_FragCoord.xy);
+    vec4 color = texelFetch(color_texture, coord, 0).abgr;
+
+    uvec4 bytes = uvec4(color * (exp2(8) - 1.0f)) << uvec4(24, 16, 8, 0);
+    uint depth_unorm = bytes.x | bytes.y | bytes.z | bytes.w;
+
+    float depth_float = uintBitsToFloat(depth_unorm);
+
+    gl_FragDepth = depth_float;
+}
diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 18f51a3274..78a60fbe64 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -8,6 +8,7 @@
 #include "common/settings.h"
 #include "video_core/host_shaders/blit_color_float_frag_spv.h"
 #include "video_core/host_shaders/convert_abgr8_to_d24s8_frag_spv.h"
+#include "video_core/host_shaders/convert_abgr8_to_d32f_frag_spv.h"
 #include "video_core/host_shaders/convert_d24s8_to_abgr8_frag_spv.h"
 #include "video_core/host_shaders/convert_d32f_to_abgr8_frag_spv.h"
 #include "video_core/host_shaders/convert_d32f_to_bgra8_frag_spv.h"
@@ -561,6 +562,13 @@ void BlitImageHelper::ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer,
     Convert(*convert_abgr8_to_d24s8_pipeline, dst_framebuffer, src_image_view);
 }
 
+void BlitImageHelper::ConvertABGR8ToD32F(const Framebuffer* dst_framebuffer,
+                                          const ImageView& src_image_view) {
+    ConvertPipelineDepthTargetEx(convert_abgr8_to_d32f_pipeline, dst_framebuffer->RenderPass(),
+                                 convert_abgr8_to_d32f_frag);
+    Convert(*convert_abgr8_to_d32f_pipeline, dst_framebuffer, src_image_view);
+}
+
 void BlitImageHelper::ConvertD32FToABGR8(const Framebuffer* dst_framebuffer,
                                          ImageView& src_image_view) {
     ConvertPipelineColorTargetEx(convert_d32f_to_abgr8_pipeline, dst_framebuffer->RenderPass(),
diff --git a/src/video_core/renderer_vulkan/blit_image.h b/src/video_core/renderer_vulkan/blit_image.h
index d083b46803..b3281ff3ea 100644
--- a/src/video_core/renderer_vulkan/blit_image.h
+++ b/src/video_core/renderer_vulkan/blit_image.h
@@ -67,6 +67,8 @@ public:
 
     void ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
 
+    void ConvertABGR8ToD32F(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
+
     void ConvertD32FToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
 
     void ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
@@ -132,6 +134,7 @@ private:
     vk::ShaderModule convert_depth_to_float_frag;
     vk::ShaderModule convert_float_to_depth_frag;
     vk::ShaderModule convert_abgr8_to_d24s8_frag;
+    vk::ShaderModule convert_abgr8_to_d32f_frag;
     vk::ShaderModule convert_d32f_to_abgr8_frag;
     vk::ShaderModule convert_d24s8_to_abgr8_frag;
     vk::ShaderModule convert_s8d24_to_abgr8_frag;
@@ -152,6 +155,7 @@ private:
     vk::Pipeline convert_d16_to_r16_pipeline;
     vk::Pipeline convert_r16_to_d16_pipeline;
     vk::Pipeline convert_abgr8_to_d24s8_pipeline;
+    vk::Pipeline convert_abgr8_to_d32f_pipeline;
     vk::Pipeline convert_d32f_to_abgr8_pipeline;
     vk::Pipeline convert_d24s8_to_abgr8_pipeline;
     vk::Pipeline convert_s8d24_to_abgr8_pipeline;
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index 3ad144dab1..f913a99b90 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -1236,6 +1236,10 @@ void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, Im
         }
         break;
     case PixelFormat::D32_FLOAT:
+        if (src_view.format == PixelFormat::A8B8G8R8_SRGB ||
+            src_view.format == PixelFormat::B8G8R8A8_SRGB) {
+            return blit_image_helper.ConvertABGR8ToD32F(dst, src_view);
+        }
         if (src_view.format == PixelFormat::R32_FLOAT) {
             return blit_image_helper.ConvertR32ToD32(dst, src_view);
         }

From 144c0734f5ed1fb827d49cdd1565bd3cf526b627 Mon Sep 17 00:00:00 2001
From: Squall Leonhart <danialhorton@hotmail.com>
Date: Mon, 16 Oct 2023 03:24:44 +1100
Subject: [PATCH 05/11] appease the format gods

---
 src/video_core/renderer_vulkan/blit_image.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 78a60fbe64..7933f4f7ee 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -563,7 +563,7 @@ void BlitImageHelper::ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer,
 }
 
 void BlitImageHelper::ConvertABGR8ToD32F(const Framebuffer* dst_framebuffer,
-                                          const ImageView& src_image_view) {
+                                         const ImageView& src_image_view) {
     ConvertPipelineDepthTargetEx(convert_abgr8_to_d32f_pipeline, dst_framebuffer->RenderPass(),
                                  convert_abgr8_to_d32f_frag);
     Convert(*convert_abgr8_to_d32f_pipeline, dst_framebuffer, src_image_view);

From 12e4757cf394d830aa730523c02639fae87c8f19 Mon Sep 17 00:00:00 2001
From: Squall-Leonhart <danialhorton@hotmail.com>
Date: Mon, 16 Oct 2023 04:20:45 +1100
Subject: [PATCH 06/11] use texelfetch instead of texturelod

---
 src/video_core/host_shaders/convert_d32f_to_abgr8.frag | 2 +-
 src/video_core/host_shaders/convert_d32f_to_bgra8.frag | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/video_core/host_shaders/convert_d32f_to_abgr8.frag b/src/video_core/host_shaders/convert_d32f_to_abgr8.frag
index 04cfef8b55..4e5a9f955b 100644
--- a/src/video_core/host_shaders/convert_d32f_to_abgr8.frag
+++ b/src/video_core/host_shaders/convert_d32f_to_abgr8.frag
@@ -9,6 +9,6 @@ layout(location = 0) out vec4 color;
 
 void main() {
     ivec2 coord = ivec2(gl_FragCoord.xy);
-    float depth = textureLod(depth_tex, coord, 0).r;
+    float depth = texelFetch(depth_tex, coord, 0).r;
     color = vec4(depth, depth, depth, 1.0);
 }
diff --git a/src/video_core/host_shaders/convert_d32f_to_bgra8.frag b/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
index c0d8ff36bf..82dfca739a 100644
--- a/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
+++ b/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
@@ -9,7 +9,7 @@ layout(location = 0) out vec4 color;
 
 void main() {
     ivec2 coord = ivec2(gl_FragCoord.xy);
-    float depth = textureLod(depth_tex, coord, 0).r;
+    float depth = texelFetch(depth_tex, coord, 0).r;
     color = vec4(depth, depth, depth, 1.0);
     color = color.bgra; // Swap color channels for BGRA format
 }
\ No newline at end of file

From 4b0291172eed95df5f491d03b68ff6243b61793a Mon Sep 17 00:00:00 2001
From: Squall Leonhart <danialhorton@hotmail.com>
Date: Mon, 16 Oct 2023 04:29:24 +1100
Subject: [PATCH 07/11] meant to add the unorms as well

---
 src/video_core/renderer_vulkan/vk_texture_cache.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index f913a99b90..a4ee9295f6 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -1236,7 +1236,9 @@ void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, Im
         }
         break;
     case PixelFormat::D32_FLOAT:
-        if (src_view.format == PixelFormat::A8B8G8R8_SRGB ||
+        if (src_view.format == PixelFormat::A8B8G8R8_UNORM ||
+            src_view.format == PixelFormat::B8G8R8A8_UNORM ||
+            src_view.format == PixelFormat::A8B8G8R8_SRGB ||
             src_view.format == PixelFormat::B8G8R8A8_SRGB) {
             return blit_image_helper.ConvertABGR8ToD32F(dst, src_view);
         }

From 90c56f5dc1cab59adbd446aa77b12e64c6c59474 Mon Sep 17 00:00:00 2001
From: Squall Leonhart <danialhorton@hotmail.com>
Date: Mon, 16 Oct 2023 06:07:26 +1100
Subject: [PATCH 08/11] added missing trailing line.

---
 src/video_core/host_shaders/convert_d32f_to_bgra8.frag | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/video_core/host_shaders/convert_d32f_to_bgra8.frag b/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
index 82dfca739a..789c3e0781 100644
--- a/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
+++ b/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
@@ -12,4 +12,4 @@ void main() {
     float depth = texelFetch(depth_tex, coord, 0).r;
     color = vec4(depth, depth, depth, 1.0);
     color = color.bgra; // Swap color channels for BGRA format
-}
\ No newline at end of file
+}

From dbc73c6c6c111b5e87bf3952bce762032802fe41 Mon Sep 17 00:00:00 2001
From: Squall Leonhart <danialhorton@hotmail.com>
Date: Tue, 17 Oct 2023 00:15:31 +1100
Subject: [PATCH 09/11] Added missing BuildShader line

Adds `convert_abgr8_to_d32f_frag(BuildShader(device, CONVERT_ABGR8_TO_D32F_FRAG_SPV)),`
---
 src/video_core/renderer_vulkan/blit_image.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 7933f4f7ee..fd6d3689ec 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -435,6 +435,7 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
       clear_stencil_frag(BuildShader(device, VULKAN_DEPTHSTENCIL_CLEAR_FRAG_SPV)),
       convert_depth_to_float_frag(BuildShader(device, CONVERT_DEPTH_TO_FLOAT_FRAG_SPV)),
       convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)),
+      convert_abgr8_to_d32f_frag(BuildShader(device, CONVERT_ABGR8_TO_D32F_FRAG_SPV)),
       convert_abgr8_to_d24s8_frag(BuildShader(device, CONVERT_ABGR8_TO_D24S8_FRAG_SPV)),
       convert_d32f_to_abgr8_frag(BuildShader(device, CONVERT_D32F_TO_ABGR8_FRAG_SPV)),
       convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)),

From 07143ce15c4cdfd85a5e0d38e838af68f0e156b2 Mon Sep 17 00:00:00 2001
From: Squall Leonhart <danialhorton@hotmail.com>
Date: Tue, 17 Oct 2023 00:26:19 +1100
Subject: [PATCH 10/11] Make Clang happy.

---
 src/video_core/renderer_vulkan/blit_image.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index fd6d3689ec..5030dd2004 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -435,8 +435,8 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
       clear_stencil_frag(BuildShader(device, VULKAN_DEPTHSTENCIL_CLEAR_FRAG_SPV)),
       convert_depth_to_float_frag(BuildShader(device, CONVERT_DEPTH_TO_FLOAT_FRAG_SPV)),
       convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)),
-      convert_abgr8_to_d32f_frag(BuildShader(device, CONVERT_ABGR8_TO_D32F_FRAG_SPV)),
       convert_abgr8_to_d24s8_frag(BuildShader(device, CONVERT_ABGR8_TO_D24S8_FRAG_SPV)),
+      convert_abgr8_to_d32f_frag(BuildShader(device, CONVERT_ABGR8_TO_D32F_FRAG_SPV)),
       convert_d32f_to_abgr8_frag(BuildShader(device, CONVERT_D32F_TO_ABGR8_FRAG_SPV)),
       convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)),
       convert_s8d24_to_abgr8_frag(BuildShader(device, CONVERT_S8D24_TO_ABGR8_FRAG_SPV)),

From 326ebbb2fa87f7e4006e1434649ba1f48b4bebfa Mon Sep 17 00:00:00 2001
From: Squall-Leonhart <danialhorton@hotmail.com>
Date: Tue, 17 Oct 2023 02:38:07 +1100
Subject: [PATCH 11/11] Changes based on hardware tests

Removes unnecessary d32f to bgra shader and blit functions,
update vk_texture_cache to use abgr shader for d32f to BGRA formats
updates  abgr to d32f shader to comply with hardware tests
---
 src/video_core/host_shaders/CMakeLists.txt        |  1 -
 .../host_shaders/convert_abgr8_to_d32f.frag       |  9 +++------
 .../host_shaders/convert_d32f_to_bgra8.frag       | 15 ---------------
 src/video_core/renderer_vulkan/blit_image.cpp     |  9 ---------
 src/video_core/renderer_vulkan/blit_image.h       |  4 ----
 .../renderer_vulkan/vk_texture_cache.cpp          |  4 ++--
 6 files changed, 5 insertions(+), 37 deletions(-)
 delete mode 100644 src/video_core/host_shaders/convert_d32f_to_bgra8.frag

diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt
index cff8e38d68..cd25492328 100644
--- a/src/video_core/host_shaders/CMakeLists.txt
+++ b/src/video_core/host_shaders/CMakeLists.txt
@@ -21,7 +21,6 @@ set(SHADER_FILES
     convert_abgr8_to_d24s8.frag
     convert_abgr8_to_d32f.frag
     convert_d32f_to_abgr8.frag
-    convert_d32f_to_bgra8.frag
     convert_d24s8_to_abgr8.frag
     convert_depth_to_float.frag
     convert_float_to_depth.frag
diff --git a/src/video_core/host_shaders/convert_abgr8_to_d32f.frag b/src/video_core/host_shaders/convert_abgr8_to_d32f.frag
index a1880b9163..095b910c29 100644
--- a/src/video_core/host_shaders/convert_abgr8_to_d32f.frag
+++ b/src/video_core/host_shaders/convert_abgr8_to_d32f.frag
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: Copyright 2023 Your Project
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
 // SPDX-License-Identifier: GPL-2.0-or-later
 
 #version 450
@@ -9,10 +9,7 @@ void main() {
     ivec2 coord = ivec2(gl_FragCoord.xy);
     vec4 color = texelFetch(color_texture, coord, 0).abgr;
 
-    uvec4 bytes = uvec4(color * (exp2(8) - 1.0f)) << uvec4(24, 16, 8, 0);
-    uint depth_unorm = bytes.x | bytes.y | bytes.z | bytes.w;
+    float value = color.a * (color.r + color.g + color.b) / 3.0f;
 
-    float depth_float = uintBitsToFloat(depth_unorm);
-
-    gl_FragDepth = depth_float;
+    gl_FragDepth = value;
 }
diff --git a/src/video_core/host_shaders/convert_d32f_to_bgra8.frag b/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
deleted file mode 100644
index 789c3e0781..0000000000
--- a/src/video_core/host_shaders/convert_d32f_to_bgra8.frag
+++ /dev/null
@@ -1,15 +0,0 @@
-// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#version 450
-
-layout(binding = 0) uniform sampler2D depth_tex;
-
-layout(location = 0) out vec4 color;
-
-void main() {
-    ivec2 coord = ivec2(gl_FragCoord.xy);
-    float depth = texelFetch(depth_tex, coord, 0).r;
-    color = vec4(depth, depth, depth, 1.0);
-    color = color.bgra; // Swap color channels for BGRA format
-}
diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 5030dd2004..1a40a4d054 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -11,7 +11,6 @@
 #include "video_core/host_shaders/convert_abgr8_to_d32f_frag_spv.h"
 #include "video_core/host_shaders/convert_d24s8_to_abgr8_frag_spv.h"
 #include "video_core/host_shaders/convert_d32f_to_abgr8_frag_spv.h"
-#include "video_core/host_shaders/convert_d32f_to_bgra8_frag_spv.h"
 #include "video_core/host_shaders/convert_depth_to_float_frag_spv.h"
 #include "video_core/host_shaders/convert_float_to_depth_frag_spv.h"
 #include "video_core/host_shaders/convert_s8d24_to_abgr8_frag_spv.h"
@@ -440,7 +439,6 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
       convert_d32f_to_abgr8_frag(BuildShader(device, CONVERT_D32F_TO_ABGR8_FRAG_SPV)),
       convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)),
       convert_s8d24_to_abgr8_frag(BuildShader(device, CONVERT_S8D24_TO_ABGR8_FRAG_SPV)),
-      convert_d32f_to_bgra8_frag(BuildShader(device, CONVERT_D32F_TO_BGRA8_FRAG_SPV)),
       linear_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_LINEAR>)),
       nearest_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_NEAREST>)) {}
 
@@ -591,13 +589,6 @@ void BlitImageHelper::ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer,
     ConvertDepthStencil(*convert_s8d24_to_abgr8_pipeline, dst_framebuffer, src_image_view);
 }
 
-void BlitImageHelper::ConvertD32FToBGRA8(const Framebuffer* dst_framebuffer,
-                                         ImageView& src_image_view) {
-    ConvertPipelineColorTargetEx(convert_d32f_to_bgra8_pipeline, dst_framebuffer->RenderPass(),
-                                 convert_d32f_to_bgra8_frag);
-    ConvertDepthStencil(*convert_d32f_to_bgra8_pipeline, dst_framebuffer, src_image_view);
-}
-
 void BlitImageHelper::ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,
                                  const std::array<f32, 4>& clear_color,
                                  const Region2D& dst_region) {
diff --git a/src/video_core/renderer_vulkan/blit_image.h b/src/video_core/renderer_vulkan/blit_image.h
index b3281ff3ea..b2104a59ee 100644
--- a/src/video_core/renderer_vulkan/blit_image.h
+++ b/src/video_core/renderer_vulkan/blit_image.h
@@ -75,8 +75,6 @@ public:
 
     void ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
 
-    void ConvertD32FToBGRA8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
-
     void ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,
                     const std::array<f32, 4>& clear_color, const Region2D& dst_region);
 
@@ -138,7 +136,6 @@ private:
     vk::ShaderModule convert_d32f_to_abgr8_frag;
     vk::ShaderModule convert_d24s8_to_abgr8_frag;
     vk::ShaderModule convert_s8d24_to_abgr8_frag;
-    vk::ShaderModule convert_d32f_to_bgra8_frag;
     vk::Sampler linear_sampler;
     vk::Sampler nearest_sampler;
 
@@ -159,7 +156,6 @@ private:
     vk::Pipeline convert_d32f_to_abgr8_pipeline;
     vk::Pipeline convert_d24s8_to_abgr8_pipeline;
     vk::Pipeline convert_s8d24_to_abgr8_pipeline;
-    vk::Pipeline convert_d32f_to_bgra8_pipeline;
 };
 
 } // namespace Vulkan
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index a4ee9295f6..cdc41816f9 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -1211,12 +1211,12 @@ void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, Im
         break;
     case PixelFormat::B8G8R8A8_SRGB:
         if (src_view.format == PixelFormat::D32_FLOAT) {
-            return blit_image_helper.ConvertD32FToBGRA8(dst, src_view);
+            return blit_image_helper.ConvertD32FToABGR8(dst, src_view);
         }
         break;
     case PixelFormat::B8G8R8A8_UNORM:
         if (src_view.format == PixelFormat::D32_FLOAT) {
-            return blit_image_helper.ConvertD32FToBGRA8(dst, src_view);
+            return blit_image_helper.ConvertD32FToABGR8(dst, src_view);
         }
         break;
     case PixelFormat::R32_FLOAT: