blob: 06455cb1133db32a3962cce6343ab3ceafda4b95 [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);
83 err = intel_winsys_submit_bo(winsys, queue->ring, bo, used, 0);
Chia-I Wuc5438c22014-08-19 14:03:06 +080084
85 queue->last_submitted_cmd = cmd;
86
87 return (err) ? XGL_ERROR_UNKNOWN : XGL_SUCCESS;
88}
89
Chia-I Wue09b5362014-08-07 09:25:14 +080090XGL_RESULT XGLAPI intelQueueSetGlobalMemReferences(
91 XGL_QUEUE queue,
92 XGL_UINT memRefCount,
93 const XGL_MEMORY_REF* pMemRefs)
94{
95 /*
96 * The winwys maintains the list of memory references. These are ignored
97 * until we move away from the winsys.
98 */
99 return XGL_SUCCESS;
100}
101
102XGL_RESULT XGLAPI intelQueueWaitIdle(
103 XGL_QUEUE queue_)
104{
105 struct intel_queue *queue = intel_queue(queue_);
106
107 return intel_queue_wait(queue, -1);
108}
Chia-I Wu251e7d92014-08-19 13:35:42 +0800109
110XGL_RESULT XGLAPI intelQueueSubmit(
Chia-I Wuc5438c22014-08-19 14:03:06 +0800111 XGL_QUEUE queue_,
Chia-I Wu251e7d92014-08-19 13:35:42 +0800112 XGL_UINT cmdBufferCount,
113 const XGL_CMD_BUFFER* pCmdBuffers,
114 XGL_UINT memRefCount,
115 const XGL_MEMORY_REF* pMemRefs,
Chia-I Wuc5438c22014-08-19 14:03:06 +0800116 XGL_FENCE fence_)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800117{
Chia-I Wuc5438c22014-08-19 14:03:06 +0800118 struct intel_queue *queue = intel_queue(queue_);
119 XGL_RESULT ret = XGL_SUCCESS;
120 XGL_UINT i;
121
122 for (i = 0; i < cmdBufferCount; i++) {
123 struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]);
124
125 ret = intel_queue_submit(queue, cmd);
126 if (ret != XGL_SUCCESS)
127 break;
128 }
129
130 if (ret == XGL_SUCCESS && fence_ != XGL_NULL_HANDLE) {
131 struct intel_fence *fence = intel_fence(fence_);
132 intel_fence_set_cmd(fence, queue->last_submitted_cmd);
133 }
134
135 /* XGL_MEMORY_REFs are ignored as the winsys already knows them */
136
137 return ret;
Chia-I Wu251e7d92014-08-19 13:35:42 +0800138}
139
140XGL_RESULT XGLAPI intelOpenSharedQueueSemaphore(
141 XGL_DEVICE device,
142 const XGL_QUEUE_SEMAPHORE_OPEN_INFO* pOpenInfo,
143 XGL_QUEUE_SEMAPHORE* pSemaphore)
144{
145 return XGL_ERROR_UNAVAILABLE;
146}
147
148XGL_RESULT XGLAPI intelCreateQueueSemaphore(
149 XGL_DEVICE device,
150 const XGL_QUEUE_SEMAPHORE_CREATE_INFO* pCreateInfo,
151 XGL_QUEUE_SEMAPHORE* pSemaphore)
152{
153 /*
154 * We want to find an unused semaphore register and initialize it. Signal
155 * will increment the register. Wait will atomically decrement it and
156 * block if the value is zero, or a large constant N if we do not want to
157 * go negative.
158 *
159 * XXX However, MI_SEMAPHORE_MBOX does not seem to have the flexibility.
160 */
161 return XGL_ERROR_UNAVAILABLE;
162}
163
164XGL_RESULT XGLAPI intelSignalQueueSemaphore(
165 XGL_QUEUE queue,
166 XGL_QUEUE_SEMAPHORE semaphore)
167{
168 return XGL_ERROR_UNAVAILABLE;
169}
170
171XGL_RESULT XGLAPI intelWaitQueueSemaphore(
172 XGL_QUEUE queue,
173 XGL_QUEUE_SEMAPHORE semaphore)
174{
175 return XGL_ERROR_UNAVAILABLE;
176}