Shaders, GPU: sampler LOD bounds follow RDNA2 #3715
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3715"
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 Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-28T10:45:26Z.
Fixes two sampler LOD mismatches against RDNA2 (
gfx1036hardware probe measurements) that affect inverted LOD ranges on immediate static samplers andSQ_TEX_MIP_FILTER_NONEon runtimeCreateSamplerXsamplers:crates/victory-shader/src/emit/sampler.rs): whenmip != 0andMIN_LOD > MAX_LODinSQ_IMG_SAMP_WORD1, clampmax_lodup tomax_lod.max(min_lod)(matchingvictory-gpu/src/sampler.rs). On RDNA2,MIN_LODwins an inverted range (min(max(min(raw, hi), lo), n - 1)), whereas D3D12 requiresMaxLOD >= MinLODand evaluatesmin(max(lod, MinLOD), MaxLOD)(pickingMaxLOD— selecting mip 0 instead of mip 2 before this fix).MipLODBiasis untouched (handled by#3043).CreateSamplerX(crates/victory-gpu/src/sampler.rs): whenself.mip == 0(SQ_TEX_MIP_FILTER_NONE), emit(0.0, 0.0)instead of(min_lod, min_lod). In response to the#474review question ("Could you point to the ISA or a capture that shows MIN_LOD is ignored without a mip filter?"): RDNA2 hardware measurements (gfx1036,image_sample_l/image_sample_lz/image_get_lod) confirmSQ_TEX_MIP_FILTER_NONEignoresS# MIN_LOD,MAX_LOD, andLOD_BIASand always reads the view's base level, matchingemit/sampler.rs.Changes
crates/victory-shader/src/emit/sampler.rs: clampmax_lodwith.max(min_lod)whenmip != 0; addan_inverted_lod_range_keeps_min_lod.crates/victory-gpu/src/sampler.rs: mapself.mip == 0to(0.0, 0.0)and updatemip_none_ignores_lod_and_inverted_lod_range_clamps.crates/victory-shader/src/emit/stride_tests.rs,crates/victory-shader/src/emit/valu_tests.rs: add synthetic GPU/WARP testsan_inverted_static_lod_range_samples_min_lodandheap_sampler_lod_bounds_choose_the_mip.Verification
cargo test --locked -p victory-shader --lib --features host -- lod: 6 passed, 0 failed (runs both local hardware adapter and WARP).cargo test --locked -p victory-gpu --lib -- sampler::tests: 5 passed, 0 failed (mip_none_ignores_lod_and_inverted_lod_range_clampsand hardware adapter sampler creation pass).cargo clippy --locked -p victory-shader --all-targets --features host -- -D warnings: clean (exit 0).cargo clippy --locked -p victory-gpu --all-targets -- -D warnings: clean (exit 0).cargo run --locked -p xtask -- policy:asset policy: 191 files ok.AI-assisted; synthetic tests only, no game files.
— Devin & Neon
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T11:27:44Z.
I combined #3715 at
065e08awith #3043 at5437d70on63bcca4. Branch2f0411ekeeps both original heads and their Git authors.I ran the same generated shader and four-mip texture on app-local WARP 1.0.22 and Agility 1.620.2, with the D3D12 debug layer off and on. Each mip stored its index. For an immediate point-mip sampler with
MIN_LOD=2,MAX_LOD=0and aSampleLevelrequest for level 0, the readbacks were:The ordered
[0, 3]control on #3043 and on the combined branch read mips0, 0, 3at biases-24, 0, +24. The original static, heap-sampler, and serialization regressions passed. The combined GPU suite passed 247 tests with one ignored in both debug settings. Strict shader and GPU Clippy in both configurations and the asset policy passed.If carrying these changes separately, please retain the Git authors on cherry-pick or rebase.
AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T15:51:47Z.
Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head
065e08aon63bcca4.heap_sampler_lod_bounds_choose_the_mip,an_inverted_static_lod_range_samples_min_lodandan_inverted_lod_range_keeps_min_lodpass.victory-shader --lib --features host: 305 passed, 0 failed, 3 ignored.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T15:59:32Z.
NVIDIA row for this PR: it passes on Ampere, and its tests fail without the fix. On this card, though, the GPU test's hardware run reads the right mip even with main's code. Only WARP's run catches the inverted static range.
RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head
065e08aon main63bcca4(one commit, clean).cargo test --locked -p victory-shader --lib -- an_inverted_lod_range_keeps_min_lod an_inverted_static_lod_range_samples_min_lod heap_sampler_lod_bounds_choose_the_mip --nocapture: 3 passed, 0 failed, 0 ignored, in 3 of 3 runs, and again in 3 of 3 runs withVICTORY_WARP=1, where every device is WARP.cargo test --locked -p victory-gpu --lib -- sampler::tests: 5 passed, 0 failed, 0 ignored, in 3 of 3 runs.The description's own command,
cargo test --locked -p victory-shader --lib --features host -- lod: 6 passed, 0 failed, 0 ignored, as quoted.Negative control: two of the PR's tests sit in the production files, so I reverted only the code hunks of
emit/sampler.rsandvictory-gpu/src/sampler.rsand kept the test hunks.git diff --stat HEAD: 2 files, 6 insertions, 11 deletions.git diff 63bcca4then shows only test changes.VICTORY_WARP=1:sampler::tests::an_inverted_lod_range_keeps_min_lodgave(2.0, 0.0), want(2.0, 2.0);stride_tests::an_inverted_static_lod_range_samples_min_lodgave0.0, want2.0, with the labelwarp. WithVICTORY_WARP=1the label ishardware, but that run is WARP too.heap_sampler_lod_bounds_choose_the_mippasses with main's code. ItsD3D12_SAMPLER_DESCis built in the test, so neithersampler.rsreaches it; it guards the heap path rather than testing the fix.sampler::tests: 4 passed, 1 failed, in 3 of 3 runs.mip_none_ignores_lod_and_inverted_lod_range_clampsgave(3.0, 3.0), want(0.0, 0.0)(no mip filter,MIN_LOD3).The GPU test reports nothing for an adapter that passes, so I ran it 3 more times with one temporary
eprintln!of the readback, then restored the file:hardware: read 2,warp: read 2;hardware: read 2,warp: read 0.So for the immediate sampler with
MIN_LOD2 andMAX_LOD0, main hands D3D12MinLOD2 andMaxLOD0. The RTX 3070 lets the minimum win and reads mip 2, which is RDNA2's answer. WARP reads mip 0, the "mip 0 instead of mip 2" in the description and the "main, bias 0: mip 0" in andrewpozdnakov7-jpg's WARP table. The fix makes both read mip 2.cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index:63bcca4: 298 passed, 3 failed, 3 ignored.The 3 failures are the same on both:
stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardware. The skipped test crashes the binary on this card (open issue #2571).cargo test --locked -p victory-gpu --lib:63bcca4: 229 passed, 2 failed, 1 ignored.The test is renamed, not added. The same 2 fail on both:
descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views.NVIDIA-specific: Ampere already resolves an inverted D3D12 LOD range the way RDNA2 does, so main is right on this card by luck. The PR makes the range well-formed (
MaxLOD >= MinLOD), so the result no longer depends on the driver. On NVIDIA alone the GPU test cannot tell main from the fix; its WARP leg does.Not tested: the combination with #3043 (andrewpozdnakov7-jpg's branch
2f0411e) or anyMipLODBias; the debug layer; a title run;CreateSamplerXsamplers on the GPU, since the victory-gpu change was only checked by its unit test.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T16:25:33Z.
AMD row, to go with upipibi's RTX 3070: Radeon 780M (RDNA3, gfx1103) + WARP, Windows 11, head
065e08a.63bcca4+ this PR's tests):heap_sampler_lod_bounds_choose_the_mippasses on both.an_inverted_static_lod_range_samples_min_lodpasses on the 780M and fails only on WARP (reads level 0, wants 2).victory-shader+victory-gpu --features diagnostics): 554 passed.So like the 3070, RDNA3 already samples the right level with main's code; the change is what makes WARP agree.
AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T23:46:54Z.
I checked
065e08awith #3716's unnormalized explicit gradients atcd3cf73. Combined11e0566keeps both exact parents and adds one generated five-mip texture case.The case sets the static sampler's minimum to 2 and maximum to 0. With just #3716, the test sees
(2.0, 0.0)in the decoded sampler. The combined shader exposes(2.0, 2.0), validates, and samples mip 2 in both readbacks on app-local Microsoft WARP. The ordinary gradient control still selects mip 0 and mip 2. The FORCE_UNNORMALIZED, mixed-sampler rejection, static and heap sampler LOD checks also passed.Both strict Clippy configurations for the shader and GPU crates passed, along with the GPU sampler tests, the 33 lowerer tests and the asset policy. The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding the regression into another commit.AI-assisted with OpenAI Codex.
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.