From d68f165aae824a6cb0a9325b1e4d7b5b7fd322d4 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 2 Dec 2026 02:13:33 -0800 Subject: [PATCH] Runtime tests: a Direct3D 11 picture drawn before rt's first commit is read whatever order external_writes_done arrives in A consumer's video path showed green frames: planes Direct3D 11 wrote, read by rt, came back without Direct3D 11's content. A plane's first acquire names the undefined layout unless Surface::external_writes_done was called before the first commit that uses it, and section 12.5.1 lets a transition from the undefined layout discard ("implying that the contents of the image subresource need not be preserved"). The new test draws picture 1 with Direct3D 11 and waits for it, imports the planes, commits and waits for rt's read of them with no external_writes_done before it, then makes the consumer's call and reads again. Both reads must be picture 1's exactly. It prints the first read's matching and zero bytes and each acquire's old layout (Work::acquired). Its run at this commit on the UHD 630 is named in the fix's message. --- .../metal2vulkan-runtime/src/tests/d3d11.rs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/crates/metal2vulkan-runtime/src/tests/d3d11.rs b/crates/metal2vulkan-runtime/src/tests/d3d11.rs index d1cc51466..5973946ee 100644 --- a/crates/metal2vulkan-runtime/src/tests/d3d11.rs +++ b/crates/metal2vulkan-runtime/src/tests/d3d11.rs @@ -707,6 +707,58 @@ mod on_device { }); } + /// What Direct3D 11 drew before rt's first use of the planes, read by a command buffer + /// committed before `Surface::external_writes_done`: Direct3D 11 draws picture 1 and waits + /// for its work, the planes are imported, and rt's read of them is committed and waited + /// for with no `external_writes_done` before it; the consumer's call comes after it, and a + /// second read follows. Both reads are picture 1's exactly: what another API wrote before + /// the first acquire is kept whatever order the two calls arrived in. The first read's + /// bytes that match picture 1 and that are zero, and each acquire's old layout + /// (`Work::acquired`, undefined 0, general 1), are printed. + #[test] + fn every_device_reads_what_direct3d_11_drew_through_a_commit_ahead_of_external_writes_done() + { + each_device("import_d3d11_surface_commit_first", |name, _, device| { + let luid = luid(&device).unwrap_or_else(|| panic!("{name}: no valid LUID")); + let d3d = D3d::on_luid(luid) + .unwrap_or_else(|| panic!("{name}: no DXGI adapter of LUID {luid:02x?}")); + let textures = PLANES + .each_ref() + .map(|p| d3d.shared_texture(p.width, p.height, p.dxgi, BOUND)); + d3d_draw(&d3d, &textures, 1); + let surface = import(name, &device, &textures); + let core = device.core(); + let from = lock(&core.work.acquired).len(); + let first = rt_read(name, &device, &surface); + surface.external_writes_done().expect("the acquire"); + let second = rt_read(name, &device, &surface); + let layouts: Vec = (lock(&core.work.acquired)[from..].iter()) + .map(|&(_, layout)| layout.as_raw()) + .collect(); + let one = picture(1); + let (at, same) = compare(&one, &first); + let zeros = first.iter().filter(|&&byte| byte == 0).count(); + let after = compare(&one, &second); + println!( + "d3d11-commit-first: {name}: the read committed before external_writes_done \ + matches picture 1 at {same} of {} bytes (first difference at {at:?}), {zeros} \ + of its bytes zero; the read after the call: first difference at {:?}, {} \ + bytes matching; the acquires' old layouts in order {layouts:?}", + one.len(), + after.0, + after.1 + ); + assert_eq!( + at, None, + "{name}: the read committed before external_writes_done is picture 1" + ); + assert_eq!( + after.0, None, + "{name}: the read after external_writes_done is picture 1" + ); + }); + } + /// The old layout of each plane's acquire. A plane is made undefined /// (`VUID-VkImageCreateInfo-pNext-01443`) and is general only after Direct3D 11's access /// (section 12.5.2), which the consumer reports by `Surface::external_writes_done`. On a