From 7a986d731b55acd2249d10b2f2264c1f61b69208 Mon Sep 17 00:00:00 2001 From: Squall-Leonhart Date: Sun, 15 Oct 2023 20:43:48 +1100 Subject: Implement missing formats for Bravely Default 2 --- src/video_core/host_shaders/CMakeLists.txt | 1 + src/video_core/host_shaders/convert_d32f_to_bgra8.frag | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/video_core/host_shaders/convert_d32f_to_bgra8.frag (limited to 'src/video_core/host_shaders') diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index 8bb429578..cf20f39f0 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 000000000..c0d8ff36b --- /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 -- cgit v1.2.3 From f40f65f5d2123c79ffa4c8587d20dada624b5047 Mon Sep 17 00:00:00 2001 From: Squall-Leonhart Date: Mon, 16 Oct 2023 03:17:53 +1100 Subject: 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 + src/video_core/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 ++++ src/video_core/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 (limited to 'src/video_core/host_shaders') diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index cf20f39f0..cff8e38d6 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 000000000..a1880b916 --- /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 18f51a327..78a60fbe6 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 d083b4680..b3281ff3e 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 3ad144dab..f913a99b9 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); } -- cgit v1.2.3 From 12e4757cf394d830aa730523c02639fae87c8f19 Mon Sep 17 00:00:00 2001 From: Squall-Leonhart Date: Mon, 16 Oct 2023 04:20:45 +1100 Subject: 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(-) (limited to 'src/video_core/host_shaders') 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 04cfef8b5..4e5a9f955 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 c0d8ff36b..82dfca739 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 -- cgit v1.2.3 From 90c56f5dc1cab59adbd446aa77b12e64c6c59474 Mon Sep 17 00:00:00 2001 From: Squall Leonhart Date: Mon, 16 Oct 2023 06:07:26 +1100 Subject: added missing trailing line. --- src/video_core/host_shaders/convert_d32f_to_bgra8.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/video_core/host_shaders') 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 82dfca739..789c3e078 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 +} -- cgit v1.2.3 From 326ebbb2fa87f7e4006e1434649ba1f48b4bebfa Mon Sep 17 00:00:00 2001 From: Squall-Leonhart Date: Tue, 17 Oct 2023 02:38:07 +1100 Subject: 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 - src/video_core/host_shaders/convert_abgr8_to_d32f.frag | 9 +++------ src/video_core/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 ---- src/video_core/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 (limited to 'src/video_core/host_shaders') diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index cff8e38d6..cd2549232 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 a1880b916..095b910c2 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 789c3e078..000000000 --- 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 5030dd200..1a40a4d05 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)), nearest_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO)) {} @@ -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& 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 b3281ff3e..b2104a59e 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& 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 a4ee9295f..cdc41816f 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: -- cgit v1.2.3