From b41fb4338e895ee896c1a3d004592441f31b7982 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Wed, 19 Aug 2026 22:00:45 -0400 Subject: [PATCH] Enhance comments on memory type selection for GpuToCpu I noticed serious slowdowns in copying from Intel integrated GPU -> CPU on systems that have both a intel CPU and GPU. --- src/vulkan/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index 59572d49..99e32cb0 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -817,6 +817,20 @@ impl Allocator { let mut memory_type_index_opt = self.find_memorytype_index(&desc.requirements, mem_loc_preferred_bits); + // A GpuToCpu allocation exists to be read by the CPU, so being cached + // matters more than being coherent. Some adapters -- Intel's ANV on + // parts whose GPU does not share the CPU's last level cache -- expose + // cached memory and coherent memory but never both, and reading the + // uncached (write-combined) type is about two orders of magnitude + // slower. Callers must flush and invalidate non-coherent ranges + // regardless, so prefer cached before giving that up. + if memory_type_index_opt.is_none() && desc.location == MemoryLocation::GpuToCpu { + memory_type_index_opt = self.find_memorytype_index( + &desc.requirements, + vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_CACHED, + ); + } + if memory_type_index_opt.is_none() { let mem_loc_required_bits = match desc.location { MemoryLocation::GpuOnly => vk::MemoryPropertyFlags::DEVICE_LOCAL,