blob: 05b917ea4ffeba4b82b176d0d9ea0f0a6302030b [file] [log] [blame]
Chia-I Wu9737a102014-08-07 07:59:51 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wu9737a102014-08-07 07:59:51 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wu9737a102014-08-07 07:59:51 +080026 */
27
Chia-I Wu9737a102014-08-07 07:59:51 +080028#include "dev.h"
29#include "mem.h"
30#include "event.h"
31
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060032static VkResult event_map(struct intel_event *event, uint32_t **ptr_ret)
Chia-I Wu9737a102014-08-07 07:59:51 +080033{
34 void *ptr;
35
Chia-I Wu9737a102014-08-07 07:59:51 +080036 /*
37 * This is an unsynchronous mapping. It doesn't look like we want a
38 * synchronous mapping. But it is also unclear what would happen when GPU
39 * writes to it at the same time. We need atomicy here.
40 */
41 ptr = intel_mem_map(event->obj.mem, 0);
42 if (!ptr)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060043 return VK_ERROR_MEMORY_MAP_FAILED;
Chia-I Wu9737a102014-08-07 07:59:51 +080044
45 *ptr_ret = (uint32_t *) ((uint8_t *) ptr + event->obj.offset);
46
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060047 return VK_SUCCESS;
Chia-I Wu9737a102014-08-07 07:59:51 +080048}
49
50static void event_unmap(struct intel_event *event)
51{
52 intel_mem_unmap(event->obj.mem);
53}
54
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060055static VkResult event_write(struct intel_event *event, uint32_t val)
Chia-I Wu9737a102014-08-07 07:59:51 +080056{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060057 VkResult ret;
Chia-I Wu9737a102014-08-07 07:59:51 +080058 uint32_t *ptr;
59
60 ret = event_map(event, &ptr);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060061 if (ret == VK_SUCCESS) {
Chia-I Wu9737a102014-08-07 07:59:51 +080062 *ptr = val;
63 event_unmap(event);
64 }
65
66 return ret;
67}
68
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060069static VkResult event_read(struct intel_event *event, uint32_t *val)
Chia-I Wu9737a102014-08-07 07:59:51 +080070{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060071 VkResult ret;
Chia-I Wu9737a102014-08-07 07:59:51 +080072 uint32_t *ptr;
73
74 ret = event_map(event, &ptr);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060075 if (ret == VK_SUCCESS) {
Chia-I Wu9737a102014-08-07 07:59:51 +080076 *val = *ptr;
77 event_unmap(event);
78 }
79
80 return ret;
81}
82
Chia-I Wu26f0bd02014-08-07 10:38:40 +080083static void event_destroy(struct intel_obj *obj)
Chia-I Wu9737a102014-08-07 07:59:51 +080084{
85 struct intel_event *event = intel_event_from_obj(obj);
86
87 intel_event_destroy(event);
88}
89
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060090VkResult intel_event_create(struct intel_dev *dev,
91 const VkEventCreateInfo *info,
Chia-I Wu9737a102014-08-07 07:59:51 +080092 struct intel_event **event_ret)
93{
94 struct intel_event *event;
Tony Barbour2094dc72015-07-09 15:26:32 -060095 VkMemoryAllocInfo mem_reqs;
Chia-I Wu9737a102014-08-07 07:59:51 +080096
Chia-I Wu545c2e12015-02-22 13:19:54 +080097 event = (struct intel_event *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060098 sizeof(*event), dev->base.dbg, VK_OBJECT_TYPE_EVENT, info, 0);
Chia-I Wu9737a102014-08-07 07:59:51 +080099 if (!event)
Tony Barbour8205d902015-04-16 15:59:00 -0600100 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu9737a102014-08-07 07:59:51 +0800101
Tony Barbour2094dc72015-07-09 15:26:32 -0600102 mem_reqs.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
103 mem_reqs.allocationSize = 4; // We know allocation is page alignned
104 mem_reqs.pNext = NULL;
105 mem_reqs.memoryTypeIndex = 0;
106 intel_mem_alloc(dev, &mem_reqs, &event->obj.mem);
107
Chia-I Wubbf2c932014-08-07 12:20:08 +0800108 event->obj.destroy = event_destroy;
Chia-I Wu9737a102014-08-07 07:59:51 +0800109
110 *event_ret = event;
111
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600112 return VK_SUCCESS;
Chia-I Wu9737a102014-08-07 07:59:51 +0800113}
114
115void intel_event_destroy(struct intel_event *event)
116{
Chia-I Wubbf2c932014-08-07 12:20:08 +0800117 intel_base_destroy(&event->obj.base);
Chia-I Wu9737a102014-08-07 07:59:51 +0800118}
119
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600120VkResult intel_event_set(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800121{
122 return event_write(event, 1);
123}
124
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600125VkResult intel_event_reset(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800126{
127 return event_write(event, 0);
128}
129
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600130VkResult intel_event_get_status(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800131{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600132 VkResult ret;
Chia-I Wu9737a102014-08-07 07:59:51 +0800133 uint32_t val;
134
135 ret = event_read(event, &val);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136 if (ret != VK_SUCCESS)
Chia-I Wu9737a102014-08-07 07:59:51 +0800137 return ret;
138
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600139 return (val) ? VK_EVENT_SET : VK_EVENT_RESET;
Chia-I Wu9737a102014-08-07 07:59:51 +0800140}
141
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600142ICD_EXPORT VkResult VKAPI vkCreateEvent(
143 VkDevice device,
144 const VkEventCreateInfo* pCreateInfo,
145 VkEvent* pEvent)
Chia-I Wu9737a102014-08-07 07:59:51 +0800146{
147 struct intel_dev *dev = intel_dev(device);
148
149 return intel_event_create(dev, pCreateInfo,
150 (struct intel_event **) pEvent);
151}
152
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600153ICD_EXPORT void VKAPI vkDestroyEvent(
Tony Barbourde4124d2015-07-03 10:33:54 -0600154 VkDevice device,
155 VkEvent event)
156
157 {
158 struct intel_obj *obj = intel_obj(event.handle);
159
Tony Barbour2094dc72015-07-09 15:26:32 -0600160 intel_mem_free(obj->mem);
Tony Barbourde4124d2015-07-03 10:33:54 -0600161 obj->destroy(obj);
Tony Barbourde4124d2015-07-03 10:33:54 -0600162 }
163
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600164ICD_EXPORT VkResult VKAPI vkGetEventStatus(
Mike Stroyan230e6252015-04-17 12:36:38 -0600165 VkDevice device,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600166 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800167{
168 struct intel_event *event = intel_event(event_);
169
170 return intel_event_get_status(event);
171}
172
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600173ICD_EXPORT VkResult VKAPI vkSetEvent(
Mike Stroyan230e6252015-04-17 12:36:38 -0600174 VkDevice device,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600175 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800176{
177 struct intel_event *event = intel_event(event_);
178
179 return intel_event_set(event);
180}
181
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600182ICD_EXPORT VkResult VKAPI vkResetEvent(
Mike Stroyan230e6252015-04-17 12:36:38 -0600183 VkDevice device,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600184 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800185{
186 struct intel_event *event = intel_event(event_);
187
188 return intel_event_reset(event);
189}