VERY experimental Nintendo Switch 2 emulator
C++
TextureCache: Add R16G16 to D24S8 converter.
Fernando Sahmkowdf1eabfc53c5
diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txtindex a2e046f126..1c91999d7e 100644--- a/src/video_core/host_shaders/CMakeLists.txt+++ b/src/video_core/host_shaders/CMakeLists.txt@@ -17,6 +17,7 @@ set(SHADER_FILESconvert_d24s8_to_r16g16.fragconvert_depth_to_float.fragconvert_float_to_depth.frag+ convert_r16g16_to_d24s8.fragfull_screen_triangle.vertfxaa.fragfxaa.vertdiff --git a/src/video_core/host_shaders/convert_r16g16_to_d24s8.frag b/src/video_core/host_shaders/convert_r16g16_to_d24s8.fragnew file mode 100644index 0000000000..7b1b914f6e--- /dev/null+++ b/src/video_core/host_shaders/convert_r16g16_to_d24s8.frag@@ -0,0 +1,18 @@+// Copyright 2021 yuzu Emulator Project+// Licensed under GPLv2 or any later version+// Refer to the license.txt file included.++#version 450+// #extension GL_ARB_shader_stencil_export : require++layout(binding = 0) uniform sampler2D color_texture;++void main() {+ ivec2 coord = ivec2(gl_FragCoord.xy);+ vec4 color = texelFetch(color_texture, coord, 0).rgba;+ uint depth_stencil_unorm = (uint(color.r * (exp2(16) - 1.0f)) << 16)+ | (uint(color.g * (exp2(16) - 1.0f)) << 16);++ gl_FragDepth = float(depth_stencil_unorm >> 8) / (exp2(24.0) - 1.0f);+ // gl_FragStencilRefARB = int(depth_stencil_unorm & 0x00FF);+}diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cppindex e70459de5a..28b631f73f 100644--- a/src/video_core/renderer_vulkan/blit_image.cpp+++ b/src/video_core/renderer_vulkan/blit_image.cpp@@ -11,6 +11,7 @@#include "video_core/host_shaders/convert_d24s8_to_r16g16_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_r16g16_to_d24s8_frag_spv.h"#include "video_core/host_shaders/full_screen_triangle_vert_spv.h"#include "video_core/host_shaders/vulkan_blit_color_float_frag_spv.h"#include "video_core/host_shaders/vulkan_blit_depth_stencil_frag_spv.h"@@ -361,6 +362,7 @@ BlitImageHelper::BlitImageHelper(const Device& device_, VKScheduler& scheduler_,convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)),convert_abgr8_to_d24s8_frag(BuildShader(device, CONVERT_ABGR8_TO_D24S8_FRAG_SPV)),convert_b10g11r11_to_d24s8_frag(BuildShader(device, CONVERT_B10G11R11_TO_D24S8_FRAG_SPV)),+ convert_r16g16_to_d24s8_frag(BuildShader(device, CONVERT_R16G16_TO_D24S8_FRAG_SPV)),convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)),convert_d24s8_to_b10g11r11_frag(BuildShader(device, CONVERT_D24S8_TO_B10G11R11_FRAG_SPV)),convert_d24s8_to_r16g16_frag(BuildShader(device, CONVERT_D24S8_TO_R16G16_FRAG_SPV)),@@ -476,6 +478,15 @@ void BlitImageHelper::ConvertB10G11R11ToD24S8(const Framebuffer* dst_framebufferdown_shift);}+void BlitImageHelper::ConvertR16G16ToD24S8(const Framebuffer* dst_framebuffer,+ const ImageView& src_image_view, u32 up_scale,+ u32 down_shift) {+ ConvertPipelineDepthTargetEx(convert_r16g16_to_d24s8_pipeline, dst_framebuffer->RenderPass(),+ convert_r16g16_to_d24s8_frag, true);+ Convert(*convert_r16g16_to_d24s8_pipeline, dst_framebuffer, src_image_view, up_scale,+ down_shift);+}+void BlitImageHelper::ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer,ImageView& src_image_view, u32 up_scale, u32 down_shift) {ConvertPipelineColorTargetEx(convert_d24s8_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.hindex 607964b5e3..cec0953413 100644--- a/src/video_core/renderer_vulkan/blit_image.h+++ b/src/video_core/renderer_vulkan/blit_image.h@@ -62,6 +62,9 @@ public:void ConvertB10G11R11ToD24S8(const Framebuffer* dst_framebuffer,const ImageView& src_image_view, u32 up_scale, u32 down_shift);+ void ConvertR16G16ToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,+ u32 up_scale, u32 down_shift);+void ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view,u32 up_scale, u32 down_shift);@@ -109,6 +112,7 @@ private:vk::ShaderModule convert_float_to_depth_frag;vk::ShaderModule convert_abgr8_to_d24s8_frag;vk::ShaderModule convert_b10g11r11_to_d24s8_frag;+ vk::ShaderModule convert_r16g16_to_d24s8_frag;vk::ShaderModule convert_d24s8_to_abgr8_frag;vk::ShaderModule convert_d24s8_to_b10g11r11_frag;vk::ShaderModule convert_d24s8_to_r16g16_frag;@@ -125,6 +129,7 @@ private:vk::Pipeline convert_r16_to_d16_pipeline;vk::Pipeline convert_abgr8_to_d24s8_pipeline;vk::Pipeline convert_b10g11r11_to_d24s8_pipeline;+ vk::Pipeline convert_r16g16_to_d24s8_pipeline;vk::Pipeline convert_d24s8_to_abgr8_pipeline;vk::Pipeline convert_d24s8_to_b10g11r11_pipeline;vk::Pipeline convert_d24s8_to_r16g16_pipeline;diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cppindex 28a659c0e0..af1a110592 100644--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp@@ -915,6 +915,9 @@ void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, Imif (src_view.format == PixelFormat::B10G11R11_FLOAT) {return blit_image_helper.ConvertB10G11R11ToD24S8(dst, src_view, up_scale, down_shift);}+ if (src_view.format == PixelFormat::R16G16_UNORM) {+ return blit_image_helper.ConvertR16G16ToD24S8(dst, src_view, up_scale, down_shift);+ }break;case PixelFormat::D32_FLOAT:if (src_view.format == PixelFormat::R32_FLOAT) {