diff options
| author | aslan2142 <jan.trencansky@protonmail.com> | 2026-11-25 00:24:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-25 00:24:32 +0100 |
| commit | cdb003ea19256ab29997b2ca1e4abf0be05ae9d2 (patch) | |
| tree | 9cd5dd1df53bc471b88991ce566e484a93da1116 /runtime/src | |
| parent | 79d044e54de1701b28a0657028c169e5f590ad2e (diff) | |
| parent | 59dcc9e91713887215168873f0c5268e4298cfd9 (diff) | |
Merge pull request #1055 from milk4sale/d3d12/barrier-into-undefined
d3d12: an enhanced texture barrier into LAYOUT_UNDEFINED closes and keeps the layout (D3D-BARRIER-INTO-UNDEFINED)
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/command_list.h | 5 | ||||
| -rw-r--r-- | runtime/src/vulkan_replay.h | 27 |
2 files changed, 22 insertions, 10 deletions
diff --git a/runtime/src/command_list.h b/runtime/src/command_list.h index bc3496ddc..c28904efe 100644 --- a/runtime/src/command_list.h +++ b/runtime/src/command_list.h | |||
| @@ -701,10 +701,11 @@ public: | |||
| 701 | return append(barrier); | 701 | return append(barrier); |
| 702 | } | 702 | } |
| 703 | 703 | ||
| 704 | // LayoutAfter UNDEFINED is legal: the subresources' contents are no longer needed, as before their memory is | ||
| 705 | // aliased (the retail title ends a depth buffer's use this way, #984; WARP closes such a list, | ||
| 706 | // d3d12_close_parity_test). Replay keeps the image's Vulkan layout and orders the accesses only. | ||
| 704 | bool barrier(const TextureBarrier& barrier) { | 707 | bool barrier(const TextureBarrier& barrier) { |
| 705 | if (!barrier.resource || !valid_sync(barrier.sync_before, barrier.sync_after)) return false; | 708 | if (!barrier.resource || !valid_sync(barrier.sync_before, barrier.sync_after)) return false; |
| 706 | if (barrier.layout_after == d3d12_layout::undefined && barrier.layout_before != d3d12_layout::undefined) | ||
| 707 | return false; | ||
| 708 | if (barrier.flags & ~texture_barrier_discard) return false; | 709 | if (barrier.flags & ~texture_barrier_discard) return false; |
| 709 | if (barrier.range.mip_count && (!barrier.range.layer_count || !barrier.range.plane_count)) return false; | 710 | if (barrier.range.mip_count && (!barrier.range.layer_count || !barrier.range.plane_count)) return false; |
| 710 | if (barrier.sync_after == d3d12_sync::split) return !closed_; | 711 | if (barrier.sync_after == d3d12_sync::split) return !closed_; |
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 386a9e46a..7dcc7e2c0 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h | |||
| @@ -3624,16 +3624,23 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c | |||
| 3624 | const auto range = detail::planes_for_layout(p.binding, p.range, separate); | 3624 | const auto range = detail::planes_for_layout(p.binding, p.range, separate); |
| 3625 | const bool discard = (texture->flags & texture_barrier_discard) || | 3625 | const bool discard = (texture->flags & texture_barrier_discard) || |
| 3626 | texture->layout_before == d3d12_layout::undefined; | 3626 | texture->layout_before == d3d12_layout::undefined; |
| 3627 | // LayoutAfter UNDEFINED from a defined layout: the contents are no longer needed (the memory is about to | ||
| 3628 | // be aliased, say). Vulkan has no transition into UNDEFINED (VUID-VkImageMemoryBarrier2-newLayout-01198), | ||
| 3629 | // so each piece keeps the layout it is in and the barrier only orders the accesses; the tracker keeps | ||
| 3630 | // that layout too. D3D12 has the next barrier on these subresources start from UNDEFINED, which discards | ||
| 3631 | // from whatever layout they are in. | ||
| 3632 | const bool release = texture->layout_after == d3d12_layout::undefined && | ||
| 3633 | texture->layout_before != d3d12_layout::undefined; | ||
| 3627 | const VkImageLayout new_layout = | 3634 | const VkImageLayout new_layout = |
| 3628 | image_layout(p.binding, vulkan_layout(texture->layout_after, p.binding.presentable)); | 3635 | image_layout(p.binding, vulkan_layout(texture->layout_after, p.binding.presentable)); |
| 3629 | LayoutPieces pieces; | 3636 | LayoutPieces pieces; |
| 3630 | if (discard) | 3637 | if (discard && !release) |
| 3631 | pieces.push_back({range, VK_IMAGE_LAYOUT_UNDEFINED}); | 3638 | pieces.push_back({range, VK_IMAGE_LAYOUT_UNDEFINED}); |
| 3632 | else { | 3639 | else { |
| 3633 | const VkImageLayout before = | 3640 | const VkImageLayout before = |
| 3634 | image_layout(p.binding, vulkan_layout(texture->layout_before, p.binding.presentable)); | 3641 | image_layout(p.binding, vulkan_layout(texture->layout_before, p.binding.presentable)); |
| 3635 | pieces = detail::current(tracker, id, range, before); | 3642 | pieces = detail::current(tracker, id, range, before); |
| 3636 | detail::initialize(vk, command_buffer, p.binding, id, pieces, before, tracker); | 3643 | if (!release) detail::initialize(vk, command_buffer, p.binding, id, pieces, before, tracker); |
| 3637 | } | 3644 | } |
| 3638 | const BarrierScope src = vulkan_barrier_scope(texture->sync_before, texture->access_before, predicates); | 3645 | const BarrierScope src = vulkan_barrier_scope(texture->sync_before, texture->access_before, predicates); |
| 3639 | const BarrierScope dst = vulkan_barrier_scope(texture->sync_after, texture->access_after, predicates); | 3646 | const BarrierScope dst = vulkan_barrier_scope(texture->sync_after, texture->access_after, predicates); |
| @@ -3644,6 +3651,8 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c | |||
| 3644 | VkImageMemoryBarrier2* const barriers = many.empty() ? few.data() : many.data(); | 3651 | VkImageMemoryBarrier2* const barriers = many.empty() ? few.data() : many.data(); |
| 3645 | std::uint32_t barrier_count = 0; | 3652 | std::uint32_t barrier_count = 0; |
| 3646 | for (const auto& piece : pieces) { | 3653 | for (const auto& piece : pieces) { |
| 3654 | // Released before it was ever used (the tracker still has it in UNDEFINED): nothing to order. | ||
| 3655 | if (release && piece.layout == VK_IMAGE_LAYOUT_UNDEFINED) continue; | ||
| 3647 | VkImageMemoryBarrier2& b = barriers[barrier_count++]; | 3656 | VkImageMemoryBarrier2& b = barriers[barrier_count++]; |
| 3648 | b = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2}; | 3657 | b = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2}; |
| 3649 | b.srcStageMask = src.stages; | 3658 | b.srcStageMask = src.stages; |
| @@ -3651,7 +3660,7 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c | |||
| 3651 | b.srcAccessMask = src.access; | 3660 | b.srcAccessMask = src.access; |
| 3652 | b.dstAccessMask = dst.access; | 3661 | b.dstAccessMask = dst.access; |
| 3653 | b.oldLayout = piece.layout; | 3662 | b.oldLayout = piece.layout; |
| 3654 | b.newLayout = new_layout; | 3663 | b.newLayout = release ? piece.layout : new_layout; |
| 3655 | b.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; | 3664 | b.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 3656 | b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; | 3665 | b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 3657 | b.image = p.binding.image; | 3666 | b.image = p.binding.image; |
| @@ -3659,11 +3668,13 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c | |||
| 3659 | if (b.srcStageMask) detail::restrict_to_queue(vk, b.srcStageMask, b.srcAccessMask); | 3668 | if (b.srcStageMask) detail::restrict_to_queue(vk, b.srcStageMask, b.srcAccessMask); |
| 3660 | if (b.dstStageMask) detail::restrict_to_queue(vk, b.dstStageMask, b.dstAccessMask); | 3669 | if (b.dstStageMask) detail::restrict_to_queue(vk, b.dstStageMask, b.dstAccessMask); |
| 3661 | } | 3670 | } |
| 3662 | VkDependencyInfo dependency{VK_STRUCTURE_TYPE_DEPENDENCY_INFO}; | 3671 | if (barrier_count) { |
| 3663 | dependency.imageMemoryBarrierCount = barrier_count; | 3672 | VkDependencyInfo dependency{VK_STRUCTURE_TYPE_DEPENDENCY_INFO}; |
| 3664 | dependency.pImageMemoryBarriers = barriers; | 3673 | dependency.imageMemoryBarrierCount = barrier_count; |
| 3665 | vk.pipeline_barrier2(command_buffer, &dependency); | 3674 | dependency.pImageMemoryBarriers = barriers; |
| 3666 | if (tracker) tracker->set(id, range, new_layout); | 3675 | vk.pipeline_barrier2(command_buffer, &dependency); |
| 3676 | } | ||
| 3677 | if (tracker && !release) tracker->set(id, range, new_layout); | ||
| 3667 | } else if (const auto* color_clear = std::get_if<ClearRenderTarget>(&command)) { | 3678 | } else if (const auto* color_clear = std::get_if<ClearRenderTarget>(&command)) { |
| 3668 | if (p.skip) continue; | 3679 | if (p.skip) continue; |
| 3669 | const VulkanAccess state = vulkan_access(d3d12_state::render_target, false); | 3680 | const VulkanAccess state = vulkan_access(d3d12_state::render_target, false); |