Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 3 | * |
| 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 28 | #include "dev.h" |
| 29 | #include "mem.h" |
| 30 | #include "event.h" |
| 31 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 32 | static VkResult event_map(struct intel_event *event, uint32_t **ptr_ret) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 33 | { |
| 34 | void *ptr; |
| 35 | |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 36 | /* |
| 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 Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | return VK_ERROR_MEMORY_MAP_FAILED; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 44 | |
| 45 | *ptr_ret = (uint32_t *) ((uint8_t *) ptr + event->obj.offset); |
| 46 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 47 | return VK_SUCCESS; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void event_unmap(struct intel_event *event) |
| 51 | { |
| 52 | intel_mem_unmap(event->obj.mem); |
| 53 | } |
| 54 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 55 | static VkResult event_write(struct intel_event *event, uint32_t val) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 56 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 57 | VkResult ret; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 58 | uint32_t *ptr; |
| 59 | |
| 60 | ret = event_map(event, &ptr); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 61 | if (ret == VK_SUCCESS) { |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 62 | *ptr = val; |
| 63 | event_unmap(event); |
| 64 | } |
| 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 69 | static VkResult event_read(struct intel_event *event, uint32_t *val) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 70 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 71 | VkResult ret; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 72 | uint32_t *ptr; |
| 73 | |
| 74 | ret = event_map(event, &ptr); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 75 | if (ret == VK_SUCCESS) { |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 76 | *val = *ptr; |
| 77 | event_unmap(event); |
| 78 | } |
| 79 | |
| 80 | return ret; |
| 81 | } |
| 82 | |
Chia-I Wu | 26f0bd0 | 2014-08-07 10:38:40 +0800 | [diff] [blame] | 83 | static void event_destroy(struct intel_obj *obj) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 84 | { |
| 85 | struct intel_event *event = intel_event_from_obj(obj); |
| 86 | |
| 87 | intel_event_destroy(event); |
| 88 | } |
| 89 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 90 | VkResult intel_event_create(struct intel_dev *dev, |
| 91 | const VkEventCreateInfo *info, |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 92 | struct intel_event **event_ret) |
| 93 | { |
| 94 | struct intel_event *event; |
Tony Barbour | 2094dc7 | 2015-07-09 15:26:32 -0600 | [diff] [blame] | 95 | VkMemoryAllocInfo mem_reqs; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 96 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 97 | event = (struct intel_event *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 98 | sizeof(*event), dev->base.dbg, VK_OBJECT_TYPE_EVENT, info, 0); |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 99 | if (!event) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 100 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 101 | |
Tony Barbour | 2094dc7 | 2015-07-09 15:26:32 -0600 | [diff] [blame] | 102 | 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 Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 108 | event->obj.destroy = event_destroy; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 109 | |
| 110 | *event_ret = event; |
| 111 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 112 | return VK_SUCCESS; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void intel_event_destroy(struct intel_event *event) |
| 116 | { |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 117 | intel_base_destroy(&event->obj.base); |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 118 | } |
| 119 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 120 | VkResult intel_event_set(struct intel_event *event) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 121 | { |
| 122 | return event_write(event, 1); |
| 123 | } |
| 124 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 125 | VkResult intel_event_reset(struct intel_event *event) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 126 | { |
| 127 | return event_write(event, 0); |
| 128 | } |
| 129 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 130 | VkResult intel_event_get_status(struct intel_event *event) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 131 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 132 | VkResult ret; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 133 | uint32_t val; |
| 134 | |
| 135 | ret = event_read(event, &val); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 136 | if (ret != VK_SUCCESS) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 137 | return ret; |
| 138 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 139 | return (val) ? VK_EVENT_SET : VK_EVENT_RESET; |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 140 | } |
| 141 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 142 | ICD_EXPORT VkResult VKAPI vkCreateEvent( |
| 143 | VkDevice device, |
| 144 | const VkEventCreateInfo* pCreateInfo, |
| 145 | VkEvent* pEvent) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 146 | { |
| 147 | struct intel_dev *dev = intel_dev(device); |
| 148 | |
| 149 | return intel_event_create(dev, pCreateInfo, |
| 150 | (struct intel_event **) pEvent); |
| 151 | } |
| 152 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 153 | ICD_EXPORT void VKAPI vkDestroyEvent( |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 154 | VkDevice device, |
| 155 | VkEvent event) |
| 156 | |
| 157 | { |
| 158 | struct intel_obj *obj = intel_obj(event.handle); |
| 159 | |
Tony Barbour | 2094dc7 | 2015-07-09 15:26:32 -0600 | [diff] [blame] | 160 | intel_mem_free(obj->mem); |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 161 | obj->destroy(obj); |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 162 | } |
| 163 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 164 | ICD_EXPORT VkResult VKAPI vkGetEventStatus( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 165 | VkDevice device, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 166 | VkEvent event_) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 167 | { |
| 168 | struct intel_event *event = intel_event(event_); |
| 169 | |
| 170 | return intel_event_get_status(event); |
| 171 | } |
| 172 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 173 | ICD_EXPORT VkResult VKAPI vkSetEvent( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 174 | VkDevice device, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 175 | VkEvent event_) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 176 | { |
| 177 | struct intel_event *event = intel_event(event_); |
| 178 | |
| 179 | return intel_event_set(event); |
| 180 | } |
| 181 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 182 | ICD_EXPORT VkResult VKAPI vkResetEvent( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 183 | VkDevice device, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 184 | VkEvent event_) |
Chia-I Wu | 9737a10 | 2014-08-07 07:59:51 +0800 | [diff] [blame] | 185 | { |
| 186 | struct intel_event *event = intel_event(event_); |
| 187 | |
| 188 | return intel_event_reset(event); |
| 189 | } |