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 | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 31 | #include "wsi_x11.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 | |
Courtney Goeltzenleuchter | fb4fb53 | 2014-08-14 09:35:21 -0600 | [diff] [blame] | 47 | fence = (struct intel_fence *) intel_base_create(dev, sizeof(*fence), |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 48 | 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 | 26f0bd0 | 2014-08-07 10:38:40 +0800 | [diff] [blame] | 52 | fence->obj.destroy = fence_destroy; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 53 | |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 54 | *fence_ret = fence; |
| 55 | |
| 56 | return XGL_SUCCESS; |
| 57 | } |
| 58 | |
| 59 | void intel_fence_destroy(struct intel_fence *fence) |
| 60 | { |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame^] | 61 | if (fence->seqno_bo) |
| 62 | intel_bo_unreference(fence->seqno_bo); |
| 63 | |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 64 | intel_base_destroy(&fence->obj.base); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 65 | } |
| 66 | |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame^] | 67 | void intel_fence_set_seqno(struct intel_fence *fence, |
| 68 | struct intel_bo *seqno_bo) |
| 69 | { |
| 70 | #ifdef ENABLE_WSI_X11 |
| 71 | fence->x11 = NULL; |
| 72 | #endif |
| 73 | |
| 74 | if (fence->seqno_bo) |
| 75 | intel_bo_unreference(fence->seqno_bo); |
| 76 | |
| 77 | fence->seqno_bo = seqno_bo; |
| 78 | intel_bo_reference(fence->seqno_bo); |
| 79 | } |
| 80 | |
| 81 | void intel_fence_set_x11(struct intel_fence *fence, |
| 82 | struct intel_wsi_x11 *x11, |
| 83 | struct intel_wsi_x11_window *win, |
| 84 | uint32_t serial) |
| 85 | { |
| 86 | if (fence->seqno_bo) { |
| 87 | intel_bo_unreference(fence->seqno_bo); |
| 88 | fence->seqno_bo = NULL; |
| 89 | } |
| 90 | |
| 91 | #ifdef ENABLE_WSI_X11 |
| 92 | fence->x11 = x11; |
| 93 | fence->x11_win = win; |
| 94 | fence->x11_serial = serial; |
| 95 | #endif |
| 96 | } |
| 97 | |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 98 | XGL_RESULT intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns) |
| 99 | { |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame^] | 100 | if (fence->seqno_bo) { |
| 101 | return (intel_bo_wait(fence->seqno_bo, timeout_ns)) ? |
| 102 | XGL_NOT_READY : XGL_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 103 | } |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 104 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 105 | #ifdef ENABLE_WSI_X11 |
| 106 | if (fence->x11) { |
| 107 | const bool wait = (timeout_ns != 0); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 108 | |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 109 | return intel_wsi_x11_wait(fence->x11, fence->x11_win, |
| 110 | fence->x11_serial, wait); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 111 | } |
| 112 | #endif |
| 113 | |
| 114 | return XGL_ERROR_UNAVAILABLE; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 115 | } |
| 116 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 117 | ICD_EXPORT XGL_RESULT XGLAPI xglCreateFence( |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 118 | XGL_DEVICE device, |
| 119 | const XGL_FENCE_CREATE_INFO* pCreateInfo, |
| 120 | XGL_FENCE* pFence) |
| 121 | { |
| 122 | struct intel_dev *dev = intel_dev(device); |
| 123 | |
| 124 | return intel_fence_create(dev, pCreateInfo, |
| 125 | (struct intel_fence **) pFence); |
| 126 | } |
| 127 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 128 | ICD_EXPORT XGL_RESULT XGLAPI xglGetFenceStatus( |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 129 | XGL_FENCE fence_) |
| 130 | { |
| 131 | struct intel_fence *fence = intel_fence(fence_); |
| 132 | |
Chia-I Wu | ca4b154 | 2014-09-23 15:02:01 +0800 | [diff] [blame] | 133 | return intel_fence_wait(fence, 0); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 134 | } |
| 135 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 136 | ICD_EXPORT XGL_RESULT XGLAPI xglWaitForFences( |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 137 | XGL_DEVICE device, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 138 | uint32_t fenceCount, |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 139 | const XGL_FENCE* pFences, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 140 | bool32_t waitAll, |
| 141 | uint64_t timeout) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 142 | { |
| 143 | XGL_RESULT ret = XGL_SUCCESS; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 144 | uint32_t i; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 145 | |
| 146 | for (i = 0; i < fenceCount; i++) { |
| 147 | struct intel_fence *fence = intel_fence(pFences[i]); |
| 148 | int64_t ns; |
| 149 | XGL_RESULT r; |
| 150 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 151 | if (timeout <= (uint64_t) (INT64_MAX / 1000 / 1000 / 1000)) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 152 | ns = timeout * 1000 * 1000 * 1000; |
| 153 | else |
| 154 | ns = -1; |
| 155 | |
| 156 | r = intel_fence_wait(fence, ns); |
| 157 | |
| 158 | if (!waitAll && r == XGL_SUCCESS) |
| 159 | return XGL_SUCCESS; |
| 160 | |
| 161 | if (r != XGL_SUCCESS) |
| 162 | ret = r; |
| 163 | } |
| 164 | |
| 165 | return ret; |
| 166 | } |