• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2023 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 shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #include "i915/anv_queue.h"
24 
25 #include "anv_private.h"
26 
27 #include "common/i915/intel_engine.h"
28 #include "common/intel_gem.h"
29 
30 #include "i915/anv_device.h"
31 
32 #include "drm-uapi/i915_drm.h"
33 
34 VkResult
anv_i915_create_engine(struct anv_device * device,struct anv_queue * queue,const VkDeviceQueueCreateInfo * pCreateInfo)35 anv_i915_create_engine(struct anv_device *device,
36                        struct anv_queue *queue,
37                        const VkDeviceQueueCreateInfo *pCreateInfo)
38 {
39    struct anv_physical_device *physical = device->physical;
40    struct anv_queue_family *queue_family =
41       &physical->queue.families[pCreateInfo->queueFamilyIndex];
42 
43    if (device->physical->engine_info == NULL) {
44       switch (queue_family->engine_class) {
45       case INTEL_ENGINE_CLASS_COPY:
46          queue->exec_flags = I915_EXEC_BLT;
47          break;
48       case INTEL_ENGINE_CLASS_RENDER:
49          queue->exec_flags = I915_EXEC_RENDER;
50          break;
51       case INTEL_ENGINE_CLASS_VIDEO:
52          /* We want VCS0 (with ring1) for HW lacking HEVC on VCS1. */
53          queue->exec_flags = I915_EXEC_BSD | I915_EXEC_BSD_RING1;
54          break;
55       default:
56          unreachable("Unsupported legacy engine");
57       }
58    } else if (device->physical->has_vm_control) {
59       assert(pCreateInfo->queueFamilyIndex < physical->queue.family_count);
60       enum intel_engine_class engine_classes[1];
61       engine_classes[0] = queue_family->engine_class;
62       if (!intel_gem_create_context_engines(device->fd, 0 /* flags */,
63                                             physical->engine_info,
64                                             1, engine_classes,
65                                             device->vm_id,
66                                             (uint32_t *)&queue->context_id))
67          return vk_errorf(device, VK_ERROR_INITIALIZATION_FAILED,
68                           "engine creation failed");
69 
70       /* Create a companion RCS logical engine to support MSAA copy/clear
71        * operation on compute/copy engine.
72        */
73       if (queue_family->engine_class == INTEL_ENGINE_CLASS_COPY ||
74           queue_family->engine_class == INTEL_ENGINE_CLASS_COMPUTE) {
75          uint32_t *context_id = (uint32_t *)&queue->companion_rcs_id;
76          engine_classes[0] = INTEL_ENGINE_CLASS_RENDER;
77          if (!intel_gem_create_context_engines(device->fd, 0 /* flags */,
78                                                physical->engine_info,
79                                                1, engine_classes,
80                                                device->vm_id,
81                                                context_id))
82             return vk_errorf(device, VK_ERROR_INITIALIZATION_FAILED,
83                              "companion RCS engine creation failed");
84       }
85 
86       /* Check if client specified queue priority. */
87       const VkDeviceQueueGlobalPriorityCreateInfoKHR *queue_priority =
88          vk_find_struct_const(pCreateInfo->pNext,
89                               DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_KHR);
90 
91       VkResult result = anv_i915_set_queue_parameters(device,
92                                                       queue->context_id,
93                                                       queue_priority);
94       if (result != VK_SUCCESS) {
95          intel_gem_destroy_context(device->fd, queue->context_id);
96          if (queue->companion_rcs_id != 0) {
97             intel_gem_destroy_context(device->fd, queue->companion_rcs_id);
98          }
99          return result;
100       }
101    } else {
102       /* When using the new engine creation uAPI, the exec_flags value is the
103        * index of the engine in the group specified at GEM context creation.
104        */
105       queue->exec_flags = device->queue_count;
106    }
107 
108    return VK_SUCCESS;
109 }
110 
111 void
anv_i915_destroy_engine(struct anv_device * device,struct anv_queue * queue)112 anv_i915_destroy_engine(struct anv_device *device, struct anv_queue *queue)
113 {
114    if (device->physical->has_vm_control) {
115       intel_gem_destroy_context(device->fd, queue->context_id);
116 
117       if (queue->companion_rcs_id != 0) {
118          intel_gem_destroy_context(device->fd, queue->companion_rcs_id);
119       }
120    }
121 }
122