From 5d3fdbc52bf8bee6f0acfd55c87b8d280908b559 Mon Sep 17 00:00:00 2001 From: Hyunjun Ko Date: Mon, 13 Jul 2020 03:08:15 +0000 Subject: [PATCH] turnip: Use the common base object type and struct. v2. Define new helper function to avoid duplicated a pair of function calls. v3. Move new helper functions to vk_object.h and call them. v4. Merge 2 commits to use commomn base object type and struct into one. Signed-off-by: Hyunjun Ko Part-of: --- src/freedreno/vulkan/tu_cmd_buffer.c | 17 ++++--- src/freedreno/vulkan/tu_descriptor_set.c | 50 +++++++++++--------- src/freedreno/vulkan/tu_descriptor_set.h | 4 ++ src/freedreno/vulkan/tu_device.c | 80 +++++++++++++++++--------------- src/freedreno/vulkan/tu_fence.c | 11 ++--- src/freedreno/vulkan/tu_image.c | 21 +++++---- src/freedreno/vulkan/tu_pass.c | 12 ++--- src/freedreno/vulkan/tu_pipeline.c | 18 ++++--- src/freedreno/vulkan/tu_pipeline_cache.c | 8 ++-- src/freedreno/vulkan/tu_private.h | 53 +++++++++++++++++---- src/freedreno/vulkan/tu_query.c | 11 ++--- src/freedreno/vulkan/tu_shader.c | 14 +++--- src/freedreno/vulkan/tu_wsi.c | 4 +- 13 files changed, 175 insertions(+), 128 deletions(-) diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index 62751ba..cb207f0 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -1333,12 +1333,12 @@ tu_create_cmd_buffer(struct tu_device *device, VkCommandBuffer *pCommandBuffer) { struct tu_cmd_buffer *cmd_buffer; - cmd_buffer = vk_zalloc(&pool->alloc, sizeof(*cmd_buffer), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + + cmd_buffer = vk_object_zalloc(&device->vk, NULL, sizeof(*cmd_buffer), + VK_OBJECT_TYPE_COMMAND_BUFFER); if (cmd_buffer == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); - cmd_buffer->_loader_data.loaderMagic = ICD_LOADER_MAGIC; cmd_buffer->device = device; cmd_buffer->pool = pool; cmd_buffer->level = level; @@ -1379,7 +1379,7 @@ tu_cmd_buffer_destroy(struct tu_cmd_buffer *cmd_buffer) tu_cs_finish(&cmd_buffer->sub_cs); tu_bo_list_destroy(&cmd_buffer->bo_list); - vk_free(&cmd_buffer->pool->alloc, cmd_buffer); + vk_object_free(&cmd_buffer->device->vk, &cmd_buffer->pool->alloc, cmd_buffer); } static VkResult @@ -1422,7 +1422,6 @@ tu_AllocateCommandBuffers(VkDevice _device, list_addtail(&cmd_buffer->pool_link, &pool->cmd_buffers); result = tu_reset_cmd_buffer(cmd_buffer); - cmd_buffer->_loader_data.loaderMagic = ICD_LOADER_MAGIC; cmd_buffer->level = pAllocateInfo->level; pCommandBuffers[i] = tu_cmd_buffer_to_handle(cmd_buffer); @@ -2481,15 +2480,15 @@ tu_CreateCommandPool(VkDevice _device, TU_FROM_HANDLE(tu_device, device, _device); struct tu_cmd_pool *pool; - pool = vk_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + pool = vk_object_alloc(&device->vk, pAllocator, sizeof(*pool), + VK_OBJECT_TYPE_COMMAND_POOL); if (pool == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); if (pAllocator) pool->alloc = *pAllocator; else - pool->alloc = device->alloc; + pool->alloc = device->vk.alloc; list_inithead(&pool->cmd_buffers); list_inithead(&pool->free_cmd_buffers); @@ -2524,7 +2523,7 @@ tu_DestroyCommandPool(VkDevice _device, tu_cmd_buffer_destroy(cmd_buffer); } - vk_free2(&device->alloc, pAllocator, pool); + vk_object_free(&device->vk, pAllocator, pool); } VkResult diff --git a/src/freedreno/vulkan/tu_descriptor_set.c b/src/freedreno/vulkan/tu_descriptor_set.c index 9dbd85b..060945c 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.c +++ b/src/freedreno/vulkan/tu_descriptor_set.c @@ -148,8 +148,8 @@ tu_CreateDescriptorSetLayout( immutable_sampler_count * sizeof(struct tu_sampler) + ycbcr_sampler_count * sizeof(struct tu_sampler_ycbcr_conversion); - set_layout = vk_zalloc2(&device->alloc, pAllocator, size, 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + set_layout = vk_object_zalloc(&device->vk, pAllocator, size, + VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT); if (!set_layout) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -163,7 +163,7 @@ tu_CreateDescriptorSetLayout( VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings( pCreateInfo->pBindings, pCreateInfo->bindingCount); if (!bindings) { - vk_free2(&device->alloc, pAllocator, set_layout); + vk_object_free(&device->vk, pAllocator, set_layout); return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); } @@ -272,7 +272,7 @@ tu_DestroyDescriptorSetLayout(VkDevice _device, if (!set_layout) return; - vk_free2(&device->alloc, pAllocator, set_layout); + vk_object_free(&device->vk, pAllocator, set_layout); } void @@ -353,8 +353,8 @@ tu_CreatePipelineLayout(VkDevice _device, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO); - layout = vk_alloc2(&device->alloc, pAllocator, sizeof(*layout), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + layout = vk_object_alloc(&device->vk, pAllocator, sizeof(*layout), + VK_OBJECT_TYPE_PIPELINE_LAYOUT); if (layout == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -411,7 +411,8 @@ tu_DestroyPipelineLayout(VkDevice _device, if (!pipeline_layout) return; - vk_free2(&device->alloc, pAllocator, pipeline_layout); + + vk_object_free(&device->vk, pAllocator, pipeline_layout); } #define EMPTY 1 @@ -445,7 +446,7 @@ tu_descriptor_set_create(struct tu_device *device, set = (struct tu_descriptor_set*)pool->host_memory_ptr; pool->host_memory_ptr += mem_size; } else { - set = vk_alloc2(&device->alloc, NULL, mem_size, 8, + set = vk_alloc2(&device->vk.alloc, NULL, mem_size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!set) @@ -453,6 +454,7 @@ tu_descriptor_set_create(struct tu_device *device, } memset(set, 0, mem_size); + vk_object_base_init(&device->vk, &set->base, VK_OBJECT_TYPE_DESCRIPTOR_SET); if (layout->dynamic_offset_count) { set->dynamic_descriptors = (uint32_t *)((uint8_t*)set + dynamic_offset); @@ -472,7 +474,7 @@ tu_descriptor_set_create(struct tu_device *device, set->size = layout_size; if (!pool->host_memory_base && pool->entry_count == pool->max_entry_count) { - vk_free2(&device->alloc, NULL, set); + vk_object_free(&device->vk, NULL, set); return vk_error(device->instance, VK_ERROR_OUT_OF_POOL_MEMORY); } @@ -500,7 +502,7 @@ tu_descriptor_set_create(struct tu_device *device, } if (pool->size - offset < layout_size) { - vk_free2(&device->alloc, NULL, set); + vk_object_free(&device->vk, NULL, set); return vk_error(device->instance, VK_ERROR_OUT_OF_POOL_MEMORY); } @@ -559,7 +561,8 @@ tu_descriptor_set_destroy(struct tu_device *device, } } } - vk_free2(&device->alloc, NULL, set); + + vk_object_free(&device->vk, NULL, set); } VkResult @@ -598,13 +601,11 @@ tu_CreateDescriptorPool(VkDevice _device, size += sizeof(struct tu_descriptor_pool_entry) * pCreateInfo->maxSets; } - pool = vk_alloc2(&device->alloc, pAllocator, size, 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + pool = vk_object_zalloc(&device->vk, pAllocator, size, + VK_OBJECT_TYPE_DESCRIPTOR_POOL); if (!pool) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); - memset(pool, 0, sizeof(*pool)); - if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) { pool->host_memory_base = (uint8_t*)pool + sizeof(struct tu_descriptor_pool); pool->host_memory_ptr = pool->host_memory_base; @@ -646,7 +647,8 @@ tu_DestroyDescriptorPool(VkDevice _device, if (pool->size) tu_bo_finish(device, &pool->bo); - vk_free2(&device->alloc, pAllocator, pool); + + vk_object_free(&device->vk, pAllocator, pool); } VkResult @@ -1036,8 +1038,8 @@ tu_CreateDescriptorUpdateTemplate( sizeof(struct tu_descriptor_update_template_entry) * entry_count; struct tu_descriptor_update_template *templ; - templ = vk_alloc2(&device->alloc, pAllocator, size, 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + templ = vk_object_alloc(&device->vk, pAllocator, size, + VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE); if (!templ) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -1109,7 +1111,7 @@ tu_DestroyDescriptorUpdateTemplate( if (!templ) return; - vk_free2(&device->alloc, pAllocator, templ); + vk_object_free(&device->vk, pAllocator, templ); } void @@ -1213,8 +1215,8 @@ tu_CreateSamplerYcbcrConversion( TU_FROM_HANDLE(tu_device, device, _device); struct tu_sampler_ycbcr_conversion *conversion; - conversion = vk_alloc2(&device->alloc, pAllocator, sizeof(*conversion), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + conversion = vk_object_alloc(&device->vk, pAllocator, sizeof(*conversion), + VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION); if (!conversion) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -1238,6 +1240,8 @@ tu_DestroySamplerYcbcrConversion(VkDevice _device, TU_FROM_HANDLE(tu_device, device, _device); TU_FROM_HANDLE(tu_sampler_ycbcr_conversion, ycbcr_conversion, ycbcrConversion); - if (ycbcr_conversion) - vk_free2(&device->alloc, pAllocator, ycbcr_conversion); + if (!ycbcr_conversion) + return; + + vk_object_free(&device->vk, pAllocator, ycbcr_conversion); } diff --git a/src/freedreno/vulkan/tu_descriptor_set.h b/src/freedreno/vulkan/tu_descriptor_set.h index 8673729..ba0e57d 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.h +++ b/src/freedreno/vulkan/tu_descriptor_set.h @@ -68,6 +68,8 @@ struct tu_descriptor_set_binding_layout struct tu_descriptor_set_layout { + struct vk_object_base base; + /* The create flags for this descriptor set layout */ VkDescriptorSetLayoutCreateFlags flags; @@ -99,6 +101,8 @@ struct tu_descriptor_set_layout struct tu_pipeline_layout { + struct vk_object_base base; + struct { struct tu_descriptor_set_layout *layout; diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index 370bd6c..a893c3b 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -218,7 +218,7 @@ tu_physical_device_init(struct tu_physical_device *device, if (instance->debug_flags & TU_DEBUG_STARTUP) tu_logi("Found compatible device '%s'.", path); - device->_loader_data.loaderMagic = ICD_LOADER_MAGIC; + vk_object_base_init(NULL, &device->base, VK_OBJECT_TYPE_PHYSICAL_DEVICE); device->instance = instance; assert(strlen(path) < ARRAY_SIZE(device->path)); strncpy(device->path, path, ARRAY_SIZE(device->path)); @@ -339,6 +339,8 @@ tu_physical_device_finish(struct tu_physical_device *device) close(device->local_fd); if (device->master_fd != -1) close(device->master_fd); + + vk_object_base_finish(&device->base); } static VKAPI_ATTR void * @@ -421,10 +423,11 @@ tu_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (!instance) return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY); - instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC; + vk_object_base_init(NULL, &instance->base, VK_OBJECT_TYPE_INSTANCE); if (pAllocator) instance->alloc = *pAllocator; @@ -445,6 +448,7 @@ tu_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, int index = tu_get_instance_extension_index(ext_name); if (index < 0 || !tu_instance_extensions_supported.extensions[index]) { + vk_object_base_finish(&instance->base); vk_free2(&default_alloc, pAllocator, instance); return vk_error(instance, VK_ERROR_EXTENSION_NOT_PRESENT); } @@ -454,6 +458,7 @@ tu_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, result = vk_debug_report_instance_init(&instance->debug_report_callbacks); if (result != VK_SUCCESS) { + vk_object_base_finish(&instance->base); vk_free2(&default_alloc, pAllocator, instance); return vk_error(instance, result); } @@ -486,6 +491,7 @@ tu_DestroyInstance(VkInstance _instance, vk_debug_report_instance_destroy(&instance->debug_report_callbacks); + vk_object_base_finish(&instance->base); vk_free(&instance->alloc, instance); } @@ -1096,7 +1102,8 @@ tu_queue_init(struct tu_device *device, int idx, VkDeviceQueueCreateFlags flags) { - queue->_loader_data.loaderMagic = ICD_LOADER_MAGIC; + vk_object_base_init(&device->vk, &queue->base, VK_OBJECT_TYPE_QUEUE); + queue->device = device; queue->queue_family_index = queue_family_index; queue->queue_idx = idx; @@ -1212,22 +1219,19 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice, if (!device) return vk_error(physical_device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); - device->_loader_data.loaderMagic = ICD_LOADER_MAGIC; + vk_device_init(&device->vk, pCreateInfo, + &physical_device->instance->alloc, pAllocator); + device->instance = physical_device->instance; device->physical_device = physical_device; device->_lost = false; - if (pAllocator) - device->alloc = *pAllocator; - else - device->alloc = physical_device->instance->alloc; - for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i]; int index = tu_get_device_extension_index(ext_name); if (index < 0 || !physical_device->supported_extensions.extensions[index]) { - vk_free(&device->alloc, device); + vk_free(&device->vk.alloc, device); return vk_error(physical_device->instance, VK_ERROR_EXTENSION_NOT_PRESENT); } @@ -1240,7 +1244,7 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice, &pCreateInfo->pQueueCreateInfos[i]; uint32_t qfi = queue_create->queueFamilyIndex; device->queues[qfi] = vk_alloc( - &device->alloc, queue_create->queueCount * sizeof(struct tu_queue), + &device->vk.alloc, queue_create->queueCount * sizeof(struct tu_queue), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); if (!device->queues[qfi]) { result = VK_ERROR_OUT_OF_HOST_MEMORY; @@ -1314,10 +1318,10 @@ fail_queues: for (unsigned q = 0; q < device->queue_count[i]; q++) tu_queue_finish(&device->queues[i][q]); if (device->queue_count[i]) - vk_free(&device->alloc, device->queues[i]); + vk_object_free(&device->vk, NULL, device->queues[i]); } - vk_free(&device->alloc, device); + vk_free(&device->vk.alloc, device); return result; } @@ -1333,7 +1337,7 @@ tu_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator) for (unsigned q = 0; q < device->queue_count[i]; q++) tu_queue_finish(&device->queues[i][q]); if (device->queue_count[i]) - vk_free(&device->alloc, device->queues[i]); + vk_object_free(&device->vk, NULL, device->queues[i]); } for (unsigned i = 0; i < ARRAY_SIZE(device->scratch_bos); i++) { @@ -1346,7 +1350,7 @@ tu_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator) VkPipelineCache pc = tu_pipeline_cache_to_handle(device->mem_cache); tu_DestroyPipelineCache(tu_device_to_handle(device), pc, NULL); - vk_free(&device->alloc, device); + vk_free(&device->vk.alloc, device); } VkResult @@ -1774,8 +1778,8 @@ tu_alloc_memory(struct tu_device *device, return VK_SUCCESS; } - mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + mem = vk_object_alloc(&device->vk, pAllocator, sizeof(*mem), + VK_OBJECT_TYPE_DEVICE_MEMORY); if (mem == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -1807,7 +1811,7 @@ tu_alloc_memory(struct tu_device *device, } if (result != VK_SUCCESS) { - vk_free2(&device->alloc, pAllocator, mem); + vk_object_free(&device->vk, pAllocator, mem); return result; } @@ -1844,7 +1848,7 @@ tu_FreeMemory(VkDevice _device, return; tu_bo_finish(device, &mem->bo); - vk_free2(&device->alloc, pAllocator, mem); + vk_object_free(&device->vk, pAllocator, mem); } VkResult @@ -2092,8 +2096,8 @@ tu_CreateSemaphore(VkDevice _device, TU_FROM_HANDLE(tu_device, device, _device); struct tu_semaphore *sem = - vk_alloc2(&device->alloc, pAllocator, sizeof(*sem), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + vk_object_alloc(&device->vk, pAllocator, sizeof(*sem), + VK_OBJECT_TYPE_SEMAPHORE); if (!sem) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -2107,7 +2111,7 @@ tu_CreateSemaphore(VkDevice _device, if (handleTypes) { if (drmSyncobjCreate(device->physical_device->local_fd, 0, &sem->permanent.syncobj) < 0) { - vk_free2(&device->alloc, pAllocator, sem); + vk_free2(&device->vk.alloc, pAllocator, sem); return VK_ERROR_OUT_OF_HOST_MEMORY; } sem->permanent.kind = TU_SEMAPHORE_SYNCOBJ; @@ -2129,7 +2133,7 @@ tu_DestroySemaphore(VkDevice _device, tu_semaphore_part_destroy(device, &sem->permanent); tu_semaphore_part_destroy(device, &sem->temporary); - vk_free2(&device->alloc, pAllocator, sem); + vk_object_free(&device->vk, pAllocator, sem); } VkResult @@ -2139,10 +2143,10 @@ tu_CreateEvent(VkDevice _device, VkEvent *pEvent) { TU_FROM_HANDLE(tu_device, device, _device); - struct tu_event *event = - vk_alloc2(&device->alloc, pAllocator, sizeof(*event), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + struct tu_event *event = + vk_object_alloc(&device->vk, pAllocator, sizeof(*event), + VK_OBJECT_TYPE_EVENT); if (!event) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -2161,7 +2165,7 @@ tu_CreateEvent(VkDevice _device, fail_map: tu_bo_finish(device, &event->bo); fail_alloc: - vk_free2(&device->alloc, pAllocator, event); + vk_object_free(&device->vk, pAllocator, event); return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); } @@ -2177,7 +2181,7 @@ tu_DestroyEvent(VkDevice _device, return; tu_bo_finish(device, &event->bo); - vk_free2(&device->alloc, pAllocator, event); + vk_object_free(&device->vk, pAllocator, event); } VkResult @@ -2219,8 +2223,8 @@ tu_CreateBuffer(VkDevice _device, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO); - buffer = vk_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + buffer = vk_object_alloc(&device->vk, pAllocator, sizeof(*buffer), + VK_OBJECT_TYPE_BUFFER); if (buffer == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -2244,7 +2248,7 @@ tu_DestroyBuffer(VkDevice _device, if (!buffer) return; - vk_free2(&device->alloc, pAllocator, buffer); + vk_object_free(&device->vk, pAllocator, buffer); } VkResult @@ -2261,8 +2265,8 @@ tu_CreateFramebuffer(VkDevice _device, size_t size = sizeof(*framebuffer) + sizeof(struct tu_attachment_info) * pCreateInfo->attachmentCount; - framebuffer = vk_alloc2(&device->alloc, pAllocator, size, 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + framebuffer = vk_object_alloc(&device->vk, pAllocator, size, + VK_OBJECT_TYPE_FRAMEBUFFER); if (framebuffer == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -2292,7 +2296,8 @@ tu_DestroyFramebuffer(VkDevice _device, if (!fb) return; - vk_free2(&device->alloc, pAllocator, fb); + + vk_object_free(&device->vk, pAllocator, fb); } static void @@ -2365,8 +2370,8 @@ tu_CreateSampler(VkDevice _device, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO); - sampler = vk_alloc2(&device->alloc, pAllocator, sizeof(*sampler), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + sampler = vk_object_alloc(&device->vk, pAllocator, sizeof(*sampler), + VK_OBJECT_TYPE_SAMPLER); if (!sampler) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -2386,7 +2391,8 @@ tu_DestroySampler(VkDevice _device, if (!sampler) return; - vk_free2(&device->alloc, pAllocator, sampler); + + vk_object_free(&device->vk, pAllocator, sampler); } /* vk_icd.h does not declare this function, so we declare it here to diff --git a/src/freedreno/vulkan/tu_fence.c b/src/freedreno/vulkan/tu_fence.c index f3de4ee..1ee88b5 100644 --- a/src/freedreno/vulkan/tu_fence.c +++ b/src/freedreno/vulkan/tu_fence.c @@ -170,9 +170,8 @@ tu_CreateFence(VkDevice _device, TU_FROM_HANDLE(tu_device, device, _device); struct tu_fence *fence = - vk_alloc2(&device->alloc, pAllocator, sizeof(*fence), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); - + vk_object_alloc(&device->vk, pAllocator, sizeof(*fence), + VK_OBJECT_TYPE_FENCE); if (!fence) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -196,7 +195,7 @@ tu_DestroyFence(VkDevice _device, tu_fence_finish(fence); - vk_free2(&device->alloc, pAllocator, fence); + vk_object_free(&device->vk, pAllocator, fence); } /** @@ -344,7 +343,7 @@ tu_WaitForFences(VkDevice _device, struct pollfd stack_fds[8]; struct pollfd *fds = stack_fds; if (fenceCount > ARRAY_SIZE(stack_fds)) { - fds = vk_alloc(&device->alloc, sizeof(*fds) * fenceCount, 8, + fds = vk_alloc(&device->vk.alloc, sizeof(*fds) * fenceCount, 8, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); if (!fds) return VK_ERROR_OUT_OF_HOST_MEMORY; @@ -362,7 +361,7 @@ tu_WaitForFences(VkDevice _device, } if (fds != stack_fds) - vk_free(&device->alloc, fds); + vk_free(&device->vk.alloc, fds); if (result != VK_SUCCESS) return result; diff --git a/src/freedreno/vulkan/tu_image.c b/src/freedreno/vulkan/tu_image.c index 88b302e..6bcfc91 100644 --- a/src/freedreno/vulkan/tu_image.c +++ b/src/freedreno/vulkan/tu_image.c @@ -95,8 +95,8 @@ tu_image_create(VkDevice _device, assert(pCreateInfo->extent.height > 0); assert(pCreateInfo->extent.depth > 0); - image = vk_zalloc2(&device->alloc, alloc, sizeof(*image), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + image = vk_object_zalloc(&device->vk, alloc, sizeof(*image), + VK_OBJECT_TYPE_IMAGE); if (!image) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -259,7 +259,7 @@ tu_image_create(VkDevice _device, return VK_SUCCESS; invalid_layout: - vk_free2(&device->alloc, alloc, image); + vk_object_free(&device->vk, alloc, image); return vk_error(device->instance, VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT); } @@ -667,7 +667,7 @@ tu_DestroyImage(VkDevice _device, if (image->owned_memory != VK_NULL_HANDLE) tu_FreeMemory(_device, image->owned_memory, pAllocator); - vk_free2(&device->alloc, pAllocator, image); + vk_object_free(&device->vk, pAllocator, image); } void @@ -729,8 +729,8 @@ tu_CreateImageView(VkDevice _device, TU_FROM_HANDLE(tu_device, device, _device); struct tu_image_view *view; - view = vk_alloc2(&device->alloc, pAllocator, sizeof(*view), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + view = vk_object_alloc(&device->vk, pAllocator, sizeof(*view), + VK_OBJECT_TYPE_IMAGE_VIEW); if (view == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -751,7 +751,8 @@ tu_DestroyImageView(VkDevice _device, if (!iview) return; - vk_free2(&device->alloc, pAllocator, iview); + + vk_object_free(&device->vk, pAllocator, iview); } void @@ -811,8 +812,8 @@ tu_CreateBufferView(VkDevice _device, TU_FROM_HANDLE(tu_device, device, _device); struct tu_buffer_view *view; - view = vk_alloc2(&device->alloc, pAllocator, sizeof(*view), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + view = vk_object_alloc(&device->vk, pAllocator, sizeof(*view), + VK_OBJECT_TYPE_BUFFER_VIEW); if (!view) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -834,5 +835,5 @@ tu_DestroyBufferView(VkDevice _device, if (!view) return; - vk_free2(&device->alloc, pAllocator, view); + vk_object_free(&device->vk, pAllocator, view); } diff --git a/src/freedreno/vulkan/tu_pass.c b/src/freedreno/vulkan/tu_pass.c index 429d25e..d5c3c82 100644 --- a/src/freedreno/vulkan/tu_pass.c +++ b/src/freedreno/vulkan/tu_pass.c @@ -533,8 +533,8 @@ tu_CreateRenderPass2(VkDevice _device, attachments_offset = size; size += pCreateInfo->attachmentCount * sizeof(pass->attachments[0]); - pass = vk_zalloc2(&device->alloc, pAllocator, size, 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + pass = vk_object_zalloc(&device->vk, pAllocator, size, + VK_OBJECT_TYPE_RENDER_PASS); if (pass == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -568,11 +568,11 @@ tu_CreateRenderPass2(VkDevice _device, if (subpass_attachment_count) { pass->subpass_attachments = vk_alloc2( - &device->alloc, pAllocator, + &device->vk.alloc, pAllocator, subpass_attachment_count * sizeof(struct tu_subpass_attachment), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (pass->subpass_attachments == NULL) { - vk_free2(&device->alloc, pAllocator, pass); + vk_object_free(&device->vk, pAllocator, pass); return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); } } else @@ -672,8 +672,8 @@ tu_DestroyRenderPass(VkDevice _device, if (!_pass) return; - vk_free2(&device->alloc, pAllocator, pass->subpass_attachments); - vk_free2(&device->alloc, pAllocator, pass); + vk_free2(&device->vk.alloc, pAllocator, pass->subpass_attachments); + vk_object_free(&device->vk, pAllocator, pass); } void diff --git a/src/freedreno/vulkan/tu_pipeline.c b/src/freedreno/vulkan/tu_pipeline.c index 4596dcd..c22cadb 100644 --- a/src/freedreno/vulkan/tu_pipeline.c +++ b/src/freedreno/vulkan/tu_pipeline.c @@ -2396,9 +2396,8 @@ tu_pipeline_builder_build(struct tu_pipeline_builder *builder, { VkResult result; - *pipeline = - vk_zalloc2(&builder->device->alloc, builder->alloc, sizeof(**pipeline), - 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + *pipeline = vk_object_zalloc(&builder->device->vk, builder->alloc, + sizeof(**pipeline), VK_OBJECT_TYPE_PIPELINE); if (!*pipeline) return VK_ERROR_OUT_OF_HOST_MEMORY; @@ -2407,13 +2406,13 @@ tu_pipeline_builder_build(struct tu_pipeline_builder *builder, /* compile and upload shaders */ result = tu_pipeline_builder_compile_shaders(builder, *pipeline); if (result != VK_SUCCESS) { - vk_free2(&builder->device->alloc, builder->alloc, *pipeline); + vk_object_free(&builder->device->vk, builder->alloc, *pipeline); return result; } result = tu_pipeline_allocate_cs(builder->device, *pipeline, builder, NULL); if (result != VK_SUCCESS) { - vk_free2(&builder->device->alloc, builder->alloc, *pipeline); + vk_object_free(&builder->device->vk, builder->alloc, *pipeline); return result; } @@ -2575,9 +2574,8 @@ tu_compute_pipeline_create(VkDevice device, *pPipeline = VK_NULL_HANDLE; - pipeline = - vk_zalloc2(&dev->alloc, pAllocator, sizeof(*pipeline), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + pipeline = vk_object_zalloc(&dev->vk, pAllocator, sizeof(*pipeline), + VK_OBJECT_TYPE_PIPELINE); if (!pipeline) return VK_ERROR_OUT_OF_HOST_MEMORY; @@ -2628,7 +2626,7 @@ fail: if (shader) tu_shader_destroy(dev, shader, pAllocator); - vk_free2(&dev->alloc, pAllocator, pipeline); + vk_object_free(&dev->vk, pAllocator, pipeline); return result; } @@ -2666,5 +2664,5 @@ tu_DestroyPipeline(VkDevice _device, return; tu_pipeline_finish(pipeline, dev, pAllocator); - vk_free2(&dev->alloc, pAllocator, pipeline); + vk_object_free(&dev->vk, pAllocator, pipeline); } diff --git a/src/freedreno/vulkan/tu_pipeline_cache.c b/src/freedreno/vulkan/tu_pipeline_cache.c index 47a8b97..dd10a9f 100644 --- a/src/freedreno/vulkan/tu_pipeline_cache.c +++ b/src/freedreno/vulkan/tu_pipeline_cache.c @@ -262,15 +262,15 @@ tu_CreatePipelineCache(VkDevice _device, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO); assert(pCreateInfo->flags == 0); - cache = vk_alloc2(&device->alloc, pAllocator, sizeof(*cache), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + cache = vk_object_alloc(&device->vk, pAllocator, sizeof(*cache), + VK_OBJECT_TYPE_PIPELINE_CACHE); if (cache == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); if (pAllocator) cache->alloc = *pAllocator; else - cache->alloc = device->alloc; + cache->alloc = device->vk.alloc; tu_pipeline_cache_init(cache, device); @@ -296,7 +296,7 @@ tu_DestroyPipelineCache(VkDevice _device, return; tu_pipeline_cache_finish(cache); - vk_free2(&device->alloc, pAllocator, cache); + vk_object_free(&device->vk, pAllocator, cache); } VkResult diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h index f6a66c6..72d5c13 100644 --- a/src/freedreno/vulkan/tu_private.h +++ b/src/freedreno/vulkan/tu_private.h @@ -49,6 +49,7 @@ #include "util/macros.h" #include "util/u_atomic.h" #include "vk_alloc.h" +#include "vk_object.h" #include "vk_debug_report.h" #include "wsi_common.h" @@ -189,7 +190,7 @@ tu_lookup_entrypoint_checked( struct tu_physical_device { - VK_LOADER_DATA _loader_data; + struct vk_object_base base; struct tu_instance *instance; @@ -245,7 +246,7 @@ enum tu_debug_flags struct tu_instance { - VK_LOADER_DATA _loader_data; + struct vk_object_base base; VkAllocationCallbacks alloc; @@ -277,6 +278,8 @@ struct cache_entry; struct tu_pipeline_cache { + struct vk_object_base base; + struct tu_device *device; pthread_mutex_t mutex; @@ -301,6 +304,7 @@ struct tu_pipeline_key struct tu_fence { + struct vk_object_base base; struct wsi_fence *fence_wsi; bool signaled; int fd; @@ -321,7 +325,8 @@ tu_fence_wait_idle(struct tu_fence *fence); struct tu_queue { - VK_LOADER_DATA _loader_data; + struct vk_object_base base; + struct tu_device *device; uint32_t queue_family_index; int queue_idx; @@ -381,10 +386,7 @@ void tu_init_clear_blit_shaders(struct tu6_global *global); struct tu_device { - VK_LOADER_DATA _loader_data; - - VkAllocationCallbacks alloc; - + struct vk_device vk; struct tu_instance *instance; struct tu_queue *queues[TU_MAX_QUEUE_FAMILIES]; @@ -565,6 +567,8 @@ struct tu_cs struct tu_device_memory { + struct vk_object_base base; + struct tu_bo bo; VkDeviceSize size; @@ -585,6 +589,8 @@ struct tu_descriptor_range struct tu_descriptor_set { + struct vk_object_base base; + const struct tu_descriptor_set_layout *layout; struct tu_descriptor_pool *pool; uint32_t size; @@ -612,6 +618,8 @@ struct tu_descriptor_pool_entry struct tu_descriptor_pool { + struct vk_object_base base; + struct tu_bo bo; uint64_t current_offset; uint64_t size; @@ -654,12 +662,16 @@ struct tu_descriptor_update_template_entry struct tu_descriptor_update_template { + struct vk_object_base base; + uint32_t entry_count; struct tu_descriptor_update_template_entry entry[0]; }; struct tu_buffer { + struct vk_object_base base; + VkDeviceSize size; VkBufferUsageFlags usage; @@ -877,6 +889,8 @@ struct tu_cmd_state struct tu_cmd_pool { + struct vk_object_base base; + VkAllocationCallbacks alloc; struct list_head cmd_buffers; struct list_head free_cmd_buffers; @@ -924,7 +938,7 @@ tu_bo_list_merge(struct tu_bo_list *list, const struct tu_bo_list *other); struct tu_cmd_buffer { - VK_LOADER_DATA _loader_data; + struct vk_object_base base; struct tu_device *device; @@ -997,11 +1011,14 @@ tu_get_descriptors_state(struct tu_cmd_buffer *cmd_buffer, struct tu_event { + struct vk_object_base base; struct tu_bo bo; }; struct tu_shader_module { + struct vk_object_base base; + unsigned char sha1[20]; uint32_t code_size; @@ -1045,6 +1062,8 @@ struct tu_program_descriptor_linkage struct tu_pipeline { + struct vk_object_base base; + struct tu_cs cs; struct tu_pipeline_layout *layout; @@ -1222,6 +1241,8 @@ tu6_base_format(VkFormat format) struct tu_image { + struct vk_object_base base; + VkImageType type; /* The original VkFormat provided by the client. This may not match any * of the actual surface formats. @@ -1271,6 +1292,8 @@ tu_get_levelCount(const struct tu_image *image, struct tu_image_view { + struct vk_object_base base; + struct tu_image *image; /**< VkImageViewCreateInfo::image */ uint64_t base_addr; @@ -1307,6 +1330,8 @@ struct tu_image_view }; struct tu_sampler_ycbcr_conversion { + struct vk_object_base base; + VkFormat format; VkSamplerYcbcrModelConversion ycbcr_model; VkSamplerYcbcrRange ycbcr_range; @@ -1316,6 +1341,8 @@ struct tu_sampler_ycbcr_conversion { }; struct tu_sampler { + struct vk_object_base base; + uint32_t descriptor[A6XX_TEX_SAMP_DWORDS]; struct tu_sampler_ycbcr_conversion *ycbcr_sampler; }; @@ -1350,6 +1377,8 @@ tu_image_view_init(struct tu_image_view *view, struct tu_buffer_view { + struct vk_object_base base; + uint32_t descriptor[A6XX_TEX_CONST_DWORDS]; struct tu_buffer *buffer; @@ -1366,6 +1395,8 @@ struct tu_attachment_info struct tu_framebuffer { + struct vk_object_base base; + uint32_t width; uint32_t height; uint32_t layers; @@ -1434,6 +1465,8 @@ struct tu_render_pass_attachment struct tu_render_pass { + struct vk_object_base base; + uint32_t attachment_count; uint32_t subpass_count; uint32_t gmem_pixels; @@ -1446,6 +1479,8 @@ struct tu_render_pass struct tu_query_pool { + struct vk_object_base base; + VkQueryType type; uint32_t stride; uint64_t size; @@ -1469,6 +1504,8 @@ struct tu_semaphore_part struct tu_semaphore { + struct vk_object_base base; + struct tu_semaphore_part permanent; struct tu_semaphore_part temporary; }; diff --git a/src/freedreno/vulkan/tu_query.c b/src/freedreno/vulkan/tu_query.c index 143f144..4e74271 100644 --- a/src/freedreno/vulkan/tu_query.c +++ b/src/freedreno/vulkan/tu_query.c @@ -129,23 +129,22 @@ tu_CreateQueryPool(VkDevice _device, } struct tu_query_pool *pool = - vk_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); - + vk_object_alloc(&device->vk, pAllocator, sizeof(*pool), + VK_OBJECT_TYPE_QUERY_POOL); if (!pool) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); VkResult result = tu_bo_init_new(device, &pool->bo, pCreateInfo->queryCount * slot_size); if (result != VK_SUCCESS) { - vk_free2(&device->alloc, pAllocator, pool); + vk_object_free(&device->vk, pAllocator, pool); return result; } result = tu_bo_map(device, &pool->bo); if (result != VK_SUCCESS) { tu_bo_finish(device, &pool->bo); - vk_free2(&device->alloc, pAllocator, pool); + vk_object_free(&device->vk, pAllocator, pool); return result; } @@ -173,7 +172,7 @@ tu_DestroyQueryPool(VkDevice _device, return; tu_bo_finish(device, &pool->bo); - vk_free2(&device->alloc, pAllocator, pool); + vk_object_free(&device->vk, pAllocator, pool); } static uint32_t diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c index f0957a3..81bb33f 100644 --- a/src/freedreno/vulkan/tu_shader.c +++ b/src/freedreno/vulkan/tu_shader.c @@ -673,7 +673,7 @@ tu_shader_create(struct tu_device *dev, struct tu_shader *shader; shader = vk_zalloc2( - &dev->alloc, alloc, + &dev->vk.alloc, alloc, sizeof(*shader), 8, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); if (!shader) @@ -699,7 +699,7 @@ tu_shader_create(struct tu_device *dev, } if (!nir) { - vk_free2(&dev->alloc, alloc, shader); + vk_free2(&dev->vk.alloc, alloc, shader); return NULL; } @@ -804,7 +804,7 @@ tu_shader_destroy(struct tu_device *dev, { ir3_shader_destroy(shader->ir3_shader); - vk_free2(&dev->alloc, alloc, shader); + vk_free2(&dev->vk.alloc, alloc, shader); } VkResult @@ -820,9 +820,9 @@ tu_CreateShaderModule(VkDevice _device, assert(pCreateInfo->flags == 0); assert(pCreateInfo->codeSize % 4 == 0); - module = vk_alloc2(&device->alloc, pAllocator, - sizeof(*module) + pCreateInfo->codeSize, 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + module = vk_object_alloc(&device->vk, pAllocator, + sizeof(*module) + pCreateInfo->codeSize, + VK_OBJECT_TYPE_SHADER_MODULE); if (module == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); @@ -847,5 +847,5 @@ tu_DestroyShaderModule(VkDevice _device, if (!module) return; - vk_free2(&device->alloc, pAllocator, module); + vk_object_free(&device->vk, pAllocator, module); } diff --git a/src/freedreno/vulkan/tu_wsi.c b/src/freedreno/vulkan/tu_wsi.c index a4af498..ce5d4c8 100644 --- a/src/freedreno/vulkan/tu_wsi.c +++ b/src/freedreno/vulkan/tu_wsi.c @@ -168,7 +168,7 @@ tu_CreateSwapchainKHR(VkDevice _device, if (pAllocator) alloc = pAllocator; else - alloc = &device->alloc; + alloc = &device->vk.alloc; return wsi_common_create_swapchain(&device->physical_device->wsi_device, tu_device_to_handle(device), @@ -186,7 +186,7 @@ tu_DestroySwapchainKHR(VkDevice _device, if (pAllocator) alloc = pAllocator; else - alloc = &device->alloc; + alloc = &device->vk.alloc; wsi_common_destroy_swapchain(_device, swapchain, alloc); } -- 2.7.4