gfx10_descriptors: clamp sampler maxLod >= minLod and guard DERIV_ADJUST_EN integer border (VK-SAMPLER-LOD-ORDER-AND-DERIV-ADJUST) #2089
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2089"
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 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.hdecodes console GFX10 S# descriptors (decode(SamplerWords)) and translates them toVkSamplerCreateInfo(vulkan_sampler()) forDeviceState::bind_sampler()and synthetic GPU tests:maxLod >= minLodand finite LOD values (VUID-VkSamplerCreateInfo-maxLod-01973):vulkan_sampler()previously copiedsampler.min_lodandsampler.max_lodverbatim whenmip_filter != MipFilter::none && !sampler.unnormalized. Any title S# carryingMIN_LOD > MAX_LODor aD3D12_SAMPLER_DESC/ caller input withmin_lod > max_lod(or NaN) produced an invalidVkSamplerCreateInfo. Raiseinfo.maxLodtoinfo.minLodwheninfo.maxLod < info.minLodand normalize NaN LOD inputs (minLod->0.0f,maxLod->info.minLod).mipLodBiasagainst NaN and negative/NaNmax_lod_bias(VUID-VkSamplerCreateInfo-mipLodBias-01069):std::clamp(sampler.lod_bias, -max_lod_bias, max_lod_bias)triggers undefined behavior whenmax_lod_bias < 0or NaN, and propagates NaNlod_bias. Normalize negative/NaN limits to0.0fand NaNlod_biasto0.0fusingdetail::clamped().DERIV_ADJUST_ENwhen checkingkIntegerBorderPtrindecode(SamplerWords): Line 582 already checks!deriv_adjustbefore interpretingWORD3bits askCompareNever, becauseDERIV_ADJUST_EN(WORD2 bit 31) repurposesWORD3. Apply the same!deriv_adjustguard tokIntegerBorderPtr(0x800) so descriptors withDERIV_ADJUST_EN = 1are not misdecoded asinteger_border = true(VK_BORDER_COLOR_INT_*).Follows the pattern of
e9f521ceb(VK-SAMPLER-UNNORM-BIAS).Tested
main/ pass with fix (runtime/test/gfx10_descriptors_test.cpp): Builtgfx10_descriptors_testagainst the pre-fix header with the new tests: failed onmainatline 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).runtime/test/gfx10_descriptors_test.cppwith/usr/bin/g++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers(0 warnings, exit 0).ctest: Rebuiltgfx10_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 ranctest --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).ps_ssharp+ inverted-LODvk_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..1andok -> .../inv.raw(65536bytes,vkCreateSamplerand render succeeded on RADV).python3 -I scripts/check_no_game_data.py runtime/src/gfx10_descriptors.h runtime/test/gfx10_descriptors_test.cppandgit diff --checkpassed.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
main(db1a22d29) and merges cleanly.CONTRIBUTING.md), including in logs or reports quoted here.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
main2859d0c9b, no game files.gfx10_descriptors,d3d12_pso_validation,d3d12_draw,d3d12_depth24_drawandd3d12_bundlepass. Same asmain, no regression.gfx10_descriptors_test.cppalone onmain, without the fix: fails atline 386: info.minLod == 3.5f && info.maxLod == 3.5f. So the test fails onmainand 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).
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).kIntegerBorderPtrdetection with!deriv_adjustavoids misclassifyingDERIV_ADJUST_EN(WORD2 bit 31) samplers as integer border colors.mipLodBiassafely against non-positive/NaN limits (VUID-VkSamplerCreateInfo-mipLodBias-01069) and clampingmaxLod >= minLodwith NaN sanitization (VUID-VkSamplerCreateInfo-maxLod-01973) are clean and match Vulkan rules.gfx10_descriptors_testand ranctest --output-on-failure -V -R ^gfx10_descriptors$: 1/1 passed (0.07 s).AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T13:12:11Z.
#2089 | head
c182b7ad31(merged cleanly with maind48a957bb9) |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_descriptorsfails atline 386: info.minLod == 3.5f && info.maxLod == 3.5f(rc=8) | green on PR+main: 3/3 CTests pass (gfx10_descriptorsT#/S#/V# + 95 format rows + Vulkan sampler mappings,d3d12_draw, andd3d12_pso_validation60 layer checks + 100 host comparisons) on RTX 3090 with0Khronos validation errors;check_no_game_data.py0violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yesImported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:17:24Z.
Verified by OreoFR
48bae6cad+ PR headc182b7ad3(tested as a merge)ctest -R ^gfx10_descriptors$(RelWithDebInfo, Ninja)gfx10_descriptorsfails (info.minLod == 3.5f && info.maxLod == 3.5f, line 405)gfx10_descriptorspassesgta6rt.exebuilds and links;dumpbin /dependentsshows the same DLLs as main, no network DLL)5825b02ff; it also merges cleanly together with #959, which touches the same two files)AI-assisted (Claude Code, Claude Opus 5.5).
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