From e77a2f1cc3f1180dc6f59da09ef892fdbe664b7b Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Wed, 7 Aug 2024 14:17:11 -0400 Subject: [PATCH] tu: Add a flag for cached non-coherent BOs We will have to flush/invalidate the memory backing an image in the driver when copying it to/from the host if it's cached and not coherent. Part-of: --- src/freedreno/vulkan/tu_knl.cc | 18 +++++++++++++++++- src/freedreno/vulkan/tu_knl.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/freedreno/vulkan/tu_knl.cc b/src/freedreno/vulkan/tu_knl.cc index 49001f74601..babafe0e414 100644 --- a/src/freedreno/vulkan/tu_knl.cc +++ b/src/freedreno/vulkan/tu_knl.cc @@ -44,6 +44,10 @@ tu_bo_init_new_explicit_iova(struct tu_device *dev, if (result != VK_SUCCESS) return result; + if ((mem_property & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) && + !(mem_property & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) + (*out_bo)->cached_non_coherent = true; + vk_address_binding_report(&instance->vk, base ? base : &dev->vk.base, (*out_bo)->iova, (*out_bo)->size, VK_DEVICE_ADDRESS_BINDING_TYPE_BIND_EXT); @@ -57,7 +61,19 @@ tu_bo_init_dmabuf(struct tu_device *dev, uint64_t size, int fd) { - return dev->instance->knl->bo_init_dmabuf(dev, bo, size, fd); + VkResult result = dev->instance->knl->bo_init_dmabuf(dev, bo, size, fd); + if (result != VK_SUCCESS) + return result; + + /* If we have non-coherent cached memory, then defensively assume that it + * may need to be invalidated/flushed. If not, then we just have to assume + * that whatever dma-buf producer didn't allocate it non-coherent cached + * because we have no way of handling that. + */ + if (dev->physical_device->has_cached_non_coherent_memory) + (*bo)->cached_non_coherent = true; + + return VK_SUCCESS; } int diff --git a/src/freedreno/vulkan/tu_knl.h b/src/freedreno/vulkan/tu_knl.h index 7ce97cdf637..305686439c1 100644 --- a/src/freedreno/vulkan/tu_knl.h +++ b/src/freedreno/vulkan/tu_knl.h @@ -69,6 +69,7 @@ struct tu_bo { bool implicit_sync : 1; bool never_unmap : 1; + bool cached_non_coherent : 1; /* Pointer to the vk_object_base associated with the BO * for the purposes of VK_EXT_device_address_binding_report