Repository navigation
Runtime: order back-to-back copies into an image already in the transfer layout - #782
Conversation
…fer layout D3D12 orders consecutive copies and resolves on a resource that stays in COPY_DEST or COPY_SOURCE without a barrier from the application; Vulkan needs one. detail::copy_layout emitted a barrier only when the layout changed, so a second copy into an image the first had already left in TRANSFER_DST_OPTIMAL was unordered with it: synchronization validation reported 10 WRITE_AFTER_WRITE hazards in d3d12_vulkan_device_test (@guimsolutions's finding in ItsNotRexed#634). When a piece needs no transition, copy_layout now adds a memory barrier from earlier transfer writes to the new transfer access (transfer stage only). Copies and resolves both go through it. With VK_LAYER_VALIDATE_SYNC=1: d3d12_vulkan_device_test goes from 10 hazards (exit 1) to 0; the descriptor, method-variants, sampler2 and replay tests report none either.
|
Confirmed 5ec780c on RTX 5080 (616.92) and AMD Radeon(TM) Graphics (26.10.1), with both LEONIDA_VK_VALIDATION=1 and VK_LAYER_VALIDATE_SYNC=1. The unchanged d3d12_vulkan_device CTest passed on both. I also ran an isolated source-built regression sharing the PR's real replay code. On 67204bf that fixture failed with exactly two WRITE_AFTER_WRITE messages per GPU, one for the footprint upload following the image copy, then one for the image copy following the upload. With your patch all 64 RGBA texels of the partially written volume matched on both devices, with zero validation errors. The GPU had also returned the expected bytes before the fix, so the before/after difference here is the synchronization check. Our claims crossed. I'll leave the production change with this PR. Here's the test-only hunk for inclusion if you'd like to keep the mixed-copy regression. The original 2×2×2 boxed copy is followed by a two-texel footprint copy and a one-texel image copy into the same COPY_DEST volume. Removing just the final copy gives RGBA (16,1,1,255) at (3,0,1) instead of the expected (51,121,48,255). Regression hunk for runtime/test/vk_command_replay_test.cppdiff --git a/runtime/test/vk_command_replay_test.cpp b/runtime/test/vk_command_replay_test.cpp
index 1fe18dc..1e3d34b 100644
--- a/runtime/test/vk_command_replay_test.cpp
+++ b/runtime/test/vk_command_replay_test.cpp
@@ -389,6 +389,10 @@ int part_c(vktest::Device& d) {
EXPECT(list.copy_texture({sub(volume_id), 0, 0, 0, slices(up_id, up_at, size), false, {}})); // four slices up
EXPECT(list.transition({volume_id, 0, s::copy_dest, s::copy_source}));
EXPECT(list.copy_texture({sub(part_id), 2, 0, 1, sub(volume_id), true, {1, 1, 1, 3, 3, 3}})); // 2x2x2 to (2, 0, 1)
+ // Copies to the same COPY_DEST subresource are ordered even without a D3D12 transition.
+ // Overwrite two texels from the footprint, then overwrite only the second one from the image.
+ EXPECT(list.copy_texture({sub(part_id), 2, 0, 1, slices(up_id, up_at, size), true, {0, 0, 0, 2, 1, 1}}));
+ EXPECT(list.copy_texture({sub(part_id), 3, 0, 1, sub(volume_id), true, {3, 3, 3, 4, 4, 4}}));
EXPECT(list.copy_resource({whole_id, volume_id}));
EXPECT(list.transition({part_id, 0, s::copy_dest, s::copy_source}));
EXPECT(list.transition({whole_id, 0, s::copy_dest, s::copy_source}));
@@ -449,7 +453,10 @@ int part_c(vktest::Device& d) {
if (z == 1 || z == 2) expect_texel("C slices", r + back_at + row, texel(x, y, z), x);
// The block came from (1..2, 1..2, 1..2); the rest of the volume was zero-filled on first use.
const bool inside = x >= 2 && y < 2 && z >= 1 && z < 3;
- expect_texel("C block", r + part_at + row, inside ? texel(x - 1, y + 1, z) : zero, x);
+ const std::uint8_t* expected = inside ? texel(x - 1, y + 1, z) : zero;
+ if (y == 0 && z == 1 && x == 2) expected = texel(0, 0, 0);
+ if (y == 0 && z == 1 && x == 3) expected = texel(3, 3, 3);
+ expect_texel("C block", r + part_at + row, expected, x);
}
}
} |
|
Tested 5ec780c on AMD Radeon RX 7600 (RDNA3, gfx1102), driver 32.0.32029.2010, Windows 11 Pro build 26300, MSVC 19.44, Vulkan SDK 1.4.363.0: pass.
Synthetic tests only, no game files. AI-assisted (Claude Code); I reviewed the diff and the runs. |
Item: @guimsolutions's finding in #634, the 10 copy write-after-write hazards under synchronization validation (claimed there).
Cause. D3D12 orders consecutive copies and resolves on a resource that stays in
COPY_DESTorCOPY_SOURCE, without a barrier from the application. Vulkan needs one.detail::copy_layout(runtime/src/vulkan_replay.h) emitted a barrier only when an image had to change layout. So when a secondvkCmdCopyImageorvkCmdCopyBufferToImagewrote an image the first copy had already left inTRANSFER_DST_OPTIMAL, the two were unordered.Reproduced on
main67204bf withLEONIDA_VK_VALIDATION=1 VK_LAYER_VALIDATE_SYNC=1:d3d12_vulkan_device_testreports 10WRITE_AFTER_WRITEhazards (7vkCmdCopyImage, 3vkCmdCopyBufferToImage) and exits 1.Change. When a piece needs no layout transition (already in the transfer layout, or
GENERAL),copy_layoutadds a memory barrier from earlier transfer writes to the new transfer access, at the transfer stage only. Copies and resolves both use it, so it covers read-after-write (a copy reading what an earlier copy wrote) as well as write-after-write. Buffer-to-buffer copies don't go throughcopy_layoutand are unchanged; syncval reports nothing for them in these tests.Tested on NVIDIA GeForce RTX 4070 SUPER, driver 32.0.16.1088, Windows 11, MSVC 2022:
LEONIDA_VK_VALIDATION=1 VK_LAYER_VALIDATE_SYNC=1:d3d12_vulkan_device_testgoes from 10 hazards and exit 1 to 0 hazards and exit 0.d3d12_descriptor_test,d3d12_method_variants_test,d3d12_sampler2_testandvk_command_replay_testreport no hazards.d3d12_clear_testfails only on the format-28 bytemainfails on (Runtime: clears match WARP on every format class: tie rounding, and the SNORM/SINT/R8/R16 formats (D3D-45) #521).ctestpasses 29/29.This overlaps with #741, which turns synchronization validation on by default in the tests: with #741 alone, these 10 hazards would fail
d3d12_vulkan_device_test. Thecheckjob may stay red until #713 fixes therpf9-explorerpin onmain. No game files used.AI-assisted.