Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 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. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 28 | #include "genhw/genhw.h" |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 29 | #include "kmd/winsys.h" |
Chia-I Wu | 34f4518 | 2014-08-19 14:02:59 +0800 | [diff] [blame] | 30 | #include "cmd.h" |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 31 | #include "dev.h" |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 32 | #include "fence.h" |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 33 | #include "queue.h" |
| 34 | |
Chia-I Wu | 465fe21 | 2015-02-11 11:27:06 -0700 | [diff] [blame] | 35 | static 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 Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame^] | 42 | 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 Wu | 465fe21 | 2015-02-11 11:27:06 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 48 | static VkResult queue_submit_bo(struct intel_queue *queue, |
Chia-I Wu | 94d2fba | 2014-08-25 11:38:08 +0800 | [diff] [blame] | 49 | struct intel_bo *bo, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 50 | VkDeviceSize used) |
Chia-I Wu | 94d2fba | 2014-08-25 11:38:08 +0800 | [diff] [blame] | 51 | { |
| 52 | struct intel_winsys *winsys = queue->dev->winsys; |
| 53 | int err; |
| 54 | |
Chia-I Wu | 94d2fba | 2014-08-25 11:38:08 +0800 | [diff] [blame] | 55 | 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 Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 60 | return (err) ? VK_ERROR_UNKNOWN : VK_SUCCESS; |
Chia-I Wu | 94d2fba | 2014-08-25 11:38:08 +0800 | [diff] [blame] | 61 | } |
| 62 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 63 | static struct intel_bo *queue_create_bo(struct intel_queue *queue, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 64 | VkDeviceSize size, |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 65 | const void *cmd, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 66 | size_t cmd_len) |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 67 | { |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 68 | struct intel_bo *bo; |
| 69 | void *ptr; |
| 70 | |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 71 | bo = intel_winsys_alloc_bo(queue->dev->winsys, |
Chia-I Wu | 32a2246 | 2014-08-26 14:13:46 +0800 | [diff] [blame] | 72 | "queue bo", size, true); |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 73 | 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 Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 81 | intel_bo_unref(bo); |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | memcpy(ptr, cmd, cmd_len); |
| 86 | intel_bo_unmap(bo); |
| 87 | |
| 88 | return bo; |
| 89 | } |
| 90 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 91 | static VkResult queue_select_pipeline(struct intel_queue *queue, |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 92 | int pipeline_select) |
| 93 | { |
| 94 | uint32_t pipeline_select_cmd[] = { |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 95 | GEN6_RENDER_CMD(SINGLE_DW, PIPELINE_SELECT), |
| 96 | GEN6_MI_CMD(MI_BATCH_BUFFER_END), |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 97 | }; |
| 98 | struct intel_bo *bo; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 99 | VkResult ret; |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 100 | |
| 101 | if (queue->ring != INTEL_RING_RENDER || |
| 102 | queue->last_pipeline_select == pipeline_select) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 103 | return VK_SUCCESS; |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 104 | |
| 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 Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 113 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 114 | break; |
| 115 | } |
| 116 | |
| 117 | if (!bo) { |
| 118 | pipeline_select_cmd[0] |= pipeline_select; |
| 119 | bo = queue_create_bo(queue, sizeof(pipeline_select_cmd), |
| 120 | pipeline_select_cmd, sizeof(pipeline_select_cmd)); |
| 121 | if (!bo) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 122 | return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 123 | |
| 124 | switch (pipeline_select) { |
| 125 | case GEN6_PIPELINE_SELECT_DW0_SELECT_3D: |
| 126 | queue->select_graphics_bo = bo; |
| 127 | break; |
| 128 | case GEN6_PIPELINE_SELECT_DW0_SELECT_MEDIA: |
| 129 | queue->select_compute_bo = bo; |
| 130 | break; |
| 131 | default: |
| 132 | break; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | ret = queue_submit_bo(queue, bo, sizeof(pipeline_select_cmd)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 137 | if (ret == VK_SUCCESS) |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 138 | queue->last_pipeline_select = pipeline_select; |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 143 | static VkResult queue_init_hw_and_atomic_bo(struct intel_queue *queue) |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 144 | { |
| 145 | const uint32_t ctx_init_cmd[] = { |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 146 | /* STATE_SIP */ |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 147 | GEN6_RENDER_CMD(COMMON, STATE_SIP), |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 148 | 0, |
| 149 | /* PIPELINE_SELECT */ |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 150 | GEN6_RENDER_CMD(SINGLE_DW, PIPELINE_SELECT) | |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 151 | GEN6_PIPELINE_SELECT_DW0_SELECT_3D, |
| 152 | /* 3DSTATE_VF_STATISTICS */ |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 153 | GEN6_RENDER_CMD(SINGLE_DW, 3DSTATE_VF_STATISTICS), |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 154 | /* end */ |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 155 | GEN6_MI_CMD(MI_BATCH_BUFFER_END), |
| 156 | GEN6_MI_CMD(MI_NOOP), |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 157 | }; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 158 | struct intel_bo *bo; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 159 | VkResult ret; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 160 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 161 | if (queue->ring != INTEL_RING_RENDER) { |
| 162 | queue->last_pipeline_select = -1; |
| 163 | queue->atomic_bo = queue_create_bo(queue, |
| 164 | sizeof(uint32_t) * INTEL_QUEUE_ATOMIC_COUNTER_COUNT, |
| 165 | NULL, 0); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 166 | return (queue->atomic_bo) ? VK_SUCCESS : VK_ERROR_OUT_OF_DEVICE_MEMORY; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 167 | } |
| 168 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 169 | bo = queue_create_bo(queue, |
| 170 | sizeof(uint32_t) * INTEL_QUEUE_ATOMIC_COUNTER_COUNT, |
| 171 | ctx_init_cmd, sizeof(ctx_init_cmd)); |
| 172 | if (!bo) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 173 | return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 174 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 175 | ret = queue_submit_bo(queue, bo, sizeof(ctx_init_cmd)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 176 | if (ret != VK_SUCCESS) { |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 177 | intel_bo_unref(bo); |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 178 | return ret; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 179 | } |
| 180 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 181 | queue->last_pipeline_select = GEN6_PIPELINE_SELECT_DW0_SELECT_3D; |
| 182 | /* reuse */ |
| 183 | queue->atomic_bo = bo; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 184 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 185 | return VK_SUCCESS; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 186 | } |
| 187 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 188 | static VkResult queue_submit_cmd_prepare(struct intel_queue *queue, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 189 | struct intel_cmd *cmd) |
| 190 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 191 | if (unlikely(cmd->result != VK_SUCCESS)) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame^] | 192 | intel_dev_log(cmd->dev, VK_DBG_REPORT_ERROR_BIT, |
| 193 | &cmd->obj.base, 0, 0, |
| 194 | "invalid command buffer submitted"); |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 195 | return cmd->result; |
| 196 | } |
| 197 | |
| 198 | return queue_select_pipeline(queue, cmd->pipeline_select); |
| 199 | } |
| 200 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 201 | static VkResult queue_submit_cmd_debug(struct intel_queue *queue, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 202 | struct intel_cmd *cmd) |
| 203 | { |
| 204 | uint32_t active[2], pending[2]; |
| 205 | struct intel_bo *bo; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 206 | VkDeviceSize used; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 207 | VkResult ret; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 208 | |
| 209 | ret = queue_submit_cmd_prepare(queue, cmd); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 210 | if (ret != VK_SUCCESS) |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 211 | return ret; |
| 212 | |
| 213 | if (intel_debug & INTEL_DEBUG_HANG) { |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 214 | intel_winsys_get_reset_stats(queue->dev->winsys, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 215 | &active[0], &pending[0]); |
| 216 | } |
| 217 | |
| 218 | bo = intel_cmd_get_batch(cmd, &used); |
| 219 | ret = queue_submit_bo(queue, bo, used); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 220 | if (ret != VK_SUCCESS) |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 221 | return ret; |
| 222 | |
| 223 | if (intel_debug & INTEL_DEBUG_HANG) { |
| 224 | intel_bo_wait(bo, -1); |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 225 | intel_winsys_get_reset_stats(queue->dev->winsys, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 226 | &active[1], &pending[1]); |
| 227 | |
| 228 | if (active[0] != active[1] || pending[0] != pending[1]) { |
| 229 | queue_submit_hang(queue, cmd, active[1] - active[0], |
| 230 | pending[1] - pending[0]); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | if (intel_debug & INTEL_DEBUG_BATCH) |
| 235 | intel_cmd_decode(cmd, false); |
| 236 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 237 | return VK_SUCCESS; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 240 | static VkResult queue_submit_cmd(struct intel_queue *queue, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 241 | struct intel_cmd *cmd) |
| 242 | { |
| 243 | struct intel_bo *bo; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 244 | VkDeviceSize used; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 245 | VkResult ret; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 246 | |
| 247 | ret = queue_submit_cmd_prepare(queue, cmd); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 248 | if (ret == VK_SUCCESS) { |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 249 | bo = intel_cmd_get_batch(cmd, &used); |
| 250 | ret = queue_submit_bo(queue, bo, used); |
| 251 | } |
| 252 | |
| 253 | return ret; |
| 254 | } |
| 255 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 256 | VkResult intel_queue_create(struct intel_dev *dev, |
Chia-I Wu | cdcff73 | 2014-08-19 14:44:15 +0800 | [diff] [blame] | 257 | enum intel_gpu_engine_type engine, |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 258 | struct intel_queue **queue_ret) |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 259 | { |
| 260 | struct intel_queue *queue; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 261 | enum intel_ring_type ring; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 262 | VkFenceCreateInfo fence_info; |
| 263 | VkResult ret; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 264 | |
Chia-I Wu | cdcff73 | 2014-08-19 14:44:15 +0800 | [diff] [blame] | 265 | switch (engine) { |
| 266 | case INTEL_GPU_ENGINE_3D: |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 267 | ring = INTEL_RING_RENDER; |
| 268 | break; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 269 | default: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 270 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 271 | break; |
| 272 | } |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 273 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 274 | queue = (struct intel_queue *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame^] | 275 | sizeof(*queue), dev->base.dbg, VK_OBJECT_TYPE_QUEUE, NULL, 0); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 276 | if (!queue) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 277 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 278 | |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 279 | queue->dev = dev; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 280 | queue->ring = ring; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 281 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 282 | if (queue_init_hw_and_atomic_bo(queue) != VK_SUCCESS) { |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 283 | intel_queue_destroy(queue); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 284 | return VK_ERROR_INITIALIZATION_FAILED; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 285 | } |
| 286 | |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 287 | memset(&fence_info, 0, sizeof(fence_info)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 288 | fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 289 | ret = intel_fence_create(dev, &fence_info, &queue->fence); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 290 | if (ret != VK_SUCCESS) { |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 291 | intel_queue_destroy(queue); |
| 292 | return ret; |
| 293 | } |
| 294 | |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 295 | *queue_ret = queue; |
| 296 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 297 | return VK_SUCCESS; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void intel_queue_destroy(struct intel_queue *queue) |
| 301 | { |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 302 | if (queue->fence) |
| 303 | intel_fence_destroy(queue->fence); |
| 304 | |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 305 | intel_bo_unref(queue->atomic_bo); |
| 306 | intel_bo_unref(queue->select_graphics_bo); |
| 307 | intel_bo_unref(queue->select_compute_bo); |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 308 | |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 309 | intel_base_destroy(&queue->base); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 310 | } |
| 311 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 312 | VkResult intel_queue_wait(struct intel_queue *queue, int64_t timeout) |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 313 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 314 | /* return VK_SUCCESS instead of VK_ERROR_UNAVAILABLE */ |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 315 | if (!queue->fence->seqno_bo) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 316 | return VK_SUCCESS; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 317 | |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 318 | return intel_fence_wait(queue->fence, timeout); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 319 | } |
| 320 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 321 | ICD_EXPORT VkResult VKAPI vkQueueWaitIdle( |
| 322 | VkQueue queue_) |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 323 | { |
| 324 | struct intel_queue *queue = intel_queue(queue_); |
| 325 | |
| 326 | return intel_queue_wait(queue, -1); |
| 327 | } |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 328 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 329 | ICD_EXPORT VkResult VKAPI vkQueueSubmit( |
| 330 | VkQueue queue_, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 331 | uint32_t cmdBufferCount, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 332 | const VkCmdBuffer* pCmdBuffers, |
| 333 | VkFence fence_) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 334 | { |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 335 | struct intel_queue *queue = intel_queue(queue_); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 336 | VkResult ret = VK_SUCCESS; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 337 | struct intel_cmd *last_cmd; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 338 | uint32_t i; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 339 | |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 340 | if (unlikely(intel_debug)) { |
| 341 | for (i = 0; i < cmdBufferCount; i++) { |
| 342 | struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]); |
| 343 | ret = queue_submit_cmd_debug(queue, cmd); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 344 | if (ret != VK_SUCCESS) |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 345 | break; |
| 346 | } |
| 347 | } else { |
| 348 | for (i = 0; i < cmdBufferCount; i++) { |
| 349 | struct intel_cmd *cmd = intel_cmd(pCmdBuffers[i]); |
| 350 | ret = queue_submit_cmd(queue, cmd); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 351 | if (ret != VK_SUCCESS) |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 352 | break; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | /* no cmd submitted */ |
| 357 | if (i == 0) |
| 358 | return ret; |
| 359 | |
| 360 | last_cmd = intel_cmd(pCmdBuffers[i - 1]); |
| 361 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 362 | if (ret == VK_SUCCESS) { |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 363 | intel_fence_set_seqno(queue->fence, |
Chia-I Wu | 7b68c50 | 2015-04-17 01:37:21 +0800 | [diff] [blame] | 364 | intel_cmd_get_batch(last_cmd, NULL)); |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 365 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 366 | if (fence_ != VK_NULL_HANDLE) { |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 367 | struct intel_fence *fence = intel_fence(fence_); |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 368 | intel_fence_copy(fence, queue->fence); |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 369 | } |
| 370 | } else { |
| 371 | struct intel_bo *last_bo; |
| 372 | |
| 373 | /* unbusy submitted BOs */ |
| 374 | last_bo = intel_cmd_get_batch(last_cmd, NULL); |
| 375 | intel_bo_wait(last_bo, -1); |
| 376 | } |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 377 | |
| 378 | return ret; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 379 | } |
| 380 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 381 | ICD_EXPORT VkResult VKAPI vkOpenSharedSemaphore( |
| 382 | VkDevice device, |
| 383 | const VkSemaphoreOpenInfo* pOpenInfo, |
| 384 | VkSemaphore* pSemaphore) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 385 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 386 | return VK_ERROR_UNAVAILABLE; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 387 | } |
| 388 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 389 | ICD_EXPORT VkResult VKAPI vkCreateSemaphore( |
| 390 | VkDevice device, |
| 391 | const VkSemaphoreCreateInfo* pCreateInfo, |
| 392 | VkSemaphore* pSemaphore) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 393 | { |
| 394 | /* |
| 395 | * We want to find an unused semaphore register and initialize it. Signal |
| 396 | * will increment the register. Wait will atomically decrement it and |
| 397 | * block if the value is zero, or a large constant N if we do not want to |
| 398 | * go negative. |
| 399 | * |
| 400 | * XXX However, MI_SEMAPHORE_MBOX does not seem to have the flexibility. |
| 401 | */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 402 | return VK_ERROR_UNAVAILABLE; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 403 | } |
| 404 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 405 | ICD_EXPORT VkResult VKAPI vkQueueSignalSemaphore( |
| 406 | VkQueue queue, |
| 407 | VkSemaphore semaphore) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 408 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 409 | return VK_ERROR_UNAVAILABLE; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 410 | } |
| 411 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 412 | ICD_EXPORT VkResult VKAPI vkQueueWaitSemaphore( |
| 413 | VkQueue queue, |
| 414 | VkSemaphore semaphore) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 415 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 416 | return VK_ERROR_UNAVAILABLE; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 417 | } |