anv/state: Respect SamplerCreateInfo.anisotropyEnable
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 7 Jan 2016 03:48:57 +0000 (19:48 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 14 Jan 2016 15:30:46 +0000 (07:30 -0800)
src/vulkan/gen7_state.c
src/vulkan/gen8_state.c
src/vulkan/genX_state_util.h

index 88598cea18e5943ccafc9e9176ab717fb558520b..09c1332e450cb878807ac8f59766500ff25bcb19 100644 (file)
@@ -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,
index 13b7e1149d98d25d5acc003c9905d72514368348..b6741e005d3967070f4b26184dfa4515decd0436 100644 (file)
@@ -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,
index 0741d766edd95996758bd1daa0a6a26d55169ae6..f7a860e796b66fcffdf4e3fe017ddc16915bd768 100644 (file)
@@ -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,