anv: prepare sampler emission code for multiplanar images
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 25 Sep 2017 17:47:33 +0000 (18:47 +0100)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Fri, 6 Oct 2017 15:32:19 +0000 (16:32 +0100)
New settings from the KHR_sampler_ycbcr_conversion specifications
might require different sampler settings for luma and chroma planes.
This change makes the sampler table emission ready to handle multiple
planes.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/intel/vulkan/anv_private.h
src/intel/vulkan/genX_cmd_buffer.c
src/intel/vulkan/genX_state.c

index ff1b1cc8a80cb478fa79148482bdba52727d46fc..5dde45f7cb9705c0ed235a860ca87c732a0345b2 100644 (file)
@@ -2545,7 +2545,7 @@ void anv_fill_buffer_surface_state(struct anv_device *device,
                                    uint32_t stride);
 
 struct anv_sampler {
-   uint32_t state[4];
+   uint32_t state[3][4];
    uint32_t n_planes;
 };
 
index 3559399019840d6b36194cb3b3c18bf0ce1482ea..f19746db44257233bcc66836d0596abd8dd9c556 100644 (file)
@@ -1742,7 +1742,7 @@ emit_samplers(struct anv_cmd_buffer *cmd_buffer,
          continue;
 
       memcpy(state->map + (s * 16),
-             sampler->state, sizeof(sampler->state));
+             sampler->state[binding->plane], sizeof(sampler->state[0]));
    }
 
    anv_state_flush(cmd_buffer->device, *state);
index 81570825a543f481758fea195fc3e465a923fd2b..91da05cddbfd4fe2a436955588bcfeaa24a4d2ef 100644 (file)
@@ -166,7 +166,7 @@ VkResult genX(CreateSampler)(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
 
-   sampler = vk_alloc2(&device->alloc, pAllocator, sizeof(*sampler), 8,
+   sampler = vk_zalloc2(&device->alloc, pAllocator, sizeof(*sampler), 8,
                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!sampler)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -181,55 +181,57 @@ VkResult genX(CreateSampler)(
    bool enable_mag_filter_addr_rounding =
       pCreateInfo->magFilter != VK_FILTER_NEAREST;
 
-   struct GENX(SAMPLER_STATE) sampler_state = {
-      .SamplerDisable = false,
-      .TextureBorderColorMode = DX10OGL,
+   for (unsigned p = 0; p < sampler->n_planes; p++) {
+      struct GENX(SAMPLER_STATE) sampler_state = {
+         .SamplerDisable = false,
+         .TextureBorderColorMode = DX10OGL,
 
 #if GEN_GEN >= 8
-      .LODPreClampMode = CLAMP_MODE_OGL,
+         .LODPreClampMode = CLAMP_MODE_OGL,
 #else
-      .LODPreClampEnable = CLAMP_ENABLE_OGL,
+         .LODPreClampEnable = CLAMP_ENABLE_OGL,
 #endif
 
 #if GEN_GEN == 8
-      .BaseMipLevel = 0.0,
+         .BaseMipLevel = 0.0,
 #endif
-      .MipModeFilter = vk_to_gen_mipmap_mode[pCreateInfo->mipmapMode],
-      .MagModeFilter = vk_to_gen_tex_filter(pCreateInfo->magFilter,
-                                            pCreateInfo->anisotropyEnable),
-      .MinModeFilter = vk_to_gen_tex_filter(pCreateInfo->minFilter,
-                                            pCreateInfo->anisotropyEnable),
-      .TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias, -16, 15.996),
-      .AnisotropicAlgorithm = EWAApproximation,
-      .MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14),
-      .MaxLOD = anv_clamp_f(pCreateInfo->maxLod, 0, 14),
-      .ChromaKeyEnable = 0,
-      .ChromaKeyIndex = 0,
-      .ChromaKeyMode = 0,
-      .ShadowFunction = vk_to_gen_shadow_compare_op[pCreateInfo->compareOp],
-      .CubeSurfaceControlMode = OVERRIDE,
-
-      .BorderColorPointer = border_color_offset,
+         .MipModeFilter = vk_to_gen_mipmap_mode[pCreateInfo->mipmapMode],
+         .MagModeFilter = vk_to_gen_tex_filter(pCreateInfo->magFilter,
+                                               pCreateInfo->anisotropyEnable),
+         .MinModeFilter = vk_to_gen_tex_filter(pCreateInfo->minFilter,
+                                               pCreateInfo->anisotropyEnable),
+         .TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias, -16, 15.996),
+         .AnisotropicAlgorithm = EWAApproximation,
+         .MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14),
+         .MaxLOD = anv_clamp_f(pCreateInfo->maxLod, 0, 14),
+         .ChromaKeyEnable = 0,
+         .ChromaKeyIndex = 0,
+         .ChromaKeyMode = 0,
+         .ShadowFunction = vk_to_gen_shadow_compare_op[pCreateInfo->compareOp],
+         .CubeSurfaceControlMode = OVERRIDE,
+
+         .BorderColorPointer = border_color_offset,
 
 #if GEN_GEN >= 8
-      .LODClampMagnificationMode = MIPNONE,
+         .LODClampMagnificationMode = MIPNONE,
 #endif
 
-      .MaximumAnisotropy = vk_to_gen_max_anisotropy(pCreateInfo->maxAnisotropy),
-      .RAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
-      .RAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
-      .VAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
-      .VAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
-      .UAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
-      .UAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
-      .TrilinearFilterQuality = 0,
-      .NonnormalizedCoordinateEnable = pCreateInfo->unnormalizedCoordinates,
-      .TCXAddressControlMode = vk_to_gen_tex_address[pCreateInfo->addressModeU],
-      .TCYAddressControlMode = vk_to_gen_tex_address[pCreateInfo->addressModeV],
-      .TCZAddressControlMode = vk_to_gen_tex_address[pCreateInfo->addressModeW],
-   };
-
-   GENX(SAMPLER_STATE_pack)(NULL, sampler->state, &sampler_state);
+         .MaximumAnisotropy = vk_to_gen_max_anisotropy(pCreateInfo->maxAnisotropy),
+         .RAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
+         .RAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
+         .VAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
+         .VAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
+         .UAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
+         .UAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
+         .TrilinearFilterQuality = 0,
+         .NonnormalizedCoordinateEnable = pCreateInfo->unnormalizedCoordinates,
+         .TCXAddressControlMode = vk_to_gen_tex_address[pCreateInfo->addressModeU],
+         .TCYAddressControlMode = vk_to_gen_tex_address[pCreateInfo->addressModeV],
+         .TCZAddressControlMode = vk_to_gen_tex_address[pCreateInfo->addressModeW],
+      };
+
+      GENX(SAMPLER_STATE_pack)(NULL, sampler->state[p], &sampler_state);
+   }
 
    *pSampler = anv_sampler_to_handle(sampler);