1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * This file implements VkQueue
26 */
27
28 #include "anv_private.h"
29
30 #include "i915/anv_queue.h"
31 #include "xe/anv_queue.h"
32
33 #include "vk_common_entrypoints.h"
34
35 static VkResult
anv_create_engine(struct anv_device * device,struct anv_queue * queue,const VkDeviceQueueCreateInfo * pCreateInfo)36 anv_create_engine(struct anv_device *device,
37 struct anv_queue *queue,
38 const VkDeviceQueueCreateInfo *pCreateInfo)
39 {
40 switch (device->info->kmd_type) {
41 case INTEL_KMD_TYPE_I915:
42 return anv_i915_create_engine(device, queue, pCreateInfo);
43 case INTEL_KMD_TYPE_XE:
44 return anv_xe_create_engine(device, queue, pCreateInfo);
45 default:
46 unreachable("Missing");
47 return VK_ERROR_UNKNOWN;
48 }
49 }
50
51 static void
anv_destroy_engine(struct anv_queue * queue)52 anv_destroy_engine(struct anv_queue *queue)
53 {
54 struct anv_device *device = queue->device;
55 switch (device->info->kmd_type) {
56 case INTEL_KMD_TYPE_I915:
57 anv_i915_destroy_engine(device, queue);
58 break;
59 case INTEL_KMD_TYPE_XE:
60 anv_xe_destroy_engine(device, queue);
61 break;
62 default:
63 unreachable("Missing");
64 }
65 }
66
67 VkResult
anv_queue_init(struct anv_device * device,struct anv_queue * queue,const VkDeviceQueueCreateInfo * pCreateInfo,uint32_t index_in_family)68 anv_queue_init(struct anv_device *device, struct anv_queue *queue,
69 const VkDeviceQueueCreateInfo *pCreateInfo,
70 uint32_t index_in_family)
71 {
72 struct anv_physical_device *pdevice = device->physical;
73 assert(queue->vk.queue_family_index < pdevice->queue.family_count);
74 struct anv_queue_family *queue_family =
75 &device->physical->queue.families[pCreateInfo->queueFamilyIndex];
76 VkResult result;
77
78 result = vk_queue_init(&queue->vk, &device->vk, pCreateInfo,
79 index_in_family);
80 if (result != VK_SUCCESS)
81 return result;
82
83 queue->vk.driver_submit = anv_queue_submit;
84 queue->device = device;
85 queue->family = queue_family;
86 queue->decoder = &device->decoder[queue->vk.queue_family_index];
87
88 result = anv_create_engine(device, queue, pCreateInfo);
89 if (result != VK_SUCCESS) {
90 vk_queue_finish(&queue->vk);
91 return result;
92 }
93
94 /* Add a debug fence to wait on submissions if we're using the synchronized
95 * submission feature, shader-print feature, or BVH dump.
96 */
97 if (INTEL_DEBUG(DEBUG_SYNC | DEBUG_SHADER_PRINT | DEBUG_BVH_ANY)) {
98 result = vk_sync_create(&device->vk,
99 &device->physical->sync_syncobj_type,
100 0, 0, &queue->sync);
101 if (result != VK_SUCCESS) {
102 anv_queue_finish(queue);
103 return result;
104 }
105 }
106
107 if (queue_family->engine_class == INTEL_ENGINE_CLASS_COPY ||
108 queue_family->engine_class == INTEL_ENGINE_CLASS_COMPUTE) {
109 result = vk_sync_create(&device->vk,
110 &device->physical->sync_syncobj_type,
111 0, 0, &queue->companion_sync);
112 if (result != VK_SUCCESS) {
113 anv_queue_finish(queue);
114 return result;
115 }
116 }
117
118 return VK_SUCCESS;
119 }
120
121 void
anv_queue_finish(struct anv_queue * queue)122 anv_queue_finish(struct anv_queue *queue)
123 {
124 if (queue->init_submit) {
125 anv_async_submit_wait(queue->init_submit);
126 anv_async_submit_destroy(queue->init_submit);
127 }
128 if (queue->init_companion_submit) {
129 anv_async_submit_wait(queue->init_companion_submit);
130 anv_async_submit_destroy(queue->init_companion_submit);
131 }
132
133 if (queue->sync)
134 vk_sync_destroy(&queue->device->vk, queue->sync);
135
136 if (queue->companion_sync)
137 vk_sync_destroy(&queue->device->vk, queue->companion_sync);
138
139 anv_destroy_engine(queue);
140 vk_queue_finish(&queue->vk);
141 }
142
143 VkResult
anv_QueueWaitIdle(VkQueue _queue)144 anv_QueueWaitIdle(VkQueue _queue)
145 {
146 VK_FROM_HANDLE(anv_queue, queue, _queue);
147 struct anv_device *device = queue->device;
148
149 switch (device->info->kmd_type) {
150 case INTEL_KMD_TYPE_XE:
151 if (queue->vk.submit.mode != VK_QUEUE_SUBMIT_MODE_THREADED) {
152 int ret = anv_xe_wait_exec_queue_idle(device, queue->exec_queue_id);
153
154 if (ret == 0)
155 return VK_SUCCESS;
156 if (ret == -ECANCELED)
157 return VK_ERROR_DEVICE_LOST;
158 return vk_errorf(device, VK_ERROR_UNKNOWN, "anv_xe_wait_exec_queue_idle failed: %m");
159 }
160 FALLTHROUGH;
161 case INTEL_KMD_TYPE_I915:
162 return vk_common_QueueWaitIdle(_queue);
163 default:
164 unreachable("Missing");
165 }
166
167 return VK_SUCCESS;
168 }
169