From: Jason Ekstrand Date: Thu, 7 Jan 2016 03:48:57 +0000 (-0800) Subject: anv/state: Respect SamplerCreateInfo.anisotropyEnable X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ed4fe3e9ba9018e68afe6fdd4f267218a537fdaa;p=mesa.git anv/state: Respect SamplerCreateInfo.anisotropyEnable --- diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c index 88598cea18e..09c1332e450 100644 --- a/src/vulkan/gen7_state.c +++ b/src/vulkan/gen7_state.c @@ -84,7 +84,6 @@ VkResult genX(CreateSampler)( { ANV_FROM_HANDLE(anv_device, device, _device); struct anv_sampler *sampler; - uint32_t mag_filter, min_filter, max_anisotropy; assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO); @@ -93,23 +92,16 @@ VkResult genX(CreateSampler)( if (!sampler) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - if (pCreateInfo->maxAnisotropy > 1) { - mag_filter = MAPFILTER_ANISOTROPIC; - min_filter = MAPFILTER_ANISOTROPIC; - max_anisotropy = (pCreateInfo->maxAnisotropy - 2) / 2; - } else { - mag_filter = vk_to_gen_tex_filter[pCreateInfo->magFilter]; - min_filter = vk_to_gen_tex_filter[pCreateInfo->minFilter]; - max_anisotropy = RATIO21; - } + uint32_t filter = vk_to_gen_tex_filter(pCreateInfo->magFilter, + pCreateInfo->anisotropyEnable); struct GEN7_SAMPLER_STATE sampler_state = { .SamplerDisable = false, .TextureBorderColorMode = DX10OGL, .BaseMipLevel = 0.0, .MipModeFilter = vk_to_gen_mipmap_mode[pCreateInfo->mipmapMode], - .MagModeFilter = mag_filter, - .MinModeFilter = min_filter, + .MagModeFilter = filter, + .MinModeFilter = filter, .TextureLODBias = pCreateInfo->mipLodBias * 256, .AnisotropicAlgorithm = EWAApproximation, .MinLOD = pCreateInfo->minLod, @@ -124,7 +116,7 @@ VkResult genX(CreateSampler)( device->border_colors.offset + pCreateInfo->borderColor * sizeof(float) * 4, - .MaximumAnisotropy = max_anisotropy, + .MaximumAnisotropy = vk_to_gen_max_anisotropy(pCreateInfo->maxAnisotropy), .RAddressMinFilterRoundingEnable = 0, .RAddressMagFilterRoundingEnable = 0, .VAddressMinFilterRoundingEnable = 0, diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c index 13b7e1149d9..b6741e005d3 100644 --- a/src/vulkan/gen8_state.c +++ b/src/vulkan/gen8_state.c @@ -363,7 +363,6 @@ VkResult genX(CreateSampler)( { ANV_FROM_HANDLE(anv_device, device, _device); struct anv_sampler *sampler; - uint32_t mag_filter, min_filter, max_anisotropy; assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO); @@ -372,15 +371,8 @@ VkResult genX(CreateSampler)( if (!sampler) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - if (pCreateInfo->maxAnisotropy > 1) { - mag_filter = MAPFILTER_ANISOTROPIC; - min_filter = MAPFILTER_ANISOTROPIC; - max_anisotropy = (pCreateInfo->maxAnisotropy - 2) / 2; - } else { - mag_filter = vk_to_gen_tex_filter[pCreateInfo->magFilter]; - min_filter = vk_to_gen_tex_filter[pCreateInfo->minFilter]; - max_anisotropy = RATIO21; - } + uint32_t filter = vk_to_gen_tex_filter(pCreateInfo->magFilter, + pCreateInfo->anisotropyEnable); struct GENX(SAMPLER_STATE) sampler_state = { .SamplerDisable = false, @@ -390,8 +382,8 @@ VkResult genX(CreateSampler)( .BaseMipLevel = 0.0, #endif .MipModeFilter = vk_to_gen_mipmap_mode[pCreateInfo->mipmapMode], - .MagModeFilter = mag_filter, - .MinModeFilter = min_filter, + .MagModeFilter = filter, + .MinModeFilter = filter, .TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias, -16, 15.996), .AnisotropicAlgorithm = EWAApproximation, .MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14), @@ -407,7 +399,7 @@ VkResult genX(CreateSampler)( pCreateInfo->borderColor * sizeof(float) * 4, .LODClampMagnificationMode = MIPNONE, - .MaximumAnisotropy = max_anisotropy, + .MaximumAnisotropy = vk_to_gen_max_anisotropy(pCreateInfo->maxAnisotropy), .RAddressMinFilterRoundingEnable = 0, .RAddressMagFilterRoundingEnable = 0, .VAddressMinFilterRoundingEnable = 0, diff --git a/src/vulkan/genX_state_util.h b/src/vulkan/genX_state_util.h index 0741d766edd..f7a860e796b 100644 --- a/src/vulkan/genX_state_util.h +++ b/src/vulkan/genX_state_util.h @@ -66,10 +66,24 @@ vk_to_gen_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component) } #endif -static const uint32_t vk_to_gen_tex_filter[] = { - [VK_FILTER_NEAREST] = MAPFILTER_NEAREST, - [VK_FILTER_LINEAR] = MAPFILTER_LINEAR -}; +static inline uint32_t +vk_to_gen_tex_filter(VkFilter filter, bool anisotropyEnable) +{ + switch (filter) { + default: + assert(!"Invalid filter"); + case VK_FILTER_NEAREST: + return MAPFILTER_NEAREST; + case VK_FILTER_LINEAR: + return anisotropyEnable ? MAPFILTER_ANISOTROPIC : MAPFILTER_LINEAR; + } +} + +static inline uint32_t +vk_to_gen_max_anisotropy(float ratio) +{ + return (anv_clamp_f(ratio, 2, 16) - 2) / 2; +} static const uint32_t vk_to_gen_mipmap_mode[] = { [VK_SAMPLER_MIPMAP_MODE_BASE] = MIPFILTER_NONE,