Recompiler: image_sample_*_g16 reads 16-bit gradients, packed in halves #436
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!436
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-436"
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?
@sennecools on GitHub · 2026-11-24 00:16 UTC · original
sennecools:recomp-mimg-g16→main· +75 −2 · 2 files · 1 commits · openThe
_g16sampling forms carry their derivatives as 16-bit halves, and the dx and dy groups each start a dword (2D: dsdx|dtdx, dsdy|dtdy; 3D: dsdx|dtdx, drdx|pad, dsdy|dtdy, drdy|pad). XCL read them as 32-bit floats. That made the gradients wrong and moved the coordinates, and every address component after them, onto the wrong VGPRs. No issue covers this.The retail title I ran uses none of these opcodes: an
xcl shaderscensus of its pack found 0 instructions of all 16IMAGE_SAMPLE_*_G16variants. This is a correctness fix for titles that do use them.What is in it
crates/xcl/src/gpu/recomp/emit.rs:_g16gradients are laid out as 16-bit halves, each group starting a dwordcrates/xcl/src/gpu/recomp/tests.rs: two new testssample_d_g16_reads_packed_half_gradientschecks the HLSL addresses for 2D and 3Dgpu_sample_d_g16_coordinates_follow_packed_gradientsruns a 2Dimage_sample_d_g16on the GPU, with decoy coordinates where 32-bit gradients would put themTested
cargo test --workspace -- --test-threads=4(debug): 668 passed, 0 failed, 41 ignored. No SKIPPED tests, and both new tests pass.emit.rschange reverted,cargo test -p xcl --lib g16: 0 passed, 2 failed (both new tests).cargo build --release -p xclfor the regression runRegression run
The retail title, 120 s, offline, release build. The
gpu:line comes from smoke.ps1, which picked the virtual display adapter; the real GPU is the one above.main:
this PR:
Not tested
_g16instructions in its pack), so the regression run only shows that nothing else broke._cl,_oandcvariants have no test of their own.AI use
@alpz1000 on GitHub · 2026-11-24 00:25 UTC · original
Independent RTX 3060 check of
1b250b6b031954a05ebff9ca74b60e7188678e49.Tested on a GeForce RTX 3060 12 GB (610.88), Intel i5-8400, Windows 11 Home 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc, MSVC 14.44.35230, and DXC 1.9.2602.17 (SDK 10.0.26100), debug.
cargo test -p xcl --lib g16 -- --nocapture:emit.rsrestored from its parent (PR tests kept)The baseline failed both the generated HLSL check and GPU readback. For lane 0, the GPU returned
[3.0, 3.0, 15.0, 1.0]instead of[0.0, 0.0, 0.0, 1.0]. Both tests passed with the fix.Not tested: full workspace, retail titles, or other GPU adapters in this run.
AI use: OpenAI Codex (GPT-6) ran the tests locally and drafted this report from the actual results.
@AC-Storm-YT on GitHub · 2026-11-24 00:35 UTC · original
Test run on AMD RDNA4 – commit
1b250b6(this PR's head, as is), clean treeTested
backend 'real' – AMD Radeon RX 9070 XT); AMD Ryzen 7 9800X3D; Windows 11 Pro build 26200; Rust 1.100.0stable-x86_64-pc-windows-msvc, debug; DXC 1.8.2502.11cargo build --workspace: okcargo test --workspace -- --test-threads=4: 668 passed, 0 failed, 41 ignored. No SKIPPED tests.gpu_sample_d_g16_coordinates_follow_packed_gradients(GPU),sample_d_g16_reads_packed_half_gradientsNot tested
smoke.ps1runmainRun and report: Claude Code (Claude Opus 5.5).
@TheHoracio on GitHub · 2026-11-24 00:36 UTC · original
Test report on AMD RDNA3: RX 7800 XT (16 GB), driver 32.0.32015.7029, Ryzen 7 9800X3D, Windows 11 Pro 10.0.26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug build. No retail data was used.
Tested: the PR head
1b250b6as it is (on its basedb1ddb2, not merged onto current main).cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 668 passed, 0 failed, 41 ignored, no SKIPPED tests.gpu_sample_d_g16_coordinates_follow_packed_gradients(on the GPU, RDNA3) andsample_d_g16_reads_packed_half_gradients.Not tested: a regression run on a title, a release build, and the head merged onto current
main.AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above.
@Luqueze on GitHub · 2026-11-24 00:45 UTC · original
Independent RTX 4070 SUPER (Ada, wave32 only) check of
1b250b6b031954a05ebff9ca74b60e7188678e49, whole workspace.Tested on a GeForce RTX 4070 SUPER 12 GB, driver 617.42 (32.0.16.1742), AMD Ryzen 7 5700X3D, 32 GB, Windows 11 Pro build 26300, Rust 1.100.0
stable-x86_64-pc-windows-msvc, VS 2022 Build Tools 17.14, DXC 1.9.2602.17 (SDK 10.0.26100.0), debug. NoXCL_SAMPLE_*set.cargo build --workspace+cargo test --workspace -- --test-threads=4 --nocapture:db1ddb2no wave64)1b250b6no wave64)main2997c9a(no conflicts, not committed)no wave64)sample_d_g16_reads_packed_half_gradientsandgpu_sample_d_g16_coordinates_follow_packed_gradients; both pass, and the GPU one ran on the card (no SKIPPED line for it).gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.cargo test -p xcl --lib g16 -- --nocaptureon the PR head, 3 runs: 2 passed, 0 failed each time.emit.rsrestored from its parent (PR tests kept): 0 passed, 2 failed. The GPU test returned[3.0, 3.0, 15.0, 1.0]for lane 0 instead of[0.0, 0.0, 0.0, 1.0], the same values as the RTX 3060 run above.Display 4101(TDR) events during the runs.Not tested: release build, retail titles /
scripts/smoke.ps1,XCL_SAMPLE_*game-data tests, 1D / 3D / cube on the GPU (the PR's GPU test is 2D only), other adapters.AI use: Claude Code (Claude Opus 5.5) ran the builds and tests on this machine and drafted this report from their output.
@QemmHD on GitHub · 2026-11-24 01:18 UTC · original
Review: the layout matches LLVM's GFX10 codegen for
image_sample_d_g16with half gradients (llvm.amdgcn.image.sample.g16.ll): 1Dv[0:2]= dsdh, dsdv, s; 2D packs dsdh|dtdh and dsdv|dtdv (v_perm_b32 … 0x5040100); 3Dv[2:8]= dsdh|dtdh, drdh, dsdv|dtdv, drdv, s, t, r.One gap:
tests.rs:2362-2400– the GPU test uses zero gradients on a one-mip texture with point filtering, so it can't observe the gradient values; the f16 decode and the 3Ddrdx|paddword are only checked as HLSL text. A case with a 2-mip view (runner::ViewTextureviadraw_console_views) and one non-zero gradient that should select mip 1 would check them on hardware; for 3D, a non-zerodrdxalone also pins the padded dword.AI-assisted review (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.
@MiguelMachado-dev on GitHub · 2026-11-24 22:38 UTC · original
The direct DXIL path has the same bug:
dxil::lower_imagestill builds the address layout the wayemit.rsdid before this PR, one 32-bit dword per gradient (crates/xcl/src/gpu/dxil/lower_image.rs:387-388onmain689f2db). WithXCL_DIRECT_DXIL=1, a_g16sample still reads its gradients as 32-bit floats and its coordinates from the wrong VGPRs. The same change (16-bit halves, with the dx and dy groups each starting a dword) applies there.gpu_sample_d_g16_coordinates_follow_packed_gradientsgoes throughrunner::run_code_with, which takes the direct path whenXCL_DIRECT_DXIL=1is set, so I expect it to fail on that path untillower_image.rsgets the fix too. I have not run it.Related: #1797 (
rdna2::vgpr_usescounting the registers the translators read) has a G16 exception that counts the derivatives as 32-bit, to match the translators onmain. Once this PR is merged, that exception is wrong, and I will take it out of #1797.(Written with Claude Code, Claude Opus 5.5, from reading the code at
main689f2dband this PR's head1b250b6. Nothing was run.)@DavidM1911 on GitHub · 2026-11-25 14:15 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.