metal: GPU time per pass behind VICTORY_PASS_TIMING=1 (#460) #484
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/484"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-27T22:06:09Z.
What this changes
Refs #460 (step 1 only; record and replay is not part of this)
VICTORY_PASS_TIMING=1, off by default: GPU time per pass on the native Metal path. Today the host times whole command buffers only (GPUEndTime - GPUStartTime), so a slow pass in a world frame can't be told from the others.Each compute, render and blit pass of a submission gets two timestamp samples through its pass descriptor (
sampleBufferAttachments): its encoder's start and end, and for render the start of the vertex stage to the end of the fragment stage. Apple GPUs sample at stage boundaries only, so a pass is the finest grain. There is oneMTLCounterSampleBufferper command buffer, resolved in its completed handler.Passes are keyed by kind, their dispatch, draw or op count, and their pipelines. A pipeline shows by its name when
name_pipelinegave one, otherwise by its address; a key lists up to four pipelines, each with its count.name_pipelinenow records names while the switch is on, as it already did withVICTORY_TRACE_GPU_FAILS.About every 10 s, one
pass timingline gives:Ticks are converted with the device's CPU/GPU clock correlation (
sampleTimestamps:gpuTimestamp:).Compute and blit encoders are made with
…EncoderWithDescriptoronly while the switch is on. With it off, nothing changes.Not timed: a submission split into pieces (
VICTORY_PASSES_PER_BUFFER), colour-clear rectangle passes, the gate pass a render pass encodes before itself (its time is in the gaps), and command buffers the GPU failed. A GPU without stage-boundary timestamps logs that once and times nothing.New module
crates/victory-metal/src/pass_timing.rs, wired intogfx.rs(submit_passes,encode_compute,encode_render,encode_blit) andmetal.rs. Documented indocs/native-host.mdnext toVICTORY_TRACE_GPU_FAILS.How it was tested
M1 Pro, macOS 27.2.1, Xcode 27.2.
gfx::owed_tests::pass_timing_times_each_pass_and_ranks_the_long_one_first. It submits three blit passes, one of them filling 64 MiB. Each pass is timed once under its own key, the 64 MiB pass is the longest, and the passes still ran. It ran on the GPU here, not skipped.pass_timing.rs: the line ranks by time and shares the command buffers' time, keys name each pipeline once with its count, ticks convert by the two clocks.cargo test -p victory-metal -p victory-gpu -p victory-backend: 488 passed, 0 failedcargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean (and native arm64 clippy on the new module: clean).cargo xtask policy: okVICTORY_PASS_TIMING=1would show the top passes of a world frame.Checklist
VICTORY_*variable and documented (VICTORY_PASS_TIMING)Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-28T08:13:36Z.
Closing: this change is already in.
Pull request closed