From e9f521cebb840868260b0fe6208da5781355c687 Mon Sep 17 00:00:00 2001 From: tahffo68hk-hash Date: Tue, 24 Nov 2026 15:08:36 +0800 Subject: [PATCH] gfx10_descriptors: zero mipLodBias for unnormalized samplers (VK-SAMPLER-UNNORM-BIAS) --- runtime/src/gfx10_descriptors.h | 6 ++++-- runtime/test/gfx10_descriptors_test.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/runtime/src/gfx10_descriptors.h b/runtime/src/gfx10_descriptors.h index b225cddef0..a4a9b44481 100644 --- a/runtime/src/gfx10_descriptors.h +++ b/runtime/src/gfx10_descriptors.h @@ -631,8 +631,9 @@ inline VkSamplerCreateInfo vulkan_sampler(const Sampler& sampler, float max_lod_ if (sampler.unnormalized) { info.unnormalizedCoordinates = VK_TRUE; // VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01075: U and V clamp to the edge or the border (a - // repeating mode would wrap at a texel count the sampler cannot know); -01072: one filter for min and mag. - // The S# allows any address mode with FORCE_UNNORMALIZED, and WRAP is its default (word 0 = 0). + // repeating mode would wrap at a texel count the sampler cannot know); -01072: one filter for min and mag; + // -01074: mipLodBias must be zero. The S# allows any address mode or LOD bias with FORCE_UNNORMALIZED, and + // WRAP is its default (word 0 = 0). const auto clamp_or_border = [](VkSamplerAddressMode m) { return m == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ? m : VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; }; @@ -640,6 +641,7 @@ inline VkSamplerCreateInfo vulkan_sampler(const Sampler& sampler, float max_lod_ info.addressModeV = clamp_or_border(info.addressModeV); info.minFilter = info.magFilter; info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; + info.mipLodBias = 0.0f; info.minLod = info.maxLod = 0.0f; info.anisotropyEnable = VK_FALSE; info.maxAnisotropy = 1.0f; diff --git a/runtime/test/gfx10_descriptors_test.cpp b/runtime/test/gfx10_descriptors_test.cpp index 523180ee70..85843edb83 100644 --- a/runtime/test/gfx10_descriptors_test.cpp +++ b/runtime/test/gfx10_descriptors_test.cpp @@ -359,18 +359,21 @@ int main() { CHECK(info.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && info.mipLodBias == -0.75f); CHECK(info.minLod == 0.5f && info.maxLod == 4.25f); info = vulkan_sampler({.mag_filter = Filter::aniso_point, .mip_filter = MipFilter::linear, .max_anisotropy = 8, - .compare = CompareFunction::greater, .max_lod = 9.0f, .unnormalized = true}); + .compare = CompareFunction::greater, .min_lod = 1.5f, .max_lod = 9.0f, + .lod_bias = 2.5f, .unnormalized = true}); CHECK(info.unnormalizedCoordinates == VK_TRUE && info.mipmapMode == VK_SAMPLER_MIPMAP_MODE_NEAREST); - CHECK(info.maxLod == 0.0f && info.anisotropyEnable == VK_FALSE && info.compareEnable == VK_FALSE); + CHECK(info.minLod == 0.0f && info.maxLod == 0.0f && info.mipLodBias == 0.0f); + CHECK(info.anisotropyEnable == VK_FALSE && info.compareEnable == VK_FALSE); // Unnormalised: U and V clamp (wrap, the default S# mode, would be invalid: VUID ...-01075), border stays border, - // W is free; min and mag filter agree (VUID ...-01072). + // W is free; min and mag filter agree (VUID ...-01072); mipLodBias is zero (VUID ...-01074). CHECK(info.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && info.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && info.addressModeW == VK_SAMPLER_ADDRESS_MODE_REPEAT && info.minFilter == info.magFilter); info = vulkan_sampler({.address_u = AddressMode::clamp_border, .address_v = AddressMode::mirror, - .min_filter = Filter::bilinear, .unnormalized = true}); + .min_filter = Filter::bilinear, .lod_bias = -3.25f, .unnormalized = true}); CHECK(info.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER && - info.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && info.minFilter == VK_FILTER_NEAREST); + info.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && info.minFilter == VK_FILTER_NEAREST && + info.mipLodBias == 0.0f); CHECK(vulkan_address_mode(AddressMode::mirror) == VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT); CHECK(vulkan_address_mode(AddressMode::mirror_once_last_texel) == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE); CHECK(vulkan_address_mode(AddressMode::clamp_half_border) == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE);