The encoder trail: name the encoder a stalled GPU stopped in, and the last one that completed

A GPU hang (a CTX SWITCH TIMEOUT on an RTX 3090) left the runtime with no way to say which
encoder never completed: encoders share batches and grouped submissions, and neither
METAL2VULKAN_LOG_PASSES nor METAL2VULKAN_QUEUE_TIMES logs anything at a stall.

METAL2VULKAN_ENCODER_TRAIL (env_vars.rs), or DeviceOptions::encoder_trail for one device, is a
default-off diagnostic (encoder_trail.rs):

- Each encoder, and each part of one a host step splits off, ends its batch (Batches::alone),
  and no batch waits in a group, so each goes in a vkQueueSubmit of its own that signals its
  queue's timeline. When work goes to the driver changes; what it computes does not.
- Each encoder notes what it was: its kind, its command buffer's object ID, its place, a
  render pass's area, samples, attachments' formats and sizes, instances and rate map, its
  indirect command executions, and the label hash of each state it bound (the first 8 bytes
  of a SHA-256 of the state's label and its functions' names; no name, no shader text). A host
  step adds the states its indirect commands named, as the GPU and the CPU left the records.
- Once no work of the device advanced for 2 s with some pending, completion.rs's stall path
  logs one Info line (id name metal2vulkan-encoder-trail) for each VkQueue whose oldest batch
  is pending: that batch's encoders and the last batch the queue completed, with how long
  before; once a stall.
- A submission a host step makes and waits for itself (a rasterization-rate map's fan-out
  probe, a predicated loop's check run again) signals no timeline; once it ran 2 s, one line
  names it, the encoder whose step made it and the states its commands named.

Off, a device reads the switch once and notes nothing.

Verified on msi (lavapipe, --cfg m2v_cpu_icd), at the branch tip this commit's tree equals:
- tests::stall::the_encoder_trail_names_the_stuck_encoder_and_the_last_one_completed: a cb
  stuck on an event wait before two blit fills; the line names the stuck cb's encoder 0 (not
  its encoder 1) and the earlier completed cb's encoder 0:
  "VkQueue 0's oldest pending batch: Blit encoder 0 of command buffer 3, states []; the last
  batch it completed: Blit encoder 0 of command buffer 2, states [] (2.106823047s before)".
- tests::rate_mapped_fan_out::the_encoder_trail_fans_out_the_same_pixels: with the trail on,
  probes/flagged/fanned [1, 1, 6] as without, no texel differs from the encoder's own draws.
- The host-step families (rate_mapped_fan_out, rate_mapped_pieces,
  indirect_command_buffer_device, host_step_neutrals, ycbcr_in_place_loop) with
  METAL2VULKAN_ENCODER_TRAIL=1: 11 passed.
- encoder_trail's unit test (one state's hash pinned: a reader of the pipeline creation log
  computes it again); the runtime suite 1504 passed; api_ tests 16 passed; clippy all features
  and the runtime under m2v_gpu and m2v_cpu_icd; rustdoc of the runtime and metal2vulkan.

The runtime-sources pin moves (not re-pinned here).
This commit is contained in:
Anees Iqbal committed 2026-11-12 20:33:17 -08:00
1 parent b6c52f1fa9
commit efcb6851ce
25 files changed
+821 -14

No files matched your search

+15
View File
@@ -1894,6 +1894,21 @@ signals, and a secondary through each primary that executes it. It reads those t
`metal2vulkan-pending-audit`, `Info` severity): what was done, the thread, the command buffer, the
timeline, its counter and the value, with the thread's backtrace for the first 8; and a line as the
device is made and as it goes, with the checks and findings by kind. It changes no work.
With `METAL2VULKAN_ENCODER_TRAIL` set (or `DeviceOptions::encoder_trail`), a device submits each
encoder, and each part of one a host step splits off, in a `vkQueueSubmit` of its own that signals
its queue's timeline, grouping no batches, and notes what each encoder was: its kind, its command
buffer's object ID, its place among the command buffer's encoders, a render pass's area, sample
count, attachments' formats and sizes, Vulkan render pass instances and whether it is over a
rasterization-rate map, its executions of indirect commands, and the label hash of each pipeline
state it bound (the first 8 bytes of the SHA-256 of the state's label and its functions' names; no
name and no shader text), and of each state its indirect commands named at a host step. Once no
work of the device advanced for 2 s while some was pending, it logs one line for each `VkQueue`
whose oldest batch is pending (id name `metal2vulkan-encoder-trail`, `Info` severity): that
batch's encoders, and the last batch the queue completed, with how long before; once a stall. A
submission a host step makes and waits for itself (a rasterization-rate map's fan-out probe, a
predicated loop's check run again) signals no timeline: once it ran for 2 s, one line names it,
the encoder whose step made it and the states its commands named. It changes when work goes to the driver, and its
timing, never what the work computes.
Whatever the variables, a placement heap's `newTextureWithDescriptor:offset:` that makes no texture
(`Nil` or `OutOfMemory`) at an offset inside the heap says so (id name
`metal2vulkan-heap-texture-refused`, `Info` severity): the descriptor, the offset, the heap's size,