Direct DXIL: MIMG operand layout fixes (A16 bias VGPR, S# FORCE_UNORMALIZED) #3728

Open
Kalmarv wants to merge 1 commit from upstream-pr/3728 into main
Kalmarv commented 2026-12-02 20:33:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:33:05Z.


Consolidates #3351 and #3254 into a single direct-DXIL fix across crates/xcl/src/gpu/dxil/lower_image.rs and crates/xcl/src/gpu/rdna2.rs, addressing the #3254 review feedback on collapsed 4-dword sampler waterfall loops, keeping rdna2::mimg_vgpr_uses in sync with lower_image, and omitting the legacy HLSL emitter changes from #3351.

What is in it

  • crates/xcl/src/gpu/dxil/lower_image.rs (mimg_addr_layout) and crates/xcl/src/gpu/rdna2.rs (mimg_vgpr_uses): fix A16 biased MIMG address packing (from #3351). On RDNA2 with A16=1, the f16 LOD bias occupies the low 16 bits of its own full 32-bit VGPR and packed 16-bit texture coordinates start at [15:0] of the following VGPR (matching rdna2::mimg_address_dwords). Mark both has_b and body[0] (k == 0) with starts = true in both lower_image::mimg_addr_layout and rdna2::mimg_vgpr_uses so body[0] is not unpacked from bias[31:16] and register-use analyses (vgpr_uses, mask_exchange::vgprs_alive, input setup, max_vgpr) report every address VGPR read by the lowering. Direct DXIL only (no recomp/emit.rs changes).
  • crates/xcl/src/gpu/dxil/lower_image.rs (Lw::mimg_s0, Lw::mimg_unorm_sample, Lw::mimg): honor S# word 0 bit 15 (FORCE_UNORMALIZED) and scale explicit (dx, dy) gradients by mip-0 dimensions for unnormalized image_sample_d (from #3254). Static samplers with FORCE_UNORMALIZED=1 lower directly through mimg_unorm_sample (zero runtime branch); dynamic heap samplers on non-cube dimensions guard GetDimensions normalization on s0[15]. Reads S# word 0 via mimg_s0 (self.vreg(v - 3) when waterfall_ssamp collapsed the 4-dword sampler loop at pc, otherwise self.sreg(ssamp)) so collapsed loops do not inspect a stale SGPR.
  • crates/xcl/src/gpu/dxil/lower_image.rs (mimg_layout_tests): 6 unit, DXIL validation, and D3D12 GPU tests covering 13 A16 biased forms (including IMAGE_GATHER4_B and poisoned upper 16 bits in every bias VGPR), multi-mip PS IMAGE_SAMPLE_B with A16, static and dynamic FORCE_UNORMALIZED, unnormalized IMAGE_SAMPLE_D gradients, a collapsed 4-dword sampler waterfall pixel shader with stale s8 = 0, and an exhaustive 3-table parity test (mimg_vgpr_uses_matches_lower_image_and_address_dwords) across all 64 non-G16 sample/gather opcodes × 6 dimensions × A16 ∈ {0, 1} plus NSA biased forms.

Tested

  • Hardware and toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 (10.0.26200), rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609.5.
  • cargo build --release -p xcl: succeeded with 39 warnings (matching origin/main 5ad98adbc, 0 new warnings).
  • cargo test -p xcl --lib -- mimg_layout_tests --nocapture: 6 passed, 0 failed, 0 ignored, 0 skipped.
  • .\scripts\test.ps1 (cargo build --workspace and cargo test --workspace -- --test-threads=4): 3011 passed, 0 failed, 52 ignored across 44 targets, 24 SKIPPED (22 no wave64 on NVIDIA SM 6.6 adapter, 2 no heap windows / opt-in XCL_HEAP_WINDOWS=1).

Regression run

main (5ad98adbc360225ac8a57ad9661e16fe8df9d8dd):

xcl-smoke v1
commit: 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1159 (PresentX 1159)
presents per 2 s (last 3): 200 89 124
device removals: 0
crashes: 0
peak commit: 16044 MB

This PR (99de451f6cc1c3c7bb2b43193e13e2c7c32ca65e):

xcl-smoke v1
commit: 99de451f6cc1c3c7bb2b43193e13e2c7c32ca65e
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1716 (PresentX 1716)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16104 MB

Not tested

  • AMD RDNA / Intel GPUs and the 22 wave64 GPU tests skipped on NVIDIA.
  • Opt-in XCL_HEAP_WINDOWS=1 tests (2 skipped).
  • Legacy HLSL recomp/emit.rs parity (intentionally omitted from this direct-DXIL PR).
  • Cold-cache shader compilation time impact of the dynamic heap-sampler FORCE_UNORMALIZED guard on a shader-heavy title.
  • Retail gameplay beyond the 60 s smoke window; the smoke title may not reach every A16 biased or FORCE_UNORMALIZED MIMG path.

AI use

  • Antigravity (Gemini 4 Neon): consolidated #3351 and #3254 in lower_image.rs, synced rdna2::mimg_vgpr_uses, implemented mimg_s0 for collapsed 4-dword sampler waterfall loops, wrote and ran the mimg_layout_tests, full workspace test suite, and paired 60 s smoke runs, and drafted this PR description.
<!-- greyfinch-sync:ivall/xcl:issue:5614216480 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3728). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T20:33:05Z. --- Consolidates #3351 and #3254 into a single direct-DXIL fix across `crates/xcl/src/gpu/dxil/lower_image.rs` and `crates/xcl/src/gpu/rdna2.rs`, addressing the #3254 review feedback on collapsed 4-dword sampler waterfall loops, keeping `rdna2::mimg_vgpr_uses` in sync with `lower_image`, and omitting the legacy HLSL emitter changes from #3351. **What is in it** - `crates/xcl/src/gpu/dxil/lower_image.rs` (`mimg_addr_layout`) and `crates/xcl/src/gpu/rdna2.rs` (`mimg_vgpr_uses`): fix A16 biased MIMG address packing (from #3351). On RDNA2 with `A16=1`, the `f16` LOD bias occupies the low 16 bits of its own full 32-bit VGPR and packed 16-bit texture coordinates start at `[15:0]` of the following VGPR (matching `rdna2::mimg_address_dwords`). Mark both `has_b` and `body[0]` (`k == 0`) with `starts = true` in both `lower_image::mimg_addr_layout` and `rdna2::mimg_vgpr_uses` so `body[0]` is not unpacked from `bias[31:16]` and register-use analyses (`vgpr_uses`, `mask_exchange::vgprs_alive`, input setup, `max_vgpr`) report every address VGPR read by the lowering. Direct DXIL only (no `recomp/emit.rs` changes). - `crates/xcl/src/gpu/dxil/lower_image.rs` (`Lw::mimg_s0`, `Lw::mimg_unorm_sample`, `Lw::mimg`): honor `S#` word 0 bit 15 (`FORCE_UNORMALIZED`) and scale explicit `(dx, dy)` gradients by mip-0 dimensions for unnormalized `image_sample_d` (from #3254). Static samplers with `FORCE_UNORMALIZED=1` lower directly through `mimg_unorm_sample` (zero runtime branch); dynamic heap samplers on non-cube dimensions guard `GetDimensions` normalization on `s0[15]`. Reads `S#` word 0 via `mimg_s0` (`self.vreg(v - 3)` when `waterfall_ssamp` collapsed the 4-dword sampler loop at `pc`, otherwise `self.sreg(ssamp)`) so collapsed loops do not inspect a stale SGPR. - `crates/xcl/src/gpu/dxil/lower_image.rs` (`mimg_layout_tests`): 6 unit, DXIL validation, and D3D12 GPU tests covering 13 A16 biased forms (including `IMAGE_GATHER4_B` and poisoned upper 16 bits in every bias VGPR), multi-mip PS `IMAGE_SAMPLE_B` with `A16`, static and dynamic `FORCE_UNORMALIZED`, unnormalized `IMAGE_SAMPLE_D` gradients, a collapsed 4-dword sampler waterfall pixel shader with stale `s8 = 0`, and an exhaustive 3-table parity test (`mimg_vgpr_uses_matches_lower_image_and_address_dwords`) across all 64 non-G16 sample/gather opcodes × 6 dimensions × `A16 ∈ {0, 1}` plus NSA biased forms. **Tested** - Hardware and toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 (10.0.26200), `rustc 1.99.0 (b940084d7 2026-09-28)`, DXC `1.9.2609.5`. - `cargo build --release -p xcl`: succeeded with 39 warnings (matching `origin/main` `5ad98adbc`, 0 new warnings). - `cargo test -p xcl --lib -- mimg_layout_tests --nocapture`: 6 passed, 0 failed, 0 ignored, 0 skipped. - `.\scripts\test.ps1` (`cargo build --workspace` and `cargo test --workspace -- --test-threads=4`): 3011 passed, 0 failed, 52 ignored across 44 targets, 24 `SKIPPED` (22 `no wave64` on NVIDIA SM 6.6 adapter, 2 `no heap windows` / opt-in `XCL_HEAP_WINDOWS=1`). **Regression run** `main` (`5ad98adbc360225ac8a57ad9661e16fe8df9d8dd`): ``` xcl-smoke v1 commit: 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 60 exit: 0x0 frames shown: 1159 (PresentX 1159) presents per 2 s (last 3): 200 89 124 device removals: 0 crashes: 0 peak commit: 16044 MB ``` This PR (`99de451f6cc1c3c7bb2b43193e13e2c7c32ca65e`): ``` xcl-smoke v1 commit: 99de451f6cc1c3c7bb2b43193e13e2c7c32ca65e gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 60 exit: 0x0 frames shown: 1716 (PresentX 1716) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16104 MB ``` **Not tested** - AMD RDNA / Intel GPUs and the 22 `wave64` GPU tests skipped on NVIDIA. - Opt-in `XCL_HEAP_WINDOWS=1` tests (2 skipped). - Legacy HLSL `recomp/emit.rs` parity (intentionally omitted from this direct-DXIL PR). - Cold-cache shader compilation time impact of the dynamic heap-sampler `FORCE_UNORMALIZED` guard on a shader-heavy title. - Retail gameplay beyond the 60 s smoke window; the smoke title may not reach every A16 biased or `FORCE_UNORMALIZED` MIMG path. **AI use** - Antigravity (Gemini 4 Neon): consolidated #3351 and #3254 in `lower_image.rs`, synced `rdna2::mimg_vgpr_uses`, implemented `mimg_s0` for collapsed 4-dword sampler waterfall loops, wrote and ran the `mimg_layout_tests`, full workspace test suite, and paired 60 s smoke runs, and drafted this PR description.
vasanex commented 2026-12-03 02:58:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-03T02:58:35Z.

Review: COMMENTED


Review of 262c8445 (code reading, a scratch test, and the suite and smoke run below; not a merge-check) · 1 finding

In short: the new operand layout for A16 biased samples is the right one, and the only layouts that change are those forms without a compare operand, where main was wrong. The FORCE_UNNORMALIZED test reads S# word 0 from the right place, also after a collapsed sampler waterfall (the four vector registers are required to be consecutive, so v - 3 is word 0). The one problem: the register-use table that the analyses work from still has the old packing, so it now disagrees with the lowering (inline).

Measured (RTX 3080, Ryzen 9 7950X, merge of this head onto main 395405e4)

  • cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 3017 passed, 0 failed, 56 ignored; 25 SKIPPED, the same tests as on main (3012 passed, 0 failed, 56 ignored there).
  • scripts/smoke.ps1, 60 s, release, offline, warm shader caches: 1698 frames, exit 0x0, 0 device removals, 0 crashes, peak commit 18188 MB (main 395405e4, same title and time: 1689 frames, 18158 MB). The start screen only; with warm caches it says nothing about the cost in note 1.
  • Scratch test for the finding (not pushed): numbers inline.

Notes, none blocking

  1. Every sample or gather with a heap sampler on a non-cube texture now carries a test of bit 15 and a guarded block (GetDimensions, the divides, a variable per coordinate), roughly doubling the IR of a plain sample, for a bit that CreateSampler never sets (main writes [0, 0, 0, index]; #3730's encoder leaves bit 15 clear too). Only an S# the title wrote itself can set it. The description has no number for cold shader compile time or module size; one from a shader-heavy title would help the maintainer weigh it.
  2. Not from this PR: mimg_gather4_lod still reads S# words 0 to 2 from the scalar registers after a collapse (only word 3 goes through mimg_s3), and the _G16 gradient forms are laid out as 32-bit gradients. Both read, not run.
  3. The CPU half of a16_biased_sample_keeps_bias_in_its_own_vgpr asserts dis.contains(", 4"), which other instructions in the module can satisfy as well; the GPU half (poisoned upper half of the bias register) is what pins the layout, and it covers 2D and 2D-array forms only.

Not checked: AMD and Intel; a title that uses A16 biased samples or sets FORCE_UNNORMALIZED (the smoke title's start screen is not known to); cold-cache compile time; the HLSL fallback, which keeps the old packing as the description says.

Review by Claude Code (Claude Fable 5.2), with an independent second read by a subagent (Claude Fable 5.2) whose points were checked before use, posted without a human check of each point. An automated PR review workflow is running at the request of the user.

<!-- greyfinch-sync:ivall/xcl:review:6162963462 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3728#pullrequestreview-6162963462). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-03T02:58:35Z. **Review:** COMMENTED --- **Review** of `262c8445` (code reading, a scratch test, and the suite and smoke run below; not a merge-check) · 1 finding **In short:** the new operand layout for A16 biased samples is the right one, and the only layouts that change are those forms without a compare operand, where `main` was wrong. The `FORCE_UNNORMALIZED` test reads S# word 0 from the right place, also after a collapsed sampler waterfall (the four vector registers are required to be consecutive, so `v - 3` is word 0). The one problem: the register-use table that the analyses work from still has the old packing, so it now disagrees with the lowering (inline). **Measured** (RTX 3080, Ryzen 9 7950X, merge of this head onto `main` `395405e4`) - `cargo test --workspace --no-fail-fast -- --test-threads=4` (debug): 3017 passed, 0 failed, 56 ignored; 25 SKIPPED, the same tests as on `main` (3012 passed, 0 failed, 56 ignored there). - `scripts/smoke.ps1`, 60 s, release, offline, warm shader caches: 1698 frames, exit 0x0, 0 device removals, 0 crashes, peak commit 18188 MB (`main` `395405e4`, same title and time: 1689 frames, 18158 MB). The start screen only; with warm caches it says nothing about the cost in note 1. - Scratch test for the finding (not pushed): numbers inline. **Notes, none blocking** 1. Every sample or gather with a heap sampler on a non-cube texture now carries a test of bit 15 and a guarded block (`GetDimensions`, the divides, a variable per coordinate), roughly doubling the IR of a plain sample, for a bit that `CreateSampler` never sets (`main` writes `[0, 0, 0, index]`; #3730's encoder leaves bit 15 clear too). Only an S# the title wrote itself can set it. The description has no number for cold shader compile time or module size; one from a shader-heavy title would help the maintainer weigh it. 2. Not from this PR: `mimg_gather4_lod` still reads S# words 0 to 2 from the scalar registers after a collapse (only word 3 goes through `mimg_s3`), and the `_G16` gradient forms are laid out as 32-bit gradients. Both read, not run. 3. The CPU half of `a16_biased_sample_keeps_bias_in_its_own_vgpr` asserts `dis.contains(", 4")`, which other instructions in the module can satisfy as well; the GPU half (poisoned upper half of the bias register) is what pins the layout, and it covers 2D and 2D-array forms only. **Not checked:** AMD and Intel; a title that uses A16 biased samples or sets `FORCE_UNNORMALIZED` (the smoke title's start screen is not known to); cold-cache compile time; the HLSL fallback, which keeps the old packing as the description says. Review by Claude Code (Claude Fable 5.2), with an independent second read by a subagent (Claude Fable 5.2) whose points were checked before use, posted without a human check of each point. An automated PR review workflow is running at the request of the user.
vasanex commented 2026-12-03 02:58:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-03T02:58:36Z.

Code review location: crates/xcl/src/gpu/dxil/lower_image.rs; line 1122

@@ -1091,7 +1117,9 @@ impl Lw {
             }
             if has_b {
                 i_bias = Some(shape.len());
-                shape.push((h, !a16));
+                // RDNA2 A16: f16 bias sits in the low 16 bits of its own full VGPR
+                // (never packed with the first coordinate; matches `rdna2::mimg_address_dwords`).
+                shape.push((h, true));

Finding (medium; the mismatch is measured, its effect is read): rdna2::mimg_vgpr_uses still has the old packing, so the lowering now reads an address register the analyses do not know about.

The comment says the table matches rdna2::mimg_address_dwords, but that function only feeds the disassembly text. The table the passes use is mimg_vgpr_uses in the same file, which still has shape.push((h, !a16)) for the bias and !a16 || (grad_n != 0 && k == 0) for the body. On main it and this table agreed; now they do not.

Scratch test on this head (A16 = 1, rdna2::vgpr_uses on the encoded instruction) against what the table here reads:

form vgpr_uses address registers read by the lowering
IMAGE_SAMPLE_B 1D 1 2
IMAGE_SAMPLE_B 3D, cube, 2D array 2 3
IMAGE_SAMPLE_B_CL 2D 2 3
IMAGE_GATHER4_B 2D array 2 3

(2D sample_b is 2 in both, which is the only form the GPU tests run.)

Consumers on the direct path: mask_exchange::vgprs_alive (decides that a register is dead after a lane fold in split waves), the used set for vertex / geometry input setup and max_vgpr in kernel.rs. Scenario: one of the forms above whose last coordinate, slice or clamp register is named by no other instruction (a stage input, or a value whose only reader is this sample): it is treated as unused or dead, and the sample reads something else. With NSA the unreported register is the last VADDRx.

Suggested: change the two lines in mimg_vgpr_uses in the same commit, and add a test that walks the forms and compares the two tables, so they cannot drift apart again.

<!-- greyfinch-sync:ivall/xcl:review-comment:4779305156 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3728#discussion_r4779305156). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-03T02:58:36Z. **Code review location:** `crates/xcl/src/gpu/dxil/lower_image.rs`; line 1122 ~~~~diff @@ -1091,7 +1117,9 @@ impl Lw { } if has_b { i_bias = Some(shape.len()); - shape.push((h, !a16)); + // RDNA2 A16: f16 bias sits in the low 16 bits of its own full VGPR + // (never packed with the first coordinate; matches `rdna2::mimg_address_dwords`). + shape.push((h, true)); ~~~~ --- **Finding (medium; the mismatch is measured, its effect is read): `rdna2::mimg_vgpr_uses` still has the old packing, so the lowering now reads an address register the analyses do not know about.** The comment says the table matches `rdna2::mimg_address_dwords`, but that function only feeds the disassembly text. The table the passes use is `mimg_vgpr_uses` in the same file, which still has `shape.push((h, !a16))` for the bias and `!a16 || (grad_n != 0 && k == 0)` for the body. On `main` it and this table agreed; now they do not. Scratch test on this head (A16 = 1, `rdna2::vgpr_uses` on the encoded instruction) against what the table here reads: | form | `vgpr_uses` address registers | read by the lowering | |---|---|---| | `IMAGE_SAMPLE_B` 1D | 1 | 2 | | `IMAGE_SAMPLE_B` 3D, cube, 2D array | 2 | 3 | | `IMAGE_SAMPLE_B_CL` 2D | 2 | 3 | | `IMAGE_GATHER4_B` 2D array | 2 | 3 | (2D `sample_b` is 2 in both, which is the only form the GPU tests run.) Consumers on the direct path: `mask_exchange::vgprs_alive` (decides that a register is dead after a lane fold in split waves), the `used` set for vertex / geometry input setup and `max_vgpr` in `kernel.rs`. Scenario: one of the forms above whose last coordinate, slice or clamp register is named by no other instruction (a stage input, or a value whose only reader is this sample): it is treated as unused or dead, and the sample reads something else. With NSA the unreported register is the last `VADDRx`. Suggested: change the two lines in `mimg_vgpr_uses` in the same commit, and add a test that walks the forms and compares the two tables, so they cannot drift apart again.
Kalmarv commented 2026-12-03 03:22:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-03T03:22:27Z.


Thanks @vasanex for catching the rdna2::mimg_vgpr_uses drift! Fixed in 99de451f6:

  • Updated crates/xcl/src/gpu/rdna2.rs (mimg_vgpr_uses) to set starts = true on has_b and k == 0 of body, matching mimg_address_dwords and lower_image.rs so vgpr_uses (and downstream liveness / input-setup / max_vgpr passes) reports every address VGPR read by the lowering, including NSA VADDRx.
  • Extracted mimg_addr_layout in crates/xcl/src/gpu/dxil/lower_image.rs and added mimg_layout_tests::mimg_vgpr_uses_matches_lower_image_and_address_dwords, which walks all 64 non-G16 IMAGE_SAMPLE* / IMAGE_GATHER4* opcodes × 6 dimensions × A16 ∈ {0, 1} (768 cases) plus NSA cases for all four biased A16 forms (IMAGE_SAMPLE_B 1D / 3D / cube / 2D array, IMAGE_SAMPLE_B_CL 2D, IMAGE_GATHER4_B 2D array) and asserts rdna2::vgpr_uses, rdna2::mimg_address_dwords, and lower_image's layout all agree.
  • Also noted cold-cache shader compile time for the dynamic heap-sampler FORCE_UNORMALIZED guard under Not tested in the PR description.

Re-verified on 99de451f6:

  • cargo build --release -p xcl: ok, 39 warnings (0 new vs main 5ad98adbc).
  • cargo test -p xcl --lib -- mimg_layout_tests --nocapture: 6 passed, 0 failed, 0 ignored, 0 skipped.
  • .\scripts\test.ps1 (DXC 1.9.2609): 3011 passed, 0 failed, 52 ignored across 44 targets (24 SKIPPED: 22 no wave64, 2 no heap windows).
  • 60 s smoke (ea3b5e4d, RTX 5070 Ti): exit: 0x0, 1716 frames (60 60 60 presents/2 s), 0 device removals, 0 crashes, 16104 MB peak commit (updated in the PR description).
  • python scripts/pr_check.py --local: description ok.
<!-- greyfinch-sync:ivall/xcl:comment:7366495192 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3728#issuecomment-7366495192). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-03T03:22:27Z. --- Thanks @vasanex for catching the `rdna2::mimg_vgpr_uses` drift! Fixed in `99de451f6`: - Updated `crates/xcl/src/gpu/rdna2.rs` (`mimg_vgpr_uses`) to set `starts = true` on `has_b` and `k == 0` of `body`, matching `mimg_address_dwords` and `lower_image.rs` so `vgpr_uses` (and downstream liveness / input-setup / `max_vgpr` passes) reports every address VGPR read by the lowering, including NSA `VADDRx`. - Extracted `mimg_addr_layout` in `crates/xcl/src/gpu/dxil/lower_image.rs` and added `mimg_layout_tests::mimg_vgpr_uses_matches_lower_image_and_address_dwords`, which walks all 64 non-G16 `IMAGE_SAMPLE*` / `IMAGE_GATHER4*` opcodes × 6 dimensions × `A16 ∈ {0, 1}` (768 cases) plus NSA cases for all four biased A16 forms (`IMAGE_SAMPLE_B` 1D / 3D / cube / 2D array, `IMAGE_SAMPLE_B_CL` 2D, `IMAGE_GATHER4_B` 2D array) and asserts `rdna2::vgpr_uses`, `rdna2::mimg_address_dwords`, and `lower_image`'s layout all agree. - Also noted cold-cache shader compile time for the dynamic heap-sampler `FORCE_UNORMALIZED` guard under **Not tested** in the PR description. Re-verified on `99de451f6`: - `cargo build --release -p xcl`: ok, 39 warnings (0 new vs `main` `5ad98adbc`). - `cargo test -p xcl --lib -- mimg_layout_tests --nocapture`: `6 passed, 0 failed, 0 ignored, 0 skipped`. - `.\scripts\test.ps1` (DXC 1.9.2609): `3011 passed, 0 failed, 52 ignored` across 44 targets (`24 SKIPPED`: 22 `no wave64`, 2 `no heap windows`). - 60 s smoke (`ea3b5e4d`, RTX 5070 Ti): `exit: 0x0`, `1716` frames (`60 60 60` presents/2 s), `0` device removals, `0` crashes, `16104 MB` peak commit (updated in the PR description). - `python scripts/pr_check.py --local`: `description ok`.
vasanex commented 2026-12-03 03:24:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-03T03:24:30Z.

Code review location: crates/xcl/src/gpu/dxil/lower_image.rs; line 1122

@@ -1091,7 +1117,9 @@ impl Lw {
             }
             if has_b {
                 i_bias = Some(shape.len());
-                shape.push((h, !a16));
+                // RDNA2 A16: f16 bias sits in the low 16 bits of its own full VGPR
+                // (never packed with the first coordinate; matches `rdna2::mimg_address_dwords`).
+                shape.push((h, true));

Fixed in 99de451f: mimg_vgpr_uses has the new packing, and the lowering's layout is now one function that the new test compares with it. Measured here (RTX 3080, Ryzen 9 7950X, debug, this head merged onto main 395405e4): mimg_layout_tests: 6 passed, 0 failed; cargo test -p xcl --lib -- gpu::dxil gpu::rdna2: 383 passed, 0 failed, 5 ignored; with main's two lines put back in mimg_vgpr_uses, mimg_vgpr_uses_matches_lower_image_and_address_dwords fails at IMAGE_SAMPLE_B 1D A16 (1 against 2), so it pins the fix. The whole suite and a smoke run on this head were not rerun here; the move of the layout into mimg_addr_layout I read only as far as the shape table. (I cannot mark the thread resolved from this account.)

Follow-up by Claude Code (Claude Fable 5.2), posted without a human check; an automated PR review workflow is running at the request of the user.

Added 04:00Z: whole suite and smoke now run on this head merged onto main 395405e4 (RTX 3080, Ryzen 9 7950X): cargo test --workspace --no-fail-fast -- --test-threads=4: 3018 passed, 0 failed, 56 ignored, 25 SKIPPED (the same tests as on main); 60 s offline smoke: 1688 frames, exit 0x0, 0 device removals, 0 crashes, peak commit 18513 MB (main: 1689 frames, 18158 MB).

<!-- greyfinch-sync:ivall/xcl:review-comment:4779489562 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3728#discussion_r4779489562). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-03T03:24:30Z. **Code review location:** `crates/xcl/src/gpu/dxil/lower_image.rs`; line 1122 ~~~~diff @@ -1091,7 +1117,9 @@ impl Lw { } if has_b { i_bias = Some(shape.len()); - shape.push((h, !a16)); + // RDNA2 A16: f16 bias sits in the low 16 bits of its own full VGPR + // (never packed with the first coordinate; matches `rdna2::mimg_address_dwords`). + shape.push((h, true)); ~~~~ --- Fixed in `99de451f`: `mimg_vgpr_uses` has the new packing, and the lowering's layout is now one function that the new test compares with it. Measured here (RTX 3080, Ryzen 9 7950X, debug, this head merged onto `main` `395405e4`): `mimg_layout_tests`: 6 passed, 0 failed; `cargo test -p xcl --lib -- gpu::dxil gpu::rdna2`: 383 passed, 0 failed, 5 ignored; with `main`'s two lines put back in `mimg_vgpr_uses`, `mimg_vgpr_uses_matches_lower_image_and_address_dwords` fails at `IMAGE_SAMPLE_B` 1D A16 (1 against 2), so it pins the fix. The whole suite and a smoke run on this head were not rerun here; the move of the layout into `mimg_addr_layout` I read only as far as the shape table. (I cannot mark the thread resolved from this account.) Follow-up by Claude Code (Claude Fable 5.2), posted without a human check; an automated PR review workflow is running at the request of the user. **Added 04:00Z:** whole suite and smoke now run on this head merged onto `main` `395405e4` (RTX 3080, Ryzen 9 7950X): `cargo test --workspace --no-fail-fast -- --test-threads=4`: 3018 passed, 0 failed, 56 ignored, 25 SKIPPED (the same tests as on `main`); 60 s offline smoke: 1688 frames, exit 0x0, 0 device removals, 0 crashes, peak commit 18513 MB (`main`: 1689 frames, 18158 MB).
Foniass commented 2026-12-03 06:29:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T06:29:17Z.


merge-check
base: 078358a058
head: 99de451f6c
merge: clean
build: ok
tests: 3012 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 4 medium, 4 nits (below)
performance: 60 s smoke run: 1669 → 1657 frames (99 % of main), peak commit 17577 → 17868 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 224 s there, 0 device removals, 0 crashes, 3.2 presents/s; run with XCL_SKIP_CS=95cc13288a27a96e (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)
verdict: not yet: PR description is red; otherwise no blocking finding, the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5


In short: The PR changes Direct DXIL MIMG lowering in two ways: on A16, the bias gets its own VGPR, and S# word 0 bit 15 (FORCE_UNORMALIZED) is honoured with gradient scaling for unnormalized image_sample_d. Since my earlier review, the push moved the layout into mimg_addr_layout, synced rdna2::mimg_vgpr_uses and added a parity test across 64 opcodes x 6 dims x A16. The reading found the logic correct and consistent with mimg_address_dwords and the existing unorm path, but none of the six earlier findings is fixed and a new conflict with #3663 needs coordinating. Nothing blocks merging.

Medium

  1. Two fixes in one PR, further over the size target. Still open from my earlier review, and the diff grew from 759 to 988 changed lines (about 280 outside tests). The A16 bias layout fix (mimg_addr_layout + rdna2::mimg_vgpr_uses + the parity test) and the FORCE_UNORMALIZED/sample_d fix (mimg_s0, the dynamic guard, the gradient scaling in mimg_unorm_sample) do not depend on each other. Over 800 lines, CONTRIBUTING requires the description to say why the work cannot be split, and it does not. Split it into two PRs or add the reason.
  2. Conflict with #3663 over the collapsed-waterfall S# words. Open PR #3663 (Prime1997) replaces mimg_s3 with mimg_sword(pc, ssamp, k) in lower_image.rs ~38-55, and it changes waterfall::collapse to store vb instead of vb + 3. A test merge of the two heads conflicts in lower_image.rs. Worse, if #3663 lands first and the conflict is resolved by keeping mimg_s0 as written, mimg_s0 reads v[vb - 3], the wrong register. Whichever PR lands second should replace mimg_s0 with mimg_sword(d.pc, ssamp, 0); the author should coordinate with #3663 and say so in the description.
  3. HLSL backend still disagrees on both fixes. Still open from my earlier review. recomp/emit.rs ~2662 still packs the A16 bias with !a16 and body[0] with (grad_n != 0 && k == 0). It also has no FORCE_UNORMALIZED handling for sample/sample_d (only the gather path at ~7074 reads s0 >> 15). HLSL is still the fallback for shaders that Direct DXIL cannot translate (README ~226), so the same MIMG gives different results depending on which backend translates the shader. rdna2::vgpr_uses now reports the next VGPR while HLSL reads bias[31:16]. Port both fixes to emit.rs in a follow-up PR (with a test) and link it from the description.
  4. Per-sample branch on every heap-sampler sample. Still open from my earlier review. lower_image.rs ~1337: every non-cube MIMG with a dynamic (non-static) S# now emits an s0 >> 15 test and a guarded block with GetDimensions. It also adds a temp variable per spatial coordinate and per gradient component, with reads after the merge. This is on the default path for every bindless sample, and the cost in shader size, compile time and frame time is not measured (the description lists it under Not tested). Measure cold-cache prep time and frame time on a shader-heavy title, or keep the guard out of the common path.

Nit

  1. CPU layout check is a substring match. Still open from my earlier review. a16_biased_sample_keeps_bias_in_its_own_vgpr (lower_image.rs ~2440) asserts that the disassembly contains ", {4 * coord0_v}". With coord0_v = 1 that is ", 4", which matches ", 40", ", 48" and any i32 4 operand, so the CPU half of the test can pass without the load it is meant to prove. Match the full load pattern, or rely on the GPU half.
  2. Test helpers duplicated. Still open from my earlier review. mimg_layout_tests redefines tsharp and half_bits, which already exist in dxil/msaa_tests.rs ~168/~238 and recomp/tests.rs ~3350/~3972, and repeats the passthrough-VS/sampler-desc boilerplate in each GPU test. Reuse the existing helpers.
  3. mimg_gather4_lod still reads S# words 0-2 from SGPRs. Still open from my earlier review. lower_image.rs ~523-525 reads sreg(ssamp..ssamp+2), so inside a collapsed waterfall gather4_l still reads stale FORCE_UNORMALIZED, LOD bias and min/max LOD. This PR added mimg_s0 but does not use it there; #3663 fixes this, which is one more reason to coordinate with it.
  4. Commit subject area is not a repo area. The subject starts with "Direct DXIL:", which is not in the area list in AGENTS.md / CONTRIBUTING.md. The two PRs this one consolidates used "Recompiler:"; use that.
Checked and fine
  • A16 bias layout matches rdna2::mimg_address_dwords on main (B counted as its own dword) and LLVM's packing; the k == 0 change only has an effect after the bias, so other forms keep their layout
  • rdna2::mimg_vgpr_uses now agrees with lower_image; the parity test checks all three tables and the A16 NSA reads, and it would fail on main for every A16 biased form
  • mimg_s0's v - 3 is correct at this head: waterfall::collapse only matches 4-dword loops with consecutive v[vb..vb+3] and stores vb + 3
  • The dynamic FORCE_UNORMALIZED path chooses the mip level and spatial dimensions like mimg_unorm_sample, and the static-sampler path only goes through mimg_unorm_sample when w[0][15] is set
  • New GPU tests cover the static and dynamic FORCE_UNORMALIZED paths, UNORM and force-unorm sample_d gradients, poisoned bias high halves, and per-lane S# in a collapsed waterfall; they skip correctly without a wave32 GPU
  • No assertions deleted or weakened; no game data; Gemini 4 Neon is not a banned model family; merges cleanly onto current origin/main with no new main commits to the touched files
  • No overlap with #3730 (desc.rs, real.rs): a test merge is clean and #3730 does not touch FORCE_UNORMALIZED
  • Smoke blocks name main 5ad98adb (the merge base) and the PR head 99de451f on the same title for 60 s: 1716 vs 1159 frames, peak commit 16104 vs 16044 MB, no device removals or crashes
How this was tested
  • Merged onto main 078358a0, then cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4.
  • The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar).
  • scripts/smoke.ps1: 60 s of a retail title on main 078358a0 and on this merge; presents per 2 s at the end: 60 60 60.
  • Title run: the release build of this merge launched the retail title with XCL_RUN_SECONDS=300 and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7369890608 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3728#issuecomment-7369890608). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T06:29:17Z. --- merge-check base: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a head: 99de451f6cc1c3c7bb2b43193e13e2c7c32ca65e merge: clean build: ok tests: 3012 passed, 0 failed, 52 ignored; 28 skipped, the same as on main review: 4 medium, 4 nits (below) performance: 60 s smoke run: 1669 → 1657 frames (99 % of main), peak commit 17577 → 17868 MB, no device removal, no crash title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 224 s there, 0 device removals, 0 crashes, 3.2 presents/s; run with `XCL_SKIP_CS=95cc13288a27a96e` (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590) verdict: not yet: `PR description` is red; otherwise no blocking finding, the suite passes and the smoke run is clean hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 --- **In short:** The PR changes Direct DXIL MIMG lowering in two ways: on A16, the bias gets its own VGPR, and S# word 0 bit 15 (FORCE_UNORMALIZED) is honoured with gradient scaling for unnormalized image_sample_d. Since my earlier review, the push moved the layout into mimg_addr_layout, synced rdna2::mimg_vgpr_uses and added a parity test across 64 opcodes x 6 dims x A16. The reading found the logic correct and consistent with mimg_address_dwords and the existing unorm path, but none of the six earlier findings is fixed and a new conflict with #3663 needs coordinating. Nothing blocks merging. #### Medium 1. **Two fixes in one PR, further over the size target.** Still open from my earlier review, and the diff grew from 759 to 988 changed lines (about 280 outside tests). The A16 bias layout fix (mimg_addr_layout + rdna2::mimg_vgpr_uses + the parity test) and the FORCE_UNORMALIZED/sample_d fix (mimg_s0, the dynamic guard, the gradient scaling in mimg_unorm_sample) do not depend on each other. Over 800 lines, CONTRIBUTING requires the description to say why the work cannot be split, and it does not. Split it into two PRs or add the reason. 2. **Conflict with #3663 over the collapsed-waterfall S# words.** Open PR #3663 (Prime1997) replaces mimg_s3 with mimg_sword(pc, ssamp, k) in lower_image.rs ~38-55, and it changes waterfall::collapse to store vb instead of vb + 3. A test merge of the two heads conflicts in lower_image.rs. Worse, if #3663 lands first and the conflict is resolved by keeping mimg_s0 as written, mimg_s0 reads v[vb - 3], the wrong register. Whichever PR lands second should replace mimg_s0 with mimg_sword(d.pc, ssamp, 0); the author should coordinate with #3663 and say so in the description. 3. **HLSL backend still disagrees on both fixes.** Still open from my earlier review. recomp/emit.rs ~2662 still packs the A16 bias with !a16 and body[0] with (grad_n != 0 && k == 0). It also has no FORCE_UNORMALIZED handling for sample/sample_d (only the gather path at ~7074 reads s0 >> 15). HLSL is still the fallback for shaders that Direct DXIL cannot translate (README ~226), so the same MIMG gives different results depending on which backend translates the shader. rdna2::vgpr_uses now reports the next VGPR while HLSL reads bias[31:16]. Port both fixes to emit.rs in a follow-up PR (with a test) and link it from the description. 4. **Per-sample branch on every heap-sampler sample.** Still open from my earlier review. lower_image.rs ~1337: every non-cube MIMG with a dynamic (non-static) S# now emits an s0 >> 15 test and a guarded block with GetDimensions. It also adds a temp variable per spatial coordinate and per gradient component, with reads after the merge. This is on the default path for every bindless sample, and the cost in shader size, compile time and frame time is not measured (the description lists it under Not tested). Measure cold-cache prep time and frame time on a shader-heavy title, or keep the guard out of the common path. #### Nit 5. **CPU layout check is a substring match.** Still open from my earlier review. a16_biased_sample_keeps_bias_in_its_own_vgpr (lower_image.rs ~2440) asserts that the disassembly contains ", {4 * coord0_v}". With coord0_v = 1 that is ", 4", which matches ", 40", ", 48" and any i32 4 operand, so the CPU half of the test can pass without the load it is meant to prove. Match the full load pattern, or rely on the GPU half. 6. **Test helpers duplicated.** Still open from my earlier review. mimg_layout_tests redefines tsharp and half_bits, which already exist in dxil/msaa_tests.rs ~168/~238 and recomp/tests.rs ~3350/~3972, and repeats the passthrough-VS/sampler-desc boilerplate in each GPU test. Reuse the existing helpers. 7. **mimg_gather4_lod still reads S# words 0-2 from SGPRs.** Still open from my earlier review. lower_image.rs ~523-525 reads sreg(ssamp..ssamp+2), so inside a collapsed waterfall gather4_l still reads stale FORCE_UNORMALIZED, LOD bias and min/max LOD. This PR added mimg_s0 but does not use it there; #3663 fixes this, which is one more reason to coordinate with it. 8. **Commit subject area is not a repo area.** The subject starts with "Direct DXIL:", which is not in the area list in AGENTS.md / CONTRIBUTING.md. The two PRs this one consolidates used "Recompiler:"; use that. <details><summary>Checked and fine</summary> - A16 bias layout matches rdna2::mimg_address_dwords on main (B counted as its own dword) and LLVM's packing; the k == 0 change only has an effect after the bias, so other forms keep their layout - rdna2::mimg_vgpr_uses now agrees with lower_image; the parity test checks all three tables and the A16 NSA reads, and it would fail on main for every A16 biased form - mimg_s0's v - 3 is correct at this head: waterfall::collapse only matches 4-dword loops with consecutive v[vb..vb+3] and stores vb + 3 - The dynamic FORCE_UNORMALIZED path chooses the mip level and spatial dimensions like mimg_unorm_sample, and the static-sampler path only goes through mimg_unorm_sample when w[0][15] is set - New GPU tests cover the static and dynamic FORCE_UNORMALIZED paths, UNORM and force-unorm sample_d gradients, poisoned bias high halves, and per-lane S# in a collapsed waterfall; they skip correctly without a wave32 GPU - No assertions deleted or weakened; no game data; Gemini 4 Neon is not a banned model family; merges cleanly onto current origin/main with no new main commits to the touched files - No overlap with #3730 (desc.rs, real.rs): a test merge is clean and #3730 does not touch FORCE_UNORMALIZED - Smoke blocks name main 5ad98adb (the merge base) and the PR head 99de451f on the same title for 60 s: 1716 vs 1159 frames, peak commit 16104 vs 16044 MB, no device removals or crashes </details> <details><summary>How this was tested</summary> - Merged onto main `078358a0`, then `cargo build --workspace` and `cargo test --workspace --no-fail-fast -- --test-threads=4`. - The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar). - `scripts/smoke.ps1`: 60 s of a retail title on main `078358a0` and on this merge; presents per 2 s at the end: 60 60 60. - Title run: the release build of this merge launched the retail title with `XCL_RUN_SECONDS=300` and scripted A presses counted from the first frame (`XCL_PRESS_BASE=frame`, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Kalmarv commented 2026-12-03 06:39:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-03T06:39:42Z.


Thanks @Foniass for the thorough merge-check and 224 s title run! Leaving HEAD at 99de451f6 untouched to preserve the verified run — the red PR description check is the repo-wide pull_request_target startup_failure currently affecting all open PRs (python scripts/pr_check.py --local passes with description ok on 99de451f6). Also noted the #3663 coordination point: if #3663 merges first, we will rebase and replace mimg_s0 with mimg_sword(d.pc, ssamp, 0).

<!-- greyfinch-sync:ivall/xcl:comment:7370086615 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3728#issuecomment-7370086615). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-03T06:39:42Z. --- Thanks @Foniass for the thorough merge-check and 224 s title run! Leaving HEAD at 99de451f6 untouched to preserve the verified run — the red PR description check is the repo-wide pull_request_target startup_failure currently affecting all open PRs (python scripts/pr_check.py --local passes with description ok on 99de451f6). Also noted the #3663 coordination point: if #3663 merges first, we will rebase and replace mimg_s0 with mimg_sword(d.pc, ssamp, 0).
Foniass commented 2026-12-03 15:33:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:33:42Z.


merge-check
base: 078358a058
head: 99de451f6c
merge: clean
build: ok
tests: 3012 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 4 medium, 4 nits (below)
performance: 60 s smoke run: 1669 → 1657 frames (99 % of main), peak commit 17577 → 17868 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 224 s there, 0 device removals, 0 crashes, 3.2 presents/s; run with XCL_SKIP_CS=95cc13288a27a96e (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)
verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5


In short: The PR changes Direct DXIL MIMG lowering in two ways: on A16, the bias gets its own VGPR, and S# word 0 bit 15 (FORCE_UNORMALIZED) is honoured with gradient scaling for unnormalized image_sample_d. Since my earlier review, the push moved the layout into mimg_addr_layout, synced rdna2::mimg_vgpr_uses and added a parity test across 64 opcodes x 6 dims x A16. The reading found the logic correct and consistent with mimg_address_dwords and the existing unorm path, but none of the six earlier findings is fixed and a new conflict with #3663 needs coordinating. Nothing blocks merging.

Medium

  1. Two fixes in one PR, further over the size target. Still open from my earlier review, and the diff grew from 759 to 988 changed lines (about 280 outside tests). The A16 bias layout fix (mimg_addr_layout + rdna2::mimg_vgpr_uses + the parity test) and the FORCE_UNORMALIZED/sample_d fix (mimg_s0, the dynamic guard, the gradient scaling in mimg_unorm_sample) do not depend on each other. Over 800 lines, CONTRIBUTING requires the description to say why the work cannot be split, and it does not. Split it into two PRs or add the reason.
  2. Conflict with #3663 over the collapsed-waterfall S# words. Open PR #3663 (Prime1997) replaces mimg_s3 with mimg_sword(pc, ssamp, k) in lower_image.rs ~38-55, and it changes waterfall::collapse to store vb instead of vb + 3. A test merge of the two heads conflicts in lower_image.rs. Worse, if #3663 lands first and the conflict is resolved by keeping mimg_s0 as written, mimg_s0 reads v[vb - 3], the wrong register. Whichever PR lands second should replace mimg_s0 with mimg_sword(d.pc, ssamp, 0); the author should coordinate with #3663 and say so in the description.
  3. HLSL backend still disagrees on both fixes. Still open from my earlier review. recomp/emit.rs ~2662 still packs the A16 bias with !a16 and body[0] with (grad_n != 0 && k == 0). It also has no FORCE_UNORMALIZED handling for sample/sample_d (only the gather path at ~7074 reads s0 >> 15). HLSL is still the fallback for shaders that Direct DXIL cannot translate (README ~226), so the same MIMG gives different results depending on which backend translates the shader. rdna2::vgpr_uses now reports the next VGPR while HLSL reads bias[31:16]. Port both fixes to emit.rs in a follow-up PR (with a test) and link it from the description.
  4. Per-sample branch on every heap-sampler sample. Still open from my earlier review. lower_image.rs ~1337: every non-cube MIMG with a dynamic (non-static) S# now emits an s0 >> 15 test and a guarded block with GetDimensions. It also adds a temp variable per spatial coordinate and per gradient component, with reads after the merge. This is on the default path for every bindless sample, and the cost in shader size, compile time and frame time is not measured (the description lists it under Not tested). Measure cold-cache prep time and frame time on a shader-heavy title, or keep the guard out of the common path.

Nit

  1. CPU layout check is a substring match. Still open from my earlier review. a16_biased_sample_keeps_bias_in_its_own_vgpr (lower_image.rs ~2440) asserts that the disassembly contains ", {4 * coord0_v}". With coord0_v = 1 that is ", 4", which matches ", 40", ", 48" and any i32 4 operand, so the CPU half of the test can pass without the load it is meant to prove. Match the full load pattern, or rely on the GPU half.
  2. Test helpers duplicated. Still open from my earlier review. mimg_layout_tests redefines tsharp and half_bits, which already exist in dxil/msaa_tests.rs ~168/~238 and recomp/tests.rs ~3350/~3972, and repeats the passthrough-VS/sampler-desc boilerplate in each GPU test. Reuse the existing helpers.
  3. mimg_gather4_lod still reads S# words 0-2 from SGPRs. Still open from my earlier review. lower_image.rs ~523-525 reads sreg(ssamp..ssamp+2), so inside a collapsed waterfall gather4_l still reads stale FORCE_UNORMALIZED, LOD bias and min/max LOD. This PR added mimg_s0 but does not use it there; #3663 fixes this, which is one more reason to coordinate with it.
  4. Commit subject area is not a repo area. The subject starts with "Direct DXIL:", which is not in the area list in AGENTS.md / CONTRIBUTING.md. The two PRs this one consolidates used "Recompiler:"; use that.
Checked and fine
  • A16 bias layout matches rdna2::mimg_address_dwords on main (B counted as its own dword) and LLVM's packing; the k == 0 change only has an effect after the bias, so other forms keep their layout
  • rdna2::mimg_vgpr_uses now agrees with lower_image; the parity test checks all three tables and the A16 NSA reads, and it would fail on main for every A16 biased form
  • mimg_s0's v - 3 is correct at this head: waterfall::collapse only matches 4-dword loops with consecutive v[vb..vb+3] and stores vb + 3
  • The dynamic FORCE_UNORMALIZED path chooses the mip level and spatial dimensions like mimg_unorm_sample, and the static-sampler path only goes through mimg_unorm_sample when w[0][15] is set
  • New GPU tests cover the static and dynamic FORCE_UNORMALIZED paths, UNORM and force-unorm sample_d gradients, poisoned bias high halves, and per-lane S# in a collapsed waterfall; they skip correctly without a wave32 GPU
  • No assertions deleted or weakened; no game data; Gemini 4 Neon is not a banned model family; merges cleanly onto current origin/main with no new main commits to the touched files
  • No overlap with #3730 (desc.rs, real.rs): a test merge is clean and #3730 does not touch FORCE_UNORMALIZED
  • Smoke blocks name main 5ad98adb (the merge base) and the PR head 99de451f on the same title for 60 s: 1716 vs 1159 frames, peak commit 16104 vs 16044 MB, no device removals or crashes
How this was tested
  • Merged onto main 078358a0, then cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4.
  • The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar).
  • scripts/smoke.ps1: 60 s of a retail title on main 078358a0 and on this merge; presents per 2 s at the end: 60 60 60.
  • Title run: the release build of this merge launched the retail title with XCL_RUN_SECONDS=300 and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7383352648 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3728#issuecomment-7383352648). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T15:33:42Z. --- merge-check base: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a head: 99de451f6cc1c3c7bb2b43193e13e2c7c32ca65e merge: clean build: ok tests: 3012 passed, 0 failed, 52 ignored; 28 skipped, the same as on main review: 4 medium, 4 nits (below) performance: 60 s smoke run: 1669 → 1657 frames (99 % of main), peak commit 17577 → 17868 MB, no device removal, no crash title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 224 s there, 0 device removals, 0 crashes, 3.2 presents/s; run with `XCL_SKIP_CS=95cc13288a27a96e` (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590) verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 --- **In short:** The PR changes Direct DXIL MIMG lowering in two ways: on A16, the bias gets its own VGPR, and S# word 0 bit 15 (FORCE_UNORMALIZED) is honoured with gradient scaling for unnormalized image_sample_d. Since my earlier review, the push moved the layout into mimg_addr_layout, synced rdna2::mimg_vgpr_uses and added a parity test across 64 opcodes x 6 dims x A16. The reading found the logic correct and consistent with mimg_address_dwords and the existing unorm path, but none of the six earlier findings is fixed and a new conflict with #3663 needs coordinating. Nothing blocks merging. #### Medium 1. **Two fixes in one PR, further over the size target.** Still open from my earlier review, and the diff grew from 759 to 988 changed lines (about 280 outside tests). The A16 bias layout fix (mimg_addr_layout + rdna2::mimg_vgpr_uses + the parity test) and the FORCE_UNORMALIZED/sample_d fix (mimg_s0, the dynamic guard, the gradient scaling in mimg_unorm_sample) do not depend on each other. Over 800 lines, CONTRIBUTING requires the description to say why the work cannot be split, and it does not. Split it into two PRs or add the reason. 2. **Conflict with #3663 over the collapsed-waterfall S# words.** Open PR #3663 (Prime1997) replaces mimg_s3 with mimg_sword(pc, ssamp, k) in lower_image.rs ~38-55, and it changes waterfall::collapse to store vb instead of vb + 3. A test merge of the two heads conflicts in lower_image.rs. Worse, if #3663 lands first and the conflict is resolved by keeping mimg_s0 as written, mimg_s0 reads v[vb - 3], the wrong register. Whichever PR lands second should replace mimg_s0 with mimg_sword(d.pc, ssamp, 0); the author should coordinate with #3663 and say so in the description. 3. **HLSL backend still disagrees on both fixes.** Still open from my earlier review. recomp/emit.rs ~2662 still packs the A16 bias with !a16 and body[0] with (grad_n != 0 && k == 0). It also has no FORCE_UNORMALIZED handling for sample/sample_d (only the gather path at ~7074 reads s0 >> 15). HLSL is still the fallback for shaders that Direct DXIL cannot translate (README ~226), so the same MIMG gives different results depending on which backend translates the shader. rdna2::vgpr_uses now reports the next VGPR while HLSL reads bias[31:16]. Port both fixes to emit.rs in a follow-up PR (with a test) and link it from the description. 4. **Per-sample branch on every heap-sampler sample.** Still open from my earlier review. lower_image.rs ~1337: every non-cube MIMG with a dynamic (non-static) S# now emits an s0 >> 15 test and a guarded block with GetDimensions. It also adds a temp variable per spatial coordinate and per gradient component, with reads after the merge. This is on the default path for every bindless sample, and the cost in shader size, compile time and frame time is not measured (the description lists it under Not tested). Measure cold-cache prep time and frame time on a shader-heavy title, or keep the guard out of the common path. #### Nit 5. **CPU layout check is a substring match.** Still open from my earlier review. a16_biased_sample_keeps_bias_in_its_own_vgpr (lower_image.rs ~2440) asserts that the disassembly contains ", {4 * coord0_v}". With coord0_v = 1 that is ", 4", which matches ", 40", ", 48" and any i32 4 operand, so the CPU half of the test can pass without the load it is meant to prove. Match the full load pattern, or rely on the GPU half. 6. **Test helpers duplicated.** Still open from my earlier review. mimg_layout_tests redefines tsharp and half_bits, which already exist in dxil/msaa_tests.rs ~168/~238 and recomp/tests.rs ~3350/~3972, and repeats the passthrough-VS/sampler-desc boilerplate in each GPU test. Reuse the existing helpers. 7. **mimg_gather4_lod still reads S# words 0-2 from SGPRs.** Still open from my earlier review. lower_image.rs ~523-525 reads sreg(ssamp..ssamp+2), so inside a collapsed waterfall gather4_l still reads stale FORCE_UNORMALIZED, LOD bias and min/max LOD. This PR added mimg_s0 but does not use it there; #3663 fixes this, which is one more reason to coordinate with it. 8. **Commit subject area is not a repo area.** The subject starts with "Direct DXIL:", which is not in the area list in AGENTS.md / CONTRIBUTING.md. The two PRs this one consolidates used "Recompiler:"; use that. <details><summary>Checked and fine</summary> - A16 bias layout matches rdna2::mimg_address_dwords on main (B counted as its own dword) and LLVM's packing; the k == 0 change only has an effect after the bias, so other forms keep their layout - rdna2::mimg_vgpr_uses now agrees with lower_image; the parity test checks all three tables and the A16 NSA reads, and it would fail on main for every A16 biased form - mimg_s0's v - 3 is correct at this head: waterfall::collapse only matches 4-dword loops with consecutive v[vb..vb+3] and stores vb + 3 - The dynamic FORCE_UNORMALIZED path chooses the mip level and spatial dimensions like mimg_unorm_sample, and the static-sampler path only goes through mimg_unorm_sample when w[0][15] is set - New GPU tests cover the static and dynamic FORCE_UNORMALIZED paths, UNORM and force-unorm sample_d gradients, poisoned bias high halves, and per-lane S# in a collapsed waterfall; they skip correctly without a wave32 GPU - No assertions deleted or weakened; no game data; Gemini 4 Neon is not a banned model family; merges cleanly onto current origin/main with no new main commits to the touched files - No overlap with #3730 (desc.rs, real.rs): a test merge is clean and #3730 does not touch FORCE_UNORMALIZED - Smoke blocks name main 5ad98adb (the merge base) and the PR head 99de451f on the same title for 60 s: 1716 vs 1159 frames, peak commit 16104 vs 16044 MB, no device removals or crashes </details> <details><summary>How this was tested</summary> - Merged onto main `078358a0`, then `cargo build --workspace` and `cargo test --workspace --no-fail-fast -- --test-threads=4`. - The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar). - `scripts/smoke.ps1`: 60 s of a retail title on main `078358a0` and on this merge; presents per 2 s at the end: 60 60 60. - Title run: the release build of this merge launched the retail title with `XCL_RUN_SECONDS=300` and scripted A presses counted from the first frame (`XCL_PRESS_BASE=frame`, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3728:upstream-pr/3728'
git switch 'upstream-pr/3728'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3728'
git switch 'upstream-pr/3728'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3728'
git switch 'upstream-pr/3728'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3728'
git switch 'main'
git merge --squash 'upstream-pr/3728'
git switch 'main'
git merge --ff-only 'upstream-pr/3728'
git switch 'main'
git merge 'upstream-pr/3728'
git push origin 'main'
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!3728
No description provided.