Files
metal2vulkan/crates
Anees Iqbal 5c1b97e7e3 Keep a logged shadow from holding while a command buffer that waits and wrote its pages runs
What: a command buffer that waits for an event or a semaphore, and whose commands write logged
host pages (HostMemory::with_dirty_pages), now keeps its writes in the device's dirty shadows
(dirty_pages.rs, WaitingWrites) from its commit until it completes. While they are kept, no
log of a shadow they meet (the shadow's truth or the shadow) takes a hold or gives one. That
covers a log made after the commit too: a shadow's log is made at its first gated copy in.
Each hold left untaken is counted in the new WorkCounts::dirty_holds_withheld. A command buffer
whose writes went unnoted (nothing collected them as it encoded), or that wrote past WRITES,
counts as writing everything. Its completion lets the writes go, after it reports them again.
committed() now reports the host writes at its end (the order against the stamps is
unchanged), and the commit site passes `unnoted`.

Why: such a command buffer may run after work committed after it. Its writes reach the log at
its commit, before that later work's stamps. A later commit whose end leaves the shadow's image
holding the truth takes a hold as of its own stamp, and a copy in behind that hold then skips
pages the waiting writer fills after the image was copied. The first design kept the waiting
writer on each ShadowLog it met at the commit. It withheld nothing in the test below ("holds
withheld 0"), because the log did not exist yet at that commit: the first copy in came later.
So the writes are kept by the device, and each log asks them when it would hold.

Test: runtime_lane::cross_queue_shadows::
a_write_of_logged_pages_after_an_event_wait_reaches_a_copy_in_behind_a_later_hold, over one
anonymous guest page with a dirty log. Y (queue 2) waits for an event, fills row 3, then spins
(150 dispatches of about 10 ms). X (queue 1, committed after Y) reads the texture and signals
the event; its end holds the texture whole. Z (queue 1, after X) reads it. The test asserts
the copies in were gated, X's hold was withheld, X's read holds the initial bytes and Z's read
holds Y's fill.

Verified on the M3 Max (MoltenVK 1.4.2, macOS 27.0.1) under --cfg m2v_gpu:
- Without this change (the test alone, on the landing's first commit), the test failed: Z's
  read lacked the fill (32 bytes of row 3 held the old texels), the gated copies in reading
  [2 gated, 1 whole, 1 skipped, 512 bytes whole, 256 copied].
- With it, 93 of 93 passed: runtime_lane::cross_queue_shadows, parallel_encodes and
  device_copies, and the runtime's tests::shadow, batches, fresh_unwritten, dirty_pages and
  copied_log. This test read [2, 2, 0, 512, 512] and "holds withheld 2".
- cargo clippy -p metal2vulkan-runtime -p metal2vulkan-validation --all-targets --all-features
  -D warnings, plain and under --cfg m2v_gpu: clean.
- metal2vulkan's api_signatures test passes with the new field's row.

(cherry picked from commit 5ef157a072f943ddcd71bb315cd4c1cb03f6097e)
(cherry picked from commit be09b8f937d221213a31230917680f1c848c4d7d)
2026-11-03 04:25:30 -08:00
..