From 369703774cfa304f4881e0e379eb02ed98933dde Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 22 Apr 2020 12:23:24 -0500 Subject: [PATCH] anv: Allocate CPU-side memory for events As discrete graphics looms, we really need to stop storing CPU data structures in GPU memory. One of the most egregious instances of this was VkEvent where we had a CPU data structure living inside a dynamic state pool allocation. Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_device.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index cf5fc4c5acf..fd3b292dbbd 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -4078,16 +4078,18 @@ VkResult anv_CreateEvent( VkEvent* pEvent) { ANV_FROM_HANDLE(anv_device, device, _device); - struct anv_state state; struct anv_event *event; assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO); - state = anv_state_pool_alloc(&device->dynamic_state_pool, - sizeof(*event), 8); - event = state.map; - event->state = state; - event->semaphore = VK_EVENT_RESET; + event = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*event), 8, + VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + if (event == NULL) + return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); + + event->state = anv_state_pool_alloc(&device->dynamic_state_pool, + sizeof(uint64_t), 8); + *(uint64_t *)event->state.map = VK_EVENT_RESET; *pEvent = anv_event_to_handle(event); @@ -4106,6 +4108,7 @@ void anv_DestroyEvent( return; anv_state_pool_free(&device->dynamic_state_pool, event->state); + vk_free2(&device->vk.alloc, pAllocator, event); } VkResult anv_GetEventStatus( @@ -4118,7 +4121,7 @@ VkResult anv_GetEventStatus( if (anv_device_is_lost(device)) return VK_ERROR_DEVICE_LOST; - return event->semaphore; + return *(uint64_t *)event->state.map; } VkResult anv_SetEvent( @@ -4127,7 +4130,7 @@ VkResult anv_SetEvent( { ANV_FROM_HANDLE(anv_event, event, _event); - event->semaphore = VK_EVENT_SET; + *(uint64_t *)event->state.map = VK_EVENT_SET; return VK_SUCCESS; } @@ -4138,7 +4141,7 @@ VkResult anv_ResetEvent( { ANV_FROM_HANDLE(anv_event, event, _event); - event->semaphore = VK_EVENT_RESET; + *(uint64_t *)event->state.map = VK_EVENT_RESET; return VK_SUCCESS; } -- 2.30.2