gfx10_descriptors: clamp sampler maxLod >= minLod and guard DERIV_ADJUST_EN integer border (VK-SAMPLER-LOD-ORDER-AND-DERIV-ADJUST) #2089

Merged
KushGene merged 1 commit from upstream-pr/2089 into main 2026-11-29 15:43:53 +00:00
KushGene commented 2026-11-25 19:56:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KushGene on 2026-11-25T19:56:28Z.


Claimed in the coordination issue as: VK-SAMPLER-LOD-ORDER-AND-DERIV-ADJUST (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172871387)

What and why

runtime/src/gfx10_descriptors.h decodes console GFX10 S# descriptors (decode(SamplerWords)) and translates them to VkSamplerCreateInfo (vulkan_sampler()) for DeviceState::bind_sampler() and synthetic GPU tests:

  1. Enforce maxLod >= minLod and finite LOD values (VUID-VkSamplerCreateInfo-maxLod-01973): vulkan_sampler() previously copied sampler.min_lod and sampler.max_lod verbatim when mip_filter != MipFilter::none && !sampler.unnormalized. Any title S# carrying MIN_LOD > MAX_LOD or a D3D12_SAMPLER_DESC / caller input with min_lod > max_lod (or NaN) produced an invalid VkSamplerCreateInfo. Raise info.maxLod to info.minLod when info.maxLod < info.minLod and normalize NaN LOD inputs (minLod -> 0.0f, maxLod -> info.minLod).
  2. Guard mipLodBias against NaN and negative/NaN max_lod_bias (VUID-VkSamplerCreateInfo-mipLodBias-01069): std::clamp(sampler.lod_bias, -max_lod_bias, max_lod_bias) triggers undefined behavior when max_lod_bias < 0 or NaN, and propagates NaN lod_bias. Normalize negative/NaN limits to 0.0f and NaN lod_bias to 0.0f using detail::clamped().
  3. Respect DERIV_ADJUST_EN when checking kIntegerBorderPtr in decode(SamplerWords): Line 582 already checks !deriv_adjust before interpreting WORD3 bits as kCompareNever, because DERIV_ADJUST_EN (WORD2 bit 31) repurposes WORD3. Apply the same !deriv_adjust guard to kIntegerBorderPtr (0x800) so descriptors with DERIV_ADJUST_EN = 1 are not misdecoded as integer_border = true (VK_BORDER_COLOR_INT_*).

Follows the pattern of e9f521ceb (VK-SAMPLER-UNNORM-BIAS).

Tested

  • Fail on main / pass with fix (runtime/test/gfx10_descriptors_test.cpp): Built gfx10_descriptors_test against the pre-fix header with the new tests: failed on main at line 386: info.minLod == 3.5f && info.maxLod == 3.5f (exit 1); passes with the fix (GFX10 descriptors: T#, S# and V# fields, round trips, 95 format rows and the Vulkan mappings OK).
  • Strict compiler check: Compiled and ran runtime/test/gfx10_descriptors_test.cpp with /usr/bin/g++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers (0 warnings, exit 0).
  • Affected CMake targets & ctest: Rebuilt gfx10_descriptors_test, vk_sampler_test, vk_harness, vk_sandbox, vk_store_test, vk_texture_test, indirect_clamp_safety_test, indirect_topology_and_stats_test, and ran ctest --test-dir runtime/build/linux-ctest -E "^(shader_library_corpus|vk_sync_validation)$" --output-on-failure -j8 -> 97/97 passed (2 skipped in full suite).
  • Real GPU (ps_ssharp + inverted-LOD vk_sampler_test):
    • LEONIDA_VK_DEVICE=6700 python3 -I scripts/run_gpu_tests.py --build runtime/build/linux-ctest --filter ps_ssharp --require-pass -> 2 shaders translated and valid (spirv-val), PASS ps_ssharp 8 S#/T# cases, 4096 pixels each exact (1/1 passed).
    • LEONIDA_VK_DEVICE=6700 ./runtime/build/linux-ctest/vk_sampler_test .../vs_ids.spv .../ps_ssharp.spv .../inv.raw 0 00000100 04000000 0 0 1 (MIN_LOD = 1.0, MAX_LOD = 0.0, point mip filter) -> mipmapMode 0, minLod 1, maxLod 1, mipLodBias 0; view levels 0..1 and ok -> .../inv.raw (65536 bytes, vkCreateSampler and render succeeded on RADV).
  • Hygiene & no-game-data: python3 -I scripts/check_no_game_data.py runtime/src/gfx10_descriptors.h runtime/test/gfx10_descriptors_test.cpp and git diff --check passed.

GPUs tested: AMD Radeon RX 6700 XT (RADV NAVI22, Mesa 26.2.7, Vulkan 1.4.354, Fedora Linux 45).

AI-assisted: yes (Antigravity)

Checklist

  • Based on current main (db1a22d29) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5498181674 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2089). Originally posted by [KushGene](https://github.com/KushGene) on 2026-11-25T19:56:28Z. --- Claimed in the coordination issue as: VK-SAMPLER-LOD-ORDER-AND-DERIV-ADJUST (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172871387) ### What and why `runtime/src/gfx10_descriptors.h` decodes console GFX10 S# descriptors (`decode(SamplerWords)`) and translates them to `VkSamplerCreateInfo` (`vulkan_sampler()`) for `DeviceState::bind_sampler()` and synthetic GPU tests: 1. **Enforce `maxLod >= minLod` and finite LOD values (`VUID-VkSamplerCreateInfo-maxLod-01973`):** `vulkan_sampler()` previously copied `sampler.min_lod` and `sampler.max_lod` verbatim when `mip_filter != MipFilter::none && !sampler.unnormalized`. Any title S# carrying `MIN_LOD > MAX_LOD` or a `D3D12_SAMPLER_DESC` / caller input with `min_lod > max_lod` (or NaN) produced an invalid `VkSamplerCreateInfo`. Raise `info.maxLod` to `info.minLod` when `info.maxLod < info.minLod` and normalize NaN LOD inputs (`minLod` -> `0.0f`, `maxLod` -> `info.minLod`). 2. **Guard `mipLodBias` against NaN and negative/NaN `max_lod_bias` (`VUID-VkSamplerCreateInfo-mipLodBias-01069`):** `std::clamp(sampler.lod_bias, -max_lod_bias, max_lod_bias)` triggers undefined behavior when `max_lod_bias < 0` or NaN, and propagates NaN `lod_bias`. Normalize negative/NaN limits to `0.0f` and NaN `lod_bias` to `0.0f` using `detail::clamped()`. 3. **Respect `DERIV_ADJUST_EN` when checking `kIntegerBorderPtr` in `decode(SamplerWords)`:** Line 582 already checks `!deriv_adjust` before interpreting `WORD3` bits as `kCompareNever`, because `DERIV_ADJUST_EN` (WORD2 bit 31) repurposes `WORD3`. Apply the same `!deriv_adjust` guard to `kIntegerBorderPtr` (`0x800`) so descriptors with `DERIV_ADJUST_EN = 1` are not misdecoded as `integer_border = true` (`VK_BORDER_COLOR_INT_*`). Follows the pattern of `e9f521ceb` (`VK-SAMPLER-UNNORM-BIAS`). ### Tested - **Fail on `main` / pass with fix (`runtime/test/gfx10_descriptors_test.cpp`):** Built `gfx10_descriptors_test` against the pre-fix header with the new tests: failed on `main` at `line 386: info.minLod == 3.5f && info.maxLod == 3.5f` (exit 1); passes with the fix (`GFX10 descriptors: T#, S# and V# fields, round trips, 95 format rows and the Vulkan mappings OK`). - **Strict compiler check:** Compiled and ran `runtime/test/gfx10_descriptors_test.cpp` with `/usr/bin/g++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers` (0 warnings, exit 0). - **Affected CMake targets & `ctest`:** Rebuilt `gfx10_descriptors_test`, `vk_sampler_test`, `vk_harness`, `vk_sandbox`, `vk_store_test`, `vk_texture_test`, `indirect_clamp_safety_test`, `indirect_topology_and_stats_test`, and ran `ctest --test-dir runtime/build/linux-ctest -E "^(shader_library_corpus|vk_sync_validation)$" --output-on-failure -j8` -> 97/97 passed (2 skipped in full suite). - **Real GPU (`ps_ssharp` + inverted-LOD `vk_sampler_test`):** - `LEONIDA_VK_DEVICE=6700 python3 -I scripts/run_gpu_tests.py --build runtime/build/linux-ctest --filter ps_ssharp --require-pass` -> 2 shaders translated and valid (`spirv-val`), `PASS ps_ssharp 8 S#/T# cases, 4096 pixels each exact` (1/1 passed). - `LEONIDA_VK_DEVICE=6700 ./runtime/build/linux-ctest/vk_sampler_test .../vs_ids.spv .../ps_ssharp.spv .../inv.raw 0 00000100 04000000 0 0 1` (`MIN_LOD = 1.0`, `MAX_LOD = 0.0`, point mip filter) -> `mipmapMode 0, minLod 1, maxLod 1, mipLodBias 0; view levels 0..1` and `ok -> .../inv.raw` (`65536` bytes, `vkCreateSampler` and render succeeded on RADV). - **Hygiene & no-game-data:** `python3 -I scripts/check_no_game_data.py runtime/src/gfx10_descriptors.h runtime/test/gfx10_descriptors_test.cpp` and `git diff --check` passed. GPUs tested: AMD Radeon RX 6700 XT (RADV NAVI22, Mesa 26.2.7, Vulkan 1.4.354, Fedora Linux 45). AI-assisted: yes (Antigravity) ### Checklist - [x] Based on current `main` (`db1a22d29`) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (`CONTRIBUTING.md`), including in logs or reports quoted here.
Tauwni commented 2026-11-27 12:09:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-27T12:09:19Z.


Tested for RT-STATE-AUDIT-PIPELINE on a Mac: Apple M3, macOS 26.5.1, Wine 11.0 (WineHQ macOS build, its MoltenVK 1.4.1), clang-cl/lld-link 23.1.6 cross build. Merged onto main 2859d0c9b, no game files.

  • With this PR: gfx10_descriptors, d3d12_pso_validation, d3d12_draw, d3d12_depth24_draw and d3d12_bundle pass. Same as main, no regression.
  • This PR's gfx10_descriptors_test.cpp alone on main, without the fix: fails at line 386: info.minLod == 3.5f && info.maxLod == 3.5f. So the test fails on main and passes with the change (MEASURED, 1 run each).

GPUs tested: Apple M3 (profile S), MoltenVK 1.4.1 under Wine.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7217903187 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2089#issuecomment-7217903187). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-27T12:09:19Z. --- Tested for RT-STATE-AUDIT-PIPELINE on a Mac: Apple M3, macOS 26.5.1, Wine 11.0 (WineHQ macOS build, its MoltenVK 1.4.1), clang-cl/lld-link 23.1.6 cross build. Merged onto `main` `2859d0c9b`, no game files. - With this PR: `gfx10_descriptors`, `d3d12_pso_validation`, `d3d12_draw`, `d3d12_depth24_draw` and `d3d12_bundle` pass. Same as `main`, no regression. - This PR's `gfx10_descriptors_test.cpp` alone on `main`, without the fix: fails at `line 386: info.minLod == 3.5f && info.maxLod == 3.5f`. So the test fails on `main` and passes with the change (MEASURED, 1 run each). GPUs tested: Apple M3 (profile S), MoltenVK 1.4.1 under Wine. AI-assisted (Claude Code, Claude Opus 5.5).
lixonik commented 2026-11-28 08:42:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T08:42:12Z.

Review: APPROVED


Reviewed and tested merged onto main (493867366) on Windows 11 (MSVC 19.44, Ninja Release).

  • Guarding kIntegerBorderPtr detection with !deriv_adjust avoids misclassifying DERIV_ADJUST_EN (WORD2 bit 31) samplers as integer border colors.
  • Clamping mipLodBias safely against non-positive/NaN limits (VUID-VkSamplerCreateInfo-mipLodBias-01069) and clamping maxLod >= minLod with NaN sanitization (VUID-VkSamplerCreateInfo-maxLod-01973) are clean and match Vulkan rules.
  • Built gfx10_descriptors_test and ran ctest --output-on-failure -V -R ^gfx10_descriptors$: 1/1 passed (0.07 s).

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6096804248 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2089#pullrequestreview-6096804248). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T08:42:12Z. **Review:** APPROVED --- Reviewed and tested merged onto `main` (`493867366`) on Windows 11 (MSVC 19.44, Ninja Release). - Guarding `kIntegerBorderPtr` detection with `!deriv_adjust` avoids misclassifying `DERIV_ADJUST_EN` (WORD2 bit 31) samplers as integer border colors. - Clamping `mipLodBias` safely against non-positive/NaN limits (`VUID-VkSamplerCreateInfo-mipLodBias-01069`) and clamping `maxLod >= minLod` with NaN sanitization (`VUID-VkSamplerCreateInfo-maxLod-01973`) are clean and match Vulkan rules. - Built `gfx10_descriptors_test` and ran `ctest --output-on-failure -V -R ^gfx10_descriptors$`: 1/1 passed (0.07 s). AI-assisted (Antigravity, Gemini).
zmasi commented 2026-11-28 13:12:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T13:12:11Z.


#2089 | head c182b7ad31 (merged cleanly with main d48a957bb9) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(gfx10_descriptors|d3d12_draw|d3d12_pso_validation)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: gfx10_descriptors fails at line 386: info.minLod == 3.5f && info.maxLod == 3.5f (rc=8) | green on PR+main: 3/3 CTests pass (gfx10_descriptors T#/S#/V# + 95 format rows + Vulkan sampler mappings, d3d12_draw, and d3d12_pso_validation 60 layer checks + 100 host comparisons) on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239767000 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2089#issuecomment-7239767000). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T13:12:11Z. --- #2089 | head c182b7ad31f628aca90b86458426cf0a1e325132 (merged cleanly with main d48a957bb9988afce424552a3c0c8d01ef12320f) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(gfx10_descriptors|d3d12_draw|d3d12_pso_validation)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: `gfx10_descriptors` fails at `line 386: info.minLod == 3.5f && info.maxLod == 3.5f` (`rc=8`) | green on PR+main: 3/3 CTests pass (`gfx10_descriptors` T#/S#/V# + 95 format rows + Vulkan sampler mappings, `d3d12_draw`, and `d3d12_pso_validation` 60 layer checks + 100 host comparisons) on RTX 3090 with `0` Khronos validation errors; `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
OreoFR commented 2026-11-29 01:17:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:17:24Z.


Verified by OreoFR

  • Base: main 48bae6cad + PR head c182b7ad3 (tested as a merge)
  • Test: ctest -R ^gfx10_descriptors$ (RelWithDebInfo, Ninja)
  • Red on main: gfx10_descriptors fails (info.minLod == 3.5f && info.maxLod == 3.5f, line 405)
  • Green with the PR: gfx10_descriptors passes
  • gta6rt link: OK (gta6rt.exe builds and links; dumpbin /dependents shows the same DLLs as main, no network DLL)
  • Verdict: READY (the PR also merges without conflict on the newer main 5825b02ff; it also merges cleanly together with #959, which touches the same two files)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248685548 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2089#issuecomment-7248685548). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:17:24Z. --- **Verified by OreoFR** - Base: main `48bae6cad` + PR head `c182b7ad3` (tested as a merge) - Test: `ctest -R ^gfx10_descriptors$` (RelWithDebInfo, Ninja) - Red on main: `gfx10_descriptors` fails (`info.minLod == 3.5f && info.maxLod == 3.5f`, line 405) - Green with the PR: `gfx10_descriptors` passes - gta6rt link: OK (`gta6rt.exe` builds and links; `dumpbin /dependents` shows the same DLLs as main, no network DLL) - Verdict: READY (the PR also merges without conflict on the newer main `5825b02ff`; it also merges cleanly together with #959, which touches the same two files) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
MoonEyes commented 2026-11-29 15:43:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T15:43:55Z.


Merged. Tested by @OreoFR on head c182b7ad3 (RTX 4070 Laptop 8GB, Windows 11): gfx10_descriptors: red on main (minLod/maxLod line 405); green with PR; Tauwni+lixonik concur. Correction: no CI check run or commit status exists for this head, so CI did not validate it. My earlier sentence about red jobs was wrong. Thanks @KushGene!

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7258321619 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2089#issuecomment-7258321619). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T15:43:55Z. --- Merged. Tested by @OreoFR on head c182b7ad3 (RTX 4070 Laptop 8GB, Windows 11): gfx10_descriptors: red on main (minLod/maxLod line 405); green with PR; Tauwni+lixonik concur. Correction: no CI check run or commit status exists for this head, so CI did not validate it. My earlier sentence about red jobs was wrong. Thanks @KushGene! AI-assisted: yes
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
ProjectLeonida/mandy!2089
No description provided.