From bc384e24f00a52a5f2f130536ea2ae41dc45803a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Wed, 17 Aug 2022 12:44:29 -0700 Subject: [PATCH] anv: Use Vulkan types for priority as much as possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Continuing the work to split i915_drm.h specific code. Reviewed-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: --- src/intel/vulkan/anv_device.c | 39 +++++++++----------------------- src/intel/vulkan/anv_gem.c | 22 +++++++++++++++++- src/intel/vulkan/anv_gem_stubs.c | 2 +- src/intel/vulkan/anv_private.h | 4 ++-- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 123f27a0e16..9d993877a81 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -282,9 +282,9 @@ get_device_extensions(const struct anv_physical_device *device, .EXT_external_memory_host = true, .EXT_fragment_shader_interlock = true, .EXT_global_priority = device->max_context_priority >= - INTEL_CONTEXT_MEDIUM_PRIORITY, + VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR, .EXT_global_priority_query = device->max_context_priority >= - INTEL_CONTEXT_MEDIUM_PRIORITY, + VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR, .EXT_host_query_reset = true, .EXT_image_2d_view_of_3d = true, .EXT_image_robustness = true, @@ -776,12 +776,13 @@ anv_i915_physical_device_get_parameters(struct anv_physical_device *device) device->has_exec_capture = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_CAPTURE); /* Start with medium; sorted low to high */ - const int priorities[] = { - INTEL_CONTEXT_MEDIUM_PRIORITY, - INTEL_CONTEXT_HIGH_PRIORITY, - INTEL_CONTEXT_REALTIME_PRIORITY, + const VkQueueGlobalPriorityKHR priorities[] = { + VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR, + VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR, + VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR, + VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR, }; - device->max_context_priority = INT_MIN; + device->max_context_priority = VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR; for (unsigned i = 0; i < ARRAY_SIZE(priorities); i++) { if (!anv_gem_has_context_priority(fd, priorities[i])) break; @@ -2683,23 +2684,6 @@ void anv_GetPhysicalDeviceProperties2( } } -static int -vk_priority_to_gen(int priority) -{ - switch (priority) { - case VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR: - return INTEL_CONTEXT_LOW_PRIORITY; - case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR: - return INTEL_CONTEXT_MEDIUM_PRIORITY; - case VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR: - return INTEL_CONTEXT_HIGH_PRIORITY; - case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR: - return INTEL_CONTEXT_REALTIME_PRIORITY; - default: - unreachable("Invalid priority"); - } -} - static const VkQueueFamilyProperties anv_queue_family_properties_template = { .timestampValidBits = 36, /* XXX: Real value here */ @@ -2738,8 +2722,7 @@ void anv_GetPhysicalDeviceQueueFamilyProperties2( uint32_t count = 0; for (unsigned i = 0; i < ARRAY_SIZE(all_priorities); i++) { - if (vk_priority_to_gen(all_priorities[i]) > - pdevice->max_context_priority) + if (all_priorities[i] > pdevice->max_context_priority) break; properties->priorities[count++] = all_priorities[i]; @@ -3158,10 +3141,10 @@ anv_device_setup_context(struct anv_device *device, * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_KHR * is returned. */ - if (physical_device->max_context_priority >= INTEL_CONTEXT_MEDIUM_PRIORITY) { + if (physical_device->max_context_priority >= VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR) { int err = anv_gem_set_context_param(device->fd, device->context_id, I915_CONTEXT_PARAM_PRIORITY, - vk_priority_to_gen(priority)); + priority); if (err != 0 && priority > VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR) { result = vk_error(device, VK_ERROR_NOT_PERMITTED_KHR); goto fail_context; diff --git a/src/intel/vulkan/anv_gem.c b/src/intel/vulkan/anv_gem.c index 651bc92f6d5..9b5ef3534ed 100644 --- a/src/intel/vulkan/anv_gem.c +++ b/src/intel/vulkan/anv_gem.c @@ -296,7 +296,7 @@ anv_gem_get_param(int fd, uint32_t param) } bool -anv_gem_has_context_priority(int fd, int priority) +anv_gem_has_context_priority(int fd, VkQueueGlobalPriorityKHR priority) { return !anv_gem_set_context_param(fd, 0, I915_CONTEXT_PARAM_PRIORITY, priority); @@ -324,9 +324,29 @@ anv_gem_destroy_context(struct anv_device *device, int context) return intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); } +static int +vk_priority_to_i915(VkQueueGlobalPriorityKHR priority) +{ + switch (priority) { + case VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR: + return INTEL_CONTEXT_LOW_PRIORITY; + case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR: + return INTEL_CONTEXT_MEDIUM_PRIORITY; + case VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR: + return INTEL_CONTEXT_HIGH_PRIORITY; + case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR: + return INTEL_CONTEXT_REALTIME_PRIORITY; + default: + unreachable("Invalid priority"); + } +} + int anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value) { + if (param == I915_CONTEXT_PARAM_PRIORITY) + value = vk_priority_to_i915(value); + struct drm_i915_gem_context_param p = { .ctx_id = context, .param = param, diff --git a/src/intel/vulkan/anv_gem_stubs.c b/src/intel/vulkan/anv_gem_stubs.c index b5ef9e51500..30df5bc01e6 100644 --- a/src/intel/vulkan/anv_gem_stubs.c +++ b/src/intel/vulkan/anv_gem_stubs.c @@ -143,7 +143,7 @@ anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value) } bool -anv_gem_has_context_priority(int fd, int priority) +anv_gem_has_context_priority(int fd, VkQueueGlobalPriorityKHR priority) { unreachable("Unused"); } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 0cacad33595..9a3241da6e5 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -987,7 +987,7 @@ struct anv_physical_device { uint32_t n_perf_query_commands; bool has_exec_async; bool has_exec_capture; - int max_context_priority; + VkQueueGlobalPriorityKHR max_context_priority; bool has_context_isolation; bool has_mmap_offset; bool has_userptr_probe; @@ -1361,7 +1361,7 @@ int anv_gem_execbuffer(struct anv_device *device, int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle, uint32_t stride, uint32_t tiling); int anv_gem_create_context(struct anv_device *device); -bool anv_gem_has_context_priority(int fd, int priority); +bool anv_gem_has_context_priority(int fd, VkQueueGlobalPriorityKHR priority); int anv_gem_destroy_context(struct anv_device *device, int context); int anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value);