Recompiler: keep A16 MIMG bias in its own VGPR before packed coordinates #3351
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3351"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T10:01:42Z.
What changed
crates/xcl/src/gpu/dxil/lower_image.rs(Lw::mimg): setstarts = trueon thehas_bbias entry and on the first body coordinate (k == 0) when building the MIMGVADDRshapetable, so underA16=1thef16bias sits in the low 16 bits of its own full 32-bit VGPR and body coordinates always start at the low 16 bits of the next VGPR.crates/xcl/src/gpu/recomp/emit.rs(Em::mimg): applied the identicalshapefix and updated theA16address-layout doc comment to match.crates/xcl/src/gpu/dxil/lower_image.rs(heap_bounds_tests::a16_biased_sample_keeps_bias_in_its_own_vgpr): added CPU/CI translation, DXIL validation, and HLSL layout assertions across 12IMAGE_SAMPLE_B*(_b,_b_cl,_b_o,_b_cl_o,_c_b,_c_b_o, 1D/2D/3D/Cube/2DArray, andNSA=1) forms withA16=1, plus GPU execution tests in both Direct DXIL and HLSL with non-zero poison in the upper 16 bits of every bias VGPR.crates/xcl/src/gpu/recomp/tests.rs(gpu_ps_image_sample_b_a16_multi_mip): added a multi-mip 5-level pixel-shader GPU draw test exercisingIMAGE_SAMPLE_BwithA16=1(bias = +1.0inv4[15:0], poison inv4[31:16], packed(u, v)inv5) in both HLSL and Direct DXIL to verify both mip-level selection and coordinate decoding.Why
On RDNA2 (
A16=1), a biased image sample'sf16LOD bias occupies a full 32-bit VGPR in its low 16 bits ([15:0], with[31:16]unused padding), and the packed 16-bit texture coordinates start at[15:0]of the following VGPR — matching LLVM AMDGPU (packImage16bitOpsToDwords/getAddrSizeMIMGOp) and XCL's own disassembler (rdna2::mimg_address_dwords).Previously, both
lower_image.rsandemit.rspushed(16, false)forbiasand(16, false)forbody[0]whenevergrad_n == 0. Forimage_sample_b,image_sample_b_cl,image_sample_b_o, andimage_sample_b_cl_owithA16=1(noz-comparedword between bias and coordinates),body[0](s) was packed into the unused upper 16 bits of the bias VGPR (v_bias[31:16]), shifting every subsequent coordinate (t,r/slice/face) and trailingclby 16 bits and dropping the final half-register.Tested
Hardware: NVIDIA GeForce RTX 5070 Ti (driver
32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (Build 26200),rustc 1.99.0, DXC1.9.2609.5(dxil 1.9.2609.5).origin/main(3b6a91ed);cargo check --workspace --all-targets: 0 errors, 0 new warnings.cargo build --workspaceandcargo build --release -p xcl: succeeded.cargo test -p xcl --lib a16_ -- --nocapture): passed (0 failed).XCL_DIRECT_DXIL=all,XCL_HEAP_WINDOWS=1,XCL_DRED=1,XCL_DIRECT_SPLIT_INSTRUCTIONS=0):PR (
b68b6e2b):Baseline (
mainancestorf0e8fdd5, same machine and settings):Not tested
_g1616-bit gradient packing (already covered separately by open PR #436).3b6a91edcurrently hits 4 pre-existingorigin/mainsplit-wave64 geometry test failures unrelated to this PR; all targeteda16_GPU and validation tests pass onb68b6e2b.image_sample_b*withA16=1were not specifically instrumented; the 150 s smoke verifies zero regressions across the real title while the targeted GPU tests directly exercise the fixed compute and multi-mip pixel-shader paths.AI use
Diagnosed, implemented, tested, and written with an AI coding assistant; all code, tests, DXIL validation, and real-hardware GPU/smoke runs were executed and verified directly.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:44:03Z.
Review (head
b68b6e2b, diff read, not a merge-check; it conflicts with main, so not built or run):heap_bounds_testsinlower_image.rs, where #2060 (3db0ee4e) addeddirect_image_gather4h_and_8h_are_rejected. The fix lines merge cleanly, and main still has the old layout (lower_image.rs~1094/1106,emit.rs~2659/2671).k == 0) gives the hardware layout (bias alone in the low half of its own dword, then coordinates two per dword), matchingrdna2::mimg_address_dwords. The(h, true)change on the bias entry has no effect, since bias always comes first or right after the 32-bit offset. Lod and clamp still pack after the coordinates, which is right.msg_gs_done_emits_in_dxilandgeometry_export_rejected, which it calls pre-existing on main; worth confirming after the rebase.half_bits/tsharp(already inrecomp/tests.rs) and sits in a module about heap bounds; thegather4_bforms take the same fix but have no test.Fine: the same change in both backends. The CPU layout checks and both GPU tests (bias register with a poisoned upper half) would fail on main, and the GPU tests use
skip_test. About 260 lines, one change. The PR's smoke run is within limits (91 % of frames, 106 % of peak commit).AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:34:03Z.
Consolidated into #3728 (
Direct DXIL: MIMG operand layout fixes (A16 bias VGPR, S# FORCE_UNORMALIZED)), keeping the direct-DXILlower_image.rsfix and its tests while omitting the legacy HLSLrecomp/emit.rschanges. Closing this PR as superseded.(Commented via Antigravity (Gemini 4 Neon).)
Pull request closed