Mesa (staging/22.0): radv: Don't hash ycbcr sampler base object.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 1 16:17:35 UTC 2022


Module: Mesa
Branch: staging/22.0
Commit: 9dfef8d48f69da6f480767a83bb0a75e698f5049
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9dfef8d48f69da6f480767a83bb0a75e698f5049

Author: Georg Lehmann <dadschoorse at gmail.com>
Date:   Fri Mar 18 14:10:21 2022 +0100

radv: Don't hash ycbcr sampler base object.

Stops gamescope from recompiling pipelines on every start.

Cc: mesa-stable

Signed-off-by: Georg Lehmann <dadschoorse at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15454>

---

 .pick_status.json                              |  2 +-
 src/amd/vulkan/radv_descriptor_set.c           | 28 +++++++++++++-------------
 src/amd/vulkan/radv_descriptor_set.h           |  4 ++--
 src/amd/vulkan/radv_nir_lower_ycbcr_textures.c |  8 ++++----
 src/amd/vulkan/radv_private.h                  |  9 +++++++--
 5 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 9e99f283faf..20a50e6b8db 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -3620,7 +3620,7 @@
         "description": "radv: Don't hash ycbcr sampler base object.",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 5,
+        "resolution": 3,
         "because_sha": null
     },
     {
diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_descriptor_set.c
index a87dd93bd22..10ec09fd5d3 100644
--- a/src/amd/vulkan/radv_descriptor_set.c
+++ b/src/amd/vulkan/radv_descriptor_set.c
@@ -139,8 +139,8 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
       /* Store block of offsets first, followed by the conversion descriptors (padded to the struct
        * alignment) */
       size += num_bindings * sizeof(uint32_t);
-      size = ALIGN(size, alignof(struct radv_sampler_ycbcr_conversion));
-      size += ycbcr_sampler_count * sizeof(struct radv_sampler_ycbcr_conversion);
+      size = ALIGN(size, alignof(struct radv_sampler_ycbcr_conversion_state));
+      size += ycbcr_sampler_count * sizeof(struct radv_sampler_ycbcr_conversion_state);
    }
 
    /* We need to allocate decriptor set layouts off the device allocator with DEVICE scope because
@@ -159,7 +159,7 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
 
    /* We just allocate all the samplers at the end of the struct */
    uint32_t *samplers = (uint32_t *)&set_layout->binding[num_bindings];
-   struct radv_sampler_ycbcr_conversion *ycbcr_samplers = NULL;
+   struct radv_sampler_ycbcr_conversion_state *ycbcr_samplers = NULL;
    uint32_t *ycbcr_sampler_offsets = NULL;
 
    if (ycbcr_sampler_count > 0) {
@@ -169,8 +169,8 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
       uintptr_t first_ycbcr_sampler_offset =
          (uintptr_t)ycbcr_sampler_offsets + sizeof(uint32_t) * num_bindings;
       first_ycbcr_sampler_offset =
-         ALIGN(first_ycbcr_sampler_offset, alignof(struct radv_sampler_ycbcr_conversion));
-      ycbcr_samplers = (struct radv_sampler_ycbcr_conversion *)first_ycbcr_sampler_offset;
+         ALIGN(first_ycbcr_sampler_offset, alignof(struct radv_sampler_ycbcr_conversion_state));
+      ycbcr_samplers = (struct radv_sampler_ycbcr_conversion_state *)first_ycbcr_sampler_offset;
    } else
       set_layout->ycbcr_sampler_offsets_offset = 0;
 
@@ -212,7 +212,7 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
             if (conversion) {
                has_ycbcr_sampler = true;
                max_sampled_image_descriptors = MAX2(max_sampled_image_descriptors,
-                                                    vk_format_get_plane_count(conversion->format));
+                                                    vk_format_get_plane_count(conversion->state.format));
             }
          }
       }
@@ -325,7 +325,7 @@ radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCrea
             for (uint32_t i = 0; i < binding->descriptorCount; i++) {
                if (radv_sampler_from_handle(binding->pImmutableSamplers[i])->ycbcr_sampler)
                   ycbcr_samplers[i] =
-                     *radv_sampler_from_handle(binding->pImmutableSamplers[i])->ycbcr_sampler;
+                     radv_sampler_from_handle(binding->pImmutableSamplers[i])->ycbcr_sampler->state;
                else
                   ycbcr_samplers[i].format = VK_FORMAT_UNDEFINED;
             }
@@ -1569,13 +1569,13 @@ radv_CreateSamplerYcbcrConversion(VkDevice _device,
 
    vk_object_base_init(&device->vk, &conversion->base, VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION);
 
-   conversion->format = pCreateInfo->format;
-   conversion->ycbcr_model = pCreateInfo->ycbcrModel;
-   conversion->ycbcr_range = pCreateInfo->ycbcrRange;
-   conversion->components = pCreateInfo->components;
-   conversion->chroma_offsets[0] = pCreateInfo->xChromaOffset;
-   conversion->chroma_offsets[1] = pCreateInfo->yChromaOffset;
-   conversion->chroma_filter = pCreateInfo->chromaFilter;
+   conversion->state.format = pCreateInfo->format;
+   conversion->state.ycbcr_model = pCreateInfo->ycbcrModel;
+   conversion->state.ycbcr_range = pCreateInfo->ycbcrRange;
+   conversion->state.components = pCreateInfo->components;
+   conversion->state.chroma_offsets[0] = pCreateInfo->xChromaOffset;
+   conversion->state.chroma_offsets[1] = pCreateInfo->yChromaOffset;
+   conversion->state.chroma_filter = pCreateInfo->chromaFilter;
 
    *pYcbcrConversion = radv_sampler_ycbcr_conversion_to_handle(conversion);
    return VK_SUCCESS;
diff --git a/src/amd/vulkan/radv_descriptor_set.h b/src/amd/vulkan/radv_descriptor_set.h
index 0271fb9075c..ba852260e60 100644
--- a/src/amd/vulkan/radv_descriptor_set.h
+++ b/src/amd/vulkan/radv_descriptor_set.h
@@ -121,7 +121,7 @@ radv_combined_image_descriptor_sampler_offset(
    return binding->size - ((!binding->immutable_samplers_equal) ? 16 : 0);
 }
 
-static inline const struct radv_sampler_ycbcr_conversion *
+static inline const struct radv_sampler_ycbcr_conversion_state *
 radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout *set, unsigned binding_index)
 {
    if (!set->ycbcr_sampler_offsets_offset)
@@ -132,7 +132,7 @@ radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout *set, unsi
 
    if (offsets[binding_index] == 0)
       return NULL;
-   return (const struct radv_sampler_ycbcr_conversion *)((const char *)set +
+   return (const struct radv_sampler_ycbcr_conversion_state *)((const char *)set +
                                                          offsets[binding_index]);
 }
 #endif /* RADV_DESCRIPTOR_SET_H */
diff --git a/src/amd/vulkan/radv_nir_lower_ycbcr_textures.c b/src/amd/vulkan/radv_nir_lower_ycbcr_textures.c
index 8695f3bd04b..e5a38b23f3e 100644
--- a/src/amd/vulkan/radv_nir_lower_ycbcr_textures.c
+++ b/src/amd/vulkan/radv_nir_lower_ycbcr_textures.c
@@ -33,7 +33,7 @@ struct ycbcr_state {
    nir_ssa_def *image_size;
    nir_tex_instr *origin_tex;
    nir_deref_instr *tex_deref;
-   const struct radv_sampler_ycbcr_conversion *conversion;
+   const struct radv_sampler_ycbcr_conversion_state *conversion;
    bool unnormalized_coordinates;
 };
 
@@ -80,7 +80,7 @@ static nir_ssa_def *
 implicit_downsampled_coords(struct ycbcr_state *state, nir_ssa_def *old_coords)
 {
    nir_builder *b = state->builder;
-   const struct radv_sampler_ycbcr_conversion *conversion = state->conversion;
+   const struct radv_sampler_ycbcr_conversion_state *conversion = state->conversion;
    nir_ssa_def *image_size = NULL;
    nir_ssa_def *comp[4] = {
       NULL,
@@ -230,7 +230,7 @@ try_lower_tex_ycbcr(const struct radv_pipeline_layout *layout, nir_builder *buil
       layout->set[var->data.descriptor_set].layout;
    const struct radv_descriptor_set_binding_layout *binding =
       &set_layout->binding[var->data.binding];
-   const struct radv_sampler_ycbcr_conversion *ycbcr_samplers =
+   const struct radv_sampler_ycbcr_conversion_state *ycbcr_samplers =
       radv_immutable_ycbcr_samplers(set_layout, var->data.binding);
 
    if (!ycbcr_samplers)
@@ -255,7 +255,7 @@ try_lower_tex_ycbcr(const struct radv_pipeline_layout *layout, nir_builder *buil
       array_index = nir_src_as_uint(deref->arr.index);
       array_index = MIN2(array_index, binding->array_size - 1);
    }
-   const struct radv_sampler_ycbcr_conversion *ycbcr_sampler = ycbcr_samplers + array_index;
+   const struct radv_sampler_ycbcr_conversion_state *ycbcr_sampler = ycbcr_samplers + array_index;
 
    if (ycbcr_sampler->format == VK_FORMAT_UNDEFINED)
       return false;
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index ea7725fcadf..c547e74825d 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -2400,8 +2400,7 @@ void radv_image_view_finish(struct radv_image_view *iview);
 
 VkFormat radv_get_aspect_format(struct radv_image *image, VkImageAspectFlags mask);
 
-struct radv_sampler_ycbcr_conversion {
-   struct vk_object_base base;
+struct radv_sampler_ycbcr_conversion_state {
    VkFormat format;
    VkSamplerYcbcrModelConversion ycbcr_model;
    VkSamplerYcbcrRange ycbcr_range;
@@ -2410,6 +2409,12 @@ struct radv_sampler_ycbcr_conversion {
    VkFilter chroma_filter;
 };
 
+struct radv_sampler_ycbcr_conversion {
+   struct vk_object_base base;
+   /* The state is hashed for the descriptor set layout. */
+   struct radv_sampler_ycbcr_conversion_state state;
+};
+
 struct radv_buffer_view {
    struct vk_object_base base;
    struct radeon_winsys_bo *bo;



More information about the mesa-commit mailing list