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 | a54b76a | 2015-09-04 13:39:59 -0600 | [diff] [blame] | 113 | /* TODOVV: Make sure coved in validation test */ |
| 114 | // return VK_ERROR_INVALID_VALUE; |
| 115 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 116 | 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 Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 124 | return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 125 | |
| 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 Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 139 | if (ret == VK_SUCCESS) |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 140 | queue->last_pipeline_select = pipeline_select; |
| 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 145 | 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] | 146 | { |
| 147 | const uint32_t ctx_init_cmd[] = { |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 148 | /* STATE_SIP */ |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 149 | GEN6_RENDER_CMD(COMMON, STATE_SIP), |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 150 | 0, |
| 151 | /* PIPELINE_SELECT */ |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 152 | GEN6_RENDER_CMD(SINGLE_DW, PIPELINE_SELECT) | |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 153 | GEN6_PIPELINE_SELECT_DW0_SELECT_3D, |
| 154 | /* 3DSTATE_VF_STATISTICS */ |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 155 | GEN6_RENDER_CMD(SINGLE_DW, 3DSTATE_VF_STATISTICS), |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 156 | /* end */ |
Chia-I Wu | 426072d | 2014-08-26 14:31:55 +0800 | [diff] [blame] | 157 | GEN6_MI_CMD(MI_BATCH_BUFFER_END), |
| 158 | GEN6_MI_CMD(MI_NOOP), |
Chia-I Wu | 6388329 | 2014-08-25 13:50:26 +0800 | [diff] [blame] | 159 | }; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 160 | struct intel_bo *bo; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 161 | VkResult ret; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 162 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 163 | 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 Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 168 | 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] | 169 | } |
| 170 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 171 | 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 Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 175 | return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 176 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 177 | ret = queue_submit_bo(queue, bo, sizeof(ctx_init_cmd)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 178 | if (ret != VK_SUCCESS) { |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 179 | intel_bo_unref(bo); |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 180 | return ret; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 181 | } |
| 182 | |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 183 | queue->last_pipeline_select = GEN6_PIPELINE_SELECT_DW0_SELECT_3D; |
| 184 | /* reuse */ |
| 185 | queue->atomic_bo = bo; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 186 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 187 | return VK_SUCCESS; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 188 | } |
| 189 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 190 | static VkResult queue_submit_cmd_prepare(struct intel_queue *queue, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 191 | struct intel_cmd *cmd) |
| 192 | { |
Chia-I Wu | 513ae5b | 2015-07-01 19:04:59 +0800 | [diff] [blame] | 193 | if (unlikely(cmd->result != VK_SUCCESS || !cmd->primary)) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 194 | intel_dev_log(cmd->dev, VK_DBG_REPORT_ERROR_BIT, |
| 195 | &cmd->obj.base, 0, 0, |
| 196 | "invalid command buffer submitted"); |
Chia-I Wu | 513ae5b | 2015-07-01 19:04:59 +0800 | [diff] [blame] | 197 | return (cmd->primary) ? cmd->result : VK_ERROR_UNKNOWN; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | return queue_select_pipeline(queue, cmd->pipeline_select); |
| 201 | } |
| 202 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 203 | static VkResult queue_submit_cmd_debug(struct intel_queue *queue, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 204 | struct intel_cmd *cmd) |
| 205 | { |
| 206 | uint32_t active[2], pending[2]; |
| 207 | struct intel_bo *bo; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 208 | VkDeviceSize used; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 209 | VkResult ret; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 210 | |
| 211 | ret = queue_submit_cmd_prepare(queue, cmd); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 212 | if (ret != VK_SUCCESS) |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 213 | return ret; |
| 214 | |
| 215 | if (intel_debug & INTEL_DEBUG_HANG) { |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 216 | intel_winsys_get_reset_stats(queue->dev->winsys, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 217 | &active[0], &pending[0]); |
| 218 | } |
| 219 | |
| 220 | bo = intel_cmd_get_batch(cmd, &used); |
| 221 | ret = queue_submit_bo(queue, bo, used); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 222 | if (ret != VK_SUCCESS) |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 223 | return ret; |
| 224 | |
| 225 | if (intel_debug & INTEL_DEBUG_HANG) { |
| 226 | intel_bo_wait(bo, -1); |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 227 | intel_winsys_get_reset_stats(queue->dev->winsys, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 228 | &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 Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 239 | return VK_SUCCESS; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 242 | static VkResult queue_submit_cmd(struct intel_queue *queue, |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 243 | struct intel_cmd *cmd) |
| 244 | { |
| 245 | struct intel_bo *bo; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 246 | VkDeviceSize used; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 247 | VkResult ret; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 248 | |
| 249 | ret = queue_submit_cmd_prepare(queue, cmd); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 250 | if (ret == VK_SUCCESS) { |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 251 | bo = intel_cmd_get_batch(cmd, &used); |
| 252 | ret = queue_submit_bo(queue, bo, used); |
| 253 | } |
| 254 | |
| 255 | return ret; |
| 256 | } |
| 257 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 258 | VkResult intel_queue_create(struct intel_dev *dev, |
Chia-I Wu | cdcff73 | 2014-08-19 14:44:15 +0800 | [diff] [blame] | 259 | enum intel_gpu_engine_type engine, |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 260 | struct intel_queue **queue_ret) |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 261 | { |
| 262 | struct intel_queue *queue; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 263 | enum intel_ring_type ring; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 264 | VkFenceCreateInfo fence_info; |
| 265 | VkResult ret; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 266 | |
Chia-I Wu | cdcff73 | 2014-08-19 14:44:15 +0800 | [diff] [blame] | 267 | switch (engine) { |
| 268 | case INTEL_GPU_ENGINE_3D: |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 269 | ring = INTEL_RING_RENDER; |
| 270 | break; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 271 | default: |
Courtney Goeltzenleuchter | a54b76a | 2015-09-04 13:39:59 -0600 | [diff] [blame] | 272 | /* TODOVV: Verify test in validation layer */ |
| 273 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 274 | break; |
| 275 | } |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 276 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 277 | queue = (struct intel_queue *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 278 | sizeof(*queue), dev->base.dbg, VK_OBJECT_TYPE_QUEUE, NULL, 0); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 279 | if (!queue) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 280 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 281 | |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 282 | queue->dev = dev; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 283 | queue->ring = ring; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 284 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 285 | if (queue_init_hw_and_atomic_bo(queue) != VK_SUCCESS) { |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 286 | intel_queue_destroy(queue); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 287 | return VK_ERROR_INITIALIZATION_FAILED; |
Chia-I Wu | 3ad3c54 | 2014-08-25 11:09:17 +0800 | [diff] [blame] | 288 | } |
| 289 | |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 290 | memset(&fence_info, 0, sizeof(fence_info)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 291 | fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 292 | ret = intel_fence_create(dev, &fence_info, &queue->fence); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 293 | if (ret != VK_SUCCESS) { |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 294 | intel_queue_destroy(queue); |
| 295 | return ret; |
| 296 | } |
| 297 | |
Chia-I Wu | 9ae59c1 | 2014-08-07 10:08:49 +0800 | [diff] [blame] | 298 | *queue_ret = queue; |
| 299 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 300 | return VK_SUCCESS; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void intel_queue_destroy(struct intel_queue *queue) |
| 304 | { |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 305 | if (queue->fence) |
| 306 | intel_fence_destroy(queue->fence); |
| 307 | |
Chia-I Wu | cb2dc0d | 2015-03-05 16:19:42 -0700 | [diff] [blame] | 308 | intel_bo_unref(queue->atomic_bo); |
| 309 | intel_bo_unref(queue->select_graphics_bo); |
| 310 | intel_bo_unref(queue->select_compute_bo); |
Chia-I Wu | 046a7a9 | 2015-02-17 14:29:01 -0700 | [diff] [blame] | 311 | |
Chia-I Wu | bbf2c93 | 2014-08-07 12:20:08 +0800 | [diff] [blame] | 312 | intel_base_destroy(&queue->base); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 313 | } |
| 314 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 315 | VkResult intel_queue_wait(struct intel_queue *queue, int64_t timeout) |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 316 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 317 | /* return VK_SUCCESS instead of VK_ERROR_UNAVAILABLE */ |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 318 | if (!queue->fence->seqno_bo) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 319 | return VK_SUCCESS; |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 320 | |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 321 | return intel_fence_wait(queue->fence, timeout); |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 322 | } |
| 323 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 324 | ICD_EXPORT VkResult VKAPI vkQueueWaitIdle( |
| 325 | VkQueue queue_) |
Chia-I Wu | e09b536 | 2014-08-07 09:25:14 +0800 | [diff] [blame] | 326 | { |
| 327 | struct intel_queue *queue = intel_queue(queue_); |
| 328 | |
| 329 | return intel_queue_wait(queue, -1); |
| 330 | } |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 331 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 332 | ICD_EXPORT VkResult VKAPI vkQueueSubmit( |
| 333 | VkQueue queue_, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 334 | uint32_t cmdBufferCount, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 335 | const VkCmdBuffer* pCmdBuffers, |
| 336 | VkFence fence_) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 337 | { |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 338 | struct intel_queue *queue = intel_queue(queue_); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 339 | VkResult ret = VK_SUCCESS; |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 340 | struct intel_cmd *last_cmd; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 341 | uint32_t i; |
Chia-I Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 342 | |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 343 | 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 Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 347 | if (ret != VK_SUCCESS) |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 348 | 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 Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 354 | if (ret != VK_SUCCESS) |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 355 | 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 Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 365 | if (ret == VK_SUCCESS) { |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 366 | intel_fence_set_seqno(queue->fence, |
Chia-I Wu | 7b68c50 | 2015-04-17 01:37:21 +0800 | [diff] [blame] | 367 | intel_cmd_get_batch(last_cmd, NULL)); |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 368 | |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 369 | if (fence_.handle != VK_NULL_HANDLE) { |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 370 | struct intel_fence *fence = intel_fence(fence_); |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 371 | intel_fence_copy(fence, queue->fence); |
Chia-I Wu | de6f9a7 | 2015-02-17 14:11:29 -0700 | [diff] [blame] | 372 | } |
| 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 Wu | c5438c2 | 2014-08-19 14:03:06 +0800 | [diff] [blame] | 380 | |
| 381 | return ret; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 382 | } |
| 383 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 384 | ICD_EXPORT VkResult VKAPI vkCreateSemaphore( |
| 385 | VkDevice device, |
| 386 | const VkSemaphoreCreateInfo* pCreateInfo, |
| 387 | VkSemaphore* pSemaphore) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 388 | { |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 389 | // TODO: fully support semaphores (mean time, simply fake it): |
| 390 | pSemaphore->handle = 1; |
| 391 | |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 392 | /* |
| 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 Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 400 | return VK_SUCCESS; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 401 | } |
| 402 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 403 | ICD_EXPORT void VKAPI vkDestroySemaphore( |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 404 | VkDevice device, |
| 405 | VkSemaphore semaphore) |
| 406 | |
| 407 | { |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 408 | } |
| 409 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 410 | ICD_EXPORT VkResult VKAPI vkQueueSignalSemaphore( |
| 411 | VkQueue queue, |
| 412 | VkSemaphore semaphore) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 413 | { |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 414 | return VK_SUCCESS; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 415 | } |
| 416 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 417 | ICD_EXPORT VkResult VKAPI vkQueueWaitSemaphore( |
| 418 | VkQueue queue, |
| 419 | VkSemaphore semaphore) |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 420 | { |
Cody Northrop | 1d6a682 | 2015-07-23 13:00:01 -0600 | [diff] [blame] | 421 | vkQueueWaitIdle(queue); |
| 422 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 423 | return VK_SUCCESS; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 424 | } |