Skip to content

gfx10_descriptors: zero mipLodBias for unnormalized samplers (VK-SAMPLER-UNNORM-BIAS) - #535

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
tahffo68hk-hash:fix/vk-sampler-unnorm-bias
Nov 24, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
tahffo68hk-hash:fix/vk-sampler-unnorm-bias

Conversation

@tahffo68hk-hash

Copy link
Copy Markdown
Contributor

Summary

When Sampler::unnormalized (FORCE_UNNORMALIZED) is set on an S#, gfx10::vulkan_sampler() in runtime/src/gfx10_descriptors.h previously clamped addressModeU/addressModeV (VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01075), equalized minFilter = magFilter (-01072), forced mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST, minLod = maxLod = 0.0f (-01073), disabled anisotropy (-01076), and disabled comparison (-01077), but left info.mipLodBias set to the decoded LOD_BIAS.

Vulkan requires mipLodBias == 0.0f whenever unnormalizedCoordinates == VK_TRUE (VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074). Any S# with FORCE_UNNORMALIZED and a non-zero LOD_BIAS passed into vkCreateSampler() (via bind_sampler(), vk_sampler_test, vk_harness, or vk_sandbox) violated this VUID.

Fix

  • Zero info.mipLodBias = 0.0f; inside the if (sampler.unnormalized) block in gfx10::vulkan_sampler() (runtime/src/gfx10_descriptors.h).
  • Add regression checks with both positive (+2.5f) and negative (-3.25f) lod_bias plus non-zero min_lod in runtime/test/gfx10_descriptors_test.cpp.

Verification

  • Built and ran gfx10_descriptors_test.exe (MSVC 19.44, Ninja, C++20, local CPU unit test):
    GFX10 descriptors: T#, S# and V# fields, round trips, 94 format rows and the Vulkan mappings OK

Coordination

中文翻译

摘要

当 S# 描述符设置了 Sampler::unnormalized(FORCE_UNNORMALIZED)时,runtime/src/gfx10_descriptors.h 中的 gfx10::vulkan_sampler() 虽然已按 Vulkan 规范约束了 addressModeU/addressModeV(-01075)、minFilter = magFilter(-01072)、mipmapMode 与 minLod/maxLod(-01073)、各向异性(-01076)和比较采样(-01077),但遗漏了将 info.mipLodBias 清零。

根据 Vulkan 规范 VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074,只要 unnormalizedCoordinates == VK_TRUE,mipLodBias 必须为 0.0f。任何同时设置了 FORCE_UNNORMALIZED 与非零 LOD_BIAS 的 S# 在调用 vkCreateSampler() 时都会触发该 VUID 违规。

修复

  • 在 gfx10::vulkan_sampler() 的 if (sampler.unnormalized) 分支中显式设置 info.mipLodBias = 0.0f;。
  • 在 runtime/test/gfx10_descriptors_test.cpp 中增加正/负 lod_bias 及非零 min_lod 的未归一化采样器回归断言。

验证

  • 本地编译并运行 gfx10_descriptors_test.exe(MSVC 19.44 + Ninja,CPU 单元测试):全部通过。

协同

@kawaii-shakal

Copy link
Copy Markdown
Contributor

Review of head e9f521cebb840868260b0fe6208da5781355c687.

Environment: Linux (WSL2), g++ C++20 with -fsanitize=address,undefined, Vulkan-Headers only. No GPU, no MSVC.

What ran:

  • runtime/test/gfx10_descriptors_test.cpp built against the PR head: passes (... and the Vulkan mappings OK), no ASan/UBSan reports.
  • The same test against gfx10_descriptors.h from origin/main: fails at the new check info.minLod == 0.0f && info.maxLod == 0.0f && info.mipLodBias == 0.0f (line 365), so the test catches the bug.

Findings: none blocking. The fix matches VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074 (mipLodBias must be zero when unnormalizedCoordinates is VK_TRUE) and sits with the other unnormalized clamps.

Not tested: vkCreateSampler under the validation layer on a GPU, and the MSVC build.


Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account.

demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…nnormalized samplers (VK-SAMPLER-UNNORM-BIAS)
QemmHD added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** D3D-CLEAR-DEPTH-RANGE: enables VK_EXT_depth_range_unrestricted where the device has it, so depth clears outside [0,1] (and NaN) behave like D3D12 instead of being clamped. Without the extension it keeps clamping, and NaN becomes 0. Four independent passes; on AMD (660M, 7900 XTX), d3d12_clear still fails only on the NaN rows, which is the driver issue tracked in #307, not this PR.

**Why it's good:** On the 4070 SUPER with validation on, main's d3d12_clear_test exits 1 with 4x VUID-VkClearDepthStencilValue-depth-00022. With this PR it exits 0 with no VUIDs, and the 1.5 / -0.5 / NaN clears match WARP. The new d3d12_clear_restricted_depth passes, and so do d3d12_clear and d3d12_clear_formats.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e2: no conflicts, and none of these touch the files #891/#882 changed. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

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

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Merging.

Why merged: VK-SAMPLER-UNNORM-BIAS: an unnormalized-coordinates sampler gets mipLodBias 0, which VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074 requires. kawaii-shakal ran it under ASan/UBSan and showed the new check fails on main.

Why it's good: gfx10_descriptors and d3d12_descriptor pass both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e2: no conflicts, and none of these touch the files #891/#882 changed. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

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

@QemmHD
QemmHD merged commit 4c8efeb into ProjectLeonida:main Nov 24, 2026
8 of 13 checks passed
QemmHD added a commit that referenced this pull request Nov 24, 2026
…opy-clear-stage

Merging.

**Why merged:** OLD-10048: SYNC_COPY maps to COPY|CLEAR, so WriteBufferImmediate (vkCmdUpdateBuffer) and the query zero-fill are ordered before later copies. moffington reproduced the read-after-write hazard on the base, and Timon360SB and SweatierKey checked it independently. Part K of vk_command_replay_test covers it.

**Why it's good:** vk_command_replay, d3d12_state_map and replay_query_edges pass both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e2: no conflicts, and none of these touch the files #891/#882 changed. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).
QemmHD added a commit that referenced this pull request Nov 24, 2026
…dup-wait

Merging.

**Why merged:** RT-RETIRE-TICKETS-DEDUP-WAIT: pending_through() merges entries per semaphore to the highest value, and completed_ can no longer move backwards. moffington (ASan/UBSan, with a differential test that fails on the base), Timon360SB, KernelSmoker and SweatierKey checked it independently.

**Why it's good:** retire_tickets passes both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e2: no conflicts, and none of these touch the files #891/#882 changed. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants