From a9158f795143fb8b333e6fe33b25c2a4e4d2da15 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 21 Apr 2020 12:42:59 -0500 Subject: [PATCH] vulkan,anv: Add a common base object type for VkDevice 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 Acked-by: Kristian H. Kristensen Acked-by: Bas Nieuwenhuizen Reviewed-by: Samuel Pitoiset Part-of: --- src/intel/vulkan/anv_cmd_buffer.c | 6 ++-- src/intel/vulkan/anv_descriptor_set.c | 16 ++++----- src/intel/vulkan/anv_device.c | 32 ++++++++--------- src/intel/vulkan/anv_formats.c | 4 +-- src/intel/vulkan/anv_image.c | 14 ++++---- src/intel/vulkan/anv_intel.c | 6 ++-- src/intel/vulkan/anv_pass.c | 6 ++-- src/intel/vulkan/anv_pipeline.c | 10 +++--- src/intel/vulkan/anv_pipeline_cache.c | 8 ++--- src/intel/vulkan/anv_private.h | 7 ++-- src/intel/vulkan/anv_queue.c | 40 ++++++++++----------- src/intel/vulkan/anv_wsi.c | 4 +-- src/intel/vulkan/anv_wsi_display.c | 8 ++--- src/intel/vulkan/genX_pipeline.c | 12 +++---- src/intel/vulkan/genX_query.c | 6 ++-- src/intel/vulkan/genX_state.c | 2 +- src/vulkan/Makefile.sources | 2 ++ src/vulkan/util/meson.build | 2 ++ src/vulkan/util/vk_object.c | 42 ++++++++++++++++++++++ src/vulkan/util/vk_object.h | 50 +++++++++++++++++++++++++++ 20 files changed, 185 insertions(+), 92 deletions(-) create mode 100644 src/vulkan/util/vk_object.c create mode 100644 src/vulkan/util/vk_object.h diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index f4921ba551e..03af604de4c 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -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( diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c index 2e101fd1fdc..ce6caafcf7a 100644 --- a/src/intel/vulkan/anv_descriptor_set.c +++ b/src/intel/vulkan/anv_descriptor_set.c @@ -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( diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index b0a02b02a6d..012bb7d1976 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -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[] = { diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index b5962f13d6c..db1ea3f1818 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -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); } diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 19809884717..1f30ee12819 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -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); } diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c index 23489c011a1..9c7e77dc9f7 100644 --- a/src/intel/vulkan/anv_intel.c +++ b/src/intel/vulkan/anv_intel.c @@ -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; } diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c index ec32e0ca3bd..b100bec929d 100644 --- a/src/intel/vulkan/anv_pass.c +++ b/src/intel/vulkan/anv_pass.c @@ -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( diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 0767aaf6cf2..d3bbd06e061 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -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; diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c index 69865951e1c..39df5f1ded5 100644 --- a/src/intel/vulkan/anv_pipeline_cache.c +++ b/src/intel/vulkan/anv_pipeline_cache.c @@ -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( diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index ed851f5aacf..e39b328cca3 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -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 { diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c index b9e19617d8a..c2229e9fd0a 100644 --- a/src/intel/vulkan/anv_queue.c +++ b/src/intel/vulkan/anv_queue.c @@ -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; } diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c index dbb8d512cbd..3b4877a3abb 100644 --- a/src/intel/vulkan/anv_wsi.c +++ b/src/intel/vulkan/anv_wsi.c @@ -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); } diff --git a/src/intel/vulkan/anv_wsi_display.c b/src/intel/vulkan/anv_wsi_display.c index d876d294c1c..62db692a9a8 100644 --- a/src/intel/vulkan/anv_wsi_display.c +++ b/src/intel/vulkan/anv_wsi_display.c @@ -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; } diff --git a/src/intel/vulkan/genX_pipeline.c b/src/intel/vulkan/genX_pipeline.c index 5277d22489e..82d6793e66a 100644 --- a/src/intel/vulkan/genX_pipeline.c +++ b/src/intel/vulkan/genX_pipeline.c @@ -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; } diff --git a/src/intel/vulkan/genX_query.c b/src/intel/vulkan/genX_query.c index ba7c1e94fe5..d5d6d6e2f91 100644 --- a/src/intel/vulkan/genX_query.c +++ b/src/intel/vulkan/genX_query.c @@ -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 diff --git a/src/intel/vulkan/genX_state.c b/src/intel/vulkan/genX_state.c index 84c43473774..fd87954d100 100644 --- a/src/intel/vulkan/genX_state.c +++ b/src/intel/vulkan/genX_state.c @@ -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); diff --git a/src/vulkan/Makefile.sources b/src/vulkan/Makefile.sources index 16a6037a447..640c36eff22 100644 --- a/src/vulkan/Makefile.sources +++ b/src/vulkan/Makefile.sources @@ -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 diff --git a/src/vulkan/util/meson.build b/src/vulkan/util/meson.build index 0798913fe86..8809b2b323c 100644 --- a/src/vulkan/util/meson.build +++ b/src/vulkan/util/meson.build @@ -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 index 00000000000..77258ab6879 --- /dev/null +++ b/src/vulkan/util/vk_object.c @@ -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 index 00000000000..8fc42b862da --- /dev/null +++ b/src/vulkan/util/vk_object.h @@ -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 +#include + +#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 */ -- 2.30.2