From b2d82c25fb62749ccf472e70c7ad6a6e97d25d60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Fri, 3 Mar 2023 11:03:18 -0800 Subject: [PATCH] anv: Properly alloc buffers that will be promoted to framebuffer in Xe KMD MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Xe KMD does a special caching handling for buffers that will be scanout to display, so that is why it needs a flag set during allocation. Checking if VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA is available in AllocateMemory() and marking the buffer as scanout. All WSI code paths but one sets VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA. The only one that doesn't requires that WSI is initialize with wsi_device_options.sw_device = true to be executed, what is not the case for ANV. Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_device.c | 15 ++++++++++++--- src/intel/vulkan/anv_private.h | 3 +++ src/intel/vulkan/xe/anv_kmd_backend.c | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 2a23bd0..d820c09 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -3959,11 +3959,20 @@ VkResult anv_AllocateMemory( } default: - if (ext->sType != VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA) - /* this isn't a real enum value, - * so use conditional to avoid compiler warn + /* VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA isn't a real + * enum value, so use conditional to avoid compiler warn + */ + if (ext->sType == VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA) { + /* TODO: Android, ChromeOS and other applications may need another + * way to allocate buffers that can be scanout to display but it + * should pretty easy to catch those as Xe KMD driver will print + * warnings in dmesg when scanning buffers allocated without + * proper flag set. */ + alloc_flags |= ANV_BO_ALLOC_SCANOUT; + } else { anv_debug_ignored_stype(ext->sType); + } break; } } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 278e384..ba0c80e 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -460,6 +460,9 @@ enum anv_bo_alloc_flags { * Should be faster for bo pools, which write but do not read */ ANV_BO_ALLOC_WRITE_COMBINE = (1 << 12), + + /** This buffer will be scanout to display */ + ANV_BO_ALLOC_SCANOUT = (1 << 13), }; struct anv_bo { diff --git a/src/intel/vulkan/xe/anv_kmd_backend.c b/src/intel/vulkan/xe/anv_kmd_backend.c index c530ff4..01784ee 100644 --- a/src/intel/vulkan/xe/anv_kmd_backend.c +++ b/src/intel/vulkan/xe/anv_kmd_backend.c @@ -37,6 +37,7 @@ xe_gem_create(struct anv_device *device, struct drm_xe_gem_create gem_create = { .vm_id = device->vm_id, .size = size, + .flags = alloc_flags & ANV_BO_ALLOC_SCANOUT ? XE_GEM_CREATE_FLAG_SCANOUT : 0, }; for (uint16_t i = 0; i < regions_count; i++) gem_create.flags |= BITFIELD_BIT(regions[i]->instance); -- 2.7.4