From a55f69a64accbe7fc184fba6d3a7cabb6c8aea9f Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Sun, 17 Sep 2023 21:10:36 -0300 Subject: [PATCH] Do not treat dGPUs as UMA When the BIOS & GPU has Resizable BAR enabled, x86 GPUs will expose DEVICE_LOCAL_BIT + HOST_VISIBLE_BIT + HOST_COHERENT_BIT memory. That doesn't mean they're UMA, and we definitely do NOT want to mess with the can of worms that is dealing with that memory type. And if Resizable BAR is disabled, that memory type may still be exposed but limited to 256MB (which is globally shared by the entire OS, if the OS runs out of it bad things happen). There's still the question of what to do with AMD iGPUs though (e.g. Vega and RDNA2 iGPUs will expose these flags and we will consider them UMAs. Technically this is correct. Is it a good idea? I don't know). --- .../Vulkan/src/OgreVulkanRenderSystem.cpp | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp b/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp index 222cbe39fb2..e4f274483ed 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp @@ -676,21 +676,27 @@ namespace Ogre // check memory properties to determine, if we can use UMA and/or TBDR optimizations const VkPhysicalDeviceMemoryProperties &memoryProperties = mDevice->mDeviceMemoryProperties; - for( uint32_t typeIndex = 0; typeIndex < memoryProperties.memoryTypeCount; ++typeIndex ) + if( mDevice->mDeviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU || + mDevice->mDeviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU ) { - const VkMemoryType &memoryType = memoryProperties.memoryTypes[typeIndex]; - if( ( memoryType.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ) != 0 && - ( memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ) != 0 && - ( memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT ) != 0 ) + for( uint32_t typeIndex = 0; typeIndex < memoryProperties.memoryTypeCount; ++typeIndex ) { - rsc->setCapability( RSC_UMA ); - } - // VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT is a prerequisite for TBDR, and is probably a good - // heuristic that TBDR mode of buffers clearing is supported efficiently, i.e. RSC_IS_TILER. - if( ( memoryType.propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT ) != 0 ) - { - rsc->setCapability( RSC_IS_TILER ); - rsc->setCapability( RSC_TILER_CAN_CLEAR_STENCIL_REGION ); + const VkMemoryType &memoryType = memoryProperties.memoryTypes[typeIndex]; + if( ( memoryType.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ) != 0 && + ( memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ) != 0 && + ( memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT ) != 0 ) + { + rsc->setCapability( RSC_UMA ); + } + + // VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT is a prerequisite for TBDR, and is probably + // a good heuristic that TBDR mode of buffers clearing is supported efficiently, + // i.e. RSC_IS_TILER. + if( ( memoryType.propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT ) != 0 ) + { + rsc->setCapability( RSC_IS_TILER ); + rsc->setCapability( RSC_TILER_CAN_CLEAR_STENCIL_REGION ); + } } } @@ -1926,8 +1932,8 @@ namespace Ogre { #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 VkSampler textureSampler = static_cast( samplerblock->mRsData ); -#else // VK handles are always 64bit, even on 32bit systems - VkSampler textureSampler = *static_cast( samplerblock->mRsData ); +#else // VK handles are always 64bit, even on 32bit systems + VkSampler textureSampler = *static_cast( samplerblock->mRsData ); #endif if( mGlobalTable.samplers[texUnit].sampler != textureSampler ) { @@ -3410,8 +3416,8 @@ namespace Ogre #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 newBlock->mRsData = textureSampler; -#else // VK handles are always 64bit, even on 32bit systems - newBlock->mRsData = new uint64(textureSampler); +#else // VK handles are always 64bit, even on 32bit systems + newBlock->mRsData = new uint64( textureSampler ); #endif } //------------------------------------------------------------------------- @@ -3420,9 +3426,9 @@ namespace Ogre assert( block->mRsData ); #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 VkSampler textureSampler = static_cast( block->mRsData ); -#else // VK handles are always 64bit, even on 32bit systems - VkSampler textureSampler = *static_cast( block->mRsData ); - delete (uint64*)block->mRsData; +#else // VK handles are always 64bit, even on 32bit systems + VkSampler textureSampler = *static_cast( block->mRsData ); + delete(uint64 *)block->mRsData; #endif delayed_vkDestroySampler( mVaoManager, mActiveDevice->mDevice, textureSampler, 0 ); }