blob: 481403a7bd0b57f5ec91744123726c26dc908b3f [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"
31#include "fence.h"
32
Chia-I Wu26f0bd02014-08-07 10:38:40 +080033static void fence_destroy(struct intel_obj *obj)
Chia-I Wubdf4c562014-08-07 06:36:33 +080034{
35 struct intel_fence *fence = intel_fence_from_obj(obj);
36
37 intel_fence_destroy(fence);
38}
39
40XGL_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 Goeltzenleuchterfb4fb532014-08-14 09:35:21 -060046 fence = (struct intel_fence *) intel_base_create(dev, sizeof(*fence),
Chia-I Wubbf2c932014-08-07 12:20:08 +080047 dev->base.dbg, XGL_DBG_OBJECT_FENCE, info, 0);
Chia-I Wubdf4c562014-08-07 06:36:33 +080048 if (!fence)
49 return XGL_ERROR_OUT_OF_MEMORY;
50
Chia-I Wu26f0bd02014-08-07 10:38:40 +080051 fence->obj.destroy = fence_destroy;
Chia-I Wubdf4c562014-08-07 06:36:33 +080052
Chia-I Wubdf4c562014-08-07 06:36:33 +080053 *fence_ret = fence;
54
55 return XGL_SUCCESS;
56}
57
58void intel_fence_destroy(struct intel_fence *fence)
59{
Chia-I Wubbf2c932014-08-07 12:20:08 +080060 intel_base_destroy(&fence->obj.base);
Chia-I Wubdf4c562014-08-07 06:36:33 +080061}
62
Chia-I Wubdf4c562014-08-07 06:36:33 +080063XGL_RESULT intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns)
64{
Chia-I Wue24c3292014-08-21 14:05:23 +080065 struct intel_bo *bo = (fence->cmd) ?
66 intel_cmd_get_batch(fence->cmd, NULL) : NULL;
Chia-I Wubdf4c562014-08-07 06:36:33 +080067 int err;
68
Chia-I Wue24c3292014-08-21 14:05:23 +080069 if (!bo)
Chia-I Wubdf4c562014-08-07 06:36:33 +080070 return XGL_ERROR_UNAVAILABLE;
71
Chia-I Wue24c3292014-08-21 14:05:23 +080072 err = intel_bo_wait(bo, timeout_ns);
Chia-I Wubdf4c562014-08-07 06:36:33 +080073
74 return (err) ? XGL_NOT_READY : XGL_SUCCESS;
75}
76
77XGL_RESULT XGLAPI intelCreateFence(
78 XGL_DEVICE device,
79 const XGL_FENCE_CREATE_INFO* pCreateInfo,
80 XGL_FENCE* pFence)
81{
82 struct intel_dev *dev = intel_dev(device);
83
84 return intel_fence_create(dev, pCreateInfo,
85 (struct intel_fence **) pFence);
86}
87
88XGL_RESULT XGLAPI intelGetFenceStatus(
89 XGL_FENCE fence_)
90{
91 struct intel_fence *fence = intel_fence(fence_);
92
Chia-I Wuca4b1542014-09-23 15:02:01 +080093 return intel_fence_wait(fence, 0);
Chia-I Wubdf4c562014-08-07 06:36:33 +080094}
95
96XGL_RESULT XGLAPI intelWaitForFences(
97 XGL_DEVICE device,
98 XGL_UINT fenceCount,
99 const XGL_FENCE* pFences,
100 XGL_BOOL waitAll,
101 XGL_UINT64 timeout)
102{
103 XGL_RESULT ret = XGL_SUCCESS;
104 XGL_UINT i;
105
106 for (i = 0; i < fenceCount; i++) {
107 struct intel_fence *fence = intel_fence(pFences[i]);
108 int64_t ns;
109 XGL_RESULT r;
110
111 if (timeout <= (XGL_UINT64) (INT64_MAX / 1000 / 1000 / 1000))
112 ns = timeout * 1000 * 1000 * 1000;
113 else
114 ns = -1;
115
116 r = intel_fence_wait(fence, ns);
117
118 if (!waitAll && r == XGL_SUCCESS)
119 return XGL_SUCCESS;
120
121 if (r != XGL_SUCCESS)
122 ret = r;
123 }
124
125 return ret;
126}