From 88d5917cc1c5bd0dec26147a8779b50e94e56dd1 Mon Sep 17 00:00:00 2001 From: Jonathan Marek Date: Sat, 6 Jun 2020 22:08:41 -0400 Subject: [PATCH] turnip: clamp sampler minLod/maxLod Otherwise A6XX_TEX_SAMP_1_{MIN,MAX}_LOD silently overflows. This fixes these tests: dEQP-VK.texture.explicit_lod.2d.derivatives.* Signed-off-by: Jonathan Marek Part-of: --- src/freedreno/vulkan/tu_device.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index 5bf3d1d6c39..c471117e5ed 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -2186,6 +2186,8 @@ tu_init_sampler(struct tu_device *device, unsigned aniso = pCreateInfo->anisotropyEnable ? util_last_bit(MIN2((uint32_t)pCreateInfo->maxAnisotropy >> 1, 8)) : 0; bool miplinear = (pCreateInfo->mipmapMode == VK_SAMPLER_MIPMAP_MODE_LINEAR); + float min_lod = CLAMP(pCreateInfo->minLod, 0.0f, 4095.0f / 256.0f); + float max_lod = CLAMP(pCreateInfo->maxLod, 0.0f, 4095.0f / 256.0f); sampler->descriptor[0] = COND(miplinear, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR) | @@ -2199,8 +2201,8 @@ tu_init_sampler(struct tu_device *device, sampler->descriptor[1] = /* COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | */ COND(pCreateInfo->unnormalizedCoordinates, A6XX_TEX_SAMP_1_UNNORM_COORDS) | - A6XX_TEX_SAMP_1_MIN_LOD(pCreateInfo->minLod) | - A6XX_TEX_SAMP_1_MAX_LOD(pCreateInfo->maxLod) | + A6XX_TEX_SAMP_1_MIN_LOD(min_lod) | + A6XX_TEX_SAMP_1_MAX_LOD(max_lod) | COND(pCreateInfo->compareEnable, A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo->compareOp))); /* This is an offset into the border_color BO, which we fill with all the -- 2.30.2