vulkan,anv: Add a common base object type for VkDevice
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 21 Apr 2020 17:42:59 +0000 (12:42 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 4 May 2020 14:06:27 +0000 (14:06 +0000)
We should keep this very minimal; I don't know that we need to go all
struct gl_context on it.  However, this gives us at least a tiny base on
which we can start building some common functionality.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Acked-by: Kristian H. Kristensen <hoegsberg@google.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4690>

20 files changed:
src/intel/vulkan/anv_cmd_buffer.c
src/intel/vulkan/anv_descriptor_set.c
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_formats.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_intel.c
src/intel/vulkan/anv_pass.c
src/intel/vulkan/anv_pipeline.c
src/intel/vulkan/anv_pipeline_cache.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/anv_queue.c
src/intel/vulkan/anv_wsi.c
src/intel/vulkan/anv_wsi_display.c
src/intel/vulkan/genX_pipeline.c
src/intel/vulkan/genX_query.c
src/intel/vulkan/genX_state.c
src/vulkan/Makefile.sources
src/vulkan/util/meson.build
src/vulkan/util/vk_object.c [new file with mode: 0644]
src/vulkan/util/vk_object.h [new file with mode: 0644]

index f4921ba551e93bf7bb733f8cbead78166377c86d..03af604de4c9b3b8e06d58205e4e4f7a0355d0e4 100644 (file)
@@ -901,7 +901,7 @@ VkResult anv_CreateCommandPool(
    ANV_FROM_HANDLE(anv_device, device, _device);
    struct anv_cmd_pool *pool;
 
-   pool = vk_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8,
+   pool = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*pool), 8,
                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (pool == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -909,7 +909,7 @@ VkResult anv_CreateCommandPool(
    if (pAllocator)
       pool->alloc = *pAllocator;
    else
-      pool->alloc = device->alloc;
+      pool->alloc = device->vk.alloc;
 
    list_inithead(&pool->cmd_buffers);
 
@@ -934,7 +934,7 @@ void anv_DestroyCommandPool(
       anv_cmd_buffer_destroy(cmd_buffer);
    }
 
-   vk_free2(&device->alloc, pAllocator, pool);
+   vk_free2(&device->vk.alloc, pAllocator, pool);
 }
 
 VkResult anv_ResetCommandPool(
index 2e101fd1fdc8ef1235499c1f6e6a7f999d1fd9c5..ce6caafcf7a27297222ef845d97678efa8157f1d 100644 (file)
@@ -358,7 +358,7 @@ VkResult anv_CreateDescriptorSetLayout(
    anv_multialloc_add(&ma, &bindings, max_binding + 1);
    anv_multialloc_add(&ma, &samplers, immutable_sampler_count);
 
-   if (!anv_multialloc_alloc(&ma, &device->alloc,
+   if (!anv_multialloc_alloc(&ma, &device->vk.alloc,
                              VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -587,7 +587,7 @@ VkResult anv_CreatePipelineLayout(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO);
 
-   layout = vk_alloc2(&device->alloc, pAllocator, sizeof(*layout), 8,
+   layout = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*layout), 8,
                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (layout == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -641,7 +641,7 @@ void anv_DestroyPipelineLayout(
    for (uint32_t i = 0; i < pipeline_layout->num_sets; i++)
       anv_descriptor_set_layout_unref(device, pipeline_layout->set[i].layout);
 
-   vk_free2(&device->alloc, pAllocator, pipeline_layout);
+   vk_free2(&device->vk.alloc, pAllocator, pipeline_layout);
 }
 
 /*
@@ -731,7 +731,7 @@ VkResult anv_CreateDescriptorPool(
       buffer_view_count * sizeof(struct anv_buffer_view);
    const size_t total_size = sizeof(*pool) + pool_size;
 
-   pool = vk_alloc2(&device->alloc, pAllocator, total_size, 8,
+   pool = vk_alloc2(&device->vk.alloc, pAllocator, total_size, 8,
                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!pool)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -748,7 +748,7 @@ VkResult anv_CreateDescriptorPool(
                                             0 /* explicit_address */,
                                             &pool->bo);
       if (result != VK_SUCCESS) {
-         vk_free2(&device->alloc, pAllocator, pool);
+         vk_free2(&device->vk.alloc, pAllocator, pool);
          return result;
       }
 
@@ -788,7 +788,7 @@ void anv_DestroyDescriptorPool(
       anv_device_release_bo(device, pool->bo);
    anv_state_stream_finish(&pool->surface_state_stream);
 
-   vk_free2(&device->alloc, pAllocator, pool);
+   vk_free2(&device->vk.alloc, pAllocator, pool);
 }
 
 VkResult anv_ResetDescriptorPool(
@@ -1599,7 +1599,7 @@ VkResult anv_CreateDescriptorUpdateTemplate(
 
    size_t size = sizeof(*template) +
       pCreateInfo->descriptorUpdateEntryCount * sizeof(template->entries[0]);
-   template = vk_alloc2(&device->alloc, pAllocator, size, 8,
+   template = vk_alloc2(&device->vk.alloc, pAllocator, size, 8,
                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (template == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -1639,7 +1639,7 @@ void anv_DestroyDescriptorUpdateTemplate(
    ANV_FROM_HANDLE(anv_descriptor_update_template, template,
                    descriptorUpdateTemplate);
 
-   vk_free2(&device->alloc, pAllocator, template);
+   vk_free2(&device->vk.alloc, pAllocator, template);
 }
 
 void anv_UpdateDescriptorSetWithTemplate(
index b0a02b02a6d1b939216d7d5107c3ff1feb644ef6..012bb7d1976d22ce1807ef0e02b89da6ecd52b74 100644 (file)
@@ -2746,6 +2746,9 @@ VkResult anv_CreateDevice(
    if (!device)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
+   vk_device_init(&device->vk, pCreateInfo,
+                  &physical_device->instance->alloc, pAllocator);
+
    if (INTEL_DEBUG & DEBUG_BATCH) {
       const unsigned decode_flags =
          GEN_BATCH_DECODE_FULL |
@@ -2759,16 +2762,10 @@ VkResult anv_CreateDevice(
                                 decode_get_bo, NULL, device);
    }
 
-   device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
    device->physical = physical_device;
    device->no_hw = physical_device->no_hw;
    device->_lost = false;
 
-   if (pAllocator)
-      device->alloc = *pAllocator;
-   else
-      device->alloc = physical_device->instance->alloc;
-
    /* XXX(chadv): Can we dup() physicalDevice->fd here? */
    device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC);
    if (device->fd == -1) {
@@ -3010,7 +3007,7 @@ VkResult anv_CreateDevice(
  fail_fd:
    close(device->fd);
  fail_device:
-   vk_free(&device->alloc, device);
+   vk_free(&device->vk.alloc, device);
 
    return result;
 }
@@ -3076,7 +3073,8 @@ void anv_DestroyDevice(
 
    close(device->fd);
 
-   vk_free(&device->alloc, device);
+   vk_device_finish(&device->vk);
+   vk_free(&device->vk.alloc, device);
 }
 
 VkResult anv_EnumerateInstanceLayerProperties(
@@ -3356,7 +3354,7 @@ VkResult anv_AllocateMemory(
    if (mem_heap_used + aligned_alloc_size > mem_heap->size)
       return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
 
-   mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
+   mem = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*mem), 8,
                     VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (mem == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -3585,7 +3583,7 @@ VkResult anv_AllocateMemory(
    return VK_SUCCESS;
 
  fail:
-   vk_free2(&device->alloc, pAllocator, mem);
+   vk_free2(&device->vk.alloc, pAllocator, mem);
 
    return result;
 }
@@ -3685,7 +3683,7 @@ void anv_FreeMemory(
       AHardwareBuffer_release(mem->ahw);
 #endif
 
-   vk_free2(&device->alloc, pAllocator, mem);
+   vk_free2(&device->vk.alloc, pAllocator, mem);
 }
 
 VkResult anv_MapMemory(
@@ -4193,7 +4191,7 @@ VkResult anv_CreateBuffer(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
 
-   buffer = vk_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8,
+   buffer = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*buffer), 8,
                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (buffer == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -4218,7 +4216,7 @@ void anv_DestroyBuffer(
    if (!buffer)
       return;
 
-   vk_free2(&device->alloc, pAllocator, buffer);
+   vk_free2(&device->vk.alloc, pAllocator, buffer);
 }
 
 VkDeviceAddress anv_GetBufferDeviceAddress(
@@ -4283,7 +4281,7 @@ void anv_DestroySampler(
                           sampler->bindless_state);
    }
 
-   vk_free2(&device->alloc, pAllocator, sampler);
+   vk_free2(&device->vk.alloc, pAllocator, sampler);
 }
 
 VkResult anv_CreateFramebuffer(
@@ -4306,7 +4304,7 @@ VkResult anv_CreateFramebuffer(
     */
    if (!(pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR)) {
       size += sizeof(struct anv_image_view *) * pCreateInfo->attachmentCount;
-      framebuffer = vk_alloc2(&device->alloc, pAllocator, size, 8,
+      framebuffer = vk_alloc2(&device->vk.alloc, pAllocator, size, 8,
                               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
       if (framebuffer == NULL)
          return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -4317,7 +4315,7 @@ VkResult anv_CreateFramebuffer(
       }
       framebuffer->attachment_count = pCreateInfo->attachmentCount;
    } else {
-      framebuffer = vk_alloc2(&device->alloc, pAllocator, size, 8,
+      framebuffer = vk_alloc2(&device->vk.alloc, pAllocator, size, 8,
                               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
       if (framebuffer == NULL)
          return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -4345,7 +4343,7 @@ void anv_DestroyFramebuffer(
    if (!fb)
       return;
 
-   vk_free2(&device->alloc, pAllocator, fb);
+   vk_free2(&device->vk.alloc, pAllocator, fb);
 }
 
 static const VkTimeDomainEXT anv_time_domains[] = {
index b5962f13d6c94ca3fbffcbe1a014f99bbeaedae5..db1ea3f1818024c6d8d6b742ca6a96e0cda0df2a 100644 (file)
@@ -1286,7 +1286,7 @@ VkResult anv_CreateSamplerYcbcrConversion(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO);
 
-   conversion = vk_alloc2(&device->alloc, pAllocator, sizeof(*conversion), 8,
+   conversion = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*conversion), 8,
                           VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!conversion)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -1342,5 +1342,5 @@ void anv_DestroySamplerYcbcrConversion(
    if (!conversion)
       return;
 
-   vk_free2(&device->alloc, pAllocator, conversion);
+   vk_free2(&device->vk.alloc, pAllocator, conversion);
 }
index 19809884717c9b83000c7a750e3a64bb6b0eaea6..1f30ee128190de4fa47b2ac2103af68bf1673170 100644 (file)
@@ -690,7 +690,7 @@ anv_image_create(VkDevice _device,
    anv_assert(pCreateInfo->extent.height > 0);
    anv_assert(pCreateInfo->extent.depth > 0);
 
-   image = vk_zalloc2(&device->alloc, alloc, sizeof(*image), 8,
+   image = vk_zalloc2(&device->vk.alloc, alloc, sizeof(*image), 8,
                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!image)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -757,7 +757,7 @@ anv_image_create(VkDevice _device,
 
 fail:
    if (image)
-      vk_free2(&device->alloc, alloc, image);
+      vk_free2(&device->vk.alloc, alloc, image);
 
    return r;
 }
@@ -889,7 +889,7 @@ anv_DestroyImage(VkDevice _device, VkImage _image,
       }
    }
 
-   vk_free2(&device->alloc, pAllocator, image);
+   vk_free2(&device->vk.alloc, pAllocator, image);
 }
 
 static void anv_image_bind_memory_plane(struct anv_device *device,
@@ -1911,7 +1911,7 @@ anv_CreateImageView(VkDevice _device,
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
    struct anv_image_view *iview;
 
-   iview = vk_zalloc2(&device->alloc, pAllocator, sizeof(*iview), 8,
+   iview = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*iview), 8,
                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (iview == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -2169,7 +2169,7 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview,
       }
    }
 
-   vk_free2(&device->alloc, pAllocator, iview);
+   vk_free2(&device->vk.alloc, pAllocator, iview);
 }
 
 
@@ -2183,7 +2183,7 @@ anv_CreateBufferView(VkDevice _device,
    ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
    struct anv_buffer_view *view;
 
-   view = vk_alloc2(&device->alloc, pAllocator, sizeof(*view), 8,
+   view = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*view), 8,
                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!view)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -2267,5 +2267,5 @@ anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView,
       anv_state_pool_free(&device->surface_state_pool,
                           view->writeonly_storage_surface_state);
 
-   vk_free2(&device->alloc, pAllocator, view);
+   vk_free2(&device->vk.alloc, pAllocator, view);
 }
index 23489c011a1fb755afd5e320cf3bea33753674b0..9c7e77dc9f7645587eb88f522396d0cc29ebe7ec 100644 (file)
@@ -44,7 +44,7 @@ VkResult anv_CreateDmaBufImageINTEL(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL);
 
-   mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
+   mem = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*mem), 8,
                     VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (mem == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -107,10 +107,10 @@ VkResult anv_CreateDmaBufImageINTEL(
    return VK_SUCCESS;
 
  fail_import:
-   vk_free2(&device->alloc, pAllocator, image);
+   vk_free2(&device->vk.alloc, pAllocator, image);
 
  fail:
-   vk_free2(&device->alloc, pAllocator, mem);
+   vk_free2(&device->vk.alloc, pAllocator, mem);
 
    return result;
 }
index ec32e0ca3bd035118aaa3cde6c709f6ae27afd98..b100bec929d850c4d0fc9af475ef98801baf2678 100644 (file)
@@ -259,7 +259,7 @@ VkResult anv_CreateRenderPass(
    }
    anv_multialloc_add(&ma, &subpass_attachments, subpass_attachment_count);
 
-   if (!anv_multialloc_alloc2(&ma, &device->alloc, pAllocator,
+   if (!anv_multialloc_alloc2(&ma, &device->vk.alloc, pAllocator,
                               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT))
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -433,7 +433,7 @@ VkResult anv_CreateRenderPass2(
    }
    anv_multialloc_add(&ma, &subpass_attachments, subpass_attachment_count);
 
-   if (!anv_multialloc_alloc2(&ma, &device->alloc, pAllocator,
+   if (!anv_multialloc_alloc2(&ma, &device->vk.alloc, pAllocator,
                               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT))
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -591,7 +591,7 @@ void anv_DestroyRenderPass(
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_render_pass, pass, _pass);
 
-   vk_free2(&device->alloc, pAllocator, pass);
+   vk_free2(&device->vk.alloc, pAllocator, pass);
 }
 
 void anv_GetRenderAreaGranularity(
index 0767aaf6cf26ba19986f16e7b4a6f5677ad3a181..d3bbd06e06142ed80f2061a7920fcd68bc31f501 100644 (file)
@@ -55,7 +55,7 @@ VkResult anv_CreateShaderModule(
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
    assert(pCreateInfo->flags == 0);
 
-   module = vk_alloc2(&device->alloc, pAllocator,
+   module = vk_alloc2(&device->vk.alloc, pAllocator,
                        sizeof(*module) + pCreateInfo->codeSize, 8,
                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (module == NULL)
@@ -82,7 +82,7 @@ void anv_DestroyShaderModule(
    if (!module)
       return;
 
-   vk_free2(&device->alloc, pAllocator, module);
+   vk_free2(&device->vk.alloc, pAllocator, module);
 }
 
 #define SPIR_V_MAGIC_NUMBER 0x07230203
@@ -307,7 +307,7 @@ void anv_DestroyPipeline(
       return;
 
    anv_reloc_list_finish(&pipeline->batch_relocs,
-                         pAllocator ? pAllocator : &device->alloc);
+                         pAllocator ? pAllocator : &device->vk.alloc);
 
    ralloc_free(pipeline->mem_ctx);
 
@@ -340,7 +340,7 @@ void anv_DestroyPipeline(
       unreachable("invalid pipeline type");
    }
 
-   vk_free2(&device->alloc, pAllocator, pipeline);
+   vk_free2(&device->vk.alloc, pAllocator, pipeline);
 }
 
 static const uint32_t vk_to_gen_primitive_type[] = {
@@ -1979,7 +1979,7 @@ anv_pipeline_init(struct anv_graphics_pipeline *pipeline,
    anv_pipeline_validate_create_info(pCreateInfo);
 
    if (alloc == NULL)
-      alloc = &device->alloc;
+      alloc = &device->vk.alloc;
 
    pipeline->base.device = device;
    pipeline->base.type = ANV_PIPELINE_GRAPHICS;
index 69865951e1cfd4ece0e131e5fa0c230490f9e886..39df5f1ded5add7fc0a822f8280ebab8bfecc81d 100644 (file)
@@ -63,7 +63,7 @@ anv_shader_bin_create(struct anv_device *device,
    anv_multialloc_add(&ma, &sampler_to_descriptor,
                            bind_map->sampler_count);
 
-   if (!anv_multialloc_alloc(&ma, &device->alloc,
+   if (!anv_multialloc_alloc(&ma, &device->vk.alloc,
                              VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
       return NULL;
 
@@ -128,7 +128,7 @@ anv_shader_bin_destroy(struct anv_device *device,
    assert(shader->ref_cnt == 0);
    anv_state_pool_free(&device->instruction_state_pool, shader->kernel);
    anv_state_pool_free(&device->dynamic_state_pool, shader->constant_data);
-   vk_free(&device->alloc, shader);
+   vk_free(&device->vk.alloc, shader);
 }
 
 static bool
@@ -514,7 +514,7 @@ VkResult anv_CreatePipelineCache(
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO);
    assert(pCreateInfo->flags == 0);
 
-   cache = vk_alloc2(&device->alloc, pAllocator,
+   cache = vk_alloc2(&device->vk.alloc, pAllocator,
                        sizeof(*cache), 8,
                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (cache == NULL)
@@ -546,7 +546,7 @@ void anv_DestroyPipelineCache(
 
    anv_pipeline_cache_finish(cache);
 
-   vk_free2(&device->alloc, pAllocator, cache);
+   vk_free2(&device->vk.alloc, pAllocator, cache);
 }
 
 VkResult anv_GetPipelineCacheData(
index ed851f5aacf3d6e18e83ca379fcab55707d21a92..e39b328cca3c3292a615cb606c011b3f09a75594 100644 (file)
@@ -62,6 +62,7 @@
 #include "util/xmlconfig.h"
 #include "vk_alloc.h"
 #include "vk_debug_report.h"
+#include "vk_object.h"
 
 /* Pre-declarations needed for WSI entrypoints */
 struct wl_surface;
@@ -1260,9 +1261,7 @@ anv_device_upload_nir(struct anv_device *device,
                       unsigned char sha1_key[20]);
 
 struct anv_device {
-    VK_LOADER_DATA                              _loader_data;
-
-    VkAllocationCallbacks                       alloc;
+    struct vk_device                            vk;
 
     struct anv_physical_device *                physical;
     bool                                        no_hw;
@@ -1922,7 +1921,7 @@ anv_descriptor_set_layout_unref(struct anv_device *device,
 {
    assert(layout && layout->ref_cnt >= 1);
    if (p_atomic_dec_zero(&layout->ref_cnt))
-      vk_free(&device->alloc, layout);
+      vk_free(&device->vk.alloc, layout);
 }
 
 struct anv_descriptor {
index b9e19617d8a5febfcd7af13ee61d038c171a067c..c2229e9fd0a2d294a79a10435bca0afd13694072 100644 (file)
@@ -139,13 +139,13 @@ anv_timeline_finish(struct anv_device *device,
                             &timeline->free_points, link) {
       list_del(&point->link);
       anv_device_release_bo(device, point->bo);
-      vk_free(&device->alloc, point);
+      vk_free(&device->vk.alloc, point);
    }
    list_for_each_entry_safe(struct anv_timeline_point, point,
                             &timeline->points, link) {
       list_del(&point->link);
       anv_device_release_bo(device, point->bo);
-      vk_free(&device->alloc, point);
+      vk_free(&device->vk.alloc, point);
    }
 }
 
@@ -159,7 +159,7 @@ anv_timeline_add_point_locked(struct anv_device *device,
 
    if (list_is_empty(&timeline->free_points)) {
       *point =
-         vk_zalloc(&device->alloc, sizeof(**point),
+         vk_zalloc(&device->vk.alloc, sizeof(**point),
                    8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
       if (!(*point))
          result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -170,7 +170,7 @@ anv_timeline_add_point_locked(struct anv_device *device,
                                       0 /* explicit_address */,
                                       &(*point)->bo);
          if (result != VK_SUCCESS)
-            vk_free(&device->alloc, *point);
+            vk_free(&device->vk.alloc, *point);
       }
    } else {
       *point = list_first_entry(&timeline->free_points,
@@ -545,7 +545,7 @@ anv_queue_submit_add_timeline_signal(struct anv_queue_submit* submit,
 static struct anv_queue_submit *
 anv_queue_submit_alloc(struct anv_device *device)
 {
-   const VkAllocationCallbacks *alloc = &device->alloc;
+   const VkAllocationCallbacks *alloc = &device->vk.alloc;
    VkSystemAllocationScope alloc_scope = VK_SYSTEM_ALLOCATION_SCOPE_DEVICE;
 
    struct anv_queue_submit *submit = vk_zalloc(alloc, sizeof(*submit), 8, alloc_scope);
@@ -1100,7 +1100,7 @@ VkResult anv_CreateFence(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
 
-   fence = vk_zalloc2(&device->alloc, pAllocator, sizeof(*fence), 8,
+   fence = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*fence), 8,
                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (fence == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -1191,7 +1191,7 @@ void anv_DestroyFence(
    anv_fence_impl_cleanup(device, &fence->temporary);
    anv_fence_impl_cleanup(device, &fence->permanent);
 
-   vk_free2(&device->alloc, pAllocator, fence);
+   vk_free2(&device->vk.alloc, pAllocator, fence);
 }
 
 VkResult anv_ResetFences(
@@ -1297,7 +1297,7 @@ anv_wait_for_syncobj_fences(struct anv_device *device,
                             bool waitAll,
                             uint64_t abs_timeout_ns)
 {
-   uint32_t *syncobjs = vk_zalloc(&device->alloc,
+   uint32_t *syncobjs = vk_zalloc(&device->vk.alloc,
                                   sizeof(*syncobjs) * fenceCount, 8,
                                   VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
    if (!syncobjs)
@@ -1325,7 +1325,7 @@ anv_wait_for_syncobj_fences(struct anv_device *device,
                                  abs_timeout_ns, waitAll);
    } while (ret == -1 && errno == ETIME && anv_gettime_ns() < abs_timeout_ns);
 
-   vk_free(&device->alloc, syncobjs);
+   vk_free(&device->vk.alloc, syncobjs);
 
    if (ret == -1) {
       if (errno == ETIME) {
@@ -1782,7 +1782,7 @@ VkResult anv_CreateSemaphore(
    uint64_t timeline_value = 0;
    VkSemaphoreTypeKHR sem_type = get_semaphore_type(pCreateInfo->pNext, &timeline_value);
 
-   semaphore = vk_alloc(&device->alloc, sizeof(*semaphore), 8,
+   semaphore = vk_alloc(&device->vk.alloc, sizeof(*semaphore), 8,
                         VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
    if (semaphore == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -1801,7 +1801,7 @@ VkResult anv_CreateSemaphore(
       else
          result = timeline_semaphore_create(device, &semaphore->permanent, timeline_value);
       if (result != VK_SUCCESS) {
-         vk_free2(&device->alloc, pAllocator, semaphore);
+         vk_free2(&device->vk.alloc, pAllocator, semaphore);
          return result;
       }
    } else if (handleTypes & VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT) {
@@ -1809,7 +1809,7 @@ VkResult anv_CreateSemaphore(
       assert(sem_type == VK_SEMAPHORE_TYPE_BINARY_KHR);
       result = binary_semaphore_create(device, &semaphore->permanent, true);
       if (result != VK_SUCCESS) {
-         vk_free2(&device->alloc, pAllocator, semaphore);
+         vk_free2(&device->vk.alloc, pAllocator, semaphore);
          return result;
       }
    } else if (handleTypes & VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) {
@@ -1819,7 +1819,7 @@ VkResult anv_CreateSemaphore(
          semaphore->permanent.type = ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ;
          semaphore->permanent.syncobj = anv_gem_syncobj_create(device, 0);
          if (!semaphore->permanent.syncobj) {
-            vk_free2(&device->alloc, pAllocator, semaphore);
+            vk_free2(&device->vk.alloc, pAllocator, semaphore);
             return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
          }
       } else {
@@ -1828,7 +1828,7 @@ VkResult anv_CreateSemaphore(
       }
    } else {
       assert(!"Unknown handle type");
-      vk_free2(&device->alloc, pAllocator, semaphore);
+      vk_free2(&device->vk.alloc, pAllocator, semaphore);
       return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE);
    }
 
@@ -1900,7 +1900,7 @@ anv_semaphore_unref(struct anv_device *device, struct anv_semaphore *semaphore)
 
    anv_semaphore_impl_cleanup(device, &semaphore->temporary);
    anv_semaphore_impl_cleanup(device, &semaphore->permanent);
-   vk_free(&device->alloc, semaphore);
+   vk_free(&device->vk.alloc, semaphore);
 }
 
 void anv_DestroySemaphore(
@@ -2295,17 +2295,17 @@ VkResult anv_WaitSemaphores(
       return VK_SUCCESS;
 
    struct anv_timeline **timelines =
-      vk_alloc(&device->alloc,
+      vk_alloc(&device->vk.alloc,
                pWaitInfo->semaphoreCount * sizeof(*timelines),
                8, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
    if (!timelines)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   uint64_t *values = vk_alloc(&device->alloc,
+   uint64_t *values = vk_alloc(&device->vk.alloc,
                                pWaitInfo->semaphoreCount * sizeof(*values),
                                8, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
    if (!values) {
-      vk_free(&device->alloc, timelines);
+      vk_free(&device->vk.alloc, timelines);
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
    }
 
@@ -2333,8 +2333,8 @@ VkResult anv_WaitSemaphores(
                                   timeout);
    }
 
-   vk_free(&device->alloc, timelines);
-   vk_free(&device->alloc, values);
+   vk_free(&device->vk.alloc, timelines);
+   vk_free(&device->vk.alloc, values);
 
    return result;
 }
index dbb8d512cbd2093cf37883fdd859a828dbe06078..3b4877a3abbe15088d654b86a909f78edba327a3 100644 (file)
@@ -219,7 +219,7 @@ VkResult anv_CreateSwapchainKHR(
    if (pAllocator)
      alloc = pAllocator;
    else
-     alloc = &device->alloc;
+     alloc = &device->vk.alloc;
 
    return wsi_common_create_swapchain(wsi_device, _device,
                                       pCreateInfo, alloc, pSwapchain);
@@ -236,7 +236,7 @@ void anv_DestroySwapchainKHR(
    if (pAllocator)
      alloc = pAllocator;
    else
-     alloc = &device->alloc;
+     alloc = &device->vk.alloc;
 
    wsi_common_destroy_swapchain(_device, swapchain, alloc);
 }
index d876d294c1caad69c4ca70b77ae5c2a94fe4e4a4..62db692a9a88c254b5a002af5a9bb12b92706d4c 100644 (file)
@@ -255,7 +255,7 @@ anv_RegisterDeviceEventEXT(VkDevice _device,
    struct anv_fence *fence;
    VkResult ret;
 
-   fence = vk_zalloc2(&device->alloc, allocator, sizeof (*fence), 8,
+   fence = vk_zalloc2(&device->vk.alloc, allocator, sizeof (*fence), 8,
                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!fence)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -270,7 +270,7 @@ anv_RegisterDeviceEventEXT(VkDevice _device,
    if (ret == VK_SUCCESS)
       *_fence = anv_fence_to_handle(fence);
    else
-      vk_free2(&device->alloc, allocator, fence);
+      vk_free2(&device->vk.alloc, allocator, fence);
    return ret;
 }
 
@@ -285,7 +285,7 @@ anv_RegisterDisplayEventEXT(VkDevice _device,
    struct anv_fence *fence;
    VkResult ret;
 
-   fence = vk_zalloc2(&device->alloc, allocator, sizeof (*fence), 8,
+   fence = vk_zalloc2(&device->vk.alloc, allocator, sizeof (*fence), 8,
                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!fence)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
@@ -299,7 +299,7 @@ anv_RegisterDisplayEventEXT(VkDevice _device,
    if (ret == VK_SUCCESS)
       *_fence = anv_fence_to_handle(fence);
    else
-      vk_free2(&device->alloc, allocator, fence);
+      vk_free2(&device->vk.alloc, allocator, fence);
    return ret;
 }
 
index 5277d22489ef2b9af85740047199955998dd2616..82d6793e66a8f7b36e33ab56d7a2ab642c68b3c6 100644 (file)
@@ -2157,7 +2157,7 @@ genX(graphics_pipeline_create)(
    if (cache == NULL && device->physical->instance->pipeline_cache_enabled)
       cache = &device->default_pipeline_cache;
 
-   pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
+   pipeline = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*pipeline), 8,
                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (pipeline == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -2165,7 +2165,7 @@ genX(graphics_pipeline_create)(
    result = anv_pipeline_init(pipeline, device, cache,
                               pCreateInfo, pAllocator);
    if (result != VK_SUCCESS) {
-      vk_free2(&device->alloc, pAllocator, pipeline);
+      vk_free2(&device->vk.alloc, pAllocator, pipeline);
       return result;
    }
 
@@ -2274,7 +2274,7 @@ compute_pipeline_create(
    if (cache == NULL && device->physical->instance->pipeline_cache_enabled)
       cache = &device->default_pipeline_cache;
 
-   pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
+   pipeline = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*pipeline), 8,
                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (pipeline == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -2283,11 +2283,11 @@ compute_pipeline_create(
    pipeline->base.type = ANV_PIPELINE_COMPUTE;
 
    const VkAllocationCallbacks *alloc =
-      pAllocator ? pAllocator : &device->alloc;
+      pAllocator ? pAllocator : &device->vk.alloc;
 
    result = anv_reloc_list_init(&pipeline->base.batch_relocs, alloc);
    if (result != VK_SUCCESS) {
-      vk_free2(&device->alloc, pAllocator, pipeline);
+      vk_free2(&device->vk.alloc, pAllocator, pipeline);
       return result;
    }
    pipeline->base.batch.alloc = alloc;
@@ -2309,7 +2309,7 @@ compute_pipeline_create(
                                     pCreateInfo->stage.pSpecializationInfo);
    if (result != VK_SUCCESS) {
       ralloc_free(pipeline->base.mem_ctx);
-      vk_free2(&device->alloc, pAllocator, pipeline);
+      vk_free2(&device->vk.alloc, pAllocator, pipeline);
       return result;
    }
 
index ba7c1e94fe5bc1f633952b4b40e4fe21f88e63e1..d5d6d6e2f910585d144d1830aa0c0442218726cb 100644 (file)
@@ -101,7 +101,7 @@ VkResult genX(CreateQueryPool)(
       assert(!"Invalid query type");
    }
 
-   pool = vk_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8,
+   pool = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*pool), 8,
                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (pool == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -135,7 +135,7 @@ VkResult genX(CreateQueryPool)(
    return VK_SUCCESS;
 
  fail:
-   vk_free2(&device->alloc, pAllocator, pool);
+   vk_free2(&device->vk.alloc, pAllocator, pool);
 
    return result;
 }
@@ -152,7 +152,7 @@ void genX(DestroyQueryPool)(
       return;
 
    anv_device_release_bo(device, pool->bo);
-   vk_free2(&device->alloc, pAllocator, pool);
+   vk_free2(&device->vk.alloc, pAllocator, pool);
 }
 
 static struct anv_address
index 84c43473774cfa64227f055270e8b6a900bf76c1..fd87954d1003b648234f3b2ff97c5db6161b285a 100644 (file)
@@ -358,7 +358,7 @@ VkResult genX(CreateSampler)(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
 
-   sampler = vk_zalloc2(&device->alloc, pAllocator, sizeof(*sampler), 8,
+   sampler = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*sampler), 8,
                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!sampler)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
index 16a6037a44726d0855772468a18e49ac63eb112d..640c36eff22de1b9505010c4df60c39048f86256 100644 (file)
@@ -28,6 +28,8 @@ VULKAN_UTIL_FILES := \
        util/vk_debug_report.c \
        util/vk_debug_report.h \
        util/vk_format.c \
+       util/vk_object.c \
+       util/vk_object.h \
        util/vk_util.c \
        util/vk_util.h
 
index 0798913fe863c252547cb1ae8e7a8c0022795e3f..8809b2b323cbd4a45518c3954101acc8ac43d87e 100644 (file)
@@ -23,6 +23,8 @@ files_vulkan_util = files(
   'vk_debug_report.c',
   'vk_debug_report.h',
   'vk_format.c',
+  'vk_object.c',
+  'vk_object.h',
   'vk_util.c',
   'vk_util.h',
 )
diff --git a/src/vulkan/util/vk_object.c b/src/vulkan/util/vk_object.c
new file mode 100644 (file)
index 0000000..77258ab
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright © 2020 Intel Corporation
+ *
+ * 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 "vk_object.h"
+
+void
+vk_device_init(struct vk_device *device,
+               UNUSED const VkDeviceCreateInfo *pCreateInfo,
+               const VkAllocationCallbacks *instance_alloc,
+               const VkAllocationCallbacks *device_alloc)
+{
+   device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
+   if (device_alloc)
+      device->alloc = *device_alloc;
+   else
+      device->alloc = *instance_alloc;
+}
+
+void
+vk_device_finish(UNUSED struct vk_device *device)
+{
+}
diff --git a/src/vulkan/util/vk_object.h b/src/vulkan/util/vk_object.h
new file mode 100644 (file)
index 0000000..8fc42b8
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2020 Intel Corporation
+ *
+ * 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.
+ */
+#ifndef VK_OBJECT_H
+#define VK_OBJECT_H
+
+#include <vulkan/vulkan.h>
+#include <vulkan/vk_icd.h>
+
+#include "util/macros.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct vk_device {
+   VK_LOADER_DATA _loader_data;
+   VkAllocationCallbacks alloc;
+};
+
+void vk_device_init(struct vk_device *device,
+                    const VkDeviceCreateInfo *pCreateInfo,
+                    const VkAllocationCallbacks *instance_alloc,
+                    const VkAllocationCallbacks *device_alloc);
+void vk_device_finish(struct vk_device *device);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* VK_OBJECT_H */