Skip to content

Commit 44a75dd

Browse files
rafadevaipoweifengphoenixxxx
authored
VK: Add a new platform method to check UMA (#8704)
* VK: Add a new context method to check UMA This heuristic should work on almost all devices, can be extended later as needed. * Addressing PR comments --------- Co-authored-by: Powei Feng <[email protected]> Co-authored-by: Serge Metral <[email protected]>
1 parent de7bcd2 commit 44a75dd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

filament/backend/src/vulkan/VulkanContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ struct VulkanContext {
142142
return mPortabilitySubsetFeatures.imageView2DOn3DImage == VK_TRUE;
143143
}
144144

145+
inline bool isUnifiedMemoryArchitecture() const noexcept {
146+
return mIsUnifiedMemoryArchitecture;
147+
}
148+
145149
private:
146150
VkPhysicalDeviceMemoryProperties mMemoryProperties = {};
147151
VkPhysicalDeviceProperties2 mPhysicalDeviceProperties = {
@@ -164,6 +168,7 @@ struct VulkanContext {
164168
bool mDebugUtilsSupported = false;
165169
bool mLazilyAllocatedMemorySupported = false;
166170
bool mProtectedMemorySupported = false;
171+
bool mIsUnifiedMemoryArchitecture = false;
167172

168173
fvkutils::VkFormatList mDepthStencilFormats;
169174
fvkutils::VkFormatList mBlittableDepthStencilFormats;

filament/backend/src/vulkan/platform/VulkanPlatform.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,21 @@ fvkutils::VkFormatList findBlittableDepthStencilFormats(VkPhysicalDevice device)
631631
return ret;
632632
}
633633

634+
/**
635+
* Check if the GPU has a unified memory architecture.
636+
*/
637+
bool hasUnifiedMemoryArchitecture(VkPhysicalDeviceMemoryProperties memoryProperties) noexcept {
638+
// Try to identify if the platform is running on a Unified Memory Architecture by inspecting the
639+
// memory heap flags, if they are all VK_MEMORY_HEAP_DEVICE_LOCAL_BIT it's UMA, otherwise not
640+
// enough information to make a decision, so default to false.
641+
for (uint32_t i = 0; i < memoryProperties.memoryHeapCount; ++i) {
642+
if ((memoryProperties.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) == 0) {
643+
return false;
644+
}
645+
}
646+
return true;
647+
}
648+
634649
}// anonymous namespace
635650

636651
using SwapChainPtr = VulkanPlatform::SwapChainPtr;
@@ -864,6 +879,8 @@ Driver* VulkanPlatform::createDriver(void* sharedContext,
864879
}
865880
}
866881

882+
context.mIsUnifiedMemoryArchitecture = hasUnifiedMemoryArchitecture(context.mMemoryProperties);
883+
867884
#ifdef NDEBUG
868885
// If we are in release build, we should not have turned on debug extensions
869886
FILAMENT_CHECK_POSTCONDITION(!context.mDebugUtilsSupported && !context.mDebugMarkersSupported)

0 commit comments

Comments
 (0)