v3dv/descriptor: move descriptor_map_get_sampler, add and use get_image_view

First one as we plan to use get_sampler on more places, second one
just to get cleaner code.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c
index ddafc89..aac8a37 100644
--- a/src/broadcom/vulkan/v3dv_cmd_buffer.c
+++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c
@@ -1951,27 +1951,22 @@
 cmd_buffer_populate_v3d_key(struct v3d_key *key,
                             struct v3dv_cmd_buffer *cmd_buffer)
 {
-   struct v3dv_descriptor_map *map = &cmd_buffer->state.pipeline->texture_map;
+   struct v3dv_descriptor_map *texture_map = &cmd_buffer->state.pipeline->texture_map;
    struct v3dv_descriptor_state *descriptor_state =
       &cmd_buffer->state.descriptor_state;
 
-   for (uint32_t i = 0; i < map->num_desc; i++) {
-      struct v3dv_descriptor *descriptor =
-         v3dv_descriptor_map_get_descriptor(descriptor_state,
-                                            map,
+   for (uint32_t i = 0; i < texture_map->num_desc; i++) {
+      struct v3dv_image_view *image_view =
+         v3dv_descriptor_map_get_image_view(descriptor_state,
+                                            texture_map,
                                             cmd_buffer->state.pipeline->layout,
-                                            i, NULL);
+                                            i);
 
-      if (descriptor == NULL)
+      if (image_view == NULL)
          return false;
 
-      assert(descriptor->type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE ||
-             descriptor->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
-      assert(descriptor->image_view);
-      assert(descriptor->image_view->image);
-
       key->tex[i].return_size =
-         v3dv_get_tex_return_size(descriptor->image_view->format,
+         v3dv_get_tex_return_size(image_view->format,
                                   0); /* FIXME: how to get the sampler compare mode? */
 
       if (key->tex[i].return_size == 16) {
diff --git a/src/broadcom/vulkan/v3dv_descriptor_set.c b/src/broadcom/vulkan/v3dv_descriptor_set.c
index 34d3ca2..6d860a6 100644
--- a/src/broadcom/vulkan/v3dv_descriptor_set.c
+++ b/src/broadcom/vulkan/v3dv_descriptor_set.c
@@ -90,6 +90,88 @@
 }
 
 /*
+ * The difference between this method and v3dv_descriptor_map_get_descriptor,
+ * is that if the sampler are added as immutable when creating the set layout,
+ * they are bound to the set layout, so not part of the descriptor per
+ * se. This method return early in that case.
+ */
+const struct v3dv_sampler *
+v3dv_descriptor_map_get_sampler(struct v3dv_descriptor_state *descriptor_state,
+                                struct v3dv_descriptor_map *map,
+                                struct v3dv_pipeline_layout *pipeline_layout,
+                                uint32_t index)
+{
+   assert(index >= 0 && index < map->num_desc);
+
+   uint32_t set_number = map->set[index];
+   if (!(descriptor_state->valid & 1 << set_number)) {
+      return NULL;
+   }
+
+   struct v3dv_descriptor_set *set =
+      descriptor_state->descriptor_sets[set_number];
+
+   if (set == NULL)
+      return NULL;
+
+   uint32_t binding_number = map->binding[index];
+   assert(binding_number < set->layout->binding_count);
+
+   const struct v3dv_descriptor_set_binding_layout *binding_layout =
+      &set->layout->binding[binding_number];
+
+   uint32_t array_index = map->array_index[index];
+   assert(array_index < binding_layout->array_size);
+
+   if (binding_layout->immutable_samplers_offset != 0) {
+      assert(binding_layout->type == VK_DESCRIPTOR_TYPE_SAMPLER ||
+             binding_layout->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
+
+      const struct v3dv_sampler *immutable_samplers =
+         v3dv_immutable_samplers(set->layout, binding_layout);
+
+      assert(immutable_samplers);
+      const struct v3dv_sampler *sampler = &immutable_samplers[array_index];
+      assert(sampler);
+
+      return sampler;
+   }
+
+   struct v3dv_descriptor *descriptor =
+      &set->descriptors[binding_layout->descriptor_index + array_index];
+
+   assert(descriptor->type == VK_DESCRIPTOR_TYPE_SAMPLER ||
+          descriptor->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
+
+   assert(descriptor->sampler);
+
+   return descriptor->sampler;
+}
+
+struct v3dv_image_view *
+v3dv_descriptor_map_get_image_view(struct v3dv_descriptor_state *descriptor_state,
+                                   struct v3dv_descriptor_map *map,
+                                   struct v3dv_pipeline_layout *pipeline_layout,
+                                   uint32_t index)
+{
+   struct v3dv_descriptor *image_descriptor =
+      v3dv_descriptor_map_get_descriptor(descriptor_state,
+                                         map,
+                                         pipeline_layout,
+                                         index, NULL);
+
+   if (image_descriptor == NULL)
+      return NULL;
+
+   assert(image_descriptor->type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE ||
+          image_descriptor->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
+   assert(image_descriptor->image_view);
+   assert(image_descriptor->image_view->image);
+
+   return image_descriptor->image_view;
+}
+
+/*
  * As anv and tu already points:
  *
  * "Pipeline layouts.  These have nothing to do with the pipeline.  They are
diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h
index 97d5940..fc93fb0 100644
--- a/src/broadcom/vulkan/v3dv_private.h
+++ b/src/broadcom/vulkan/v3dv_private.h
@@ -1237,6 +1237,18 @@
                                    uint32_t index,
                                    uint32_t *dynamic_offset);
 
+const struct v3dv_sampler *
+v3dv_descriptor_map_get_sampler(struct v3dv_descriptor_state *descriptor_state,
+                                struct v3dv_descriptor_map *map,
+                                struct v3dv_pipeline_layout *pipeline_layout,
+                                uint32_t index);
+
+struct v3dv_image_view *
+v3dv_descriptor_map_get_image_view(struct v3dv_descriptor_state *descriptor_state,
+                                   struct v3dv_descriptor_map *map,
+                                   struct v3dv_pipeline_layout *pipeline_layout,
+                                   uint32_t index);
+
 static inline const struct v3dv_sampler *
 v3dv_immutable_samplers(const struct v3dv_descriptor_set_layout *set,
                         const struct v3dv_descriptor_set_binding_layout *binding)
diff --git a/src/broadcom/vulkan/v3dv_uniforms.c b/src/broadcom/vulkan/v3dv_uniforms.c
index 456c16c..48ba4e7 100644
--- a/src/broadcom/vulkan/v3dv_uniforms.c
+++ b/src/broadcom/vulkan/v3dv_uniforms.c
@@ -81,66 +81,6 @@
    cmd_buffer->state.dirty &= ~V3DV_CMD_DIRTY_PUSH_CONSTANTS;
 }
 
-/*
- * The difference between this method and v3dv_descriptor_map_get_descriptor,
- * is that if the sampler are added as immutable when creating the set layout,
- * they are bound to the set layout, so not part of the descriptor per
- * se. This method return early in that case.
- */
-static const struct v3dv_sampler *
-descriptor_map_get_sampler(struct v3dv_descriptor_state *descriptor_state,
-                           struct v3dv_descriptor_map *map,
-                           struct v3dv_pipeline_layout *pipeline_layout,
-                           uint32_t index)
-
-{
-   assert(index >= 0 && index < map->num_desc);
-
-   uint32_t set_number = map->set[index];
-   if (!(descriptor_state->valid & 1 << set_number)) {
-      return NULL;
-   }
-
-   struct v3dv_descriptor_set *set =
-      descriptor_state->descriptor_sets[set_number];
-
-   if (set == NULL)
-      return NULL;
-
-   uint32_t binding_number = map->binding[index];
-   assert(binding_number < set->layout->binding_count);
-
-   const struct v3dv_descriptor_set_binding_layout *binding_layout =
-      &set->layout->binding[binding_number];
-
-   uint32_t array_index = map->array_index[index];
-   assert(array_index < binding_layout->array_size);
-
-   if (binding_layout->immutable_samplers_offset != 0) {
-      assert(binding_layout->type == VK_DESCRIPTOR_TYPE_SAMPLER ||
-             binding_layout->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
-
-      const struct v3dv_sampler *immutable_samplers =
-         v3dv_immutable_samplers(set->layout, binding_layout);
-
-      assert(immutable_samplers);
-      const struct v3dv_sampler *sampler = &immutable_samplers[array_index];
-      assert(sampler);
-
-      return sampler;
-   }
-
-   struct v3dv_descriptor *descriptor =
-      &set->descriptors[binding_layout->descriptor_index + array_index];
-
-   assert(descriptor->type == VK_DESCRIPTOR_TYPE_SAMPLER ||
-          descriptor->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
-
-   assert(descriptor->sampler);
-
-   return descriptor->sampler;
-}
-
 /** V3D 4.x TMU configuration parameter 0 (texture) */
 static void
 write_tmu_p0(struct v3dv_cmd_buffer *cmd_buffer,
@@ -154,19 +94,18 @@
    struct v3dv_descriptor_state *descriptor_state =
       &cmd_buffer->state.descriptor_state;
 
-   struct v3dv_descriptor *descriptor =
-      v3dv_descriptor_map_get_descriptor(descriptor_state, &pipeline->texture_map,
-                                         pipeline->layout, unit, NULL);
+   struct v3dv_image_view *image_view =
+      v3dv_descriptor_map_get_image_view(descriptor_state, &pipeline->texture_map,
+                                         pipeline->layout, unit);
 
-   assert(descriptor);
-   assert(descriptor->image_view);
+   assert(image_view);
 
    cl_aligned_reloc(&job->indirect, uniforms,
-                    descriptor->image_view->texture_shader_state,
+                    image_view->texture_shader_state,
                     v3d_unit_data_get_offset(data));
 
    /* We need to ensure that the texture bo is added to the job */
-   v3dv_job_add_bo(job, descriptor->image_view->image->mem->bo);
+   v3dv_job_add_bo(job, image_view->image->mem->bo);
 }
 
 /** V3D 4.x TMU configuration parameter 1 (sampler) */
@@ -182,8 +121,8 @@
       &cmd_buffer->state.descriptor_state;
 
    const struct v3dv_sampler *sampler =
-      descriptor_map_get_sampler(descriptor_state, &pipeline->sampler_map,
-                                 pipeline->layout, unit);
+      v3dv_descriptor_map_get_sampler(descriptor_state, &pipeline->sampler_map,
+                                      pipeline->layout, unit);
 
    assert(sampler);