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/i915/intel_gem.h"
29 #include "common/intel_gem.h"
30
31 #include "i915/anv_device.h"
32
33 #include "drm-uapi/i915_drm.h"
34
35 VkResult
anv_i915_create_engine(struct anv_device * device,struct anv_queue * queue,const VkDeviceQueueCreateInfo * pCreateInfo)36 anv_i915_create_engine(struct anv_device *device,
37 struct anv_queue *queue,
38 const VkDeviceQueueCreateInfo *pCreateInfo)
39 {
40 struct anv_physical_device *physical = device->physical;
41 struct anv_queue_family *queue_family =
42 &physical->queue.families[pCreateInfo->queueFamilyIndex];
43
44 if (device->physical->engine_info == NULL) {
45 switch (queue_family->engine_class) {
46 case INTEL_ENGINE_CLASS_COPY:
47 queue->exec_flags = I915_EXEC_BLT;
48 break;
49 case INTEL_ENGINE_CLASS_RENDER:
50 queue->exec_flags = I915_EXEC_RENDER;
51 break;
52 case INTEL_ENGINE_CLASS_VIDEO:
53 /* We want VCS0 (with ring1) for HW lacking HEVC on VCS1. */
54 queue->exec_flags = I915_EXEC_BSD | I915_EXEC_BSD_RING1;
55 break;
56 default:
57 unreachable("Unsupported legacy engine");
58 }
59 } else if (device->physical->has_vm_control) {
60 assert(pCreateInfo->queueFamilyIndex < physical->queue.family_count);
61 enum intel_engine_class engine_classes[1];
62 enum intel_gem_create_context_flags flags = 0;
63 int val = 0;
64
65 engine_classes[0] = queue_family->engine_class;
66 if (pCreateInfo->flags & VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT)
67 flags |= INTEL_GEM_CREATE_CONTEXT_EXT_PROTECTED_FLAG;
68
69 if (device->physical->instance->force_guc_low_latency &&
70 i915_gem_get_param(device->fd, I915_PARAM_HAS_CONTEXT_FREQ_HINT, &val) && (val == 1)) {
71 flags |= INTEL_GEM_CREATE_CONTEXT_EXT_LOW_LATENCY_FLAG;
72 }
73
74 if (!intel_gem_create_context_engines(device->fd, flags,
75 physical->engine_info,
76 1, engine_classes,
77 device->vm_id,
78 (uint32_t *)&queue->context_id))
79 return vk_errorf(device, VK_ERROR_INITIALIZATION_FAILED,
80 "engine creation failed");
81
82 /* Create a companion RCS logical engine to support MSAA copy/clear
83 * operation on compute/copy engine.
84 */
85 if (queue_family->engine_class == INTEL_ENGINE_CLASS_COPY ||
86 queue_family->engine_class == INTEL_ENGINE_CLASS_COMPUTE) {
87 uint32_t *context_id = (uint32_t *)&queue->companion_rcs_id;
88 engine_classes[0] = INTEL_ENGINE_CLASS_RENDER;
89 if (!intel_gem_create_context_engines(device->fd, flags,
90 physical->engine_info,
91 1, engine_classes,
92 device->vm_id,
93 context_id))
94 return vk_errorf(device, VK_ERROR_INITIALIZATION_FAILED,
95 "companion RCS engine creation failed");
96 }
97
98 /* Check if client specified queue priority. */
99 const VkDeviceQueueGlobalPriorityCreateInfoKHR *queue_priority =
100 vk_find_struct_const(pCreateInfo->pNext,
101 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_KHR);
102
103 VkResult result = anv_i915_set_queue_parameters(device,
104 queue->context_id,
105 queue_priority);
106 if (result != VK_SUCCESS) {
107 intel_gem_destroy_context(device->fd, queue->context_id);
108 if (queue->companion_rcs_id != 0) {
109 intel_gem_destroy_context(device->fd, queue->companion_rcs_id);
110 }
111 return result;
112 }
113 } else {
114 /* When using the new engine creation uAPI, the exec_flags value is the
115 * index of the engine in the group specified at GEM context creation.
116 */
117 queue->exec_flags = device->queue_count;
118 }
119
120 return VK_SUCCESS;
121 }
122
123 void
anv_i915_destroy_engine(struct anv_device * device,struct anv_queue * queue)124 anv_i915_destroy_engine(struct anv_device *device, struct anv_queue *queue)
125 {
126 if (device->physical->has_vm_control) {
127 intel_gem_destroy_context(device->fd, queue->context_id);
128
129 if (queue->companion_rcs_id != 0) {
130 intel_gem_destroy_context(device->fd, queue->companion_rcs_id);
131 }
132 }
133 }
134