blob: 5449f5987c8c05dd10798964dfe531d70f02ffdc [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) {
Tony Barbour8205d902015-04-16 15:59:00 -060099 case VK_OBJECT_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;
Jeremy Hayesd02809a2015-04-15 14:17:56 -0600109 mem_req->memPropsAllowed = INTEL_MEMORY_PROPERTY_ALL;
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800110 }
111 break;
112 default:
113 ret = intel_base_get_info(base, type, size, data);
114 break;
115 }
116
117 return ret;
118}
119
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600120VkResult intel_event_create(struct intel_dev *dev,
121 const VkEventCreateInfo *info,
Chia-I Wu9737a102014-08-07 07:59:51 +0800122 struct intel_event **event_ret)
123{
124 struct intel_event *event;
Chia-I Wu9737a102014-08-07 07:59:51 +0800125
Chia-I Wu545c2e12015-02-22 13:19:54 +0800126 event = (struct intel_event *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600127 sizeof(*event), dev->base.dbg, VK_DBG_OBJECT_EVENT, info, 0);
Chia-I Wu9737a102014-08-07 07:59:51 +0800128 if (!event)
Tony Barbour8205d902015-04-16 15:59:00 -0600129 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wu9737a102014-08-07 07:59:51 +0800130
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800131 event->obj.base.get_info = event_get_info;
Chia-I Wubbf2c932014-08-07 12:20:08 +0800132 event->obj.destroy = event_destroy;
Chia-I Wu9737a102014-08-07 07:59:51 +0800133
134 *event_ret = event;
135
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136 return VK_SUCCESS;
Chia-I Wu9737a102014-08-07 07:59:51 +0800137}
138
139void intel_event_destroy(struct intel_event *event)
140{
Chia-I Wubbf2c932014-08-07 12:20:08 +0800141 intel_base_destroy(&event->obj.base);
Chia-I Wu9737a102014-08-07 07:59:51 +0800142}
143
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600144VkResult intel_event_set(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800145{
146 return event_write(event, 1);
147}
148
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600149VkResult intel_event_reset(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800150{
151 return event_write(event, 0);
152}
153
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600154VkResult intel_event_get_status(struct intel_event *event)
Chia-I Wu9737a102014-08-07 07:59:51 +0800155{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600156 VkResult ret;
Chia-I Wu9737a102014-08-07 07:59:51 +0800157 uint32_t val;
158
159 ret = event_read(event, &val);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600160 if (ret != VK_SUCCESS)
Chia-I Wu9737a102014-08-07 07:59:51 +0800161 return ret;
162
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600163 return (val) ? VK_EVENT_SET : VK_EVENT_RESET;
Chia-I Wu9737a102014-08-07 07:59:51 +0800164}
165
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600166ICD_EXPORT VkResult VKAPI vkCreateEvent(
167 VkDevice device,
168 const VkEventCreateInfo* pCreateInfo,
169 VkEvent* pEvent)
Chia-I Wu9737a102014-08-07 07:59:51 +0800170{
171 struct intel_dev *dev = intel_dev(device);
172
173 return intel_event_create(dev, pCreateInfo,
174 (struct intel_event **) pEvent);
175}
176
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600177ICD_EXPORT VkResult VKAPI vkGetEventStatus(
178 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800179{
180 struct intel_event *event = intel_event(event_);
181
182 return intel_event_get_status(event);
183}
184
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600185ICD_EXPORT VkResult VKAPI vkSetEvent(
186 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800187{
188 struct intel_event *event = intel_event(event_);
189
190 return intel_event_set(event);
191}
192
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600193ICD_EXPORT VkResult VKAPI vkResetEvent(
194 VkEvent event_)
Chia-I Wu9737a102014-08-07 07:59:51 +0800195{
196 struct intel_event *event = intel_event(event_);
197
198 return intel_event_reset(event);
199}