Recompiler: honor S# FORCE_UNORMALIZED and scale unnormalized image_sample_d gradients in direct DXIL #3254
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3254"
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-29T01:10:47Z.
Honor RDNA2 sampler
FORCE_UNORMALIZED(S#word 0 bit 15) on direct-DXILimage_sample*/image_gather4*instructions, and scale explicitimage_sample_dgradients(dx, dy)by mip dimensions when sampling with unnormalized coordinates (UNORM=1orFORCE_UNORMALIZED=1).On RDNA2, a sampler descriptor (
S#) can setFORCE_UNORMALIZED(w[0][15]), causing texel-space coordinates even when theMIMGinstruction itself hasUNORM=0(and forimage_sample_d, explicit gradients(dx, dy)are also in texel units rather than normalized[0, 1]UV space). Previously, direct DXIL only normalized coordinates whend.unormwas set on the instruction and leftimage_sample_dgradients unscaled, soFORCE_UNORMALIZED=1samplers read wrong texels and unnormalizedimage_sample_dselected the wrong mip level.What is in it
crates/xcl/src/gpu/dxil/lower_image.rs:(dx, dy)gradients by mip dimensions (sizes[0..spatial_n]) inmimg_unorm_samplesoimage_sample_dwithUNORM=1or staticFORCE_UNORMALIZED=1computes correct normalized derivatives.w[0] & (1 << 15)inemit_mimgto route staticFORCE_UNORMALIZED=1directly tomimg_unorm_sample(zero runtime branch) while keeping zerogetDimensionsoverhead when staticFORCE_UNORMALIZED=0.S#on non-cube dimensions insample_body, test wave-uniforms0[15]vialw.guardedto divide spatial coordinates (and explicit gradients forhas_d) bygetDimensions(tex, level)whenFORCE_UNORMALIZED=1.force_unorm_tests::static_and_dynamic_force_unormalized_validateand guarded RTX GPU testforce_unorm_tests::gpu_force_unormalized_sample_and_unorm_sample_d.Tested
rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9 (XCL_DXC_DIR), debug for tests and release forxcl-smoke.cargo test -p xcl --lib -- force_unorm_tests gather4_lod_tests heap_bounds_tests --nocapture): 8 passed, 0 failed (0 skips on RTX 5070 Ti; verifiedFORCE_UNORMALIZED=1 IMAGE_SAMPLE_LZ,FORCE_UNORMALIZED=0,UNORM=1 IMAGE_SAMPLE_Dmip 0, andFORCE_UNORMALIZED=1 IMAGE_SAMPLE_Dmip 1).cargo test --workspace -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::): 2601 passed, 0 failed, 49 ignored.SKIPPEDGPU tests on this adapter (26 total): 21no wave64(RTX 5070 Ti is wave32), 3 wave32 per-lane#1426f16/cvt-f16 refusals, 2no heap windows(opt-inXCL_HEAP_WINDOWS=1).ea3b5e4d) 150 s regression run below (0device removals,0crashes,1605frames vs1695onmain,32312 MBpeak commit vs31546 MBonmain).Regression run
Not tested
FORCE_UNORMALIZEDvariants on hardware (covered by DXIL validation; GPU test exercises 2DIMAGE_SAMPLE_LZandIMAGE_SAMPLE_D), and retail titles withFORCE_UNORMALIZED=1samplers (ea3b5e4dsmoke is a regression check).uma_driver::tests::(skipped locally due to pre-existing0x7C10003exit on NVIDIA) andtest_title_runs_and_game_folder_is_untouched.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:53:00Z.
Review (head
ff6be42e, diff read, not a merge-check; it conflicts with main, so not built or run):4250e761(waterfall collapse, the cause of the conflict next to the news0line),waterfall::collapseremoves thev_readfirstlanewrites tos[sb..sb+3]in a collapsed sampler loop. So the newlet s0 = self.sreg(ssamp)(lower_image.rs~1177) reads a stale SGPR there, and its bit 15 decides whether coordinates and gradients are divided by the texture size. Read word 0 from the per-lane VGPR instead (vreg(waterfall_ssamp[pc] - 3), asmimg_s3does); the branch then varies per lane. (Main'smimg_gather4_lodreads s0-s2 the same stale way, an existing bug.)recomp/emit.rs~2808) still ignores FORCE_UNORMALIZED, so the backends disagree.getDimensionsto every non-cube sample with a heap S#; the PR's 150 s smoke run shows 1605 vs 1695 frames and +766 MB peak commit, unexplained.Fine: not superseded (on main FORCE_UNORMALIZED is only honoured in
gather4_l); dividing gradients by the mip-0 size inmimg_unorm_sample, adding offsets after normalising and skipping cubes look right; the GPU test covers the dynamic FORCE_UNORMALIZED sample, UNORM=1sample_dand FORCE_UNORMALIZEDsample_d, and would fail without the fix.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:06Z.
Consolidated into #3728 (
Direct DXIL: MIMG operand layout fixes (A16 bias VGPR, S# FORCE_UNORMALIZED)), which includes theS#FORCE_UNORMALIZED/ unnormalizedimage_sample_dgradient fix and addresses the review feedback on collapsed 4-dword sampler waterfall loops viamimg_s0plus a dedicated GPU regression test. Closing this PR as superseded.(Commented via Antigravity (Gemini 4 Neon).)
Pull request closed