anv: Implement VK_EXT_global_priority_query

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11250>
This commit is contained in:
Jason Ekstrand
2021-05-25 10:30:49 -05:00
committed by Marge Bot
parent e7599f09a1
commit 39f2594531
4 changed files with 75 additions and 27 deletions

View File

@@ -256,7 +256,10 @@ get_device_extensions(const struct anv_physical_device *device,
.EXT_external_memory_dma_buf = true, .EXT_external_memory_dma_buf = true,
.EXT_external_memory_host = true, .EXT_external_memory_host = true,
.EXT_fragment_shader_interlock = device->info.ver >= 9, .EXT_fragment_shader_interlock = device->info.ver >= 9,
.EXT_global_priority = device->has_context_priority, .EXT_global_priority = device->max_context_priority >=
INTEL_CONTEXT_MEDIUM_PRIORITY,
.EXT_global_priority_query = device->max_context_priority >=
INTEL_CONTEXT_MEDIUM_PRIORITY,
.EXT_host_query_reset = true, .EXT_host_query_reset = true,
.EXT_image_robustness = true, .EXT_image_robustness = true,
.EXT_image_drm_format_modifier = true, .EXT_image_drm_format_modifier = true,
@@ -868,7 +871,18 @@ anv_physical_device_try_create(struct anv_instance *instance,
device->has_syncobj_wait_available = device->has_syncobj_wait_available =
anv_gem_get_drm_cap(fd, DRM_CAP_SYNCOBJ_TIMELINE) != 0; anv_gem_get_drm_cap(fd, DRM_CAP_SYNCOBJ_TIMELINE) != 0;
device->has_context_priority = anv_gem_has_context_priority(fd); /* Start with medium; sorted low to high */
const int priorities[] = {
INTEL_CONTEXT_MEDIUM_PRIORITY,
INTEL_CONTEXT_HIGH_PRIORITY,
INTEL_CONTEXT_REALTIME_PRIORITY,
};
device->max_context_priority = INT_MIN;
for (unsigned i = 0; i < ARRAY_SIZE(priorities); i++) {
if (!anv_gem_has_context_priority(fd, priorities[i]))
break;
device->max_context_priority = priorities[i];
}
/* Initialize memory regions struct to 0. */ /* Initialize memory regions struct to 0. */
memset(&device->vram, 0, sizeof(device->vram)); memset(&device->vram, 0, sizeof(device->vram));
@@ -1500,6 +1514,13 @@ void anv_GetPhysicalDeviceFeatures2(
break; break;
} }
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GLOBAL_PRIORITY_QUERY_FEATURES_EXT: {
VkPhysicalDeviceGlobalPriorityQueryFeaturesEXT *features =
(VkPhysicalDeviceGlobalPriorityQueryFeaturesEXT *)ext;
features->globalPriorityQuery = true;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR: { case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR: {
VkPhysicalDeviceFragmentShadingRateFeaturesKHR *features = VkPhysicalDeviceFragmentShadingRateFeaturesKHR *features =
(VkPhysicalDeviceFragmentShadingRateFeaturesKHR *)ext; (VkPhysicalDeviceFragmentShadingRateFeaturesKHR *)ext;
@@ -2494,6 +2515,23 @@ void anv_GetPhysicalDeviceProperties2(
} }
} }
static int
vk_priority_to_gen(int priority)
{
switch (priority) {
case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT:
return INTEL_CONTEXT_LOW_PRIORITY;
case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT:
return INTEL_CONTEXT_MEDIUM_PRIORITY;
case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT:
return INTEL_CONTEXT_HIGH_PRIORITY;
case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT:
return INTEL_CONTEXT_REALTIME_PRIORITY;
default:
unreachable("Invalid priority");
}
}
static const VkQueueFamilyProperties static const VkQueueFamilyProperties
anv_queue_family_properties_template = { anv_queue_family_properties_template = {
.timestampValidBits = 36, /* XXX: Real value here */ .timestampValidBits = 36, /* XXX: Real value here */
@@ -2533,8 +2571,35 @@ void anv_GetPhysicalDeviceQueueFamilyProperties2(
p->queueFamilyProperties.queueFlags = queue_family->queueFlags; p->queueFamilyProperties.queueFlags = queue_family->queueFlags;
p->queueFamilyProperties.queueCount = queue_family->queueCount; p->queueFamilyProperties.queueCount = queue_family->queueCount;
vk_foreach_struct(s, p->pNext) { vk_foreach_struct(ext, p->pNext) {
anv_debug_ignored_stype(s->sType); switch (ext->sType) {
case VK_STRUCTURE_TYPE_QUEUE_FAMILY_GLOBAL_PRIORITY_PROPERTIES_EXT: {
VkQueueFamilyGlobalPriorityPropertiesEXT *properties =
(VkQueueFamilyGlobalPriorityPropertiesEXT *)ext;
/* Deliberately sorted low to high */
VkQueueGlobalPriorityEXT all_priorities[] = {
VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT,
VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT,
VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT,
VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT,
};
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)
break;
properties->priorities[count++] = all_priorities[i];
}
properties->priorityCount = count;
break;
}
default:
anv_debug_ignored_stype(ext->sType);
}
} }
} }
} }
@@ -2773,23 +2838,6 @@ anv_device_init_trivial_batch(struct anv_device *device)
return VK_SUCCESS; return VK_SUCCESS;
} }
static int
vk_priority_to_gen(int priority)
{
switch (priority) {
case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT:
return INTEL_CONTEXT_LOW_PRIORITY;
case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT:
return INTEL_CONTEXT_MEDIUM_PRIORITY;
case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT:
return INTEL_CONTEXT_HIGH_PRIORITY;
case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT:
return INTEL_CONTEXT_REALTIME_PRIORITY;
default:
unreachable("Invalid priority");
}
}
static bool static bool
get_bo_from_pool(struct intel_batch_decode_bo *ret, get_bo_from_pool(struct intel_batch_decode_bo *ret,
struct anv_block_pool *pool, struct anv_block_pool *pool,
@@ -3087,7 +3135,7 @@ VkResult anv_CreateDevice(
* have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
* is returned. * is returned.
*/ */
if (physical_device->has_context_priority) { if (physical_device->max_context_priority >= INTEL_CONTEXT_MEDIUM_PRIORITY) {
int err = anv_gem_set_context_param(device->fd, device->context_id, int err = anv_gem_set_context_param(device->fd, device->context_id,
I915_CONTEXT_PARAM_PRIORITY, I915_CONTEXT_PARAM_PRIORITY,
vk_priority_to_gen(priority)); vk_priority_to_gen(priority));

View File

@@ -386,10 +386,10 @@ close_and_return:
} }
bool bool
anv_gem_has_context_priority(int fd) anv_gem_has_context_priority(int fd, int priority)
{ {
return !anv_gem_set_context_param(fd, 0, I915_CONTEXT_PARAM_PRIORITY, return !anv_gem_set_context_param(fd, 0, I915_CONTEXT_PARAM_PRIORITY,
INTEL_CONTEXT_MEDIUM_PRIORITY); priority);
} }
int int

View File

@@ -174,7 +174,7 @@ anv_gem_get_context_param(int fd, int context, uint32_t param, uint64_t *value)
} }
bool bool
anv_gem_has_context_priority(int fd) anv_gem_has_context_priority(int fd, int priority)
{ {
unreachable("Unused"); unreachable("Unused");
} }

View File

@@ -893,7 +893,7 @@ struct anv_physical_device {
bool has_exec_fence; bool has_exec_fence;
bool has_syncobj_wait; bool has_syncobj_wait;
bool has_syncobj_wait_available; bool has_syncobj_wait_available;
bool has_context_priority; int max_context_priority;
bool has_context_isolation; bool has_context_isolation;
bool has_thread_submit; bool has_thread_submit;
bool has_mmap_offset; bool has_mmap_offset;
@@ -1434,7 +1434,7 @@ int anv_gem_create_context_engines(struct anv_device *device,
const struct drm_i915_query_engine_info *info, const struct drm_i915_query_engine_info *info,
int num_engines, int num_engines,
uint16_t *engine_classes); uint16_t *engine_classes);
bool anv_gem_has_context_priority(int fd); bool anv_gem_has_context_priority(int fd, int priority);
int anv_gem_destroy_context(struct anv_device *device, int context); int anv_gem_destroy_context(struct anv_device *device, int context);
int anv_gem_set_context_param(int fd, int context, uint32_t param, int anv_gem_set_context_param(int fd, int context, uint32_t param,
uint64_t value); uint64_t value);