blob: 7f11bb8578812e4e894be1a0388181d9b668399d [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 Wu34f45182014-08-19 14:02:59 +080067 struct intel_cmd *cmd = queue->last_submitted_cmd;
Chia-I Wue09b5362014-08-07 09:25:14 +080068
Chia-I Wu34f45182014-08-19 14:02:59 +080069 return (!cmd || intel_bo_wait(cmd->bo, timeout) == 0) ?
Chia-I Wue09b5362014-08-07 09:25:14 +080070 XGL_SUCCESS : XGL_ERROR_UNKNOWN;
71}
72
Chia-I Wuc5438c22014-08-19 14:03:06 +080073XGL_RESULT intel_queue_submit(struct intel_queue *queue,
74 struct intel_cmd *cmd)
75{
76 struct intel_winsys *winsys = queue->dev->winsys;
77 int err;
78
79 err = intel_winsys_submit_bo(winsys, queue->ring,
80 cmd->bo, cmd->used * sizeof(uint32_t), 0);
81
82 queue->last_submitted_cmd = cmd;
83
84 return (err) ? XGL_ERROR_UNKNOWN : XGL_SUCCESS;
85}
86
Chia-I Wue09b5362014-08-07 09:25:14 +080087XGL_RESULT XGLAPI intelQueueSetGlobalMemReferences(
88 XGL_QUEUE queue,
89 XGL_UINT memRefCount,
90 const XGL_MEMORY_REF* pMemRefs)
91{
92 /*
93 * The winwys maintains the list of memory references. These are ignored
94 * until we move away from the winsys.
95 */
96 return XGL_SUCCESS;
97}
98
99XGL_RESULT XGLAPI intelQueueWaitIdle(
100 XGL_QUEUE queue_)
101{
102 struct intel_queue *queue = intel_queue(queue_);
103
104 return intel_queue_wait(queue, -1);
105}
Chia-I Wu251e7d92014-08-19 13:35:42 +0800106
107XGL_RESULT XGLAPI intelQueueSubmit(
Chia-I Wuc5438c22014-08-19 14:03:06 +0800108 XGL_QUEUE queue_,
Chia-I Wu251e7d92014-08-19 13:35:42 +0800109 XGL_UINT cmdBufferCount,
110 const XGL_CMD_BUFFER* pCmdBuffers,
111 XGL_UINT memRefCount,
112 const XGL_MEMORY_REF* pMemRefs,
Chia-I Wuc5438c22014-08-19 14:03:06 +0800113 XGL_FENCE fence_)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800114{
Chia-I Wuc5438c22014-08-19 14:03:06 +0800115 struct intel_queue *queue = intel_queue(queue_);
116 XGL_RESULT ret = XGL_SUCCESS;
117 XGL_UINT i;
118
119 for (i = 0; i < cmdBufferCount; i++) {
120 struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]);
121
122 ret = intel_queue_submit(queue, cmd);
123 if (ret != XGL_SUCCESS)
124 break;
125 }
126
127 if (ret == XGL_SUCCESS && fence_ != XGL_NULL_HANDLE) {
128 struct intel_fence *fence = intel_fence(fence_);
129 intel_fence_set_cmd(fence, queue->last_submitted_cmd);
130 }
131
132 /* XGL_MEMORY_REFs are ignored as the winsys already knows them */
133
134 return ret;
Chia-I Wu251e7d92014-08-19 13:35:42 +0800135}
136
137XGL_RESULT XGLAPI intelOpenSharedQueueSemaphore(
138 XGL_DEVICE device,
139 const XGL_QUEUE_SEMAPHORE_OPEN_INFO* pOpenInfo,
140 XGL_QUEUE_SEMAPHORE* pSemaphore)
141{
142 return XGL_ERROR_UNAVAILABLE;
143}
144
145XGL_RESULT XGLAPI intelCreateQueueSemaphore(
146 XGL_DEVICE device,
147 const XGL_QUEUE_SEMAPHORE_CREATE_INFO* pCreateInfo,
148 XGL_QUEUE_SEMAPHORE* pSemaphore)
149{
150 /*
151 * We want to find an unused semaphore register and initialize it. Signal
152 * will increment the register. Wait will atomically decrement it and
153 * block if the value is zero, or a large constant N if we do not want to
154 * go negative.
155 *
156 * XXX However, MI_SEMAPHORE_MBOX does not seem to have the flexibility.
157 */
158 return XGL_ERROR_UNAVAILABLE;
159}
160
161XGL_RESULT XGLAPI intelSignalQueueSemaphore(
162 XGL_QUEUE queue,
163 XGL_QUEUE_SEMAPHORE semaphore)
164{
165 return XGL_ERROR_UNAVAILABLE;
166}
167
168XGL_RESULT XGLAPI intelWaitQueueSemaphore(
169 XGL_QUEUE queue,
170 XGL_QUEUE_SEMAPHORE semaphore)
171{
172 return XGL_ERROR_UNAVAILABLE;
173}