From 37c5af12a45f256767e0274b0d1a2d0a858968c8 Mon Sep 17 00:00:00 2001 From: milk4sale <53350507+milk4sale@users.noreply.github.com> Date: Tue, 24 Nov 2026 11:19:38 -0600 Subject: [PATCH] d3d12: an enhanced texture barrier into LAYOUT_UNDEFINED closes and keeps the layout (D3D-BARRIER-INTO-UNDEFINED) CommandList::barrier(TextureBarrier) refused LayoutAfter = UNDEFINED from a defined layout, so the list's Close failed. D3D12 allows it: the contents are no longer needed, as before the memory is aliased. WARP closes such a list (measured on Windows 11 26340 in #984), and #984 reports that the retail title ends a depth buffer's use this way and takes the failed Close as fatal. The rule goes. Vulkan has no transition into UNDEFINED (VUID-VkImageMemoryBarrier2-newLayout-01198), so replay gives each piece a barrier with oldLayout = newLayout, the layout the tracker has for it, which orders the accesses and changes nothing in the image; the tracker keeps the layouts. A piece that was never used gets no barrier and is not zero-filled for it. The next barrier starts from UNDEFINED and discards, as before. UNDEFINED -> UNDEFINED is not touched here: that is #600. The barrier half of item 2 of the split proposed in #984, carried onto main from Moriz82's integration branch (command_list.h, the emit change and the command_list_test, replay_texture_barrier_test and d3d12_close_parity_test cases), restricted to a defined LayoutBefore, with more cases and two GPU tests added. Tests: - command_list_test, replay_texture_barrier_test (CPU): the recorded barrier; kept layouts over mips in two layouts, with the discard flag and without a tracker; an unused image released without a barrier or a zero-fill; the barrier from UNDEFINED that follows. - d3d12_close_parity_test: three enhanced-barrier rows (116 cases, 85 match). - vk_command_replay_test part K (GPU): a colour target, a depth buffer whose planes are in two layouts and an unused image released; the target used again and read back. - d3d12_com_test (GPU, D3D12 list and queue): a depth buffer cleared, released, taken from UNDEFINED again, cleared and read back. Co-authored-by: Moriz82 <72836413+Moriz82@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 --- docs/d3d12_vulkan.md | 20 ++- runtime/src/command_list.h | 5 +- runtime/src/vulkan_replay.h | 27 ++-- runtime/test/command_list_test.cpp | 8 +- runtime/test/d3d12_close_parity_test.cpp | 55 +++++++- runtime/test/d3d12_com_test.cpp | 93 +++++++++++++ runtime/test/replay_texture_barrier_test.cpp | 136 ++++++++++++++++++- runtime/test/vk_command_replay_test.cpp | 119 +++++++++++++++- 8 files changed, 446 insertions(+), 17 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 8bf2bd38ea..354283059e 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -146,7 +146,8 @@ The design is therefore an **IR per command list**: - `Close` freezes the IR. `ExecuteBundle` is accepted only on a direct list, with an already-closed bundle as its callee; the bundle's recorded commands and calls are replayed at the call site, so the source can be reused or reset without changing the parent. Command-list creation and reset require an allocator of the same type. A bundle cannot be submitted directly to a command queue. - Bundle restrictions are checked while recording for the IR operations currently implemented here (barriers, clears, copies, resolves, `SetPredication`, `DiscardResource`, the atomic copies, `RSSetViewports`, `RSSetScissorRects`, `OMSetRenderTargets` and `ClearState`; `WriteBufferImmediate` is allowed in a bundle); those calls are not legal inside a D3D12 bundle and make `Close` return `E_INVALIDARG`. `d3d12_bundle_forbidden_test` measured the last four on the PC runtime without the debug layer: the bundle's `Close` fails (`E_FAIL`, where this layer gives `E_INVALIDARG`) on the default adapter and on WARP, and executing a bundle whose `Close` failed crashes the runtime, so the layer refuses it in `ExecuteBundle` instead. A bundle has no render targets, viewport or root signature of its own, so its state calls (pipeline state, root signature and arguments, vertex and index buffers, topology, blend factor, stencil references) and its draws and dispatches are kept as they were called, and `ExecuteBundle` plays them on the parent through the same members the application would have called. A draw then snapshots the parent's state plus what the bundle set, and what the bundle set stays on the parent afterwards. Commands that need no state (markers, immediate writes) are copied between them in order. `d3d12_bundle_test` measured the rule on the PC runtime, where the default adapter (an RTX 4060 Ti) and WARP drew the same picture in every case it ran. A bundle's draws see the parent's render targets, viewport and scissor, root signature and arguments (also when the bundle sets the same root signature first, so those arguments stay), and vertex and index buffers. A bundle starts with the pipeline state it was created or reset with, not the parent's. After `ExecuteBundle` the parent has that pipeline state and whatever else the bundle set: topology, root arguments, vertex and index buffers, and a different root signature with the bundle's arguments in place of the parent's. Topology: the default adapter takes the parent's when the bundle sets none. That is more lenient than Microsoft's stated rule (topology is undefined when a bundle begins), and WARP follows the rule by removing the device when a bundle draws or hands back without one, so a bundle should set it; the layer follows the default adapter. A bundle that sets a root argument before any root signature crashes the NVIDIA driver (the layer applies it to the parent's signature). The deferred calls are checked when they play, against the parent's root signature, so a bad one makes the parent's `Close` fail, not the bundle's. A per-list state setter must go through the deferred path (`defer()` in `d3d12_com.cpp`, replaying through a private member that does not trace) to work in a bundle. Not deferred yet: `ExecuteIndirect` in a bundle, and bundle `Dispatch` has no GPU test. - What `Close` returns after one recorded call is compared with the PC runtime over WARP (no debug layer) by - `d3d12_close_parity_test`, 113 cases on fresh lists, nothing executed. 82 agree; the other 31 are listed in the + `d3d12_close_parity_test`, 116 cases on fresh lists, nothing executed. 85 agree (three of them enhanced texture + barriers, two into `LAYOUT_UNDEFINED`: section 4.3); the other 31 are listed in the test as known differences. In 16 the layer fails a list WARP closes: draws and dispatches with no pipeline, root arguments before a root signature, a `CopyTextureRegion` box that is empty or inverted, footprint to footprint or at an unaligned footprint offset or pitch, `CopyResource` of a resource onto itself, @@ -2689,6 +2690,23 @@ mapped stages/accesses, and if no single layout serves all uses, use `GENERAL` a `VkPipelineStageFlags2`, `VkAccessFlags2` and `VkImageLayout` (`vulkan_sync`, `vulkan_barrier_access`, `vulkan_layout`). Queue-specific layouts map like their generic forms; ray tracing, video and split scopes use `ALL_COMMANDS`; `LayoutBefore = UNDEFINED` or the discard flag becomes `oldLayout = UNDEFINED`. +- `LayoutAfter = UNDEFINED` from a defined layout (D3D-BARRIER-INTO-UNDEFINED) releases the subresources: their + contents are no longer needed, as before their memory is aliased. Vulkan has no transition into `UNDEFINED` + (VUID-VkImageMemoryBarrier2-newLayout-01198), so each piece gets a barrier with `oldLayout = newLayout`, the + layout the tracker has for it: the accesses are ordered and nothing in the image changes. The tracker keeps those + layouts. A piece never used yet gets no barrier and is not zero-filled for it. The next barrier on these + subresources has to start from `UNDEFINED`, which discards from whatever layout they are in, as before. The list + closes, as it does on WARP (measured on Windows 11 26340 in #984). #984 also reports that the retail title ends a + depth buffer's use this way and takes a failed `Close` as fatal; the layer failed such a list's `Close` until + this change. `UNDEFINED` to `UNDEFINED` is a separate case (#600). + - **Tests:** `command_list_test` and `replay_texture_barrier_test` (CPU: the barriers recorded, the kept layouts, + an unused image, the barrier that follows); three rows of `d3d12_close_parity_test`; `vk_command_replay_test` + part K (a colour target, a depth buffer whose planes are in two layouts and an unused image released, the target + used again and read back); and `d3d12_com_test`, where a depth buffer is cleared, released, taken from + `UNDEFINED` again, cleared and read back through the D3D12 list and queue (16 depth and 16 stencil texels + exact). Run on an RTX 4070 Ti (NVIDIA 620.70.06, Linux): part K natively with the validation layer 1.4.363 and + no error, where the same barriers with `newLayout = UNDEFINED` give VUID-VkImageMemoryBarrier2-newLayout-01198 + four times; the D3D12 tests under Wine. - `DiscardResource` (D3D-26): each discarded image subresource gets a barrier from `oldLayout = UNDEFINED` to the layout the tracker already has for it, so the driver may drop the contents while later commands see no layout change. The other cases are no-ops, which "contents undefined" allows: buffers, discards with rectangles (only diff --git a/runtime/src/command_list.h b/runtime/src/command_list.h index 7c5c09e0ac..eda841ab8a 100644 --- a/runtime/src/command_list.h +++ b/runtime/src/command_list.h @@ -688,10 +688,11 @@ class CommandList { return append(barrier); } + // LayoutAfter UNDEFINED is legal: the subresources' contents are no longer needed, as before their memory is + // aliased (the retail title ends a depth buffer's use this way, #984; WARP closes such a list, + // d3d12_close_parity_test). Replay keeps the image's Vulkan layout and orders the accesses only. bool barrier(const TextureBarrier& barrier) { if (!barrier.resource || !valid_sync(barrier.sync_before, barrier.sync_after)) return false; - if (barrier.layout_after == d3d12_layout::undefined && barrier.layout_before != d3d12_layout::undefined) - return false; if (barrier.flags & ~texture_barrier_discard) return false; if (barrier.range.mip_count && (!barrier.range.layer_count || !barrier.range.plane_count)) return false; if (barrier.sync_after == d3d12_sync::split) return !closed_; diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index d5a73b909d..11aac392a8 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -3602,16 +3602,23 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c const auto range = detail::planes_for_layout(p.binding, p.range, separate); const bool discard = (texture->flags & texture_barrier_discard) || texture->layout_before == d3d12_layout::undefined; + // LayoutAfter UNDEFINED from a defined layout: the contents are no longer needed (the memory is about to + // be aliased, say). Vulkan has no transition into UNDEFINED (VUID-VkImageMemoryBarrier2-newLayout-01198), + // so each piece keeps the layout it is in and the barrier only orders the accesses; the tracker keeps + // that layout too. D3D12 has the next barrier on these subresources start from UNDEFINED, which discards + // from whatever layout they are in. + const bool release = texture->layout_after == d3d12_layout::undefined && + texture->layout_before != d3d12_layout::undefined; const VkImageLayout new_layout = image_layout(p.binding, vulkan_layout(texture->layout_after, p.binding.presentable)); LayoutPieces pieces; - if (discard) + if (discard && !release) pieces.push_back({range, VK_IMAGE_LAYOUT_UNDEFINED}); else { const VkImageLayout before = image_layout(p.binding, vulkan_layout(texture->layout_before, p.binding.presentable)); pieces = detail::current(tracker, id, range, before); - detail::initialize(vk, command_buffer, p.binding, id, pieces, before, tracker); + if (!release) detail::initialize(vk, command_buffer, p.binding, id, pieces, before, tracker); } const BarrierScope src = vulkan_barrier_scope(texture->sync_before, texture->access_before, predicates); const BarrierScope dst = vulkan_barrier_scope(texture->sync_after, texture->access_after, predicates); @@ -3622,6 +3629,8 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c VkImageMemoryBarrier2* const barriers = many.empty() ? few.data() : many.data(); std::uint32_t barrier_count = 0; for (const auto& piece : pieces) { + // Released before it was ever used (the tracker still has it in UNDEFINED): nothing to order. + if (release && piece.layout == VK_IMAGE_LAYOUT_UNDEFINED) continue; VkImageMemoryBarrier2& b = barriers[barrier_count++]; b = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2}; b.srcStageMask = src.stages; @@ -3629,7 +3638,7 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c b.srcAccessMask = src.access; b.dstAccessMask = dst.access; b.oldLayout = piece.layout; - b.newLayout = new_layout; + b.newLayout = release ? piece.layout : new_layout; b.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; b.image = p.binding.image; @@ -3637,11 +3646,13 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c if (b.srcStageMask) detail::restrict_to_queue(vk, b.srcStageMask, b.srcAccessMask); if (b.dstStageMask) detail::restrict_to_queue(vk, b.dstStageMask, b.dstAccessMask); } - VkDependencyInfo dependency{VK_STRUCTURE_TYPE_DEPENDENCY_INFO}; - dependency.imageMemoryBarrierCount = barrier_count; - dependency.pImageMemoryBarriers = barriers; - vk.pipeline_barrier2(command_buffer, &dependency); - if (tracker) tracker->set(id, range, new_layout); + if (barrier_count) { + VkDependencyInfo dependency{VK_STRUCTURE_TYPE_DEPENDENCY_INFO}; + dependency.imageMemoryBarrierCount = barrier_count; + dependency.pImageMemoryBarriers = barriers; + vk.pipeline_barrier2(command_buffer, &dependency); + } + if (tracker && !release) tracker->set(id, range, new_layout); } else if (const auto* color_clear = std::get_if(&command)) { if (p.skip) continue; const VulkanAccess state = vulkan_access(d3d12_state::render_target, false); diff --git a/runtime/test/command_list_test.cpp b/runtime/test/command_list_test.cpp index 4367df6ecf..ea81503e6e 100644 --- a/runtime/test/command_list_test.cpp +++ b/runtime/test/command_list_test.cpp @@ -99,15 +99,19 @@ int main() { CHECK(!list.barrier(BufferBarrier{y::copy, y::vertex_shading, a::copy_dest, a::vertex_buffer, 0})); CHECK(list.barrier(TextureBarrier{y::none, y::render_target, a::no_access, a::render_target, l::undefined, l::render_target, 9, all, texture_barrier_discard})); - CHECK(!list.barrier(TextureBarrier{y::all, y::all, a::common, a::common, l::common, l::undefined, 9, all, 0})); + // Into UNDEFINED: the contents are no longer needed (WARP closes such a list, d3d12_close_parity_test). + CHECK(list.barrier(TextureBarrier{y::depth_stencil, y::none, a::depth_stencil_write, a::no_access, + l::depth_stencil_write, l::undefined, 9, all, 0})); CHECK(!list.barrier(TextureBarrier{y::all, y::all, a::common, a::common, l::common, l::common, 9, all, 0x2})); CHECK(!list.barrier(TextureBarrier{y::all, y::all, a::common, a::common, l::common, l::common, 9, {0, 1, 0, 0, 0, 1}, 0})); // zero layers CHECK(list.close()); - CHECK(list.commands().size() == 4); + CHECK(list.commands().size() == 5); CHECK(std::get(list.commands()[1]).sync_before == y::split); CHECK(std::get(list.commands()[2]).resource == 7); CHECK(std::get(list.commands()[3]).flags == texture_barrier_discard); + CHECK(std::get(list.commands()[4]).layout_before == l::depth_stencil_write && + std::get(list.commands()[4]).layout_after == l::undefined); // Copies: D3D12's own call rules (aligned footprints; degenerate boxes and DEFAULT-heap // CopyResource self-copies are accepted as no-ops and must not record Vulkan commands). diff --git a/runtime/test/d3d12_close_parity_test.cpp b/runtime/test/d3d12_close_parity_test.cpp index 0f01f261d7..eaea8a955e 100644 --- a/runtime/test/d3d12_close_parity_test.cpp +++ b/runtime/test/d3d12_close_parity_test.cpp @@ -48,9 +48,11 @@ struct Env { Ref occlusion; Ref closed_bundle_allocator; Ref closed_bundle; - // The list being recorded, and the same list as ID3D12GraphicsCommandList2 (null when not given). + // The list being recorded, and the same list as ID3D12GraphicsCommandList2 and 7 (null when not given; list7 + // also when the device has no enhanced barriers). ID3D12GraphicsCommandList* list = nullptr; ID3D12GraphicsCommandList2* list2 = nullptr; + ID3D12GraphicsCommandList7* list7 = nullptr; bool init(ID3D12Device* d) { device = d; @@ -163,6 +165,28 @@ constexpr auto stricter = Known::layer_stricter; constexpr auto looser = Known::layer_looser; constexpr auto match = Known::match; +// One enhanced texture barrier over every subresource of `resource`; false when the list has no enhanced barriers. +bool texture_barrier(Env& e, ID3D12Resource* resource, D3D12_BARRIER_SYNC sync_before, D3D12_BARRIER_SYNC sync_after, + D3D12_BARRIER_ACCESS access_before, D3D12_BARRIER_ACCESS access_after, + D3D12_BARRIER_LAYOUT layout_before, D3D12_BARRIER_LAYOUT layout_after) { + if (!e.list7) return false; + D3D12_TEXTURE_BARRIER b{}; + b.SyncBefore = sync_before; + b.SyncAfter = sync_after; + b.AccessBefore = access_before; + b.AccessAfter = access_after; + b.LayoutBefore = layout_before; + b.LayoutAfter = layout_after; + b.pResource = resource; + b.Subresources = {0xffffffff, 0, 0, 0, 0, 0}; // every subresource + D3D12_BARRIER_GROUP group{}; + group.Type = D3D12_BARRIER_TYPE_TEXTURE; + group.NumBarriers = 1; + group.pTextureBarriers = &b; + e.list7->Barrier(1, &group); + return true; +} + std::vector cases() { return { {"empty list", true, match, [](Env&) { return true; }}, @@ -200,6 +224,28 @@ std::vector cases() { e.list->ResourceBarrier(1, &b))}, {"barrier type 7", false, match, CALLS(D3D12_RESOURCE_BARRIER b{}; b.Type = D3D12_RESOURCE_BARRIER_TYPE(7); e.list->ResourceBarrier(1, &b))}, + // Enhanced barriers (ID3D12GraphicsCommandList7::Barrier). LayoutAfter UNDEFINED says the contents are no + // longer needed; the retail title ends a depth buffer's use that way (sync DEPTH_STENCIL -> NONE, access + // DEPTH_STENCIL_WRITE -> NO_ACCESS), and the layer failed the list's Close for it. The WARP column of these + // three rows was measured on Windows 11 26340 (#984), not on the build the header names. + {"Barrier: depth DEPTH_STENCIL_WRITE -> COPY_SOURCE", true, match, + [](Env& e) { + return texture_barrier(e, e.depth.p, D3D12_BARRIER_SYNC_DEPTH_STENCIL, D3D12_BARRIER_SYNC_COPY, + D3D12_BARRIER_ACCESS_DEPTH_STENCIL_WRITE, D3D12_BARRIER_ACCESS_COPY_SOURCE, + D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE, D3D12_BARRIER_LAYOUT_COPY_SOURCE); + }}, + {"Barrier: depth DEPTH_STENCIL_WRITE -> UNDEFINED, sync NONE after", true, match, + [](Env& e) { + return texture_barrier(e, e.depth.p, D3D12_BARRIER_SYNC_DEPTH_STENCIL, D3D12_BARRIER_SYNC_NONE, + D3D12_BARRIER_ACCESS_DEPTH_STENCIL_WRITE, D3D12_BARRIER_ACCESS_NO_ACCESS, + D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE, D3D12_BARRIER_LAYOUT_UNDEFINED); + }}, + {"Barrier: texture COMMON -> UNDEFINED", true, match, + [](Env& e) { + return texture_barrier(e, e.tex.p, D3D12_BARRIER_SYNC_ALL, D3D12_BARRIER_SYNC_NONE, + D3D12_BARRIER_ACCESS_COMMON, D3D12_BARRIER_ACCESS_NO_ACCESS, + D3D12_BARRIER_LAYOUT_COMMON, D3D12_BARRIER_LAYOUT_UNDEFINED); + }}, // CopyBufferRegion {"CopyBufferRegion of 0 bytes", true, match, CALLS(e.list->CopyBufferRegion(e.buffer.p, 0, e.upload.p, 0, 0))}, {"CopyBufferRegion past the end of the destination", false, looser, @@ -434,17 +480,24 @@ bool run_case(Env& env, const Case& c, HRESULT& close) { Ref allocator; Ref list; Ref list2; + Ref list7; CHECK(SUCCEEDED(env.device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator.p)))); CHECK(SUCCEEDED(env.device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocator.p, nullptr, IID_PPV_ARGS(&list.p)))); if (FAILED(list->QueryInterface(IID_PPV_ARGS(&list2.p)))) list2.p = nullptr; + D3D12_FEATURE_DATA_D3D12_OPTIONS12 options12{}; + if (FAILED(env.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &options12, sizeof(options12))) || + !options12.EnhancedBarriersSupported || FAILED(list->QueryInterface(IID_PPV_ARGS(&list7.p)))) + list7.p = nullptr; env.list = list.p; env.list2 = list2.p; + env.list7 = list7.p; const bool recorded = c.record(env); close = recorded ? list->Close() : not_run; if (!recorded) list->Close(); env.list = nullptr; env.list2 = nullptr; + env.list7 = nullptr; return true; } diff --git a/runtime/test/d3d12_com_test.cpp b/runtime/test/d3d12_com_test.cpp index d1d4bf3a61..7f07e8bdf1 100644 --- a/runtime/test/d3d12_com_test.cpp +++ b/runtime/test/d3d12_com_test.cpp @@ -54,9 +54,18 @@ int main(int argc, char** argv) { constexpr VkDeviceSize depth_offset = texels * 4, stencil_offset = depth_offset + texels * 4; const VkBuffer buffer = d.buffer(stencil_offset + texels, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &mapped); EXPECT(rt && ds && buffer && d.depth_format_usable(VK_FORMAT_D32_SFLOAT_S8_UINT)); + // A second depth buffer, for a barrier into LAYOUT_UNDEFINED (a release) and the use that follows it. + const VkImage released = + d.image(VK_FORMAT_D32_SFLOAT_S8_UINT, size, size, 1, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); + void* released_mapped = nullptr; + constexpr VkDeviceSize released_stencil_offset = texels * 4; + const VkBuffer released_buffer = + d.buffer(released_stencil_offset + texels, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &released_mapped); + EXPECT(released && released_buffer); EXPECT(d.run([&](VkCommandBuffer cb) { d.initial_layout(cb, rt, VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); d.initial_layout(cb, ds, depth_stencil_aspects, 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + d.initial_layout(cb, released, depth_stencil_aspects, 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); return true; })); @@ -79,6 +88,13 @@ int main(int argc, char** argv) { const TargetView dsv{rt::d3d12::resource_id(ds_resource), 0, 0, 1}; const D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle{reinterpret_cast(&rtv)}; const D3D12_CPU_DESCRIPTOR_HANDLE dsv_handle{reinterpret_cast(&dsv)}; + auto* released_resource = reinterpret_cast(std::uintptr_t{0x3000}); + ResourceBinding released_binding = ds_binding; + released_binding.image = released; + context.add_resource(rt::d3d12::resource_id(released_resource), released_binding, + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + const TargetView released_dsv{rt::d3d12::resource_id(released_resource), 0, 0, 1}; + const D3D12_CPU_DESCRIPTOR_HANDLE released_dsv_handle{reinterpret_cast(&released_dsv)}; { D3D12_COMMAND_QUEUE_DESC queue_desc{}; @@ -338,6 +354,66 @@ int main(int argc, char** argv) { EXPECT(context.layout(rt::d3d12::resource_id(ds_resource), 0) == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); EXPECT(context.layout(rt::d3d12::resource_id(ds_resource), 1) == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + // A barrier into LAYOUT_UNDEFINED releases a texture: its contents are no longer needed (the retail title + // ends a depth buffer's use this way, #984). The list closes and runs. Vulkan has no transition into + // UNDEFINED, so both planes stay in the layout they were in. + const auto released_barrier = [&](D3D12_BARRIER_SYNC sync_before, D3D12_BARRIER_SYNC sync_after, + D3D12_BARRIER_ACCESS access_before, D3D12_BARRIER_ACCESS access_after, + D3D12_BARRIER_LAYOUT layout_before, D3D12_BARRIER_LAYOUT layout_after) { + D3D12_TEXTURE_BARRIER b{}; + b.SyncBefore = sync_before; + b.SyncAfter = sync_after; + b.AccessBefore = access_before; + b.AccessAfter = access_after; + b.LayoutBefore = layout_before; + b.LayoutAfter = layout_after; + b.pResource = released_resource; + b.Subresources = {0xffffffff, 0, 0, 0, 0, 0}; + D3D12_BARRIER_GROUP g{}; + g.Type = D3D12_BARRIER_TYPE_TEXTURE; + g.NumBarriers = 1; + g.pTextureBarriers = &b; + list->Barrier(1, &g); + }; + // Executes the closed list and waits until the queue has signalled `value` on `done`. + const auto run_list = [&](UINT64 value) { + queue->ExecuteCommandLists(1, lists); + if (rt::d3d12::last_execute_result(queue.p) != ReplayResult::success) return false; + if (FAILED(queue->Signal(done.p, value))) return false; + const HANDLE finished = CreateEventW(nullptr, FALSE, FALSE, nullptr); + const bool ok = finished && SUCCEEDED(done->SetEventOnCompletion(value, finished)) && + WaitForSingleObject(finished, 5000) == WAIT_OBJECT_0; + if (finished) CloseHandle(finished); + return ok; + }; + const auto released_id = rt::d3d12::resource_id(released_resource); + const auto depth_and_stencil = D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL; + EXPECT(SUCCEEDED(allocator->Reset())); + EXPECT(SUCCEEDED(list->Reset(allocator.p, nullptr))); + list->ClearDepthStencilView(released_dsv_handle, depth_and_stencil, 0.25f, 0x07, 0, nullptr); + released_barrier(D3D12_BARRIER_SYNC_DEPTH_STENCIL, D3D12_BARRIER_SYNC_NONE, + D3D12_BARRIER_ACCESS_DEPTH_STENCIL_WRITE, D3D12_BARRIER_ACCESS_NO_ACCESS, + D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE, D3D12_BARRIER_LAYOUT_UNDEFINED); + EXPECT(list->Close() == S_OK); + EXPECT(run_list(2)); + EXPECT(context.layout(released_id, 0) == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + EXPECT(context.layout(released_id, 1) == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + + // Its next use starts from UNDEFINED, which discards; what is written after that is what is read back. + EXPECT(SUCCEEDED(allocator->Reset())); + EXPECT(SUCCEEDED(list->Reset(allocator.p, nullptr))); + released_barrier(D3D12_BARRIER_SYNC_NONE, D3D12_BARRIER_SYNC_DEPTH_STENCIL, D3D12_BARRIER_ACCESS_NO_ACCESS, + D3D12_BARRIER_ACCESS_DEPTH_STENCIL_WRITE, D3D12_BARRIER_LAYOUT_UNDEFINED, + D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE); + list->ClearDepthStencilView(released_dsv_handle, depth_and_stencil, 0.75f, 0x09, 0, nullptr); + released_barrier(D3D12_BARRIER_SYNC_DEPTH_STENCIL, D3D12_BARRIER_SYNC_COPY, + D3D12_BARRIER_ACCESS_DEPTH_STENCIL_WRITE, D3D12_BARRIER_ACCESS_COPY_SOURCE, + D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE, D3D12_BARRIER_LAYOUT_COPY_SOURCE); + EXPECT(list->Close() == S_OK); + EXPECT(run_list(3)); + EXPECT(context.layout(released_id, 0) == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + EXPECT(context.layout(released_id, 1) == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + // A depth outside [0, 1] is recorded as given and the list closes, as on WARP (3ce953ae8; // d3d12_close_parity_test "ClearDepthStencilView depth 1.5", d3d12_clear_test reads the texels back). EXPECT(SUCCEEDED(allocator->Reset())); @@ -383,6 +459,10 @@ int main(int argc, char** argv) { depth_offset); d.read_back(cb, ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_ASPECT_STENCIL_BIT, size, size, 1, buffer, stencil_offset); + d.read_back(cb, released, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_ASPECT_DEPTH_BIT, size, size, 1, + released_buffer, 0); + d.read_back(cb, released, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_ASPECT_STENCIL_BIT, size, size, 1, + released_buffer, released_stencil_offset); return true; })); const auto* data = static_cast(mapped); @@ -404,6 +484,19 @@ int main(int argc, char** argv) { } } EXPECT(!mismatches); + // The depth buffer that was released and used again holds what was written after the release. + const auto* released_data = static_cast(released_mapped); + unsigned released_mismatches = 0; + for (std::uint32_t i = 0; i < texels; ++i) { + float depth; + std::memcpy(&depth, released_data + i * 4, 4); + if (depth != 0.75f || released_data[released_stencil_offset + i] != 0x09) { + if (released_mismatches++ < 4) + std::fprintf(stderr, "released texel %u: depth %f stencil 0x%02x\n", i, depth, + unsigned(released_data[released_stencil_offset + i])); + } + } + EXPECT(!released_mismatches); if (d.validation_errors()) { std::fprintf(stderr, "%u validation errors\n", d.validation_errors()); return 1; diff --git a/runtime/test/replay_texture_barrier_test.cpp b/runtime/test/replay_texture_barrier_test.cpp index 66c594779e..43ee9dcb7d 100644 --- a/runtime/test/replay_texture_barrier_test.cpp +++ b/runtime/test/replay_texture_barrier_test.cpp @@ -3,6 +3,9 @@ // - A range in one layout is one piece: emit makes no heap allocation for it. // - A range whose mips are in different layouts is one piece for each mip: all of them are in the same call, // each with its own old layout. +// - A barrier into UNDEFINED from a defined layout keeps each piece's layout (Vulkan has no transition into +// UNDEFINED) and the tracker's; a piece that was never used records nothing, and the next barrier, from +// UNDEFINED, discards as before. // vkCmdPipelineBarrier2 is a function that records its barriers. No Vulkan loader, GPU or game data. #ifndef VK_NO_PROTOTYPES #define VK_NO_PROTOTYPES @@ -68,6 +71,20 @@ void VKAPI_CALL record_barrier2(VkCommandBuffer, const VkDependencyInfo* info) { g_barriers.push_back(info->pImageMemoryBarriers[i]); } +// What zero-filling an image that was never used calls: its own layout changes and the clear. Counted, not recorded. +std::uint32_t g_fill_calls = 0; + +void VKAPI_CALL count_barrier(VkCommandBuffer, VkPipelineStageFlags, VkPipelineStageFlags, VkDependencyFlags, + std::uint32_t, const VkMemoryBarrier*, std::uint32_t, const VkBufferMemoryBarrier*, + std::uint32_t, const VkImageMemoryBarrier*) { + ++g_fill_calls; +} + +void VKAPI_CALL count_clear(VkCommandBuffer, VkImage, VkImageLayout, const VkClearColorValue*, std::uint32_t, + const VkImageSubresourceRange*) { + ++g_fill_calls; +} + int failures = 0; void expect(bool ok, const char* what) { if (!ok) { @@ -95,7 +112,11 @@ int main() { image.aspects = VK_IMAGE_ASPECT_COLOR_BIT; image.width = image.height = 64; image.mip_levels = mips; - const auto resolve = [&](ResourceId r) { return r == id ? &image : nullptr; }; + // A second image that nothing has used yet: the tracker has it in UNDEFINED. + constexpr ResourceId unused_id = 2; + ResourceBinding unused = image; + unused.image = reinterpret_cast(std::uintptr_t(0x2000)); + const auto resolve = [&](ResourceId r) { return r == id ? &image : r == unused_id ? &unused : nullptr; }; ReplayFunctions vk{}; vk.pipeline_barrier2 = record_barrier2; @@ -170,6 +191,119 @@ int main() { } } + // 3. Into UNDEFINED from a defined layout (the retail title ends a depth buffer's use this way before its memory + // is aliased, #984): Vulkan has no transition into UNDEFINED, so each mip keeps the layout it is in and the + // barrier only orders the accesses. The tracker keeps those layouts. + const auto kept = [&](std::uint32_t mip) { return mip == 1 ? transfer_src : attachment; }; + { + for (std::uint32_t mip = 0; mip < mips; ++mip) + tracker.set(id, {VK_IMAGE_ASPECT_COLOR_BIT, mip, 1, 0, 1}, kept(mip)); + g_barriers.clear(); + g_calls = 0; + CommandList list; + expect(list.barrier(TextureBarrier{y::render_target, y::none, a::render_target, a::no_access, + l::render_target, l::undefined, id, all, 0}) && + list.close(), + "record a barrier into UNDEFINED"); + PreparedList prepared; + expect(prepare(list, resolve, vk, prepared) == ReplayResult::success, "prepare a barrier into UNDEFINED"); + emit(prepared, cb, vk, &tracker); + expect(g_calls == 1 && g_barriers.size() == mips, "into UNDEFINED: one call with a barrier for each mip"); + for (const VkImageMemoryBarrier2& b : g_barriers) { + expect(b.newLayout != VK_IMAGE_LAYOUT_UNDEFINED, "no transition into VK_IMAGE_LAYOUT_UNDEFINED"); + expect(b.oldLayout == b.newLayout && b.oldLayout == kept(b.subresourceRange.baseMipLevel), + "into UNDEFINED: each mip keeps its own layout"); + expect(b.srcStageMask != 0 && b.srcAccessMask != 0, "into UNDEFINED: the earlier accesses are ordered"); + } + for (std::uint32_t mip = 0; mip < mips; ++mip) + expect(tracker.layout(id, mip) == kept(mip), "into UNDEFINED: the tracker keeps the layout"); + } + + // 4. The discard flag changes nothing there: a release has nothing to discard into. + { + g_barriers.clear(); + g_calls = 0; + CommandList list; + expect(list.barrier(TextureBarrier{y::render_target, y::none, a::render_target, a::no_access, + l::render_target, l::undefined, id, all, texture_barrier_discard}) && + list.close(), + "record a barrier into UNDEFINED with the discard flag"); + PreparedList prepared; + expect(prepare(list, resolve, vk, prepared) == ReplayResult::success, + "prepare a barrier into UNDEFINED with the discard flag"); + emit(prepared, cb, vk, &tracker); + expect(g_calls == 1 && g_barriers.size() == mips, "into UNDEFINED with discard: a barrier for each mip"); + for (const VkImageMemoryBarrier2& b : g_barriers) + expect(b.oldLayout == b.newLayout && b.oldLayout == kept(b.subresourceRange.baseMipLevel), + "into UNDEFINED with discard: each mip keeps its own layout"); + for (std::uint32_t mip = 0; mip < mips; ++mip) + expect(tracker.layout(id, mip) == kept(mip), "into UNDEFINED with discard: the tracker keeps the layout"); + } + + // 5. Without a tracker the layout kept is the one the barrier names. + { + g_barriers.clear(); + g_calls = 0; + CommandList list; + expect(list.barrier(TextureBarrier{y::render_target, y::none, a::render_target, a::no_access, + l::render_target, l::undefined, id, all, 0}) && + list.close(), + "record a barrier into UNDEFINED for an untracked replay"); + PreparedList prepared; + expect(prepare(list, resolve, vk, prepared) == ReplayResult::success, + "prepare a barrier into UNDEFINED for an untracked replay"); + emit(prepared, cb, vk, nullptr); + expect(g_calls == 1 && g_barriers.size() == 1 && g_barriers[0].oldLayout == attachment && + g_barriers[0].newLayout == attachment, + "into UNDEFINED without a tracker: the named layout is kept"); + } + + // 6. An image nothing has used is released without a Vulkan call: there is no access to order, and it is not + // zero-filled first, as it would be on its way into any other layout. It stays in UNDEFINED. + { + tracker.track(unused_id, unused, VK_IMAGE_LAYOUT_UNDEFINED); + vk.pipeline_barrier = count_barrier; + vk.clear_color_image = count_clear; + g_barriers.clear(); + g_calls = 0; + CommandList list; + expect(list.barrier(TextureBarrier{y::render_target, y::none, a::render_target, a::no_access, + l::render_target, l::undefined, unused_id, all, 0}) && + list.close(), + "record a barrier into UNDEFINED for an unused image"); + PreparedList prepared; + expect(prepare(list, resolve, vk, prepared) == ReplayResult::success, + "prepare a barrier into UNDEFINED for an unused image"); + emit(prepared, cb, vk, &tracker); + expect(g_calls == 0 && g_barriers.empty(), "an unused image is released without a barrier"); + expect(g_fill_calls == 0, "an unused image is not zero-filled to be released"); + for (std::uint32_t mip = 0; mip < mips; ++mip) + expect(tracker.layout(unused_id, mip) == VK_IMAGE_LAYOUT_UNDEFINED, "an unused image stays in UNDEFINED"); + vk.pipeline_barrier = nullptr; + vk.clear_color_image = nullptr; + } + + // 7. After a release D3D12 has the next barrier start from UNDEFINED: one barrier that discards from whatever + // layouts the mips are in (case 3 left them in two), and the tracker has the new layout. + { + g_barriers.clear(); + g_calls = 0; + CommandList list; + expect(list.barrier(TextureBarrier{y::none, y::render_target, a::no_access, a::render_target, l::undefined, + l::render_target, id, all, 0}) && + list.close(), + "record the barrier that follows a release"); + PreparedList prepared; + expect(prepare(list, resolve, vk, prepared) == ReplayResult::success, + "prepare the barrier that follows a release"); + emit(prepared, cb, vk, &tracker); + expect(g_calls == 1 && g_barriers.size() == 1 && g_barriers[0].oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && + g_barriers[0].newLayout == attachment, + "after a release: one barrier from UNDEFINED into the new layout"); + for (std::uint32_t mip = 0; mip < mips; ++mip) + expect(tracker.layout(id, mip) == attachment, "after a release: the tracker has the new layout"); + } + if (failures) return 1; std::printf("replay_texture_barrier_test: OK\n"); return 0; diff --git a/runtime/test/vk_command_replay_test.cpp b/runtime/test/vk_command_replay_test.cpp index 9769e70be0..f98a962176 100644 --- a/runtime/test/vk_command_replay_test.cpp +++ b/runtime/test/vk_command_replay_test.cpp @@ -8,7 +8,7 @@ // list, which D3D12 orders on the queue and needs an explicit dependency for on Vulkan. Part H copies depth to colour // and back (D32_FLOAT <-> R32_FLOAT), which the replay stages through a scratch buffer. Part I resolves a depth // rectangle (MIN) and checks that the texels around it keep their values. Part J copies between disjoint regions -// of one texture subresource. +// of one texture subresource. Part K releases textures with a barrier into LAYOUT_UNDEFINED and uses one again. // Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation; any validation error fails the test. #include "vk_test_device.h" #include "../src/vulkan_replay.h" @@ -1265,6 +1265,121 @@ int part_j(vktest::Device& d) { return 0; } +// Part K: an enhanced barrier into LAYOUT_UNDEFINED releases a texture (D3D-BARRIER-INTO-UNDEFINED). Vulkan has no +// transition into UNDEFINED, so the replay keeps the layout of every plane and only orders the accesses. Released +// here: a colour target after a clear, a depth buffer whose two planes are in different layouts, and an image nothing +// has used. The colour target is then taken from UNDEFINED again, cleared and read back. Under +// LEONIDA_VK_VALIDATION=1 these barriers must pass the validation layer. +int part_k(vktest::Device& d) { + if (!d.depth_format_usable(VK_FORMAT_D32_SFLOAT_S8_UINT)) { + std::printf("K: skipped, no D32_SFLOAT_S8_UINT\n"); + return 0; + } + constexpr std::uint32_t size = 4, texels = size * size; + const VkImage rt = d.image(VK_FORMAT_R8G8B8A8_UNORM, size, size, 1, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); + const VkImage ds = d.image(VK_FORMAT_D32_SFLOAT_S8_UINT, size, size, 1, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); + const VkImage unused = d.image(VK_FORMAT_R8G8B8A8_UNORM, size, size, 1, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); + void* mapped = nullptr; + const VkBuffer buffer = d.buffer(texels * 4, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &mapped); + EXPECT(rt && ds && unused && buffer); + + const auto binding = [&](VkImage image, VkFormat format, VkImageAspectFlags aspects) { + ResourceBinding b{}; + b.image = image; + b.format = format; + b.aspects = aspects; + b.width = b.height = size; + return b; + }; + constexpr ResourceId rt_id = 50, ds_id = 51, unused_id = 52; + const std::map bindings{ + {rt_id, binding(rt, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT)}, + {ds_id, binding(ds, VK_FORMAT_D32_SFLOAT_S8_UINT, depth_stencil_aspects)}, + {unused_id, binding(unused, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT)}, + }; + const auto resolve = [&](ResourceId id) -> const ResourceBinding* { + const auto it = bindings.find(id); + return it == bindings.end() ? nullptr : &it->second; + }; + + Views views{d, {}}; + ReplayFunctions vk{}; + vk.pipeline_barrier = d.fn("vkCmdPipelineBarrier"); + vk.clear_color_image = d.fn("vkCmdClearColorImage"); + vk.clear_depth_stencil_image = d.fn("vkCmdClearDepthStencilImage"); + vk.pipeline_barrier2 = d.fn("vkCmdPipelineBarrier2"); + vk.begin_rendering = d.fn("vkCmdBeginRendering"); + vk.end_rendering = d.fn("vkCmdEndRendering"); + vk.clear_attachments = d.fn("vkCmdClearAttachments"); + vk.image_view = [&](const ResourceBinding& r, const VkImageSubresourceRange& range) { return views(r, range); }; + vk.separate_depth_stencil_layouts = true; + + LayoutTracker tracker(true); + tracker.track(rt_id, bindings.at(rt_id), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); // render_target + tracker.track(ds_id, bindings.at(ds_id), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); // depth_write + tracker.track(unused_id, bindings.at(unused_id), VK_IMAGE_LAYOUT_UNDEFINED); // never used + + namespace y = d3d12_sync; + namespace a = d3d12_access; + namespace l = d3d12_layout; + const BarrierSubresourceRange all{all_subresources, 0, 0, 0, 0, 0}; + // What the releases give up: a red target, and a depth buffer with its stencil plane moved to a read-only state. + CommandList written; + EXPECT(written.clear_render_target({rt_id, 0, 0, 1}, {1, 0, 0, 1})); + EXPECT(written.clear_depth_stencil({ds_id, 0, 0, 1}, clear_depth | clear_stencil, 1.0f, 0x11)); + EXPECT(written.transition({ds_id, 1, s::depth_write, s::depth_read | s::pixel_shader_resource})); + EXPECT(written.close()); + CommandList release; + EXPECT(release.barrier(TextureBarrier{y::render_target, y::none, a::render_target, a::no_access, l::render_target, + l::undefined, rt_id, all, 0})); + EXPECT(release.barrier(TextureBarrier{y::depth_stencil, y::none, a::depth_stencil_write, a::no_access, + l::depth_stencil_write, l::undefined, ds_id, all, 0})); + EXPECT(release.barrier(TextureBarrier{y::render_target, y::none, a::render_target, a::no_access, l::render_target, + l::undefined, unused_id, all, 0})); + EXPECT(release.close()); + // D3D12 has the next barrier start from UNDEFINED, which discards; green is written after it. + CommandList reuse; + EXPECT(reuse.barrier(TextureBarrier{y::none, y::render_target, a::no_access, a::render_target, l::undefined, + l::render_target, rt_id, all, 0})); + EXPECT(reuse.clear_render_target({rt_id, 0, 0, 1}, {0, 1, 0, 1})); + EXPECT(reuse.barrier(TextureBarrier{y::render_target, y::copy, a::render_target, a::copy_source, l::render_target, + l::copy_source, rt_id, all, 0})); + EXPECT(reuse.close()); + + const unsigned errors_before = d.validation_errors(); + VkImageLayout before[3]{}, after[3]{}; + const auto layouts = [&](VkImageLayout* out) { + out[0] = tracker.layout(rt_id, 0); + out[1] = tracker.layout(ds_id, 0); + out[2] = tracker.layout(ds_id, 1); + }; + const bool ok = d.run([&](VkCommandBuffer cb) { + d.initial_layout(cb, rt, VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + d.initial_layout(cb, ds, depth_stencil_aspects, 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + if (replay(written, cb, resolve, vk, &tracker) != ReplayResult::success) return false; + layouts(before); + if (replay(release, cb, resolve, vk, &tracker) != ReplayResult::success) return false; + layouts(after); + if (tracker.layout(unused_id, 0) != VK_IMAGE_LAYOUT_UNDEFINED) return false; // released without a fill + if (replay(reuse, cb, resolve, vk, &tracker) != ReplayResult::success) return false; + d.read_back(cb, rt, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT, size, size, 1, buffer, 0); + return true; + }); + EXPECT(ok); + // The release changed no layout, and the two depth planes were in different ones. + EXPECT(before[0] == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL && after[0] == before[0]); + EXPECT(before[1] == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL && after[1] == before[1]); + EXPECT(before[2] != before[1] && before[2] != VK_IMAGE_LAYOUT_UNDEFINED && after[2] == before[2]); + EXPECT(tracker.layout(rt_id, 0) == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + const auto* data = static_cast(mapped); + for (std::uint32_t i = 0; i < texels; ++i) expect_rgba("K reuse", data, i, green); + const unsigned errors = d.validation_errors() - errors_before; + std::printf("K: a target, a depth buffer in two plane layouts and an unused image released into UNDEFINED; " + "%u texels of the reused target%s\n", texels, + d.validation ? (errors ? ": validation errors" : ", no validation errors") : " (validation off)"); + return 0; +} + } // namespace int main() { @@ -1276,7 +1391,7 @@ int main() { } EXPECT(status == vktest::DeviceStatus::ready); if (part_a(device) || part_b(device) || part_c(device) || part_d(device) || part_e(device) || part_f(device) || - part_g(device) || part_h(device) || part_i(device) || part_j(device)) + part_g(device) || part_h(device) || part_i(device) || part_j(device) || part_k(device)) return 1; if (g_mismatches) return 1; if (device.validation_errors()) {