Skip to content

anv: Swap ordering of memory types on non-LLC platforms to work around application bugs.

Francisco Jerez requested to merge currojerez/mesa:anv-nonllc-memtypes into main

The Vulkan specification indicates that if memory types have properties which are a strict subset of another type's, then they should appear before that memory type. Otherwise the specification does not require a specific ordering of memory types.

But, it appears that Aztec Ruins and the Vulkan CTS make an assumption that the first host-accessible memory type is host-coherent and select it when they expect data written by the CPU to become visible without calling vkFlushMappedMemoryRanges(), even though flushing is required by the spec, which leads to misrendering and hangs on MTL platforms.

We found that other drivers also put a host-coherent, but not cached memory type as the first host-accessible memory type, so let's do the same in order to match the expectations of such broken applications.

Host-coherent uncached memory types are currently implemented with a WC CPU map on non-LLC platforms, so there shouldn't be a huge performance penalty from this: If an application intends to do heavy R/W CPU access on a memory range it's expected to loop over the available memory types and select one marked as host-cached -- If an application fails to do that and simply selects the first available type it seems more robust to stay on the safe side and give them a host-coherent type rather than a cached one.

Merge request reports