anv: Add support all possible cached and coherent memory types

This changes allow us to support HOST_COHERENT, HOST_CACHED and
HOST_COHERENT + HOST_CACHED memory types for platforms that has
the PAT uAPI.

Be aware that Xe KMD will not be able to support cached only memory
types, anv_xe_physical_device_init_memory_types() will reflect that
but internal usage should not allocate
VK_MEMORY_PROPERTY_HOST_CACHED_BIT only memory, hence the assert
added.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25462>
This commit is contained in:
José Roberto de Souza 2023-09-13 08:16:49 -07:00 committed by Marge Bot
parent 3baab9bb38
commit d491742d19
4 changed files with 22 additions and 4 deletions

View file

@ -1463,6 +1463,10 @@ anv_device_alloc_bo(struct anv_device *device,
uint64_t explicit_address,
struct anv_bo **bo_out)
{
/* bo can only be one: cached+coherent, cached(incoherent) or coherent(no flags) */
assert(!(!!(alloc_flags & ANV_BO_ALLOC_HOST_CACHED_COHERENT) &&
!!(alloc_flags & ANV_BO_ALLOC_HOST_CACHED)));
const uint32_t bo_flags =
device->kmd_backend->bo_alloc_flags_to_bo_flags(device, alloc_flags);

View file

@ -4146,10 +4146,13 @@ VkResult anv_AllocateMemory(
if (mem->vk.export_handle_types || mem->vk.import_handle_type)
alloc_flags |= (ANV_BO_ALLOC_EXTERNAL | ANV_BO_ALLOC_IMPLICIT_SYNC);
if ((mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) &&
(mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) &&
(alloc_flags & (ANV_BO_ALLOC_EXTERNAL | ANV_BO_ALLOC_SCANOUT)) == 0)
alloc_flags |= ANV_BO_ALLOC_HOST_CACHED_COHERENT;
if ((alloc_flags & (ANV_BO_ALLOC_EXTERNAL | ANV_BO_ALLOC_SCANOUT)) == 0) {
if ((mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) &&
(mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT))
alloc_flags |= ANV_BO_ALLOC_HOST_CACHED_COHERENT;
else if (mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT)
alloc_flags |= ANV_BO_ALLOC_HOST_CACHED;
}
if (mem->vk.ahardware_buffer) {
result = anv_import_ahw_memory(_device, mem);
@ -5188,6 +5191,8 @@ anv_device_get_pat_entry(struct anv_device *device,
return &device->info->pat.cached_coherent;
else if (alloc_flags & (ANV_BO_ALLOC_EXTERNAL | ANV_BO_ALLOC_SCANOUT))
return &device->info->pat.scanout;
else if (alloc_flags & ANV_BO_ALLOC_HOST_CACHED)
return &device->info->pat.writeback_incoherent;
else
return &device->info->pat.writecombining;
}

View file

@ -425,6 +425,13 @@ enum anv_bo_alloc_flags {
/** Protected buffer */
ANV_BO_ALLOC_PROTECTED = (1 << 15),
/** Specifies that the BO should be cached and incoherent.
*
* If ANV_BO_ALLOC_HOST_CACHED or ANV_BO_ALLOC_HOST_CACHED_COHERENT are not
* set it will allocate a coherent BO.
**/
ANV_BO_ALLOC_HOST_CACHED = (1 << 16),
};
struct anv_bo {

View file

@ -42,6 +42,8 @@ xe_gem_create(struct anv_device *device,
{
/* TODO: protected content */
assert((alloc_flags & ANV_BO_ALLOC_PROTECTED) == 0);
/* WB+0 way coherent not supported by Xe KMD */
assert((alloc_flags & ANV_BO_ALLOC_HOST_CACHED) == 0);
uint32_t flags = 0;
if (alloc_flags & ANV_BO_ALLOC_SCANOUT)