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" |
| 31 | #include "fence.h" |
| 32 | |
Chia-I Wu | 26f0bd0 | 2014-08-07 10:38:40 +0800 | [diff] [blame] | 33 | static void fence_destroy(struct intel_obj *obj) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 34 | { |
| 35 | struct intel_fence *fence = intel_fence_from_obj(obj); |
| 36 | |
| 37 | intel_fence_destroy(fence); |
| 38 | } |
| 39 | |
| 40 | XGL_RESULT intel_fence_create(struct intel_dev *dev, |
| 41 | const XGL_FENCE_CREATE_INFO *info, |
| 42 | struct intel_fence **fence_ret) |
| 43 | { |
| 44 | struct intel_fence *fence; |
| 45 | |
Courtney Goeltzenleuchter | fb4fb53 | 2014-08-14 09:35:21 -0600 | [diff] [blame] | 46 | fence = (struct intel_fence *) intel_base_create(dev, sizeof(*fence), |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 47 | dev->base.dbg, XGL_DBG_OBJECT_FENCE, info, 0); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 48 | if (!fence) |
| 49 | return XGL_ERROR_OUT_OF_MEMORY; |
| 50 | |
Chia-I Wu | 26f0bd0 | 2014-08-07 10:38:40 +0800 | [diff] [blame] | 51 | fence->obj.destroy = fence_destroy; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 52 | |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 53 | *fence_ret = fence; |
| 54 | |
| 55 | return XGL_SUCCESS; |
| 56 | } |
| 57 | |
| 58 | void intel_fence_destroy(struct intel_fence *fence) |
| 59 | { |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 60 | intel_base_destroy(&fence->obj.base); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | XGL_RESULT intel_fence_get_status(struct intel_fence *fence) |
| 64 | { |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 65 | struct intel_bo *bo = (fence->cmd) ? |
| 66 | intel_cmd_get_batch(fence->cmd, NULL) : NULL; |
| 67 | |
| 68 | if (!bo) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 69 | return XGL_ERROR_UNAVAILABLE; |
| 70 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 71 | return (intel_bo_is_busy(bo)) ? XGL_NOT_READY : XGL_SUCCESS; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | XGL_RESULT intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns) |
| 75 | { |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 76 | struct intel_bo *bo = (fence->cmd) ? |
| 77 | intel_cmd_get_batch(fence->cmd, NULL) : NULL; |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 78 | int err; |
| 79 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 80 | if (!bo) |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 81 | return XGL_ERROR_UNAVAILABLE; |
| 82 | |
Chia-I Wu | e24c329 | 2014-08-21 14:05:23 +0800 | [diff] [blame] | 83 | err = intel_bo_wait(bo, timeout_ns); |
Chia-I Wu | bdf4c56 | 2014-08-07 06:36:33 +0800 | [diff] [blame] | 84 | |
| 85 | return (err) ? XGL_NOT_READY : XGL_SUCCESS; |
| 86 | } |
| 87 | |
| 88 | XGL_RESULT XGLAPI intelCreateFence( |
| 89 | XGL_DEVICE device, |
| 90 | const XGL_FENCE_CREATE_INFO* pCreateInfo, |
| 91 | XGL_FENCE* pFence) |
| 92 | { |
| 93 | struct intel_dev *dev = intel_dev(device); |
| 94 | |
| 95 | return intel_fence_create(dev, pCreateInfo, |
| 96 | (struct intel_fence **) pFence); |
| 97 | } |
| 98 | |
| 99 | XGL_RESULT XGLAPI intelGetFenceStatus( |
| 100 | XGL_FENCE fence_) |
| 101 | { |
| 102 | struct intel_fence *fence = intel_fence(fence_); |
| 103 | |
| 104 | return intel_fence_get_status(fence); |
| 105 | } |
| 106 | |
| 107 | XGL_RESULT XGLAPI intelWaitForFences( |
| 108 | XGL_DEVICE device, |
| 109 | XGL_UINT fenceCount, |
| 110 | const XGL_FENCE* pFences, |
| 111 | XGL_BOOL waitAll, |
| 112 | XGL_UINT64 timeout) |
| 113 | { |
| 114 | XGL_RESULT ret = XGL_SUCCESS; |
| 115 | XGL_UINT i; |
| 116 | |
| 117 | for (i = 0; i < fenceCount; i++) { |
| 118 | struct intel_fence *fence = intel_fence(pFences[i]); |
| 119 | int64_t ns; |
| 120 | XGL_RESULT r; |
| 121 | |
| 122 | if (timeout <= (XGL_UINT64) (INT64_MAX / 1000 / 1000 / 1000)) |
| 123 | ns = timeout * 1000 * 1000 * 1000; |
| 124 | else |
| 125 | ns = -1; |
| 126 | |
| 127 | r = intel_fence_wait(fence, ns); |
| 128 | |
| 129 | if (!waitAll && r == XGL_SUCCESS) |
| 130 | return XGL_SUCCESS; |
| 131 | |
| 132 | if (r != XGL_SUCCESS) |
| 133 | ret = r; |
| 134 | } |
| 135 | |
| 136 | return ret; |
| 137 | } |