anv: Honor memory coherency of the memory type selected

Integrated GPUs almost always works with write-back caching(only
scanout and external bos works in write-combine) but in platforms
without LLC the coherency is broken if not explict asked to KMD.

vkFlushMappedMemoryRanges and vkInvalidateMappedMemoryRanges()
don't do any flushing or invalidate for memory allocated with
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT.

So if an application asked for a memory coherent, the
ANV_BO_ALLOC_SNOOPED flag needs to be set in alloc_flags and that
will be passed to KMD backends to properly ask to KMD for coherent
buffer.

The other chunk here removes the assert(alloc_flags & ANV_BO_ALLOC_MAPPED),
that is needed otherwise application can't ask for a coherent and
mapped memory.
Tried to find a reason for that assert in git history but did not
found what was the reasoning of this assert.

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/26099>
This commit is contained in:
José Roberto de Souza
2023-09-07 12:29:36 -07:00
committed by Marge Bot
parent 740e596c62
commit 66dce74d74
2 changed files with 5 additions and 1 deletions

View File

@@ -4036,6 +4036,11 @@ 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_SNOOPED;
if (mem->vk.ahardware_buffer) {
result = anv_import_ahw_memory(_device, mem);
if (result != VK_SUCCESS)

View File

@@ -108,7 +108,6 @@ i915_gem_create(struct anv_device *device,
*actual_size = gem_create.size;
if (alloc_flags & ANV_BO_ALLOC_SNOOPED) {
assert(alloc_flags & ANV_BO_ALLOC_MAPPED);
/* We don't want to change these defaults if it's going to be shared
* with another process.
*/