Skip to content

victory-gpu: 16-bit packed colour widens for the host (the second crash between the account screen and gameplay), and the two tools it took - #2936

Open
pes7 wants to merge 22 commits into
Marvisak:mainfrom
pes7:fix/prologue
Open

pes7 wants to merge 22 commits into
Marvisak:mainfrom
pes7:fix/prologue

Conversation

@pes7

@pes7 pes7 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What is left after the null-alias fix was merged upstream (219878a, "GPU: a null shader view has no alias source"): the second crash that stood between the account screen and gameplay, and the two tools this needed. Rebased onto main (63bcca4); the branch is now only these three commits.

commit what it does what the run showed
b1ec6e0 16-bit packed colour (B5G6R5, B5G5R5A1, B4G4R4A4) widens to BGRA8 in pc_format, the one function resources, views, twins and pipeline target formats all go through the device was removed with DXGI_ERROR_INVALID_CALL on a typed UAV of B5G5R5A1 and on a B4G4R4A4 render target; with it the title reaches gameplay - 2 555 draws a frame, 8 137 at the widest
b1ec6e0 fail() drains the D3D12 debug layer's stored messages a removal now names the call (ID3D12Device::CreateUnorderedAccessView: ...) instead of only DXGI_ERROR_INVALID_CALL
2e15dc6 VICTORY_DUMP_SHADER=<hash> writes that shader's translated DXIL to %TEMP%\victory-<hash>.dxil for dxc -dumpbin named the two families behind "the GPU hangs": a ray march whose only exit is a float compare or the 2^20 loop limit, and a straight-line shader with no loops and no barriers at all

The prologue then runs at 1.0-2.4 fps (867-1006 ms a frame, 683-807 ms of it on the GPU, 372-508 draws a frame dropped while their pipelines are made, 4 481 host textures / 6 050 MB). Those numbers, and the way VICTORY_SHADER_LOOP_LIMIT=16 moves the GPU term to 147-370 ms, are in the comments below - that is the next piece of work, not this PR.

Tests on this branch: cargo test --release --workspace - 30 suites, all ok; clippy clean; builds with and without --features diagnostics.

@kotekompotek

Copy link
Copy Markdown

Substantial and mostly verified — the HEAP_VIEWS = 1,000,000 change is the principled fix: translated shaders clamp heap indices below it, D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_2 caps every creatable heap at 1,000,000, so a 1<<21 clamp could only ever produce out-of-heap reads (device removal), never a valid descriptor. NULL_RESERVE correctly protects the null-view pair on the capped path (MIN_DYNAMIC - 1024 leaves slots 999,998/999,999 free exactly where NULL_BUFFER_VIEW lands).

Two things to untangle before merge:

  1. The alias_source hunk is already on main — placed.is_null() guard merged as 219878a ("a null shader view has no alias source", the GPU: since #1273, null SRVs reach alias_source and crash (0xc0000005, read 0x30) as the world loads #2847 crash class). Identical code and comment; a rebase will show it as an empty diff. Your earlier PR victory-gpu: a view of no resource is not looked up as an alias (null dereference that ends every run after the account screen) #2933 was the same change.

  2. Residual OOB on smaller heaps: HEAP_VIEWS = 1M only puts NULL_BUFFER_VIEW inside the heap when the heap is actually ≥1M. On NVIDIA, make(count + MIN_DYNAMIC) succeeds for counts ≤934,464 — e.g. a 737,856-count title heap makes an 803,392-descriptor heap, where index 999,998 is still past the end (pairs_end falls back to total, the nulls are never written, and a clamped index still reads OOB). GTA6's own 934,464-count heap lands exactly at make(1,000,000) so its crash is covered, but the title-side cap is only fully guaranteed on the PORTABLE_VIEWS arm. Possibly worth pairs_end/null placement at total - 2 when HEAP_VIEWS > total — or a comment noting the smaller-heap case remains a documented shortcut.

  3. pc_format 85/86/115→87 is the alternative shape of GPU: a texture flags unordered access only where a view can take it #2442's fix for the same crash class (B5G5R5A1 + typed UAV → DXGI_ERROR_INVALID_CALL removal): yours widens the resource format at creation, GPU: a texture flags unordered access only where a view can take it #2442 keeps the format and strips ALLOW_UNORDERED_ACCESS where the host can't store typed. They're complementary rather than conflicting — worth a line in the PR description saying which case each covers (widening handles RT too; the flag strip handles formats that must keep their bit layout).

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, continued (the branch is fix/prologue, and this comment is the running record - evidence from actual runs, not intentions):

#4 - the prologue now runs. With the two crashers fixed (#1, #2 above), the first gameplay frame is reached. It then hung the GPU within seconds: DRED breadcrumbs named it exactly -

a list stopped at command 143 of 147 (op 6): dispatch 16x16x16 [compute 00167d58cc5a78d7]

and, with that one skipped (VICTORY_SKIP_PIPELINES=00167d58cc5a78d7), the next run stopped at another:

command 91 (op 5): indirect kind 2 max 1 at 0xd9358fe80 [compute f607780aa8e502d0]

With both skipped the title plays: 37 consecutive world frames, 534-4434 draws a frame, 600-3227 ms a frame, and the run lasts until a third command of the same kind (still to identify).

#5 - the numbers that frame report finally gives (steady part of that run):

per frame
frame 867-1006 ms
on the GPU 683-807 ms
preparing (copies + textures) 110 ms
- title memory copied 35 ms / 110-139 MB
- texture uploads 7-23 ms
copying back 49 ms / 8 MB
draws 1 260-1 667
dropped without a host pipeline 372-508
host textures 4 481 (6 050 MB)

So the fps problem in the prologue is on the GPU (80 % of the frame), and separately 30 % of the draws are dropped because their host pipelines are still being made in that frame.

next, in this order: (a) rank the GPU work per command with VICTORY_GPU_TIMING during these frames, (b) the dropped draws - their pipelines are made during the frame, so the same frame both stalls and drops, (c) the two hanging compute dispatches, which is a translation question (s_barrier-style waits are the known family, issue #1799).

Everything above is one run away from reproducible: drive4.ps1-style driver, Enter at 15 s/45 s/80 s/110 s (the account screen, then the menu's Start), VICTORY_SKIP_PIPELINES=<the two hashes>.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and RTX 5090 + WARP check at head 0082b445a252 against main (63bcca43c6a0):

Several blocking issues here:

  1. Merge conflict & superseded commit in resource.rs:
    • Commit eca1d364 (alias_source null check) directly duplicates and conflicts with 219878a0e775 (GPU: a null shader view has no alias source), which is already on main (along with a_null_view_has_no_alias_source).
    • This PR also bundles 5 unrelated changes across 4 commits (alias_source, NULL_RESERVE=1024, lowering HEAP_VIEWS to 1_000_000, 16-bit format remapping, and log_messages on device removal).
  2. 16-bit packed -> BGRA8 remapping (crates/victory-gpu/src/resource.rs:247: 85 | 86 | 115 => 87) breaks byte width and pixel layout:
    • Formats 85 (B5G6R5_UNORM), 86 (B5G5R5A1_UNORM), and 115 (B4G4R4A4_UNORM) are 2 B/texel (resource.rs:127), whereas 87 (B8G8R8A8_UNORM) is 4 B/texel.
    • texture.rs:696,788,813 detiles raw 2-bpp title bytes straight into the 4-bpp BGRA8 host staging pitch without 16->32-bit pixel expansion, corrupting every row/channel.
    • list.rs:725-795 (upload) and list.rs:853-903 (read_back) pass 2-bpp title footprints into/out of a 4-bpp host texture, causing D3D12 CopyTextureRegion format-mismatch failures (DXGI_ERROR_INVALID_CALL). pipeline/host.rs:142 (InputLayout) and texture.rs:294 (alias_copy) are also affected.
  3. Tier-3 view heap NULL_BUFFER_VIEW overlap (crates/victory-gpu/src/descriptor/host.rs:210):
    • extra.min(total.saturating_sub(count).saturating_sub(NULL_RESERVE)) assumes NULL_BUFFER_VIEW sits near total, whereas it is fixed at HEAP_VIEWS - 2 = 999_998. On Tier-3 GPUs that allow total > 1_000_000 (e.g. count = 750_000, total = 1_012_144), count + extra = 1_011_120 > 999_998, placing NULL_BUFFER_VIEW inside the dynamic allocation range (see #2461 for a full view_heap_limit() solution that handles both 1M-capped and uncapped heaps).

Recommend dropping the superseded alias_source commit and splitting any remaining independent fixes into focused PRs.

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work (unchanged blocker). The new head 652cd44 reverts 1e53e91, so the memory::CAPACITY change is no longer in this PR. That's fine if you plan to send it as its own small PR, as suggested, with the doc comment and the memory cost stated. Your progress logs (parts 24 and 25) are useful context for that PR. Part 25 already notes that one run cannot show it removes the TDR.

The blocker in this PR is still there. resource.rs pc_format maps 85 | 86 | 115 => 87 for every use. That puts 2-byte texels into a 4-byte host format, and nothing converts them on upload or read-back, so the title's data and the host texture disagree in size and layout. Please replace this with a use-dependent path that converts the texels, or drop the commit. Also still open: in draw.rs, count for VICTORY_DUMP_ARGUMENTS is read eagerly, outside the deferred closure. The diagnostics commits would also be easier to review as their own PR.

CI: passing.


Generated by Claude Code

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 3 - the first measured fps number and what moves it.

The frame's GPU cost is in the indirect dispatches. With the two hanging compute dispatches skipped (part 2), one more hash shows up at the top of the per-command ranking (VICTORY_GPU_TIMING, 27 world frames):

command                            samples  total ms  worst
indirect kind                       299      12 965     1 115
indirect kind 8bbcbda6008eaa37       49       7 488       292
indirect kind 776d835da5ffa646       37       1 564        69
indirect kind c7feccae4e01e454       52       1 112        66
draw                                 20         872        91

Skipping that one is worth ~2x on the real path (no debug layer, no per-command timing):

frame on the GPU draws
skip 2 hashes 867-1 006 ms (1.0-1.2 fps) 683-807 ms 1 260-1 667
skip those + 8bbcbda6008eaa37 415-584 ms (1.7-2.4 fps) 179-421 ms 412-3 060

So one indirect command family is about half of the prologue's frame time, and the frame report's "on the GPU" tracks it exactly - it is not a CPU problem there.

The hang is not deterministic. The same build with the same skips ran 24 world frames and 60 s of gameplay in one run and was removed in the next, and the command named by the breadcrumbs changed when one was skipped (00167d58cc5a78d7 -> f607780aa8e502d0 -> indirect [mesh c82b7a0b51f8f8a9, pixel e4d3d1ea315a7036]). That is the shape of a GPU-side wait on data that may not be there yet - the family issue #1799 describes - rather than one bad shader.

Next: the traced-record dump (VICTORY_TRACE_SHADERS=<hash>) prints what the indirect records actually ask for, which says whether the 400 ms is real work the title requests or our translation of it.

Numbers above are one run each, but the two skip sets differ by exactly one hash and the frame's draw counts overlap, so the ~2x is not scene drift.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 4 - the prologue's frame time and its hangs are the same thing: translated loops running to their limit.

The trace says the second most expensive GPU command asks for almost nothing:

indirect kind 2 max 1 count None: 1 of 1 records with work, 746 in all; first [[746, 1, 1]] [compute 8bbcbda6008eaa37] frame 2458

746 groups of 64 threads, ~48 000 threads - and it costs 200-400 ms of the frame. So the work is not the title's; it is in the shader our translator emits. The project already has the instrument for exactly this: VICTORY_SHADER_LOOP_LIMIT (emit::loop_limit, lower::LOOP_LIMIT = 1 << 20 - "data the host has not mirrored yet (a null view reads zeros) can make that four billion iterations, which hangs the host GPU until the driver resets it").

Same run, same two skipped hashes, only VICTORY_SHADER_LOOP_LIMIT=16:

default limit (2^20) limit 16
frame 867-1 006 ms 622-836 ms
on the GPU 683-807 ms 147-370 ms
world frames before the device was removed 37 57, and end: no crash
fps 1.0-1.2 1.2-1.6

So with the loops cut short the GPU term drops 2-4x and the run stops crashing entirely (it ran the whole 260 s window). The picture is wrong at 16 iterations, of course - this is the diagnostic, not the fix - but it says the prologue's fps and its "GPU hangs" have one root: a translated loop whose data-driven bound does not terminate as the console's does, so a lane burns up to a million iterations per entry, and a dispatch with tens of thousands of lanes takes hundreds of milliseconds (and, sometimes, over the 2 s TDR).

Next: find which loop. The shader is named by the trace above (8bbcbda6008eaa37) and the hang by the breadcrumbs; the emitters' loop lowering (lower.rs, the phi-based counters and the limit exit) is where a bound that should terminate is not terminating - most likely a loop that reads its condition from memory we have not refreshed at that point (the same "null view reads zeros" the comment warns about).

Still open and unchanged in the branch: nothing in this comment is a patch yet.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 5 - the tool that shows what our translation of a bad shader is, and what it says.

VICTORY_DUMP_SHADER=<hash> (diagnostics, 6ac972c in this branch) writes each named shader's translated DXIL to %TEMP%\victory-<hash>.dxil; dxc -dumpbin turns it into the IR. It works on the three hashes the runs named:

shader dumped shader="f607780aa8e502d0" bytes=40824
shader dumped shader="8bbcbda6008eaa37" bytes=95020
shader dumped shader="00167d58cc5a78d7" bytes=47292

What the group counts say. The trace on 8bbcbda6008eaa37: 746 groups, and its IR is NumThreads=(8,4,1) - 23 872 threads in all. That command is worth 200-400 ms of the frame (part 3), so the time is in the body, not in the amount of work.

What the body is. A ray march with a float exit condition and the loop limit as the only other way out:

; <label>:7481
  %7482 = add i32 %7435, 1
  %7483 = icmp ult i32 %7482, 1048576        ; the loop limit
  br i1 %7483, label %7434, label %12631

with %7480 = fcmp oge float %7459, %7417 as the real test and SampleCmpLevelZero inside. So either the march really runs a million steps (wrong data: a NaN or a non-advancing step) or it needs far fewer and hits the limit in some lanes - either way every iteration past the first few dozen is waste.

And the other two hashes are not loops at all. 00167d58cc5a78d7 is NumThreads=(4,4,4) with no dx.op.barrier and no loop-limit check at all - straight-line code that still stops the queue, so it is not a spinning loop: it is memory access (it reads the placed buffers we mirror in system RAM, at PCIe latency) or sheer instruction count. f607780aa8e502d0 has two loops and two limits, NumThreads=(32,1,1).

That means "the GPU hangs" is at least two different problems, and they need different fixes:

  • 00167d58cc5a78d7 - the cost of reading title memory that lives in system RAM (the same copy path we measured at 87-313 MB a frame). VICTORY_COPIES_IN_VIDEO_MEMORY=1 is the project's own answer to that, and on this GPU it is supported (host copies of title memory in video memory (diagnostics) on=true) - measured in the menu it makes copy-back 5x more expensive (239 ms against 19-49 ms) because the CPU then reads our copy out of VRAM, so it trades one side for the other; worth a proper measurement in the world, not taken yet.
  • 8bbcbda6008eaa37, f607780aa8e502d0 - the translated loops. VICTORY_SHADER_LOOP_LIMIT=16 cut the GPU term from 683-807 ms to 147-370 ms and let the run finish its whole window without a removal, but the picture is wrong at 16 and the runs drift by scene, so the number that matters (same scene, limit 2^20 vs a limit that still admits every legitimate march) is not measured yet.

Tests: cargo test --release --workspace - 27 suites, all ok, on this branch (the 195 in victory-gpu included).

pes7 added 3 commits November 26, 2026 05:57
`VICTORY_DUMP_SHADER=8bbcbda6008eaa37` (or `all`) writes each named
shader's DXIL to `%TEMP%\victory-<hash>.dxil` as it is translated; `dxc
-dumpbin` reads it as LLVM IR. The pipeline log and the breadcrumb reports
name shaders by this hash, and until now there was no way to see what our
translation of one looks like - which is what a frame spent in a compute
dispatch that asks for 746 tiny groups needs.

Found with it in the prologue: `8bbcbda6008eaa37` (NumThreads 8x4x1) is a
ray march whose exit is a float comparison and whose only other way out is
the loop limit (1 << 20), and `00167d58cc5a78d7` (4x4x4) has no loops and
no barriers at all yet stops the queue - two different causes behind the
same "GPU hang".
The title renders to a 2560x1440 B4G4R4A4_UNORM texture and makes a typed
unordered view of a B5G5R5A1_UNORM one. D3D12 supports neither, and the
debug layer says so while the run is going:

    CreateCommittedResource: A texture that has
    D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET set ... must be created with a
    format that either can be used as a render target, or cast to a format
    that could be

    CreateUnorderedAccessView: The format (0x56, B5G5R5A1_UNORM) cannot be
    used with a Typed Unordered Access View. This is because the current
    graphics implementation does not even support this Format.

    RemoveDevice: DXGI_ERROR_INVALID_CALL

so the run ended a minute after the account screen, in the first scene of
the prologue, with the device removed. (The 16-bit render target's creation
was already failing quietly - `no host texture` - and the unordered view
above removed the device.)

`pc_format` now widens B5G6R5, B5G5R5A1 and B4G4R4A4 (85, 86, 115) to
B8G8R8A8_UNORM (87): the same channel order, legal for render targets,
unordered access and shader reads, and it is the one function resources,
views, twins and pipeline target formats all go through, so they agree. The
title loses the console's 5 or 4 bits a channel, not the picture's layout.

With it the title reaches gameplay and the numbers the frame report then
prints for the first time: 2 555 draws a frame (before: the device was
removed in the loading screen), 3 969 ms a frame, 1 674 draws dropped for
want of a host pipeline, 621 MB of title memory copied and 139 MB of
textures uploaded a frame. That frame's 3.6 s on the GPU is the next
problem - and, being over the 2 s TDR, the next removal.

Found with the debug layer (`VICTORY_D3D12_DEBUG=1`) in a diagnostics
build: `fail()` now drains the layer's stored messages, which name the
call instead of only its code.
@pes7 pes7 changed the title victory-gpu: get the title through the account screen into the prologue (two crashes found by running it, and the frame report that finally comes out) victory-gpu: 16-bit packed colour widens for the host (the second crash between the account screen and gameplay), and the two tools it took Nov 26, 2026
@steven-seagull27

Copy link
Copy Markdown

@pes7 I tested the 16-bit format change separately from the two diagnostics. The global BGRA8 mapping also changes sampled-only textures, where the original 16-bit storage works. This loses the source pixels on both adapters I tested. I put a combined branch on my fork if you can try the same account-screen → gameplay run.

The fixture tiled all 65,536 possible 16-bit words into one 256×256 sampled-only texture per format, used the production detile/upload path and host copy footprint, then read one RGBA sample per texel with a compute shader. I converted the samples back to their original guest precision. For B5G6R5 I also checked opaque alpha. The diagnostic zero-initialized its staging window before each detile so untouched bytes had a known value.

Guest format Wrong / 65,536 at this head b456c70 On main 63bcca43 On combined 4684227
B5G6R5 65,536 0 0
B5G5R5A1 65,530 0 0
B4G4R4A4 65,527 0 0

Two fresh processes per adapter agreed on every count (RTX 5080, driver 621.40, and built-in WARP 10.0.26100.10068, debug layer on). For example, guest B5G6R5 0xf800 should sample as opaque red. This head produced RGBA8 [1,248,0,248]. The combined branch produced [255,0,0,255]. Native RTX sampling of some intermediate 5/6-bit values differs from the nearest 8-bit expansion by one code. All those values still recover the original guest word.

The branch merges this exact head with @moe-miau's #2626 (c8cc83e), preserves both diagnostics, and replaces the unconditional mapping with #2626's use-dependent path. For writable B5G5R5A1 and B4G4R4A4, both padded upload/clear/partial-readback tests also matched all 4,096 bytes in each of three runs per adapter. RTX used the RGBA8 stand-in and WARP used the native formats.

B5G6R5 stays native in this combination. Both devices advertise sampling and rendering for it. WARP also advertises typed UAV stores, while the RTX does not. A title request to write B5G6R5 via a typed UAV on that RTX would still need a separate fallback. Your original log names formats 86 and 115. An in-game comparison would tell us whether the branch retains your gameplay progress and whether a format-85 UAV is actually requested.

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2936-packed-integration
git switch -c verify-2936-packed FETCH_HEAD
cargo test -p victory-gpu --all-features --locked --lib packed_copy_tests -- --nocapture

AI-assisted with Codex. The results here used synthetic textures.

The pipeline log says how long a translation took but not who ran it: with
the prologue's cold cache 1 725 translations of ~110 ms each add up to the
20-25 s the first gameplay frame spends, and the question that decides the
fix is whether that is one thread (move it off the recorder) or the eight
pipeline workers (a translator throughput problem). It is the workers:
victory-pipelines-3..7 took 181-288 translations and 18 000-27 000 ms of
wall time each in the same run, so the batch is already spread and the
stall is per-translation cost.
@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 6 - what the cold-cache stall actually is (measured, not guessed), and two ideas that lost their own measurement.

Translations run on the eight pipeline workers, not on the recorder. The new line in the shader log names its thread; a run with a cold cache (the loop limit changes the cache key, so everything re-translates) says:

victory-pipelines-2: 288 translations, 20 247 ms
victory-pipelines-5: 255 translations, 19 334 ms
victory-pipelines-4: 246 translations, 18 925 ms
victory-pipelines-6: 220 translations, 26 938 ms
victory-pipelines-7: 209 translations, 18 076 ms
victory-pipelines-3: 181 translations, 18 065 ms

1 725 translations in the run, ~110 ms each, spread over the workers - so the 20-25 s the first gameplay frame spends on a cold cache is per-translation cost, not scheduling. Moving it off the recorder would change nothing; the win there is translator throughput (or the warm-up, victory translate --cache, which the pipeline library already leans on).

Dropped: block skipping in the copy-back merge. Measured in the build, same data (64 KiB piece, one byte written in 128):

per byte 569.1us (3 us a piece), blocks 4.5734ms (23 us a piece), 0.1x

10x worse, and 3 us a piece means the whole 8 MB of copy-back merge is 0.4 ms of a 19-49 ms item - the cost there is the two ReadProcessMemory calls a piece, not the merge. Reverted.

Dropped: copies in video memory (VICTORY_COPIES_IN_VIDEO_MEMORY=1). Supported here (GPUUploadHeapSupported, "on=true"), but in the menu copy-back goes 19-49 ms -> 239 ms a frame (the CPU reads our copy out of VRAM) and the menu drops 30 fps -> 3, and with the prologue's key presses the run ended in a device removal (a GPU hang, per the debug layer) twice out of two. It needs a staging copy in system memory beside the VRAM one before it can be measured in the world.

What is still the frame, from the runs with the two hanging compute dispatches skipped: 867-1006 ms a frame, 683-807 ms of it on the GPU, 1 260-1 667 draws with 368 indirect, 372-508 dropped while their pipelines are made; skipping one more hash (8bbcbda6008eaa37, 746 groups, the ray march) takes the frame to 415-584 ms and the GPU to 179-421 ms.

cargo test --release -p victory-gpu: 231 pass.

…sses

Two diagnostics (the `diagnostics` feature only) that answer why a cold
shader cache costs the first gameplay frame 20-25 s:

    shader phases (us): stage=Cs blocks=1542 range=342 resource=99315 io=5255 emit=8126713
    lowering passes: 74 blocks=1542 setup_us=5561 run_us=85672

- a translation is 74 % structurisation/resource tracing and 25 % lowering
  in the aggregate, but the *worst* shaders are lowering: 8.1 s of 8.2 s for
  the biggest one;
- `emit::lower` re-runs the whole lowering once per phi that does not
  settle (`Stop::Retry`): 74 passes for one shader, 222 extra passes over 17
  shaders in a batch of 1 725. At ~86 ms a pass on 1 542 blocks that is
  6.7 s for one shader alone - the whole cold batch is 160 s of CPU across
  eight workers, 25 s of wall.

Nothing changes in a release build (no `diagnostics`): the phases are
`Instant`s behind `cfg` and the pass count is not compiled at all.
@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 7 - the cold-cache stall is one algorithm, measured to the line.

Phase timing in the translator (diagnostics) and emit::lower's retry counter (4fdad62) answer where the 20-25 s of a cold batch go. A batch of 1 725 translations, summed:

phase sum median worst
range::build (structurisation) 0.15 s 40 us 0.6 ms
resource::track 115.9 s 1.0 ms 1.47 s
io::raise 1.0 s 83 us 26 ms
lower::lower (emit) 39.6 s 1.4 ms 8.13 s

So the median translation is 2.7 ms (as the project's own numbers say), and the batch is dominated by a handful of shaders. The worst:

shader phases (us): stage=Cs blocks=1542 range=342 resource=99315 io=5255 emit=8126713

Which is emit::lower's retry loop: lower() re-runs the whole lowering once per phi that does not settle.

lowering passes: 74 blocks=1542 setup_us=5561 run_us=85672
lowering passes: 21 blocks=70   setup_us=91   run_us=1839
lowering passes: 13 blocks=956  setup_us=2955 run_us=201072
lowering passes: 13 blocks=967  setup_us=3020 run_us=115554
lowering passes: 11 blocks=663  setup_us=2713 run_us=32890

74 passes x ~86 ms on 1 542 blocks = the 6.7 s; 222 extra passes across 17 shaders in the batch. The setup is 6 % of a pass, so reusing it would not help; the passes themselves must go. bad is consulted where a phi is first lowered (Val::Missing), so a value marked bad changes how earlier code lowers - that is why the loop restarts, and why batching them needs the failure set collected inside the two phi loops at the end of run() (which is the next change here, not this comment).

Also from the same instrument: resource::track has a 1.47 s outlier on one shader (median 1 ms), the second target.

Nothing in the release build changes: the phases are Instants under cfg(feature = "diagnostics") and the pass count is not compiled.

cargo test --release --workspace: 30 suites, all ok (302 in victory-shader), on this branch.

@steven-seagull27

Copy link
Copy Markdown

@pes7 Your Part 6 numbers point to a concrete cold-cache A/B. I tested #2942 (1569277, lowering) and #2957 (dfa6126, SSA) on the same inputs through translate_with. On eight CPU workers, 64 synthetic buffer/VALU shaders took 75.4 ms on base, 67.4 ms with #2942 alone and 63.4 ms with both. For 64 shaders with many live registers at joins, the corresponding medians were 42.2, 36.4 and 35.5 ms. All 128 produced byte-identical DXIL and the same host bindings across all four builds, and every output validated.

I verified that the two compiler heads together merge cleanly onto your 4eaaf60, and also onto 4684227 with the sampled-format test fix. If you have time for a cold-cache run of the same route, comparing your existing eight-worker build with those two compiler changes would show whether the translation gain reaches the first gameplay frame. I didn't measure title startup, pipeline creation or warm-cache FPS. Full table, benchmark fixture and reproduction on #2957.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 8 - the retry batching was implemented, measured, and then reverted: its own soundness check failed.

What it did. fill_phis now catches a Stop::Retry per phi, records the value and leaves a type-correct placeholder, so one pass finds many non-settling phis instead of one; lower merges the whole list into bad.

What it measured (same scenario, cold cache, 1 725 translations in the "before" run):

before  translations 1725  sum 235828 ms  median 13 ms  max 8030 ms  passes>1 19  max passes 74
after   translations  401  sum  30208 ms  median  5 ms  max 2559 ms  passes>1  4  max passes  8

(the "after" run is partial: it ended early, see below.) Max passes 74 -> 8, the worst translation 8.0 s -> 2.6 s.

Why it was reverted. The batched build ended two runs with the title faulting inside its own image (write 0x0) about 40 s in. A later run of the unbatched build ended the same way, so the crash is not attributable to the change - but the change also cannot be shown sound by that argument either. The placeholders mean a phi that fails because of a placeholder gets marked bad too, and a value marked bad is lowered as Val::Missing from then on, so the fixed point of the batched loop may differ from the sequential one. That is exactly what a wrong picture looks like, and 302 victory-shader tests do not cover the game's biggest shaders.

So the next step is not another run, it is a proof: dump every translated shader (VICTORY_DUMP_SHADER=all) on both builds in the same scenario and compare the files - identical output is the soundness evidence, any difference says which phis were marked bad needlessly. Only then is the 74 -> 8 passes win something to keep.

The measured shape of resource::track, from the same phase instrument (1727 translations):

resource > 10 ms: 274 shaders, sum 113.3 s
resource > 100 ms: 224 shaders, sum 111.9 s
resource > 500 ms:  87 shaders, sum  67.6 s

224 shaders over 100 ms in one phase that should be a walk of the instructions: the second target, and unlike the batching it is a pure scan-vs-map question.

Branch state: lower.rs and resource.rs back to their committed contents (git status clean), cargo test --release --workspace 30 suites ok, builds with and without diagnostics.

@steven-seagull27

steven-seagull27 commented Nov 26, 2026 •

Copy link
Copy Markdown

@pes7 Correction to my earlier interpretation of the 111.9 s figure. On df3c5df, mark("resource") runs immediately after range::build(&native.patched_code(), ...). The printed resource= bucket therefore measures native code patching and range construction, including the IR work inside it. The next bucket, io=, measures resource::track. The existing log can be re-bucketed without asking you to rerun the title. For the 224 translations above 100 ms I’d look first at the range-building phases and use io= to assess resource tracking. Instrumentation on the tested commit

The synthetic benchmark called resource::track directly. Its two cases went from 146.2 to 66.9 µs and 21.8 to 14.2 µs. The 192 compiled shader fixtures were byte-identical across the two builds, and I measured no end-to-end translation speedup on that corpus. Those results support the isolated improvement in #2785. They don’t establish how much time it saves on the prologue. Benchmark details

AI-assisted testing and analysis on my machine.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 24 - with the capacity fix the prologue plays on an unmodified build, renders correctly, and gets to its opening scene.

Same binary as 1e53e91 (CAPACITY 2048, diagnostics), no VICTORY_SKIP_PIPELINES, no loop-limit override, 620 s window with the account screen and menu pressed through and W held now and then in the scene:

238 world frames, 0 device removals, the whole 620 s window
frames 1.8-3.0 s: GPU 1.8-2.7 s, copies 0.5-2.0 GB / 70-160 ms

Two screenshots from that run (O:\tmp\victory-work\run\play_353.png, play_555.png):

  • at 353 s: the city at dusk from a distance - skyline, lights, clouds, palm trees - 1 798 ms a frame;
  • at 555 s: a character close-up on a grassy cliff with the ocean behind, 1 433 draws a frame, 1 648 ms.

So the picture is correct, not the compressed garbage of the loop-limit diagnostic, and the title is in the prologue's own scene rather than stuck in loading. That is the first time any of this session's runs has got there without a skip switch or a loop cap.

What is left is fps, and it is now the only thing in the way: 1 400-4 400 draws at 1.8-3.0 s a frame. The per-command report says where: 6697dff15287e544 (indirect dispatch, ~0.5-0.6 s a call, several a frame) plus the drain between submissions; the CPU side is 0.5-2.0 GB of title-memory copies a frame (70-160 ms) and 3 000-44 000 heap slots a frame. Both are measurable with what is in the branch now.

Branch fix/prologue at 1e53e91 (the capacity fix is the latest commit); corpus A/B and 30 workspace suites were verified on it in part 23.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 25 - 6697dff15287e544 is a different animal, and a caveat on part 23's claim.

The shader. Dumped and disassembled: NumThreads=(8,4,1), 29 112 IR lines (193 KB of DXIL), seven loops each with a icmp ult i32 %counter, 1048576 exit, and 23 atomics, no barriers. That is a heavy data-parallel pass (the atomics alone suggest work distribution), an order of magnitude bigger than the 5 s one, and its ~0.5-0.6 s per indirect call may simply be real work that the memory table no longer breaks. Nothing in it looks like the "search a table that is not there" shape of caa78b8ca62bc3d6; the exits are counters with the cap behind them, not loaded != key.

A caveat I owe the record. With CAPACITY = 4096 the same play scenario showed caa78b8ca62bc3d6 at 4 180 ms again, which reads like 4 096 being worse than 2 048. It cannot be, in data terms: write_table sorts copies by size and assigns level-2 blocks as regions are first touched, so a larger cap names a superset of the regions a smaller one does. The 4 180 ms is therefore either the drain attribution the report is known to include (the DROPPED dispatch ... 6 301 ms line in the same run is a 6 s "command" that records no GPU work) or run-to-run variation - not a regression. What that means for part 23 is stated plainly: the capacity change names more of the title's memory, the play run with it reached 238 frames and the prologue's own scene, but a single run cannot prove it removed the TDR, and one run at 4 096 muddies the picture rather than disproving it. A proper claim needs interleaved runs of the same scenario, which is the next measurement rather than another one-shot.

CAPACITY is back at 2 048 in the tree (the value the play run used); the 4 096 experiment is not kept.

What is still true and measured: the loading no longer needs skips or a loop cap to reach the prologue's scene (screenshots at 353 s and 555 s), caa78b8ca62bc3d6 costs 5-6 s only when its memory is missing (1024 regions named: 6 s; 2048: below the report's threshold), and 6-22 regions remain unnamed at 2 048.

Branch fix/prologue at 1e53e91, tree clean, 231 tests in victory-gpu pass.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 26 - part 23's fix is withdrawn: the interleaved A/B does not support it, and the mechanism it named never happens.

Part 23 credited memory::CAPACITY 512 -> 2048 with removing the loading's TDR. I could not reproduce that, so the change is reverted (652cd44) and the numbers are below, as measured.

Interleaved A/B, same scenario (account screen and menu pressed through, no skip switches, default loop limit, warm cache), 2 runs per build, both tools from the same source otherwise:

run CAPACITY world frames removals median ms/frame median GPU ms median draws
ab512_1 512 17 0 3 387 2 553 3 167
ab2048_1 2048 22 0 3 091 2 639 5 329
ab2048_2 2048 19 0 3 444 3 089 3 959
ab512_2 512 21 0 3 799 3 322 3 404

Each build wins one pair, and the scenes differ (3 167-5 329 draws), so the difference is inside run-to-run noise. No run of either build lost its device, so the removals the change was credited with do not reproduce at 512 either.

The claimed mechanism does not exist in these runs. write_table prints one warning when copies need more 256 MiB regions than the table has blocks ("...more 256 MiB regions than a page table has room for"). It fires zero times at CAPACITY 512, in every run of both builds: the table was never full. And a build whose table can name every level-1 entry (CAPACITY = LEVEL1 - 1, 134 MB of table per heap) still reports the same 34 missed regions and 96 310 missed pages - unchanged - so "missed" means pages the title reads that have no host copy at all, not regions the table had no room for. That build also fails one of the table's unit tests, so it was not kept either.

What that leaves: the 5-6 s dispatch (caa78b8ca62bc3d6) and the loading TDR come and go with the scene and the data, not with the table's capacity; part 23's two observations were one-shot runs of a variable thing, and the honest reading is that the cause is still open.

The diagnostics that made this checkable stay in the branch (VICTORY_GPU_STAMPS per-list attribution, VICTORY_DUMP_SHADER, VICTORY_DUMP_ARGUMENTS, VICTORY_DUMP_VIEWS), as does the 16-bit-format fix. Branch fix/prologue at 652cd44; cargo test --release --workspace 30 suites, 0 failures; both build configurations clean.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 27 - the prologue now plays its own scripted scenes, and the frame cost is not the loops.

What the run shows. play2 (diagnostics build, no skip switches, default loop limit, no stamps): account screen and menu pressed through, then W held in bursts and a step left/right now and then; a screenshot every two minutes.

at what frame
243 s the two leads talking on the rooftop, subtitles on ("И потом спокойно составим план, который не будет звучать как бред") 1 566-1 798 ms, 1 330 draws
368 s the same conversation, other camera 1 566 ms, 1 330 draws
493 s the opening credits over the rooftop ("Out Production - james nicholson, adam smith, jason hayes, roberta gatti") 1 786 ms, 1 994 draws

129 world frames before that, 0 device removals, and the run ended at 566 s not with a GPU fault but with the title's own breakpoint: unhandled exception 0x80000003 at victory-image+0x5149aec (three first-chance ones first, then the fatal), followed by the title's Breakpad reporter writing a minidump. 0x80000003 is int3 - the game's own consistency check, not ours and not the driver. That is the next error class to chase, and it is after the opening credits, i.e. deeper than anything reached before.

So the prologue's content runs: dialogue, cameras, subtitles, credits. Two visible rendering defects remain in those frames (checkerboard patches under the rooftop and in the sky in the credits shot), which is what a broken invariant at the end may be about.

The frame cost is genuine work, not loop burn. Ladder on the same scenario (warm cache for each limit, 420 s window, cold translation excluded):

loop limit world frames removals median ms/frame median GPU ms
default (2^20) 17-22 0 3 091-3 799 2 553-3 322
4 096 28 0 3 433 2 395
65 536 2 (run died at startup) - - -

Capping every translated loop at 4 096 iterations - the switch that took the loading from 15 450 ms to 56-83 ms - leaves the prologue's frames where they were. So the 1.5-3.8 s frames are the title's real compute and draw work (the per-command report puts it in eight compute pipelines of 0.3-0.8 s each a frame), and improving fps means making those cheaper, not shortening loops.

Also in this turn: CAPACITY 512 -> 2048 is reverted (652cd44) - the A/B in part 26 shows the values within noise and the "table full" warning never firing, so the fix part 23 claimed was not one. The diagnostics stay.

cargo test --release --workspace: 30 suites, 0 failures. (Two runs during the session failed one hardware-sensitive test each - a GPU valu test and the low-guard memory test - both pass alone and the workspace is green on a quiet machine, so they are load flakiness on this shared box, not the branch.)

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 26, 2026
…pump coalescing & 16-bit/indirect completeness (Wave 29A)

Adapts and integrates:
- GPU-to-CPU title-window write-back with retire-ticket fencing, xmem dirty-stamp + byte-level CPU-write precedence, and LEONIDA_TITLE_WRITEBACK=0 kill switch (ubiquitarianism/leonida#2129, GPL-3.0).
- Slot-133 shadow GPU-write preservation via 256-byte piece sums (LEONIDA_SHADOW_KEEP, ubiquitarianism/leonida#2163, GPL-3.0), saved-snapshot advancement after partial merge (Marvisak/VIctory#3031, GPL-3.0), and read-only hash skip for foreign PAGE_READONLY pages (ubiquitarianism/leonida#1897, GPL-3.0).
- Held-batch fence-pump fix: snapshot has_shader_work / internal_staging on ExecuteCommandLists thread in VulkanQueue::Deferred and coalesce redundant back-to-back refresh_shadows() / refresh_console_heaps() inside a single QueueHolds::pump_ready() sweep when xmem epochs and shadow registry are unchanged.
- Transient dedicated command-pool renewal for long recordings above LEONIDA_CMD_POOL_RENEW (default 512, Rubenpannen/VIctory-RTX5070@5df4fb3, GPL-3.0).
- Complete 16-bit packed colour widening for B5G6R5_UNORM RT/UAV, B4G4R4A4_UNORM RT/UAV, and B5G5R5A1_UNORM RT/UAV (Marvisak/VIctory#2936, GPL-3.0; californiaAlmonds/OpenScarlett@ee7153c, MIT).
- Compound graphics ExecuteIndirect host-visible expansion, Tier 1.1 incrementing-constant stride fix, and D3D12 state-leakage binding reset (ubiquitarianism/leonida#1937, GPL-3.0).

AI-assisted; verified on NVIDIA GeForce RTX 3080 (Windows 11, VS 18 MSVC 19.51) with LEONIDA_VK_VALIDATION=1 (18/18 CTests passed, 0 validation errors).
Three prologue compute pipelines read a *root view's* offset while the title
had bound that root as 32-bit constants, and every such draw or dispatch was
dropped:

    dropped 1-2.4/frame without a host pipeline:
      dispatch: a root view's offset: no root view, or outside title buffers
      [compute 35e51bb27a463294], [compute f94e5d8bf4e1cf05], ...

A diagnostics count of the two halves of that reason says which it is: over a
whole run, `no_view` fires and `no_copy` never does - the slot holds
`Root::Constants(...)`, not `Root::View(...)`. The console lets a title pass a
descriptor itself as root constants, and the ones here hold their buffer's
address in dword 0 (`Constants([1915200512, 13, 0, 0, 190980448, 16, 8, ...])`).

`State::root_address` now answers "the title address this root stands for" for
both forms: the view's address, or the first dword of the constants when that
address lies in a host copy (`shadow::find`), and `root_view_at` binds the view
at that address exactly as it did for a view root. When the address is in no
copy the old drop stands, so nothing is invented.

Measured on the prologue scenario (play driver, 560 s window, diagnostics):

    before: 2.4/frame dropped for this reason, run ends on the title's int3
    after:  0 dropped for this reason
    after, with the diagnostic loop cap 1024 (so the unrelated 5-6 s loop
    class does not end the run first): 208 world frames, 0 device removals,
    0 drops, the whole 560 s window, no title exception

The visible checkerboard patches in the credits frame are the shape this
should fix; the fix is not yet shown to remove them (the run above has no
screenshots), which is the next check.
@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 28 - the dropped dispatches are fixed, and they were a binding form we did not read, not a memory gap.

What the drops were. Three prologue compute pipelines read a root view's offset while the title had bound that root as 32-bit constants:

dropped 1-2.4/frame without a host pipeline:
  dispatch: a root view's offset: no root view, or outside title buffers
  [compute 35e51bb27a463294, compute f94e5d8bf4e1cf05, compute ffd93c8a029ff016, ...]

The diagnostics added for this turn split the reason in two - a slot holding no view, versus a view whose address is in no copy - and over a whole run no_copy never fires while no_view does, with the slot's state printed:

slot=8 root=Some(Constants([1915200512, 13, 0, 0, 190980448, 16, 8, 0, 2, 2, 0, 1, 262148, 0])) no_view=1 no_copy=0
slot=2 root=Some(Constants([1, 512, 4294967295]))                                        no_view=32 no_copy=0

So the title passes the descriptor itself as root constants (the console allows it), and those descriptors hold their buffer's address in dword 0.

The fix (3ebf6ec). State::root_address answers "the address this root stands for" for both forms - the view's address, or the first dword of the constants when that address lies in a host copy - and root_view_at binds the view there exactly as it does for a view root. If the address is in no copy, the old drop stands, so nothing is invented.

Measured, same play scenario, 560 s window:

drops for this reason world frames removals title exception
before 2.4/frame 129 (ends at 566 s) 0 int3 after the credits
after 0 - (two runs ended early on the unrelated 5-6 s loop hang) 2 none reached
after + diagnostic loop cap 1024 0 208 0 none, whole 560 s

The last line is the longest the prologue has run: 208 world frames, no removal, no exception, no dropped dispatch. The loop cap is only there to keep the other known class (a dispatch that runs a translated loop to 2^20 in 5-6 s, which hangs the device) from ending the run first; it is not part of the fix.

Still to show: whether the checkerboard patches in the credits frame go away (that run took no screenshots), and whether the run now gets past the credits without the title's int3. Both need the same scenario with screenshots, which is the next run.

cargo test --release --workspace: 30 suites, 0 failures; clippy -D warnings clean with and without diagnostics; branch fix/prologue at 3ebf6ec.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 29 - with the root-address fix the prologue runs 15 minutes and 343 frames with no removal and no exception, and the picture is a character walking in the world, not a crashed credits sequence.

Same build as part 28 (3ebf6ec), the play driver with screenshots, the diagnostic loop cap 1024 in place only so the unrelated 5-6 s loop class cannot end the run first:

343 world frames, 0 device removals, 0 title exceptions, 0 dropped dispatches
the whole 900 s window

The screenshots tell the story of the sequence, which is well past where the last crash was:

at what frame
243 s a night street with a red car (plate readable), lit windows, palm trees, a street lamp 2 363 ms
493 s looking into the sun over water, bloom and flare 908 ms, 550 draws
743 s the protagonist walking through vegetation at dusk (black top, denim shorts) 2 781 ms, 5 142 draws
868 s a near-white frame, 7 draws - a fade between shots 2 263 ms

Compare part 27's run on the same driver without the fix: 129 frames, ending at 566 s on the title's int3 right after the credits, with 2.4 dropped dispatches a frame and checkerboard patches visible in the credits frame. None of that appears in this run: no drop, no assert, no patch.

What is still in the way of a mission. The hang class. Four of the runs in this turn ended early with DXGI_ERROR_DEVICE_HUNG between 80 and 90 s (7 world frames, 2 removals), two with the fix and two without, and two with a 1024 loop cap - so it is neither caused by the fix nor fully mitigated by the cap (a nested loop is 1024 x 1024 even then). Until that is named and fixed, whether a 15-minute run reaches a mission is a coin flip; the two survivors of this turn (560 s and 900 s) both did not.

cargo test --release --workspace: 30 suites, 0 failures (part 28); branch fix/prologue at 3ebf6ec, PR mergeable and clean.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 30 - no diagnostic switch at all: 350 world frames, 15 minutes, no removal, no exception - and the scene then stands still.

Same binary as part 28 (3ebf6ec), the play driver with screenshots, nothing switched on: no VICTORY_SKIP_PIPELINES, no loop cap, no DRED, no stamps.

350 world frames (>800 draws), 0 device removals, 0 title exceptions, the whole 900 s
median 3 179 ms/frame, median GPU 2 941 ms, median 6 176 draws/frame

What the screenshots show, in order:

at what frame
243 s a night street with a red car, lit windows, palm trees 2 363 ms
368 s / 493 s city, then into the sun over water ~900-2 400 ms
618 s an interior: fluorescent ceiling lights, a figure silhouetted against the windows 3 160 ms, 6 522 draws
868 s the same interior, almost the same camera 3 272 ms, 5 984 draws

So the run is stable and deep, but from about 10 minutes it stops advancing: the last 250 s are the same interior shot. That is not a crash and not a hang - it is a scripted scene that does not move on, which is the next thing to look at for "first mission" (a cutscene waiting for an event we do not deliver - audio/subtitle/fade - rather than a rendering failure).

The hang did not reproduce. Three runs with VICTORY_D3D12_DRED=1 (so that note_op records each list's commands, which survive until the list is reset - they are what the removal message appends as ; list N of M, of its K: <command>) all ran their full windows: 87, 92 and 48 world frames, no removal. The report path is in place and costs nothing when nothing fails; it needs a failing run to say anything, and this hour did not have one. The earlier early deaths (7 world frames, ~85 s) were in runs before 3ebf6ec.

Branch fix/prologue at 3ebf6ec, PR mergeable and clean, workspace 30 suites green (part 28).

…nts at

A refusal carries `at 0x14dc`, and until now the offset was all it said: the
program is 12 000 words of native code and the instruction at that offset was
the one thing the message did not have. It has it now, in the same line:

    bvh_skinning:CSComputeSkinningPedBlendShapesVelocity_1c34db0a_Wrapped Cs
      at 0x14dc  [s_cbranch_execz Sopp { imm: 92 }]  emit: a lane mask read as data

That names the prologue's remaining functional hole instead of hinting at it:
four programs of the whole pack (`CSComputeSkinningPedBlendShapes`,
`...SecMotion`, `...Velocity`, `...SecMotionVelocity` - the character skinning
with blend shapes) fail on the same opcode, and the one the prologue binds
(`compute 82a2ad6d07417d36`) is dropped 4 times a frame in the interior scene
that the play run then stands in for four minutes. The other three shader
families that refuse at an offset get the same line for free.
@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 31 - the scene that stands still has a cause, and it is a named one: the character skinning shader does not translate.

The stall. In part 30's clean run the last four minutes are the same interior shot. Its frames carry a drop I had not looked at:

dropped 4.0/frame without a host pipeline: compute 82a2ad6d07417d36
WARN victory_gpu::pipeline: shader does not translate;
  stage="compute" hash=82a2ad6d07417d36
  error=GFX10 code at 0x150c: a lane mask read as data

So one compute pass is refused and dropped four times a frame for the whole scene. It is the character skinning with blend shapes.

Naming the instruction. A refusal used to give only an offset; translate --list now prints the opcode there too (049c3f6), and the corpus run says which one:

bvh_skinning:CSComputeSkinningPedBlendShapesVelocity_1c34db0a_Wrapped Cs
  at 0x14dc [s_cbranch_execz Sopp { imm: 92 }]  emit: a lane mask read as data

Four programs in the entire 26 084-program pack fail this way, and they are all the same family: CSComputeSkinningPedBlendShapes, ...SecMotion, ...Velocity, ...SecMotionVelocity. The opcode is s_cbranch_execz - "branch if no lane is active" - which reads the EXEC mask, and the mask's value at that point is the per-lane boolean the emitter keeps in lane_bits rather than a mask dword, so the read comes back as Val::Missing("a lane mask read as data") and the branch refuses. That is a concrete, bounded bug in the emitter's mask handling, not a data or memory problem.

Also measured and rejected this turn: copies in video memory. Same play scenario, only VICTORY_COPIES_IN_VIDEO_MEMORY=1, compared inside the 4 000-8 000 draws band where both runs have frames:

frames removals median ms/frame median GPU ms draws
plain (playclean) 112 0 3 196 2 956 6 238
copies in VRAM 54 0 4 289 2 804 5 917

The GPU term does improve (-5 %: 2 956 -> 2 804), but the CPU side more than eats it: the total goes up 34 %. Not kept.

Where this leaves the objective. The prologue now runs 15 min and 350 frames with no switch, no removal and no exception, and the scene that does not advance does not advance because a skinning pass is missing. Fixing s_cbranch_execz's mask read is the next step and the first one that should move the content forward rather than the frame time.

cargo test --release --workspace: 30 suites, 0 failures; clippy -D warnings clean; branch fix/prologue at 049c3f6.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 32 - the mask fix was attempted four ways, measured each time, and not kept: the corpus does not move.

The target was compute 82a2ad6d07417d36 (character skinning, dropped 4/frame in the interior scene), refused at s_cbranch_execz with "a lane mask read as data". Four attempts, each built and run over the whole pack (victory translate --list, 26 084 programs, ~50 s):

attempt what it changed corpus
1 get falls back to the emitter's own bit (lane_bits) when a mask is missing 5 refusals, DXIL 14 246 - no change
2 s_cbranch_execz/execnz may read a mask as data (in inst()) 5 refusals, DXIL 14 246 - no change
3 mask_ok is forced true for a block's branch in exit() 5 refusals, DXIL 14 246 - no change
4 64-bit scalar logical ops and v_readlane_b32 may read masks as data 5 refusals, DXIL 14 246 - no change

What the probes found, and why none of them hit:

  • a probe inside get (printing the instruction being lowered) fires zero times at s_cbranch_execz - so the branch's mask is not read through get;
  • the same probe fires 978 times at v_readlane_b32, 6 at s_xor_b64, 4 each at v_cmpx_gt_u32 and v_cndmask_b32, all of which are caught (the translation continues), so none of them is the fatal one;
  • a probe at the branch's own condition (exit()'s atom(..) -> map_err) also fires zero times - so the fatal LANE_MASK comes from somewhere that is neither get nor the branch's atom: mask_dword/i32_of, or the structuring pass that hands the branch its condition.

That is the precise next step, and it is one instrumented run away: put the probe in mask_dword, i32_of (and mask_number) rather than in get, and print the IR block/instruction that asked. Four attempts that each left the corpus bit-identical is the evidence that guessing at the gate is not the way in.

Everything reverted (git status clean at 1e49107); cargo test --release --workspace: 30 suites, 0 failures. The branch keeps the two things that are measured: the root-address fix (drops 2.4/frame -> 0, 3ebf6ec) and the CLI naming the refusing opcode (049c3f6, 1e49107).

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Addendum to part 32 - the refusal site is now pin-pointed, which is what the next attempt needs.

Two more probes (both reverted; the corpus is unchanged and the branch is clean at 1e49107):

  • mask_dword's "not a structural mask" path: 0 hits in the whole pack - the fatal mask never reaches it;
  • i32_of's missing-value path: 32 169 hits, all caught (translation continues);
  • the branch's own boolean(when, ..) in exit(), i.e. the _ arm of the branch-condition match: 5 hits, all fatal, and mask_ok is true there:
PROBE exit boolean: when Bool(22261) why "a lane mask read as data" mask_ok=true
PROBE exit boolean: when Bool(25212) why "a lane mask read as data" mask_ok=true
PROBE exit boolean: when Bool(25509) why "a lane mask read as data" mask_ok=true
PROBE exit boolean: when Bool(29239) why "a lane mask read as data" mask_ok=true

Four of those are the four CSComputeSkinningPedBlendShapes* programs; the fifth is Bool(2) ... "a descriptor read only as data", a different, already-known refusal. So the fatal path is: the branch's condition is a compound boolean (Bool(n), a node of the boolean tree) whose evaluation reaches a mask atom that cannot be read - not the atom-only fast path the branch takes when the condition is (atom, TRUE, FALSE).

For the next attempt that means: the fix belongs inside boolean()/atom() (in structure's boolean tree), not in get, mask_dword or inst. With mask_ok already true there, the atom must be a mask the emitter has neither in x.st.masks nor a bit for in lane_bits - which is the case a probe inside atom() can print in one run.

Everything else stays as it was: corpus 5 refusals / 14 246 DXIL before and after every attempt, cargo test --release --workspace 30 suites green, victory-shader 302 tests green, branch fix/prologue at 1e49107, CI green.

@steven-seagull27

Copy link
Copy Markdown

@pes7 I reproduced the compound exit/boolean refusal from your part 32 addendum with a synthetic compute shader on 1e49107. I put an opt-in producer trace on that exact head, following ThomasSAMP’s producer-tracing work in #1425.

In my fixture, s_and_saveexec_b32 produces an SCC that feeds a scalar select and then a vector compare. The branch reports:

lane-mask trace: Cs s_cbranch_execz at 0x28 [exit/boolean] from s_and_saveexec_b32 at 0x18; numeric helpers ["i32_of"]; leaf Lane(Value(17)) defined by v_cmp_gt_u32 at 0x20, structural mask=true, lane bit=false

The compare is where the leaf lost its bit. The missing input came from the earlier save-EXEC instruction. Your shader may reach a different producer. On the unmodified head, ordinary compare → save EXEC → branch → restore controls with 0, 8, and 32 active lanes matched 96/96 lanes per adapter on RTX 5080, Windows WARP, and WARP 1.0.22. The existing mask/data-join control matched another 32/32 per adapter.

To try the trace on your branch in PowerShell, substitute your usual input path in the last command:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2936-exec-branch-origin
git cherry-pick b8b7c6e108e97df83f07c56f4aee4aaf3ab5c5bd
$env:VICTORY_TRACE_LANE_MASK = '1'
cargo run --release --locked -p victory --features diagnostics -- translate --list "<your usual shader-pack path>"

Could you share just the text trace line for one of the four skinning shaders? The stage, leaf and producer opcodes and offsets should be enough to build a narrower synthetic case. All my inputs were synthetic. AI-assisted with Codex.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Addendum to part 32 - the poisoned value is traced to its entry-block origin, and that rules out the seven guesses.

A probe now records, for every value marked "a lane mask read as data", the instruction that wrote it (name, machine offset, IR block), keeps the last twelve mask reads of a thread, and prints them when a lowering ends on one. Worth keeping in mind: the emitter tolerates per-instruction failures (it marks their writes missing and goes on), so a value's reason is often the reason of an instruction several steps earlier - that is why every gate I tried looked right and changed nothing.

For the four CSComputeSkinningPedBlendShapes* programs the chain is:

PROBE fatal mask read 11: Some(("v_cndmask_b32",        3452, block 75))
PROBE fatal mask read 10: Some(("s_andn2_wrexec_b32",   3392, block 74))
PROBE fatal mask read  9: Some(("s_and_saveexec_b64",   5988, block 32))
PROBE fatal mask read  8: Some(("s_and_saveexec_b64",   5988, block 32))
PROBE fatal mask read  0: Some(("s_mov_b64",              44, block  0))   <- the entry block
PROBE fatal mask read  1: Some(("s_mov_b64",              44, block  0))

So the mask is copied out of EXEC at the entry block (s_mov_b64 at 0x2c), saved and restored (s_and_saveexec_b64), inverted (s_andn2_wrexec_b32) and finally selected on (v_cndmask_b32) - and every one of those steps is a mask operation whose value the emitter has no number for. The read that finally kills the program is the select, but the missing thing is the entry EXEC.

Seven attempts, each built and checked against the whole pack (26 084 programs, ~45-50 s), each leaving it bit-identical (5 refusals, DXIL 14 246) and each reverted:

  1. get falls back to the emitter's bit (lane_bits);
  2. s_cbranch_execz/execnz may read masks in inst();
  3. mask_ok forced true for a block's branch;
  4. the 64-bit logical ops and v_readlane_b32 may read masks;
  5. the branch condition's boolean(when) swallows LANE_MASK (branch taken);
  6. a v_cmp_* writing its mask to VGPRs gets the ballot dwords;
  7. Atom::Lane of the entry EXEC reads as "all lanes active".

Where that leaves it: the emitter has no number for the entry EXEC because it never records the exec mask as a mask in structure's tables for these programs (x.st.masks has the value at the branch, but its provenance is an instruction that already failed). The next attempt should therefore start from the entry EXEC's structure entry rather than from the branch, and the disassembly of the native code at 0x2c/0x1764/0x1794/0xcf8 of one program (CSComputeSkinningPedBlendShapesVelocity) is the cheapest way to see what the console compiler was doing.

State: branch clean at 1e49107, victory-shader 302 tests green, clippy clean, corpus 5 refusals / 14 246 DXIL as before.

@steven-seagull27

Copy link
Copy Markdown

@pes7 Your four opcodes were enough to reproduce the compound branch refusal on 1e49107 with a synthetic guest Wave64 compute shader. The wave width and register operands of one skinning variant would tell us whether this is the same failure.

I copied entry EXEC into s[20:21], narrowed it with s_and_saveexec_b64, ran s_andn2_wrexec_b32 s24,s20 with s25 initially zero, restored EXEC, then used s[24:25] as the condition of v_cndmask_b32. Feeding the selected value into a compare and then s_cbranch_execz gave “a lane mask read as data” before pipeline creation. This reproduced with both 8 and 40 lanes selected initially. Runnable synthetic case and control

The entry EXEC pair and its saved copy were both structurally Bool::TRUE in this fixture. At the select, the WREXEC low result had other=Some(Bool(3)), pair=None and stored=a lane mask read as data. The high register still held numeric zero. Both the branch and a separate store traced the propagated failure back to WREXEC. That gives us a way to distinguish a missing entry mask from a lost low/high pair downstream.

Changing only WREXEC to its B64 form let all six guest-Wave64 controls run. 384/384 lane values matched on each of RTX 5080, inbox WARP and WARP 1.0.22. B32 and B64 write different halves, so each form has its own expected output. The host wave width was unpinned.

Could you post the guest wave width and the four decoded instructions with operands from one named variant? The decimal offsets from the ring (44, 5988, 3392, 3452) convert to 0x2c, 0x1764, 0xd40, 0xd7c. The last two differ from the offsets listed at the end of the addendum. One variant’s text is enough.

If convenient, my opt-in offset diagnostic prints those operands, SSA reads/writes and mask-pair state only when a lane-mask refusal escapes. The branch includes the earlier producer trace and is based on your 1e49107. From a checkout of that branch, use the same translate command as before with:

$env:VICTORY_TRACE_LANE_MASK = '1'
$env:VICTORY_TRACE_LANE_MASK_AT = '2c,1764,d40,d7c'

I validated the diagnostic on both branch and store refusals. All local shader inputs were synthetic. AI-assisted with Codex.

…'s refusals

A program's refusal is usually not the instruction the message names: the
emitter gives up on an instruction, marks its writes missing and goes on, so a
branch can report a reason that came from something dozens of instructions
earlier (the prologue's character skinning reports `s_cbranch_execz` at
0x14dc while the first thing it cannot do is a mask copy at 0x5c).

Two switches for that:

- `VICTORY_ONLY=@0x<offset>` (`translate --list`): translate only that
  container, so one program's log is its own;
- `VICTORY_TRACE_FAILS=1`: log every instruction the emitter gives up on, with
  its offset, block, reason and reads.

Together they give the ordered list, which is what says where to look:

    FAIL s_setreg_imm32_b32 at 0x1c (block 0): a register the emitter does not model
    FAIL s_mov_b32 at 0x5c (block 1): a lane mask read as data reads [(S(126), Value(8))]
    ...

Both are read at run time only, so a normal run pays nothing.
@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 33 - the refusal now has an ordered list, and its first entry is not where the message points.

Two switches are in the branch (433d49b, diagnostics only, read at run time):

  • VICTORY_ONLY=@0x<offset> - translate --list translates just that container;
  • VICTORY_TRACE_FAILS=1 - every instruction the emitter gives up on, with offset, block, reason and reads.

For CSComputeSkinningPedBlendShapesVelocity (@0xbe8bb1f) that gives the whole story in order:

FAIL s_setreg_imm32_b32 at 0x1c (block 0): a register the emitter does not model
FAIL s_setreg_imm32_b32 at 0x24 (block 0): a register the emitter does not model
FAIL s_mov_b32 at 0x5c (block 1): a lane mask read as data  reads [(S(126), Value(8))]
FAIL s_mov_b32 at 0x60 (block 1): a lane mask read as data  reads [(S(126), Value(8))]
FAIL s_and_b32 at 0x9c (block 2): a lane mask read as data  reads [(S(106), Value(184)), (S(0), Value(185))]
FAIL s_and_saveexec_b32 at 0xa0 ... reads [(S(0), Value(186)), (S(126), Value(106))]

So the first thing that cannot be done is s_mov_b32 at 0x5c copying the exec mask's low dword (S(126), the entry value 8) into a register - and everything after it is fallout. The program's own error is reported 2 000 words later, at the branch.

Five more attempts were measured against the pack and reverted, all bit-identical (5 refusals, DXIL 14 246):

  1. mask_dword falls back to the emitter's bit, then to "the entry exec is all lanes";
  2. the same fallback in get, before it refuses;
  3. is_mask no longer gated by mask_ok in get;
  4. bit_masked (ballot of the bit) shared by both callers;
  5. the entry-exec short circuit placed first in mask_dword, before the structure's table.

With the trace on, the failing s_mov_b32 does not go through i32_of (a probe there logs other values, never Value(8)), so the refusal comes from the SOP1 move's own mask path rather than from get. That is the piece to instrument next: probe mask_dword and the scalar-move handler together, with VICTORY_ONLY set, and see which of them produces the reason for that one instruction.

Branch fix/prologue at 433d49b; cargo test --release --workspace 30 suites, 0 failures; clippy -D warnings clean across the workspace.

@steven-seagull27

Copy link
Copy Markdown

@pes7 I tested the SOP1-vs-mask_dword question from part 33 on 433d49b. Both s_mov_b32 entries can log FAIL in a shader that executes correctly. My synthetic fixture put consecutive copies of entry EXEC_LO at 0x5c and 0x60. Both destinations were tracked masks. Lower::sop therefore returned LANE_MASK before reading the source, and neither copy called i32_of or mask_dword. The branch/restore control still matched 40/40 output words on each of RTX 5080, inbox WARP and WARP 1.0.22 (groups of 8 and 32).

Making a subsequent vector move consume the saved register as data invoked mask_dword on the copied SSA value, not the original entry value. On the RTX 5080 all eight lanes read 0xff in the partial group and all 32 read 0xffffffff in the full group. That distinction explains how a probe watching only Value(8) could miss the numeric consumer in a case like this.

I put the requested 27-line diagnostic on your exact head. It prints the decoded source and destination, the destination SSA ID, whether the move took the structural or numeric path, and the SSA ID of each actual mask_dword call. To use it on your branch:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2936-sop-path
git cherry-pick 45f68677f68ed02deea4d9bcc49066e91519dde8
$env:VICTORY_ONLY = '@0xbe8bb1f'
$env:VICTORY_TRACE_FAILS = '1'
$env:VICTORY_TRACE_EXEC_MOV = '1'

With your usual diagnostics-enabled translate --list command, the useful excerpt is the two EXEC move lines at 0x5c/0x60 and any EXEC numeric lines referencing their destination IDs. That would identify which path this particular game shader takes. The earlier mixed-width case remains a separate synthetic reproducer. AI-assisted with Codex.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 34 - the gate is found and measured; the change that opens it needs the join redesigned first, so nothing is kept.

The gate. lower.rs, sop(): after computing the destination, it refuses outright -

if inst.write(Reg::S(EXEC)).is_some() || self.is_mask(lo) {
    return Err(LANE_MASK);
}

so any scalar op that writes a lane mask is refused: the copy of EXEC at the top of the character-skinning programs, s_and_saveexec_b32, a mask combine. That refusal is what the branch finally reports.

What opens it. Lowering the mask the op leaves behind - the structure's boolean for every mask register it writes, the destination's bit for writes the structure does not name - instead of refusing. Measured over the whole pack, per program, against a baseline taken with the change stashed:

before 25889 program lines, after 25889
only before: 4   only after: 4
  before: CSComputeSkinningPedBlendShapes{,_SecMotion,_Velocity,_SecMotionVelocity} ... emit: a lane mask read as data
  after : the same four ... emitted
compute programs 2658 -> 2662

Exactly the four intended programs, nothing else. (For scale: with an additional shortcut that makes an untracked mask join contribute no lane, 17 program lines change - these four plus thirteen CS_RTShadowTrace* ray-traced-shadow programs that refuse the same way today.)

Why it is not kept. The emitter's mask joins are the contract that keeps the approximations honest, and the two sides of it are pinned by tests that my change breaks one each way:

  • with the join still refusing an untracked arg: emit::lower::tests::a_scalar_result_needs_no_exec fails ("a lane read under an EXEC with no mask" now refuses);
  • with the join contributing no lane: emit::synthetic_tests::a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there fails;
  • with the join falling back to the emitter's own bit: CS_IrradianceCache_Shade (which translates today) starts refusing.

So the piece to write next is the join itself (pending_masks in fill_phis): it must tell a mask register reused as data on one edge (the case those two tests describe) from a mask joined with a mask. The four skinning programs give it a target and the two tests give it a contract; the change above is one git stash away and is exactly four programs wide.

Reverted: branch fix/prologue at 433d49b, 302 victory-shader tests and 30 workspace suites green, clippy clean.

@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Progress log, part 35 - the join's contract is now written down exactly, from the tests themselves, and the one place a fix still dies is named.

Four variants were built and measured; each one satisfies part of the contract and breaks another part, so nothing is kept:

variant test 1 a_scalar_result_needs_no_exec test 2 a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there corpus
sop() lowers every mask write from the structure's Bool, join unchanged fails (untracked join) passes +4 compute (2 662)
+ join takes the emitter's bit fails passes +4, 0 other lines
+ data edge gives 0 lanes passes fails (second half) +17 lines
only structure-named mask writes get a bit fails passes -

The contract, from the two tests:

  1. a mask register the compiler reuses as data on an edge (zeros) gives that edge no lanes - ..._joined_with_data_on_the_skip_edge_is_0_there, first half;
  2. a mask that holds lanes off its edge (the saved EXEC of an s_and_saveexec) joined with data must stay refused - the same test's second half (a mask holding lanes off its edge joined with data translated panics otherwise);
  3. a copy of EXEC that only guards a v_readlane must not create a lane-mask phi at all - a_scalar_result_needs_no_exec.

Where the clean fix dies. sop() can lower s_mov_b32 sX, exec_lo from the structure's boolean, and that is exactly what the four CSComputeSkinningPedBlendShapes* programs need (measured: 2 658 -> 2 662 compute programs, four lines changed, nothing else). But when the destination's boolean is itself a join, evaluating it registers a mask phi in pending_masks, and if one of that phi's edges is untracked, fill_phis turns it into Err(unsupported(...)) - fatal for the whole program, where the old refusal was merely tolerated (the instruction's writes marked missing). That is why a_scalar_result_needs_no_exec fails in every variant that lowers the copy.

So the missing piece is in pending_masks itself: a phi registered because a mask was read as data must not fail the program when an edge is untracked - it should fall back to the tolerated path (the value stays a number, EXEC drawn from it only guards a v_readlane). With that, variant 2's numbers (+4 programs, 0 other lines) should hold with both tests green.

Branch fix/prologue at 433d49b, clean; 302 victory-shader tests and 30 workspace suites green after the revert.

pes7 added 2 commits November 26, 2026 16:43
…not a refusal

`sop()` refused every scalar instruction whose destination is a lane mask -

    if inst.write(Reg::S(EXEC)).is_some() || self.is_mask(lo) {
        return Err(LANE_MASK);
    }

- so a program that copies exec before its first branch was refused at that
branch, and the whole pipeline was dropped. That is the prologue's character
skinning with blend shapes (`CSComputeSkinningPedBlendShapes`, `...SecMotion`,
`...Velocity`, `...SecMotionVelocity`), dropped four dispatches a frame in the
scene where the play run then stands still.

Now the op lowers the mask the structure already has for what it writes,
instead of refusing. Three details make it hold:

* only the writes the structure names as masks get a bit; a write it does not
  name (the saved exec of an `s_and_saveexec`, a register the compiler reuses
  for data) carries the destination's mask, because the branch that follows
  would otherwise read a value with no definition at all;
* a phi registered while such an evaluation runs is *lenient*: an edge the
  structure cannot name gives it no lanes instead of failing the program, so
  `a_scalar_result_needs_no_exec` (a copy of exec that only guards a
  `v_readlane`) keeps translating;
* every other mask join keeps its refusal, so a mask holding lanes off its edge
  joined with data still does not translate
  (`a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there`, second half).

Measured over the whole shader pack (`translate --list`, 26 084 programs),
against a baseline taken with this change stashed:

    before 25889 program lines, after 25889
    only before: 4   only after: 4      (the same four, now emitted)
    compute programs 2658 -> 2662

Nothing else changes. `cargo test --release --workspace`: 30 suites, 0
failures; clippy `-D warnings` clean.

`lower.rs` is at the repository's 512 KiB asset-policy limit, so the two new
methods live in `emit/lower/masks.rs`.
…focus

`VICTORY_KEYS=<seconds>:<key>` held each key for 200 ms, which is enough for a
menu press and not for walking. The entries now take a third field, the hold
in milliseconds:

    VICTORY_KEYS=200:W:6000,215:A:1200,10:Enter:300,20:Enter:300

Both the keyboard device and the stand-in pad see the keys (the HLE merges
them in `poll`), so a run can be driven while the title's window stays in the
background: nothing calls `SetForegroundWindow` or `keybd_event`, and the
person using the machine keeps their focus. Enter is the pad's A and W the
left stick up, so the account screen, the menu and walking all work this way.

First run with it (`nofocus`): the title reached the world without any window
activation - 1 862 draws/frame at 153 s, 4 657 at 196 s - where every earlier
driver had to attach to the window's input queue and steal focus at 15/40/70 s.
@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Attribution of the prologue's GPU time, measured - and why cutting the biggest pipeline would not move the frame.

The no-focus run (prologue, 1 200 s, VICTORY_KEYS only) gave 477 world frames, 0 removals, 0 exceptions, and its per-command report (VICTORY_GPU_STAMPS + DRED, one line per command over 200 ms) names every pipeline:

pipeline dispatches per frame median ms total ms
compute 39f0e9aeb156a61c 341 0.71 303 103 764
compute 5cf00dc39042edaf 266 0.56 85 24 104
compute df11dcd012cd7382 294 0.62 61 17 895
compute 3df629ffc3d0a2a6 1 - 9 265 9 265
compute 8cb27ccf2d50c606 335 0.70 25 8 904
compute 34fb51b8a0312e82 199 0.42 36 6 821
compute 0a5ecfee6b79e13b 244 0.51 29 6 453

Two things fall out of it:

  1. The single biggest pipeline is ~218 ms of a 2 900 ms GPU frame (about 7 %), not the 44 % the earlier 196-frame sum suggested - that sum was over the reported commands only, and the report logs commands above 200 ms, so it is a ranking, not a budget.
  2. The frame is many commands of moderate cost, not a few heavy ones. The seven families above add to ~360 ms/frame; the remaining ~2.5 s is spread over the mesh draws, the indirect dispatches and 1 400-6 000 draws a frame. compute 3df629ffc3d0a2a6 is one 9.3 s dispatch in the whole run (a bake during loading), not a frame cost.

So an optimization aimed at 39f0e9aeb156a61c would be worth ~7 % at best, and the shape of the data says the cost is per-command overhead (binding, descriptors, barriers) rather than one bad shader. That changes what to attack next, and it is why nothing is committed here: a shader-level micro-optimization would not have shown a frame-time win.

39f0e9aeb156a61c itself, for the record: 24 896 IR lines, NumThreads=(32,1,1), 3 600 groups a dispatch, five translated loops, 464 waveReadLaneFirst, 170 raw buffer loads, 26 atomics - a coarse BVH-style pass whose cost is the work it is asked for.

Next, in this order: (a) count what the 1 400-6 000 draws and ~31 barriers a frame each cost, with the same report (it logs a command only above 200 ms today, so the threshold has to come down for a frame's worth of commands); (b) the per-frame CPU side - 1 192 root-view slots, 533 k heap slots and 1.5 GB of copies - where the numbers are already in the frame line.

…_GPU_REPORT`)

The batched report named two commands a list, and only for submissions over
200 ms, so a frame's ~350 commands were ranked by their two longest - which is
why the biggest pipeline looked like 44 % of the frame when it is 7 %.

Two switches now say how much to list and when:

    VICTORY_GPU_REPORT=40           commands per list (default 2)
    VICTORY_GPU_REPORT_MIN_MS=250   submission length that triggers it (default 200)

With 40, a 1 150 ms submission lists 354 commands summing to 1 144 ms, i.e. the
report accounts for the submission's whole time. On the prologue's frames it
gives the family table the next optimization needs - no single shader:

    indirect 25ebc92075b62822   2 453 ms   (an indirect draw: geometry)
    dispatch 39f0e9aeb156a61c   2 019
    indirect 7a071f906f98311b   1 749
    draw     05e958b19269d596   1 126
    dispatch 5cf00dc39042edaf     538
    mesh     04b9be3756e8f41c     475

over the sampled submissions, each family 200-600 ms of a ~3 s frame: geometry
and compute in similar measure, not one bad pass.

Diagnostics only (the switches are read at run time, nothing changes without
them); clippy `-D warnings` clean, `cargo test --release -p victory-gpu` 231
passed.
@pes7

pes7 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

The report now ranks a whole submission (621935a8), and the frame turns out not to be one bad pass.

Two switches: VICTORY_GPU_REPORT=<commands per list> (2 by default) and VICTORY_GPU_REPORT_MIN_MS=<submission length> (200 by default). With VICTORY_GPU_REPORT=40 on a 1 200 s no-focus run (149 world frames, 0 removals, 0 exceptions, frames 2.9-3.4 s at 4 800-10 400 draws), a 1 150 ms submission lists 354 commands summing to 1 144 ms - the report accounts for the submission's whole time, so its ranking is now a budget.

The families, over the sampled submissions:

command family ms
indirect 25ebc92075b62822 (an indirect draw: geometry) 2 453
dispatch 39f0e9aeb156a61c 2 019
indirect 7a071f906f98311b 1 749
draw 05e958b19269d596 1 126
dispatch 5cf00dc39042edaf 538
mesh 04b9be3756e8f41c 475

Each family is 200-600 ms of a ~3 s frame: geometry and compute in similar measure. That is why nothing was committed as an fps fix this turn - the earlier "39f0e9aeb156a61c is 44 % of the frame" reading came from ranking only the two longest commands per list, and the biggest single family is indirect 25ebc92075b62822, a vertex shader driven by an indirect draw.

Next, concretely: the vertex shader behind the indirect draws (25ebc…) and the indirect dispatcher (7a07…) are now the two candidates with the largest budgets; the geometry side is where our translation adds the most per-vertex work (typed buffer fetches read as raw bytes and converted per component), so that is the first thing to time against the console's form.

Verification: cargo test --release -p victory-gpu 231 passed, clippy -D warnings clean; the switches are diagnostics-only, read at run time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants