Skip to content

Commit

Permalink
[Vk] Add VulkanPhysicalDevice::physicalDeviceID to compare physical d…
Browse files Browse the repository at this point in the history
…evice with new one obtained from fresh VkInstance. TODO: use deviceLUID/UUID if available, rather than name hash
  • Loading branch information
eugenegff committed Nov 22, 2024
1 parent bb766ad commit 334884d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace Ogre
struct VulkanPhysicalDevice
{
VkPhysicalDevice physicalDevice;
long long physicalDeviceID;
String title;
};

Expand Down
13 changes: 12 additions & 1 deletion RenderSystems/Vulkan/src/OgreVulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ THE SOFTWARE.
# include "swappy/swappyVk.h"
#endif

#if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
# define OGRE_HASH128_FUNC MurmurHash3_x86_128
#else
# define OGRE_HASH128_FUNC MurmurHash3_x64_128
#endif

#define OGRE_VK_KHR_WIN32_SURFACE_EXTENSION_NAME "VK_KHR_win32_surface"
#define OGRE_VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface"
#define OGRE_VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "VK_KHR_android_surface"
Expand Down Expand Up @@ -428,8 +434,13 @@ namespace Ogre
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];

This comment has been minimized.

Copy link
@darksylinc

darksylinc Nov 26, 2024

Member

GCC & Clang warn of unsigned -> signed conversion.

Shouldn't deviceLUID be uint64_t?

Besides that, since VkPhysicalDeviceIDProperties::deviceUUID is 128 bits / 16 bytes and our hashing function also returns a 128 bit output, perhaps it's just better to make Ogre::VulkanPhysicalDevice::physicalDeviceID a uint64_t [2] variable?

This comment has been minimized.

Copy link
@eugenegff

eugenegff Nov 27, 2024

Author Member

Quite possibly. I wanted simple comparison, i.e. something 64bit rather than 128bit, and xor upper and lower halves of deviceUUID if deviceLUID is not available, but it is not necessary to be so

P.S. fixed in 6d574ab


LogManager::getSingleton().logMessage( "Vulkan: \"" + name + "\"" );
mVulkanPhysicalDevices.push_back( { device, name } );
mVulkanPhysicalDevices.push_back( { device, deviceLUID, name } );
}

LogManager::getSingleton().logMessage( "Vulkan: Device detection ends" );
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace Ogre
mVulkanProgramFactory1( 0 ),
mVulkanProgramFactory2( 0 ),
mVulkanProgramFactory3( 0 ),
mActiveDevice( { 0, String() } ),
mActiveDevice( { 0, 0, String() } ),
mFirstUnflushedAutoParamsBuffer( 0 ),
mAutoParamsBufferIdx( 0 ),
mCurrentAutoParamsBufferPtr( 0 ),
Expand Down Expand Up @@ -1090,7 +1090,7 @@ namespace Ogre
dbgFunc, this );

mActiveDevice = externalDevice
? VulkanPhysicalDevice( { externalDevice->physicalDevice, String() } )
? VulkanPhysicalDevice( { externalDevice->physicalDevice, 0, String() } )
: *mInstance->findByName( mVulkanSupport->getSelectedDeviceName() );

mDevice = new VulkanDevice( this );
Expand Down

0 comments on commit 334884d

Please sign in to comment.