dxil: emulate explicit-LOD gather4_l(_o) and support UNORM=1 non-cube sampling #1951
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!1951
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1951/head"
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?
@raylitebull on GitHub · 2026-11-24 23:49 UTC · original
raylitebull:feat/dxil-gather4-lod-unorm→main· +615 −2 · 1 files · 1 commits · merged 2026-11-25 10:40 UTCEmulates explicit-LOD
image_gather4_l/image_gather4_l_o/image_gather4_c_l/image_gather4_c_l_o(plus_clclamp,A16,D16, andUNORM=1/FORCE_UNORMALIZED) in the direct RDNA2 -> DXIL translator across all 8 RDNA2 address modes, and adds non-cubeUNORM=1coordinate normalization forsample*andgather4*.Part of #1269 and #1833.
What is in it
crates/xcl/src/gpu/dxil/lower_image.rs(mimg_gather4_lod,apply_rdna2_addr_mode,apply_depth_compare): emulate explicit-LODgather4_l(_o)onTexture2DandTexture2DArrayvia 4 mip-leveldx.op.textureLoadtaps in hardware gather order(-,+), (+,+), (+,-), (-,-)honoring all 8SQ_TEX_CLAMPaddress modes, S# signed S5.8LOD_BIAS(s2[13:0] / 256.0), T#MIN_LOD(tw1[19:8], u4.8 /256.0—MIP_FILTER=nonereadsfloor(T# MIN_LOD)at every LOD, and filtered samplers raise S#-clamped LOD toT# MIN_LODbefore half-up rounding), S#[min_lod, max_lod]+mip_filter == 0clamping, RDNA2 half-up mip rounding (floor(lod + 0.501953125)=257/512,0x3F00_8000) +GetDimensionsmip count, signed 6-bit texel offsets (has_o), S# border color types (s3[31:30]),SQ_TEX_DEPTH_COMPARE(s0[14:12]), and#1969's MIMG heap-bounds guard (self.guarded(run, ...)).crates/xcl/src/gpu/dxil/lower_image.rs(mimg_unorm_sample): normalize unnormalized texel coordinates (and optional signed 6-bit offsets) via mipGetDimensionsfor non-cube textures (D1,D2,D3,D1Array,D2Array) before DXIL sample/gather emission, with#1969heap-bounds guard (safe_tw0forimplicit_lod).gather4_lod_tests:gather4_lod_variants_translate_and_validate,gather4_lod_emits_bias_and_rdna2_half_up_rounding,gather4_lod_honors_tsharp_min_lod_and_mip_filter_none, andnon_cube_unorm_sampling_translates_and_validate.Tested
rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly ontoae0518c(ff184be).ff184beintegrates the T#MIN_LODfix (@brothernogcatch) and#1969heap-bounds guard atopae0518cvia pure git during a local test hold; queued for GitHub ActionsBuild and testand fresh AMD / NVIDIA verification (gather4_lod_tests).e201efepassedcargo check --workspace --tests,gather4_lod_tests(3/3), and@upipibi's 5-case DXIL verification.scripts/smoke.ps1regression pair on AMD Radeon RX 9070 (@Toons29): passed (0 device removals, 0 crashes).Regression run
60 s
scripts/smoke.ps1pair on exact headff184bevsmain(AMD Radeon RX 9070, driver 32.0.32029.2010, Windows 11 26300, release,XCL_NETWORK=0on a retail title), contributed by@Toons29:main:
this PR:
Not tested
cargo check/gather4_lod_testsandscripts/smoke.ps1on updated headff184be, runtime GPU pixel comparison against HLSL on AMD / NVIDIA / Intel hardware, wave32-only adapters, and Linux/Wine/vkd3d-proton.AI use
@upipibi on GitHub · 2026-11-25 00:06 UTC · original
Checked on an RTX 3070 (Ampere, driver 616.56, Windows 11, debug build) at
940c51b.The batch run is clean:
dxil::andbvh::units pass, and so do thegpu_tests withXCL_DIRECT_DXIL=0and1(110 passed each, same asmain). None of the existing GPU tests reaches agather4_lwith a level above 0, though, so I ran a pixel-shader check. It has an 8×8 texture with 4 levels, where level k holds100·k + x. The test reads the 2×2 footprint and goes through the direct translator (draw_console_viewsrouted throughdirect_or).7f804be(direct / HLSL)MIP_FILTERpointMAX_LOD1.0MIP_FILTERnoneMIP_FILTERpointThe last row comes from
l_rnd = ROUND_NE(l). RDNA2 picks the level asfloor(lod + 0.501953125), measured on gfx1030/gfx1036 in boykopovar/AnyPS5's hardware-oracle runs. That is, it rounds half up, so LOD 0.5 reads level 1 and 2.5 reads level 3, where round-to-even gives 0 and 2. From reading only (not run): the S#LOD_BIASisn't added before the clamp either.Overlap: #1812 (brothernog, open and mergeable) already does explicit-LOD
gather4_l/_l_ofor 2D and 2D arrays on both backends. It applies the bias, uses the measured rounding, and has GPU tests. This PR'sgather4_lhalf duplicates it for the direct path. TheUNORM=1non-cube sampling half is separate and could stand as its own PR.AI-assisted (Claude Code). Synthetic tests only.
@raylitebull on GitHub · 2026-11-25 00:16 UTC · original
Thanks for the thorough pixel check and catch,
@upipibi!Updated
#1951cleanly on top of80f4819in commite201efeto fix both points incrates/xcl/src/gpu/dxil/lower_image.rs(mimg_gather4_lod):LOD_BIAS(s2[13:0]): extracts the signed 14-bit S5.8LOD_BIAS(((s2 << 18) as i32 >> 18) / 256.0) and adds it tolodbefore optionalcland[min_lod, max_lod]clamping.ROUND_NEtofloor(lod + 0.501953125)(op::ROUND_NI,257/512/0x3F00_8000) soLOD 0.5selects level1andLOD 2.5selects level3(withMIP_FILTER=nonestill collapsingmax_lod = min_lod).Verified locally with
cargo check --workspace --testsandcargo test -p xcl --lib gather4_lod_tests(3 passed, 0 failed,dxil 1.8.2502.11validated, including newgather4_lod_emits_bias_and_rdna2_half_up_rounding); GPU pixel checks have not been re-run one201efeyet.Re
#1812: understood on the overlap forgather4_l/_l_o! If#1812merges first (or if maintainers prefer keeping#1951focused strictly on non-cubeUNORM=1normalization), I am happy to rebase#1951down to justmimg_unorm_sampleand its tests.@Anon64 on GitHub · 2026-11-25 00:18 UTC · original
Regression run for this PR: head
940c51b, based onmain62265d3. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s, in one batch with themainrun.main
62265d3:this PR:
No device removals or crashes; 99 % of main's frames, 102 % of its peak commit.
Not tested: the whole suite; the direct DXIL path this PR changes (these runs use the default HLSL path,
XCL_DIRECT_DXILunset).Written with Claude Code (Claude Opus 5.5) from runs on this machine.
@raylitebull on GitHub · 2026-11-25 00:47 UTC · original
Quick overlap note: full credit to #1812 (@brothernog), which already implements explicit-LOD
gather4_l(_o)across both the HLSL and Direct DXIL backends.#1951 adds Direct DXIL support for
UNORM=1non-cube sampling (mimg_unorm_sample) as well as compare/clamp explicit-LODgather4forms (gather4_c_l/gather4_cl). Once #1812 lands, we will rebase and trim #1951 down to only the non-overlappingUNORM=1and_c_/_clpaths.@upipibi on GitHub · 2026-11-25 00:49 UTC · original
Re-checked
e201efeon the RTX 3070 (driver 616.56, Windows 11, debug) with the same pixel test through the direct translator, plus one bias case:940c51be201efeMAX_LOD1.0MIP_FILTERnoneLOD_BIAS−0.75 (0x3F40) → 1.25Both points are fixed on hardware. The overlap with #1812 for the
gather4_lpart still stands; that's for the maintainers to pick.AI-assisted (Claude Code). Synthetic tests only.
@brothernog on GitHub · 2026-11-25 01:09 UTC · original
Heads-up on overlap, from reading the diff, not from a run: #1812, opened earlier, emulates the same
image_gather4_l/_l_oforms with four mip-levelLoads and the S# address modes. It does this in both the HLSL and the direct DXIL backend, with GPU pixel tests on both: 18 S# / T# cases, plus @upipibi's three review cases. The two PRs conflict in the same block oflower_image.rs, so whichever lands second needs to be rebuilt on the other.Two differences:
MIN_LODand readsfloor(T# MIN_LOD)withMIP_FILTERnone, per the gfx1036 measurement @upipibi cited there. As I readmimg_gather4_lod, it doesn't read the T#MIN_LOD, and withMIP_FILTERnone it collapses the range to the S#MIN_LOD.gather4_c_l,_c_l_o) andUNORM=1, which #1812 leaves alone.One way to split it: #1812 for the uncompared
gather4_llevel and taps on both backends, and this PR rebased on top of it for the compare forms andUNORM. The maintainers can decide.This comment was AI-assisted.
@raylitebull on GitHub · 2026-11-25 01:13 UTC · original
Thanks for the detailed comparison, @brothernog! Agreed on the clean split: once #1812 lands for uncompared explicit-LOD \gather4_l\ / _l_o\ across HLSL and Direct DXIL (including \T# MIN_LOD\ floor handling), we will rebase and trim #1951 strictly down to the non-overlapping \gather4_c_l\ / _c_l_o\ compare forms and non-cube \UNORM=1\ sampling paths.
@raylitebull on GitHub · 2026-11-25 01:54 UTC · original
Thanks for catching the missing T#
MIN_LODclamping,@brothernog!Updated
#1951cleanly ontoae0518c(ff184be):MIN_LOD(tw1[19:8], u4.8 /256.0) inmimg_gather4_lod:MIP_FILTER=nonenow readsfloor(T# MIN_LOD)at every LOD, and non-noneMIP_FILTERraises the S#-clamped level toT# MIN_LODbefore half-up+ 0.501953125rounding (addedgather4_lod_honors_tsharp_min_lod_and_mip_filter_nonetest).#1969): wiredself.guarded(run, ...)(plussafe_tw0forimplicit_lod) into bothmimg_gather4_lodandmimg_unorm_sample(and we can still trim#1951cleanly togather4_c_l(_o)+UNORM=1if#1812lands first).Pushed
ff184befor GitHub ActionsBuild and testand fresh verification!@upipibi on GitHub · 2026-11-25 02:38 UTC · original
Re-checked
ff184beon the RTX 3070 (driver 616.56, Windows 11, debug) through the direct translator. The same six level cases as before all pass: LOD 1.0; LOD 2.0 under S#MAX_LOD1.0;MIP_FILTERnone; LOD 0.5; LOD 2.0 with S#LOD_BIAS−0.75; and LOD 0.499 (literal), which RDNA2 reads at level 1. For comparison, #1812 atb0f160fstill reads level 0 for that last case.AI-assisted (Claude Code). Synthetic tests only.
@DavidM1911 on GitHub · 2026-11-25 02:59 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!
@JJAutoCompare on GitHub · 2026-11-25 03:14 UTC · original
Tested
Verified PR #1951 from a clean checkout at
ff184bedd65af7d0e74a32a1515e0b7d591d8242. GitHub showed the PR open at that SHA before and after the run.x86_64-pc-windows-msvc, unoptimized test profile. The runtime log confirmeddxcompiler.dllanddxil.dll1.9.2609.5 from%LOCALAPPDATA%\XclTooling\dxc-1.9.2609\bin\x64viaXCL_DXC_DIR.XCL_ADAPTER=A770,CARGO_TARGET_DIR=L:/XclTooling/pr2014-1c971de6/target.TEMPandTMPpointed to the run’stempdirectory underL:/XclTooling/pr1951.1 passed, 0 failed, 0 ignored, 0 skipped (1,066 filtered out, Cargo exit 0). The one fixture translated seven synthetic
UNORM=1RDNA2 shaders and DXC accepted all seven emitted DXIL containers. The cases cover samples on 1D, 2D, 3D, 1D-array, and 2D-array textures, plus 2D and 2D-array LOD-zero gathers, including a 3D sample offset and a 2D-array gather offset with D16 output.Not tested
GPU execution, numerical sampling or pixel parity, bounds behavior, the explicit-mip
gather4_lemulation covered separately by #1812, retail titles, smoke runs, and the broader suite.AI use
T3 Code / Codex (gpt-6.2-sol) ran the checked-in fixture and wrote this report.
@Toons29 on GitHub · 2026-11-25 10:32 UTC · original
Regression run of
ff184bedon the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon568e7db7, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 104 % of
main's frames, 102 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.@raylitebull on GitHub · 2026-11-25 10:37 UTC · original
Thanks @Toons29 for running and sharing the exact-head 60 s
scripts/smoke.ps1pair onff184be(0 device removals, 0 crashes) — added to the PR description!@DavidM1911 on GitHub · 2026-11-26 06:51 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin