Module: Mesa
Branch: master
Commit: c120edd8e861985496e1054a84844641c10de643
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c120edd8e861985496e1054a84844641c10de643

Author: Jason Ekstrand <[email protected]>
Date:   Wed Mar 10 20:20:37 2021 -0600

vulkan/alloc: Add VK_MULTIALLOC_DECL macros

These both declare the variable and add it to the allocator in one go.

Reviewed-by: Jesse Natalie <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9511>

---

 src/intel/vulkan/anv_descriptor_set.c | 12 +++++------
 src/intel/vulkan/anv_pass.c           | 20 +++++++++---------
 src/intel/vulkan/anv_pipeline_cache.c | 38 ++++++++++++++++-------------------
 src/intel/vulkan/anv_queue.c          |  3 +--
 src/intel/vulkan/anv_wsi.c            | 10 ++++-----
 src/intel/vulkan/genX_query.c         |  3 +--
 src/vulkan/util/vk_alloc.h            |  7 +++++++
 src/vulkan/util/vk_render_pass.c      | 20 +++++++++---------
 8 files changed, 53 insertions(+), 60 deletions(-)

diff --git a/src/intel/vulkan/anv_descriptor_set.c 
b/src/intel/vulkan/anv_descriptor_set.c
index bcb70ea17f1..3b5412ca01e 100644
--- a/src/intel/vulkan/anv_descriptor_set.c
+++ b/src/intel/vulkan/anv_descriptor_set.c
@@ -372,18 +372,16 @@ VkResult anv_CreateDescriptorSetLayout(
          immutable_sampler_count += pCreateInfo->pBindings[j].descriptorCount;
    }
 
-   struct anv_descriptor_set_layout *set_layout;
-   struct anv_descriptor_set_binding_layout *bindings;
-   struct anv_sampler **samplers;
-
    /* We need to allocate decriptor set layouts off the device allocator
     * with DEVICE scope because they are reference counted and may not be
     * destroyed when vkDestroyDescriptorSetLayout is called.
     */
    VK_MULTIALLOC(ma);
-   vk_multialloc_add(&ma, &set_layout, 1);
-   vk_multialloc_add(&ma, &bindings, max_binding + 1);
-   vk_multialloc_add(&ma, &samplers, immutable_sampler_count);
+   VK_MULTIALLOC_DECL(&ma, struct anv_descriptor_set_layout, set_layout, 1);
+   VK_MULTIALLOC_DECL(&ma, struct anv_descriptor_set_binding_layout,
+                           bindings, max_binding + 1);
+   VK_MULTIALLOC_DECL(&ma, struct anv_sampler *, samplers,
+                           immutable_sampler_count);
 
    if (!vk_multialloc_alloc(&ma, &device->vk.alloc,
                             VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c
index 61efab48e9a..a4158b81d5d 100644
--- a/src/intel/vulkan/anv_pass.c
+++ b/src/intel/vulkan/anv_pass.c
@@ -311,24 +311,22 @@ VkResult anv_CreateRenderPass2(
 
    assert(pCreateInfo->sType == 
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR);
 
-   struct anv_render_pass *pass;
-   struct anv_subpass *subpasses;
-   struct anv_render_pass_attachment *attachments;
-   enum anv_pipe_bits *subpass_flushes;
-
    VK_MULTIALLOC(ma);
-   vk_multialloc_add(&ma, &pass, 1);
-   vk_multialloc_add(&ma, &subpasses, pCreateInfo->subpassCount);
-   vk_multialloc_add(&ma, &attachments, pCreateInfo->attachmentCount);
-   vk_multialloc_add(&ma, &subpass_flushes, pCreateInfo->subpassCount + 1);
+   VK_MULTIALLOC_DECL(&ma, struct anv_render_pass, pass, 1);
+   VK_MULTIALLOC_DECL(&ma, struct anv_subpass, subpasses,
+                           pCreateInfo->subpassCount);
+   VK_MULTIALLOC_DECL(&ma, struct anv_render_pass_attachment, attachments,
+                           pCreateInfo->attachmentCount);
+   VK_MULTIALLOC_DECL(&ma, enum anv_pipe_bits, subpass_flushes,
+                           pCreateInfo->subpassCount + 1);
 
-   struct anv_subpass_attachment *subpass_attachments;
    uint32_t subpass_attachment_count = 0;
    for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
       subpass_attachment_count +=
          num_subpass_attachments2(&pCreateInfo->pSubpasses[i]);
    }
-   vk_multialloc_add(&ma, &subpass_attachments, subpass_attachment_count);
+   VK_MULTIALLOC_DECL(&ma, struct anv_subpass_attachment, subpass_attachments,
+                      subpass_attachment_count);
 
    if (!vk_multialloc_alloc2(&ma, &device->vk.alloc, pAllocator,
                              VK_SYSTEM_ALLOCATION_SCOPE_OBJECT))
diff --git a/src/intel/vulkan/anv_pipeline_cache.c 
b/src/intel/vulkan/anv_pipeline_cache.c
index c4a04ae03fd..dc4d12379a3 100644
--- a/src/intel/vulkan/anv_pipeline_cache.c
+++ b/src/intel/vulkan/anv_pipeline_cache.c
@@ -42,28 +42,24 @@ anv_shader_bin_create(struct anv_device *device,
                       const nir_xfb_info *xfb_info_in,
                       const struct anv_pipeline_bind_map *bind_map)
 {
-   struct anv_shader_bin *shader;
-   struct anv_shader_bin_key *key;
-   struct brw_stage_prog_data *prog_data;
-   struct brw_shader_reloc *prog_data_relocs;
-   uint32_t *prog_data_param;
-   nir_xfb_info *xfb_info;
-   struct anv_pipeline_binding *surface_to_descriptor, *sampler_to_descriptor;
-
    VK_MULTIALLOC(ma);
-   vk_multialloc_add(&ma, &shader, 1);
-   vk_multialloc_add_size(&ma, &key, sizeof(*key) + key_size);
-   vk_multialloc_add_size(&ma, &prog_data, prog_data_size);
-   vk_multialloc_add(&ma, &prog_data_relocs, prog_data_in->num_relocs);
-   vk_multialloc_add(&ma, &prog_data_param, prog_data_in->nr_params);
-   if (xfb_info_in) {
-      uint32_t xfb_info_size = nir_xfb_info_size(xfb_info_in->output_count);
-      vk_multialloc_add_size(&ma, &xfb_info, xfb_info_size);
-   }
-   vk_multialloc_add(&ma, &surface_to_descriptor,
-                          bind_map->surface_count);
-   vk_multialloc_add(&ma, &sampler_to_descriptor,
-                          bind_map->sampler_count);
+   VK_MULTIALLOC_DECL(&ma, struct anv_shader_bin, shader, 1);
+   VK_MULTIALLOC_DECL_SIZE(&ma, struct anv_shader_bin_key, key,
+                                sizeof(*key) + key_size);
+   VK_MULTIALLOC_DECL_SIZE(&ma, struct brw_stage_prog_data, prog_data,
+                                prog_data_size);
+   VK_MULTIALLOC_DECL(&ma, struct brw_shader_reloc, prog_data_relocs,
+                           prog_data_in->num_relocs);
+   VK_MULTIALLOC_DECL(&ma, uint32_t, prog_data_param, prog_data_in->nr_params);
+
+   VK_MULTIALLOC_DECL_SIZE(&ma, nir_xfb_info, xfb_info,
+                                xfb_info_in == NULL ? 0 :
+                                nir_xfb_info_size(xfb_info_in->output_count));
+
+   VK_MULTIALLOC_DECL(&ma, struct anv_pipeline_binding, surface_to_descriptor,
+                           bind_map->surface_count);
+   VK_MULTIALLOC_DECL(&ma, struct anv_pipeline_binding, sampler_to_descriptor,
+                           bind_map->sampler_count);
 
    if (!vk_multialloc_alloc(&ma, &device->vk.alloc,
                             VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c
index 6df5b904434..87afebfcfcd 100644
--- a/src/intel/vulkan/anv_queue.c
+++ b/src/intel/vulkan/anv_queue.c
@@ -2787,11 +2787,10 @@ VkResult anv_WaitSemaphores(
    ANV_FROM_HANDLE(anv_device, device, _device);
    uint32_t *handles;
    struct anv_timeline **timelines;
-   uint64_t *values;
 
    VK_MULTIALLOC(ma);
 
-   vk_multialloc_add(&ma, &values, pWaitInfo->semaphoreCount);
+   VK_MULTIALLOC_DECL(&ma, uint64_t, values, pWaitInfo->semaphoreCount);
    if (device->has_thread_submit) {
       vk_multialloc_add(&ma, &handles, pWaitInfo->semaphoreCount);
    } else {
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
index 9c12cdc6277..d452cf6cf61 100644
--- a/src/intel/vulkan/anv_wsi.c
+++ b/src/intel/vulkan/anv_wsi.c
@@ -306,12 +306,10 @@ VkResult anv_QueuePresentKHR(
        * using a threaded submission.
        */
       VK_MULTIALLOC(ma);
-
-      uint64_t *values;
-      uint32_t *syncobjs;
-
-      vk_multialloc_add(&ma, &values, pPresentInfo->waitSemaphoreCount);
-      vk_multialloc_add(&ma, &syncobjs, pPresentInfo->waitSemaphoreCount);
+      VK_MULTIALLOC_DECL(&ma, uint64_t, values,
+                              pPresentInfo->waitSemaphoreCount);
+      VK_MULTIALLOC_DECL(&ma, uint32_t, syncobjs,
+                              pPresentInfo->waitSemaphoreCount);
 
       if (!vk_multialloc_alloc(&ma, &device->vk.alloc,
                                VK_SYSTEM_ALLOCATION_SCOPE_COMMAND))
diff --git a/src/intel/vulkan/genX_query.c b/src/intel/vulkan/genX_query.c
index 32459f7b572..6520c39d568 100644
--- a/src/intel/vulkan/genX_query.c
+++ b/src/intel/vulkan/genX_query.c
@@ -72,7 +72,6 @@ VkResult genX(CreateQueryPool)(
    uint32_t n_passes = 0;
 #endif
    uint32_t data_offset = 0;
-   struct anv_query_pool *pool;
    VK_MULTIALLOC(ma);
    VkResult result;
 
@@ -90,7 +89,7 @@ VkResult genX(CreateQueryPool)(
     */
    uint32_t uint64s_per_slot = 0;
 
-   vk_multialloc_add(&ma, &pool, 1);
+   VK_MULTIALLOC_DECL(&ma, struct anv_query_pool, pool, 1);
 
    VkQueryPipelineStatisticFlags pipeline_statistics = 0;
    switch (pCreateInfo->queryType) {
diff --git a/src/vulkan/util/vk_alloc.h b/src/vulkan/util/vk_alloc.h
index 4a502de96e5..ef4067b4483 100644
--- a/src/vulkan/util/vk_alloc.h
+++ b/src/vulkan/util/vk_alloc.h
@@ -182,6 +182,13 @@ _vk_multialloc_add(struct vk_multialloc *ma,
 #define vk_multialloc_add(_ma, _ptr, _count) \
    vk_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
 
+#define VK_MULTIALLOC_DECL_SIZE(_ma, _type, _name, _size) \
+   _type *_name; \
+   vk_multialloc_add_size(_ma, &_name, _size);
+
+#define VK_MULTIALLOC_DECL(_ma, _type, _name, _count) \
+   VK_MULTIALLOC_DECL_SIZE(_ma, _type, _name, (_count) * sizeof(_type));
+
 static ALWAYS_INLINE void *
 vk_multialloc_alloc(struct vk_multialloc *ma,
                     const VkAllocationCallbacks *alloc,
diff --git a/src/vulkan/util/vk_render_pass.c b/src/vulkan/util/vk_render_pass.c
index 3d9b3e8764a..599228a413a 100644
--- a/src/vulkan/util/vk_render_pass.c
+++ b/src/vulkan/util/vk_render_pass.c
@@ -64,12 +64,6 @@ vk_common_CreateRenderPass(VkDevice _device,
 {
    VK_FROM_HANDLE(vk_device, device, _device);
 
-   VkRenderPassCreateInfo2 *create_info;
-   VkAttachmentDescription2 *attachments;
-   VkSubpassDescription2 *subpasses;
-   VkSubpassDependency2 *dependencies;
-   VkAttachmentReference2 *references;
-
    uint32_t reference_count = 0;
    for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
       reference_count += pCreateInfo->pSubpasses[i].inputAttachmentCount;
@@ -81,11 +75,15 @@ vk_common_CreateRenderPass(VkDevice _device,
    }
 
    VK_MULTIALLOC(ma);
-   vk_multialloc_add(&ma, &create_info, 1);
-   vk_multialloc_add(&ma, &subpasses, pCreateInfo->subpassCount);
-   vk_multialloc_add(&ma, &attachments, pCreateInfo->attachmentCount);
-   vk_multialloc_add(&ma, &dependencies, pCreateInfo->dependencyCount);
-   vk_multialloc_add(&ma, &references, reference_count);
+   VK_MULTIALLOC_DECL(&ma, VkRenderPassCreateInfo2, create_info, 1);
+   VK_MULTIALLOC_DECL(&ma, VkSubpassDescription2, subpasses,
+                           pCreateInfo->subpassCount);
+   VK_MULTIALLOC_DECL(&ma, VkAttachmentDescription2, attachments,
+                           pCreateInfo->attachmentCount);
+   VK_MULTIALLOC_DECL(&ma, VkSubpassDependency2, dependencies,
+                           pCreateInfo->dependencyCount);
+   VK_MULTIALLOC_DECL(&ma, VkAttachmentReference2, references,
+                           reference_count);
    if (!vk_multialloc_alloc2(&ma, &device->alloc, pAllocator,
                              VK_SYSTEM_ALLOCATION_SCOPE_COMMAND))
       return VK_ERROR_OUT_OF_HOST_MEMORY;

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to