Recompiler: image instructions name the registers they use #1787

Closed
MiguelMachado-dev wants to merge 1 commit from upstream-pr/1797 into main
MiguelMachado-dev commented 2026-11-24 20:52:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MiguelMachado-dev on 2026-11-24T20:52:26Z.


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 direct DXIL VS sets up only the initial VGPRs it lists: vertex and instance id, and the fetched attributes (dxil/kernel.rs → setup_vertex).
  • The HLSL path bounds its movrel switches with them (max_vgpr, as #885 describes).
  • xcl shaders reports a program's inputs from them.

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 #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 (#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.
<!-- greyfinch-sync:ivall/xcl:issue:5480131330 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797). Originally posted by [MiguelMachado-dev](https://github.com/MiguelMachado-dev) on 2026-11-24T20:52:26Z. --- `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 direct DXIL VS sets up only the initial VGPRs it lists: vertex and instance id, and the fetched attributes (`dxil/kernel.rs` → `setup_vertex`). - The HLSL path bounds its movrel switches with them (`max_vgpr`, as #885 describes). - `xcl shaders` reports a program's inputs from them. 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 #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](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7144492591)): - 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](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7145968922)): - 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 (#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.
Raul-Paiva commented 2026-11-24 21:09:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Raul-Paiva on 2026-11-24T21:06:49Z.


@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.

<!-- greyfinch-sync:ivall/xcl:comment:7144492591 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7144492591). Originally posted by [Raul-Paiva](https://github.com/Raul-Paiva) on 2026-11-24T21:06:49Z. --- @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 commented 2026-11-24 21:30:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by alexmircea1299 on 2026-11-24T21:30:05Z.


Test report on NVIDIA GeForce RTX 5070 (12 GB)

  • PR / Commit: #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.
<!-- greyfinch-sync:ivall/xcl:comment:7145012737 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7145012737). Originally posted by [alexmircea1299](https://github.com/alexmircea1299) on 2026-11-24T21:30:05Z. --- **Test report on NVIDIA GeForce RTX 5070 (12 GB)** * **PR / Commit:** #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 commented 2026-11-24 23:08:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Raghav314 on 2026-11-24T22:13:48Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7145968922 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7145968922). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-11-24T22:13:48Z. --- 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 commented 2026-11-25 00:09:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T00:04:57Z.


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

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

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7148118064 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7148118064). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T00:04:57Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. Thanks!
throny commented 2026-11-25 16:12:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-25T15:33:28Z.


Two contributors checked independently and found that #886 #2287 solves the same problem (for #885) in a different way: #1607, group D81. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

<!-- greyfinch-sync:ivall/xcl:comment:7167027056 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7167027056). Originally posted by [throny](https://github.com/throny) on 2026-11-25T15:33:28Z. --- <!-- xcl-1607-hint:D81 --> Two contributors checked independently and found that #886 #2287 solves the same problem (for #885) in a different way: #1607, group D81. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Chrysana commented 2026-11-25 20:08:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Chrysana on 2026-11-25T19:53:29Z.


AMD results for this change, for "AMD, wave64, heap windows" under Not tested. They come from my run of #1825 (comment), whose head carries this PR's commit (c2b0c00, the same patch as 8ec49c0: git patch-id --stable matches). I didn't run 8ec49c0 on its own base. On an RX 9070 XT (RDNA4, wave64) and an RDNA2 iGPU, both new tests pass, the per-lane image tests that depend on this change pass on both GPUs, and nothing fails in the full suite.

Setup: AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008; Ryzen 7 9800X3D with its RDNA2 Radeon iGPU (XCL_ADAPTER=1); Windows 11 26200.9974, rustc 1.100.0 MSVC, debug. #1825's head 434f428 on c4d37be, and that base alone, each in its own checkout and target folder.

  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 (RX 9070 XT): 965 passed, 0 failed, 43 ignored with this commit and #1825's tests, against 959 / 0 / 43 on c4d37be. The difference is the six tests: two here, four in #1825.
  • gpu::rdna2::tests::image_register_uses and image_address_counts_reach_the_operand_tables: ok on both GPUs (gpu::rdna2:: 11 passed on each).
  • Two of the four tests your RTX 5080 skips run on this card: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware both pass. Neither is changed by this PR, so that only shows the wave64 side of the base is fine here.
  • The tests that need this change, #1825's per_lane_image_instructions_agree_with_the_hlsl_path_on_the_gpu and a_per_lane_bvh_with_nsa_addresses_runs_on_the_gpu (NSA and sequential addresses, D16, compare-swap, BVH with NSA), pass on both GPUs. They run their programs as wave32, so they don't cover wave64 image instructions.
  • heap_window_out_of_memory_falls_back_to_the_switch_form is SKIPPED here too (no heap windows).

Not tested

  • 8ec49c0 on its own base 4178e88, or merged onto current main.
  • Heap windows; image instructions in wave64 programs; a smoke pair (#1797 already has Raul-Paiva's).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests (in the #1825 run), checked that the two commits carry the same patch, and drafted this comment. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7172904800 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7172904800). Originally posted by [Chrysana](https://github.com/Chrysana) on 2026-11-25T19:53:29Z. --- AMD results for this change, for "AMD, wave64, heap windows" under **Not tested**. They come from my run of #1825 ([comment](https://github.com/xcl-dev/xcl/pull/1825#issuecomment-7172404663)), whose head carries this PR's commit (`c2b0c00`, the same patch as `8ec49c0`: `git patch-id --stable` matches). I didn't run `8ec49c0` on its own base. **On an RX 9070 XT (RDNA4, wave64) and an RDNA2 iGPU, both new tests pass, the per-lane image tests that depend on this change pass on both GPUs, and nothing fails in the full suite.** **Setup:** AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008; Ryzen 7 9800X3D with its RDNA2 Radeon iGPU (`XCL_ADAPTER=1`); Windows 11 26200.9974, rustc 1.100.0 MSVC, debug. #1825's head `434f428` on `c4d37be`, and that base alone, each in its own checkout and target folder. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4` (RX 9070 XT): **965 passed, 0 failed, 43 ignored** with this commit and #1825's tests, against 959 / 0 / 43 on `c4d37be`. The difference is the six tests: two here, four in #1825. - `gpu::rdna2::tests::image_register_uses` and `image_address_counts_reach_the_operand_tables`: ok on both GPUs (`gpu::rdna2::` 11 passed on each). - Two of the four tests your RTX 5080 skips run on this card: `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` both pass. Neither is changed by this PR, so that only shows the wave64 side of the base is fine here. - The tests that need this change, #1825's `per_lane_image_instructions_agree_with_the_hlsl_path_on_the_gpu` and `a_per_lane_bvh_with_nsa_addresses_runs_on_the_gpu` (NSA and sequential addresses, D16, compare-swap, BVH with NSA), pass on both GPUs. They run their programs as wave32, so they don't cover wave64 image instructions. - `heap_window_out_of_memory_falls_back_to_the_switch_form` is SKIPPED here too (no heap windows). **Not tested** - `8ec49c0` on its own base `4178e88`, or merged onto current `main`. - Heap windows; image instructions in wave64 programs; a smoke pair (#1797 already has Raul-Paiva's). **AI use** - Claude Code (Claude Opus 5.5) ran the tests (in the #1825 run), checked that the two commits carry the same patch, and drafted this comment. I checked it before posting.
bmjask commented 2026-11-25 21:25:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T21:25:47Z.

Review: COMMENTED


No confirmed source blocker. Image VGPR-use tracking aligns with HLSL/Direct-DXIL operands including NSA/compare-swap; focused and later AMD/wave64 evidence is strong. This dirty/non-mergeable head needs rebase/current Windows CI and resolution/consolidation with overlapping #886/#2287 before merge. Residual gaps: Direct-DXIL graphics execution and heap-window/native-wave64 title validation; retain documented G16 packing limitation.

<!-- greyfinch-sync:ivall/xcl:review:6065197246 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#pullrequestreview-6065197246). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T21:25:47Z. **Review:** COMMENTED --- No confirmed source blocker. Image VGPR-use tracking aligns with HLSL/Direct-DXIL operands including NSA/compare-swap; focused and later AMD/wave64 evidence is strong. This dirty/non-mergeable head needs rebase/current Windows CI and resolution/consolidation with overlapping #886/#2287 before merge. Residual gaps: Direct-DXIL graphics execution and heap-window/native-wave64 title validation; retain documented G16 packing limitation.
upstream-sync closed this pull request 2026-11-25 23:07:43 +00:00
CalvyPZ commented 2026-11-25 23:09:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CalvyPZ on 2026-11-25T22:37:34Z.


This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.

<!-- greyfinch-sync:ivall/xcl:comment:7176594136 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7176594136). Originally posted by [CalvyPZ](https://github.com/CalvyPZ) on 2026-11-25T22:37:34Z. --- This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.
upstream-sync reopened this pull request 2026-11-26 00:04:38 +00:00
thehollowedone commented 2026-11-27 11:25:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-27T11:25:51Z.


I prepared a local rebase of #1797 head 8ec49c0 onto current main 623d02e4, then placed the unchanged #1825 test commit on top. This is an unpublished local candidate, not a new PR head. The compact conflict-resolution diff below preserves main's newer 64-bit and floating-point image atomic handling while adding #1797's exact register accounting. It also makes the existing D16 RESINFO sentinel test explicitly read its trailing VGPRs; no assertion is relaxed.

The corrected image_register_uses test is red on clean main (0 passed, 1 failed; the 2D DMASK 0x5 case counts four inputs/outputs where two are expected) and green on the rebased stack. Astra independently traced the 32/64-bit atomic and D16 paths and found the scoped resolution consistent with their callers.

Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, DXC 1.8.2502.11, isolated writable DXIL cache per revision. cargo build --workspace passed. cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: clean main 1,458 passed / 0 failed / 47 ignored; local #1797 + #1825 stack 1,464 passed / 0 failed / 47 ignored. Both runs logged 25 GPU skips (21 no wave64, three existing per-lane f16/packed refusals, one no heap windows); the stock #1825 GPU image and BVH tests ran and passed. The extra six passes are the two parent and four child tests. A clean-head retail smoke pair and CI on an updated PR head remain to be done after the author pushes a rebase; these local counts do not satisfy that PR gate.

Compact rebase resolution diff against the cherry-pick conflict
diff --git a/crates/xcl/src/gpu/dxil/lower_image.rs b/crates/xcl/src/gpu/dxil/lower_image.rs
index c366666f..a1de59f6 100644
--- a/crates/xcl/src/gpu/dxil/lower_image.rs
+++ b/crates/xcl/src/gpu/dxil/lower_image.rs
@@ -1575,7 +1575,8 @@ impl Lw {
                 if wide64 {
                     return self.mimg_atomic64(d, opn, &ic, tw0, lkind, vdata, glc, run);
                 }
-                let (v, cmpv) = (self.vreg(vdata), self.vreg(vdata + 1));
+                let v = self.vreg(vdata);
+                let cmpv = if is_cmpswap { self.vreg(vdata + 1) } else { v };
                 let ui = self.addc(tw0, 1);
                 let signed = opn == "smin" || opn == "smax";
                 let ct = if signed { CompType::I32 } else { CompType::U32 };
diff --git a/crates/xcl/src/gpu/dxil/msaa_tests.rs b/crates/xcl/src/gpu/dxil/msaa_tests.rs
index d39bd978..20f76e7c 100644
--- a/crates/xcl/src/gpu/dxil/msaa_tests.rs
+++ b/crates/xcl/src/gpu/dxil/msaa_tests.rs
@@ -311,6 +311,10 @@ fn gpu_direct_image_get_resinfo_d16() {
     // T# 0: 2D 64x32 R32_UINT (s[16:23], SRSRC 4); T# 1: 2D MSAA array 4x4x3 (s[24:31], SRSRC 6)
     code.extend(mimg("IMAGE_GET_RESINFO", &[("VDATA", 0), ("VADDR", 10), ("SRSRC", 4), ("DMASK", 0xF), ("DIM", 1), ("D16", 1)]));
     code.extend(mimg("IMAGE_GET_RESINFO", &[("VDATA", 4), ("VADDR", 10), ("SRSRC", 6), ("DMASK", 0xF), ("DIM", 7), ("D16", 1)]));
+    // The runner only records registers the program uses. Read the sentinels so they are visible.
+    for reg in [2, 3, 6, 7] {
+        code.extend(encode("V_MOV_B32", "ENC_VOP1", &[("VDST", reg), ("SRC0", 256 + reg)], None).unwrap());
+    }
     code.extend(encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap());
     if !gpu_ready() {
         return;
diff --git a/crates/xcl/src/gpu/rdna2.rs b/crates/xcl/src/gpu/rdna2.rs
index 53a34646..ad62a8a6 100644
--- a/crates/xcl/src/gpu/rdna2.rs
+++ b/crates/xcl/src/gpu/rdna2.rs
@@ -590,12 +590,13 @@ pub fn vgpr_uses(d: &Decoded) -> (Vec<u64>, Vec<u64>) {
 /// largest case: four data registers, the address of a 3-D sample with every modifier). The
 /// address is VADDR and the registers after it, or with NSA VADDR then one register per byte of
 /// the extra dwords (VADDRA, VADDRB, …). The data: the DMASK components (D16: two per register),
-/// four for a gather and for BVH; an atomic reads its data (a compare-swap two registers: the
-/// new value, then the compare value) and with GLC gets the value before back in the first.
+/// four for a gather and for BVH. An atomic reads one value, followed by the compare value
+/// for compare-swap. Each value uses one or two registers. With GLC the previous value is
+/// written to the registers that held the new value.
 fn mimg_vgpr_uses(d: &Decoded) -> (Vec<u64>, Vec<u64>) {
     let f = |n: &str| field_value(d.enc, &d.words, n).unwrap_or(0);
     let name = d.inst.name;
-    let (vaddr, n) = (f("VADDR"), mimg_address_dwords(d));
+    let (vaddr, n) = (f("VADDR"), mimg_lowered_address_dwords(d));
     let mut r: Vec<u64> = match f("NSA") {
         0 => (vaddr..vaddr + n).collect(),
         nsa => {
@@ -603,17 +604,18 @@ fn mimg_vgpr_uses(d: &Decoded) -> (Vec<u64>, Vec<u64>) {
             std::iter::once(vaddr).chain(extra).collect()
         }
     };
-    let dmask = (f("DMASK").count_ones() as u64).max(1);
+    let dmask = f("DMASK").count_ones() as u64;
     let (reads, writes) = if name.starts_with("IMAGE_BVH") {
         (0, 4)
     } else if name.starts_with("IMAGE_ATOMIC") {
         let cmpswap = name.contains("CMPSWAP");
-        let n = if cmpswap { dmask.max(2) } else { dmask };
-        let back = if cmpswap { n / 2 } else { n };
-        (n, if f("GLC") == 1 { back } else { 0 })
+        let wide_dmask_count = if cmpswap { 4 } else { 2 };
+        let width = if dmask == wide_dmask_count { 2 } else { 1 };
+        let reads = if cmpswap { 2 * width } else { width };
+        (reads, if f("GLC") == 1 { width } else { 0 })
     } else {
-        let n = if name.starts_with("IMAGE_GATHER") || name == "IMAGE_MSAA_LOAD" { 4 } else { dmask };
-        let n = if f("D16") == 1 && name != "IMAGE_GET_RESINFO" { n.div_ceil(2) } else { n };
+        let n = if name.starts_with("IMAGE_GATHER") || name == "IMAGE_MSAA_LOAD" { 4 } else { dmask.max(1) };
+        let n = if f("D16") == 1 { n.div_ceil(2) } else { n };
         if name.starts_with("IMAGE_STORE") { (n, 0) } else { (0, n + (f("TFE") | f("LWE"))) }
     };
     let vdata = f("VDATA");
@@ -626,7 +628,7 @@ fn mimg_vgpr_uses(d: &Decoded) -> (Vec<u64>, Vec<u64>) {
 /// `dxil::lower_image` read them: offset, bias, z-compare, derivatives, the DIM's coordinates,
 /// then LOD (or mip level) and clamp. With A16 the 16-bit components pair up in dwords; the
 /// offset, z-compare and derivatives stay 32-bit.
-fn mimg_address_dwords(d: &Decoded) -> u64 {
+fn mimg_lowered_address_dwords(d: &Decoded) -> u64 {
     let f = |n: &str| field_value(d.enc, &d.words, n).unwrap_or(0);
     let (name, a16) = (d.inst.name, f("A16") == 1);
     match name {
@@ -1167,6 +1169,7 @@ mod tests {
         let d16 = [("VDATA", 20), ("VADDR", 30), ("DMASK", 0x7), ("DIM", 1), ("D16", 1)];
         assert_eq!(uses("IMAGE_SAMPLE_LZ", &d16, &[]).1, at(20, 2));
         assert_eq!(uses("IMAGE_STORE", &d16, &[]), (vec![30, 31, 20, 21], vec![]));
+        assert_eq!(uses("IMAGE_GET_RESINFO", &d16, &[]), (vec![30], at(20, 2)));
         assert_eq!(uses("IMAGE_GATHER4_LZ", &[("VDATA", 40), ("VADDR", 33), ("DMASK", 0x1), ("DIM", 1)], &[]).1, at(40, 4));
         // atomics read their data and give the value before back with GLC only; a compare-swap
         // reads the new value and the compare value
@@ -1175,6 +1178,8 @@ mod tests {
         assert_eq!(uses("IMAGE_ATOMIC_ADD", &atomic(1, 0x1), &[]), (vec![35, 36, 7], vec![7]));
         assert_eq!(uses("IMAGE_ATOMIC_CMPSWAP", &atomic(1, 0x3), &[60]), (vec![35, 60, 7, 8], vec![7]));
         assert!(uses("IMAGE_ATOMIC_CMPSWAP", &atomic(0, 0x3), &[]).1.is_empty());
+        assert_eq!(uses("IMAGE_ATOMIC_ADD", &atomic(1, 0x3), &[]), (vec![35, 36, 7, 8], at(7, 2)));
+        assert_eq!(uses("IMAGE_ATOMIC_CMPSWAP", &atomic(1, 0xF), &[]), (vec![35, 36, 7, 8, 9, 10], at(7, 2)));
         // no register past v255
         assert_eq!(uses("IMAGE_SAMPLE_LZ", &[("VDATA", 254), ("VADDR", 255), ("DMASK", 0xF), ("DIM", 1)], &[]), (vec![255], vec![254, 255]));
     }
@@ -1187,7 +1192,7 @@ mod tests {
     fn image_address_counts_reach_the_operand_tables() {
         for inst in all_instructions().filter(|i| i.encs.iter().any(|e| ENCODINGS[e.encoding as usize].name == "ENC_MIMG")) {
             let size = inst.encs[0].operands.iter().find(|o| o.field == Some("VADDR")).unwrap().size as u64 / 32;
-            let most = (0..6).map(|dim| mimg_address_dwords(&mimg(inst.name, &[("DIM", dim)], &[]))).max().unwrap();
+            let most = (0..6).map(|dim| mimg_lowered_address_dwords(&mimg(inst.name, &[("DIM", dim)], &[]))).max().unwrap();
             let sampling = inst.name.starts_with("IMAGE_SAMPLE") || inst.name.starts_with("IMAGE_GATHER") || inst.name.starts_with("IMAGE_BVH");
             if inst.name.ends_with("_G16") {
                 assert!(most > size, "{}: {most} against {size}", inst.name);

The child tests in #1825 only need placement after this parent; I will leave that short note there. AI use: Codex (GPT-6.2 Sol) resolved the integration and ran the builds and tests; Codex (GPT-6.2 Astra) reviewed the image register and D16 behavior.

<!-- greyfinch-sync:ivall/xcl:comment:7217064441 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7217064441). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-27T11:25:51Z. --- I prepared a local rebase of [#1797 head `8ec49c0`](https://github.com/xcl-dev/xcl/commit/8ec49c0e1374f72875cdff6984dcbf77d3439f6b) onto current [`main` `623d02e4`](https://github.com/xcl-dev/xcl/commit/623d02e465a17497a757a4ce867f482b0a6c8f3b), then placed the unchanged #1825 test commit on top. This is an **unpublished local candidate**, not a new PR head. The compact conflict-resolution diff below preserves main's newer 64-bit and floating-point image atomic handling while adding #1797's exact register accounting. It also makes the existing D16 RESINFO sentinel test explicitly read its trailing VGPRs; no assertion is relaxed. The corrected `image_register_uses` test is red on clean main (0 passed, 1 failed; the 2D DMASK 0x5 case counts four inputs/outputs where two are expected) and green on the rebased stack. Astra independently traced the 32/64-bit atomic and D16 paths and found the scoped resolution consistent with their callers. Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, DXC 1.8.2502.11, isolated writable DXIL cache per revision. `cargo build --workspace` passed. `cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture`: **clean main 1,458 passed / 0 failed / 47 ignored; local #1797 + #1825 stack 1,464 passed / 0 failed / 47 ignored**. Both runs logged 25 GPU skips (21 no wave64, three existing per-lane f16/packed refusals, one no heap windows); the stock #1825 GPU image and BVH tests ran and passed. The extra six passes are the two parent and four child tests. A clean-head retail smoke pair and CI on an updated PR head remain to be done after the author pushes a rebase; these local counts do not satisfy that PR gate. <details><summary>Compact rebase resolution diff against the cherry-pick conflict</summary> ```diff diff --git a/crates/xcl/src/gpu/dxil/lower_image.rs b/crates/xcl/src/gpu/dxil/lower_image.rs index c366666f..a1de59f6 100644 --- a/crates/xcl/src/gpu/dxil/lower_image.rs +++ b/crates/xcl/src/gpu/dxil/lower_image.rs @@ -1575,7 +1575,8 @@ impl Lw { if wide64 { return self.mimg_atomic64(d, opn, &ic, tw0, lkind, vdata, glc, run); } - let (v, cmpv) = (self.vreg(vdata), self.vreg(vdata + 1)); + let v = self.vreg(vdata); + let cmpv = if is_cmpswap { self.vreg(vdata + 1) } else { v }; let ui = self.addc(tw0, 1); let signed = opn == "smin" || opn == "smax"; let ct = if signed { CompType::I32 } else { CompType::U32 }; diff --git a/crates/xcl/src/gpu/dxil/msaa_tests.rs b/crates/xcl/src/gpu/dxil/msaa_tests.rs index d39bd978..20f76e7c 100644 --- a/crates/xcl/src/gpu/dxil/msaa_tests.rs +++ b/crates/xcl/src/gpu/dxil/msaa_tests.rs @@ -311,6 +311,10 @@ fn gpu_direct_image_get_resinfo_d16() { // T# 0: 2D 64x32 R32_UINT (s[16:23], SRSRC 4); T# 1: 2D MSAA array 4x4x3 (s[24:31], SRSRC 6) code.extend(mimg("IMAGE_GET_RESINFO", &[("VDATA", 0), ("VADDR", 10), ("SRSRC", 4), ("DMASK", 0xF), ("DIM", 1), ("D16", 1)])); code.extend(mimg("IMAGE_GET_RESINFO", &[("VDATA", 4), ("VADDR", 10), ("SRSRC", 6), ("DMASK", 0xF), ("DIM", 7), ("D16", 1)])); + // The runner only records registers the program uses. Read the sentinels so they are visible. + for reg in [2, 3, 6, 7] { + code.extend(encode("V_MOV_B32", "ENC_VOP1", &[("VDST", reg), ("SRC0", 256 + reg)], None).unwrap()); + } code.extend(encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap()); if !gpu_ready() { return; diff --git a/crates/xcl/src/gpu/rdna2.rs b/crates/xcl/src/gpu/rdna2.rs index 53a34646..ad62a8a6 100644 --- a/crates/xcl/src/gpu/rdna2.rs +++ b/crates/xcl/src/gpu/rdna2.rs @@ -590,12 +590,13 @@ pub fn vgpr_uses(d: &Decoded) -> (Vec<u64>, Vec<u64>) { /// largest case: four data registers, the address of a 3-D sample with every modifier). The /// address is VADDR and the registers after it, or with NSA VADDR then one register per byte of /// the extra dwords (VADDRA, VADDRB, …). The data: the DMASK components (D16: two per register), -/// four for a gather and for BVH; an atomic reads its data (a compare-swap two registers: the -/// new value, then the compare value) and with GLC gets the value before back in the first. +/// four for a gather and for BVH. An atomic reads one value, followed by the compare value +/// for compare-swap. Each value uses one or two registers. With GLC the previous value is +/// written to the registers that held the new value. fn mimg_vgpr_uses(d: &Decoded) -> (Vec<u64>, Vec<u64>) { let f = |n: &str| field_value(d.enc, &d.words, n).unwrap_or(0); let name = d.inst.name; - let (vaddr, n) = (f("VADDR"), mimg_address_dwords(d)); + let (vaddr, n) = (f("VADDR"), mimg_lowered_address_dwords(d)); let mut r: Vec<u64> = match f("NSA") { 0 => (vaddr..vaddr + n).collect(), nsa => { @@ -603,17 +604,18 @@ fn mimg_vgpr_uses(d: &Decoded) -> (Vec<u64>, Vec<u64>) { std::iter::once(vaddr).chain(extra).collect() } }; - let dmask = (f("DMASK").count_ones() as u64).max(1); + let dmask = f("DMASK").count_ones() as u64; let (reads, writes) = if name.starts_with("IMAGE_BVH") { (0, 4) } else if name.starts_with("IMAGE_ATOMIC") { let cmpswap = name.contains("CMPSWAP"); - let n = if cmpswap { dmask.max(2) } else { dmask }; - let back = if cmpswap { n / 2 } else { n }; - (n, if f("GLC") == 1 { back } else { 0 }) + let wide_dmask_count = if cmpswap { 4 } else { 2 }; + let width = if dmask == wide_dmask_count { 2 } else { 1 }; + let reads = if cmpswap { 2 * width } else { width }; + (reads, if f("GLC") == 1 { width } else { 0 }) } else { - let n = if name.starts_with("IMAGE_GATHER") || name == "IMAGE_MSAA_LOAD" { 4 } else { dmask }; - let n = if f("D16") == 1 && name != "IMAGE_GET_RESINFO" { n.div_ceil(2) } else { n }; + let n = if name.starts_with("IMAGE_GATHER") || name == "IMAGE_MSAA_LOAD" { 4 } else { dmask.max(1) }; + let n = if f("D16") == 1 { n.div_ceil(2) } else { n }; if name.starts_with("IMAGE_STORE") { (n, 0) } else { (0, n + (f("TFE") | f("LWE"))) } }; let vdata = f("VDATA"); @@ -626,7 +628,7 @@ fn mimg_vgpr_uses(d: &Decoded) -> (Vec<u64>, Vec<u64>) { /// `dxil::lower_image` read them: offset, bias, z-compare, derivatives, the DIM's coordinates, /// then LOD (or mip level) and clamp. With A16 the 16-bit components pair up in dwords; the /// offset, z-compare and derivatives stay 32-bit. -fn mimg_address_dwords(d: &Decoded) -> u64 { +fn mimg_lowered_address_dwords(d: &Decoded) -> u64 { let f = |n: &str| field_value(d.enc, &d.words, n).unwrap_or(0); let (name, a16) = (d.inst.name, f("A16") == 1); match name { @@ -1167,6 +1169,7 @@ mod tests { let d16 = [("VDATA", 20), ("VADDR", 30), ("DMASK", 0x7), ("DIM", 1), ("D16", 1)]; assert_eq!(uses("IMAGE_SAMPLE_LZ", &d16, &[]).1, at(20, 2)); assert_eq!(uses("IMAGE_STORE", &d16, &[]), (vec![30, 31, 20, 21], vec![])); + assert_eq!(uses("IMAGE_GET_RESINFO", &d16, &[]), (vec![30], at(20, 2))); assert_eq!(uses("IMAGE_GATHER4_LZ", &[("VDATA", 40), ("VADDR", 33), ("DMASK", 0x1), ("DIM", 1)], &[]).1, at(40, 4)); // atomics read their data and give the value before back with GLC only; a compare-swap // reads the new value and the compare value @@ -1175,6 +1178,8 @@ mod tests { assert_eq!(uses("IMAGE_ATOMIC_ADD", &atomic(1, 0x1), &[]), (vec![35, 36, 7], vec![7])); assert_eq!(uses("IMAGE_ATOMIC_CMPSWAP", &atomic(1, 0x3), &[60]), (vec![35, 60, 7, 8], vec![7])); assert!(uses("IMAGE_ATOMIC_CMPSWAP", &atomic(0, 0x3), &[]).1.is_empty()); + assert_eq!(uses("IMAGE_ATOMIC_ADD", &atomic(1, 0x3), &[]), (vec![35, 36, 7, 8], at(7, 2))); + assert_eq!(uses("IMAGE_ATOMIC_CMPSWAP", &atomic(1, 0xF), &[]), (vec![35, 36, 7, 8, 9, 10], at(7, 2))); // no register past v255 assert_eq!(uses("IMAGE_SAMPLE_LZ", &[("VDATA", 254), ("VADDR", 255), ("DMASK", 0xF), ("DIM", 1)], &[]), (vec![255], vec![254, 255])); } @@ -1187,7 +1192,7 @@ mod tests { fn image_address_counts_reach_the_operand_tables() { for inst in all_instructions().filter(|i| i.encs.iter().any(|e| ENCODINGS[e.encoding as usize].name == "ENC_MIMG")) { let size = inst.encs[0].operands.iter().find(|o| o.field == Some("VADDR")).unwrap().size as u64 / 32; - let most = (0..6).map(|dim| mimg_address_dwords(&mimg(inst.name, &[("DIM", dim)], &[]))).max().unwrap(); + let most = (0..6).map(|dim| mimg_lowered_address_dwords(&mimg(inst.name, &[("DIM", dim)], &[]))).max().unwrap(); let sampling = inst.name.starts_with("IMAGE_SAMPLE") || inst.name.starts_with("IMAGE_GATHER") || inst.name.starts_with("IMAGE_BVH"); if inst.name.ends_with("_G16") { assert!(most > size, "{}: {most} against {size}", inst.name); ``` </details> The child tests in #1825 only need placement after this parent; I will leave that short note there. AI use: Codex (GPT-6.2 Sol) resolved the integration and ran the builds and tests; Codex (GPT-6.2 Astra) reviewed the image register and D16 behavior.
Foniass commented 2026-12-01 06:49:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:49:11Z.


Triage (#1607) – head 8ec49c0

Update (rechecked against main 6bfb5c51): withdrawn from the close list; recommendation: keep open. Main's mimg_vgpr_uses (43c56dce) counts atomic data as always written, gives IMAGE_MSAA_LOAD DMASK registers and has no TFE/LWE register; this PR handles all three. Not superseded.

Main now has mimg_vgpr_uses and mimg_address_dwords in rdna2.rs, from #3502 (43c56dce). They count image address registers (NSA one per byte, A16 packing, BVH 11/12) and data registers (DMASK, D16, gather 4, store reads, atomic reads), which is what this PR adds. The lower_image.rs part (no read of vdata+1 for atomics other than compare-swap) is in open #2077. What is left here are refinements to main's version: atomics write back only with GLC, the TFE/LWE extra register, and 4 for IMAGE_MSAA_LOAD. They could go in a short PR rebased on main. #1825 is stacked on this PR (same first commit). #886 adds NSA registers only, which main also covers now.
Recommendation: close (superseded by #3502; the lower_image fix is in #2077).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run.

<!-- greyfinch-sync:ivall/xcl:comment:7303315915 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1797#issuecomment-7303315915). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:49:11Z. --- **Triage (#1607)** – head 8ec49c0 **Update (rechecked against main 6bfb5c51): withdrawn from the close list; recommendation: keep open.** Main's `mimg_vgpr_uses` (43c56dce) counts atomic data as always written, gives `IMAGE_MSAA_LOAD` DMASK registers and has no TFE/LWE register; this PR handles all three. Not superseded. Main now has `mimg_vgpr_uses` and `mimg_address_dwords` in `rdna2.rs`, from #3502 (43c56dce). They count image address registers (NSA one per byte, A16 packing, BVH 11/12) and data registers (DMASK, D16, gather 4, store reads, atomic reads), which is what this PR adds. The `lower_image.rs` part (no read of `vdata+1` for atomics other than compare-swap) is in open #2077. What is left here are refinements to main's version: atomics write back only with GLC, the TFE/LWE extra register, and 4 for `IMAGE_MSAA_LOAD`. They could go in a short PR rebased on main. #1825 is stacked on this PR (same first commit). #886 adds NSA registers only, which main also covers now. ~~Recommendation: close (superseded by #3502; the lower_image fix is in #2077).~~ AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1787
No description provided.