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