Shaders respect the minimum LOD of biased cubemap gradient samples #3523

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3523 into main
andrewpozdnakov7-jpg commented 2026-11-27 13:41:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T13:41:42Z.


Cubemap image_sample_d_cl folds its explicit minimum into an LOD for SampleLevel. The host then applies the sampler bias, which can move the sample below its minimum or push it to a blurrier mip.

Use SampleGrad for clamped cubemap gradient samples. Convert the two face-space derivatives into the tangent vectors expected by D3D12 using the existing cube-face transform. This lets the host apply sampler bias and then enforce the explicit minimum LOD. D3D12 SampleGrad clamp · Cube derivative projection

A synthetic GFX10 shader samples all six faces at both centered and off-center coordinates. A trilinear cube encodes its selected mip in the readback. The same test fails on main and passes with the change. For an unbiased LOD of 3 and an explicit minimum of 3.5:

Sampler bias Main Patched
+1 4.5 4.0
−2 1.5 3.5

The test checks 3,456 samples, including the unclamped control and zero bias. The bias/clamp matrix ran on app-local WARP 1.0.22 with Agility 1.620.2. An independent run on RTX 5070 Ti with driver 621.40 passed all 18 face/bias combinations at f9fe970. The observation build confirmed the physical adapter, and WARP separately passed the same 18 cases. In-game impact remains unmeasured. Tester report The tangent conversion builds on the approach discussed in #563 and #1280. Coordination comment

36 VALU tests and 33 lowering tests passed. Shader Clippy passed with warnings denied in default and all-feature builds. The asset policy check passed.

Please retain the original Git author when cherry-picking or rebasing this commit. If folding it into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5527624683 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3523). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T13:41:42Z. --- Cubemap `image_sample_d_cl` folds its explicit minimum into an LOD for `SampleLevel`. The host then applies the sampler bias, which can move the sample below its minimum or push it to a blurrier mip. Use `SampleGrad` for clamped cubemap gradient samples. Convert the two face-space derivatives into the tangent vectors expected by D3D12 using the existing cube-face transform. This lets the host apply sampler bias and then enforce the explicit minimum LOD. [D3D12 SampleGrad clamp](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/tcube-samplegrad-s-float-float-float-float-uint-) · [Cube derivative projection](https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm#LODCalculation) A synthetic GFX10 shader samples all six faces at both centered and off-center coordinates. A trilinear cube encodes its selected mip in the readback. The same test fails on `main` and passes with the change. For an unbiased LOD of `3` and an explicit minimum of `3.5`: | Sampler bias | Main | Patched | | --- | ---: | ---: | | +1 | 4.5 | 4.0 | | −2 | 1.5 | 3.5 | The test checks 3,456 samples, including the unclamped control and zero bias. The bias/clamp matrix ran on app-local WARP 1.0.22 with Agility 1.620.2. An independent run on RTX 5070 Ti with driver 621.40 passed all 18 face/bias combinations at `f9fe970`. The observation build confirmed the physical adapter, and WARP separately passed the same 18 cases. In-game impact remains unmeasured. [Tester report](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7225261335) The tangent conversion builds on the approach discussed in #563 and #1280. [Coordination comment](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7219724608) 36 VALU tests and 33 lowering tests passed. Shader Clippy passed with warnings denied in default and all-feature builds. The asset policy check passed. Please retain the original Git author when cherry-picking or rebasing this commit. If folding it into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted.
andrewpozdnakov7-jpg commented 2026-11-27 13:44:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T13:44:33Z.


GitHub CI passed on f9fe970f6c4123a1daca3bc343d8d91761927b8c, including both Clippy configurations and the workspace tests. Exact-head Windows CI

A physical-adapter check would complement the app-local WARP readback. The focused command is cargo test --locked -p victory-shader --lib emit::valu_tests::cube_gradient_lod_bias_precedes_explicit_min_lod -- --exact --test-threads=1. Leave VICTORY_WARP unset to include the physical adapter. The fixture is synthetic and checks both bias signs across all six faces.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7219887415 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7219887415). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T13:44:33Z. --- GitHub CI passed on `f9fe970f6c4123a1daca3bc343d8d91761927b8c`, including both Clippy configurations and the workspace tests. [Exact-head Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46009327811/job/140540497180) A physical-adapter check would complement the app-local WARP readback. The focused command is `cargo test --locked -p victory-shader --lib emit::valu_tests::cube_gradient_lod_bias_precedes_explicit_min_lod -- --exact --test-threads=1`. Leave `VICTORY_WARP` unset to include the physical adapter. The fixture is synthetic and checks both bias signs across all six faces.
andrewpozdnakov7-jpg commented 2026-11-27 14:03:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T14:03:26Z.


I combined f9fe970 with the earlier #1256/#2372 cube-array and packed-gradient work on 63bcca4. Tested branch 378a316 keeps the original commits. The cube direction and its tangent derivatives now use the same decoded face. The array slice is passed as a coordinate to SampleGrad. TextureCubeArray SampleGrad

The new synthetic cube-array fixture exercises layer 1, ordinary face 2 and encoded face 7 (mapped to face 5), both bias signs, and all four combinations of a16 and _g16. On the earlier integration 102b5c2, the first +1-bias case returned 85.072914 where the face/mip tag should be 84. The new branch matches all 512 per-lane values on app-local WARP 1.0.22. It also passes the original six-face #3523 fixture, all 12 cube tests and all 49 VALU tests with DXIL validation. Strict shader Clippy and asset policy passed.

If folding the integration or its test into another commit, please retain Git authorship or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted with Codex. Synthetic texture and shader data only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220278240 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7220278240). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T14:03:26Z. --- I combined `f9fe970` with the earlier #1256/#2372 cube-array and packed-gradient work on `63bcca4`. [Tested branch 378a316](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/cube-array-gradient-min-lod) keeps the original commits. The cube direction and its tangent derivatives now use the same decoded face. The array slice is passed as a coordinate to SampleGrad. [TextureCubeArray SampleGrad](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/tcubearray-samplegrad-s-float-float-float-float-) The new synthetic cube-array fixture exercises layer 1, ordinary face 2 and encoded face 7 (mapped to face 5), both bias signs, and all four combinations of `a16` and `_g16`. On the earlier integration `102b5c2`, the first +1-bias case returned 85.072914 where the face/mip tag should be 84. The new branch matches all 512 per-lane values on app-local WARP 1.0.22. It also passes the original six-face #3523 fixture, all 12 cube tests and all 49 VALU tests with DXIL validation. Strict shader Clippy and asset policy passed. If folding the integration or its test into another commit, please retain Git authorship or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted with Codex. Synthetic texture and shader data only.
oni-swr commented 2026-11-27 14:17:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T14:17:19Z.


Independent verification of f9fe970f (base 63bcca4), claimed in #1633. WARP + CPU only.

Environment: AMD Ryzen 7 5700X3D, Windows 11 25H2 build 10.0.26200.9974, rustc 1.98.1, VICTORY_WARP=1 + VICTORY_D3D12_WARP=1, system WARP d3d10warp.dll 10.0.26100.9818 (not the app-local 1.0.22 from the PR body), VICTORY_DXIL = Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11. No physical GPU.

Trees: base = 63bcca4; head = f9fe970f (unchanged when I posted).

New test emit::valu_tests::cube_gradient_lod_bias_precedes_explicit_min_lod (--test-threads=1):

  • base lowering with the PR's valu_tests.rs copied in: FAILED (panics at valu_tests.rs:2014). So it fails on main, as the PR says.
  • head: 1 passed.

victory-shader lib suite (cargo test -p victory-shader --lib --no-fail-fast -- --test-threads=1):

  • base: 298 passed, 4 failed, 3 ignored.
  • head: 299 passed, 4 failed, 3 ignored.
  • The same 4 fail on both sides (baseline on WARP here, not caused by the PR): synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out. The +1 passed on head is the new test.

Diff read: cube_face is captured before cs[..3] is overwritten by the direction, so the face index used for the gradient projection is the right one. Unclamped image_sample_d on a cube keeps the old isotropic-LOD path; the clamped (_cl) form now goes through SampleGrad so the host applies bias before the min-LOD clamp. Nothing wrong found; I did not check the physical-GPU result.

AI-assisted: Claude Code, Claude Sonnet 5.5.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220591649 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7220591649). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-27T14:17:19Z. --- Independent verification of f9fe970f (base 63bcca4), claimed in #1633. WARP + CPU only. **Environment:** AMD Ryzen 7 5700X3D, Windows 11 25H2 build 10.0.26200.9974, rustc 1.98.1, `VICTORY_WARP=1` + `VICTORY_D3D12_WARP=1`, system WARP `d3d10warp.dll` 10.0.26100.9818 (not the app-local 1.0.22 from the PR body), `VICTORY_DXIL` = Windows SDK 10.0.26100.0 x64 `dxil.dll` 1.8.2502.11. No physical GPU. **Trees:** base = `63bcca4`; head = `f9fe970f` (unchanged when I posted). **New test** `emit::valu_tests::cube_gradient_lod_bias_precedes_explicit_min_lod` (`--test-threads=1`): - base lowering with the PR's `valu_tests.rs` copied in: **FAILED** (panics at valu_tests.rs:2014). So it fails on main, as the PR says. - head: **1 passed**. **victory-shader lib suite** (`cargo test -p victory-shader --lib --no-fail-fast -- --test-threads=1`): - base: 298 passed, 4 failed, 3 ignored. - head: 299 passed, 4 failed, 3 ignored. - The same 4 fail on both sides (baseline on WARP here, not caused by the PR): `synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_mask_high_address_bits_and_divergent_branches`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`. The +1 passed on head is the new test. **Diff read:** `cube_face` is captured before `cs[..3]` is overwritten by the direction, so the face index used for the gradient projection is the right one. Unclamped `image_sample_d` on a cube keeps the old isotropic-LOD path; the clamped (`_cl`) form now goes through `SampleGrad` so the host applies bias before the min-LOD clamp. Nothing wrong found; I did not check the physical-GPU result. AI-assisted: Claude Code, Claude Sonnet 5.5.
oddmaniv commented 2026-11-27 16:35:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oddmaniv on 2026-11-27T16:35:30Z.


Independent verification of the PR author's shader-package parser tests at f9fe970f6c4123a1daca3bc343d8d91761927b8c.

cargo test --locked -p victory-game --lib shaderpack::tests -- --nocapture

Tree Result
Unmodified PR head 3 passed, 0 failed, 0 ignored; native exit 0
Unmodified main 3 passed, 0 failed, 0 ignored; native exit 0
PR patch applied to pinned main 3 passed, 0 failed, 0 ignored; native exit 0

Main baseline pin: 63bcca43c6a00a758510398fa43096ce7e4f7df0.

Windows x86_64 MSVC native runs. Local and remote source snapshots matched before and after each check. The adaptation applies the PR diff without additional source edits.
This is focused regression coverage, not the full workspace suite, a gameplay test, or an independent validation of every behavior in the PR. No new fix is claimed.

AI-assisted verification.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7223439185 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7223439185). Originally posted by [oddmaniv](https://github.com/oddmaniv) on 2026-11-27T16:35:30Z. --- Independent verification of the PR author's shader-package parser tests at `f9fe970f6c4123a1daca3bc343d8d91761927b8c`. `cargo test --locked -p victory-game --lib shaderpack::tests -- --nocapture` | Tree | Result | | --- | --- | | Unmodified PR head | 3 passed, 0 failed, 0 ignored; native exit 0 | | Unmodified main | 3 passed, 0 failed, 0 ignored; native exit 0 | | PR patch applied to pinned main | 3 passed, 0 failed, 0 ignored; native exit 0 | Main baseline pin: `63bcca43c6a00a758510398fa43096ce7e4f7df0`. Windows x86_64 MSVC native runs. Local and remote source snapshots matched before and after each check. The adaptation applies the PR diff without additional source edits. This is focused regression coverage, not the full workspace suite, a gameplay test, or an independent validation of every behavior in the PR. No new fix is claimed. AI-assisted verification.
kilolimaVI commented 2026-11-27 16:35:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T16:35:51Z.

Review: COMMENTED


Verified on AMD hardware, head f9fe970: Windows 11, Radeon 780M (RDNA3 iGPU), toolchain 1.98.1.

  • cube_gradient_lod_bias_precedes_explicit_min_lod (hardware + WARP in one run): passes, 0/20 failures over 20 runs.
  • Same test with main's lower.rs restored: fails on the 780M as expected, warp false, face 0, bias 1, lane 0, sample 2: 4.5 vs 4 (clamp 3.5 applied before the +1 bias), so the test catches the old ordering on RDNA3, not only on WARP.
  • cargo test -p victory-shader on the 780M: 303 passed, 0 failed (302 on main plus the new test).

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:review:6091057714 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3523#pullrequestreview-6091057714). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T16:35:51Z. **Review:** COMMENTED --- Verified on AMD hardware, head f9fe970: Windows 11, Radeon 780M (RDNA3 iGPU), toolchain 1.98.1. - `cube_gradient_lod_bias_precedes_explicit_min_lod` (hardware + WARP in one run): passes, 0/20 failures over 20 runs. - Same test with main's `lower.rs` restored: fails on the 780M as expected, `warp false, face 0, bias 1, lane 0, sample 2: 4.5 vs 4` (clamp 3.5 applied before the +1 bias), so the test catches the old ordering on RDNA3, not only on WARP. - `cargo test -p victory-shader` on the 780M: 303 passed, 0 failed (302 on main plus the new test). AI-assisted (Claude).
UncommonDLL commented 2026-11-27 18:13:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by UncommonDLL on 2026-11-27T18:13:30Z.


We tested f9fe970f6c4123a1daca3bc343d8d91761927b8c on an RTX 5070 Ti with NVIDIA driver 621.40. The requested command ran with VICTORY_WARP unset and exited 0 with one test passed. That output did not identify which adapter ran.

A separate observation build logged the test’s D3D12 device and each case after the original assertions passed. The RTX 5070 Ti completed all six cube faces at biases 0, +1 and −2. All 18 cases passed, with 32 lanes and six readback checks per lane. WARP separately passed 18/18. Neither adapter skipped a case. OpenAI Codex ran the Windows tests and verified the readbacks.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7225261335 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7225261335). Originally posted by [UncommonDLL](https://github.com/UncommonDLL) on 2026-11-27T18:13:30Z. --- We tested `f9fe970f6c4123a1daca3bc343d8d91761927b8c` on an RTX 5070 Ti with NVIDIA driver 621.40. The requested command ran with `VICTORY_WARP` unset and exited 0 with one test passed. That output did not identify which adapter ran. A separate observation build logged the test’s D3D12 device and each case after the original assertions passed. The RTX 5070 Ti completed all six cube faces at biases 0, +1 and −2. All 18 cases passed, with 32 lanes and six readback checks per lane. WARP separately passed 18/18. Neither adapter skipped a case. OpenAI Codex ran the Windows tests and verified the readbacks.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3523:upstream-pr/3523'
git switch 'upstream-pr/3523'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3523'
git switch 'upstream-pr/3523'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3523'
git switch 'upstream-pr/3523'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3523'
git switch 'main'
git merge --squash 'upstream-pr/3523'
git switch 'main'
git merge --ff-only 'upstream-pr/3523'
git switch 'main'
git merge 'upstream-pr/3523'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3523
No description provided.