blob: a90a9917c842e337a8f08e07d633e75180f0b862 [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"
26#include "dev.h"
27#include "fence.h"
28
Chia-I Wu26f0bd02014-08-07 10:38:40 +080029static void fence_destroy(struct intel_obj *obj)
Chia-I Wubdf4c562014-08-07 06:36:33 +080030{
31 struct intel_fence *fence = intel_fence_from_obj(obj);
32
33 intel_fence_destroy(fence);
34}
35
36XGL_RESULT intel_fence_create(struct intel_dev *dev,
37 const XGL_FENCE_CREATE_INFO *info,
38 struct intel_fence **fence_ret)
39{
40 struct intel_fence *fence;
41
Chia-I Wubbf2c932014-08-07 12:20:08 +080042 fence = (struct intel_fence *) intel_base_create(sizeof(*fence),
43 dev->base.dbg, XGL_DBG_OBJECT_FENCE, info, 0);
Chia-I Wubdf4c562014-08-07 06:36:33 +080044 if (!fence)
45 return XGL_ERROR_OUT_OF_MEMORY;
46
Chia-I Wu26f0bd02014-08-07 10:38:40 +080047 fence->obj.destroy = fence_destroy;
Chia-I Wubdf4c562014-08-07 06:36:33 +080048
Chia-I Wubdf4c562014-08-07 06:36:33 +080049 *fence_ret = fence;
50
51 return XGL_SUCCESS;
52}
53
54void intel_fence_destroy(struct intel_fence *fence)
55{
56 if (fence->submitted_bo)
57 intel_bo_unreference(fence->submitted_bo);
58
Chia-I Wubbf2c932014-08-07 12:20:08 +080059 intel_base_destroy(&fence->obj.base);
Chia-I Wubdf4c562014-08-07 06:36:33 +080060}
61
62XGL_RESULT intel_fence_get_status(struct intel_fence *fence)
63{
64 if (!fence->submitted_bo)
65 return XGL_ERROR_UNAVAILABLE;
66
67 return (intel_bo_is_busy(fence->submitted_bo)) ?
68 XGL_NOT_READY : XGL_SUCCESS;
69}
70
71XGL_RESULT intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns)
72{
73 int err;
74
75 if (!fence->submitted_bo)
76 return XGL_ERROR_UNAVAILABLE;
77
78 err = intel_bo_wait(fence->submitted_bo, timeout_ns);
79
80 return (err) ? XGL_NOT_READY : XGL_SUCCESS;
81}
82
83XGL_RESULT XGLAPI intelCreateFence(
84 XGL_DEVICE device,
85 const XGL_FENCE_CREATE_INFO* pCreateInfo,
86 XGL_FENCE* pFence)
87{
88 struct intel_dev *dev = intel_dev(device);
89
90 return intel_fence_create(dev, pCreateInfo,
91 (struct intel_fence **) pFence);
92}
93
94XGL_RESULT XGLAPI intelGetFenceStatus(
95 XGL_FENCE fence_)
96{
97 struct intel_fence *fence = intel_fence(fence_);
98
99 return intel_fence_get_status(fence);
100}
101
102XGL_RESULT XGLAPI intelWaitForFences(
103 XGL_DEVICE device,
104 XGL_UINT fenceCount,
105 const XGL_FENCE* pFences,
106 XGL_BOOL waitAll,
107 XGL_UINT64 timeout)
108{
109 XGL_RESULT ret = XGL_SUCCESS;
110 XGL_UINT i;
111
112 for (i = 0; i < fenceCount; i++) {
113 struct intel_fence *fence = intel_fence(pFences[i]);
114 int64_t ns;
115 XGL_RESULT r;
116
117 if (timeout <= (XGL_UINT64) (INT64_MAX / 1000 / 1000 / 1000))
118 ns = timeout * 1000 * 1000 * 1000;
119 else
120 ns = -1;
121
122 r = intel_fence_wait(fence, ns);
123
124 if (!waitAll && r == XGL_SUCCESS)
125 return XGL_SUCCESS;
126
127 if (r != XGL_SUCCESS)
128 ret = r;
129 }
130
131 return ret;
132}