Skip to content

[upstream #1770] Recompiler: direct DXIL's signature dependency sets are bit masks - #362

Open
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1770
Open

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1770

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

The direct DXIL translator (xcl-dev#1426) recomputes a vertex or pixel shader's input → output dependency tables (PSV0, dx.viewIdState) from the code it emitted. compute_deps kept the input components of every value as a BTreeSet<u32>, cloned and merged at each operand of each instruction, in hash maps keyed by value. On a retail pack that was 39 % of the time its vertex and pixel shaders took to translate. This PR keeps the algorithm and makes the sets bit masks. The DXIL is byte for byte the same. Part of xcl-dev#1269.

What is in it

  • crates/xcl/src/gpu/dxil/graphics.rs, compute_deps:
    • the sets are bit masks (Comps: a u128 for components 0..128, words after that);
    • the two memo tables are indexed by instruction and by block instead of hashed;
    • the base of a pointer chain is found once per instruction (it was walked again at every instruction with two operands or more);
    • the instruction → block map, which nothing read, is gone.
      The traversal order and what is memoised are unchanged.
  • crates/xcl/src/gpu/dxil/graphics_tests.rs: a test of the set type on both sides of component 128, and a test that an input placed past row 32 reaches the dependency table. The second one passes on main too: it pins the behaviour the pack does not cover.

Tested

  • AMD Radeon RX 9070 (driver 32.0.32029.2010), Ryzen 7 9700X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2602.17. Tests in debug, measurements and regression runs in release.

  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 on 6f8cb8b: 860 passed, 0 failed, 42 ignored (SKIPPED GPU tests: heap_window_out_of_memory_falls_back_to_the_switch_form, no heap windows).

  • Same output: xcl shaders <pack> --direct --sample 0 --max-bytes 0 --dump <dir> on main c160d86 and on this commit, all 26 698 programs of a retail pack (26 229 translated, the same 469 refused in both). diff -rq of the two folders: all 52 168 files identical, 25 615 of them DXIL containers.

  • Time, same command without --dump, 8 threads, two runs each (main → this PR):

    main c160d86 this PR
    compute_deps, summed over the threads 156 s / 154 s 37.5 s / 38.0 s
    vertex + pixel shaders (14 337 programs), summed 399 s / 392 s 284 s / 288 s
    all stages, summed 801 s / 794 s 685 s / 692 s
    the whole sweep, wall clock 103.6 s / 102.7 s 89.1 s / 89.9 s

    The first three rows come from timers added to both builds for the measurement; they are not part of this PR.

Regression run

Both runs with XCL_PRESS_A_AT=10,14,18,22,26,30,34,38,42,46,50,54,58 set before scripts/smoke.ps1, so that the title takes the same path in both (in a first pair without it, a real key press reached the title at 12 s in one run and at 36 s in the other, and the runs were not comparable). The game folder is given through a junction named retail-title.

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 9070
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1290 (PresentX 1290)
presents per 2 s (last 3): 35 41 46
device removals: 0
crashes: 0
peak commit: 26128 MB

PR:

xcl-smoke v1
commit: 6f8cb8b321fb27b9bd0082486c6750b77f657448
gpu: AMD Radeon RX 9070
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1251 (PresentX 1252)
presents per 2 s (last 3): 5 32 39
device removals: 0
crashes: 0
peak commit: 26555 MB

Not tested

  • A title run with XCL_DIRECT_DXIL=all. The regression runs above use the default HLSL path, which does not send the title's shaders through compute_deps; for the changed code the evidence is the whole-pack comparison and the tests.
  • Other GPUs (NVIDIA, Intel, wave32-only). The change runs on the CPU and the containers are identical, but nothing was run there.
  • Mesh-stage entries of finish_graphics on game data: the pack's NGG programs go through the compute entry. The mesh unit tests (ms_*_parts_match_dxc) pass.
  • Signatures with rows past 32 on game data: none in the pack, only the new unit test.

Noticed while measuring, not changed here: Shader::infer_type_features takes about 39 s of the 800 s summed above (insts_use_type builds a Vec per instruction), and xcl-dev#1544 already touches that code.

AI use

  • Claude Code with Claude Fable 5.2: profiled the direct translator on the pack, wrote the change and its tests, ran the tests, the measurements and the regression runs, and wrote this description.

🤖 Generated with Claude Code


Mirror of xcl-dev#1770 (auto-synced, do not edit).

The direct translator recomputes a vertex or pixel shader's input -> output
dependency tables (PSV0, dx.viewIdState) from the code it emitted.
compute_deps kept the set of input components of every value as a
BTreeSet<u32>, cloned and merged at each operand of each instruction, in
hash maps keyed by value. On a retail pack that was 39 % of the time its
vertex and pixel shaders took to translate.

- the sets are bit masks (a u128 for components 0..128, words after that);
- the two memo tables are indexed by instruction and by block;
- the base of a pointer chain is found once per instruction, not walked
  again at every instruction with two operands or more;
- the instruction -> block map, which nothing read, is gone.

The traversal and what it memoises are unchanged, so the tables are too.

Measured on a retail pack's 26 698 programs (xcl shaders --direct
--sample 0 --max-bytes 0, 8 threads, Ryzen 7 9700X), two runs each:
- compute_deps: 156 / 154 s -> 37.5 / 38.0 s summed over the threads;
- vertex and pixel shaders (14 337 programs): 399 / 392 s -> 284 / 288 s;
- the whole sweep: 103.6 / 102.7 s -> 89.1 / 89.9 s.
The per-phase times come from timers added for the measurement, not part
of this commit. With --dump, all 52 168 files of the two builds are
identical (25 615 DXIL containers).

Part of xcl-dev#1269.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants