blob: 52d80792c401b22a85b76e3ea3419dd4489ac8d9 [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.
23 */
24
25#include "kmd/winsys.h"
Chia-I Wu34f45182014-08-19 14:02:59 +080026#include "cmd.h"
Chia-I Wubdf4c562014-08-07 06:36:33 +080027#include "dev.h"
28#include "fence.h"
29
Chia-I Wu26f0bd02014-08-07 10:38:40 +080030static void fence_destroy(struct intel_obj *obj)
Chia-I Wubdf4c562014-08-07 06:36:33 +080031{
32 struct intel_fence *fence = intel_fence_from_obj(obj);
33
34 intel_fence_destroy(fence);
35}
36
37XGL_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 Goeltzenleuchterfb4fb532014-08-14 09:35:21 -060043 fence = (struct intel_fence *) intel_base_create(dev, sizeof(*fence),
Chia-I Wubbf2c932014-08-07 12:20:08 +080044 dev->base.dbg, XGL_DBG_OBJECT_FENCE, info, 0);
Chia-I Wubdf4c562014-08-07 06:36:33 +080045 if (!fence)
46 return XGL_ERROR_OUT_OF_MEMORY;
47
Chia-I Wu26f0bd02014-08-07 10:38:40 +080048 fence->obj.destroy = fence_destroy;
Chia-I Wubdf4c562014-08-07 06:36:33 +080049
Chia-I Wubdf4c562014-08-07 06:36:33 +080050 *fence_ret = fence;
51
52 return XGL_SUCCESS;
53}
54
55void intel_fence_destroy(struct intel_fence *fence)
56{
Chia-I Wubbf2c932014-08-07 12:20:08 +080057 intel_base_destroy(&fence->obj.base);
Chia-I Wubdf4c562014-08-07 06:36:33 +080058}
59
60XGL_RESULT intel_fence_get_status(struct intel_fence *fence)
61{
Chia-I Wu34f45182014-08-19 14:02:59 +080062 if (!fence->cmd)
Chia-I Wubdf4c562014-08-07 06:36:33 +080063 return XGL_ERROR_UNAVAILABLE;
64
Chia-I Wu34f45182014-08-19 14:02:59 +080065 return (intel_bo_is_busy(fence->cmd->bo)) ? XGL_NOT_READY : XGL_SUCCESS;
Chia-I Wubdf4c562014-08-07 06:36:33 +080066}
67
68XGL_RESULT intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns)
69{
70 int err;
71
Chia-I Wu34f45182014-08-19 14:02:59 +080072 if (!fence->cmd)
Chia-I Wubdf4c562014-08-07 06:36:33 +080073 return XGL_ERROR_UNAVAILABLE;
74
Chia-I Wu34f45182014-08-19 14:02:59 +080075 err = intel_bo_wait(fence->cmd->bo, timeout_ns);
Chia-I Wubdf4c562014-08-07 06:36:33 +080076
77 return (err) ? XGL_NOT_READY : XGL_SUCCESS;
78}
79
80XGL_RESULT XGLAPI intelCreateFence(
81 XGL_DEVICE device,
82 const XGL_FENCE_CREATE_INFO* pCreateInfo,
83 XGL_FENCE* pFence)
84{
85 struct intel_dev *dev = intel_dev(device);
86
87 return intel_fence_create(dev, pCreateInfo,
88 (struct intel_fence **) pFence);
89}
90
91XGL_RESULT XGLAPI intelGetFenceStatus(
92 XGL_FENCE fence_)
93{
94 struct intel_fence *fence = intel_fence(fence_);
95
96 return intel_fence_get_status(fence);
97}
98
99XGL_RESULT XGLAPI intelWaitForFences(
100 XGL_DEVICE device,
101 XGL_UINT fenceCount,
102 const XGL_FENCE* pFences,
103 XGL_BOOL waitAll,
104 XGL_UINT64 timeout)
105{
106 XGL_RESULT ret = XGL_SUCCESS;
107 XGL_UINT i;
108
109 for (i = 0; i < fenceCount; i++) {
110 struct intel_fence *fence = intel_fence(pFences[i]);
111 int64_t ns;
112 XGL_RESULT r;
113
114 if (timeout <= (XGL_UINT64) (INT64_MAX / 1000 / 1000 / 1000))
115 ns = timeout * 1000 * 1000 * 1000;
116 else
117 ns = -1;
118
119 r = intel_fence_wait(fence, ns);
120
121 if (!waitAll && r == XGL_SUCCESS)
122 return XGL_SUCCESS;
123
124 if (r != XGL_SUCCESS)
125 ret = r;
126 }
127
128 return ret;
129}