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