anv/meta: Allocate descriptor pools on-the-fly
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 24 Feb 2016 01:04:19 +0000 (17:04 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 24 Feb 2016 01:04:19 +0000 (17:04 -0800)
We can't use a global descriptor pool like we were because it's not
thread-safe.  For now, we'll allocate them on-the-fly and that should work
fine.  At some point in the future, we could do something where we
stack-allocate them or allocate them out of one of the state streams.

src/intel/vulkan/anv_meta.c
src/intel/vulkan/anv_meta_blit.c
src/intel/vulkan/anv_meta_resolve.c
src/intel/vulkan/anv_private.h

index 683a1623cc3d3d5ebe2f3c4f70fd9a6884b18bca..82944ea1a92012360d488d6476289c916663a80c 100644 (file)
@@ -138,27 +138,6 @@ anv_device_init_meta(struct anv_device *device)
       .pfnFree = meta_free,
    };
 
-   const VkDescriptorPoolCreateInfo create_info = {
-      .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
-      .pNext = NULL,
-      .flags = 0,
-      .maxSets = 1,
-      .poolSizeCount = 1,
-      .pPoolSizes = (VkDescriptorPoolSize[]) {
-         {
-            .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
-            .descriptorCount = 1
-         },
-      }
-   };
-
-   result = anv_CreateDescriptorPool(anv_device_to_handle(device),
-                                     &create_info,
-                                     &device->meta_state.alloc,
-                                     &device->meta_state.desc_pool);
-   if (result != VK_SUCCESS)
-      goto fail_desc_pool;
-
    result = anv_device_init_meta_clear_state(device);
    if (result != VK_SUCCESS)
       goto fail_clear;
@@ -178,10 +157,6 @@ fail_blit:
 fail_resolve:
    anv_device_finish_meta_clear_state(device);
 fail_clear:
-   anv_DestroyDescriptorPool(anv_device_to_handle(device),
-                             device->meta_state.desc_pool,
-                             &device->meta_state.alloc);
-fail_desc_pool:
    return result;
 }
 
index 9c6cd8c510e8b9a443fa55704b91b0cd5284c3c4..8ef943aa5122561e42ec518ed027f828e6779cff 100644 (file)
@@ -243,14 +243,31 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
          .minFilter = blit_filter,
       }, &cmd_buffer->pool->alloc, &sampler);
 
+   VkDescriptorPool desc_pool;
+   anv_CreateDescriptorPool(anv_device_to_handle(device),
+      &(const VkDescriptorPoolCreateInfo) {
+         .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
+         .pNext = NULL,
+         .flags = 0,
+         .maxSets = 1,
+         .poolSizeCount = 1,
+         .pPoolSizes = (VkDescriptorPoolSize[]) {
+            {
+               .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+               .descriptorCount = 1
+            },
+         }
+      }, &cmd_buffer->pool->alloc, &desc_pool);
+
    VkDescriptorSet set;
    anv_AllocateDescriptorSets(anv_device_to_handle(device),
       &(VkDescriptorSetAllocateInfo) {
          .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
-         .descriptorPool = device->meta_state.desc_pool,
+         .descriptorPool = desc_pool,
          .descriptorSetCount = 1,
          .pSetLayouts = &device->meta_state.blit.ds_layout
       }, &set);
+
    anv_UpdateDescriptorSets(anv_device_to_handle(device),
       1, /* writeCount */
       (VkWriteDescriptorSet[]) {
@@ -340,8 +357,8 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
    /* At the point where we emit the draw call, all data from the
     * descriptor sets, etc. has been used.  We are free to delete it.
     */
-   anv_ResetDescriptorPool(anv_device_to_handle(device),
-                           device->meta_state.desc_pool, 0);
+   anv_DestroyDescriptorPool(anv_device_to_handle(device),
+                             desc_pool, &cmd_buffer->pool->alloc);
    anv_DestroySampler(anv_device_to_handle(device), sampler,
                       &cmd_buffer->pool->alloc);
    anv_DestroyFramebuffer(anv_device_to_handle(device), fb,
index 9a77d21452f4f73e528b734b15638bf74f8d2210..8eb2548b5aecc8720dd7bd339dd7f64edb915700 100644 (file)
@@ -559,11 +559,27 @@ emit_resolve(struct anv_cmd_buffer *cmd_buffer,
       &cmd_buffer->pool->alloc,
       &sampler_h);
 
+   VkDescriptorPool desc_pool;
+   anv_CreateDescriptorPool(anv_device_to_handle(device),
+      &(const VkDescriptorPoolCreateInfo) {
+         .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
+         .pNext = NULL,
+         .flags = 0,
+         .maxSets = 1,
+         .poolSizeCount = 1,
+         .pPoolSizes = (VkDescriptorPoolSize[]) {
+            {
+               .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+               .descriptorCount = 1
+            },
+         }
+      }, &cmd_buffer->pool->alloc, &desc_pool);
+
    VkDescriptorSet desc_set_h;
    anv_AllocateDescriptorSets(device_h,
       &(VkDescriptorSetAllocateInfo) {
          .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
-         .descriptorPool = device->meta_state.desc_pool,
+         .descriptorPool = desc_pool,
          .descriptorSetCount = 1,
          .pSetLayouts = (VkDescriptorSetLayout[]) {
             device->meta_state.resolve.ds_layout,
@@ -641,8 +657,8 @@ emit_resolve(struct anv_cmd_buffer *cmd_buffer,
    /* All objects below are consumed by the draw call. We may safely destroy
     * them.
     */
-   anv_ResetDescriptorPool(anv_device_to_handle(device),
-                           device->meta_state.desc_pool, 0);
+   anv_DestroyDescriptorPool(anv_device_to_handle(device),
+                             desc_pool, &cmd_buffer->pool->alloc);
    anv_DestroySampler(device_h, sampler_h,
                       &cmd_buffer->pool->alloc);
 }
index 6ce3f02d1f7ed6c51a6121e1dc934cf5def1ee8c..b1b4d265b89a49e6ec903c27c4bf59e9e7dca9a5 100644 (file)
@@ -571,8 +571,6 @@ void anv_finish_wsi(struct anv_instance *instance);
 struct anv_meta_state {
    VkAllocationCallbacks alloc;
 
-   VkDescriptorPool desc_pool;
-
    /**
     * Use array element `i` for images with `2^i` samples.
     */