DXIL: forward min_lod_clamp on cubemap sample, sample_bias, and sample_cmp #3408
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3408"
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-29T14:01:02Z.
What is in it
crates/xcl/src/gpu/dxil/lower_image.rs): passmin_lod_clamp(cl) through on cubemap (DIM=3,TextureCubeArray)sample_cmp,sample_bias, andsampleops instead of replacingclwithNone(float undef). DXILdx.op.sample(60),dx.op.sampleBias(61), anddx.op.sampleCmp(64) accept aclampargument independently of texture offsets (whichsample_commonalready emits asundefforCubeArray), matching the HLSL recompiler path.crates/xcl/src/gpu/dxil/graphics_tests.rs): addedps_cube_sample_cl_passes_min_lod_clamp_and_validates(verifying DXC 1.9 validation and non-undefclamp operand in DXIL disassembly forIMAGE_SAMPLE_CL,IMAGE_SAMPLE_B_CL, andIMAGE_SAMPLE_C_CLwithDIM=3) andgpu_ps_cube_sample_cl_honors_min_lod_clamp(GPU pixel-shader test sampling a 2-mipR32_FLOATTextureCubeArraywith mip 0 =1.0, mip 1 =0.25, andclamp = 1.0, checkingsample_cl == 0.25,sample_b_cl == 0.25,sample_c_cl == 1.0, and unclampedsample == 1.0). Both tests failed before the fix (float undefin disassembly; GPU returned[1.0, 1.0, ...]from mip 0) and pass after.Tested
cargo test -p xcl --lib -- cube_sample_cl(2 passed, 0 failed; DXC 1.9.2609.5 validation + RTX 5070 Ti execution).XCL_DXC_DIRset to DXC 1.9.2609.5):cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::— 41 test binaries, 2668 passed, 0 failed, 49 ignored, 9 filtered; 26 runtimeSKIPPED(21no wave64on wave32 RTX 5070 Ti, 3 refused#1426per-lanef16/f32forms, 2no heap windowsopt-in).Regression run
Not tested
test_title_runs_and_game_folder_is_untouchedanduma_driver::tests::(skipped during workspace test run).sample_cmp_level_zero(DXIL op 65 has no clamp operand in SM 6.6).AI use
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-29T14:20:45Z.
Reviewed and tested at
8868613f.Code review notes
clonsample_cmp,sample_bias, andsamplefordim == 3validates cleanly and passes on GPU.crates/xcl/src/gpu/dxil/lower_image.rs: the(None, Some((dx, dy)), _, _) if dim == 3(IMAGE_SAMPLE_D_CL) arm right above line 1361 computes an explicit LODland callssample_level(..., l)without clampinglagainstcl(fmax(l, cl)). Worth either applyingclthere as well or notingsample_gradis intentionally out of scope.Tested locally
32.0.16.2140), AMD Ryzen 7 7800X3D,rustc 1.100.0, DXC1.8.2502.11.cargo test -p xcl --lib cube_sample_cl -- --test-threads=1 --nocapture: 2 passed, 0 failed (ps_cube_sample_cl_passes_min_lod_clamp_and_validates,gpu_ps_cube_sample_cl_honors_min_lod_clamp).AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:16:55Z.
merge-check
base:
d0832e614fhead:
8868613ffbmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (lower_image.rs +3/-3, graphics_tests.rs tests). It changes the default path for pixel-shader cube
image_sample_cl,image_sample_b_clandimage_sample_c_clonly (vertex and compute shaders take the level paths first). Findings: (1) it makes the same threelower_image.rschanges as the older open draft #1939 (mastrr9, which conflicts with main). Of the two, this one has the green checks and the tests, so #1939 is the one to close as its duplicate. (2) AI use names no tool or model; the commit subject usesdxil:, not an existing area (Recompiler:). (3) The PR's suite run skippedtest_title_runs_and_game_folder_is_untouchedanduma_driver::tests(stated under Not tested; the run above covers them). (4) Not from this PR: the direct DXILsample_cmparm still ignores the bias ofsample_c_b*, while the HLSL path uses SampleCmpGrad scaled by 2^bias. Fine: the clamp goes in the right operand of DXIL ops 60/61/64 (after bias in 61, after the compare value in 64), cubes get undef offsets, it matches the HLSL path'stail(), and the TiledResources flag is set as for non-cube samples. The tests' VGPR layouts follow RDNA2 MIMG order, and the GPU test tells clamped from unclamped results for all three ops and callsskip_test. The disassembly test fails on main.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (c4b5869f): 1516 -> 1675 frames shown (110 %; last presents per 2 s: 61 60 60), peak commit 18133 -> 17154 MB, 0 device removals, 0 crashes.verdict: safe to merge (close the older duplicate #1939; the description should name the AI model and use the Recompiler area)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T05:41:21Z.
merge-check claim
head:
8868613ffbImported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T05:48:08Z.
merge-check claim
head:
8868613ffbImported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T05:54:00Z.
merge-check
base:
d0832e614fhead:
8868613ffbmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 1 failed, 51 ignored; 29 SKIPPED lines
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:44:23Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_image.rs; line 1336In a pixel shader, the comparison arm
(Some(z), _, _, _)matches before the lod, grads and bias arms. Soimage_sample_c_l,image_sample_c_d(_cl)andimage_sample_c_b(_cl)all become a plain implicit-LODsampleCmp, and the explicit LOD, gradients or bias are silently dropped. A PS IMAGE_SAMPLE_C_L with LOD 3.0 (or C_B_CL with bias +2) on a mip-mapped shadow cube compares at the derivative LOD (mip 0 in a full-screen pass), so shadow/PCF results are wrong with no error. Matching the lod/grads/bias arms first, then emitting sampleCmpLevel / sampleCmpGrad / sampleCmpBias, would keep them.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:44:23Z.
Review: COMMENTED
Review of
8868613f: 2 finding(s).The cube min_lod_clamp fix itself looks correct. The two findings below are older bugs in the same match this PR edits, not caused by it, but the cube
c_b_clcase the PR adds still loses its bias because of the first one. 1 are inline. These are on lines outside the diff:crates/xcl/src/gpu/dxil/lower_image.rs:1332: Thehas_lz || !pscomparison arm always usessample_cmp_level_zero, which ignores bothcland an explicitlod. The non-comparison arms raise LOD 0 tofloor(cl), but comparison samples outside a pixel shader never do. A VS/CS IMAGE_SAMPLE_C_CL with clamp 1.0 (or IMAGE_SAMPLE_C_L with LOD 2) on a 2-mip texture compares mip 0 instead of mip 1. With this PR forwarding the clamp for cube comparisons in PS only, the same instruction now behaves differently by stage.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:14:24Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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.