From 161fe2623011cf09d867939f61ed34ee56d81519 Mon Sep 17 00:00:00 2001 From: Eugene Golushkov Date: Wed, 27 Nov 2024 15:03:14 +0100 Subject: [PATCH] [Vk] Let VulkanPhysicalDevice::physicalDeviceID be unsigned and hold deviceLUID if available --- .../Vulkan/include/OgreVulkanRenderSystem.h | 2 +- RenderSystems/Vulkan/src/OgreVulkanDevice.cpp | 33 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h b/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h index 2820fb00de..6a6dbf777a 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h +++ b/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h @@ -56,7 +56,7 @@ namespace Ogre struct VulkanPhysicalDevice { VkPhysicalDevice physicalDevice; - long long physicalDeviceID; + uint64 physicalDeviceID; // deviceLUID on Windows String title; }; diff --git a/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp b/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp index cef88038ef..51f09ab73b 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp @@ -424,24 +424,43 @@ namespace Ogre "VulkanRenderSystem::getVkPhysicalDevices" ); } + // prepare to obtain deviceLUID or deviceUUID + bool hasProperties2 = hasExtension( VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ); + PFN_vkGetPhysicalDeviceProperties2KHR GetPhysicalDeviceProperties2KHR = + hasProperties2 ? (PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr( + mVkInstance, "vkGetPhysicalDeviceProperties2KHR" ) + : nullptr; + VkPhysicalDeviceProperties2 deviceProps2; + VkPhysicalDeviceIDProperties deviceIDProps; + makeVkStruct( deviceProps2, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 ); + makeVkStruct( deviceIDProps, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES ); + deviceProps2.pNext = &deviceIDProps; + // assign unique names, allowing reordering/inserting/removing map::type sameNameCounter; mVulkanPhysicalDevices.clear(); mVulkanPhysicalDevices.reserve( devices.size() ); for( VkPhysicalDevice device : devices ) { - VkPhysicalDeviceProperties deviceProps; - vkGetPhysicalDeviceProperties( device, &deviceProps ); + if( GetPhysicalDeviceProperties2KHR ) + GetPhysicalDeviceProperties2KHR( device, &deviceProps2 ); + else + vkGetPhysicalDeviceProperties( device, &deviceProps2.properties ); - String name( deviceProps.deviceName ); + String name( deviceProps2.properties.deviceName ); unsigned sameNameIndex = sameNameCounter[name]++; // inserted entry is zero-initialized if( sameNameIndex != 0 ) name += " (" + Ogre::StringConverter::toString( sameNameIndex + 1 ) + ")"; - // TODO: use deviceLUID or deviceUUID if available - uint64 hashResult[2] = {}; - OGRE_HASH128_FUNC( name.c_str(), (int)name.size(), IdString::Seed, hashResult ); - long long deviceLUID = hashResult[0]; + // use deviceLUID or deviceUUID if available + uint64 uid[2] = {}; + if( hasProperties2 && deviceIDProps.deviceLUIDValid ) + memcpy( uid, deviceIDProps.deviceLUID, VK_LUID_SIZE ); + else if( hasProperties2 ) + memcpy( uid, deviceIDProps.deviceUUID, VK_UUID_SIZE ); + else + OGRE_HASH128_FUNC( name.c_str(), (int)name.size(), IdString::Seed, uid ); + uint64 deviceLUID = uid[0] ^ uid[1]; LogManager::getSingleton().logMessage( "Vulkan: \"" + name + "\"" ); mVulkanPhysicalDevices.push_back( { device, deviceLUID, name } );