vk: Implement transport for D24S8_FLOAT data

This commit is contained in:
kd-11 2020-08-15 21:37:10 +03:00 committed by kd-11
parent 794378d5e9
commit f6c6c04648
2 changed files with 65 additions and 6 deletions

View File

@ -280,6 +280,8 @@ namespace vk
"// Depth format conversions\n"
"#define d24_to_f32(bits) floatBitsToUint(float(bits) / 16777215.f)\n"
"#define f32_to_d24(bits) uint(uintBitsToFloat(bits) * 16777215.f)\n"
"#define d24f_to_f32(bits) (bits << 7)\n"
"#define f32_to_d24f(bits) (bits >> 7)\n"
"#define d24x8_to_f32(bits) d24_to_f32(bits >> 8)\n"
"#define d24x8_to_d24x8_swapped(bits) (bits & 0xFF00) | (bits & 0xFF0000) >> 16 | (bits & 0xFF) << 16\n"
"#define f32_to_d24x8_swapped(bits) d24x8_to_d24x8_swapped(f32_to_d24(bits))\n"
@ -492,7 +494,7 @@ namespace vk
}
};
template<bool _SwapBytes = false>
template<bool _SwapBytes = false, bool _DepthFloat = false>
struct cs_gather_d32x8 : cs_interleave_task
{
cs_gather_d32x8()
@ -500,8 +502,20 @@ namespace vk
work_kernel =
" if (index >= block_length)\n"
" return;\n"
"\n"
" depth = f32_to_d24(data[index + z_offset]);\n"
"\n";
if constexpr (!_DepthFloat)
{
work_kernel +=
" depth = f32_to_d24(data[index + z_offset]);\n";
}
else
{
work_kernel +=
" depth = f32_to_d24f(data[index + z_offset]);\n";
}
work_kernel +=
" stencil_offset = (index / 4);\n"
" stencil_shift = (index % 4) * 8;\n"
" stencil = data[stencil_offset + s_offset];\n"
@ -542,6 +556,7 @@ namespace vk
}
};
template<bool _DepthFloat = false>
struct cs_scatter_d32x8 : cs_interleave_task
{
cs_scatter_d32x8()
@ -550,8 +565,20 @@ namespace vk
" if (index >= block_length)\n"
" return;\n"
"\n"
" value = data[index];\n"
" data[index + z_offset] = d24_to_f32(value >> 8);\n"
" value = data[index];\n";
if constexpr (!_DepthFloat)
{
work_kernel +=
" data[index + z_offset] = d24_to_f32(value >> 8);\n";
}
else
{
work_kernel +=
" data[index + z_offset] = d24f_to_f32(value >> 8);\n";
}
work_kernel +=
" stencil_offset = (index / 4);\n"
" stencil_shift = (index % 4) * 8;\n"
" stencil = (value & 0xFF) << stencil_shift;\n"

View File

@ -78,6 +78,11 @@ namespace vk
vkCmdCopyImageToBuffer(cmd, src->value, src->current_layout, dst->value, 1, &region);
break;
}
case VK_FORMAT_D32_SFLOAT:
{
fmt::throw_exception("Unsupported transfer (D16_FLOAT");
break;
}
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
{
@ -113,6 +118,11 @@ namespace vk
{
job = vk::get_compute_task<vk::cs_gather_d24x8<false>>();
}
else if (auto dsv = dynamic_cast<const vk::render_target*>(src);
dsv && dsv->get_format_type() == rsx::format_type::depth_float)
{
job = vk::get_compute_task<vk::cs_gather_d32x8<false, true>>();
}
else
{
job = vk::get_compute_task<vk::cs_gather_d32x8<false>>();
@ -124,6 +134,11 @@ namespace vk
{
job = vk::get_compute_task<vk::cs_gather_d24x8<true>>();
}
else if (auto dsv = dynamic_cast<const vk::render_target*>(src);
dsv && dsv->get_format_type() == rsx::format_type::depth_float)
{
job = vk::get_compute_task<vk::cs_gather_d32x8<true, true>>();
}
else
{
job = vk::get_compute_task<vk::cs_gather_d32x8<true>>();
@ -162,6 +177,11 @@ namespace vk
vkCmdCopyBufferToImage(cmd, src->value, dst->value, dst->current_layout, 1, &region);
break;
}
case VK_FORMAT_D32_SFLOAT:
{
fmt::throw_exception("Unsupported transfer (D16_FLOAT");
break;
}
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
{
@ -191,9 +211,14 @@ namespace vk
{
job = vk::get_compute_task<vk::cs_scatter_d24x8>();
}
else if (auto dsv = dynamic_cast<const vk::render_target*>(dst);
dsv && dsv->get_format_type() == rsx::format_type::depth_float)
{
job = vk::get_compute_task<vk::cs_scatter_d32x8<true>>();
}
else
{
job = vk::get_compute_task<vk::cs_scatter_d32x8>();
job = vk::get_compute_task<vk::cs_scatter_d32x8<false>>();
}
job->run(cmd, src, data_offset, packed_length, z_offset, s_offset);
@ -518,6 +543,13 @@ namespace vk
stretch_image_typeless_unsafe(src, dst, typeless->value, src_rect, dst_rect, VK_IMAGE_ASPECT_DEPTH_BIT);
break;
}
case VK_FORMAT_D32_SFLOAT:
{
auto typeless = vk::get_typeless_helper(VK_FORMAT_R32_SFLOAT, typeless_w, typeless_h);
change_image_layout(cmd, typeless, VK_IMAGE_LAYOUT_GENERAL);
stretch_image_typeless_unsafe(src, dst, typeless->value, src_rect, dst_rect, VK_IMAGE_ASPECT_DEPTH_BIT);
break;
}
case VK_FORMAT_D24_UNORM_S8_UINT:
{
const VkImageAspectFlags depth_stencil = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;