Skip to content

Shaders: console containers are walked without decoding instructions - #1082

Open
TG0000 wants to merge 1 commit into
xcl-dev:mainfrom
TG0000:perf/shader-container-scan
Open

TG0000 wants to merge 1 commit into
xcl-dev:mainfrom
TG0000:perf/shader-container-scan

Conversation

@TG0000

@TG0000 TG0000 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

While a title loads, every console shader it submits goes through xbox::parse, and once through the instruction statistics of shader::capture. Both only need an instruction's length, whether it ends the program, its branch offset and its mnemonic, but they used rdna2::decode for that: three Vecs, SipHash lookups and bit-at-a-time field reads per instruction, with each program decoded in full three times.

I sampled a retail title's running threads for its first 40 s on main (6efdabc): xbox::parse was in 20.3 % of the samples and InstStats::add_shader in 10.8 %, on the threads that make the title's pipelines.

This adds rdna2_scan::step, which walks code from tables built from the decoder's own tables and does not allocate. decode() is unchanged and stays the reference that the tests compare against.

A whole retail pack: 26 503 shaders, 44.4 M instructions, one thread before after
xbox::parse (about 2 s of both is inflate) 38.1 s 4.7 s 8.1x
instruction statistics 23.3 s 1.8 s 13x

A digest over the Debug output of every parsed shader and of its statistics is the same before and after, for the whole pack.

Synthetic benchmark (bench_scan, release, three runs, other load on the machine). "Before" is the old walk, kept in the tests as the reference:

ns / instruction before after
split_segments 230 - 253 21 - 22 11 - 12x
branch_targets 346 - 370 20 - 22 17 - 18x
statistics 408 - 466 21 - 22 19 - 21x

The same sampling on this PR's head (one run each): 2150 samples of running threads instead of 3570; xbox::parse and InstStats::add_shader are below 12 % each over the run (no longer in the sampler's top 26; on one thread and 4 s window parse still had 13.5 %, inflate included). shader::capture itself is still visible (its lock and hashing, which #1026 is about). One run each, so take it as a direction, not a figure.

Related: #1026 moves the statistics of shader::capture to a worker thread (shader.rs only, no shared file). This PR makes that work cheaper, and also the parse that every pipeline translation does on its own thread. #479 speeds up decode() itself. Both change rdna2.rs; I have not tried merging them together.

What is in it (one commit)

  • gpu/rdna2_scan.rs (new): the tables, step, and its tests.
  • gpu/xbox.rs: split_segments, branch_targets, is_data_block and InstStats use it. A segment with s_getpc_b64 three instructions before an s_setpc_b64 (where resolve_far_jumps may find a far jump) still goes through decode. Mnemonics are counted by number and named once per shader.
  • gpu/rdna2.rs: three helpers are visible to the sibling module; mnemonic is split into mnemonic_of. No change in behaviour.
  • build.rs: the new file is part of the translator's source identity. As with any change to these sources, the translation cache is rebuilt once.

It is over 400 changed lines because more than half of them are the tests and the old walks they compare with.

Tested

  • AMD Radeon RX 6800 (driver 32.0.21045.29003), Ryzen 9 5900X, Windows 11 build 26300, Rust 1.100.0 stable-x86_64-pc-windows-msvc.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 741 passed, 3 failed, 42 ignored. The three failures are title_textures::placed_title_textures_share_vram_and_preserve_pixels, title_textures::transitions_apply_when_their_list_is_submitted and vram::d32s8_targets_take_their_own_size_of_video_memory; the same three fail on main (384f7f7) on this machine.
  • SKIPPED: test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state (no D3D12 debug layer).
  • New tests: every_opcode_steps_as_it_decodes (every opcode of every primary encoding, assigned or not, with literals, SDWA / DPP and cut short), random_dwords_step_as_they_decode (100 000), programs_and_statistics_are_as_decoded (3 000 random programs with branches, far jumps, data blocks and padding: segments, branch targets, data blocks and statistics against the old walks).
  • cargo test --release -p xcl --lib scan_tests -- --ignored --nocapture for the benchmark.
  • A retail title reaches the same 60 presents per 2 s as main. The frame counts of these runs vary too much from run to run (earlier runs of 6efdabc gave 416 and 928) to show the gain.

Regression run

The title: line of both blocks is replaced by a neutral name; the rest is as scripts/smoke.ps1 printed it. The main block is from a run on the same machine by another session.

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 954 (PresentX 954)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15118 MB

PR:

xcl-smoke v1
commit: 3c325a9080790815bae0e79349ac24d93f2bb52b
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 1030 (PresentX 1030)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15102 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5 found the cost with a sampling profiler of its own, wrote the change, the tests and this description, and ran everything above.

xbox::parse decoded every program twice in full (segments, branch targets; a
third time for a segment that may be data) and the statistics of a captured
shader once more: three Vecs, hash lookups and bit-at-a-time fields per
instruction, for its length, terminator, branch offset and mnemonic. Sampled
in a retail title's first 40 s, the two were 31 % of the samples of its
running threads, on the threads that make its pipelines.

rdna2_scan::step gives those from tables made of the decoder's own, without
allocating; mnemonics are counted by number and named once. decode() is
unchanged and stays the reference: every opcode of every encoding, random
dwords and random programs are compared with it, and a segment with a far
jump still goes through it.

A whole retail pack (26 503 shaders, 44.4 M instructions), one thread:
parse 38.1 -> 4.7 s (2 s of both is inflate), statistics 23.3 -> 1.8 s, with
the same result for every shader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fromthemoonx

Copy link
Copy Markdown

NVIDIA run, since Not tested lists NVIDIA. The change is CPU-side; this covers the suite, the equivalence tests repeated, and the benchmark on another CPU.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools installed; rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17

  • Exact head 3c325a9080790815bae0e79349ac24d93f2bb52b, which is on current main 47efa2e (so also the merged result), debug: cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 744 passed, 0 failed, 42 ignored (lib 701 / 0 / 22; the extra ignored test is bench_scan). New tests passed: rdna2_scan::tests::every_opcode_steps_as_it_decodes, rdna2_scan::tests::random_dwords_step_as_they_decode, xbox::scan_tests::programs_and_statistics_are_as_decoded.

  • gpu::rdna2_scan + gpu::xbox + gpu::rdna2 + gpu::pack lib tests, 10 runs (the random-dword comparison included): 10 of 10 passed (25 passed, 1 ignored each)

  • Integration tests on parsed containers, 3 runs: disasm_e2e, console_shaders, rpf_e2e: 3 of 3 passed

  • bench_scan, release (cargo test --release -p xcl --lib gpu::xbox::scan_tests::bench_scan -- --ignored --nocapture), 3 runs, ns per instruction:

    before after
    split_segments 205 – 220 19.7 – 20.6 10 – 11×
    branch_targets 271 – 277 18.1 – 19.6 14 – 15×
    statistics 260 – 266 18.2 – 18.6 14 – 15×

    Close to your numbers. The old walk is a little faster on this CPU, so the ratios are a bit lower.

  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

  • XCL_SAMPLE_* not set, so the retail-pack tests did nothing

Not tested

  • The whole-pack digest and timing (no shader pack here), and a title's load.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds, tests and benchmark on the machine above and wrote this report from the output.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Tested

  • Exact PR head 3c325a9080790815bae0e79349ac24d93f2bb52b on Windows 11 build 26200, Ryzen 9 5980HX, Rust 1.99.0 MSVC. The focused scanner tests are CPU tests; they did not exercise the RX 6800M GPU.
  • cargo test --locked -p xcl --lib -j 2 gpu::rdna2_scan::tests:: -- --test-threads=1 --show-output: 2 passed, 0 failed, 0 ignored. These compare the scanner with the reference decoder across opcode encodings and random dwords.
  • Same command with filter scan_tests: 1 passed, 0 failed, 1 ignored. The passing test compares split segments, branch targets, data-block detection, and instruction statistics against the old decoding walks over 3,000 generated programs. The ignored test is the benchmark.
  • cargo build --locked --workspace -j 2: passed.

Not tested

AI use

OpenAI Codex (GPT-6, exact variant not exposed in this session) reviewed the exact diff, ran the scanner suites and workspace build, checked the logs, and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@thehollowedone

Copy link
Copy Markdown

Independent Windows/NVIDIA workspace run on clean 3c325a9.

Tested
Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug. cargo build --offline --locked --workspace passed. cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture reported 744 passed, 0 failed, 42 ignored. The scanner matched the decoder in the primary-opcode and random-dword fixtures. The console shader-container test also matched decoded program and statistics results. Cargo’s passed count includes two wave64 skip notices.

Not tested
Retail shader-pack timing, world load, and other GPUs.

AI-assisted. Codex (GPT-6, exact variant unavailable) ran the tests and drafted this report.

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants