Shaders: scale unnormalized sample gradients and honor FORCE_UNNORMALIZED #3716
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3716"
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:46:42Z.
Fixes two unnormalized texture sampling bugs in DXIL lowering:
image_sample_d/image_sample_d_clwith unnormalized coordinates (crates/victory-shader/src/emit/lower.rs):dx.op.getDimensionsscaled coordinatescs[0..spatial]by(W, H, D), while explicit derivativesddx/ddy(g[0..spatial]andg[3..3+spatial]) were passed unscaled todx.op.sampleGrad.f32. In RDNA2 unnormalized mode, gradients are also in texel units, so leaving them unscaled overestimates LOD bylog2(dim)(selecting mip 4[4.0]on a 16×16 texture instead of mips[0.0, 2.0]). Bothg[0..spatial]andg[3..3+spatial]are now divided by level-0 spatial dimensions.SQ_IMG_SAMP_WORD0bit 15 (FORCE_UNNORMALIZED) on immediate samplers (crates/victory-shader/src/emit/lower.rs): RDNA2 enables texel coordinates wheneverinst.unorm || S#.FORCE_UNNORMALIZED(bit 15 of word 0).force_unnormalizednow reads bit 15 acrossSource::Constantand constant-pairSource::Phisampler handles (returning an explicitErrif aPhimixes unnormalized and normalized immediate samplers), and applies the dimension scaling (or rejection on 2Dimage_gather4_l(_o)and cube samples) consistently withinst.unorm.Changes
crates/victory-shader/src/emit/lower.rs(522,176 B<524,288 B): addforce_unnormalized, computeunnormalized = *unorm || force_unnormalized(ss)?.unwrap_or(false), scaleg[0..spatial]andg[3..3+spatial]by level-0 dimensions inop == 63.crates/victory-shader/src/emit/stride_tests.rs: addmixed_force_unnormalized_sampler_phi_is_refused.crates/victory-shader/src/emit/synthetic_tests.rs: add synthetic GPU/WARP testsunnormalized_explicit_gradients_select_their_mips(image_sample_dandimage_sample_d_clon mipmapped 2DView::Levels(16, 5)) andsampler_force_unnormalized_makes_texel_coordinates(image_samplewithS#.word0 = 0x8092).Verification
upstream/main(63bcca4): all 3 tests fail (0 passed, 3 failed):unnormalized_explicit_gradients_select_their_mips:left: [4.0, 4.0], right: [0.0, 2.0]sampler_force_unnormalized_makes_texel_coordinates:left: [256.0], right: [150.0]mixed_force_unnormalized_sampler_phi_is_refused:mixed texel-coordinate modes must be refusedcargo test --locked -p victory-shader --lib --features host -- unnormalized: 3 passed, 0 failed (local hardware adapter + WARP).cargo test --locked -p victory-shader --lib --features host -- image_addresses_of_16_bits_and_clamps: 1 passed, 0 failed.cargo clippy --locked -p victory-shader --all-targets --features host -- -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 oni-swr on 2026-11-28T13:11:37Z.
Independent software-only WARP verification of #3716.
63bcca43c6a00a758510398fa43096ce7e4f7df0, PR headcd3cf73e59ff9ded9a00c09579158d5e550831bc, and GitHub test merge0eacc6c312b85a10b430589120976fcff4171609. The test merge has those exact parents. The Windows CI check passed for the pinned head.dxil.dll(file version 1.8.2502.11). BothVICTORY_WARP=1andVICTORY_D3D12_WARP=1were set. All adapter calls in the shader harness ran on WARP, including passes labeled “hardware” by the tests. Cargo used-j 4.[4, 4]instead of[0, 2], the immediate sampler returned256instead of150, and mixed immediate sampler modes were accepted. All three passed on the test merge.host. Clean main had 298 passed, 4 failed, 3 ignored. The test merge had 301 passed, 4 failed, 3 ignored. The same four tests failed on both revisions, covering three wave-32 pipeline cases and one gather comparison.lower.rswas 522,176 bytes, 2,112 bytes under the 524,288-byte limit.Synthetic tests only. AI-assisted with OpenAI Codex (
gpt-6.2-sol), which ran the verification. The original Gemini 4 Neon launch hit quota and the Claude Sonnet 5.5 restart hit an authentication error before either ran tests.Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T15:30:04Z.
NVIDIA row for this PR: it passes on Ampere, and the three new tests fail on this card without the fix. This adds a hardware run to oni-swr's WARP-only one.
RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head
cd3cf73on main63bcca4(one commit, clean).synthetic_tests::unnormalized_explicit_gradients_select_their_mips,synthetic_tests::sampler_force_unnormalized_makes_texel_coordinatesandstride_tests::mixed_force_unnormalized_sampler_phi_is_refused: 3 passed, 0 failed, in 3 of 3 runs. The two synthetic tests run on the hardware adapter and then on WARP. The mixed-phi test only translates and uses no device.run_unnormalized_shaderskips an adapter it cannot open and prints nothing, so a pass alone does not show that WARP ran. One extra run withVICTORY_WARP=1, where every device is WARP, also passed 3 of 3.Negative control: the same tests with main's
crates/victory-shader/src/emit/lower.rs(git diff --stat HEAD: 1 file, 3 insertions, 39 deletions) gave 0 passed, 3 failed, in 3 of 3 runs. The failures are the ones the description quotes:hardware: explicit gradientsgave[4.0, 4.0], want[0.0, 2.0];hardware: FORCE_UNNORMALIZEDgave[256.0], want[150.0]; and "mixed texel-coordinate modes must be refused". TheVICTORY_WARP=1control fails with the same values. Its messages still say "hardware", but that run is WARP.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).Nothing NVIDIA-specific: the card gives the values the description and oni-swr's WARP run give, with and without the fix.
Not tested: a title run;
--features host(the PR's own command; the run above uses the default features, which build the host checks here too).AI-assisted (Claude Code, Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T15:51:48Z.
Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head
cd3cf73on63bcca4.sampler_force_unnormalized_makes_texel_coordinates,unnormalized_explicit_gradients_select_their_mipsandmixed_force_unnormalized_sampler_phi_is_refusedpass.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 kilolimaVI on 2026-11-28T21:56:10Z.
AMD Radeon 780M (RDNA3) + WARP, Windows 11, head
cd3cf73. Before (main63bcca4+ this PR's tests): all three fail;sampler_force_unnormalized_makes_texel_coordinatesreads 256.0 for 150.0 on the hardware adapter, and the mixed-mode phi is not refused. After: 3/3 pass, 5 of 5 runs. Full suite: 554 passed. AI-assisted (Claude).Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T22:38:14Z.
I checked whether
cd3cf73can land with the two FP16 changes in #3617 and #3717. Git merges them cleanly with the verified rounding follow-up. Even so,xtask policyrejects the resultinglower.rsat 524,561 bytes. The repository limit is 524,288 bytes.Combined
2045456includes the exact sampling PR, the tested FP16 integration and the test split in #3797. Itslower.rsis 472,291 bytes. The asset policy passes on all 192 files. All three sampling regressions, both FP16 regressions and the 33 lowerer tests passed locally, using Microsoft WARP for the graphics cases. Both strict shader Clippy configurations passed.The maintainer can land #3797 before taking the sampling and FP16 changes together. Please retain the Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding the changes into another commit.AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-29T14:04:57Z.
AMD row, from the integration runs on a Radeon 780M (RDNA3, driver 32.0.13022.3006, Windows 11): this PR at
cd3cf73is part ofkilolimaVI/VIctoryintegration/shader-6throughintegration/shader-10(with #3097, #2999, #3617, #3717, #1315, #2398, #385, #1262, #3401). On each of those trees the whole victory-shader lib passed with 0 failures (318 to 354 tests), which includesunnormalized_explicit_gradients_select_their_mips,sampler_force_unnormalized_makes_texel_coordinatesandmixed_force_unnormalized_sampler_phi_is_refused; victory-gpu (diagnostics) 246 passed. So the values upipibi got on the RTX 3070 hold on AMD too.Its one conflict there is with #2999: both append tests at the end of
synthetic_tests.rs(kept both).AI-assisted (Claude).
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.