blob: 353b27a933a31ff6e4537f2f921fe0eb46e347d6 [file] [log] [blame]
Chia-I Wue09b5362014-08-07 09:25:14 +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 Wue09b5362014-08-07 09:25:14 +080027#include "dev.h"
Chia-I Wuc5438c22014-08-19 14:03:06 +080028#include "fence.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080029#include "queue.h"
30
Chia-I Wu9ae59c12014-08-07 10:08:49 +080031XGL_RESULT intel_queue_create(struct intel_dev *dev,
Chia-I Wucdcff732014-08-19 14:44:15 +080032 enum intel_gpu_engine_type engine,
Chia-I Wu9ae59c12014-08-07 10:08:49 +080033 struct intel_queue **queue_ret)
Chia-I Wue09b5362014-08-07 09:25:14 +080034{
35 struct intel_queue *queue;
Chia-I Wuc5438c22014-08-19 14:03:06 +080036 enum intel_ring_type ring;
37
Chia-I Wucdcff732014-08-19 14:44:15 +080038 switch (engine) {
39 case INTEL_GPU_ENGINE_3D:
Chia-I Wuc5438c22014-08-19 14:03:06 +080040 ring = INTEL_RING_RENDER;
41 break;
Chia-I Wuc5438c22014-08-19 14:03:06 +080042 default:
43 return XGL_ERROR_INVALID_VALUE;
44 break;
45 }
Chia-I Wue09b5362014-08-07 09:25:14 +080046
Courtney Goeltzenleuchterfb4fb532014-08-14 09:35:21 -060047 queue = (struct intel_queue *) intel_base_create(dev, sizeof(*queue),
Chia-I Wubbf2c932014-08-07 12:20:08 +080048 dev->base.dbg, XGL_DBG_OBJECT_QUEUE, NULL, 0);
Chia-I Wue09b5362014-08-07 09:25:14 +080049 if (!queue)
Chia-I Wu9ae59c12014-08-07 10:08:49 +080050 return XGL_ERROR_OUT_OF_MEMORY;
Chia-I Wue09b5362014-08-07 09:25:14 +080051
Chia-I Wue09b5362014-08-07 09:25:14 +080052 queue->dev = dev;
Chia-I Wuc5438c22014-08-19 14:03:06 +080053 queue->ring = ring;
Chia-I Wue09b5362014-08-07 09:25:14 +080054
Chia-I Wu9ae59c12014-08-07 10:08:49 +080055 *queue_ret = queue;
56
57 return XGL_SUCCESS;
Chia-I Wue09b5362014-08-07 09:25:14 +080058}
59
60void intel_queue_destroy(struct intel_queue *queue)
61{
Chia-I Wubbf2c932014-08-07 12:20:08 +080062 intel_base_destroy(&queue->base);
Chia-I Wue09b5362014-08-07 09:25:14 +080063}
64
65XGL_RESULT intel_queue_wait(struct intel_queue *queue, int64_t timeout)
66{
Chia-I Wue24c3292014-08-21 14:05:23 +080067 struct intel_bo *bo = (queue->last_submitted_cmd) ?
68 intel_cmd_get_batch(queue->last_submitted_cmd, NULL) : NULL;
Chia-I Wue09b5362014-08-07 09:25:14 +080069
Chia-I Wue24c3292014-08-21 14:05:23 +080070 return (!bo || intel_bo_wait(bo, timeout) == 0) ?
Chia-I Wue09b5362014-08-07 09:25:14 +080071 XGL_SUCCESS : XGL_ERROR_UNKNOWN;
72}
73
Chia-I Wuc5438c22014-08-19 14:03:06 +080074XGL_RESULT intel_queue_submit(struct intel_queue *queue,
75 struct intel_cmd *cmd)
76{
77 struct intel_winsys *winsys = queue->dev->winsys;
Chia-I Wue24c3292014-08-21 14:05:23 +080078 struct intel_bo *bo;
79 XGL_GPU_SIZE used;
Chia-I Wuc5438c22014-08-19 14:03:06 +080080 int err;
81
Chia-I Wue24c3292014-08-21 14:05:23 +080082 bo = intel_cmd_get_batch(cmd, &used);
Courtney Goeltzenleuchterbc407eb2014-08-22 17:54:03 -060083
Chia-I Wu1c527012014-08-23 14:57:35 +080084 if (intel_debug & INTEL_DEBUG_BATCH)
85 intel_winsys_decode_bo(winsys, bo, used);
Courtney Goeltzenleuchterbc407eb2014-08-22 17:54:03 -060086
Chia-I Wu93ada312014-08-23 15:02:25 +080087 if (intel_debug & INTEL_DEBUG_NOHW)
88 err = 0;
89 else
90 err = intel_winsys_submit_bo(winsys, queue->ring, bo, used, 0);
Chia-I Wuc5438c22014-08-19 14:03:06 +080091
92 queue->last_submitted_cmd = cmd;
93
94 return (err) ? XGL_ERROR_UNKNOWN : XGL_SUCCESS;
95}
96
Chia-I Wue09b5362014-08-07 09:25:14 +080097XGL_RESULT XGLAPI intelQueueSetGlobalMemReferences(
98 XGL_QUEUE queue,
99 XGL_UINT memRefCount,
100 const XGL_MEMORY_REF* pMemRefs)
101{
102 /*
103 * The winwys maintains the list of memory references. These are ignored
104 * until we move away from the winsys.
105 */
106 return XGL_SUCCESS;
107}
108
109XGL_RESULT XGLAPI intelQueueWaitIdle(
110 XGL_QUEUE queue_)
111{
112 struct intel_queue *queue = intel_queue(queue_);
113
114 return intel_queue_wait(queue, -1);
115}
Chia-I Wu251e7d92014-08-19 13:35:42 +0800116
117XGL_RESULT XGLAPI intelQueueSubmit(
Chia-I Wuc5438c22014-08-19 14:03:06 +0800118 XGL_QUEUE queue_,
Chia-I Wu251e7d92014-08-19 13:35:42 +0800119 XGL_UINT cmdBufferCount,
120 const XGL_CMD_BUFFER* pCmdBuffers,
121 XGL_UINT memRefCount,
122 const XGL_MEMORY_REF* pMemRefs,
Chia-I Wuc5438c22014-08-19 14:03:06 +0800123 XGL_FENCE fence_)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800124{
Chia-I Wuc5438c22014-08-19 14:03:06 +0800125 struct intel_queue *queue = intel_queue(queue_);
126 XGL_RESULT ret = XGL_SUCCESS;
127 XGL_UINT i;
128
129 for (i = 0; i < cmdBufferCount; i++) {
130 struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]);
131
132 ret = intel_queue_submit(queue, cmd);
133 if (ret != XGL_SUCCESS)
134 break;
135 }
136
137 if (ret == XGL_SUCCESS && fence_ != XGL_NULL_HANDLE) {
138 struct intel_fence *fence = intel_fence(fence_);
139 intel_fence_set_cmd(fence, queue->last_submitted_cmd);
140 }
141
142 /* XGL_MEMORY_REFs are ignored as the winsys already knows them */
143
144 return ret;
Chia-I Wu251e7d92014-08-19 13:35:42 +0800145}
146
147XGL_RESULT XGLAPI intelOpenSharedQueueSemaphore(
148 XGL_DEVICE device,
149 const XGL_QUEUE_SEMAPHORE_OPEN_INFO* pOpenInfo,
150 XGL_QUEUE_SEMAPHORE* pSemaphore)
151{
152 return XGL_ERROR_UNAVAILABLE;
153}
154
155XGL_RESULT XGLAPI intelCreateQueueSemaphore(
156 XGL_DEVICE device,
157 const XGL_QUEUE_SEMAPHORE_CREATE_INFO* pCreateInfo,
158 XGL_QUEUE_SEMAPHORE* pSemaphore)
159{
160 /*
161 * We want to find an unused semaphore register and initialize it. Signal
162 * will increment the register. Wait will atomically decrement it and
163 * block if the value is zero, or a large constant N if we do not want to
164 * go negative.
165 *
166 * XXX However, MI_SEMAPHORE_MBOX does not seem to have the flexibility.
167 */
168 return XGL_ERROR_UNAVAILABLE;
169}
170
171XGL_RESULT XGLAPI intelSignalQueueSemaphore(
172 XGL_QUEUE queue,
173 XGL_QUEUE_SEMAPHORE semaphore)
174{
175 return XGL_ERROR_UNAVAILABLE;
176}
177
178XGL_RESULT XGLAPI intelWaitQueueSemaphore(
179 XGL_QUEUE queue,
180 XGL_QUEUE_SEMAPHORE semaphore)
181{
182 return XGL_ERROR_UNAVAILABLE;
183}