Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 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 | |
| 41 | XGL_RESULT intel_fence_create(struct intel_dev *dev, |
| 42 | const XGL_FENCE_CREATE_INFO *info, |
| 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, |
| 48 | sizeof(*fence), dev->base.dbg, XGL_DBG_OBJECT_FENCE, info, 0); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 49 | if (!fence) |
| 50 | return XGL_ERROR_OUT_OF_MEMORY; |
| 51 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 52 | if (dev->exts[INTEL_EXT_WSI_X11]) { |
| 53 | XGL_RESULT ret = intel_wsi_fence_init(fence); |
| 54 | if (ret != XGL_SUCCESS) { |
| 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; |
| 63 | |
| 64 | return XGL_SUCCESS; |
| 65 | } |
| 66 | |
| 67 | void intel_fence_destroy(struct intel_fence *fence) |
| 68 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 69 | if (fence->wsi_data) |
| 70 | intel_wsi_fence_cleanup(fence); |
| 71 | |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 72 | intel_bo_unref(fence->seqno_bo); |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 73 | |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 74 | intel_base_destroy(&fence->obj.base); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 75 | } |
| 76 | |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 77 | void intel_fence_copy(struct intel_fence *fence, |
| 78 | const struct intel_fence *src) |
| 79 | { |
| 80 | intel_wsi_fence_copy(fence, src); |
| 81 | intel_fence_set_seqno(fence, src->seqno_bo); |
| 82 | } |
| 83 | |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 84 | void intel_fence_set_seqno(struct intel_fence *fence, |
| 85 | struct intel_bo *seqno_bo) |
| 86 | { |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 87 | intel_bo_unref(fence->seqno_bo); |
| 88 | fence->seqno_bo = intel_bo_ref(seqno_bo); |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 91 | XGL_RESULT intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns) |
| 92 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 93 | XGL_RESULT ret; |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 94 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 95 | ret = intel_wsi_fence_wait(fence, timeout_ns); |
| 96 | if (ret != XGL_SUCCESS) |
| 97 | return ret; |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 98 | |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 99 | if (fence->seqno_bo) { |
| 100 | return (intel_bo_wait(fence->seqno_bo, timeout_ns)) ? |
| 101 | XGL_NOT_READY : XGL_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 102 | } |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 103 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 104 | return XGL_ERROR_UNAVAILABLE; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 105 | } |
| 106 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 107 | ICD_EXPORT XGL_RESULT XGLAPI xglCreateFence( |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 108 | XGL_DEVICE device, |
| 109 | const XGL_FENCE_CREATE_INFO* pCreateInfo, |
| 110 | XGL_FENCE* pFence) |
| 111 | { |
| 112 | struct intel_dev *dev = intel_dev(device); |
| 113 | |
| 114 | return intel_fence_create(dev, pCreateInfo, |
| 115 | (struct intel_fence **) pFence); |
| 116 | } |
| 117 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 118 | ICD_EXPORT XGL_RESULT XGLAPI xglGetFenceStatus( |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 119 | XGL_FENCE fence_) |
| 120 | { |
| 121 | struct intel_fence *fence = intel_fence(fence_); |
| 122 | |
Chia-I Wu | ca4b154 | 2014-09-23 15:02:01 +0800 | [diff] [blame] | 123 | return intel_fence_wait(fence, 0); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 124 | } |
| 125 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 126 | ICD_EXPORT XGL_RESULT XGLAPI xglWaitForFences( |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 127 | XGL_DEVICE device, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 128 | uint32_t fenceCount, |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 129 | const XGL_FENCE* pFences, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 130 | bool32_t waitAll, |
| 131 | uint64_t timeout) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 132 | { |
| 133 | XGL_RESULT ret = XGL_SUCCESS; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 134 | uint32_t i; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 135 | |
| 136 | for (i = 0; i < fenceCount; i++) { |
| 137 | struct intel_fence *fence = intel_fence(pFences[i]); |
| 138 | int64_t ns; |
| 139 | XGL_RESULT r; |
| 140 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 141 | if (timeout <= (uint64_t) (INT64_MAX / 1000 / 1000 / 1000)) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 142 | ns = timeout * 1000 * 1000 * 1000; |
| 143 | else |
| 144 | ns = -1; |
| 145 | |
| 146 | r = intel_fence_wait(fence, ns); |
| 147 | |
| 148 | if (!waitAll && r == XGL_SUCCESS) |
| 149 | return XGL_SUCCESS; |
| 150 | |
| 151 | if (r != XGL_SUCCESS) |
| 152 | ret = r; |
| 153 | } |
| 154 | |
| 155 | return ret; |
| 156 | } |