From ae4be2d7ae402d9321fee7dce3d4bcd64141d6cb Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 4 Oct 2021 13:40:44 +0200 Subject: [PATCH] radv: fix vk_object_base_init/finish for internal device memory objects Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/amd/vulkan/radv_device.c | 23 +++++++++++++++++++---- src/amd/vulkan/radv_meta_bufimage.c | 6 +++++- src/amd/vulkan/radv_private.h | 4 ++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 982603172dd..e0b4baa7061 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -5045,6 +5045,22 @@ radv_get_memory_fd(struct radv_device *device, struct radv_device_memory *memory return device->ws->buffer_get_fd(device->ws, memory->bo, pFD); } +void +radv_device_memory_init(struct radv_device_memory *mem, struct radv_device *device, + struct radeon_winsys_bo *bo) +{ + memset(mem, 0, sizeof(*mem)); + vk_object_base_init(&device->vk, &mem->base, VK_OBJECT_TYPE_DEVICE_MEMORY); + + mem->bo = bo; +} + +void +radv_device_memory_finish(struct radv_device_memory *mem) +{ + vk_object_base_finish(&mem->base); +} + void radv_free_memory(struct radv_device *device, const VkAllocationCallbacks *pAllocator, struct radv_device_memory *mem) @@ -5070,7 +5086,7 @@ radv_free_memory(struct radv_device *device, const VkAllocationCallbacks *pAlloc mem->bo = NULL; } - vk_object_base_finish(&mem->base); + radv_device_memory_finish(mem); vk_free2(&device->vk.alloc, pAllocator, mem); } @@ -5108,11 +5124,11 @@ radv_alloc_memory(struct radv_device *device, const VkMemoryAllocateInfo *pAlloc } mem = - vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*mem), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*mem), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (mem == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); - vk_object_base_init(&device->vk, &mem->base, VK_OBJECT_TYPE_DEVICE_MEMORY); + radv_device_memory_init(mem, device, NULL); if (wsi_info) { if(wsi_info->implicit_sync) @@ -5153,7 +5169,6 @@ radv_alloc_memory(struct radv_device *device, const VkMemoryAllocateInfo *pAlloc (int)(priority_float * RADV_BO_PRIORITY_APPLICATION_MAX)); mem->user_ptr = NULL; - mem->bo = NULL; #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER mem->android_hardware_buffer = NULL; diff --git a/src/amd/vulkan/radv_meta_bufimage.c b/src/amd/vulkan/radv_meta_bufimage.c index ce13aeea708..502d1e9b9a5 100644 --- a/src/amd/vulkan/radv_meta_bufimage.c +++ b/src/amd/vulkan/radv_meta_bufimage.c @@ -1334,7 +1334,9 @@ create_buffer_from_image(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_bl VkBufferUsageFlagBits usage, VkBuffer *buffer) { struct radv_device *device = cmd_buffer->device; - struct radv_device_memory mem = {.bo = surf->image->bo}; + struct radv_device_memory mem; + + radv_device_memory_init(&mem, device, surf->image->bo); radv_CreateBuffer(radv_device_to_handle(device), &(VkBufferCreateInfo){ @@ -1353,6 +1355,8 @@ create_buffer_from_image(struct radv_cmd_buffer *cmd_buffer, struct radv_meta_bl .memory = radv_device_memory_to_handle(&mem), .memoryOffset = surf->image->offset, }}); + + radv_device_memory_finish(&mem); } static void diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index d9fb16d5e31..9e68cc24e97 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -867,6 +867,10 @@ struct radv_device_memory { #endif }; +void radv_device_memory_init(struct radv_device_memory *mem, struct radv_device *device, + struct radeon_winsys_bo *bo); +void radv_device_memory_finish(struct radv_device_memory *mem); + struct radv_descriptor_range { uint64_t va; uint32_t size;