Mesa (main): v3dv: split v3dv_descriptor hw version dependant to a new source file.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 22 10:35:42 UTC 2021


Module: Mesa
Branch: main
Commit: 1bea0d76b8ce9ecc2fa079a4e1ab98ec84442c3f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1bea0d76b8ce9ecc2fa079a4e1ab98ec84442c3f

Author: Alejandro Piñeiro <apinheiro at igalia.com>
Date:   Tue Jun  1 10:41:00 2021 +0200

v3dv: split v3dv_descriptor hw version dependant to a new source file.

As part of this, we get rid of the v3dv_xxx_descriptor structs to
v3dv_descriptor. The main reason is that in order to support several
versions, we would need to define them several times. Also, they were
somewhat an overkill even before, as their main advantage was getting
the offset for each data on the combined case. That functionality is
replaced with some new helpers.

Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11310>

---

 src/broadcom/vulkan/meson.build            |   1 +
 src/broadcom/vulkan/v3dv_descriptor_set.c  | 124 ++++++++++++-----------------
 src/broadcom/vulkan/v3dv_device.c          |   2 +-
 src/broadcom/vulkan/v3dv_private.h         |  35 +-------
 src/broadcom/vulkan/v3dv_uniforms.c        |   4 +-
 src/broadcom/vulkan/v3dvx_descriptor_set.c |  98 +++++++++++++++++++++++
 src/broadcom/vulkan/v3dvx_private.h        |   9 +++
 7 files changed, 165 insertions(+), 108 deletions(-)

diff --git a/src/broadcom/vulkan/meson.build b/src/broadcom/vulkan/meson.build
index c523fb713c2..3dadb49e69f 100644
--- a/src/broadcom/vulkan/meson.build
+++ b/src/broadcom/vulkan/meson.build
@@ -55,6 +55,7 @@ libv3dv_files = files(
 
 files_per_version = files(
   'v3dvx_cmd_buffer.c',
+  'v3dvx_descriptor_set.c',
   'v3dvx_device.c',
   'v3dvx_formats.c',
   'v3dvx_image.c',
diff --git a/src/broadcom/vulkan/v3dv_descriptor_set.c b/src/broadcom/vulkan/v3dv_descriptor_set.c
index 15f23912b65..81c2ee762b8 100644
--- a/src/broadcom/vulkan/v3dv_descriptor_set.c
+++ b/src/broadcom/vulkan/v3dv_descriptor_set.c
@@ -26,51 +26,21 @@
 
 #include "v3dv_private.h"
 
-/*
- * Returns how much space a given descriptor type needs on a bo (GPU
- * memory).
- */
-static uint32_t
-descriptor_bo_size(VkDescriptorType type)
-{
-   switch(type) {
-   case VK_DESCRIPTOR_TYPE_SAMPLER:
-      return sizeof(struct v3dv_sampler_descriptor);
-   case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-      return sizeof(struct v3dv_combined_image_sampler_descriptor);
-   case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
-   case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
-   case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
-   case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
-   case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
-      return sizeof(struct v3dv_sampled_image_descriptor);
-   default:
-      return 0;
-   }
-}
-
-uint32_t
-v3dv_max_descriptor_bo_size()
-{
-   return MAX3(sizeof(struct v3dv_sampler_descriptor),
-               sizeof(struct v3dv_combined_image_sampler_descriptor),
-               sizeof(struct v3dv_sampled_image_descriptor));
-}
-
 /*
  * For a given descriptor defined by the descriptor_set it belongs, its
  * binding layout, and array_index, it returns the map region assigned to it
  * from the descriptor pool bo.
  */
 static void*
-descriptor_bo_map(struct v3dv_descriptor_set *set,
+descriptor_bo_map(struct v3dv_device *device,
+                  struct v3dv_descriptor_set *set,
                   const struct v3dv_descriptor_set_binding_layout *binding_layout,
                   uint32_t array_index)
 {
-   assert(descriptor_bo_size(binding_layout->type) > 0);
+   assert(v3dv_X(device, descriptor_bo_size)(binding_layout->type) > 0);
    return set->pool->bo->map +
       set->base_offset + binding_layout->descriptor_offset +
-      array_index * descriptor_bo_size(binding_layout->type);
+      array_index * v3dv_X(device, descriptor_bo_size)(binding_layout->type);
 }
 
 static bool
@@ -133,7 +103,8 @@ v3dv_descriptor_map_get_descriptor(struct v3dv_descriptor_state *descriptor_stat
  * validation or adding extra offsets if the bo contains more that one field.
  */
 static struct v3dv_cl_reloc
-v3dv_descriptor_map_get_descriptor_bo(struct v3dv_descriptor_state *descriptor_state,
+v3dv_descriptor_map_get_descriptor_bo(struct v3dv_device *device,
+                                      struct v3dv_descriptor_state *descriptor_state,
                                       struct v3dv_descriptor_map *map,
                                       struct v3dv_pipeline_layout *pipeline_layout,
                                       uint32_t index,
@@ -154,7 +125,7 @@ v3dv_descriptor_map_get_descriptor_bo(struct v3dv_descriptor_state *descriptor_s
    const struct v3dv_descriptor_set_binding_layout *binding_layout =
       &set->layout->binding[binding_number];
 
-   assert(descriptor_bo_size(binding_layout->type) > 0);
+   assert(v3dv_X(device, descriptor_bo_size)(binding_layout->type) > 0);
    *out_type = binding_layout->type;
 
    uint32_t array_index = map->array_index[index];
@@ -163,7 +134,7 @@ v3dv_descriptor_map_get_descriptor_bo(struct v3dv_descriptor_state *descriptor_s
    struct v3dv_cl_reloc reloc = {
       .bo = set->pool->bo,
       .offset = set->base_offset + binding_layout->descriptor_offset +
-      array_index * descriptor_bo_size(binding_layout->type),
+      array_index * v3dv_X(device, descriptor_bo_size)(binding_layout->type),
    };
 
    return reloc;
@@ -226,24 +197,23 @@ v3dv_descriptor_map_get_sampler(struct v3dv_descriptor_state *descriptor_state,
 
 
 struct v3dv_cl_reloc
-v3dv_descriptor_map_get_sampler_state(struct v3dv_descriptor_state *descriptor_state,
+v3dv_descriptor_map_get_sampler_state(struct v3dv_device *device,
+                                      struct v3dv_descriptor_state *descriptor_state,
                                       struct v3dv_descriptor_map *map,
                                       struct v3dv_pipeline_layout *pipeline_layout,
                                       uint32_t index)
 {
    VkDescriptorType type;
    struct v3dv_cl_reloc reloc =
-      v3dv_descriptor_map_get_descriptor_bo(descriptor_state, map,
+      v3dv_descriptor_map_get_descriptor_bo(device, descriptor_state, map,
                                             pipeline_layout,
                                             index, &type);
 
    assert(type == VK_DESCRIPTOR_TYPE_SAMPLER ||
           type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
 
-   if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
-      reloc.offset += offsetof(struct v3dv_combined_image_sampler_descriptor,
-                               sampler_state);
-   }
+   if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
+      reloc.offset += v3dv_X(device, combined_image_sampler_sampler_state_offset)();
 
    return reloc;
 }
@@ -305,14 +275,16 @@ v3dv_descriptor_map_get_texture_bo(struct v3dv_descriptor_state *descriptor_stat
 }
 
 struct v3dv_cl_reloc
-v3dv_descriptor_map_get_texture_shader_state(struct v3dv_descriptor_state *descriptor_state,
+v3dv_descriptor_map_get_texture_shader_state(struct v3dv_device *device,
+                                             struct v3dv_descriptor_state *descriptor_state,
                                              struct v3dv_descriptor_map *map,
                                              struct v3dv_pipeline_layout *pipeline_layout,
                                              uint32_t index)
 {
    VkDescriptorType type;
    struct v3dv_cl_reloc reloc =
-      v3dv_descriptor_map_get_descriptor_bo(descriptor_state, map,
+      v3dv_descriptor_map_get_descriptor_bo(device,
+                                            descriptor_state, map,
                                             pipeline_layout,
                                             index, &type);
 
@@ -323,10 +295,8 @@ v3dv_descriptor_map_get_texture_shader_state(struct v3dv_descriptor_state *descr
           type == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER ||
           type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER);
 
-   if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
-      reloc.offset += offsetof(struct v3dv_combined_image_sampler_descriptor,
-                               texture_state);
-   }
+   if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
+      reloc.offset += v3dv_X(device, combined_image_sampler_texture_state_offset)();
 
    return reloc;
 }
@@ -443,7 +413,7 @@ v3dv_CreateDescriptorPool(VkDevice _device,
 
       assert(pCreateInfo->pPoolSizes[i].descriptorCount > 0);
       descriptor_count += pCreateInfo->pPoolSizes[i].descriptorCount;
-      bo_size += descriptor_bo_size(pCreateInfo->pPoolSizes[i].type) *
+      bo_size += v3dv_X(device, descriptor_bo_size)(pCreateInfo->pPoolSizes[i].type) *
          pCreateInfo->pPoolSizes[i].descriptorCount;
    }
 
@@ -688,7 +658,7 @@ v3dv_CreateDescriptorSetLayout(VkDevice _device,
 
       set_layout->binding[binding_number].descriptor_offset = set_layout->bo_size;
       set_layout->bo_size +=
-         descriptor_bo_size(set_layout->binding[binding_number].type) *
+         v3dv_X(device, descriptor_bo_size)(set_layout->binding[binding_number].type) *
          binding->descriptorCount;
    }
 
@@ -826,10 +796,9 @@ descriptor_set_create(struct v3dv_device *device,
       for (uint32_t i = 0; i < layout->binding[b].array_size; i++) {
          uint32_t combined_offset =
             layout->binding[b].type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ?
-            offsetof(struct v3dv_combined_image_sampler_descriptor, sampler_state) :
-            0;
+            v3dv_X(device, combined_image_sampler_sampler_state_offset)() : 0;
 
-         void *desc_map = descriptor_bo_map(set, &layout->binding[b], i);
+         void *desc_map = descriptor_bo_map(device, set, &layout->binding[b], i);
          desc_map += combined_offset;
 
          memcpy(desc_map,
@@ -896,7 +865,8 @@ v3dv_FreeDescriptorSets(VkDevice _device,
 }
 
 static void
-descriptor_bo_copy(struct v3dv_descriptor_set *dst_set,
+descriptor_bo_copy(struct v3dv_device *device,
+                   struct v3dv_descriptor_set *dst_set,
                    const struct v3dv_descriptor_set_binding_layout *dst_binding_layout,
                    uint32_t dst_array_index,
                    struct v3dv_descriptor_set *src_set,
@@ -905,10 +875,10 @@ descriptor_bo_copy(struct v3dv_descriptor_set *dst_set,
 {
    assert(dst_binding_layout->type == src_binding_layout->type);
 
-   void *dst_map = descriptor_bo_map(dst_set, dst_binding_layout, dst_array_index);
-   void *src_map = descriptor_bo_map(src_set, src_binding_layout, src_array_index);
+   void *dst_map = descriptor_bo_map(device, dst_set, dst_binding_layout, dst_array_index);
+   void *src_map = descriptor_bo_map(device, src_set, src_binding_layout, src_array_index);
 
-   memcpy(dst_map, src_map, descriptor_bo_size(src_binding_layout->type));
+   memcpy(dst_map, src_map, v3dv_X(device, descriptor_bo_size)(src_binding_layout->type));
 }
 
 static void
@@ -930,7 +900,8 @@ write_buffer_descriptor(struct v3dv_descriptor *descriptor,
 }
 
 static void
-write_image_descriptor(struct v3dv_descriptor *descriptor,
+write_image_descriptor(struct v3dv_device *device,
+                       struct v3dv_descriptor *descriptor,
                        VkDescriptorType desc_type,
                        struct v3dv_descriptor_set *set,
                        const struct v3dv_descriptor_set_binding_layout *binding_layout,
@@ -942,7 +913,8 @@ write_image_descriptor(struct v3dv_descriptor *descriptor,
    descriptor->sampler = sampler;
    descriptor->image_view = iview;
 
-   void *desc_map = descriptor_bo_map(set, binding_layout, array_index);
+   void *desc_map = descriptor_bo_map(device, set,
+                                      binding_layout, array_index);
 
    if (iview) {
       const uint32_t tex_state_index =
@@ -951,8 +923,7 @@ write_image_descriptor(struct v3dv_descriptor *descriptor,
       memcpy(desc_map,
              iview->texture_shader_state[tex_state_index],
              sizeof(iview->texture_shader_state[0]));
-      desc_map += offsetof(struct v3dv_combined_image_sampler_descriptor,
-                           sampler_state);
+      desc_map += v3dv_X(device, combined_image_sampler_sampler_state_offset)();
    }
 
    if (sampler && !binding_layout->immutable_samplers_offset) {
@@ -967,7 +938,8 @@ write_image_descriptor(struct v3dv_descriptor *descriptor,
 
 
 static void
-write_buffer_view_descriptor(struct v3dv_descriptor *descriptor,
+write_buffer_view_descriptor(struct v3dv_device *device,
+                             struct v3dv_descriptor *descriptor,
                              VkDescriptorType desc_type,
                              struct v3dv_descriptor_set *set,
                              const struct v3dv_descriptor_set_binding_layout *binding_layout,
@@ -978,7 +950,7 @@ write_buffer_view_descriptor(struct v3dv_descriptor *descriptor,
    descriptor->type = desc_type;
    descriptor->buffer_view = bview;
 
-   void *desc_map = descriptor_bo_map(set, binding_layout, array_index);
+   void *desc_map = descriptor_bo_map(device, set, binding_layout, array_index);
 
    memcpy(desc_map,
           bview->texture_shader_state,
@@ -992,6 +964,7 @@ v3dv_UpdateDescriptorSets(VkDevice  _device,
                           uint32_t descriptorCopyCount,
                           const VkCopyDescriptorSet *pDescriptorCopies)
 {
+   V3DV_FROM_HANDLE(v3dv_device, device, _device);
    for (uint32_t i = 0; i < descriptorWriteCount; i++) {
       const VkWriteDescriptorSet *writeset = &pDescriptorWrites[i];
       V3DV_FROM_HANDLE(v3dv_descriptor_set, set, writeset->dstSet);
@@ -1023,7 +996,7 @@ v3dv_UpdateDescriptorSets(VkDevice  _device,
              */
             const VkDescriptorImageInfo *image_info = writeset->pImageInfo + j;
             V3DV_FROM_HANDLE(v3dv_sampler, sampler, image_info->sampler);
-            write_image_descriptor(descriptor, writeset->descriptorType,
+            write_image_descriptor(device, descriptor, writeset->descriptorType,
                                    set, binding_layout, NULL, sampler,
                                    writeset->dstArrayElement + j);
 
@@ -1034,7 +1007,7 @@ v3dv_UpdateDescriptorSets(VkDevice  _device,
          case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: {
             const VkDescriptorImageInfo *image_info = writeset->pImageInfo + j;
             V3DV_FROM_HANDLE(v3dv_image_view, iview, image_info->imageView);
-            write_image_descriptor(descriptor, writeset->descriptorType,
+            write_image_descriptor(device, descriptor, writeset->descriptorType,
                                    set, binding_layout, iview, NULL,
                                    writeset->dstArrayElement + j);
 
@@ -1044,7 +1017,7 @@ v3dv_UpdateDescriptorSets(VkDevice  _device,
             const VkDescriptorImageInfo *image_info = writeset->pImageInfo + j;
             V3DV_FROM_HANDLE(v3dv_image_view, iview, image_info->imageView);
             V3DV_FROM_HANDLE(v3dv_sampler, sampler, image_info->sampler);
-            write_image_descriptor(descriptor, writeset->descriptorType,
+            write_image_descriptor(device, descriptor, writeset->descriptorType,
                                    set, binding_layout, iview, sampler,
                                    writeset->dstArrayElement + j);
 
@@ -1054,7 +1027,7 @@ v3dv_UpdateDescriptorSets(VkDevice  _device,
          case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: {
             V3DV_FROM_HANDLE(v3dv_buffer_view, buffer_view,
                              writeset->pTexelBufferView[j]);
-            write_buffer_view_descriptor(descriptor, writeset->descriptorType,
+            write_buffer_view_descriptor(device, descriptor, writeset->descriptorType,
                                          set, binding_layout, buffer_view,
                                          writeset->dstArrayElement + j);
             break;
@@ -1095,8 +1068,9 @@ v3dv_UpdateDescriptorSets(VkDevice  _device,
          dst_descriptor++;
          src_descriptor++;
 
-         if (descriptor_bo_size(src_binding_layout->type) > 0) {
-            descriptor_bo_copy(dst_set, dst_binding_layout,
+         if (v3dv_X(device, descriptor_bo_size)(src_binding_layout->type) > 0) {
+            descriptor_bo_copy(device,
+                               dst_set, dst_binding_layout,
                                j + copyset->dstArrayElement,
                                src_set, src_binding_layout,
                                j + copyset->srcArrayElement);
@@ -1108,10 +1082,11 @@ v3dv_UpdateDescriptorSets(VkDevice  _device,
 
 VKAPI_ATTR void VKAPI_CALL
 v3dv_GetDescriptorSetLayoutSupport(
-   VkDevice device,
+   VkDevice _device,
    const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
    VkDescriptorSetLayoutSupport *pSupport)
 {
+   V3DV_FROM_HANDLE(v3dv_device, device, _device);
    VkDescriptorSetLayoutBinding *bindings = NULL;
    VkResult result = vk_create_sorted_bindings(
       pCreateInfo->pBindings, pCreateInfo->bindingCount, &bindings);
@@ -1133,7 +1108,7 @@ v3dv_GetDescriptorSetLayoutSupport(
          break;
       }
 
-      uint32_t desc_bo_size = descriptor_bo_size(binding->descriptorType);
+      uint32_t desc_bo_size = v3dv_X(device, descriptor_bo_size)(binding->descriptorType);
       if (desc_bo_size > 0 &&
           (UINT32_MAX - bo_size) / desc_bo_size < binding->descriptorCount) {
          supported = false;
@@ -1216,6 +1191,7 @@ v3dv_UpdateDescriptorSetWithTemplate(
    VkDescriptorUpdateTemplate descriptorUpdateTemplate,
    const void *pData)
 {
+   V3DV_FROM_HANDLE(v3dv_device, device, _device);
    V3DV_FROM_HANDLE(v3dv_descriptor_set, set, descriptorSet);
    V3DV_FROM_HANDLE(v3dv_descriptor_update_template, template,
                     descriptorUpdateTemplate);
@@ -1254,7 +1230,7 @@ v3dv_UpdateDescriptorSetWithTemplate(
                pData + entry->offset + j * entry->stride;
             V3DV_FROM_HANDLE(v3dv_image_view, iview, info->imageView);
             V3DV_FROM_HANDLE(v3dv_sampler, sampler, info->sampler);
-            write_image_descriptor(descriptor + j, entry->type,
+            write_image_descriptor(device, descriptor + j, entry->type,
                                    set, binding_layout, iview, sampler,
                                    entry->array_element + j);
          }
@@ -1266,7 +1242,7 @@ v3dv_UpdateDescriptorSetWithTemplate(
             const VkBufferView *_bview =
                pData + entry->offset + j * entry->stride;
             V3DV_FROM_HANDLE(v3dv_buffer_view, bview, *_bview);
-            write_buffer_view_descriptor(descriptor + j, entry->type,
+            write_buffer_view_descriptor(device, descriptor + j, entry->type,
                                          set, binding_layout, bview,
                                          entry->array_element + j);
          }
diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c
index d6f95fa381d..f7496e1af6e 100644
--- a/src/broadcom/vulkan/v3dv_device.c
+++ b/src/broadcom/vulkan/v3dv_device.c
@@ -1368,7 +1368,7 @@ v3dv_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
             (UINT32_MAX - sizeof(struct v3dv_descriptor_set)) /
             sizeof(struct v3dv_descriptor);
          uint32_t max_gpu_descriptors =
-            (UINT32_MAX / v3dv_max_descriptor_bo_size());
+            (UINT32_MAX / v3dv_X(pdevice, max_descriptor_bo_size)());
          props->maxPerSetDescriptors =
             MIN2(max_host_descriptors, max_gpu_descriptors);
 
diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h
index 1a9e249a7fa..12c63584c8b 100644
--- a/src/broadcom/vulkan/v3dv_private.h
+++ b/src/broadcom/vulkan/v3dv_private.h
@@ -1173,33 +1173,6 @@ struct v3dv_descriptor {
    };
 };
 
-/* The following v3dv_xxx_descriptor structs represent descriptor info that we
- * upload to a bo, specifically a subregion of the descriptor pool bo.
- *
- * The general rule that we apply right now to decide which info goes to such
- * bo is that we upload those that are referenced by an address when emitting
- * a packet, so needed to be uploaded to an bo in any case.
- *
- * Note that these structs are mostly helpers that improve the semantics when
- * doing all that, but we could do as other mesa vulkan drivers and just
- * upload the info we know it is expected based on the context.
- *
- * Also note that the sizes are aligned, as there is an alignment requirement
- * for addresses.
- */
-struct v3dv_sampled_image_descriptor {
-   uint8_t texture_state[cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32)];
-};
-
-struct v3dv_sampler_descriptor {
-   uint8_t sampler_state[cl_aligned_packet_length(SAMPLER_STATE, 32)];
-};
-
-struct v3dv_combined_image_sampler_descriptor {
-   uint8_t texture_state[cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32)];
-   uint8_t sampler_state[cl_aligned_packet_length(SAMPLER_STATE, 32)];
-};
-
 struct v3dv_query {
    bool maybe_available;
    union {
@@ -1502,8 +1475,6 @@ struct v3dv_descriptor_set {
    struct v3dv_descriptor descriptors[0];
 };
 
-uint32_t v3dv_max_descriptor_bo_size(void);
-
 struct v3dv_descriptor_set_binding_layout {
    VkDescriptorType type;
 
@@ -1931,13 +1902,15 @@ v3dv_descriptor_map_get_sampler(struct v3dv_descriptor_state *descriptor_state,
                                 uint32_t index);
 
 struct v3dv_cl_reloc
-v3dv_descriptor_map_get_sampler_state(struct v3dv_descriptor_state *descriptor_state,
+v3dv_descriptor_map_get_sampler_state(struct v3dv_device *device,
+                                      struct v3dv_descriptor_state *descriptor_state,
                                       struct v3dv_descriptor_map *map,
                                       struct v3dv_pipeline_layout *pipeline_layout,
                                       uint32_t index);
 
 struct v3dv_cl_reloc
-v3dv_descriptor_map_get_texture_shader_state(struct v3dv_descriptor_state *descriptor_state,
+v3dv_descriptor_map_get_texture_shader_state(struct v3dv_device *device,
+                                             struct v3dv_descriptor_state *descriptor_state,
                                              struct v3dv_descriptor_map *map,
                                              struct v3dv_pipeline_layout *pipeline_layout,
                                              uint32_t index);
diff --git a/src/broadcom/vulkan/v3dv_uniforms.c b/src/broadcom/vulkan/v3dv_uniforms.c
index 8816c93969d..43155da4797 100644
--- a/src/broadcom/vulkan/v3dv_uniforms.c
+++ b/src/broadcom/vulkan/v3dv_uniforms.c
@@ -146,7 +146,7 @@ write_tmu_p0(struct v3dv_cmd_buffer *cmd_buffer,
    tex_bos->tex[texture_idx] = texture_bo;
 
    struct v3dv_cl_reloc state_reloc =
-      v3dv_descriptor_map_get_texture_shader_state(descriptor_state,
+      v3dv_descriptor_map_get_texture_shader_state(cmd_buffer->device, descriptor_state,
                                                    &pipeline->shared_data->maps[stage]->texture_map,
                                                    pipeline->layout,
                                                    texture_idx);
@@ -182,7 +182,7 @@ write_tmu_p1(struct v3dv_cmd_buffer *cmd_buffer,
           sampler_idx != V3DV_NO_SAMPLER_32BIT_IDX);
 
    struct v3dv_cl_reloc sampler_state_reloc =
-      v3dv_descriptor_map_get_sampler_state(descriptor_state,
+      v3dv_descriptor_map_get_sampler_state(cmd_buffer->device, descriptor_state,
                                             &pipeline->shared_data->maps[stage]->sampler_map,
                                             pipeline->layout, sampler_idx);
 
diff --git a/src/broadcom/vulkan/v3dvx_descriptor_set.c b/src/broadcom/vulkan/v3dvx_descriptor_set.c
new file mode 100644
index 00000000000..2c28ce46aa5
--- /dev/null
+++ b/src/broadcom/vulkan/v3dvx_descriptor_set.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2021 Raspberry Pi
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "v3dv_private.h"
+#include "broadcom/common/v3d_macros.h"
+#include "broadcom/cle/v3dx_pack.h"
+#include "broadcom/compiler/v3d_compiler.h"
+
+/*
+ * Returns how much space a given descriptor type needs on a bo (GPU
+ * memory).
+ */
+uint32_t
+v3dX(descriptor_bo_size)(VkDescriptorType type)
+{
+   switch(type) {
+   case VK_DESCRIPTOR_TYPE_SAMPLER:
+      return cl_aligned_packet_length(SAMPLER_STATE, 32);
+   case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
+      return cl_aligned_packet_length(SAMPLER_STATE, 32) +
+         cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
+   case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
+   case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
+   case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
+   case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
+   case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
+      return cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
+   default:
+      return 0;
+   }
+}
+
+/* To compute the max_bo_size we want to iterate through the descriptor
+ * types. Unfourtunately we can't just use the descriptor type enum values, as
+ * the values are not defined consecutively (so extensions could add new
+ * descriptor types), and VK_DESCRIPTOR_TYPE_MAX_ENUM is also a really big
+ * number.
+ */
+static const uint32_t supported_descriptor_types[] = {
+   VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+   VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+   VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
+   VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC,
+   VK_DESCRIPTOR_TYPE_SAMPLER,
+   VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
+   VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+   VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
+   VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
+   VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
+   VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
+};
+
+uint32_t
+v3dX(max_descriptor_bo_size)(void)
+{
+   static uint32_t max = 0;
+
+   if (max == 0) {
+      for (uint32_t i = 0; i < ARRAY_SIZE(supported_descriptor_types); i++)
+         max = MAX2(max, v3dX(descriptor_bo_size)(supported_descriptor_types[i]));
+   }
+   assert(max != 0);
+
+   return max;
+}
+
+
+uint32_t
+v3dX(combined_image_sampler_texture_state_offset)(void)
+{
+   return 0;
+}
+
+uint32_t
+v3dX(combined_image_sampler_sampler_state_offset)(void)
+{
+   return cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
+}
diff --git a/src/broadcom/vulkan/v3dvx_private.h b/src/broadcom/vulkan/v3dvx_private.h
index e689b4d5eb8..438ec1f69dd 100644
--- a/src/broadcom/vulkan/v3dvx_private.h
+++ b/src/broadcom/vulkan/v3dvx_private.h
@@ -301,3 +301,12 @@ v3dX(pipeline_pack_compile_state)(struct v3dv_pipeline *pipeline,
 /* Used at v3dv_queue */
 void
 v3dX(job_emit_noop)(struct v3dv_job *job);
+
+/* Used at v3dv_descriptor_set, and other descriptor set utils */
+uint32_t v3dX(descriptor_bo_size)(VkDescriptorType type);
+
+uint32_t v3dX(max_descriptor_bo_size)(void);
+
+uint32_t v3dX(combined_image_sampler_texture_state_offset)(void);
+
+uint32_t v3dX(combined_image_sampler_sampler_state_offset)(void);



More information about the mesa-commit mailing list