upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorAslan2142 <jan.trencansky@protonmail.com>2026-11-26 02:52:29 +0100
committerGitHub <noreply@github.com>2026-11-26 02:52:29 +0100
commitef3493186028023b1fbd2ca3a255ba4337f230da (patch)
tree185ab0d5a302439caefbf2886448aa7e9beaca4b /runtime/src
parent8ff7bc5b23f02d017ab9c33ddc8a043da6e9fc08 (diff)
parent40a69e008403e152e52a0c1983e7e6674b71ff7b (diff)
Merge pull request #2123 from qhukz13/cont/d16s8-d24-uav
d3d12: depth-stencil UAVs for console D16S8 (format 118) made as D24S8
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/vulkan_backend.h5
-rw-r--r--runtime/src/vulkan_replay.h89
2 files changed, 78 insertions, 16 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h
index 4a4d9d485..4e47057f2 100644
--- a/runtime/src/vulkan_backend.h
+++ b/runtime/src/vulkan_backend.h
@@ -1920,6 +1920,11 @@ public:
1920 }; 1920 };
1921 } 1921 }
1922 1922
1923 bool has_depth24() {
1924 std::shared_lock lock(resource_mutex_);
1925 return depth24_ != nullptr;
1926 }
1927
1923 // Copies the replay stages through a buffer (depth <-> colour, vulkan_replay.h) take device-local scratch from 1928 // Copies the replay stages through a buffer (depth <-> colour, vulkan_replay.h) take device-local scratch from
1924 // `allocate`. Without this such a copy is refused as unsupported. `extra_usage` is added to the chunks' transfer 1929 // `allocate`. Without this such a copy is refused as unsupported. `extra_usage` is added to the chunks' transfer
1925 // usage, for configure_quad_indices. 1930 // usage, for configure_quad_indices.
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h
index 706bb2f72..f4e8136c4 100644
--- a/runtime/src/vulkan_replay.h
+++ b/runtime/src/vulkan_replay.h
@@ -1461,6 +1461,9 @@ struct DepthUavCopy {
1461 ResourceBinding conversion{}; 1461 ResourceBinding conversion{};
1462 VkBuffer scratch; 1462 VkBuffer scratch;
1463 VkDeviceSize offset; 1463 VkDeviceSize offset;
1464 VkBuffer depth24_scratch = VK_NULL_HANDLE;
1465 VkDeviceSize depth24_scratch_offset = 0;
1466 std::vector<Depth24Job> depth24_parts;
1464 bool to_storage; 1467 bool to_storage;
1465}; 1468};
1466 1469
@@ -2588,10 +2591,13 @@ void round_trip(const ReplayFunctions& vk, VkCommandBuffer command_buffer, const
2588// Vulkan cannot copy a depth or stencil image aspect directly to or from a color image. The transfer 2591// Vulkan cannot copy a depth or stencil image aspect directly to or from a color image. The transfer
2589// buffer preserves the native D16, D32 or S8 bits. Only the requested layers and planes are copied, even when the device 2592// buffer preserves the native D16, D32 or S8 bits. Only the requested layers and planes are copied, even when the device
2590// requires both parent aspects to transition layouts together. A storage descriptor always names GENERAL. 2593// requires both parent aspects to transition layouts together. A storage descriptor always names GENERAL.
2594template<typename RunDepth24, typename EndStatistics, typename BeginStatistics>
2591inline void copy_depth_uav(const ReplayFunctions& vk, VkCommandBuffer cb, const Prepared& p, const DepthUavCopy& copy, 2595inline void copy_depth_uav(const ReplayFunctions& vk, VkCommandBuffer cb, const Prepared& p, const DepthUavCopy& copy,
2592 VkImageLayout parent_layout, LayoutTracker* tracker) { 2596 VkImageLayout parent_layout, LayoutTracker* tracker, RunDepth24&& run_depth24,
2597 EndStatistics&& end_statistics, BeginStatistics&& begin_statistics) {
2593 constexpr auto all = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 2598 constexpr auto all = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
2594 constexpr auto transfer = VK_PIPELINE_STAGE_TRANSFER_BIT; 2599 constexpr auto transfer = VK_PIPELINE_STAGE_TRANSFER_BIT;
2600 constexpr auto compute = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
2595 constexpr VkAccessFlags any = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; 2601 constexpr VkAccessFlags any = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
2596 const auto parent_access = copy.to_storage ? VK_ACCESS_TRANSFER_READ_BIT : VK_ACCESS_TRANSFER_WRITE_BIT; 2602 const auto parent_access = copy.to_storage ? VK_ACCESS_TRANSFER_READ_BIT : VK_ACCESS_TRANSFER_WRITE_BIT;
2597 const auto child_access = copy.to_storage ? VK_ACCESS_TRANSFER_WRITE_BIT : VK_ACCESS_TRANSFER_READ_BIT; 2603 const auto child_access = copy.to_storage ? VK_ACCESS_TRANSFER_WRITE_BIT : VK_ACCESS_TRANSFER_READ_BIT;
@@ -2619,10 +2625,12 @@ inline void copy_depth_uav(const ReplayFunctions& vk, VkCommandBuffer cb, const
2619 child_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; 2625 child_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2620 // Last use of this staging range was a read by CopyBufferToImage, possibly on the previous barrier. 2626 // Last use of this staging range was a read by CopyBufferToImage, possibly on the previous barrier.
2621 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_READ_BIT, transfer, VK_ACCESS_TRANSFER_WRITE_BIT, transfer); 2627 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_READ_BIT, transfer, VK_ACCESS_TRANSFER_WRITE_BIT, transfer);
2622 // A D32 depth aspect and R32_FLOAT colour carry the same bits through transfer scratch. The 2628 // A D32 depth aspect and R32_FLOAT colour carry the same bits through transfer scratch. A native D24
2623 // intermediate colour image permits a real normalized blit between R32_FLOAT and R16_UNORM; 2629 // depth aspect carries 24-bit UNORM words in copy.scratch and converts to/from floats in depth24_scratch
2624 // shaders see the latter's exact bits through an R16_UINT view. 2630 // via Depth24Converter. The intermediate R32_FLOAT colour image then permits a normalized blit to/from
2631 // R16_UNORM; shaders see the latter's exact bits through an R16_UINT (or R16_UNORM) view.
2625 const bool convert = plane == 0 && copy.conversion.image; 2632 const bool convert = plane == 0 && copy.conversion.image;
2633 const bool d24_convert = convert && !copy.depth24_parts.empty();
2626 const VkImage colour = convert ? copy.conversion.image : child.image; 2634 const VkImage colour = convert ? copy.conversion.image : child.image;
2627 VkImageBlit blit{}; 2635 VkImageBlit blit{};
2628 if (convert) { 2636 if (convert) {
@@ -2640,14 +2648,40 @@ inline void copy_depth_uav(const ReplayFunctions& vk, VkCommandBuffer cb, const
2640 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_WRITE_BIT, transfer, VK_ACCESS_TRANSFER_READ_BIT, transfer); 2648 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_WRITE_BIT, transfer, VK_ACCESS_TRANSFER_READ_BIT, transfer);
2641 } 2649 }
2642 } 2650 }
2643 vk.copy_image_to_buffer(cb, copy.to_storage ? p.binding.image : colour, VK_IMAGE_LAYOUT_GENERAL, 2651 if (d24_convert) {
2644 copy.scratch, 1, copy.to_storage ? &parent_region : &child_region); 2652 child_region.bufferOffset = copy.depth24_scratch_offset;
2645 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_WRITE_BIT, transfer, VK_ACCESS_TRANSFER_READ_BIT, transfer); 2653 if (copy.to_storage) {
2646 vk.copy_buffer_to_image(cb, copy.scratch, copy.to_storage ? colour : p.binding.image, VK_IMAGE_LAYOUT_GENERAL, 2654 vk.copy_image_to_buffer(cb, p.binding.image, VK_IMAGE_LAYOUT_GENERAL, copy.scratch, 1, &parent_region);
2647 1, copy.to_storage ? &child_region : &parent_region); 2655 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_WRITE_BIT, transfer,
2648 if (convert && copy.to_storage) { 2656 VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, compute);
2657 end_statistics();
2658 for (const auto& part : copy.depth24_parts) run_depth24(part);
2659 begin_statistics();
2660 memory_barrier(vk, cb, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, compute,
2661 VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, transfer);
2662 vk.copy_buffer_to_image(cb, copy.depth24_scratch, colour, VK_IMAGE_LAYOUT_GENERAL, 1, &child_region);
2663 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_WRITE_BIT, transfer, VK_ACCESS_TRANSFER_READ_BIT, transfer);
2664 vk.blit_image(cb, colour, VK_IMAGE_LAYOUT_GENERAL, child.image, VK_IMAGE_LAYOUT_GENERAL, 1, &blit, VK_FILTER_NEAREST);
2665 } else {
2666 vk.copy_image_to_buffer(cb, colour, VK_IMAGE_LAYOUT_GENERAL, copy.depth24_scratch, 1, &child_region);
2667 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT,
2668 transfer | compute, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, compute);
2669 end_statistics();
2670 for (const auto& part : copy.depth24_parts) run_depth24(part);
2671 begin_statistics();
2672 memory_barrier(vk, cb, VK_ACCESS_SHADER_WRITE_BIT, compute, VK_ACCESS_TRANSFER_READ_BIT, transfer);
2673 vk.copy_buffer_to_image(cb, copy.scratch, p.binding.image, VK_IMAGE_LAYOUT_GENERAL, 1, &parent_region);
2674 }
2675 } else {
2676 vk.copy_image_to_buffer(cb, copy.to_storage ? p.binding.image : colour, VK_IMAGE_LAYOUT_GENERAL,
2677 copy.scratch, 1, copy.to_storage ? &parent_region : &child_region);
2649 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_WRITE_BIT, transfer, VK_ACCESS_TRANSFER_READ_BIT, transfer); 2678 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_WRITE_BIT, transfer, VK_ACCESS_TRANSFER_READ_BIT, transfer);
2650 vk.blit_image(cb, colour, VK_IMAGE_LAYOUT_GENERAL, child.image, VK_IMAGE_LAYOUT_GENERAL, 1, &blit, VK_FILTER_NEAREST); 2679 vk.copy_buffer_to_image(cb, copy.scratch, copy.to_storage ? colour : p.binding.image, VK_IMAGE_LAYOUT_GENERAL,
2680 1, copy.to_storage ? &child_region : &parent_region);
2681 if (convert && copy.to_storage) {
2682 memory_barrier(vk, cb, VK_ACCESS_TRANSFER_WRITE_BIT, transfer, VK_ACCESS_TRANSFER_READ_BIT, transfer);
2683 vk.blit_image(cb, colour, VK_IMAGE_LAYOUT_GENERAL, child.image, VK_IMAGE_LAYOUT_GENERAL, 1, &blit, VK_FILTER_NEAREST);
2684 }
2651 } 2685 }
2652 image_barrier(vk, cb, child, color, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, 2686 image_barrier(vk, cb, child, color, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL,
2653 child_access, transfer, any, all); 2687 child_access, transfer, any, all);
@@ -3138,6 +3172,8 @@ inline bool has_helper_dispatch(const PreparedList& out, std::size_t i) {
3138 const auto& p = out.commands[i]; 3172 const auto& p = out.commands[i];
3139 if (p.predicate.scratch || !p.predicated_copy.empty() || p.has_depth24 || p.counted_dispatch.indirect) 3173 if (p.predicate.scratch || !p.predicated_copy.empty() || p.has_depth24 || p.counted_dispatch.indirect)
3140 return true; 3174 return true;
3175 if (p.depth_uav_copy != UINT32_MAX && !out.depth_uav_copies[p.depth_uav_copy].depth24_parts.empty())
3176 return true;
3141 return std::holds_alternative<Draw>(out.list->commands()[i]) && p.draw < out.draws.size() && 3177 return std::holds_alternative<Draw>(out.list->commands()[i]) && p.draw < out.draws.size() &&
3142 out.draws[p.draw].quad_indices.buffer; 3178 out.draws[p.draw].quad_indices.buffer;
3143} 3179}
@@ -3477,8 +3513,27 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun
3477 copy.scratch = plane_scratch; 3513 copy.scratch = plane_scratch;
3478 copy.offset = plane_offset; 3514 copy.offset = plane_offset;
3479 copy.to_storage = after; 3515 copy.to_storage = after;
3516 if (copy.conversion.image && p.binding.format == VK_FORMAT_D24_UNORM_S8_UINT) {
3517 if (!vk.depth24_prepare || !vk.depth24_run ||
3518 (vk.queue_stages && !(vk.queue_stages & VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT)) ||
3519 texels > UINT32_MAX || (statistics_active && !statistics_helpers))
3520 return ReplayResult::unsupported;
3521 Depth24Job job{};
3522 job.to_float = after;
3523 job.app = plane_scratch;
3524 job.app_offset = plane_offset;
3525 job.app_size = plane_offset + bytes;
3526 job.width = p.binding.width;
3527 job.height = p.binding.height;
3528 job.slices = p.range.layerCount;
3529 job.app_row_words = job.width;
3530 job.app_slice_words = std::uint32_t(texels);
3531 if (!vk.depth24_prepare(job, copy.depth24_parts)) return ReplayResult::unsupported;
3532 copy.depth24_scratch = job.scratch;
3533 copy.depth24_scratch_offset = job.scratch_offset;
3534 }
3480 p.depth_uav_copy = static_cast<std::uint32_t>(out.depth_uav_copies.size()); 3535 p.depth_uav_copy = static_cast<std::uint32_t>(out.depth_uav_copies.size());
3481 out.depth_uav_copies.push_back(copy); 3536 out.depth_uav_copies.push_back(std::move(copy));
3482 return ReplayResult::success; 3537 return ReplayResult::success;
3483 }; 3538 };
3484 3539
@@ -4592,9 +4647,11 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_
4592 vk.depth24_run(command_buffer, job); 4647 vk.depth24_run(command_buffer, job);
4593 if (predicate.buffer) vk.begin_conditional_rendering(command_buffer, &predicate); 4648 if (predicate.buffer) vk.begin_conditional_rendering(command_buffer, &predicate);
4594 }; 4649 };
4595 const auto finish_depth_uav_barrier = [&](const detail::Prepared& p, VkImageLayout layout) { 4650 const auto finish_depth_uav_barrier = [&](const detail::Prepared& p, VkImageLayout layout,
4651 auto&& end_statistics, auto&& begin_statistics) {
4596 if (p.depth_uav_copy != UINT32_MAX) { 4652 if (p.depth_uav_copy != UINT32_MAX) {
4597 detail::copy_depth_uav(vk, command_buffer, p, prepared.depth_uav_copies[p.depth_uav_copy], layout, tracker); 4653 detail::copy_depth_uav(vk, command_buffer, p, prepared.depth_uav_copies[p.depth_uav_copy], layout, tracker,
4654 run_depth24, end_statistics, begin_statistics);
4598 } else if (p.order_depth_uav) { 4655 } else if (p.order_depth_uav) {
4599 // A UAV-to-UAV texture barrier names the parent, but the actual shader accesses target its children. 4656 // A UAV-to-UAV texture barrier names the parent, but the actual shader accesses target its children.
4600 detail::memory_barrier(vk, command_buffer, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 4657 detail::memory_barrier(vk, command_buffer, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
@@ -4677,7 +4734,7 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_
4677 detail::image_barrier(vk, command_buffer, p.binding, piece.range, piece.layout, new_layout, 4734 detail::image_barrier(vk, command_buffer, p.binding, piece.range, piece.layout, new_layout,
4678 from.access, from.stages, to.access, to.stages); 4735 from.access, from.stages, to.access, to.stages);
4679 if (tracker) tracker->set(id, range, new_layout); 4736 if (tracker) tracker->set(id, range, new_layout);
4680 finish_depth_uav_barrier(p, new_layout); 4737 finish_depth_uav_barrier(p, new_layout, end_statistics, begin_statistics);
4681 } else if (std::holds_alternative<UavBarrier>(command)) { 4738 } else if (std::holds_alternative<UavBarrier>(command)) {
4682 const VulkanAccess uav = vulkan_access(d3d12_state::unordered_access, false); 4739 const VulkanAccess uav = vulkan_access(d3d12_state::unordered_access, false);
4683 VkAccessFlags src_access = VK_ACCESS_SHADER_WRITE_BIT; 4740 VkAccessFlags src_access = VK_ACCESS_SHADER_WRITE_BIT;
@@ -4777,7 +4834,7 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_
4777 vk.pipeline_barrier2(command_buffer, &dependency); 4834 vk.pipeline_barrier2(command_buffer, &dependency);
4778 } 4835 }
4779 if (tracker && !release) tracker->set(id, range, new_layout); 4836 if (tracker && !release) tracker->set(id, range, new_layout);
4780 if (!release) finish_depth_uav_barrier(p, new_layout); 4837 if (!release) finish_depth_uav_barrier(p, new_layout, end_statistics, begin_statistics);
4781 } else if (const auto* color_clear = std::get_if<ClearRenderTarget>(&command)) { 4838 } else if (const auto* color_clear = std::get_if<ClearRenderTarget>(&command)) {
4782 if (p.skip) continue; 4839 if (p.skip) continue;
4783 if constexpr (Checkpoints) checkpoints->record(command_buffer, i, CheckpointKind::clear); 4840 if constexpr (Checkpoints) checkpoints->record(command_buffer, i, CheckpointKind::clear);