[dawn] Fallback to host memory for dma fd import
Some devices may fail to find device local memory for these FD imports
(likely from camera) when this occurs we can alternatively use host
memory even though there could be performance consequences. This
issue was discovered on AMD.
AMD device:
(https://www.techpowerup.com/gpu-specs/amd-mendocino.g1022).
For the device in question the FD import allowed for memory types that
had the 'propertyFlags' with 0x0E and 0xCE.
Both memory types therefore support
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
VK_MEMORY_PROPERTY_HOST_CACHED_BIT
Bug: 422128949
Change-Id: I320288343be9f9bfb676c45ec4a262383242d7c8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/245874
Reviewed-by: Brandon Jones <bajones@chromium.org>
Commit-Queue: Peter McNeeley <petermcneeley@google.com>
diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp
index b64e18c..b76e1fc 100644
--- a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp
+++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp
@@ -265,6 +265,16 @@
memoryRequirements.memoryTypeBits &= fdProperties.memoryTypeBits;
int memoryTypeIndex = mDevice->GetResourceMemoryAllocator()->FindBestTypeIndex(
memoryRequirements, MemoryKind::DeviceLocal);
+ // Some devices may fail to find device local memory for these FD imports (likely from
+ // camera). When this occurs we can alternatively use host memory even though there could
+ // be performance consequences. This issue was discovered on AMD
+ // (https://www.techpowerup.com/gpu-specs/amd-mendocino.g1022).
+ // See crbug.com/422128949
+ if (memoryTypeIndex == -1) {
+ memoryTypeIndex = mDevice->GetResourceMemoryAllocator()->FindBestTypeIndex(
+ memoryRequirements, MemoryKind::HostCached);
+ }
+
DAWN_INVALID_IF(memoryTypeIndex == -1,
"Unable to find an appropriate memory type for import.");