From 7149c017b6174925706cd8b7be7c91740ef38474 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Tue, 22 Jun 2021 14:59:26 +0000 Subject: [PATCH] Vulkan: Fix FindBestType logic for device-local preference. Previously when comparing a "bestType" that's device-local with a "current" that's non-device-local, the logic to favor device-local memory would be skipped and the types compared on their size. This lead to incorrect memory types selection on some configurations (where the small device local heap was selected). Bug: dawn:659 Change-Id: Ie764815082ebeef845b70077fe630df05bcdb92b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/39500 Commit-Queue: Corentin Wallez Reviewed-by: Austin Eng Reviewed-by: Stephen White --- .../vulkan/ResourceMemoryAllocatorVk.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dawn_native/vulkan/ResourceMemoryAllocatorVk.cpp b/src/dawn_native/vulkan/ResourceMemoryAllocatorVk.cpp index 375a22fd9c..72bb019a29 100644 --- a/src/dawn_native/vulkan/ResourceMemoryAllocatorVk.cpp +++ b/src/dawn_native/vulkan/ResourceMemoryAllocatorVk.cpp @@ -259,14 +259,15 @@ namespace dawn_native { namespace vulkan { } // For non-mappable resources, favor device local memory. - if (!mappable) { - if ((info.memoryTypes[bestType].propertyFlags & - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == 0 && - (info.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != - 0) { + bool currentDeviceLocal = + info.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + bool bestDeviceLocal = + info.memoryTypes[bestType].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + if (!mappable && (currentDeviceLocal != bestDeviceLocal)) { + if (currentDeviceLocal) { bestType = static_cast(i); - continue; } + continue; } // All things equal favor the memory in the biggest heap