diff --git a/filament/backend/src/vulkan/VulkanContext.h b/filament/backend/src/vulkan/VulkanContext.h index d4804bf31b..0ca6d05722 100644 --- a/filament/backend/src/vulkan/VulkanContext.h +++ b/filament/backend/src/vulkan/VulkanContext.h @@ -142,6 +142,10 @@ public: return mPortabilitySubsetFeatures.imageView2DOn3DImage == VK_TRUE; } + inline bool isUnifiedMemoryArchitecture() const noexcept { + return mIsUnifiedMemoryArchitecture; + } + private: VkPhysicalDeviceMemoryProperties mMemoryProperties = {}; VkPhysicalDeviceProperties2 mPhysicalDeviceProperties = { @@ -164,6 +168,7 @@ private: bool mDebugUtilsSupported = false; bool mLazilyAllocatedMemorySupported = false; bool mProtectedMemorySupported = false; + bool mIsUnifiedMemoryArchitecture = false; fvkutils::VkFormatList mDepthStencilFormats; fvkutils::VkFormatList mBlittableDepthStencilFormats; diff --git a/filament/backend/src/vulkan/platform/VulkanPlatform.cpp b/filament/backend/src/vulkan/platform/VulkanPlatform.cpp index 4323aba877..46763e5c8a 100644 --- a/filament/backend/src/vulkan/platform/VulkanPlatform.cpp +++ b/filament/backend/src/vulkan/platform/VulkanPlatform.cpp @@ -631,6 +631,21 @@ fvkutils::VkFormatList findBlittableDepthStencilFormats(VkPhysicalDevice device) return ret; } +/** + * Check if the GPU has a unified memory architecture. + */ +bool hasUnifiedMemoryArchitecture(VkPhysicalDeviceMemoryProperties memoryProperties) noexcept { + // Try to identify if the platform is running on a Unified Memory Architecture by inspecting the + // memory heap flags, if they are all VK_MEMORY_HEAP_DEVICE_LOCAL_BIT it's UMA, otherwise not + // enough information to make a decision, so default to false. + for (uint32_t i = 0; i < memoryProperties.memoryHeapCount; ++i) { + if ((memoryProperties.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) == 0) { + return false; + } + } + return true; +} + }// anonymous namespace using SwapChainPtr = VulkanPlatform::SwapChainPtr; @@ -864,6 +879,8 @@ Driver* VulkanPlatform::createDriver(void* sharedContext, } } + context.mIsUnifiedMemoryArchitecture = hasUnifiedMemoryArchitecture(context.mMemoryProperties); + #ifdef NDEBUG // If we are in release build, we should not have turned on debug extensions FILAMENT_CHECK_POSTCONDITION(!context.mDebugUtilsSupported && !context.mDebugMarkersSupported)