vk_blit_helper: Corect depth to color convertion

This commit is contained in:
GPUCode
2023-08-20 18:48:11 +03:00
parent d22d556d30
commit 622c20761c
3 changed files with 16 additions and 7 deletions

View File

@ -12,15 +12,17 @@ layout(set = 0, binding = 2, rgba8) uniform highp writeonly image2D color;
layout(push_constant, std140) uniform ComputeInfo { layout(push_constant, std140) uniform ComputeInfo {
mediump ivec2 src_offset; mediump ivec2 src_offset;
mediump ivec2 dst_offset;
mediump ivec2 extent; mediump ivec2 extent;
}; };
void main() { 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 = highp uint depth_val =
uint(texelFetch(depth, tex_coord, 0).x * (exp2(32.0) - 1.0)); uint(texelFetch(depth, src_coord, 0).x * (exp2(32.0) - 1.0));
lowp uint stencil_val = texelFetch(stencil, tex_coord, 0).x; lowp uint stencil_val = texelFetch(stencil, src_coord, 0).x;
highp uvec4 components = highp uvec4 components =
uvec4(stencil_val, (uvec3(depth_val) >> uvec3(24u, 16u, 8u)) & 0x000000FFu); 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));
} }

View File

@ -14,6 +14,7 @@ layout(binding = 2) writeonly buffer OutputBuffer{
layout(push_constant, std140) uniform ComputeInfo { layout(push_constant, std140) uniform ComputeInfo {
mediump ivec2 src_offset; mediump ivec2 src_offset;
mediump ivec2 dst_offset;
mediump ivec2 extent; mediump ivec2 extent;
}; };

View File

@ -27,13 +27,14 @@ struct PushConstants {
struct ComputeInfo { struct ComputeInfo {
Common::Vec2i src_offset; Common::Vec2i src_offset;
Common::Vec2i dst_offset;
Common::Vec2i src_extent; Common::Vec2i src_extent;
}; };
inline constexpr vk::PushConstantRange COMPUTE_PUSH_CONSTANT_RANGE{ inline constexpr vk::PushConstantRange COMPUTE_PUSH_CONSTANT_RANGE{
.stageFlags = vk::ShaderStageFlagBits::eCompute, .stageFlags = vk::ShaderStageFlagBits::eCompute,
.offset = 0, .offset = 0,
.size = 2 * sizeof(Common::Vec2i), .size = sizeof(ComputeInfo),
}; };
constexpr std::array<vk::DescriptorSetLayoutBinding, 3> COMPUTE_BINDINGS = {{ constexpr std::array<vk::DescriptorSetLayoutBinding, 3> COMPUTE_BINDINGS = {{
@ -395,9 +396,14 @@ bool BlitHelper::ConvertDS24S8ToRGBA8(Surface& source, Surface& dest,
descriptor_set, {}); descriptor_set, {});
cmdbuf.bindPipeline(vk::PipelineBindPoint::eCompute, d24s8_to_rgba8_pipeline); 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<int>(blit.src_rect.left),
static_cast<int>(blit.src_rect.bottom)},
.dst_offset = Common::Vec2i{static_cast<int>(blit.dst_rect.left),
static_cast<int>(blit.dst_rect.bottom)},
};
cmdbuf.pushConstants(compute_pipeline_layout, vk::ShaderStageFlagBits::eCompute, 0, 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); cmdbuf.dispatch(blit.src_rect.GetWidth() / 8, blit.src_rect.GetHeight() / 8, 1);