blob: b19cabd272441adbf80a6fc75a34f3cbdcdaba05 [file] [log] [blame]
Chia-I Wubdf4c562014-08-07 06:36:33 +08001/*
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 Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wubdf4c562014-08-07 06:36:33 +080026 */
27
28#include "kmd/winsys.h"
Chia-I Wu34f45182014-08-19 14:02:59 +080029#include "cmd.h"
Chia-I Wubdf4c562014-08-07 06:36:33 +080030#include "dev.h"
Chia-I Wu41858c82015-04-04 16:39:25 +080031#include "wsi.h"
Chia-I Wubdf4c562014-08-07 06:36:33 +080032#include "fence.h"
33
Chia-I Wu26f0bd02014-08-07 10:38:40 +080034static void fence_destroy(struct intel_obj *obj)
Chia-I Wubdf4c562014-08-07 06:36:33 +080035{
36 struct intel_fence *fence = intel_fence_from_obj(obj);
37
38 intel_fence_destroy(fence);
39}
40
41XGL_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 Wu545c2e12015-02-22 13:19:54 +080047 fence = (struct intel_fence *) intel_base_create(&dev->base.handle,
48 sizeof(*fence), dev->base.dbg, XGL_DBG_OBJECT_FENCE, info, 0);
Chia-I Wubdf4c562014-08-07 06:36:33 +080049 if (!fence)
50 return XGL_ERROR_OUT_OF_MEMORY;
51
Chia-I Wu41858c82015-04-04 16:39:25 +080052 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 Wu26f0bd02014-08-07 10:38:40 +080060 fence->obj.destroy = fence_destroy;
Chia-I Wubdf4c562014-08-07 06:36:33 +080061
Chia-I Wubdf4c562014-08-07 06:36:33 +080062 *fence_ret = fence;
63
64 return XGL_SUCCESS;
65}
66
67void intel_fence_destroy(struct intel_fence *fence)
68{
Chia-I Wu41858c82015-04-04 16:39:25 +080069 if (fence->wsi_data)
70 intel_wsi_fence_cleanup(fence);
71
Chia-I Wucb2dc0d2015-03-05 16:19:42 -070072 intel_bo_unref(fence->seqno_bo);
Chia-I Wu046a7a92015-02-17 14:29:01 -070073
Chia-I Wubbf2c932014-08-07 12:20:08 +080074 intel_base_destroy(&fence->obj.base);
Chia-I Wubdf4c562014-08-07 06:36:33 +080075}
76
Chia-I Wu046a7a92015-02-17 14:29:01 -070077void intel_fence_set_seqno(struct intel_fence *fence,
78 struct intel_bo *seqno_bo)
79{
Chia-I Wucb2dc0d2015-03-05 16:19:42 -070080 intel_bo_unref(fence->seqno_bo);
81 fence->seqno_bo = intel_bo_ref(seqno_bo);
Chia-I Wu046a7a92015-02-17 14:29:01 -070082}
83
Chia-I Wubdf4c562014-08-07 06:36:33 +080084XGL_RESULT intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns)
85{
Chia-I Wu41858c82015-04-04 16:39:25 +080086 XGL_RESULT ret;
Chia-I Wubda4f622015-02-25 15:06:15 -070087
Chia-I Wu41858c82015-04-04 16:39:25 +080088 ret = intel_wsi_fence_wait(fence, timeout_ns);
89 if (ret != XGL_SUCCESS)
90 return ret;
Chia-I Wubda4f622015-02-25 15:06:15 -070091
Chia-I Wu046a7a92015-02-17 14:29:01 -070092 if (fence->seqno_bo) {
93 return (intel_bo_wait(fence->seqno_bo, timeout_ns)) ?
94 XGL_NOT_READY : XGL_SUCCESS;
Chia-I Wu1db76e02014-09-15 14:21:14 +080095 }
Chia-I Wubdf4c562014-08-07 06:36:33 +080096
Chia-I Wu1db76e02014-09-15 14:21:14 +080097 return XGL_ERROR_UNAVAILABLE;
Chia-I Wubdf4c562014-08-07 06:36:33 +080098}
99
Chia-I Wu96177272015-01-03 15:27:41 +0800100ICD_EXPORT XGL_RESULT XGLAPI xglCreateFence(
Chia-I Wubdf4c562014-08-07 06:36:33 +0800101 XGL_DEVICE device,
102 const XGL_FENCE_CREATE_INFO* pCreateInfo,
103 XGL_FENCE* pFence)
104{
105 struct intel_dev *dev = intel_dev(device);
106
107 return intel_fence_create(dev, pCreateInfo,
108 (struct intel_fence **) pFence);
109}
110
Chia-I Wu96177272015-01-03 15:27:41 +0800111ICD_EXPORT XGL_RESULT XGLAPI xglGetFenceStatus(
Chia-I Wubdf4c562014-08-07 06:36:33 +0800112 XGL_FENCE fence_)
113{
114 struct intel_fence *fence = intel_fence(fence_);
115
Chia-I Wuca4b1542014-09-23 15:02:01 +0800116 return intel_fence_wait(fence, 0);
Chia-I Wubdf4c562014-08-07 06:36:33 +0800117}
118
Chia-I Wu96177272015-01-03 15:27:41 +0800119ICD_EXPORT XGL_RESULT XGLAPI xglWaitForFences(
Chia-I Wubdf4c562014-08-07 06:36:33 +0800120 XGL_DEVICE device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600121 uint32_t fenceCount,
Chia-I Wubdf4c562014-08-07 06:36:33 +0800122 const XGL_FENCE* pFences,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600123 bool32_t waitAll,
124 uint64_t timeout)
Chia-I Wubdf4c562014-08-07 06:36:33 +0800125{
126 XGL_RESULT ret = XGL_SUCCESS;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600127 uint32_t i;
Chia-I Wubdf4c562014-08-07 06:36:33 +0800128
129 for (i = 0; i < fenceCount; i++) {
130 struct intel_fence *fence = intel_fence(pFences[i]);
131 int64_t ns;
132 XGL_RESULT r;
133
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600134 if (timeout <= (uint64_t) (INT64_MAX / 1000 / 1000 / 1000))
Chia-I Wubdf4c562014-08-07 06:36:33 +0800135 ns = timeout * 1000 * 1000 * 1000;
136 else
137 ns = -1;
138
139 r = intel_fence_wait(fence, ns);
140
141 if (!waitAll && r == XGL_SUCCESS)
142 return XGL_SUCCESS;
143
144 if (r != XGL_SUCCESS)
145 ret = r;
146 }
147
148 return ret;
149}