blob: 03ca08782b4d1cc336c4fa0927a6d9072e3f47a2 [file] [log] [blame]
Chia-I Wue09b5362014-08-07 09:25:14 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wue09b5362014-08-07 09:25:14 +08003 *
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 Wue09b5362014-08-07 09:25:14 +080026 */
27
Chia-I Wu3ad3c542014-08-25 11:09:17 +080028#include "genhw/genhw.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080029#include "kmd/winsys.h"
Chia-I Wu34f45182014-08-19 14:02:59 +080030#include "cmd.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080031#include "dev.h"
Chia-I Wuc5438c22014-08-19 14:03:06 +080032#include "fence.h"
Chia-I Wue09b5362014-08-07 09:25:14 +080033#include "queue.h"
34
Chia-I Wu465fe212015-02-11 11:27:06 -070035static void queue_submit_hang(struct intel_queue *queue,
36 struct intel_cmd *cmd,
37 uint32_t active_lost,
38 uint32_t pending_lost)
39{
40 intel_cmd_decode(cmd, true);
41
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060042 intel_dev_log(queue->dev, VK_DBG_REPORT_ERROR_BIT,
43 VK_NULL_HANDLE, 0, 0,
44 "GPU hanged with %d/%d active/pending command buffers lost",
45 active_lost, pending_lost);
Chia-I Wu465fe212015-02-11 11:27:06 -070046}
47
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060048static VkResult queue_submit_bo(struct intel_queue *queue,
Chia-I Wu94d2fba2014-08-25 11:38:08 +080049 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -060050 VkDeviceSize used)
Chia-I Wu94d2fba2014-08-25 11:38:08 +080051{
52 struct intel_winsys *winsys = queue->dev->winsys;
53 int err;
54
Chia-I Wu94d2fba2014-08-25 11:38:08 +080055 if (intel_debug & INTEL_DEBUG_NOHW)
56 err = 0;
57 else
58 err = intel_winsys_submit_bo(winsys, queue->ring, bo, used, 0);
59
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060060 return (err) ? VK_ERROR_UNKNOWN : VK_SUCCESS;
Chia-I Wu94d2fba2014-08-25 11:38:08 +080061}
62
Chia-I Wuec841722014-08-25 22:36:01 +080063static struct intel_bo *queue_create_bo(struct intel_queue *queue,
Tony Barbour8205d902015-04-16 15:59:00 -060064 VkDeviceSize size,
Chia-I Wuec841722014-08-25 22:36:01 +080065 const void *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060066 size_t cmd_len)
Chia-I Wu3ad3c542014-08-25 11:09:17 +080067{
Chia-I Wuec841722014-08-25 22:36:01 +080068 struct intel_bo *bo;
69 void *ptr;
70
Chia-I Wucb2dc0d2015-03-05 16:19:42 -070071 bo = intel_winsys_alloc_bo(queue->dev->winsys,
Chia-I Wu32a22462014-08-26 14:13:46 +080072 "queue bo", size, true);
Chia-I Wuec841722014-08-25 22:36:01 +080073 if (!bo)
74 return NULL;
75
76 if (!cmd_len)
77 return bo;
78
79 ptr = intel_bo_map(bo, true);
80 if (!ptr) {
Chia-I Wucb2dc0d2015-03-05 16:19:42 -070081 intel_bo_unref(bo);
Chia-I Wuec841722014-08-25 22:36:01 +080082 return NULL;
83 }
84
85 memcpy(ptr, cmd, cmd_len);
86 intel_bo_unmap(bo);
87
88 return bo;
89}
90
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060091static VkResult queue_select_pipeline(struct intel_queue *queue,
Chia-I Wuec841722014-08-25 22:36:01 +080092 int pipeline_select)
93{
94 uint32_t pipeline_select_cmd[] = {
Chia-I Wu426072d2014-08-26 14:31:55 +080095 GEN6_RENDER_CMD(SINGLE_DW, PIPELINE_SELECT),
96 GEN6_MI_CMD(MI_BATCH_BUFFER_END),
Chia-I Wuec841722014-08-25 22:36:01 +080097 };
98 struct intel_bo *bo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060099 VkResult ret;
Chia-I Wuec841722014-08-25 22:36:01 +0800100
101 if (queue->ring != INTEL_RING_RENDER ||
102 queue->last_pipeline_select == pipeline_select)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600103 return VK_SUCCESS;
Chia-I Wuec841722014-08-25 22:36:01 +0800104
105 switch (pipeline_select) {
106 case GEN6_PIPELINE_SELECT_DW0_SELECT_3D:
107 bo = queue->select_graphics_bo;
108 break;
109 case GEN6_PIPELINE_SELECT_DW0_SELECT_MEDIA:
110 bo = queue->select_compute_bo;
111 break;
112 default:
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -0600113 /* TODOVV: Make sure coved in validation test */
114// return VK_ERROR_INVALID_VALUE;
115 return VK_ERROR_UNKNOWN;
Chia-I Wuec841722014-08-25 22:36:01 +0800116 break;
117 }
118
119 if (!bo) {
120 pipeline_select_cmd[0] |= pipeline_select;
121 bo = queue_create_bo(queue, sizeof(pipeline_select_cmd),
122 pipeline_select_cmd, sizeof(pipeline_select_cmd));
123 if (!bo)
Tony Barbour8205d902015-04-16 15:59:00 -0600124 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
Chia-I Wuec841722014-08-25 22:36:01 +0800125
126 switch (pipeline_select) {
127 case GEN6_PIPELINE_SELECT_DW0_SELECT_3D:
128 queue->select_graphics_bo = bo;
129 break;
130 case GEN6_PIPELINE_SELECT_DW0_SELECT_MEDIA:
131 queue->select_compute_bo = bo;
132 break;
133 default:
134 break;
135 }
136 }
137
138 ret = queue_submit_bo(queue, bo, sizeof(pipeline_select_cmd));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600139 if (ret == VK_SUCCESS)
Chia-I Wuec841722014-08-25 22:36:01 +0800140 queue->last_pipeline_select = pipeline_select;
141
142 return ret;
143}
144
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600145static VkResult queue_init_hw_and_atomic_bo(struct intel_queue *queue)
Chia-I Wuec841722014-08-25 22:36:01 +0800146{
147 const uint32_t ctx_init_cmd[] = {
Chia-I Wu63883292014-08-25 13:50:26 +0800148 /* STATE_SIP */
Chia-I Wu426072d2014-08-26 14:31:55 +0800149 GEN6_RENDER_CMD(COMMON, STATE_SIP),
Chia-I Wu63883292014-08-25 13:50:26 +0800150 0,
151 /* PIPELINE_SELECT */
Chia-I Wu426072d2014-08-26 14:31:55 +0800152 GEN6_RENDER_CMD(SINGLE_DW, PIPELINE_SELECT) |
Chia-I Wu63883292014-08-25 13:50:26 +0800153 GEN6_PIPELINE_SELECT_DW0_SELECT_3D,
154 /* 3DSTATE_VF_STATISTICS */
Chia-I Wu426072d2014-08-26 14:31:55 +0800155 GEN6_RENDER_CMD(SINGLE_DW, 3DSTATE_VF_STATISTICS),
Chia-I Wu63883292014-08-25 13:50:26 +0800156 /* end */
Chia-I Wu426072d2014-08-26 14:31:55 +0800157 GEN6_MI_CMD(MI_BATCH_BUFFER_END),
158 GEN6_MI_CMD(MI_NOOP),
Chia-I Wu63883292014-08-25 13:50:26 +0800159 };
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800160 struct intel_bo *bo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600161 VkResult ret;
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800162
Chia-I Wuec841722014-08-25 22:36:01 +0800163 if (queue->ring != INTEL_RING_RENDER) {
164 queue->last_pipeline_select = -1;
165 queue->atomic_bo = queue_create_bo(queue,
166 sizeof(uint32_t) * INTEL_QUEUE_ATOMIC_COUNTER_COUNT,
167 NULL, 0);
Tony Barbour8205d902015-04-16 15:59:00 -0600168 return (queue->atomic_bo) ? VK_SUCCESS : VK_ERROR_OUT_OF_DEVICE_MEMORY;
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800169 }
170
Chia-I Wuec841722014-08-25 22:36:01 +0800171 bo = queue_create_bo(queue,
172 sizeof(uint32_t) * INTEL_QUEUE_ATOMIC_COUNTER_COUNT,
173 ctx_init_cmd, sizeof(ctx_init_cmd));
174 if (!bo)
Tony Barbour8205d902015-04-16 15:59:00 -0600175 return VK_ERROR_OUT_OF_DEVICE_MEMORY;
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800176
Chia-I Wuec841722014-08-25 22:36:01 +0800177 ret = queue_submit_bo(queue, bo, sizeof(ctx_init_cmd));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600178 if (ret != VK_SUCCESS) {
Chia-I Wucb2dc0d2015-03-05 16:19:42 -0700179 intel_bo_unref(bo);
Chia-I Wuec841722014-08-25 22:36:01 +0800180 return ret;
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800181 }
182
Chia-I Wuec841722014-08-25 22:36:01 +0800183 queue->last_pipeline_select = GEN6_PIPELINE_SELECT_DW0_SELECT_3D;
184 /* reuse */
185 queue->atomic_bo = bo;
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800186
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600187 return VK_SUCCESS;
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800188}
189
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600190static VkResult queue_submit_cmd_prepare(struct intel_queue *queue,
Chia-I Wude6f9a72015-02-17 14:11:29 -0700191 struct intel_cmd *cmd)
192{
Chia-I Wu513ae5b2015-07-01 19:04:59 +0800193 if (unlikely(cmd->result != VK_SUCCESS || !cmd->primary)) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600194 intel_dev_log(cmd->dev, VK_DBG_REPORT_ERROR_BIT,
195 &cmd->obj.base, 0, 0,
196 "invalid command buffer submitted");
Chia-I Wu513ae5b2015-07-01 19:04:59 +0800197 return (cmd->primary) ? cmd->result : VK_ERROR_UNKNOWN;
Chia-I Wude6f9a72015-02-17 14:11:29 -0700198 }
199
200 return queue_select_pipeline(queue, cmd->pipeline_select);
201}
202
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600203static VkResult queue_submit_cmd_debug(struct intel_queue *queue,
Chia-I Wude6f9a72015-02-17 14:11:29 -0700204 struct intel_cmd *cmd)
205{
206 uint32_t active[2], pending[2];
207 struct intel_bo *bo;
Tony Barbour8205d902015-04-16 15:59:00 -0600208 VkDeviceSize used;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600209 VkResult ret;
Chia-I Wude6f9a72015-02-17 14:11:29 -0700210
211 ret = queue_submit_cmd_prepare(queue, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600212 if (ret != VK_SUCCESS)
Chia-I Wude6f9a72015-02-17 14:11:29 -0700213 return ret;
214
215 if (intel_debug & INTEL_DEBUG_HANG) {
Chia-I Wucb2dc0d2015-03-05 16:19:42 -0700216 intel_winsys_get_reset_stats(queue->dev->winsys,
Chia-I Wude6f9a72015-02-17 14:11:29 -0700217 &active[0], &pending[0]);
218 }
219
220 bo = intel_cmd_get_batch(cmd, &used);
221 ret = queue_submit_bo(queue, bo, used);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600222 if (ret != VK_SUCCESS)
Chia-I Wude6f9a72015-02-17 14:11:29 -0700223 return ret;
224
225 if (intel_debug & INTEL_DEBUG_HANG) {
226 intel_bo_wait(bo, -1);
Chia-I Wucb2dc0d2015-03-05 16:19:42 -0700227 intel_winsys_get_reset_stats(queue->dev->winsys,
Chia-I Wude6f9a72015-02-17 14:11:29 -0700228 &active[1], &pending[1]);
229
230 if (active[0] != active[1] || pending[0] != pending[1]) {
231 queue_submit_hang(queue, cmd, active[1] - active[0],
232 pending[1] - pending[0]);
233 }
234 }
235
236 if (intel_debug & INTEL_DEBUG_BATCH)
237 intel_cmd_decode(cmd, false);
238
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600239 return VK_SUCCESS;
Chia-I Wude6f9a72015-02-17 14:11:29 -0700240}
241
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242static VkResult queue_submit_cmd(struct intel_queue *queue,
Chia-I Wude6f9a72015-02-17 14:11:29 -0700243 struct intel_cmd *cmd)
244{
245 struct intel_bo *bo;
Tony Barbour8205d902015-04-16 15:59:00 -0600246 VkDeviceSize used;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600247 VkResult ret;
Chia-I Wude6f9a72015-02-17 14:11:29 -0700248
249 ret = queue_submit_cmd_prepare(queue, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250 if (ret == VK_SUCCESS) {
Chia-I Wude6f9a72015-02-17 14:11:29 -0700251 bo = intel_cmd_get_batch(cmd, &used);
252 ret = queue_submit_bo(queue, bo, used);
253 }
254
255 return ret;
256}
257
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600258VkResult intel_queue_create(struct intel_dev *dev,
Chia-I Wucdcff732014-08-19 14:44:15 +0800259 enum intel_gpu_engine_type engine,
Chia-I Wu9ae59c12014-08-07 10:08:49 +0800260 struct intel_queue **queue_ret)
Chia-I Wue09b5362014-08-07 09:25:14 +0800261{
262 struct intel_queue *queue;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800263 enum intel_ring_type ring;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600264 VkFenceCreateInfo fence_info;
265 VkResult ret;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800266
Chia-I Wucdcff732014-08-19 14:44:15 +0800267 switch (engine) {
268 case INTEL_GPU_ENGINE_3D:
Chia-I Wuc5438c22014-08-19 14:03:06 +0800269 ring = INTEL_RING_RENDER;
270 break;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800271 default:
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -0600272 /* TODOVV: Verify test in validation layer */
273 return VK_ERROR_UNKNOWN;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800274 break;
275 }
Chia-I Wue09b5362014-08-07 09:25:14 +0800276
Chia-I Wu545c2e12015-02-22 13:19:54 +0800277 queue = (struct intel_queue *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600278 sizeof(*queue), dev->base.dbg, VK_OBJECT_TYPE_QUEUE, NULL, 0);
Chia-I Wue09b5362014-08-07 09:25:14 +0800279 if (!queue)
Tony Barbour8205d902015-04-16 15:59:00 -0600280 return VK_ERROR_OUT_OF_HOST_MEMORY;
Chia-I Wue09b5362014-08-07 09:25:14 +0800281
Chia-I Wue09b5362014-08-07 09:25:14 +0800282 queue->dev = dev;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800283 queue->ring = ring;
Chia-I Wue09b5362014-08-07 09:25:14 +0800284
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600285 if (queue_init_hw_and_atomic_bo(queue) != VK_SUCCESS) {
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800286 intel_queue_destroy(queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600287 return VK_ERROR_INITIALIZATION_FAILED;
Chia-I Wu3ad3c542014-08-25 11:09:17 +0800288 }
289
Chia-I Wub56f5df2015-04-04 20:21:10 +0800290 memset(&fence_info, 0, sizeof(fence_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600291 fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
Chia-I Wub56f5df2015-04-04 20:21:10 +0800292 ret = intel_fence_create(dev, &fence_info, &queue->fence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600293 if (ret != VK_SUCCESS) {
Chia-I Wub56f5df2015-04-04 20:21:10 +0800294 intel_queue_destroy(queue);
295 return ret;
296 }
297
Chia-I Wu9ae59c12014-08-07 10:08:49 +0800298 *queue_ret = queue;
299
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600300 return VK_SUCCESS;
Chia-I Wue09b5362014-08-07 09:25:14 +0800301}
302
303void intel_queue_destroy(struct intel_queue *queue)
304{
Chia-I Wub56f5df2015-04-04 20:21:10 +0800305 if (queue->fence)
306 intel_fence_destroy(queue->fence);
307
Chia-I Wucb2dc0d2015-03-05 16:19:42 -0700308 intel_bo_unref(queue->atomic_bo);
309 intel_bo_unref(queue->select_graphics_bo);
310 intel_bo_unref(queue->select_compute_bo);
Chia-I Wu046a7a92015-02-17 14:29:01 -0700311
Chia-I Wubbf2c932014-08-07 12:20:08 +0800312 intel_base_destroy(&queue->base);
Chia-I Wue09b5362014-08-07 09:25:14 +0800313}
314
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600315VkResult intel_queue_wait(struct intel_queue *queue, int64_t timeout)
Chia-I Wue09b5362014-08-07 09:25:14 +0800316{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600317 /* return VK_SUCCESS instead of VK_ERROR_UNAVAILABLE */
Chia-I Wub56f5df2015-04-04 20:21:10 +0800318 if (!queue->fence->seqno_bo)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600319 return VK_SUCCESS;
Chia-I Wue09b5362014-08-07 09:25:14 +0800320
Chia-I Wub56f5df2015-04-04 20:21:10 +0800321 return intel_fence_wait(queue->fence, timeout);
Chia-I Wue09b5362014-08-07 09:25:14 +0800322}
323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324ICD_EXPORT VkResult VKAPI vkQueueWaitIdle(
325 VkQueue queue_)
Chia-I Wue09b5362014-08-07 09:25:14 +0800326{
327 struct intel_queue *queue = intel_queue(queue_);
328
329 return intel_queue_wait(queue, -1);
330}
Chia-I Wu251e7d92014-08-19 13:35:42 +0800331
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600332ICD_EXPORT VkResult VKAPI vkQueueSubmit(
333 VkQueue queue_,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600334 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600335 const VkCmdBuffer* pCmdBuffers,
336 VkFence fence_)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800337{
Chia-I Wuc5438c22014-08-19 14:03:06 +0800338 struct intel_queue *queue = intel_queue(queue_);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600339 VkResult ret = VK_SUCCESS;
Chia-I Wude6f9a72015-02-17 14:11:29 -0700340 struct intel_cmd *last_cmd;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600341 uint32_t i;
Chia-I Wuc5438c22014-08-19 14:03:06 +0800342
Chia-I Wude6f9a72015-02-17 14:11:29 -0700343 if (unlikely(intel_debug)) {
344 for (i = 0; i < cmdBufferCount; i++) {
345 struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]);
346 ret = queue_submit_cmd_debug(queue, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600347 if (ret != VK_SUCCESS)
Chia-I Wude6f9a72015-02-17 14:11:29 -0700348 break;
349 }
350 } else {
351 for (i = 0; i < cmdBufferCount; i++) {
352 struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]);
353 ret = queue_submit_cmd(queue, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600354 if (ret != VK_SUCCESS)
Chia-I Wude6f9a72015-02-17 14:11:29 -0700355 break;
356 }
357 }
358
359 /* no cmd submitted */
360 if (i == 0)
361 return ret;
362
363 last_cmd = intel_cmd(pCmdBuffers[i - 1]);
364
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365 if (ret == VK_SUCCESS) {
Chia-I Wub56f5df2015-04-04 20:21:10 +0800366 intel_fence_set_seqno(queue->fence,
Chia-I Wu7b68c502015-04-17 01:37:21 +0800367 intel_cmd_get_batch(last_cmd, NULL));
Chia-I Wude6f9a72015-02-17 14:11:29 -0700368
Tony Barbourde4124d2015-07-03 10:33:54 -0600369 if (fence_.handle != VK_NULL_HANDLE) {
Chia-I Wude6f9a72015-02-17 14:11:29 -0700370 struct intel_fence *fence = intel_fence(fence_);
Chia-I Wub56f5df2015-04-04 20:21:10 +0800371 intel_fence_copy(fence, queue->fence);
Chia-I Wude6f9a72015-02-17 14:11:29 -0700372 }
373 } else {
374 struct intel_bo *last_bo;
375
376 /* unbusy submitted BOs */
377 last_bo = intel_cmd_get_batch(last_cmd, NULL);
378 intel_bo_wait(last_bo, -1);
379 }
Chia-I Wuc5438c22014-08-19 14:03:06 +0800380
381 return ret;
Chia-I Wu251e7d92014-08-19 13:35:42 +0800382}
383
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600384ICD_EXPORT VkResult VKAPI vkCreateSemaphore(
385 VkDevice device,
386 const VkSemaphoreCreateInfo* pCreateInfo,
387 VkSemaphore* pSemaphore)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800388{
Ian Elliott4f299362015-07-06 14:45:11 -0600389 // TODO: fully support semaphores (mean time, simply fake it):
390 pSemaphore->handle = 1;
391
Chia-I Wu251e7d92014-08-19 13:35:42 +0800392 /*
393 * We want to find an unused semaphore register and initialize it. Signal
394 * will increment the register. Wait will atomically decrement it and
395 * block if the value is zero, or a large constant N if we do not want to
396 * go negative.
397 *
398 * XXX However, MI_SEMAPHORE_MBOX does not seem to have the flexibility.
399 */
Ian Elliott4f299362015-07-06 14:45:11 -0600400 return VK_SUCCESS;
Chia-I Wu251e7d92014-08-19 13:35:42 +0800401}
402
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600403ICD_EXPORT void VKAPI vkDestroySemaphore(
Tony Barbourde4124d2015-07-03 10:33:54 -0600404 VkDevice device,
405 VkSemaphore semaphore)
406
407 {
Tony Barbourde4124d2015-07-03 10:33:54 -0600408 }
409
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600410ICD_EXPORT VkResult VKAPI vkQueueSignalSemaphore(
411 VkQueue queue,
412 VkSemaphore semaphore)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800413{
Ian Elliott4f299362015-07-06 14:45:11 -0600414 return VK_SUCCESS;
Chia-I Wu251e7d92014-08-19 13:35:42 +0800415}
416
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600417ICD_EXPORT VkResult VKAPI vkQueueWaitSemaphore(
418 VkQueue queue,
419 VkSemaphore semaphore)
Chia-I Wu251e7d92014-08-19 13:35:42 +0800420{
Cody Northrop1d6a6822015-07-23 13:00:01 -0600421 vkQueueWaitIdle(queue);
422
Ian Elliott4f299362015-07-06 14:45:11 -0600423 return VK_SUCCESS;
Chia-I Wu251e7d92014-08-19 13:35:42 +0800424}