Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +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 | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include "kmd/winsys.h" |
Chia-I Wu | 34f4518 | 2014-08-19 14:02:59 +0800 | [diff] [blame] | 29 | #include "cmd.h" |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 30 | #include "dev.h" |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 31 | #include "wsi.h" |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 32 | #include "fence.h" |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 33 | #include "instance.h" |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 34 | |
Chia-I Wu | 26f0bd0 | 2014-08-07 10:38:40 +0800 | [diff] [blame] | 35 | static void fence_destroy(struct intel_obj *obj) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 36 | { |
| 37 | struct intel_fence *fence = intel_fence_from_obj(obj); |
| 38 | |
| 39 | intel_fence_destroy(fence); |
| 40 | } |
| 41 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 42 | VkResult intel_fence_create(struct intel_dev *dev, |
| 43 | const VkFenceCreateInfo *info, |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 44 | struct intel_fence **fence_ret) |
| 45 | { |
| 46 | struct intel_fence *fence; |
| 47 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 48 | fence = (struct intel_fence *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 49 | sizeof(*fence), dev->base.dbg, VK_OBJECT_TYPE_FENCE, info, 0); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 50 | if (!fence) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 51 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 52 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 53 | if (dev->base.handle.instance->global_exts[INTEL_GLOBAL_EXT_WSI_SWAPCHAIN]) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 54 | VkResult ret = intel_wsi_fence_init(fence); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 55 | if (ret != VK_SUCCESS) { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 56 | intel_fence_destroy(fence); |
| 57 | return ret; |
| 58 | } |
| 59 | } |
| 60 | |
Chia-I Wu | 26f0bd0 | 2014-08-07 10:38:40 +0800 | [diff] [blame] | 61 | fence->obj.destroy = fence_destroy; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 62 | |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 63 | *fence_ret = fence; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 64 | fence->signaled = (info->flags & VK_FENCE_CREATE_SIGNALED_BIT); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 65 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 66 | return VK_SUCCESS; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void intel_fence_destroy(struct intel_fence *fence) |
| 70 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 71 | if (fence->wsi_data) |
| 72 | intel_wsi_fence_cleanup(fence); |
| 73 | |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 74 | intel_bo_unref(fence->seqno_bo); |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 75 | |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 76 | intel_base_destroy(&fence->obj.base); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 77 | } |
| 78 | |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 79 | void intel_fence_copy(struct intel_fence *fence, |
| 80 | const struct intel_fence *src) |
| 81 | { |
| 82 | intel_wsi_fence_copy(fence, src); |
| 83 | intel_fence_set_seqno(fence, src->seqno_bo); |
| 84 | } |
| 85 | |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 86 | void intel_fence_set_seqno(struct intel_fence *fence, |
| 87 | struct intel_bo *seqno_bo) |
| 88 | { |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 89 | intel_bo_unref(fence->seqno_bo); |
| 90 | fence->seqno_bo = intel_bo_ref(seqno_bo); |
Mark Lobodzinski | ebe814d | 2015-04-07 16:07:57 -0500 | [diff] [blame] | 91 | |
| 92 | fence->signaled = false; |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 95 | VkResult intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 96 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 97 | VkResult ret; |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 98 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 99 | ret = intel_wsi_fence_wait(fence, timeout_ns); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 100 | if (ret != VK_SUCCESS) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 101 | return ret; |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 102 | |
Mark Lobodzinski | ebe814d | 2015-04-07 16:07:57 -0500 | [diff] [blame] | 103 | if (fence->signaled) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 104 | return VK_SUCCESS; |
Mark Lobodzinski | ebe814d | 2015-04-07 16:07:57 -0500 | [diff] [blame] | 105 | } |
| 106 | |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 107 | if (fence->seqno_bo) { |
Mark Lobodzinski | ebe814d | 2015-04-07 16:07:57 -0500 | [diff] [blame] | 108 | ret = (intel_bo_wait(fence->seqno_bo, timeout_ns)) ? |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 109 | VK_NOT_READY : VK_SUCCESS; |
| 110 | if (ret == VK_SUCCESS) { |
Mark Lobodzinski | ebe814d | 2015-04-07 16:07:57 -0500 | [diff] [blame] | 111 | fence->signaled = true; |
| 112 | } |
| 113 | return ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 114 | } |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 115 | |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 116 | assert(0 && "Invalid fence status"); |
| 117 | return VK_SUCCESS; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 118 | } |
| 119 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 120 | ICD_EXPORT VkResult VKAPI vkCreateFence( |
| 121 | VkDevice device, |
| 122 | const VkFenceCreateInfo* pCreateInfo, |
| 123 | VkFence* pFence) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 124 | { |
| 125 | struct intel_dev *dev = intel_dev(device); |
| 126 | |
| 127 | return intel_fence_create(dev, pCreateInfo, |
| 128 | (struct intel_fence **) pFence); |
| 129 | } |
| 130 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 131 | ICD_EXPORT void VKAPI vkDestroyFence( |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 132 | VkDevice device, |
| 133 | VkFence fence) |
| 134 | |
| 135 | { |
| 136 | struct intel_obj *obj = intel_obj(fence.handle); |
| 137 | |
| 138 | obj->destroy(obj); |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 139 | } |
| 140 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 141 | ICD_EXPORT VkResult VKAPI vkGetFenceStatus( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 142 | VkDevice device, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 143 | VkFence fence_) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 144 | { |
| 145 | struct intel_fence *fence = intel_fence(fence_); |
| 146 | |
Chia-I Wu | ca4b154 | 2014-09-23 15:02:01 +0800 | [diff] [blame] | 147 | return intel_fence_wait(fence, 0); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 148 | } |
| 149 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 150 | ICD_EXPORT VkResult VKAPI vkWaitForFences( |
| 151 | VkDevice device, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 152 | uint32_t fenceCount, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 153 | const VkFence* pFences, |
Courtney Goeltzenleuchter | 1f41f54 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 154 | VkBool32 waitAll, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 155 | uint64_t timeout) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 156 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 157 | VkResult ret = VK_SUCCESS; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 158 | uint32_t i; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 159 | |
| 160 | for (i = 0; i < fenceCount; i++) { |
| 161 | struct intel_fence *fence = intel_fence(pFences[i]); |
| 162 | int64_t ns; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 163 | VkResult r; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 164 | |
Courtney Goeltzenleuchter | b29b8e4 | 2015-03-25 16:37:00 -0600 | [diff] [blame] | 165 | /* timeout in nano seconds */ |
| 166 | ns = (timeout <= (uint64_t) INT64_MAX) ? ns : -1; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 167 | r = intel_fence_wait(fence, ns); |
| 168 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 169 | if (!waitAll && r == VK_SUCCESS) |
| 170 | return VK_SUCCESS; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 171 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 172 | if (r != VK_SUCCESS) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 173 | ret = r; |
| 174 | } |
| 175 | |
| 176 | return ret; |
| 177 | } |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 178 | ICD_EXPORT VkResult VKAPI vkResetFences( |
| 179 | VkDevice device, |
Courtney Goeltzenleuchter | f2e33ad | 2015-06-18 17:28:20 -0600 | [diff] [blame] | 180 | uint32_t fenceCount, |
| 181 | const VkFence* pFences) |
Mark Lobodzinski | ebe814d | 2015-04-07 16:07:57 -0500 | [diff] [blame] | 182 | { |
| 183 | uint32_t i; |
| 184 | |
| 185 | for (i = 0; i < fenceCount; i++) { |
| 186 | struct intel_fence *fence = intel_fence(pFences[i]); |
| 187 | fence->signaled = false; |
| 188 | } |
| 189 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 190 | return VK_SUCCESS; |
Mark Lobodzinski | ebe814d | 2015-04-07 16:07:57 -0500 | [diff] [blame] | 191 | } |