Files
metal2vulkan/docs
Anees Iqbal 6ee9db2b60 METAL2VULKAN_PENDING_AUDIT: a default-off audit of command buffers freed or reused while pending
A GPU hang on Iris (ANV) left a compute dispatch reading an interface
descriptor that another pass's viewport state had overwritten: the hung
command buffer's dynamic state went back to ANV's pool (a reset or begin)
while its request still ran. The path that freed it is not known yet. This
adds a diagnostic that finds it where it happens, against the GPU's own
timelines rather than what the host saw of them.

What it checks, where it is on (DeviceOptions::pending_audit, or
METAL2VULKAN_PENDING_AUDIT set, read at device creation):
- every vkBeginCommandBuffer made through the device's functions (Vk's
  begin_command_buffer, in both the full and the exit guard's tables), a
  primary begun ahead in a spare pool among them;
- each vkResetCommandPool of a spare pool, and each pool given back to the
  spares, for every command buffer the pool made;
- each submission of a command buffer submitted before and not begun for
  simultaneous use (ANV rewrites a chainable primary's tail at each
  submission).
What carries a command buffer: a batch's submission (direct or held in the
scheduler's group) to its queue's timeline value; the device's own and the
staging queue's submissions to their timelines; a secondary through each
primary that executes it (Vk's cmd_execute_commands notes it, a begin of
the primary forgets it). A failed submission is withdrawn. Each check reads
the carrying timelines with vkGetSemaphoreCounterValue; a value not reached
is a finding, logged (id name metal2vulkan-pending-audit, Info) with the
thread, command buffer, timeline, counter and value, and a backtrace for the
first 8. Off, each site tests an Option; on, it changes no work.

Tests: tests::pending_audit (the ledger: timelines, latest value per
timeline, one read per timeline per check, secondaries through primaries,
withdrawal, unreadable timelines, simultaneous use), and the device test
tests::pending_audit_device: a command buffer held on the GPU by a wait for
a reserved event signal has its pool given back early (a cfg(test) hook);
the audit finds it once and says it; after the host signal, the next command
buffer's pool reset, the primary begun ahead and its taking are checked and
nothing more is found. env_vars.rs registers the variable with its cost;
docs/API.md and api_signatures.tsv carry the option.

Verification: pending (potluck jobs on lavapipe and Iris).
(cherry picked from commit 2c524391e70921596add39688daf761cbc20662f)
2026-11-09 01:09:02 -08:00
..