Skip to content

Commit

Permalink
Do not treat dGPUs as UMA
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
darksylinc committed Sep 18, 2023
1 parent a5f83b2 commit a55f69a
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}

Expand Down Expand Up @@ -1926,8 +1932,8 @@ namespace Ogre
{
#if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64
VkSampler textureSampler = static_cast<VkSampler>( samplerblock->mRsData );
#else // VK handles are always 64bit, even on 32bit systems
VkSampler textureSampler = *static_cast<VkSampler*>( samplerblock->mRsData );
#else // VK handles are always 64bit, even on 32bit systems
VkSampler textureSampler = *static_cast<VkSampler *>( samplerblock->mRsData );
#endif
if( mGlobalTable.samplers[texUnit].sampler != textureSampler )
{
Expand Down Expand Up @@ -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
}
//-------------------------------------------------------------------------
Expand All @@ -3420,9 +3426,9 @@ namespace Ogre
assert( block->mRsData );
#if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64
VkSampler textureSampler = static_cast<VkSampler>( block->mRsData );
#else // VK handles are always 64bit, even on 32bit systems
VkSampler textureSampler = *static_cast<VkSampler*>( block->mRsData );
delete (uint64*)block->mRsData;
#else // VK handles are always 64bit, even on 32bit systems
VkSampler textureSampler = *static_cast<VkSampler *>( block->mRsData );
delete(uint64 *)block->mRsData;
#endif
delayed_vkDestroySampler( mVaoManager, mActiveDevice->mDevice, textureSampler, 0 );
}
Expand Down

0 comments on commit a55f69a

Please sign in to comment.