vulkan,nir: Refactor ycbcr conversion state into a struct
authorKonstantin Seurer <konstantin.seurer@gmail.com>
Mon, 16 Jan 2023 19:47:22 +0000 (20:47 +0100)
committerMarge Bot <emma+marge@anholt.net>
Mon, 6 Feb 2023 18:36:29 +0000 (18:36 +0000)
This will be useful for RADV since it hashes the state.

v3dv changes:
Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20731>

src/broadcom/vulkan/v3dv_descriptor_set.c
src/broadcom/vulkan/v3dv_device.c
src/broadcom/vulkan/v3dv_pipeline.c
src/compiler/nir/nir_convert_ycbcr.c
src/compiler/nir/nir_vulkan.h
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_pipeline.c
src/intel/vulkan/genX_state.c
src/vulkan/runtime/vk_ycbcr_conversion.c
src/vulkan/runtime/vk_ycbcr_conversion.h

index beead08..1d777ba 100644 (file)
@@ -292,7 +292,7 @@ v3dv_descriptor_map_get_texture_shader_state(struct v3dv_device *device,
 
 static void
 sha1_update_ycbcr_conversion(struct mesa_sha1 *ctx,
-                             const struct vk_ycbcr_conversion *conversion)
+                             const struct vk_ycbcr_conversion_state *conversion)
 {
    SHA1_UPDATE_VALUE(ctx, conversion->format);
    SHA1_UPDATE_VALUE(ctx, conversion->ycbcr_model);
@@ -323,7 +323,7 @@ sha1_update_descriptor_set_binding_layout(struct mesa_sha1 *ctx,
       for (unsigned i = 0; i < layout->array_size; i++) {
          const struct v3dv_sampler *sampler = &immutable_samplers[i];
          if (sampler->conversion)
-            sha1_update_ycbcr_conversion(ctx, sampler->conversion);
+            sha1_update_ycbcr_conversion(ctx, &sampler->conversion->state);
       }
    }
 }
index ad082d5..6fedb66 100644 (file)
@@ -3060,7 +3060,7 @@ v3dv_CreateSampler(VkDevice _device,
 
    if (ycbcr_conv_info) {
       VK_FROM_HANDLE(vk_ycbcr_conversion, conversion, ycbcr_conv_info->conversion);
-      ycbcr_info = vk_format_get_ycbcr_info(conversion->format);
+      ycbcr_info = vk_format_get_ycbcr_info(conversion->state.format);
       if (ycbcr_info) {
          sampler->plane_count = ycbcr_info->n_planes;
          sampler->conversion = conversion;
index 4f942a6..cbffa53 100644 (file)
@@ -247,7 +247,7 @@ v3dv_pipeline_get_nir_options(void)
    return &v3dv_nir_options;
 }
 
-static const struct vk_ycbcr_conversion *
+static const struct vk_ycbcr_conversion_state *
 lookup_ycbcr_conversion(const void *_pipeline_layout, uint32_t set,
                         uint32_t binding, uint32_t array_index)
 {
@@ -266,7 +266,7 @@ lookup_ycbcr_conversion(const void *_pipeline_layout, uint32_t set,
       const struct v3dv_sampler *immutable_samplers =
          v3dv_immutable_samplers(set_layout, bind_layout);
       const struct v3dv_sampler *sampler = &immutable_samplers[array_index];
-      return sampler->conversion;
+      return sampler->conversion ? &sampler->conversion->state : NULL;
    } else {
       return NULL;
    }
index 60027b4..14013b6 100644 (file)
@@ -148,7 +148,7 @@ struct ycbcr_state {
    nir_ssa_def *image_size;
    nir_tex_instr *origin_tex;
    nir_deref_instr *tex_deref;
-   const struct vk_ycbcr_conversion *conversion;
+   const struct vk_ycbcr_conversion_state *conversion;
    const struct vk_format_ycbcr_info *format_ycbcr_info;
 };
 
@@ -202,7 +202,7 @@ implicit_downsampled_coords(struct ycbcr_state *state,
                             const struct vk_format_ycbcr_plane *format_plane)
 {
    nir_builder *b = state->builder;
-   const struct vk_ycbcr_conversion *conversion = state->conversion;
+   const struct vk_ycbcr_conversion_state *conversion = state->conversion;
    nir_ssa_def *image_size = get_texture_size(state, state->tex_deref);
    nir_ssa_def *comp[4] = { NULL, };
    int c;
@@ -231,7 +231,7 @@ create_plane_tex_instr_implicit(struct ycbcr_state *state,
                                 uint32_t plane)
 {
    nir_builder *b = state->builder;
-   const struct vk_ycbcr_conversion *conversion = state->conversion;
+   const struct vk_ycbcr_conversion_state *conversion = state->conversion;
    const struct vk_format_ycbcr_plane *format_plane =
       &state->format_ycbcr_info->planes[plane];
    nir_tex_instr *old_tex = state->origin_tex;
@@ -337,7 +337,7 @@ lower_ycbcr_tex_instr(nir_builder *b, nir_instr *instr, void *_state)
       array_index = nir_src_as_uint(deref->arr.index);
    }
 
-   const struct vk_ycbcr_conversion *conversion =
+   const struct vk_ycbcr_conversion_state *conversion =
       state->cb(state->cb_data, set, binding, array_index);
    if (conversion == NULL)
       return false;
index 06c1e17..0d84a7a 100644 (file)
@@ -41,7 +41,7 @@ nir_convert_ycbcr_to_rgb(nir_builder *b,
 
 struct vk_ycbcr_conversion;
 
-typedef const struct vk_ycbcr_conversion *
+typedef const struct vk_ycbcr_conversion_state *
    (*nir_vk_ycbcr_conversion_lookup_cb)(const void *data, uint32_t set,
                                         uint32_t binding, uint32_t array_index);
 
index 0cda512..4926c58 100644 (file)
@@ -2541,7 +2541,7 @@ anv_CreateImageView(VkDevice _device,
 
    if (conv_info) {
       VK_FROM_HANDLE(vk_ycbcr_conversion, conversion, conv_info->conversion);
-      conv_format = conversion->format;
+      conv_format = conversion->state.format;
    }
 
 #ifdef ANDROID
index 75f82de..5677c72 100644 (file)
@@ -772,7 +772,7 @@ anv_pipeline_stage_get_nir(struct anv_pipeline *pipeline,
    return NULL;
 }
 
-static const struct vk_ycbcr_conversion *
+static const struct vk_ycbcr_conversion_state *
 lookup_ycbcr_conversion(const void *_pipeline_layout, uint32_t set,
                         uint32_t binding, uint32_t array_index)
 {
@@ -791,7 +791,7 @@ lookup_ycbcr_conversion(const void *_pipeline_layout, uint32_t set,
    const struct anv_sampler *sampler =
       bind_layout->immutable_samplers[array_index];
 
-   return sampler ? sampler->conversion : NULL;
+   return sampler && sampler->conversion ? &sampler->conversion->state : NULL;
 }
 
 static void
index e0e24c4..f8305de 100644 (file)
@@ -852,7 +852,7 @@ VkResult genX(CreateSampler)(
          if (conversion == NULL)
             break;
 
-         ycbcr_info = vk_format_get_ycbcr_info(conversion->format);
+         ycbcr_info = vk_format_get_ycbcr_info(conversion->state.format);
          if (ycbcr_info == NULL)
             break;
 
@@ -926,16 +926,16 @@ VkResult genX(CreateSampler)(
       const bool plane_has_chroma =
          ycbcr_info && ycbcr_info->planes[p].has_chroma;
       const VkFilter min_filter =
-         plane_has_chroma ? sampler->conversion->chroma_filter : pCreateInfo->minFilter;
+         plane_has_chroma ? sampler->conversion->state.chroma_filter : pCreateInfo->minFilter;
       const VkFilter mag_filter =
-         plane_has_chroma ? sampler->conversion->chroma_filter : pCreateInfo->magFilter;
+         plane_has_chroma ? sampler->conversion->state.chroma_filter : pCreateInfo->magFilter;
       const bool enable_min_filter_addr_rounding = min_filter != VK_FILTER_NEAREST;
       const bool enable_mag_filter_addr_rounding = mag_filter != VK_FILTER_NEAREST;
       /* From Broadwell PRM, SAMPLER_STATE:
        *   "Mip Mode Filter must be set to MIPFILTER_NONE for Planar YUV surfaces."
        */
       enum isl_format plane0_isl_format = sampler->conversion ?
-         anv_get_format(sampler->conversion->format)->planes[0].isl_format :
+         anv_get_format(sampler->conversion->state.format)->planes[0].isl_format :
          ISL_FORMAT_UNSUPPORTED;
       const bool isl_format_is_planar_yuv =
          plane0_isl_format != ISL_FORMAT_UNSUPPORTED &&
index e461a59..9c1da39 100644 (file)
@@ -46,9 +46,11 @@ vk_common_CreateSamplerYcbcrConversion(VkDevice _device,
    if (!conversion)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
-   conversion->format = pCreateInfo->format;
-   conversion->ycbcr_model = pCreateInfo->ycbcrModel;
-   conversion->ycbcr_range = pCreateInfo->ycbcrRange;
+   struct vk_ycbcr_conversion_state *state = &conversion->state;
+
+   state->format = pCreateInfo->format;
+   state->ycbcr_model = pCreateInfo->ycbcrModel;
+   state->ycbcr_range = pCreateInfo->ycbcrRange;
 
    /* Search for VkExternalFormatANDROID and resolve the format. */
    const VkExternalFormatANDROID *android_ext_info =
@@ -57,25 +59,25 @@ vk_common_CreateSamplerYcbcrConversion(VkDevice _device,
    /* We assume that Android externalFormat is just a VkFormat */
    if (android_ext_info && android_ext_info->externalFormat) {
       assert(pCreateInfo->format == VK_FORMAT_UNDEFINED);
-      conversion->format = android_ext_info->externalFormat;
+      state->format = android_ext_info->externalFormat;
    } else {
       /* The Vulkan 1.1.95 spec says:
        *
        *    "When creating an external format conversion, the value of
        *    components if ignored."
        */
-      conversion->mapping[0] = pCreateInfo->components.r;
-      conversion->mapping[1] = pCreateInfo->components.g;
-      conversion->mapping[2] = pCreateInfo->components.b;
-      conversion->mapping[3] = pCreateInfo->components.a;
+      state->mapping[0] = pCreateInfo->components.r;
+      state->mapping[1] = pCreateInfo->components.g;
+      state->mapping[2] = pCreateInfo->components.b;
+      state->mapping[3] = pCreateInfo->components.a;
    }
 
-   conversion->chroma_offsets[0] = pCreateInfo->xChromaOffset;
-   conversion->chroma_offsets[1] = pCreateInfo->yChromaOffset;
-   conversion->chroma_filter = pCreateInfo->chromaFilter;
+   state->chroma_offsets[0] = pCreateInfo->xChromaOffset;
+   state->chroma_offsets[1] = pCreateInfo->yChromaOffset;
+   state->chroma_filter = pCreateInfo->chromaFilter;
 
    const struct vk_format_ycbcr_info *ycbcr_info =
-      vk_format_get_ycbcr_info(conversion->format);
+      vk_format_get_ycbcr_info(state->format);
 
    bool has_chroma_subsampled = false;
    if (ycbcr_info) {
@@ -86,9 +88,9 @@ vk_common_CreateSamplerYcbcrConversion(VkDevice _device,
             has_chroma_subsampled = true;
       }
    }
-   conversion->chroma_reconstruction = has_chroma_subsampled &&
-      (conversion->chroma_offsets[0] == VK_CHROMA_LOCATION_COSITED_EVEN ||
-       conversion->chroma_offsets[1] == VK_CHROMA_LOCATION_COSITED_EVEN);
+   state->chroma_reconstruction = has_chroma_subsampled &&
+      (state->chroma_offsets[0] == VK_CHROMA_LOCATION_COSITED_EVEN ||
+       state->chroma_offsets[1] == VK_CHROMA_LOCATION_COSITED_EVEN);
 
    *pYcbcrConversion = vk_ycbcr_conversion_to_handle(conversion);
 
index c16a5c4..cc4ed3e 100644 (file)
@@ -29,9 +29,7 @@
 extern "C" {
 #endif
 
-struct vk_ycbcr_conversion {
-   struct vk_object_base base;
-
+struct vk_ycbcr_conversion_state {
    VkFormat format;
    VkSamplerYcbcrModelConversion ycbcr_model;
    VkSamplerYcbcrRange ycbcr_range;
@@ -41,6 +39,11 @@ struct vk_ycbcr_conversion {
    bool chroma_reconstruction;
 };
 
+struct vk_ycbcr_conversion {
+   struct vk_object_base base;
+   struct vk_ycbcr_conversion_state state;
+};
+
 VK_DEFINE_NONDISP_HANDLE_CASTS(vk_ycbcr_conversion, base,
                                VkSamplerYcbcrConversion,
                                VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION)