Skip to content

Recompiler: image instructions name the registers they use - #1797

Open
MiguelMachado-dev wants to merge 1 commit into
xcl-dev:mainfrom
MiguelMachado-dev:recomp/mimg-vgpr-uses
Open

MiguelMachado-dev wants to merge 1 commit into
xcl-dev:mainfrom
MiguelMachado-dev:recomp/mimg-vgpr-uses

Conversation

@MiguelMachado-dev

@MiguelMachado-dev MiguelMachado-dev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 #885. Part of #1269.

On main, these callers act on the registers:

The per-lane form in #1745 passes exactly these registers to #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 #1745.

This overlaps draft #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) #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 #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.

`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)
@Raul-Paiva

Copy link
Copy Markdown

@MiguelMachado-dev the paired xcl-smoke blocks you asked for, same title and same time (60 s) on both commits.

Tested

  • NVIDIA GeForce RTX 3070 Laptop GPU 8 GB (driver 32.0.16.2124, 32-lane waves), Intel Core i7-11800H, 32 GB RAM, Windows 10 build 19045, rustc 1.100.0, release builds.
  • Each commit was built in its own clean worktree (cargo build --release -p xcl), and scripts/smoke.ps1 was run from that worktree. On Windows PowerShell 5.1 the script's default -Xcl path fails ($PSScriptRoot is empty inside the param block), so I passed -Xcl with the worktree's target\release\xcl.exe; nothing else was changed.

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

#1797 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

The PR's run has 97.9 % of main's frames and 103.8 % of its peak commit, with no device removal or crash. 60 s on this title is the intro and menus, before the world load, so it does not reach the direct-DXIL VS path or the per-lane form this PR feeds.

Not tested: AMD, native wave64, heap windows, a longer run into the world load.

AI use: Claude Code (Claude Opus 5.5) built both commits, ran the smoke script and wrote this comment.

@alexmircea1299

Copy link
Copy Markdown

Test report on NVIDIA GeForce RTX 5070 (12 GB)

  • PR / Commit: Recompiler: image instructions name the registers they use #1797 (8ec49c0)
  • Hardware: AMD Ryzen 5 9600X, NVIDIA GeForce RTX 5070 (12 GB VRAM, driver 621.35), 32 GB DDR5 6000MT/s
  • Environment: Windows 11 (build 26300), rustc 1.100.0 (0ef1bc386 2026-11-09), Windows SDK 10.0.26100.0 (debug build)
  • Command: .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4)
  • Results: Total workspace 852 passed; 0 failed; 34 ignored (including xcl --lib and integration tests).
  • GPU tests skipped on this adapter:
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask & gpu_wave32_program_in_wave64_hardware (no wave64)
    • shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (requires Windows Developer Mode for driver cache)
    • Plus 1 integration test (no heap windows).
  • Notes: Retail title, shader pack sweep, release build, and native wave64 GPUs were not tested. Assisted by Google Gemini.

@Raghav314

Copy link
Copy Markdown

A paired run that reaches the direct DXIL path, for the gap noted in the Regression run section (the 60 s runs end in the menus). RTX 4090 24 GB (driver 617.14, 32-lane waves), Windows 11, release, XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_PRESS_A_AT=20, 180 s, network off, the same retail title for both.

Both runs go through the menus into the world load. On each, about 13 300–13 600 draws ran with translated pipelines (none skipped) and around 400 compute pipelines were built on the direct path. Presents stop at ~70 s on both, which is main's known world-load stall (#1833), not this PR. No fallback, device removal or crash on either.

main 4178e88:

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:

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

101.5 % of main's frames, 102.9 % of its peak commit.

Not tested: whether any of the changed register counts decided a translation in these runs (the log does not say which programs took the changed path), AMD.

AI use: Claude Code (Claude Opus 5.5) ran both builds and runs and wrote this comment for @Raghav314.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.

Thanks!

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.

Recompiler: VGPR tracking misses non-sequential MIMG address registers

6 participants