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