• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    if (INTEL_DEBUG(DEBUG_SYNC)) {
93       result = vk_sync_create(&device->vk,
94                               &device->physical->sync_syncobj_type,
95                               0, 0, &queue->sync);
96       if (result != VK_SUCCESS) {
97          anv_queue_finish(queue);
98          return result;
99       }
100    }
101 
102    if (queue_family->engine_class == INTEL_ENGINE_CLASS_COPY ||
103        queue_family->engine_class == INTEL_ENGINE_CLASS_COMPUTE) {
104       result = vk_sync_create(&device->vk,
105                               &device->physical->sync_syncobj_type,
106                               0, 0, &queue->companion_sync);
107       if (result != VK_SUCCESS) {
108          anv_queue_finish(queue);
109          return result;
110       }
111    }
112 
113    return VK_SUCCESS;
114 }
115 
116 void
anv_queue_finish(struct anv_queue * queue)117 anv_queue_finish(struct anv_queue *queue)
118 {
119    if (queue->sync)
120       vk_sync_destroy(&queue->device->vk, queue->sync);
121 
122    if (queue->companion_sync)
123       vk_sync_destroy(&queue->device->vk, queue->companion_sync);
124 
125    anv_destroy_engine(queue);
126    vk_queue_finish(&queue->vk);
127 }
128