D3D12.X: heap samplers and views carry their real S#/T# words (incl. T# MIN_LOD) #3730
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3730"
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:50:02Z.
Consolidates #3248 and the
T# MIN_LODpart of #3258 ontomain, addressing all review findings from @Foniass (dropping #3258's unrelated wildcard SRV/3D-UAV count andCreateUnorderedAccessViewAtchanges, fixingMIN_MAG_ANISOTROPIC_MIP_POINTmip-filter encoding, documenting the HLSL implicit-LOD offset path, and addingMostDetailedMip > 0D3D12 parity coverage).Previously:
dev_create_sampler_xwrote[0, 0, 0, slot.index & 0xFFF]into the console sampler heap, so shader paths that decodeS#directly (mimg_gather4_lodforIMAGE_GATHER4_L*/IMAGE_GATHER4_C_L*ingpu/dxil/lower_image.rs, and the HLSL fallback implicit-LOD offset path ingpu/recomp/emit.rswhich readsMIP_FILTERfromS#word 2) sawWRAP,MAX_LOD = 0,MIP_FILTER = NONE,DEPTH_COMPARE_FUNC = NEVER, and transparent-black border for heap-created samplers.srv_tsharp_from_descleftT# MIN_LOD(t[1][19:8], u4.8 fixed-point relative toBASE_LEVEL) at0for all SRV dimensions, so direct-DXILIMAGE_GATHER4_L*ignoredResourceMinLODClamp.What is in it
crates/xcl/src/gpu/desc.rs:xcl_sampler_for_desc(&D3D12_SAMPLER_DESC, u32) -> [u32; 4]encoding RDNA2S#words (w[0..2]andw[3][31:30]border color type, keepingsampler_heap_index & 0xFFFinw[3][11:0], saturatingMaxLOD = f32::MAXto0xFFF, encoding point mip asSQ_TEX_MIP_FILTER_POINT = 1including forMIN_MAG_ANISOTROPIC_MIP_POINT0x54and its variants, and linear mip as2).gpu/recomp/emit.rs), reading the realMIP_FILTERfromS#word 2 means linear-mip heap samplers now take the two-mip blend instead of collapsing to a singleSampleas when word 2 was zero.view_tests::sampler_desc_encodes_and_decodes_back.crates/xcl/src/hle/d3d12x/real.rs:xcl_sampler_for_descintodev_create_sampler_x(keeping[0, 0, 0, slot.index & 0xFFF]fallback whendescis null).encode_tsharp_min_lod(clamp, base_level)and populateT# MIN_LOD(t[1][19:8]) insrv_tsharp_from_descacross all 7 SRV dimensions that carryResourceMinLODClamp(1D,1DArray,2D,2DArray,3D,Cube,CubeArray). Because D3D12ResourceMinLODClampis measured from resource mip 0 while GFX10T# MIN_LODis relative toBASE_LEVEL(MostDetailedMip), this encodesmax(0, clamp - base_level)(verified against native D3D12SampleLevelon hardware).srv_tsharp_encodes_min_lod_across_dimensions_and_most_detailed_mip, WARP testdev_create_sampler_writes_ssharp_and_copy_preserves_it, and GPU parity testsgpu_heap_sampler_gather4_l_and_c_l_use_created_ssharpandgpu_srv_tsharp_min_lod_clamp_controls_image_gather4_l_mip(which compares direct-DXILIMAGE_GATHER4_Lagainst native HLSLSampleLevelfor bothMostDetailedMip = 0andMostDetailedMip = 1).Tested
rustc 1.99.0 (b940084d7 2026-09-28), DXC1.9.2609.5.cargo build --release -p xcl: succeeded, 39 warnings (0 new vsorigin/main39).cargo test -p xcl --lib -- sampler_desc_encodes_and_decodes_back dev_create_sampler_writes_ssharp_and_copy_preserves_it gpu_heap_sampler_gather4_l_and_c_l_use_created_ssharp srv_tsharp_encodes_min_lod_across_dimensions_and_most_detailed_mip gpu_srv_tsharp_min_lod_clamp_controls_image_gather4_l_mip --nocapture): 5 passed, 0 failed, 0 ignored (0 skipped). Confirmed native D3D12SampleLevelreturns[0.5, 0.25, 0.5, 0.75]and translatedIMAGE_GATHER4_Lmatches[0.5, 0.25, 0.5, 0.75]for(MostDetailedMip=0, clamp=1.0),(0, 0.0),(1, 1.0), and(1, 2.0)..\scripts\test.ps1(full workspace build, bench compile-check, and test suite, no--skipfilters): 3,010 passed, 0 failed, 52 ignored across 44 test binaries (GPU tests skipped on this wave32-only adapter: 24 total — 22no wave64, 2no heap windowsopt-in).Regression run
Base (
origin/main817eb1fc9):PR (
1f2b9f045):Not tested
XCL_DIRECT_DXIL=0) with linear-mip heap samplers.BORDER_COLOR_TYPE == 3maps to standard border types0/1/2).gpu/desc.rs::image_d3d12passest.min_loddirectly toResourceMinLODClampwithout addingt.base_level.AI use
T# MIN_LODpart of #3258 ontomain, fixedMIN_MAG_ANISOTROPIC_MIP_POINTmip-filter encoding andMostDetailedMip > 0T# MIN_LODoffset relative toBASE_LEVEL, added the native-D3D12SampleLevelparity test, and ran release build, fullscripts/test.ps1, and 60 s retail smoke verification.Imported from ivall/xcl. Originally posted by vasanex on 2026-12-03T02:44:38Z.
Review: COMMENTED
Review of
1f2b9f04(code reading and the tests named below, not a merge-check) · no findingsIn short:
CreateSamplernow writes the sampler's real S# words where it wrote zeros, and SRVs carry T#MIN_LODrelative to the view's first mip. The encoding matches the decoder in the same file and the field positions the readers use. Every reader of S# word 3 masks the heap index (11 or 12 bits), so the border type in its top bits disturbs nothing. Words 0 to 2 are read in two places only: the explicit-LOD gather in direct DXIL, which this fixes, and the HLSL implicit-LOD offset path, where a linear-mip heap sampler now takes the two-mip blend the path was written for (the description says so).Result: no blockers found. From the code, nothing stands in the way of a merge. This is a review, not a merge-check: the suite and a title run are not covered here.
Measured (RTX 3080, Ryzen 9 7950X, merge of this head onto
main395405e4, debug)cargo test -p xcl --lib -- sampler_desc_encodes_and_decodes_back dev_create_sampler_writes_ssharp_and_copy_preserves_it gpu_heap_sampler_gather4_l_and_c_l_use_created_ssharp srv_tsharp_encodes_min_lod_across_dimensions_and_most_detailed_mip gpu_srv_tsharp_min_lod_clamp_controls_image_gather4_l_mip): 5 passed, 0 failed, none skipped.dev_create_sampler_xwriting[0, 0, 0, index]again andMIN_LODleft at 0: 4 of the 5 fail (all but the encoder's own unit test), so the tests pin both changes.Notes, none blocking
mimg_gather4_lodtakes S# words 0 to 2 from the scalar registers (sreg(ssamp..ssamp+2)) and only word 3 per lane (mimg_s3) after a sampler waterfall was collapsed. If a collapsed loop contains an explicit-LOD gather, the sampler picked per lane is right, but its address modes, LOD clamps and compare function come from whatever those registers held before the loop. Read, not run;mainhas the same gap.sampler_desc_encodes_and_decodes_backchecks the raw mip bits forMIN_MAG_ANISOTROPIC_MIP_POINT; decoded throughsampler_d3d12those words come back asANISOTROPIC. No runtime code decodes heap sampler words today, so nothing depends on it.Not checked: the whole suite and a title run on this head; AMD and Intel; the HLSL fallback path with a linear-mip heap sampler and a non-zero LOD bias (whether the bias is applied once), which the description lists as not tested.
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 Foniass on 2026-12-03T05:51:56Z.
merge-check
base:
078358a058head:
1f2b9f0452merge: clean
build: ok
tests: 3011 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 4 medium, 1 nit (below)
performance: 60 s smoke run: 1669 → 1676 frames (100 % of main), peak commit 17577 → 18168 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 233 s there, 0 device removals, 0 crashes, 2.7 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: Heap samplers from CreateSampler/CreateSamplerX now carry their real S# words 0-2 and border type, and SRV T#s carry MIN_LOD from ResourceMinLODClamp, counted from MostDetailedMip. The encoding converts back through sampler_d3d12 unchanged, the GPU test compares against native D3D12 SampleLevel, and no blocking bug was found. Open points: two features in one 742-line PR, an untested behaviour change on the HLSL path, and a smoke run at 87 % of main's frames.
Medium
817eb1fc, not the merge-base5ad98adb. That is within the 80 % limit and probably noise, but nothing explains it; the gaming-PC run should confirm.Nit
Checked and fine
How 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: 61 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.