D3D12.X: encode full RDNA2 S# words in dev_create_sampler_x #3248
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3248"
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-29T00:25:41Z.
Encode full RDNA2
S#words indev_create_sampler_xinstead of writing[0, 0, 0, slot.index & 0xFFF]into the console sampler heap.Direct-DXIL
IMAGE_GATHER4_L*/IMAGE_GATHER4_C_L*lowering (mimg_gather4_lodingpu/dxil/lower_image.rs) reads the console sampler'sS#metadata directly from the shader-visible console sampler heap (w[0]clamp/comparison/unorm,w[1]min/max LOD,w[2]LOD bias and mip filter,w[3][31:30]border color) alongside the PC sampler heap index inw[3][11:0]. Becausedev_create_sampler_xpreviously leftw[0..2]andw[3][31:30]zeroed, heap-created samplers read back asWRAP,MAX_LOD = 0,MIP_FILTER = NONE,DEPTH_COMPARE_FUNC = NEVER, and transparent-black border whenever sampled throughmimg_gather4_lod.What is in it
crates/xcl/src/gpu/desc.rs: addxcl_sampler_for_desc(&D3D12_SAMPLER_DESC, u32) -> [u32; 4]encoding RDNA2S#words (w[0..3], keepingsampler_heap_index & 0xFFFinw[3][11:0]and border colour type inw[3][31:30], saturatingMaxLOD = f32::MAXto0xFFF, and encoding point mip filter asSQ_TEX_MIP_FILTER_POINT = 1); add round-trip unit testview_tests::sampler_desc_encodes_and_decodes_back.crates/xcl/src/hle/d3d12x/real.rs: wirexcl_sampler_for_descintodev_create_sampler_x(preserving the[0, 0, 0, slot.index & 0xFFF]fallback ifdescis null); add WARP testdescriptor_heap_tests::dev_create_sampler_writes_ssharp_and_copy_preserves_it(verifyingCopyDescriptorsSimplekeepsw[0..2]andw[3][31:30]while renumberingw[3][11:0]) and end-to-end GPU testdescriptor_heap_tests::gpu_heap_sampler_gather4_l_and_c_l_use_created_ssharp(verifying Direct-DXILIMAGE_GATHER4_Lexplicit mip 1,IMAGE_GATHER4_C_LLESS_EQUAL, and opaque-whiteBORDERaddressing using theS#written bydev_create_sampler_x; skips cleanly on non-wave32/no-GPU adapters).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 -- 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 --nocapture): 3 passed, 0 failed, 0 skipped (the WARP and GPU tests fail before the fix:IMAGE_GATHER4_L mip 1sampled mip 00.1instead of mip 10.75withs_words=[0, 0, 0, 0]).cargo test --workspace -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::): 2589 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,1647frames vs1695onmain,32425 MBpeak commit vs31546 MBonmain).Regression run
Not tested
BORDER_COLOR_TYPE == 3custom border table pointers are mapped to the closest standardBORDER_COLOR_TYPE0/1/2).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-01T07:03:37Z.
merge-check
base:
d0832e614fhead:
5a3a97c94amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2893 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 (gpu/desc.rs +129, real.rs +265/-3, ~60 lines of runtime code). On main CreateSampler (#22) and CreateSamplerX (#61) write
[0, 0, 0, idx]; now every heap sampler carries its real S# words 0-2 and border colour type. The encoding matchessampler_d3d12bit for bit and the test round-trips through it: address modes (0/1/2/3/6), aniso ratio, compare function, min/max reduction, u4.8 min/max LOD (f32::MAX saturates to 0xFFF), s5.8 LOD bias, mag/min/Z/mip filters, border types 0/1/2; FORCE_UNNORMALIZED is never set, as D3D12 requires. Findings: (1) a change beyond the described scope: the HLSL fallback for implicit-LOD offset sampling in pixel shaders (recomp/emit.rs ~2882-2902) reads the mip filter from S# word 2; heap samplers used to read 0 and take oneSample, and linear-mip ones now take the two-mip blend (3 samples). Probably more correct, but neither described nor tested. (2)MIN_MAG_ANISOTROPIC_MIP_POINT(0x54) and its variants are encoded with a linear mip filter (desc.rs ~371), since the aniso bit forces mip = 2. (3) AI use says "Antigravity (Gemini)", not an exact model; the suite ran with--skipfilters (disclosed). Not from this PR: under a collapsed sampler waterfall,mimg_gather4_lodreads words 0-2 from SGPRs the collapse no longer writes (lower_image.rs ~513-516). Fine: the null-desc fallback, CopyDescriptors keeping words 0-2 and the border type, and a GPU test that fails on main.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (28aa4bc9): 1516 -> 1664 frames shown (109 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17377 MB, 0 device removals, 0 crashes.verdict: safe to merge (the description should mention the HLSL implicit-LOD offset path change and name the AI model; aniso-mip-point filters encode a linear mip)
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 stijn-boer on 2026-12-02T18:24:19Z.
merge-check
base:
c53e969602head:
5a3a97c94averdict: not yet: the targeted AMD descriptor and explicit-LOD gather tests passed and the workspace and smoke exits reproduced on main. The same-head review identified unverified implicit-LOD fallback behavior and anisotropic mip-point encoding in the changed sampler path.
Windows / AMD RDNA4 (native D3D12) — sampler encoding and explicit-LOD gather checks on
5a3a97cClean merge onto
mainatc53e969(merge commit8e2b481592b47d981fb9e62914c10e93a7e93c47).git diff --checkwas clean.Setup
d3d12SDKLayers.dll, DXC 1.9.2609.5Tested
cargo build --workspacepassed.cargo test --workspace --no-fail-fast -- --test-threads=4 --show-outputexited 101 on both builds.SKIPPEDnoticesmainCounts are partial because two test processes aborted on each build.
main— none observed in the comparable results.--test-threads=1 --show-output --nocapture. This includes descriptor encode/decode, CreateSampler and copy preservation, and AMDgather4_landgather4_c_ldraws with the created descriptor.uploads_start_from_each_subresources_statepassed.Shared failures and process aborts
fuzz_validate_and_gpu_1,fuzz_validate_and_gpu_3, andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsreported failures on both builds.gpu_compute_e2etest processes exited with0xc0000409on both builds.Retail smoke
Ran
scripts/smoke.ps1 -Game <local folder> -Seconds 60 -Xcl <debug binary>withXCL_UMA_DRIVER=mixedfor title hash2c508222.main0xc00004090xc00004090xc0000409The first run's higher startup commit did not reproduce. These exits leave frame and steady-state memory behavior unverified.
Diff review
The selected tests checked that the sampler words encode the descriptor and survive a copy, and that translated explicit-LOD gathers use the encoded sampler fields.
Not tested
Remaining workspace tests after the aborts and retail performance.
AI use
Codex (GPT-6) merged and built the PR, ran the tests, compared the results with
main, reviewed the diff, and drafted this report.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T20:23:31Z.
Code review location:
crates/xcl/src/gpu/desc.rs; line 397Medium: This maps every valid border color other than opaque black or white to
BORDER_COLOR_TYPE=0(transparent black). The explicit-LOD gather paths documented above consume this S# directly, so a custom D3D12 border such as[0.25, 0.5, 0.75, 1.0]produces the wrong out-of-range sample. Could the custom color be preserved for these paths, or use a fallback when it cannot be represented, with a GPU test for a border-addressed gather? AI-assisted review: GPT-6 helped inspect the S# encoding; I traced the direct-gather path and checked the D3D12 sampler contract and RDNA2 border-color field.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T20:23:31Z.
Review: COMMENTED
AI-assisted review: GPT-6 helped inspect the sampler encoding; I verified the changed mapping and the direct-S# gather path.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:50:04Z.
Closing: consolidated into #3730 alongside the
T# MIN_LODpart of #3258, addressing @Foniass's review notes (MIN_MAG_ANISOTROPIC_MIP_POINTmip-filter encoding and documenting the HLSL implicit-LOD offset path).Pull request closed