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

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

@⁠KushGene on GitHub · 2026-11-25 19:56 UTC · original
KushGene:fix/vk-sampler-lod-order-and-deriv-adjust → main · +45 −4 · 2 files · 1 commits · open

Claimed in the coordination issue as: VK-SAMPLER-LOD-ORDER-AND-DERIV-ADJUST (#1608)

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.
**@⁠KushGene** on GitHub · 2026-11-25 19:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2089) `KushGene:fix/vk-sampler-lod-order-and-deriv-adjust` → `main` · +45 −4 · 2 files · 1 commits · open Claimed in the coordination issue as: VK-SAMPLER-LOD-ORDER-AND-DERIV-ADJUST (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:17:26 +00:00
Author
Owner

@⁠Tauwni on GitHub · 2026-11-27 12:09 UTC · original

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

**@⁠Tauwni** on GitHub · 2026-11-27 12:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2089#issuecomment-7217903187) 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2089/head:github-bot/gh-2089'
git switch 'github-bot/gh-2089'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2089'
git switch 'github-bot/gh-2089'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2089'
git switch 'github-bot/gh-2089'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2089'
git switch 'main'
git merge --squash 'github-bot/gh-2089'
git switch 'main'
git merge --ff-only 'github-bot/gh-2089'
git switch 'main'
git merge 'github-bot/gh-2089'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.