Skip to content

[upstream #1797] Recompiler: image instructions name the registers they use - #338

Open
ufoptg wants to merge 3 commits into
mainfrom
upstream-pr/1797
Open

ufoptg wants to merge 3 commits into
mainfrom
upstream-pr/1797

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

rdna2::vgpr_uses took an image instruction's registers from the operand tables, which give the largest case: a 3-D address with every modifier, and four data registers. That gets several things wrong:

  • it misses the addresses in the NSA dwords (VADDRA, VADDRB, …);
  • it misses a compare-swap's compare value (VDATA + 1);
  • it takes a G16 sample's address as shorter than what the translators read;
  • it counts an atomic's data as written only, and as written even without GLC;
  • it claims data registers that DMASK and D16 leave alone.

It now counts what recomp::emit and dxil::lower_image read. Fixes xcl-dev#885. Part of xcl-dev#1269.

On main, these callers act on the registers:

The per-lane form in xcl-dev#1745 passes exactly these registers to xcl-dev#1426's lowering, so without this it refuses every image instruction with NSA addresses. The per-lane tests are a follow-up on top of xcl-dev#1745.

This overlaps draft xcl-dev#886 (also Fixes #885), which counts every encoded NSA byte, padding included, and leaves the data registers as they are. This PR counts the address dwords and the data registers exactly, and its tests cover NSA1, NSA2, NSA3 and the v255 bound.

What is in it

  • Recompiler: image instructions name the registers they use
    • crates/xcl/src/gpu/rdna2.rs: mimg_vgpr_uses and mimg_address_dwords, and the tests image_register_uses and image_address_counts_reach_the_operand_tables.
    • crates/xcl/src/gpu/dxil/lower_image.rs: an atomic reads VDATA + 1 for a compare-swap only.
    • Size: runtime +80/−2, tests +77.

Tested

  • Setup:

    • NVIDIA GeForce RTX 5080, driver 621.24 (no wave64), Intel Core i7-14700KF
    • Windows 11 build 26300, rustc 1.97.1, DXC 1.8.2502.11, debug build
  • cargo build --workspace && cargo test --workspace -- --test-threads=4:

    • at 8ec49c0: 893 passed, 0 failed, 42 ignored (lib: 844 / 0 / 22);
    • at main 4178e88: 891 passed, 0 failed, 42 ignored (lib: 842 / 0 / 22).
    • The difference is the two new tests.
  • SKIPPED GPU tests, the same 4 on both runs:

    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
    • heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
    • shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required)
  • image_register_uses fails without the change. For a 2-D load with DMASK 0x5, it gets ([3, 4, 5, 6], [14, 15, 16, 17]) where ([3, 4], [14, 15]) is expected.

  • image_address_counts_reach_the_operand_tables checks the address count of every image instruction against the operand tables.

  • On Recompiler: a per-lane form for the direct DXIL backend (XCL_PER_LANE) xcl-dev/xcl#1745's per-lane form (at 3ca3633), a sweep sent every IMAGE_* instruction through the per-lane compute lowering, over DIM, A16, D16, DMASK, GLC and sequential or scattered NSA addresses:

    • before the change, 6562 of 28032 cases were refused for a register not passed (6130 NSA, 288 compare-swap, 144 G16);
    • after it, none, and no case that lowered before is refused.

    The follow-up's GPU tests compare loads and samples with NSA and sequential addresses, D16, a store, a gather, resinfo, GLC atomics and BVH with NSA addresses against the HLSL path.

Regression run

  • Run by Raul-Paiva (comment):
    • NVIDIA GeForce RTX 3070 Laptop GPU, driver 32.0.16.2124, Intel Core i7-11800H, Windows 10 build 19045
    • rustc 1.100.0, release builds, each commit in its own clean worktree
    • scripts/smoke.ps1 with -Xcl pointing at that worktree's xcl.exe
  • The PR's run has 97.9 % of main's frames and 103.8 % of its peak commit, with no device removal or crash.
  • The 60 s cover the intro and menus, before the world load, so they do not reach the direct DXIL VS path.

main 4178e88:

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: NVIDIA GeForce RTX 3070 Laptop GPU
title: xbox-title
seconds: 60
exit: 0x0
frames shown: 1444 (PresentX 1444)
presents per 2 s (last 3): 58 54 49
device removals: 0
crashes: 0
peak commit: 17667 MB

This PR's head 8ec49c0:

xcl-smoke v1
commit: 8ec49c0e1374f72875cdff6984dcbf77d3439f6b
gpu: NVIDIA GeForce RTX 3070 Laptop GPU
title: xbox-title
seconds: 60
exit: 0x0
frames shown: 1413 (PresentX 1413)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18334 MB
  • A second pair, by Raghav314 (comment):
    • NVIDIA GeForce RTX 4090, driver 617.14, Windows 11, release builds
    • 180 s with XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_PRESS_A_AT=20, network off
  • This run goes through the menus into the world load on both commits:
    • about 13 300–13 600 draws with translated pipelines (none skipped);
    • around 400 compute pipelines built on the direct path;
    • no fallback, device removal or crash.
  • The PR's run has 101.5 % of main's frames and 102.9 % of its peak commit.

main 4178e88, 180 s:

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 180
exit: 0x0
frames shown: 1512 (PresentX 1512)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31808 MB

This PR's head 8ec49c0, 180 s:

xcl-smoke v1
commit: 8ec49c0e1374f72875cdff6984dcbf77d3439f6b
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 180
exit: 0x0
frames shown: 1535 (PresentX 1535)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 32731 MB

Not tested

  • Whether any of the changed register counts decided a translation in the 180 s runs: the log does not say which programs took the changed path. In both runs the presents stop at about 70 s, at main's world-load stall (Roadmap: retail title past world load xcl-dev/xcl#1833).
  • The main-side effects listed above come from reading the code, not from a run. I have no title with a VS that reads its inputs only as NSA addresses, or with a movrel past them.
  • AMD, wave64, heap windows (this adapter has none), and a release build.
  • Not changed here, but kept by the tests:
    • G16: both translators read the derivatives as 32-bit, while the ISA packs them in 16-bit pairs.
    • vgpr_uses follows the translators, and image_address_counts_reach_the_operand_tables pins the difference.

AI use

  • Claude Code (Claude Opus 5.5, xhigh) found the cause, wrote the change, the tests and this description, and ran the tests above.

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

raylitebull and others added 3 commits November 24, 2026 21:05
…-oom

dxil: eliminate giant-shader IR and CFG blowup in FormatLoad and multi-window memory
`vgpr_uses` took an image instruction's registers from the operand tables,
which give the largest case: a 3-D address with every modifier and four data
registers. It missed the addresses in the NSA dwords (VADDRA, VADDRB, ...) and
a compare-swap's compare value (VDATA + 1), took a G16 sample's address as
shorter than the translators read it, took an atomic's data as written only
(and written without GLC too), and claimed data registers that DMASK and D16
leave alone.

Its callers act on those registers: the direct DXIL VS sets up the initial
VGPRs it lists (vertex and instance id, fetched attributes), the HLSL path
bounds its movrel switches with them, `xcl shaders` reports the inputs a
program reads from them, and the per-lane form of xcl-dev#1745 passes exactly them
to xcl-dev#1426's lowering, which refuses an instruction that reads another: every
image instruction with NSA addresses.

`vgpr_uses` now counts them as `recomp::emit` and `dxil::lower_image` read
them: the address dwords from the opcode's modifiers, DIM and A16, at VADDR
and the registers after it or VADDR then the NSA bytes; the data from DMASK,
D16, TFE/LWE, GLC and the opcode. `dxil::lower_image` read VDATA + 1 for every
atomic; it reads it for a compare-swap only now.

In xcl-dev#1745's per-lane form (at 3ca3633), a sweep of every IMAGE_* instruction
over DIM, A16, D16, DMASK, GLC and sequential or scattered NSA addresses
through the per-lane compute lowering: 6562 of 28032 cases refused for a
register not passed before (6130 NSA, 288 compare-swap, 144 G16), none after,
and no case that lowered before refused.

Assisted-by: Claude Code (Claude Opus 5.5, xhigh)
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.

Recompiler: VGPR tracking misses non-sequential MIMG address registers

3 participants