blob: 293dd9f8d2657faf5b6e21e7767990b61b371e5e [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
36 if (!event->obj.mem)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060037 return VK_ERROR_MEMORY_NOT_BOUND;
Chia-I Wu9737a102014-08-07 07:59:51 +080038
39 /*
40 * This is an unsynchronous mapping. It doesn't look like we want a
41 * synchronous mapping. But it is also unclear what would happen when GPU
42 * writes to it at the same time. We need atomicy here.
43 */
44 ptr = intel_mem_map(event->obj.mem, 0);
45 if (!ptr)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060046 return VK_ERROR_MEMORY_MAP_FAILED;
Chia-I Wu9737a102014-08-07 07:59:51 +080047
48 *ptr_ret = (uint32_t *) ((uint8_t *) ptr + event->obj.offset);
49
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060050 return VK_SUCCESS;
Chia-I Wu9737a102014-08-07 07:59:51 +080051}
52
53static void event_unmap(struct intel_event *event)
54{
55 intel_mem_unmap(event->obj.mem);
56}
57
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060058static VkResult event_write(struct intel_event *event, uint32_t val)
Chia-I Wu9737a102014-08-07 07:59:51 +080059{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060060 VkResult ret;
Chia-I Wu9737a102014-08-07 07:59:51 +080061 uint32_t *ptr;
62
63 ret = event_map(event, &ptr);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060064 if (ret == VK_SUCCESS) {
Chia-I Wu9737a102014-08-07 07:59:51 +080065 *ptr = val;
66 event_unmap(event);
67 }
68
69 return ret;
70}
71
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060072static VkResult event_read(struct intel_event *event, uint32_t *val)
Chia-I Wu9737a102014-08-07 07:59:51 +080073{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060074 VkResult ret;
Chia-I Wu9737a102014-08-07 07:59:51 +080075 uint32_t *ptr;
76
77 ret = event_map(event, &ptr);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060078 if (ret == VK_SUCCESS) {
Chia-I Wu9737a102014-08-07 07:59:51 +080079 *val = *ptr;
80 event_unmap(event);
81 }
82
83 return ret;
84}
85
Chia-I Wu26f0bd02014-08-07 10:38:40 +080086static void event_destroy(struct intel_obj *obj)
Chia-I Wu9737a102014-08-07 07:59:51 +080087{
88 struct intel_event *event = intel_event_from_obj(obj);
89
90 intel_event_destroy(event);
91}
92
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060093static VkResult event_get_info(struct intel_base *base, int type,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060094 size_t *size, void *data)
Chia-I Wu26f0bd02014-08-07 10:38:40 +080095{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060096 VkResult ret = VK_SUCCESS;
Chia-I Wu26f0bd02014-08-07 10:38:40 +080097
98 switch (type) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060099 case VK_INFO_TYPE_MEMORY_REQUIREMENTS:
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800100 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600101 VkMemoryRequirements *mem_req = data;
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800102
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600103 *size = sizeof(VkMemoryRequirements);
Jon Ashburn408daec2014-12-05 09:23:52 -0700104 if (data == NULL)
105 return ret;
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800106 /* use dword aligned to 64-byte boundaries */
107 mem_req->size = 4;
108 mem_req->alignment = 64;
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800109 }
110 break;
111 default:
112 ret = intel_base_get_info(base, type, size, data);
113 break;
114 }
115
116 return ret;
117}
118
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600119VkResult intel_event_create(struct intel_dev *dev,
120 const VkEventCreateInfo *info,
Chia-I Wu9737a102014-08-07 07:59:51 +0800121 struct intel_event **event_ret)
122{
123 struct intel_event *event;
Chia-I Wu9737a102014-08-07 07:59:51 +0800124
Chia-I Wu545c2e12015-02-22 13:19:54 +0800125 event = (struct intel_event *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600126 sizeof(*event), dev->base.dbg, VK_DBG_OBJECT_EVENT, info, 0);
Chia-I Wu9737a102014-08-07 07:59:51 +0800127 if (!event)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600128 return VK_ERROR_OUT_OF_MEMORY;
Chia-I Wu9737a102014-08-07 07:59:51 +0800129
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800130 event->obj.base.get_info = event_get_info;
Chia-I Wubbf2c932014-08-07 12:20:08 +0800131 event->obj.destroy = event_destroy;
Chia-I Wu9737a102014-08-07 07:59:51 +0800132
133 *event_ret = event;
134
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600135 return VK_SUCCESS;
Chia-I Wu9737a102014-08-07 07:59:51 +0800136}
137
138void intel_event_destroy(struct intel_event *event)
139{
Chia-I Wubbf2c932014-08-07 12:20:08 +0800140 intel_base_destroy(&event->obj.base);
Chia-I Wu9737a102014-08-07 07:59:51 +0800141}
142
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600143VkResult intel_event_set(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800144{
145 return event_write(event, 1);
146}
147
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600148VkResult intel_event_reset(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800149{
150 return event_write(event, 0);
151}
152
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600153VkResult intel_event_get_status(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800154{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600155 VkResult ret;
Chia-I Wu9737a102014-08-07 07:59:51 +0800156 uint32_t val;
157
158 ret = event_read(event, &val);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600159 if (ret != VK_SUCCESS)
Chia-I Wu9737a102014-08-07 07:59:51 +0800160 return ret;
161
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600162 return (val) ? VK_EVENT_SET : VK_EVENT_RESET;
Chia-I Wu9737a102014-08-07 07:59:51 +0800163}
164
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600165ICD_EXPORT VkResult VKAPI vkCreateEvent(
166 VkDevice device,
167 const VkEventCreateInfo* pCreateInfo,
168 VkEvent* pEvent)
Chia-I Wu9737a102014-08-07 07:59:51 +0800169{
170 struct intel_dev *dev = intel_dev(device);
171
172 return intel_event_create(dev, pCreateInfo,
173 (struct intel_event **) pEvent);
174}
175
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600176ICD_EXPORT VkResult VKAPI vkGetEventStatus(
177 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800178{
179 struct intel_event *event = intel_event(event_);
180
181 return intel_event_get_status(event);
182}
183
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600184ICD_EXPORT VkResult VKAPI vkSetEvent(
185 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800186{
187 struct intel_event *event = intel_event(event_);
188
189 return intel_event_set(event);
190}
191
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600192ICD_EXPORT VkResult VKAPI vkResetEvent(
193 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800194{
195 struct intel_event *event = intel_event(event_);
196
197 return intel_event_reset(event);
198}