Skip to content

arb_texture_query_lod: fix LOD queries in divergent control flow

For Zink (or other GL drivers layered on Vulkan), the behavior LOD queries or implicit LOD calculations in divergent control flow are defined only if VkPhysicalDeviceDescriptorIndexingProperties::quadDivergentImplicitLod is true :

"quadDivergentImplicitLod is a boolean value indicating whether implicit LOD calculations for image operations have well-defined results when the image and/or sampler objects used for the instruction are not uniform within a quad. See Derivative Image Operations. [1]"

I suspect there is the same undefined behavior in GL drivers, people might just have been lucky with copy propagation sourcing values from non divergent control flow up to this point.

In the tests here, the LOD query is done in divergent control flow and this can lead to undefined results as some of the lane values can get disabled.

You can reproduce on Zink/Anv on DG2 with :

$ MESA_LOADER_DRIVER_OVERRIDE=zink ANV_ALWAYS_BINDLESS=1 ./bin/shader_runner tests/spec/arb_texture_query_lod/execution/fs-textureQueryLOD-linear.shader_test -auto -fbo

There is also an excellent blog post about this [2].

[1] : https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#textures-derivative-image-operations [2] : https://themaister.net/blog/2019/09/12/the-weird-world-of-shader-divergence-and-lod/

Signed-off-by: Lionel Landwerlin lionel.g.landwerlin@intel.com

Edited by Lionel Landwerlin

Merge request reports