Skip to content

Commit

Permalink
Prefer using UINT64_MAX over (uint64_t)-1
Browse files Browse the repository at this point in the history
mPsoRequestsTimeout should be a uint32, not an int.
  • Loading branch information
darksylinc committed Feb 17, 2025
1 parent 6004eee commit 8af3ecb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions OgreMain/include/OgreRenderQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ namespace Ogre
LightweightMutex mMutex;
Semaphore mSemaphore;
std::atomic<bool> mKeepCompiling;
uint64 mCompilationDeadline; // 16ms in the future, or (uint64)-1
std::atomic<uint64> mCompilationIncompleteCounter; // at least one was skipped
uint64 mCompilationDeadline; // 16ms in the future, or UINT64_MAX.
std::atomic<uint64> mCompilationIncompleteCounter; // at least one was skipped.

bool mExceptionFound; // GUARDED_BY( mMutex )
std::exception_ptr mThreadedException; // GUARDED_BY( mMutex )
Expand Down
9 changes: 5 additions & 4 deletions OgreMain/include/OgreRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -906,13 +906,14 @@ namespace Ogre
virtual void executeResourceTransition( const ResourceTransitionArray &rstCollection ) {}

/// PSO creation on Vulkan could be skipped after exhausting per-frame time budget
void setPsoRequestsTimeout( int ms ) { mPsoRequestsTimeout = ms; }
int getPsoRequestsTimeout() const { return mPsoRequestsTimeout; }
void setPsoRequestsTimeout( uint32 ms ) { mPsoRequestsTimeout = ms; }
uint32 getPsoRequestsTimeout() const { return mPsoRequestsTimeout; }

uint64 getIncompletePsoRequestsCounter() const { return mIncompletePsoRequestsCounter; }
void _notifyIncompletePsoRequests( uint64 count );

/// return false for recoverable errors, for example for exhausted per-frame time budget
virtual bool _hlmsPipelineStateObjectCreated( HlmsPso *newPso, uint64 deadline = (uint64)-1 )
virtual bool _hlmsPipelineStateObjectCreated( HlmsPso *newPso, uint64 deadline = UINT64_MAX )
{
return true;
}
Expand Down Expand Up @@ -1719,7 +1720,7 @@ namespace Ogre
bool mReverseDepth;
bool mInvertedClipSpaceY;

int mPsoRequestsTimeout; // ms, per frame, or 0 to disable
uint32 mPsoRequestsTimeout; // ms, per frame, or 0 to disable
uint64 mIncompletePsoRequestsCounter;
};
/** @} */
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/OgreHlms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3719,7 +3719,7 @@ namespace Ogre
if( !parallelQueue || mType == HLMS_LOW_LEVEL )
{
lastReturnedValue = createShaderCacheEntry(
hash[0], passCache, finalHash, queuedRenderable, nullptr, (uint64)-1, kNoTid );
hash[0], passCache, finalHash, queuedRenderable, nullptr, UINT64_MAX, kNoTid );
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/OgrePsoCacheHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace Ogre
mPsoCache.insert( itor, 1u, entry );
itor = mPsoCache.begin() + idx;

mRenderSystem->_hlmsPipelineStateObjectCreated( &itor->pso, (uint64)-1 );
mRenderSystem->_hlmsPipelineStateObjectCreated( &itor->pso, UINT64_MAX );
}

mLastFinalHash = finalHash;
Expand Down
16 changes: 9 additions & 7 deletions OgreMain/src/OgreRenderQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,9 +1195,11 @@ namespace Ogre
void ParallelHlmsCompileQueue::start( SceneManager *sceneManager, bool casterPass )
{
mKeepCompiling = true;
int timeout = casterPass ? 0 : Root::getSingleton().getRenderSystem()->getPsoRequestsTimeout();
mCompilationDeadline =
timeout <= 0 ? (uint64)-1 : Root::getSingleton().getTimer()->getMilliseconds() + timeout;
uint32 timeout =
casterPass ? 0u : Root::getSingleton().getRenderSystem()->getPsoRequestsTimeout();
mCompilationDeadline = timeout == 0u
? UINT64_MAX
: ( Root::getSingleton().getTimer()->getMilliseconds() + timeout );
mCompilationIncompleteCounter = 0;
sceneManager->_fireParallelHlmsCompile();
}
Expand Down Expand Up @@ -1232,7 +1234,7 @@ namespace Ogre
//-----------------------------------------------------------------------
void ParallelHlmsCompileQueue::fireWarmUpParallel( SceneManager *sceneManager )
{
mCompilationDeadline = (uint64)-1;
mCompilationDeadline = UINT64_MAX;
mCompilationIncompleteCounter = 0;
sceneManager->_fireWarmUpShadersCompile();
OGRE_ASSERT_LOW( mRequests.empty() ); // Should be empty, whether we found an exception or not.
Expand Down Expand Up @@ -1272,7 +1274,7 @@ namespace Ogre
try
{
hlms->compileStubEntry( passCaches[reinterpret_cast<size_t>( request.passCache )],
request.reservedStubEntry, (uint64)-1, request.queuedRenderable,
request.reservedStubEntry, UINT64_MAX, request.queuedRenderable,
request.renderableHash, request.finalHash, threadIdx );
OGRE_ASSERT_LOW( request.reservedStubEntry->flags == HLMS_CACHE_FLAGS_NONE );
}
Expand All @@ -1292,14 +1294,14 @@ namespace Ogre
//-----------------------------------------------------------------------
void ParallelHlmsCompileQueue::warmUpSerial( HlmsManager *hlmsManager, const HlmsCache *passCaches )
{
mCompilationDeadline = (uint64)-1;
mCompilationDeadline = UINT64_MAX;
mCompilationIncompleteCounter = 0;
for( const Request &request : mRequests )
{
const HlmsDatablock *datablock = request.queuedRenderable.renderable->getDatablock();
Hlms *hlms = hlmsManager->getHlms( static_cast<HlmsTypes>( datablock->mType ) );
hlms->compileStubEntry( passCaches[reinterpret_cast<size_t>( request.passCache )],
request.reservedStubEntry, (uint64)-1, request.queuedRenderable,
request.reservedStubEntry, UINT64_MAX, request.queuedRenderable,
request.renderableHash, request.finalHash, 0u );
OGRE_ASSERT_LOW( request.reservedStubEntry->flags == HLMS_CACHE_FLAGS_NONE );
}
Expand Down
4 changes: 2 additions & 2 deletions OgreMain/src/OgreRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace Ogre
mTexProjRelativeOrigin( Vector3::ZERO ),
mReverseDepth( true ),
mInvertedClipSpaceY( false ),
mPsoRequestsTimeout( 0 ),
mPsoRequestsTimeout( 0u ),
mIncompletePsoRequestsCounter( 0 )
{
mEventNames.push_back( "RenderSystemCapabilitiesCreated" );
Expand Down Expand Up @@ -1383,7 +1383,7 @@ namespace Ogre
//---------------------------------------------------------------------
void RenderSystem::_notifyIncompletePsoRequests( uint64 count )
{
if( count > 0 )
if( count > 0u )
{
LogManager::getSingleton().logMessage(
"Deferred to next frame " + StringConverter::toString( count ) +
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3449,7 +3449,7 @@ namespace Ogre
makeVkStruct( pipeline, VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO );

bool deadlineMissed =
deadline != (uint64)-1 &&
deadline != UINT64_MAX &&
(int64)( Root::getSingleton().getTimer()->getMilliseconds() - deadline ) > 0;
pipeline.flags = deadlineMissed && mDevice->mDeviceExtraFeatures.pipelineCreationCacheControl
? VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT
Expand Down

0 comments on commit 8af3ecb

Please sign in to comment.