Skip to content

Commit

Permalink
Add TextureGpuManager::setAllowMemoryless
Browse files Browse the repository at this point in the history
And adds option to be toggeld via RenderSystem option.
This enables the user to fix potential rendering crashes if their scenes
are so heavy that a flush is necessary (which means TilerMemoryless flag
must be ignored).

Fix clang format
Remove use of auto keyword
  • Loading branch information
darksylinc committed Nov 21, 2024
1 parent bf991d0 commit d0393ac
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 18 deletions.
10 changes: 10 additions & 0 deletions OgreMain/include/OgreTextureGpuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ namespace Ogre

DefaultMipmapGen::DefaultMipmapGen mDefaultMipmapGen;
DefaultMipmapGen::DefaultMipmapGen mDefaultMipmapGenCubemaps;
bool mAllowMemoryLess;
bool mShuttingDown;
std::atomic<bool> mUseMultiload;
ThreadHandlePtr mWorkerThread;
Expand Down Expand Up @@ -754,6 +755,15 @@ namespace Ogre
DefaultMipmapGen::DefaultMipmapGen getDefaultMipmapGeneration() const;
DefaultMipmapGen::DefaultMipmapGen getDefaultMipmapGenerationCubemaps() const;

/** When false, TextureFlags::TilerMemoryless will be ignored (including implicit MSAA surfaces).
Useful if you're rendering a heavy scene and run out of tile memory on mobile / TBDR.
@param bAllowMemoryLess
True to allow TilerMemoryless. False otherwise.
If HW does not support TilerMemoryless, this value will be forced to false.
*/
void setAllowMemoryless( const bool bAllowMemoryLess );
bool allowMemoryless() const { return mAllowMemoryLess; }

const ResourceEntryMap &getEntries() const { return mEntries; }

/// Must be called from main thread.
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/GLX/OgreConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace Ogre
{
/* GUI constants */
static const int wWidth = 600; // Width of window
static const int wHeight = 380; // Height of window
static const int wHeight = 420; // Height of window
static const int col1x = 20; // Starting x of column 1 (labels)
static const int col2x = 220; // Starting x of column 2 (options)
static const int col1w = 180; // Width of column 1 (labels)
Expand Down
18 changes: 18 additions & 0 deletions OgreMain/src/OgreTextureGpuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace Ogre
TextureGpuManager::TextureGpuManager( VaoManager *vaoManager, RenderSystem *renderSystem ) :
mDefaultMipmapGen( DefaultMipmapGen::HwMode ),
mDefaultMipmapGenCubemaps( DefaultMipmapGen::SwMode ),
mAllowMemoryLess( false ),
mShuttingDown( false ),
mUseMultiload( false ),
mTryLockMutexFailureCount( 0u ),
Expand Down Expand Up @@ -2093,6 +2094,23 @@ namespace Ogre
return mDefaultMipmapGenCubemaps;
}
//-----------------------------------------------------------------------------------
void TextureGpuManager::setAllowMemoryless( const bool bAllowMemoryLess )
{
if( !mRenderSystem->getCapabilities()->hasCapability( RSC_IS_TILER ) )
{
mAllowMemoryLess = false;
LogManager::getSingleton().logMessage(
"Device is NOT tiler. TilerMemoryless flag will be ignored." );
}
else
{
mAllowMemoryLess = bAllowMemoryLess;
LogManager::getSingleton().logMessage(
String( "Device IS tiler. TilerMemoryless flag will be: " ) +
( bAllowMemoryLess ? "allowed." : "ignored" ) );
}
}
//-----------------------------------------------------------------------------------
void TextureGpuManager::_reserveSlotForTexture( TextureGpu *texture )
{
bool matchFound = false;
Expand Down
16 changes: 16 additions & 0 deletions RenderSystems/Metal/src/OgreMetalRenderSystem.mm
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ of this software and associated documentation files (the "Software"), to deal
ConfigOption optDevice;
ConfigOption optFSAA;
ConfigOption optSRGB;
ConfigOption optAllowMemoryless;

optDevice.name = "Rendering Device";
optDevice.currentValue = "(default)";
Expand All @@ -179,9 +180,16 @@ of this software and associated documentation files (the "Software"), to deal
optSRGB.currentValue = "Yes";
optSRGB.immutable = false;

optAllowMemoryless.name = "Allow Memoryless RTT";
optAllowMemoryless.immutable = false;
optAllowMemoryless.possibleValues.push_back( "Yes" );
optAllowMemoryless.possibleValues.push_back( "No" );
optAllowMemoryless.currentValue = optAllowMemoryless.possibleValues.front();

mOptions[optDevice.name] = optDevice;
mOptions[optFSAA.name] = optFSAA;
mOptions[optSRGB.name] = optSRGB;
mOptions[optAllowMemoryless.name] = optAllowMemoryless;

refreshFSAAOptions();
}
Expand Down Expand Up @@ -607,6 +615,14 @@ of this software and associated documentation files (the "Software"), to deal
OGRE_ASSERT_LOW( mVaoManager->getDynamicBufferMultiplier() == dynamicBufferMultiplier );
mHardwareBufferManager = new v1::MetalHardwareBufferManager( &mDevice, mVaoManager );
mTextureGpuManager = OGRE_NEW MetalTextureGpuManager( mVaoManager, this, &mDevice );
{
ConfigOptionMap::const_iterator it = getConfigOptions().find( "Allow Memoryless RTT" );
if( it != getConfigOptions().end() )
{
mTextureGpuManager->setAllowMemoryless(
StringConverter::parseBool( it->second.currentValue, true ) );
}
}

mInitialized = true;
}
Expand Down
8 changes: 3 additions & 5 deletions RenderSystems/Metal/src/OgreMetalTextureGpu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ of this software and associated documentation files (the "Software"), to deal
if( mTextureType == TextureTypes::TypeCube || mTextureType == TextureTypes::TypeCubeArray )
desc.arrayLength /= 6u;

const RenderSystemCapabilities *capabilities =
mTextureManager->getRenderSystem()->getCapabilities();
const bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
if( isTiler && isTilerMemoryless() )
const bool bAllowMemoryless = mTextureManager->allowMemoryless();
if( bAllowMemoryless && isTilerMemoryless() )
{
if( @available( iOS 10, macOS 11, * ) )
desc.storageMode = MTLStorageModeMemoryless;
Expand Down Expand Up @@ -121,7 +119,7 @@ of this software and associated documentation files (the "Software"), to deal

if( isMultisample() && !hasMsaaExplicitResolves() )
{
if( isTiler )
if( bAllowMemoryless )
{
// mMsaaFramebufferName is always Memoryless because the user *NEVER* has access to it
// and we always auto-resolve in the same pass, thus MSAA contents are always transient.
Expand Down
14 changes: 11 additions & 3 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,14 +1356,14 @@ namespace Ogre
// assign unique names, allowing reordering/inserting/removing
map<String, unsigned>::type sameNameCounter;
mVulkanPhysicalDeviceList.clear();
mVulkanPhysicalDeviceList.reserve(devices.size());
for (auto device : devices)
mVulkanPhysicalDeviceList.reserve( devices.size() );
for( VkPhysicalDevice device : devices )
{
VkPhysicalDeviceProperties deviceProps;
vkGetPhysicalDeviceProperties( device, &deviceProps );

String name( deviceProps.deviceName );
unsigned sameNameIndex = sameNameCounter[name]++; // inserted entry is zero-initialized
unsigned sameNameIndex = sameNameCounter[name]++; // inserted entry is zero-initialized
if( sameNameIndex != 0 )
name += " (" + Ogre::StringConverter::toString( sameNameIndex + 1 ) + ")";

Expand Down Expand Up @@ -1634,6 +1634,14 @@ namespace Ogre
VulkanTextureGpuManager *textureGpuManager = OGRE_NEW VulkanTextureGpuManager(
vaoManager, this, mDevice, bCanRestrictImageViewUsage );
mTextureGpuManager = textureGpuManager;
{
ConfigOptionMap::const_iterator it = getConfigOptions().find( "Allow Memoryless RTT" );
if( it != getConfigOptions().end() )
{
mTextureGpuManager->setAllowMemoryless(
StringConverter::parseBool( it->second.currentValue, true ) );
}
}

uint32 dummyData = 0u;
mDummyBuffer = vaoManager->createConstBuffer( 4u, BT_IMMUTABLE, &dummyData, false );
Expand Down
13 changes: 4 additions & 9 deletions RenderSystems/Vulkan/src/OgreVulkanTextureGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ THE SOFTWARE.
#include "OgrePixelFormatGpuUtils.h"

#include "OgreException.h"
#include "OgreRenderSystem.h"
#include "OgreTextureBox.h"
#include "OgreVector2.h"
#include "OgreVulkanMappings.h"
Expand Down Expand Up @@ -148,10 +147,8 @@ namespace Ogre
if( isUav() )
imageInfo.usage |= VK_IMAGE_USAGE_STORAGE_BIT;

const RenderSystemCapabilities *capabilities =
mTextureManager->getRenderSystem()->getCapabilities();
const bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
if( isTiler && isTilerMemoryless() )
const bool bAllowMemoryless = mTextureManager->allowMemoryless();
if( bAllowMemoryless && isTilerMemoryless() )
{
imageInfo.usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
imageInfo.usage &=
Expand Down Expand Up @@ -994,10 +991,8 @@ namespace Ogre
? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;

const RenderSystemCapabilities *capabilities =
mTextureManager->getRenderSystem()->getCapabilities();
const bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
if( isTiler )
const bool bAllowMemoryless = mTextureManager->allowMemoryless();
if( bAllowMemoryless )
{
// mMsaaFramebufferName is always Memoryless because the user *NEVER* has access to it
// and we always auto-resolve in the same pass, thus MSAA contents are always transient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Ogre
ConfigOption optVSync;
ConfigOption optVSyncInterval;
ConfigOption optVSyncMethod;
ConfigOption optAllowMemoryless;

// Video mode possibilities
optVideoMode.name = "Video Mode";
Expand Down Expand Up @@ -89,11 +90,18 @@ namespace Ogre
optVSyncMethod.possibleValues.push_back( "Lowest Latency" );
optVSyncMethod.currentValue = optVSyncMethod.possibleValues.front();

optAllowMemoryless.name = "Allow Memoryless RTT";
optAllowMemoryless.immutable = false;
optAllowMemoryless.possibleValues.push_back( "Yes" );
optAllowMemoryless.possibleValues.push_back( "No" );
optAllowMemoryless.currentValue = optAllowMemoryless.possibleValues.front();

mOptions[optVideoMode.name] = optVideoMode;
mOptions[optDisplayFrequency.name] = optDisplayFrequency;
mOptions[optVSync.name] = optVSync;
mOptions[optVSyncInterval.name] = optVSyncInterval;
mOptions[optVSyncMethod.name] = optVSyncMethod;
mOptions[optAllowMemoryless.name] = optAllowMemoryless;

refreshConfig();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ namespace Ogre
ConfigOption optVSync;
ConfigOption optVSyncInterval;
ConfigOption optVSyncMethod;
ConfigOption optAllowMemoryless;

// FS setting possibilities
optFullScreen.name = "Full Screen";
Expand Down Expand Up @@ -175,12 +176,19 @@ namespace Ogre
optVSyncMethod.possibleValues.push_back( "Lowest Latency" );
optVSyncMethod.currentValue = optVSyncMethod.possibleValues.front();

optAllowMemoryless.name = "Allow Memoryless RTT";
optAllowMemoryless.immutable = false;
optAllowMemoryless.possibleValues.push_back( "Yes" );
optAllowMemoryless.possibleValues.push_back( "No" );
optAllowMemoryless.currentValue = optAllowMemoryless.possibleValues.front();

mOptions[optFullScreen.name] = optFullScreen;
mOptions[optVideoMode.name] = optVideoMode;
mOptions[optDisplayFrequency.name] = optDisplayFrequency;
mOptions[optVSync.name] = optVSync;
mOptions[optVSyncInterval.name] = optVSyncInterval;
mOptions[optVSyncMethod.name] = optVSyncMethod;
mOptions[optAllowMemoryless.name] = optAllowMemoryless;

refreshConfig();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace Ogre
ConfigOption optVSync;
ConfigOption optVSyncInterval;
ConfigOption optVSyncMethod;
ConfigOption optAllowMemoryless;

// FS setting possibilities
optFullScreen.name = "Full Screen";
Expand Down Expand Up @@ -140,13 +141,20 @@ namespace Ogre
optVSyncMethod.possibleValues.push_back( "Lowest Latency" );
optVSyncMethod.currentValue = optVSyncMethod.possibleValues.front();

optAllowMemoryless.name = "Allow Memoryless RTT";
optAllowMemoryless.immutable = false;
optAllowMemoryless.possibleValues.push_back( "Yes" );
optAllowMemoryless.possibleValues.push_back( "No" );
optAllowMemoryless.currentValue = optAllowMemoryless.possibleValues.front();

mOptions[optFullScreen.name] = optFullScreen;
mOptions[optVideoMode.name] = optVideoMode;
mOptions[optColourDepth.name] = optColourDepth;
mOptions[optDisplayFrequency.name] = optDisplayFrequency;
mOptions[optVSync.name] = optVSync;
mOptions[optVSyncInterval.name] = optVSyncInterval;
mOptions[optVSyncMethod.name] = optVSyncMethod;
mOptions[optAllowMemoryless.name] = optAllowMemoryless;

refreshConfig();
}
Expand Down

0 comments on commit d0393ac

Please sign in to comment.