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 static VkResult
anv_create_engine(struct anv_device * device,struct anv_queue * queue,const VkDeviceQueueCreateInfo * pCreateInfo)34 anv_create_engine(struct anv_device *device,
35 struct anv_queue *queue,
36 const VkDeviceQueueCreateInfo *pCreateInfo)
37 {
38 switch (device->info->kmd_type) {
39 case INTEL_KMD_TYPE_I915:
40 return anv_i915_create_engine(device, queue, pCreateInfo);
41 case INTEL_KMD_TYPE_XE:
42 return anv_xe_create_engine(device, queue, pCreateInfo);
43 default:
44 unreachable("Missing");
45 return VK_ERROR_UNKNOWN;
46 }
47 }
48
49 static void
anv_destroy_engine(struct anv_queue * queue)50 anv_destroy_engine(struct anv_queue *queue)
51 {
52 struct anv_device *device = queue->device;
53 switch (device->info->kmd_type) {
54 case INTEL_KMD_TYPE_I915:
55 anv_i915_destroy_engine(device, queue);
56 break;
57 case INTEL_KMD_TYPE_XE:
58 anv_xe_destroy_engine(device, queue);
59 break;
60 default:
61 unreachable("Missing");
62 }
63 }
64
65 VkResult
anv_queue_init(struct anv_device * device,struct anv_queue * queue,const VkDeviceQueueCreateInfo * pCreateInfo,uint32_t index_in_family)66 anv_queue_init(struct anv_device *device, struct anv_queue *queue,
67 const VkDeviceQueueCreateInfo *pCreateInfo,
68 uint32_t index_in_family)
69 {
70 struct anv_physical_device *pdevice = device->physical;
71 assert(queue->vk.queue_family_index < pdevice->queue.family_count);
72 struct anv_queue_family *queue_family =
73 &device->physical->queue.families[pCreateInfo->queueFamilyIndex];
74 VkResult result;
75
76 result = vk_queue_init(&queue->vk, &device->vk, pCreateInfo,
77 index_in_family);
78 if (result != VK_SUCCESS)
79 return result;
80
81 queue->vk.driver_submit = anv_queue_submit;
82 queue->device = device;
83 queue->family = queue_family;
84 queue->decoder = &device->decoder[queue->vk.queue_family_index];
85
86 result = anv_create_engine(device, queue, pCreateInfo);
87 if (result != VK_SUCCESS) {
88 vk_queue_finish(&queue->vk);
89 return result;
90 }
91
92 /* Add a debug fence to wait on submissions if we're using the synchronized
93 * submission feature or the shader-print feature.
94 */
95 if (INTEL_DEBUG(DEBUG_SYNC | DEBUG_SHADER_PRINT)) {
96 result = vk_sync_create(&device->vk,
97 &device->physical->sync_syncobj_type,
98 0, 0, &queue->sync);
99 if (result != VK_SUCCESS) {
100 anv_queue_finish(queue);
101 return result;
102 }
103 }
104
105 if (queue_family->engine_class == INTEL_ENGINE_CLASS_COPY ||
106 queue_family->engine_class == INTEL_ENGINE_CLASS_COMPUTE) {
107 result = vk_sync_create(&device->vk,
108 &device->physical->sync_syncobj_type,
109 0, 0, &queue->companion_sync);
110 if (result != VK_SUCCESS) {
111 anv_queue_finish(queue);
112 return result;
113 }
114 }
115
116 return VK_SUCCESS;
117 }
118
119 void
anv_queue_finish(struct anv_queue * queue)120 anv_queue_finish(struct anv_queue *queue)
121 {
122 if (queue->init_submit) {
123 anv_async_submit_wait(queue->init_submit);
124 anv_async_submit_destroy(queue->init_submit);
125 }
126 if (queue->init_companion_submit) {
127 anv_async_submit_wait(queue->init_companion_submit);
128 anv_async_submit_destroy(queue->init_companion_submit);
129 }
130
131 if (queue->sync)
132 vk_sync_destroy(&queue->device->vk, queue->sync);
133
134 if (queue->companion_sync)
135 vk_sync_destroy(&queue->device->vk, queue->companion_sync);
136
137 anv_destroy_engine(queue);
138 vk_queue_finish(&queue->vk);
139 }
140