From 1ae6ece9802e77ede97722c0f7cdd0c24e6fbd04 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 14 Oct 2016 13:31:35 +1000 Subject: [PATCH] anv: move to using vk_alloc helpers. This moves all the alloc/free in anv to the generic helpers. Acked-by: Jason Ekstrand Signed-off-by: Dave Airlie --- src/intel/vulkan/anv_batch_chain.c | 40 +++++++++++------------ src/intel/vulkan/anv_cmd_buffer.c | 22 ++++++------- src/intel/vulkan/anv_descriptor_set.c | 12 +++---- src/intel/vulkan/anv_device.c | 26 +++++++-------- src/intel/vulkan/anv_image.c | 14 ++++---- src/intel/vulkan/anv_intel.c | 4 +-- src/intel/vulkan/anv_pass.c | 10 +++--- src/intel/vulkan/anv_pipeline.c | 6 ++-- src/intel/vulkan/anv_pipeline_cache.c | 8 ++--- src/intel/vulkan/anv_private.h | 46 +-------------------------- src/intel/vulkan/anv_query.c | 6 ++-- src/intel/vulkan/anv_wsi.c | 2 +- src/intel/vulkan/anv_wsi_wayland.c | 16 +++++----- src/intel/vulkan/anv_wsi_x11.c | 22 ++++++------- src/intel/vulkan/gen7_pipeline.c | 4 +-- src/intel/vulkan/gen8_pipeline.c | 4 +-- src/intel/vulkan/genX_pipeline.c | 6 ++-- src/intel/vulkan/genX_state.c | 2 +- 18 files changed, 103 insertions(+), 147 deletions(-) diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index 11bd4ef778d..dfa9abfabaa 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -59,18 +59,18 @@ anv_reloc_list_init_clone(struct anv_reloc_list *list, } list->relocs = - anv_alloc(alloc, list->array_length * sizeof(*list->relocs), 8, + vk_alloc(alloc, list->array_length * sizeof(*list->relocs), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (list->relocs == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); list->reloc_bos = - anv_alloc(alloc, list->array_length * sizeof(*list->reloc_bos), 8, + vk_alloc(alloc, list->array_length * sizeof(*list->reloc_bos), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (list->reloc_bos == NULL) { - anv_free(alloc, list->relocs); + vk_free(alloc, list->relocs); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); } @@ -95,8 +95,8 @@ void anv_reloc_list_finish(struct anv_reloc_list *list, const VkAllocationCallbacks *alloc) { - anv_free(alloc, list->relocs); - anv_free(alloc, list->reloc_bos); + vk_free(alloc, list->relocs); + vk_free(alloc, list->reloc_bos); } static VkResult @@ -112,16 +112,16 @@ anv_reloc_list_grow(struct anv_reloc_list *list, new_length *= 2; struct drm_i915_gem_relocation_entry *new_relocs = - anv_alloc(alloc, new_length * sizeof(*list->relocs), 8, + vk_alloc(alloc, new_length * sizeof(*list->relocs), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (new_relocs == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); struct anv_bo **new_reloc_bos = - anv_alloc(alloc, new_length * sizeof(*list->reloc_bos), 8, + vk_alloc(alloc, new_length * sizeof(*list->reloc_bos), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (new_reloc_bos == NULL) { - anv_free(alloc, new_relocs); + vk_free(alloc, new_relocs); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); } @@ -129,8 +129,8 @@ anv_reloc_list_grow(struct anv_reloc_list *list, memcpy(new_reloc_bos, list->reloc_bos, list->num_relocs * sizeof(*list->reloc_bos)); - anv_free(alloc, list->relocs); - anv_free(alloc, list->reloc_bos); + vk_free(alloc, list->relocs); + vk_free(alloc, list->reloc_bos); list->array_length = new_length; list->relocs = new_relocs; @@ -246,7 +246,7 @@ anv_batch_bo_create(struct anv_cmd_buffer *cmd_buffer, { VkResult result; - struct anv_batch_bo *bbo = anv_alloc(&cmd_buffer->pool->alloc, sizeof(*bbo), + struct anv_batch_bo *bbo = vk_alloc(&cmd_buffer->pool->alloc, sizeof(*bbo), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (bbo == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -267,7 +267,7 @@ anv_batch_bo_create(struct anv_cmd_buffer *cmd_buffer, fail_bo_alloc: anv_bo_pool_free(&cmd_buffer->device->batch_bo_pool, &bbo->bo); fail_alloc: - anv_free(&cmd_buffer->pool->alloc, bbo); + vk_free(&cmd_buffer->pool->alloc, bbo); return result; } @@ -279,7 +279,7 @@ anv_batch_bo_clone(struct anv_cmd_buffer *cmd_buffer, { VkResult result; - struct anv_batch_bo *bbo = anv_alloc(&cmd_buffer->pool->alloc, sizeof(*bbo), + struct anv_batch_bo *bbo = vk_alloc(&cmd_buffer->pool->alloc, sizeof(*bbo), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (bbo == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -306,7 +306,7 @@ anv_batch_bo_clone(struct anv_cmd_buffer *cmd_buffer, fail_bo_alloc: anv_bo_pool_free(&cmd_buffer->device->batch_bo_pool, &bbo->bo); fail_alloc: - anv_free(&cmd_buffer->pool->alloc, bbo); + vk_free(&cmd_buffer->pool->alloc, bbo); return result; } @@ -377,7 +377,7 @@ anv_batch_bo_destroy(struct anv_batch_bo *bbo, { anv_reloc_list_finish(&bbo->relocs, &cmd_buffer->pool->alloc); anv_bo_pool_free(&cmd_buffer->device->batch_bo_pool, &bbo->bo); - anv_free(&cmd_buffer->pool->alloc, bbo); + vk_free(&cmd_buffer->pool->alloc, bbo); } static VkResult @@ -659,8 +659,8 @@ anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer) anv_batch_bo_destroy(bbo, cmd_buffer); } - anv_free(&cmd_buffer->pool->alloc, cmd_buffer->execbuf2.objects); - anv_free(&cmd_buffer->pool->alloc, cmd_buffer->execbuf2.bos); + vk_free(&cmd_buffer->pool->alloc, cmd_buffer->execbuf2.objects); + vk_free(&cmd_buffer->pool->alloc, cmd_buffer->execbuf2.bos); } void @@ -877,16 +877,16 @@ anv_cmd_buffer_add_bo(struct anv_cmd_buffer *cmd_buffer, cmd_buffer->execbuf2.array_length * 2 : 64; struct drm_i915_gem_exec_object2 *new_objects = - anv_alloc(&cmd_buffer->pool->alloc, new_len * sizeof(*new_objects), + vk_alloc(&cmd_buffer->pool->alloc, new_len * sizeof(*new_objects), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (new_objects == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); struct anv_bo **new_bos = - anv_alloc(&cmd_buffer->pool->alloc, new_len * sizeof(*new_bos), + vk_alloc(&cmd_buffer->pool->alloc, new_len * sizeof(*new_bos), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (new_bos == NULL) { - anv_free(&cmd_buffer->pool->alloc, new_objects); + vk_free(&cmd_buffer->pool->alloc, new_objects); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); } diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 72f4f28172b..a652f9ad879 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -137,7 +137,7 @@ anv_cmd_state_reset(struct anv_cmd_buffer *cmd_buffer) state->need_query_wa = true; if (state->attachments != NULL) { - anv_free(&cmd_buffer->pool->alloc, state->attachments); + vk_free(&cmd_buffer->pool->alloc, state->attachments); state->attachments = NULL; } @@ -154,14 +154,14 @@ anv_cmd_state_setup_attachments(struct anv_cmd_buffer *cmd_buffer, struct anv_cmd_state *state = &cmd_buffer->state; ANV_FROM_HANDLE(anv_render_pass, pass, info->renderPass); - anv_free(&cmd_buffer->pool->alloc, state->attachments); + vk_free(&cmd_buffer->pool->alloc, state->attachments); if (pass->attachment_count == 0) { state->attachments = NULL; return; } - state->attachments = anv_alloc(&cmd_buffer->pool->alloc, + state->attachments = vk_alloc(&cmd_buffer->pool->alloc, pass->attachment_count * sizeof(state->attachments[0]), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); @@ -207,12 +207,12 @@ anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer *cmd_buffer, struct anv_push_constants **ptr = &cmd_buffer->state.push_constants[stage]; if (*ptr == NULL) { - *ptr = anv_alloc(&cmd_buffer->pool->alloc, size, 8, + *ptr = vk_alloc(&cmd_buffer->pool->alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (*ptr == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); } else if ((*ptr)->size < size) { - *ptr = anv_realloc(&cmd_buffer->pool->alloc, *ptr, size, 8, + *ptr = vk_realloc(&cmd_buffer->pool->alloc, *ptr, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (*ptr == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -231,7 +231,7 @@ static VkResult anv_create_cmd_buffer( struct anv_cmd_buffer *cmd_buffer; VkResult result; - cmd_buffer = anv_alloc(&pool->alloc, sizeof(*cmd_buffer), 8, + cmd_buffer = vk_alloc(&pool->alloc, sizeof(*cmd_buffer), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (cmd_buffer == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -265,7 +265,7 @@ static VkResult anv_create_cmd_buffer( return VK_SUCCESS; fail: - anv_free(&cmd_buffer->pool->alloc, cmd_buffer); + vk_free(&cmd_buffer->pool->alloc, cmd_buffer); return result; } @@ -305,8 +305,8 @@ anv_cmd_buffer_destroy(struct anv_cmd_buffer *cmd_buffer) anv_state_stream_finish(&cmd_buffer->surface_state_stream); anv_state_stream_finish(&cmd_buffer->dynamic_state_stream); - anv_free(&cmd_buffer->pool->alloc, cmd_buffer->state.attachments); - anv_free(&cmd_buffer->pool->alloc, cmd_buffer); + vk_free(&cmd_buffer->pool->alloc, cmd_buffer->state.attachments); + vk_free(&cmd_buffer->pool->alloc, cmd_buffer); } void anv_FreeCommandBuffers( @@ -771,7 +771,7 @@ VkResult anv_CreateCommandPool( ANV_FROM_HANDLE(anv_device, device, _device); struct anv_cmd_pool *pool; - pool = anv_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8, + pool = vk_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (pool == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -801,7 +801,7 @@ void anv_DestroyCommandPool( anv_cmd_buffer_destroy(cmd_buffer); } - anv_free2(&device->alloc, pAllocator, pool); + vk_free2(&device->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 4ab1802facb..7d5a78d018c 100644 --- a/src/intel/vulkan/anv_descriptor_set.c +++ b/src/intel/vulkan/anv_descriptor_set.c @@ -58,7 +58,7 @@ VkResult anv_CreateDescriptorSetLayout( (max_binding + 1) * sizeof(set_layout->binding[0]) + immutable_sampler_count * sizeof(struct anv_sampler *); - set_layout = anv_alloc2(&device->alloc, pAllocator, size, 8, + set_layout = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!set_layout) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -200,7 +200,7 @@ void anv_DestroyDescriptorSetLayout( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_descriptor_set_layout, set_layout, _set_layout); - anv_free2(&device->alloc, pAllocator, set_layout); + vk_free2(&device->alloc, pAllocator, set_layout); } static void @@ -228,7 +228,7 @@ VkResult anv_CreatePipelineLayout( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO); - layout = anv_alloc2(&device->alloc, pAllocator, sizeof(*layout), 8, + layout = vk_alloc2(&device->alloc, pAllocator, sizeof(*layout), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (layout == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -282,7 +282,7 @@ void anv_DestroyPipelineLayout( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_pipeline_layout, pipeline_layout, _pipelineLayout); - anv_free2(&device->alloc, pAllocator, pipeline_layout); + vk_free2(&device->alloc, pAllocator, pipeline_layout); } /* @@ -329,7 +329,7 @@ VkResult anv_CreateDescriptorPool( descriptor_count * sizeof(struct anv_descriptor) + buffer_count * sizeof(struct anv_buffer_view); - pool = anv_alloc2(&device->alloc, pAllocator, size, 8, + pool = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!pool) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -356,7 +356,7 @@ void anv_DestroyDescriptorPool( ANV_FROM_HANDLE(anv_descriptor_pool, pool, _pool); anv_state_stream_finish(&pool->surface_state_stream); - anv_free2(&device->alloc, pAllocator, pool); + vk_free2(&device->alloc, pAllocator, pool); } VkResult anv_ResetDescriptorPool( diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 53b9b1b9ac4..c995630f152 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -293,7 +293,7 @@ VkResult anv_CreateInstance( return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT); } - instance = anv_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8, + instance = vk_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!instance) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -333,7 +333,7 @@ void anv_DestroyInstance( _mesa_locale_fini(); - anv_free(&instance->alloc, instance); + vk_free(&instance->alloc, instance); } VkResult anv_EnumeratePhysicalDevices( @@ -855,7 +855,7 @@ VkResult anv_CreateDevice( return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT); } - device = anv_alloc2(&physical_device->instance->alloc, pAllocator, + device = vk_alloc2(&physical_device->instance->alloc, pAllocator, sizeof(*device), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); if (!device) @@ -952,7 +952,7 @@ VkResult anv_CreateDevice( fail_fd: close(device->fd); fail_device: - anv_free(&device->alloc, device); + vk_free(&device->alloc, device); return result; } @@ -990,7 +990,7 @@ void anv_DestroyDevice( pthread_mutex_destroy(&device->mutex); - anv_free(&device->alloc, device); + vk_free(&device->alloc, device); } VkResult anv_EnumerateInstanceExtensionProperties( @@ -1175,7 +1175,7 @@ VkResult anv_AllocateMemory( /* FINISHME: Fail if allocation request exceeds heap size. */ - mem = anv_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, + mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (mem == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -1194,7 +1194,7 @@ VkResult anv_AllocateMemory( return VK_SUCCESS; fail: - anv_free2(&device->alloc, pAllocator, mem); + vk_free2(&device->alloc, pAllocator, mem); return result; } @@ -1216,7 +1216,7 @@ void anv_FreeMemory( if (mem->bo.gem_handle != 0) anv_gem_close(device, mem->bo.gem_handle); - anv_free2(&device->alloc, pAllocator, mem); + vk_free2(&device->alloc, pAllocator, mem); } VkResult anv_MapMemory( @@ -1707,7 +1707,7 @@ VkResult anv_CreateBuffer( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO); - buffer = anv_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8, + buffer = vk_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (buffer == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -1730,7 +1730,7 @@ void anv_DestroyBuffer( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); - anv_free2(&device->alloc, pAllocator, buffer); + vk_free2(&device->alloc, pAllocator, buffer); } void @@ -1757,7 +1757,7 @@ void anv_DestroySampler( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_sampler, sampler, _sampler); - anv_free2(&device->alloc, pAllocator, sampler); + vk_free2(&device->alloc, pAllocator, sampler); } VkResult anv_CreateFramebuffer( @@ -1773,7 +1773,7 @@ VkResult anv_CreateFramebuffer( size_t size = sizeof(*framebuffer) + sizeof(struct anv_image_view *) * pCreateInfo->attachmentCount; - framebuffer = anv_alloc2(&device->alloc, pAllocator, size, 8, + framebuffer = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (framebuffer == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -1801,5 +1801,5 @@ void anv_DestroyFramebuffer( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_framebuffer, fb, _fb); - anv_free2(&device->alloc, pAllocator, fb); + vk_free2(&device->alloc, pAllocator, fb); } diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 1701f5009a1..b7c2e991daa 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -222,7 +222,7 @@ anv_image_create(VkDevice _device, anv_assert(pCreateInfo->extent.height > 0); anv_assert(pCreateInfo->extent.depth > 0); - image = anv_alloc2(&device->alloc, alloc, sizeof(*image), 8, + image = vk_alloc2(&device->alloc, alloc, sizeof(*image), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!image) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -251,7 +251,7 @@ anv_image_create(VkDevice _device, fail: if (image) - anv_free2(&device->alloc, alloc, image); + vk_free2(&device->alloc, alloc, image); return r; } @@ -276,7 +276,7 @@ anv_DestroyImage(VkDevice _device, VkImage _image, { ANV_FROM_HANDLE(anv_device, device, _device); - anv_free2(&device->alloc, pAllocator, anv_image_from_handle(_image)); + vk_free2(&device->alloc, pAllocator, anv_image_from_handle(_image)); } VkResult anv_BindImageMemory( @@ -411,7 +411,7 @@ anv_CreateImageView(VkDevice _device, ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); struct anv_image_view *iview; - iview = anv_alloc2(&device->alloc, pAllocator, sizeof(*iview), 8, + iview = vk_alloc2(&device->alloc, pAllocator, sizeof(*iview), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (iview == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -580,7 +580,7 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview, iview->storage_surface_state); } - anv_free2(&device->alloc, pAllocator, iview); + vk_free2(&device->alloc, pAllocator, iview); } @@ -594,7 +594,7 @@ anv_CreateBufferView(VkDevice _device, ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer); struct anv_buffer_view *view; - view = anv_alloc2(&device->alloc, pAllocator, sizeof(*view), 8, + view = vk_alloc2(&device->alloc, pAllocator, sizeof(*view), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!view) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -663,7 +663,7 @@ anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView, anv_state_pool_free(&device->surface_state_pool, view->storage_surface_state); - anv_free2(&device->alloc, pAllocator, view); + vk_free2(&device->alloc, pAllocator, view); } const struct anv_surface * diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c index d95d9afe8cf..3e1cc3f31a3 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 = anv_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, + mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (mem == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -94,7 +94,7 @@ VkResult anv_CreateDmaBufImageINTEL( return VK_SUCCESS; fail: - anv_free2(&device->alloc, pAllocator, mem); + vk_free2(&device->alloc, pAllocator, mem); return result; } diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c index 595c2ea67d7..6eaa5c85cab 100644 --- a/src/intel/vulkan/anv_pass.c +++ b/src/intel/vulkan/anv_pass.c @@ -41,7 +41,7 @@ VkResult anv_CreateRenderPass( attachments_offset = size; size += pCreateInfo->attachmentCount * sizeof(pass->attachments[0]); - pass = anv_alloc2(&device->alloc, pAllocator, size, 8, + pass = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (pass == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -76,11 +76,11 @@ VkResult anv_CreateRenderPass( } pass->subpass_attachments = - anv_alloc2(&device->alloc, pAllocator, + vk_alloc2(&device->alloc, pAllocator, subpass_attachment_count * sizeof(uint32_t), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (pass->subpass_attachments == NULL) { - anv_free2(&device->alloc, pAllocator, pass); + vk_free2(&device->alloc, pAllocator, pass); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); } @@ -146,8 +146,8 @@ void anv_DestroyRenderPass( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_render_pass, pass, _pass); - anv_free2(&device->alloc, pAllocator, pass->subpass_attachments); - anv_free2(&device->alloc, pAllocator, pass); + vk_free2(&device->alloc, pAllocator, pass->subpass_attachments); + vk_free2(&device->alloc, pAllocator, pass); } void anv_GetRenderAreaGranularity( diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index c185e8c4f65..4817de13af2 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -51,7 +51,7 @@ VkResult anv_CreateShaderModule( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO); assert(pCreateInfo->flags == 0); - module = anv_alloc2(&device->alloc, pAllocator, + module = vk_alloc2(&device->alloc, pAllocator, sizeof(*module) + pCreateInfo->codeSize, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (module == NULL) @@ -75,7 +75,7 @@ void anv_DestroyShaderModule( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_shader_module, module, _module); - anv_free2(&device->alloc, pAllocator, module); + vk_free2(&device->alloc, pAllocator, module); } #define SPIR_V_MAGIC_NUMBER 0x07230203 @@ -199,7 +199,7 @@ void anv_DestroyPipeline( anv_shader_bin_unref(device, pipeline->shaders[s]); } - anv_free2(&device->alloc, pAllocator, pipeline); + vk_free2(&device->alloc, pAllocator, pipeline); } static const uint32_t vk_to_gen_primitive_type[] = { diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c index 6e3f0f2c1de..79df315fab3 100644 --- a/src/intel/vulkan/anv_pipeline_cache.c +++ b/src/intel/vulkan/anv_pipeline_cache.c @@ -65,7 +65,7 @@ anv_shader_bin_create(struct anv_device *device, bind_map->surface_count, bind_map->sampler_count); struct anv_shader_bin *shader = - anv_alloc(&device->alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + vk_alloc(&device->alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); if (!shader) return NULL; @@ -108,7 +108,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_free(&device->alloc, shader); + vk_free(&device->alloc, shader); } static size_t @@ -417,7 +417,7 @@ VkResult anv_CreatePipelineCache( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO); assert(pCreateInfo->flags == 0); - cache = anv_alloc2(&device->alloc, pAllocator, + cache = vk_alloc2(&device->alloc, pAllocator, sizeof(*cache), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (cache == NULL) @@ -445,7 +445,7 @@ void anv_DestroyPipelineCache( anv_pipeline_cache_finish(cache); - anv_free2(&device->alloc, pAllocator, cache); + vk_free2(&device->alloc, pAllocator, cache); } VkResult anv_GetPipelineCacheData( diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 7efbe01f08f..2e3706906cc 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -47,6 +47,7 @@ #include "util/macros.h" #include "util/list.h" #include "util/u_vector.h" +#include "util/vk_alloc.h" /* Pre-declarations needed for WSI entrypoints */ struct wl_surface; @@ -452,51 +453,6 @@ struct anv_bo *anv_scratch_pool_alloc(struct anv_device *device, extern struct anv_dispatch_table dtable; -static inline void * -anv_alloc(const VkAllocationCallbacks *alloc, - size_t size, size_t align, - VkSystemAllocationScope scope) -{ - return alloc->pfnAllocation(alloc->pUserData, size, align, scope); -} - -static inline void * -anv_realloc(const VkAllocationCallbacks *alloc, - void *ptr, size_t size, size_t align, - VkSystemAllocationScope scope) -{ - return alloc->pfnReallocation(alloc->pUserData, ptr, size, align, scope); -} - -static inline void -anv_free(const VkAllocationCallbacks *alloc, void *data) -{ - alloc->pfnFree(alloc->pUserData, data); -} - -static inline void * -anv_alloc2(const VkAllocationCallbacks *parent_alloc, - const VkAllocationCallbacks *alloc, - size_t size, size_t align, - VkSystemAllocationScope scope) -{ - if (alloc) - return anv_alloc(alloc, size, align, scope); - else - return anv_alloc(parent_alloc, size, align, scope); -} - -static inline void -anv_free2(const VkAllocationCallbacks *parent_alloc, - const VkAllocationCallbacks *alloc, - void *data) -{ - if (alloc) - anv_free(alloc, data); - else - anv_free(parent_alloc, data); -} - struct anv_wsi_interaface; #define VK_ICD_WSI_PLATFORM_MAX 5 diff --git a/src/intel/vulkan/anv_query.c b/src/intel/vulkan/anv_query.c index e45b519c0f3..4afdaaf3679 100644 --- a/src/intel/vulkan/anv_query.c +++ b/src/intel/vulkan/anv_query.c @@ -54,7 +54,7 @@ VkResult anv_CreateQueryPool( } slot_size = sizeof(struct anv_query_pool_slot); - pool = anv_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8, + pool = vk_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (pool == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -74,7 +74,7 @@ VkResult anv_CreateQueryPool( return VK_SUCCESS; fail: - anv_free2(&device->alloc, pAllocator, pool); + vk_free2(&device->alloc, pAllocator, pool); return result; } @@ -89,7 +89,7 @@ void anv_DestroyQueryPool( anv_gem_munmap(pool->bo.map, pool->bo.size); anv_gem_close(device, pool->bo.gem_handle); - anv_free2(&device->alloc, pAllocator, pool); + vk_free2(&device->alloc, pAllocator, pool); } VkResult anv_GetQueryPoolResults( diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c index 006944a7e25..e15d1a3e073 100644 --- a/src/intel/vulkan/anv_wsi.c +++ b/src/intel/vulkan/anv_wsi.c @@ -68,7 +68,7 @@ void anv_DestroySurfaceKHR( ANV_FROM_HANDLE(anv_instance, instance, _instance); ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface); - anv_free2(&instance->alloc, pAllocator, surface); + vk_free2(&instance->alloc, pAllocator, surface); } VkResult anv_GetPhysicalDeviceSurfaceSupportKHR( diff --git a/src/intel/vulkan/anv_wsi_wayland.c b/src/intel/vulkan/anv_wsi_wayland.c index 5b1a6759ac6..ad3a8038069 100644 --- a/src/intel/vulkan/anv_wsi_wayland.c +++ b/src/intel/vulkan/anv_wsi_wayland.c @@ -233,14 +233,14 @@ wsi_wl_display_destroy(struct wsi_wayland *wsi, struct wsi_wl_display *display) u_vector_finish(&display->formats); if (display->drm) wl_drm_destroy(display->drm); - anv_free(&wsi->physical_device->instance->alloc, display); + vk_free(&wsi->physical_device->instance->alloc, display); } static struct wsi_wl_display * wsi_wl_display_create(struct wsi_wayland *wsi, struct wl_display *wl_display) { struct wsi_wl_display *display = - anv_alloc(&wsi->physical_device->instance->alloc, sizeof(*display), 8, + vk_alloc(&wsi->physical_device->instance->alloc, sizeof(*display), 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!display) return NULL; @@ -442,7 +442,7 @@ VkResult anv_CreateWaylandSurfaceKHR( VkIcdSurfaceWayland *surface; - surface = anv_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8, + surface = vk_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (surface == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -728,7 +728,7 @@ wsi_wl_swapchain_destroy(struct anv_swapchain *anv_chain, wsi_wl_image_finish(chain, &chain->images[i], pAllocator); } - anv_free2(&chain->base.device->alloc, pAllocator, chain); + vk_free2(&chain->base.device->alloc, pAllocator, chain); return VK_SUCCESS; } @@ -760,7 +760,7 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, num_images = MAX2(num_images, 4); size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]); - chain = anv_alloc2(&device->alloc, pAllocator, size, 8, + chain = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (chain == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -825,7 +825,7 @@ anv_wl_init_wsi(struct anv_physical_device *device) struct wsi_wayland *wsi; VkResult result; - wsi = anv_alloc(&device->instance->alloc, sizeof(*wsi), 8, + wsi = vk_alloc(&device->instance->alloc, sizeof(*wsi), 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!wsi) { result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -867,7 +867,7 @@ fail_mutex: pthread_mutex_destroy(&wsi->mutex); fail_alloc: - anv_free(&device->instance->alloc, wsi); + vk_free(&device->instance->alloc, wsi); fail: device->wsi[VK_ICD_WSI_PLATFORM_WAYLAND] = NULL; @@ -885,6 +885,6 @@ anv_wl_finish_wsi(struct anv_physical_device *device) pthread_mutex_destroy(&wsi->mutex); - anv_free(&device->instance->alloc, wsi); + vk_free(&device->instance->alloc, wsi); } } diff --git a/src/intel/vulkan/anv_wsi_x11.c b/src/intel/vulkan/anv_wsi_x11.c index 57485060322..3b7ecf06381 100644 --- a/src/intel/vulkan/anv_wsi_x11.c +++ b/src/intel/vulkan/anv_wsi_x11.c @@ -53,7 +53,7 @@ wsi_x11_connection_create(struct anv_physical_device *device, xcb_query_extension_reply_t *dri3_reply, *pres_reply; struct wsi_x11_connection *wsi_conn = - anv_alloc(&device->instance->alloc, sizeof(*wsi_conn), 8, + vk_alloc(&device->instance->alloc, sizeof(*wsi_conn), 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!wsi_conn) return NULL; @@ -66,7 +66,7 @@ wsi_x11_connection_create(struct anv_physical_device *device, if (dri3_reply == NULL || pres_reply == NULL) { free(dri3_reply); free(pres_reply); - anv_free(&device->instance->alloc, wsi_conn); + vk_free(&device->instance->alloc, wsi_conn); return NULL; } @@ -83,7 +83,7 @@ static void wsi_x11_connection_destroy(struct anv_physical_device *device, struct wsi_x11_connection *conn) { - anv_free(&device->instance->alloc, conn); + vk_free(&device->instance->alloc, conn); } static struct wsi_x11_connection * @@ -438,7 +438,7 @@ VkResult anv_CreateXcbSurfaceKHR( VkIcdSurfaceXcb *surface; - surface = anv_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8, + surface = vk_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (surface == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -464,7 +464,7 @@ VkResult anv_CreateXlibSurfaceKHR( VkIcdSurfaceXlib *surface; - surface = anv_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8, + surface = vk_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (surface == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -800,7 +800,7 @@ x11_swapchain_destroy(struct anv_swapchain *anv_chain, xcb_unregister_for_special_event(chain->conn, chain->special_event); - anv_free2(&chain->base.device->alloc, pAllocator, chain); + vk_free2(&chain->base.device->alloc, pAllocator, chain); return VK_SUCCESS; } @@ -830,7 +830,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, num_images = MAX2(num_images, 4); size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]); - chain = anv_alloc2(&device->alloc, pAllocator, size, 8, + chain = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (chain == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -893,7 +893,7 @@ fail_init_images: fail_register: xcb_unregister_for_special_event(chain->conn, chain->special_event); - anv_free2(&device->alloc, pAllocator, chain); + vk_free2(&device->alloc, pAllocator, chain); return result; } @@ -904,7 +904,7 @@ anv_x11_init_wsi(struct anv_physical_device *device) struct wsi_x11 *wsi; VkResult result; - wsi = anv_alloc(&device->instance->alloc, sizeof(*wsi), 8, + wsi = vk_alloc(&device->instance->alloc, sizeof(*wsi), 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!wsi) { result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -944,7 +944,7 @@ anv_x11_init_wsi(struct anv_physical_device *device) fail_mutex: pthread_mutex_destroy(&wsi->mutex); fail_alloc: - anv_free(&device->instance->alloc, wsi); + vk_free(&device->instance->alloc, wsi); fail: device->wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL; device->wsi[VK_ICD_WSI_PLATFORM_XLIB] = NULL; @@ -963,6 +963,6 @@ anv_x11_finish_wsi(struct anv_physical_device *device) pthread_mutex_destroy(&wsi->mutex); - anv_free(&device->instance->alloc, wsi); + vk_free(&device->instance->alloc, wsi); } } diff --git a/src/intel/vulkan/gen7_pipeline.c b/src/intel/vulkan/gen7_pipeline.c index 90ce3fb527f..4ffb16cb730 100644 --- a/src/intel/vulkan/gen7_pipeline.c +++ b/src/intel/vulkan/gen7_pipeline.c @@ -53,7 +53,7 @@ genX(graphics_pipeline_create)( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); - pipeline = anv_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8, + pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (pipeline == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -61,7 +61,7 @@ genX(graphics_pipeline_create)( result = anv_pipeline_init(pipeline, device, cache, pCreateInfo, pAllocator); if (result != VK_SUCCESS) { - anv_free2(&device->alloc, pAllocator, pipeline); + vk_free2(&device->alloc, pAllocator, pipeline); return result; } diff --git a/src/intel/vulkan/gen8_pipeline.c b/src/intel/vulkan/gen8_pipeline.c index 28c0f890dee..6cf55f551b2 100644 --- a/src/intel/vulkan/gen8_pipeline.c +++ b/src/intel/vulkan/gen8_pipeline.c @@ -63,7 +63,7 @@ genX(graphics_pipeline_create)( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); - pipeline = anv_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8, + pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (pipeline == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -71,7 +71,7 @@ genX(graphics_pipeline_create)( result = anv_pipeline_init(pipeline, device, cache, pCreateInfo, pAllocator); if (result != VK_SUCCESS) { - anv_free2(&device->alloc, pAllocator, pipeline); + vk_free2(&device->alloc, pAllocator, pipeline); return result; } diff --git a/src/intel/vulkan/genX_pipeline.c b/src/intel/vulkan/genX_pipeline.c index 2a4dd8efe2e..2d5c62e2a9c 100644 --- a/src/intel/vulkan/genX_pipeline.c +++ b/src/intel/vulkan/genX_pipeline.c @@ -43,7 +43,7 @@ compute_pipeline_create( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO); - pipeline = anv_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8, + pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (pipeline == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); @@ -56,7 +56,7 @@ compute_pipeline_create( result = anv_reloc_list_init(&pipeline->batch_relocs, pAllocator ? pAllocator : &device->alloc); if (result != VK_SUCCESS) { - anv_free2(&device->alloc, pAllocator, pipeline); + vk_free2(&device->alloc, pAllocator, pipeline); return result; } pipeline->batch.next = pipeline->batch.start = pipeline->batch_data; @@ -82,7 +82,7 @@ compute_pipeline_create( pCreateInfo->stage.pName, pCreateInfo->stage.pSpecializationInfo); if (result != VK_SUCCESS) { - anv_free2(&device->alloc, pAllocator, pipeline); + vk_free2(&device->alloc, pAllocator, pipeline); return result; } diff --git a/src/intel/vulkan/genX_state.c b/src/intel/vulkan/genX_state.c index a6d405dac5d..be1bd785bce 100644 --- a/src/intel/vulkan/genX_state.c +++ b/src/intel/vulkan/genX_state.c @@ -159,7 +159,7 @@ VkResult genX(CreateSampler)( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO); - sampler = anv_alloc2(&device->alloc, pAllocator, sizeof(*sampler), 8, + sampler = vk_alloc2(&device->alloc, pAllocator, sizeof(*sampler), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!sampler) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); -- 2.30.2