Direct DXIL: MIMG operand layout fixes (A16 bias VGPR, S# FORCE_UNORMALIZED) #3728
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3728"
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-12-02T20:33:05Z.
Consolidates #3351 and #3254 into a single direct-DXIL fix across
crates/xcl/src/gpu/dxil/lower_image.rsandcrates/xcl/src/gpu/rdna2.rs, addressing the #3254 review feedback on collapsed 4-dword sampler waterfall loops, keepingrdna2::mimg_vgpr_usesin sync withlower_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) andcrates/xcl/src/gpu/rdna2.rs(mimg_vgpr_uses): fix A16 biased MIMG address packing (from #3351). On RDNA2 withA16=1, thef16LOD 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 (matchingrdna2::mimg_address_dwords). Mark bothhas_bandbody[0](k == 0) withstarts = truein bothlower_image::mimg_addr_layoutandrdna2::mimg_vgpr_usessobody[0]is not unpacked frombias[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 (norecomp/emit.rschanges).crates/xcl/src/gpu/dxil/lower_image.rs(Lw::mimg_s0,Lw::mimg_unorm_sample,Lw::mimg): honorS#word 0 bit 15 (FORCE_UNORMALIZED) and scale explicit(dx, dy)gradients by mip-0 dimensions for unnormalizedimage_sample_d(from #3254). Static samplers withFORCE_UNORMALIZED=1lower directly throughmimg_unorm_sample(zero runtime branch); dynamic heap samplers on non-cube dimensions guardGetDimensionsnormalization ons0[15]. ReadsS#word 0 viamimg_s0(self.vreg(v - 3)whenwaterfall_ssampcollapsed the 4-dword sampler loop atpc, otherwiseself.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 (includingIMAGE_GATHER4_Band poisoned upper 16 bits in every bias VGPR), multi-mip PSIMAGE_SAMPLE_BwithA16, static and dynamicFORCE_UNORMALIZED, unnormalizedIMAGE_SAMPLE_Dgradients, a collapsed 4-dword sampler waterfall pixel shader with stales8 = 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
rustc 1.99.0 (b940084d7 2026-09-28), DXC1.9.2609.5.cargo build --release -p xcl: succeeded with 39 warnings (matchingorigin/main5ad98adbc, 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 --workspaceandcargo test --workspace -- --test-threads=4): 3011 passed, 0 failed, 52 ignored across 44 targets, 24SKIPPED(22no wave64on NVIDIA SM 6.6 adapter, 2no heap windows/ opt-inXCL_HEAP_WINDOWS=1).Regression run
main(5ad98adbc360225ac8a57ad9661e16fe8df9d8dd):This PR (
99de451f6cc1c3c7bb2b43193e13e2c7c32ca65e):Not tested
wave64GPU tests skipped on NVIDIA.XCL_HEAP_WINDOWS=1tests (2 skipped).recomp/emit.rsparity (intentionally omitted from this direct-DXIL PR).FORCE_UNORMALIZEDguard on a shader-heavy title.FORCE_UNORMALIZEDMIMG path.AI use
lower_image.rs, syncedrdna2::mimg_vgpr_uses, implementedmimg_s0for collapsed 4-dword sampler waterfall loops, wrote and ran themimg_layout_tests, full workspace test suite, and paired 60 s smoke runs, and drafted this PR description.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 findingIn 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
mainwas wrong. TheFORCE_UNNORMALIZEDtest reads S# word 0 from the right place, also after a collapsed sampler waterfall (the four vector registers are required to be consecutive, sov - 3is 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
main395405e4)cargo test --workspace --no-fail-fast -- --test-threads=4(debug): 3017 passed, 0 failed, 56 ignored; 25 SKIPPED, the same tests as onmain(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 (main395405e4, same title and time: 1689 frames, 18158 MB). The start screen only; with warm caches it says nothing about the cost in note 1.Notes, none blocking
GetDimensions, the divides, a variable per coordinate), roughly doubling the IR of a plain sample, for a bit thatCreateSamplernever sets (mainwrites[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.mimg_gather4_lodstill reads S# words 0 to 2 from the scalar registers after a collapse (only word 3 goes throughmimg_s3), and the_G16gradient forms are laid out as 32-bit gradients. Both read, not run.a16_biased_sample_keeps_bias_in_its_own_vgprassertsdis.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.
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 1122Finding (medium; the mismatch is measured, its effect is read):
rdna2::mimg_vgpr_usesstill 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 ismimg_vgpr_usesin the same file, which still hasshape.push((h, !a16))for the bias and!a16 || (grad_n != 0 && k == 0)for the body. Onmainit and this table agreed; now they do not.Scratch test on this head (A16 = 1,
rdna2::vgpr_useson the encoded instruction) against what the table here reads:vgpr_usesaddress registersIMAGE_SAMPLE_B1DIMAGE_SAMPLE_B3D, cube, 2D arrayIMAGE_SAMPLE_B_CL2DIMAGE_GATHER4_B2D array(2D
sample_bis 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), theusedset for vertex / geometry input setup andmax_vgprinkernel.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 lastVADDRx.Suggested: change the two lines in
mimg_vgpr_usesin the same commit, and add a test that walks the forms and compares the two tables, so they cannot drift apart again.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-03T03:22:27Z.
Thanks @vasanex for catching the
rdna2::mimg_vgpr_usesdrift! Fixed in99de451f6:crates/xcl/src/gpu/rdna2.rs(mimg_vgpr_uses) to setstarts = trueonhas_bandk == 0ofbody, matchingmimg_address_dwordsandlower_image.rssovgpr_uses(and downstream liveness / input-setup /max_vgprpasses) reports every address VGPR read by the lowering, including NSAVADDRx.mimg_addr_layoutincrates/xcl/src/gpu/dxil/lower_image.rsand addedmimg_layout_tests::mimg_vgpr_uses_matches_lower_image_and_address_dwords, which walks all 64 non-G16IMAGE_SAMPLE*/IMAGE_GATHER4*opcodes × 6 dimensions ×A16 ∈ {0, 1}(768 cases) plus NSA cases for all four biased A16 forms (IMAGE_SAMPLE_B1D / 3D / cube / 2D array,IMAGE_SAMPLE_B_CL2D,IMAGE_GATHER4_B2D array) and assertsrdna2::vgpr_uses,rdna2::mimg_address_dwords, andlower_image's layout all agree.FORCE_UNORMALIZEDguard under Not tested in the PR description.Re-verified on
99de451f6:cargo build --release -p xcl: ok, 39 warnings (0 new vsmain5ad98adbc).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 ignoredacross 44 targets (24 SKIPPED: 22no wave64, 2no heap windows).ea3b5e4d, RTX 5070 Ti):exit: 0x0,1716frames (60 60 60presents/2 s),0device removals,0crashes,16104 MBpeak commit (updated in the PR description).python scripts/pr_check.py --local:description ok.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 1122Fixed in
99de451f:mimg_vgpr_useshas 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 ontomain395405e4):mimg_layout_tests: 6 passed, 0 failed;cargo test -p xcl --lib -- gpu::dxil gpu::rdna2: 383 passed, 0 failed, 5 ignored; withmain's two lines put back inmimg_vgpr_uses,mimg_vgpr_uses_matches_lower_image_and_address_dwordsfails atIMAGE_SAMPLE_B1D 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 intomimg_addr_layoutI 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
main395405e4(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 onmain); 60 s offline smoke: 1688 frames, exit 0x0, 0 device removals, 0 crashes, peak commit 18513 MB (main: 1689 frames, 18158 MB).Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T06:29:17Z.
merge-check
base:
078358a058head:
99de451f6cmerge: 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 descriptionis red; otherwise no blocking finding, the suite passes and the smoke run is cleanhardware / 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
Nit
Checked and fine
5ad98adb(the merge base) and the PR head99de451fon the same title for 60 s: 1716 vs 1159 frames, peak commit 16104 vs 16044 MB, no device removals or crashesHow this was tested
078358a0, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main078358a0and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and 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.
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
99de451f6untouched 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 on99de451f6). Also noted the #3663 coordination point: if #3663 merges first, we will rebase and replace mimg_s0 with mimg_sword(d.pc, ssamp, 0).Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:33:42Z.
merge-check
base:
078358a058head:
99de451f6cmerge: 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
Nit
Checked and fine
5ad98adb(the merge base) and the PR head99de451fon the same title for 60 s: 1716 vs 1159 frames, peak commit 16104 vs 16044 MB, no device removals or crashesHow this was tested
078358a0, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main078358a0and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.