From 622c20761c75510fa84a980d53bef31fe4c4fc64 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 20 Aug 2023 18:48:11 +0300 Subject: [PATCH] vk_blit_helper: Corect depth to color convertion --- .../format_reinterpreter/vulkan_d24s8_to_rgba8.comp | 10 ++++++---- .../host_shaders/vulkan_depth_to_buffer.comp | 1 + src/video_core/renderer_vulkan/vk_blit_helper.cpp | 12 +++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/video_core/host_shaders/format_reinterpreter/vulkan_d24s8_to_rgba8.comp b/src/video_core/host_shaders/format_reinterpreter/vulkan_d24s8_to_rgba8.comp index a3e4c4037..c70748c21 100644 --- a/src/video_core/host_shaders/format_reinterpreter/vulkan_d24s8_to_rgba8.comp +++ b/src/video_core/host_shaders/format_reinterpreter/vulkan_d24s8_to_rgba8.comp @@ -12,15 +12,17 @@ layout(set = 0, binding = 2, rgba8) uniform highp writeonly image2D color; layout(push_constant, std140) uniform ComputeInfo { mediump ivec2 src_offset; + mediump ivec2 dst_offset; mediump ivec2 extent; }; void main() { - ivec2 tex_coord = src_offset + ivec2(gl_GlobalInvocationID.xy); + ivec2 src_coord = src_offset + ivec2(gl_GlobalInvocationID.xy); + ivec2 dst_coord = dst_offset + ivec2(gl_GlobalInvocationID.xy); highp uint depth_val = - uint(texelFetch(depth, tex_coord, 0).x * (exp2(32.0) - 1.0)); - lowp uint stencil_val = texelFetch(stencil, tex_coord, 0).x; + uint(texelFetch(depth, src_coord, 0).x * (exp2(32.0) - 1.0)); + lowp uint stencil_val = texelFetch(stencil, src_coord, 0).x; highp uvec4 components = uvec4(stencil_val, (uvec3(depth_val) >> uvec3(24u, 16u, 8u)) & 0x000000FFu); - imageStore(color, tex_coord, vec4(components) / (exp2(8.0) - 1.0)); + imageStore(color, dst_coord, vec4(components) / (exp2(8.0) - 1.0)); } diff --git a/src/video_core/host_shaders/vulkan_depth_to_buffer.comp b/src/video_core/host_shaders/vulkan_depth_to_buffer.comp index f88209c66..05f656183 100644 --- a/src/video_core/host_shaders/vulkan_depth_to_buffer.comp +++ b/src/video_core/host_shaders/vulkan_depth_to_buffer.comp @@ -14,6 +14,7 @@ layout(binding = 2) writeonly buffer OutputBuffer{ layout(push_constant, std140) uniform ComputeInfo { mediump ivec2 src_offset; + mediump ivec2 dst_offset; mediump ivec2 extent; }; diff --git a/src/video_core/renderer_vulkan/vk_blit_helper.cpp b/src/video_core/renderer_vulkan/vk_blit_helper.cpp index a9e428703..1fea0dee5 100644 --- a/src/video_core/renderer_vulkan/vk_blit_helper.cpp +++ b/src/video_core/renderer_vulkan/vk_blit_helper.cpp @@ -27,13 +27,14 @@ struct PushConstants { struct ComputeInfo { Common::Vec2i src_offset; + Common::Vec2i dst_offset; Common::Vec2i src_extent; }; inline constexpr vk::PushConstantRange COMPUTE_PUSH_CONSTANT_RANGE{ .stageFlags = vk::ShaderStageFlagBits::eCompute, .offset = 0, - .size = 2 * sizeof(Common::Vec2i), + .size = sizeof(ComputeInfo), }; constexpr std::array COMPUTE_BINDINGS = {{ @@ -395,9 +396,14 @@ bool BlitHelper::ConvertDS24S8ToRGBA8(Surface& source, Surface& dest, descriptor_set, {}); cmdbuf.bindPipeline(vk::PipelineBindPoint::eCompute, d24s8_to_rgba8_pipeline); - const auto src_offset = Common::MakeVec(blit.src_rect.left, blit.src_rect.bottom); + const ComputeInfo info = { + .src_offset = Common::Vec2i{static_cast(blit.src_rect.left), + static_cast(blit.src_rect.bottom)}, + .dst_offset = Common::Vec2i{static_cast(blit.dst_rect.left), + static_cast(blit.dst_rect.bottom)}, + }; cmdbuf.pushConstants(compute_pipeline_layout, vk::ShaderStageFlagBits::eCompute, 0, - sizeof(Common::Vec2i), src_offset.AsArray()); + sizeof(info), &info); cmdbuf.dispatch(blit.src_rect.GetWidth() / 8, blit.src_rect.GetHeight() / 8, 1);