5

Suppose I'm making a VkSampler, or possibly a set of VkSamplers, that I'm planning on using with several textures. Each texture has multiple mip levels, and the number of mip levels varies from texture to texture. I want all sampler options to be the same for all the textures, with the possible exception of maxLod.

I don't actually want maxLod to block any particular mip levels from being used; I only want all of each texture's levels to be used in an ordinary, non-erroneous way. So can I just throw in an absurdly high upper bound and use the same sampler for all the textures:

VkSamplerCreateInfo samplerCreateInfo;

...

samplerCreateInfo.minLod = 0;
samplerCreateInfo.maxLod = 1048576;

...or do I need to create a different sampler for each texture and set maxLod for the sampler to that texture's unique maximal mip index?

I think the answer is probably that I can count on reasonable clamping to happen even if my sampler's maxLod is very high - even if I then explicitly pass a uselessly high value to textureLod in a shader - but I'm not totally sure I've correctly interpreted the relevant sections in the Vulkan and GLSL specifications.

mjwach
  • 1,174
  • 2
  • 9
  • 25
  • The Vulkan specification states: `maxLod` is used to clamp the maximum of the computed LOD value. To avoid clamping the maximum value, set maxLod to the constant `VK_LOD_CLAMP_NONE`. – Ocelot Apr 19 '22 at 06:30

1 Answers1

6

No, you can make maxLod as large as you want. If there were cases where it would be "too high", they would be listed as Valid Usage requirements. According to the spec, the only requirements are that it be greater than or equal to minLod, and if unnormalizedCoordinates is true then it must be zero. Beyond that, it is only used to clamp the computed lod. The actual mipmap level accessed is the computed lod (clamped to maxLod), further clamped to the number of mipmaps levels actually available in the texture.

In spec language, maxLod is used to limit the value of λ (Level of Detail Operation). Then the mipmap level accessed, is d' = levelbase + clamp(λ, 0, levelCount - 1) (Image Level(s) Selection). So if maxLod is larger than levelCount - 1, it won't affect the outcome.

Jesse Hall
  • 6,441
  • 23
  • 29
  • Ahh okay, I had seen the maxLod clamping in Level of Detail Operation but I'd missed the (levelCount - 1) clamping. Since I have a mild anxiety disorder I still felt compelled to check just now that (level_base + levelCount - 1) cannot exceed the image's actual level count. (It turns out that it can't; if I followed the trail correctly then it's the Valid Usage text for VkImageViewCreateInfo that establishes that levelCount must be small enough to fit between the base level and the image's level count.) – mjwach Aug 03 '18 at 07:02