Skip to content

Shaders: move capture hashing off lock and offload xbox stats - #1026

Open
rdj415 wants to merge 1 commit into
xcl-dev:mainfrom
rdj415:shaders-capture-lock-offload
Open

rdj415 wants to merge 1 commit into
xcl-dev:mainfrom
rdj415:shaders-capture-lock-offload

Conversation

@rdj415

@rdj415 rdj415 commented Nov 24, 2026 •

Copy link
Copy Markdown

Move shader validation, in-place FNV-1a hashing, and container classification outside the global STATE lock in gpu::shader::capture, and offload non-dump account_xbox FSSM decompression and RDNA2 instruction counting to a low-priority background worker flushed by shader::stats().

A retail title submits 200k+ shader blobs across parallel loading threads while >98% are duplicates of ~3.6k-19k unique shaders (e.g. 204,736 submissions for 3,579 unique shaders in the first 60 s, 15.67M RDNA2 instructions). Previously shader::capture held the global STATE mutex across readable(), heap-copying every duplicate into a Vec<u8>, fnv64(), and classify(), and then ran account_xbox() synchronously on the title's loading threads.

What is in it

  • crates/xcl/src/gpu/shader.rs: run readable() and fnv64() directly on the borrowed slice outside STATE, skip allocating Vec<u8> on duplicate hashes, avoid String allocations on existing stage/kind keys, classify unique blobs outside STATE, and offload non-dump account_xbox() to a low-priority xcl-shader-stats worker thread with a bounded flush in stats().
  • crates/xcl/src/gpu/shader.rs: unit tests covering concurrent multi-thread deduplication, deterministic worker flush on stats(), and unreadable-pointer rejection.

Tested

Regression run

main:

xcl-smoke v1
commit: 077ce40c3e371cf3df8c57985b1cc6b1db39e75a
gpu: NVIDIA GeForce RTX 5060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 500 (PresentX 500)
presents per 2 s (last 3): 60 62 60
device removals: 0
crashes: 0
peak commit: 8851 MB

PR:

xcl-smoke v1
commit: 870de7ddbcbbfe425c46eb5e574740ca2469b93b
gpu: NVIDIA GeForce RTX 5060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 694 (PresentX 694)
presents per 2 s (last 3): 57 60 60
device removals: 0
crashes: 0
peak commit: 8885 MB

Not tested

  • AMD / Intel GPUs and native wave64 tests (skipped on NVIDIA RTX 5060 Ti).
  • XCL_DUMP_SHADERS=1 disk dump path (behavior unchanged, not exercised during smoke run).
  • XCL_SAMPLE_* sample-data tests (environment variables unset).

AI use

  • Antigravity 2.0 (Gemini 4 Neon): diagnosed the contention/accounting overhead in shader::capture, wrote the implementation, unit tests, commit message, and PR description; all builds, tests, and smoke runs were executed on the hardware named above.

A retail title submits 200k+ shader blobs across parallel loading threads while >98% are duplicates of ~3.6k-19k unique shaders. Previously shader::capture held the global STATE mutex across readable(), heap-copying every duplicate into a Vec, fnv64(), and classify(), and then ran account_xbox() (FSSM decompression and RDNA2 disassembly) synchronously on the title's loading threads.

Validate readable(), hash the slice in place without copying duplicates, and classify unique blobs outside STATE. Offload non-dump account_xbox() to a low-priority worker thread (xcl-shader-stats) that stats() flushes with a bounded wait before reading STATE so report.json and e2e counts stay identical.

Assisted-by: Antigravity IDE (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib shader: 27 passed, 0 failed, 2 ignored (bench + retail-sample tests) — includes capture_deduplicates_across_threads_and_flushes_xbox_stats and capture_flushes_multiple_unique_console_shaders_from_worker, which exercise the new off-lock hashing/stats path. fnv64 now runs on the borrowed slice before the copy, dedup seen.insert happens under a short lock, and classification/unique accounting moved off it — the lock is no longer held across to_vec/classify.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Test report for exact head 870de7d.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on 870de7d as it is (its own base): 719 passed, 0 failed, 41 ignored. SKIPPED: 2 lines (no wave64 on this adapter, and the like).
  • scripts/smoke.ps1, the retail title, 60 s, release builds, main 568e7db first, then this head:

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1608 (PresentX 1608)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15841 MB

PR:

xcl-smoke v1
commit: 870de7ddbcbbfe425c46eb5e574740ca2469b93b
gpu: NVIDIA GeForce RTX 4080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1571 (PresentX 1571)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17407 MB

Not tested: AMD, the head merged onto current main, a world load.

AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.

@4usphs

4usphs commented Nov 25, 2026

Copy link
Copy Markdown

AMD run on the exact head 870de7d (870de7d), as pushed on its base 077ce40 (not merged onto current main), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2.

Tested

  • Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug, clean checkout, XCL_TRANSLATED_CACHE=0; adapter picked with XCL_ADAPTER.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:
    • AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: 716 passed, 3 failed, 41 ignored
    • AMD Radeon(TM) Graphics, the 9800X3D's iGPU (RDNA2, gfx1036), driver 32.0.21045.29003: 716 passed, 3 failed, 41 ignored
  • No SKIPPED tests on either adapter.
  • This PR's tests capture_deduplicates_across_threads_and_flushes_xbox_stats, capture_flushes_multiple_unique_console_shaders_from_worker, capture_rejects_unreadable_pointer_without_polluting_seen run and pass on both adapters.
  • The 3 failures on each adapter are the title-texture group (placed_title_textures_share_vram_and_preserve_pixels at its cubemap reuse check, transitions_apply_when_their_list_is_submitted, d32s8_targets_take_their_own_size_of_video_memory): the intermittent failure of Tests: placed_title_textures_share_vram_and_preserve_pixels fails now and then at its cubemap reuse check (main 9ce2070) #718, which takes the other two with it (Tests: a panicking title-texture test no longer poisons the others #673), not this PR. They pass on their own on this head. cargo test -p xcl --lib -- --test-threads=4 on the base 077ce40 fails the same 3 on the iGPU (that run passed on the RX 9070 XT, so it is intermittent there too).

Not tested

  • smoke or a retail title (I have none), a release build, Linux.

AI use

  • Claude Code (Claude Opus 5.5) read the diff, ran the tests and the base-commit controls on my PC and wrote this report. I have not reviewed the code.

@ClosetPie107

Copy link
Copy Markdown

Linux / AMD RDNA4 (RADV) test report for head 870de7d merged locally onto main 1a0bbe3 (clean merge).

Environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton v3.1 (#257 + dxil-spirv 53aac418), DXVK v3.1.1-209, DXC 1.9.2609.5, x86_64-pc-windows-gnu cross-compile

Tested (debug test binary under Wine, --test-threads=1 --nocapture)

  • gpu::shader::tests: 7 passed, 0 failed, 0 ignored, 0 skipped (0.04 s), including capture_deduplicates_across_threads_and_flushes_xbox_stats, capture_flushes_multiple_unique_console_shaders_from_worker, and capture_rejects_unreadable_pointer_without_polluting_seen.

Not tested: full workspace suite, retail title run, native Windows.

AI use: T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, 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.

5 participants