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

Open
github-bot wants to merge 1 commit from github-bot/gh-3523 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 13:41 UTC · original
andrewpozdnakov7-jpg:codex2/cube-gradient-min-lod-bias → main · +157 −30 · 2 files · 1 commits · open

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. Physical GPU behavior and in-game impact remain to be measured. 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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 13:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/3523) `andrewpozdnakov7-jpg:codex2/cube-gradient-min-lod-bias` → `main` · +157 −30 · 2 files · 1 commits · open 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. Physical GPU behavior and in-game impact remain to be measured. The tangent conversion builds on the approach discussed in #563 and #1280. [Coordination comment](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:49:03 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 13:44 UTC · original

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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 13:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7219887415) 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.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 14:03 UTC · original

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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 14:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7220278240) 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.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 14:17 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-27 14:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7220591649) 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.
Author
Owner

@⁠oddmaniv on GitHub · 2026-11-27 16:35 UTC · original

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.

**@⁠oddmaniv** on GitHub · 2026-11-27 16:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7223439185) 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.
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 16:35 UTC · original · reviewed

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).

**@⁠kilolimaVI** on GitHub · 2026-11-27 16:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/3523#pullrequestreview-6091057714) · **reviewed** 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).
Author
Owner

@⁠UncommonDLL on GitHub · 2026-11-27 18:13 UTC · original

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.

**@⁠UncommonDLL** on GitHub · 2026-11-27 18:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/3523#issuecomment-7225261335) 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 can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3523/head:github-bot/gh-3523'
git switch 'github-bot/gh-3523'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3523'
git switch 'github-bot/gh-3523'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3523'
git switch 'github-bot/gh-3523'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3523'
git switch 'main'
git merge --squash 'github-bot/gh-3523'
git switch 'main'
git merge --ff-only 'github-bot/gh-3523'
git switch 'main'
git merge 'github-bot/gh-3523'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3523
No description provided.