1 /* Copyright © 2024 Intel Corporation
2 * SPDX-License-Identifier: MIT
3 */
4
5 #include "anv_private.h"
6
anv_CreateEvent(VkDevice _device,const VkEventCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkEvent * pEvent)7 VkResult anv_CreateEvent(
8 VkDevice _device,
9 const VkEventCreateInfo* pCreateInfo,
10 const VkAllocationCallbacks* pAllocator,
11 VkEvent* pEvent)
12 {
13 ANV_FROM_HANDLE(anv_device, device, _device);
14 struct anv_event *event;
15
16 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO);
17
18 event = vk_object_alloc(&device->vk, pAllocator, sizeof(*event),
19 VK_OBJECT_TYPE_EVENT);
20 if (event == NULL)
21 return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
22
23 event->state = anv_state_pool_alloc(&device->dynamic_state_pool,
24 sizeof(uint64_t), 8);
25 *(uint64_t *)event->state.map = VK_EVENT_RESET;
26
27 ANV_RMV(event_create, device, event, pCreateInfo->flags, false);
28
29 *pEvent = anv_event_to_handle(event);
30
31 return VK_SUCCESS;
32 }
33
anv_DestroyEvent(VkDevice _device,VkEvent _event,const VkAllocationCallbacks * pAllocator)34 void anv_DestroyEvent(
35 VkDevice _device,
36 VkEvent _event,
37 const VkAllocationCallbacks* pAllocator)
38 {
39 ANV_FROM_HANDLE(anv_device, device, _device);
40 ANV_FROM_HANDLE(anv_event, event, _event);
41
42 if (!event)
43 return;
44
45 ANV_RMV(resource_destroy, device, event);
46
47 anv_state_pool_free(&device->dynamic_state_pool, event->state);
48
49 vk_object_free(&device->vk, pAllocator, event);
50 }
51
anv_GetEventStatus(VkDevice _device,VkEvent _event)52 VkResult anv_GetEventStatus(
53 VkDevice _device,
54 VkEvent _event)
55 {
56 ANV_FROM_HANDLE(anv_device, device, _device);
57 ANV_FROM_HANDLE(anv_event, event, _event);
58
59 if (vk_device_is_lost(&device->vk))
60 return VK_ERROR_DEVICE_LOST;
61
62 return *(uint64_t *)event->state.map;
63 }
64
anv_SetEvent(VkDevice _device,VkEvent _event)65 VkResult anv_SetEvent(
66 VkDevice _device,
67 VkEvent _event)
68 {
69 ANV_FROM_HANDLE(anv_event, event, _event);
70
71 *(uint64_t *)event->state.map = VK_EVENT_SET;
72
73 return VK_SUCCESS;
74 }
75
anv_ResetEvent(VkDevice _device,VkEvent _event)76 VkResult anv_ResetEvent(
77 VkDevice _device,
78 VkEvent _event)
79 {
80 ANV_FROM_HANDLE(anv_event, event, _event);
81
82 *(uint64_t *)event->state.map = VK_EVENT_RESET;
83
84 return VK_SUCCESS;
85 }
86