[2.2] Exception after light baking + PCC probes update

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

[2.2] Exception after light baking + PCC probes update

Post by rujialiu » Tue Jun 11, 2019 5:26 am

Hi!

I got this exception:

Code: Select all

11:09:07: OGRE EXCEPTION(1:InvalidStateException): Last frame called map( bAdvanceFrame = false ) but didn't call advanceFrame!!!. in BufferPacked::map at C:\ogremygui\OGRE\OgreMain\src\Vao\OgreBufferPacked.cpp (line 190)
Detail:

Code: Select all

if( //This is a different frame from the last time we called map
                mLastFrameMapped != currentFrame &&
                //map was called, but bAdvanceFrame was not.
                (int)(mLastFrameMapped - mLastFrameMappedAndAdvanced) > 0 )
            {
                OGRE_EXCEPT( Exception::ERR_INVALID_STATE,
                             "Last frame called map( bAdvanceFrame = false ) but "
                             "didn't call advanceFrame!!!.", "BufferPacked::map" );
            }
When the exception occurs, mLastFrameMapped=150, mLastFrameMappedAndAdvanced=149, currentFrame=153 and the next function in the call stack is:

Code: Select all

float* RESTRICT_ALIAS_RETURN HlmsBufferManager::mapNextTexBuffer( CommandBuffer *commandBuffer,
                                                                      size_t minimumSizeBytes )
    {
...

        mRealStartMappedTexBuffer   = reinterpret_cast<float*>(
                                            texBuffer->map( mTexLastOffset,
                                                            texBuffer->getNumElements() - mTexLastOffset, /////////// here
                                                            false ) );
This happens when I do some light bakings and THEN update PCC probes. The light baking loop is something like:

Code: Select all

 for (const auto& action : mLightmapBakingActions) {
	beforeLightBakingAction(action); // change visilibty mask, move camera etc

        sceneManager->updateSceneGraph();

        auto bakingWorkspace = action.worspace;
        bakingWorkspace->_beginUpdate(false);
        bakingWorkspace->_update();
        bakingWorkspace->_endUpdate(false);
        sceneManager->clearFrameData();

        afterLightBakingAction(idx); // restore changed things
    }
Back to the exception-rasing code. In the first bake, currentFrame=150 so mLastFrameMapped changed to 150 too, but mLastFrameMappedAndAdvanced is still 149.

In the second bake in the loop (I have 5 actions in the loop), although (int)(mLastFrameMapped - mLastFrameMappedAndAdvanced) > 0 is true (150>149), but mLastFrameMapped == currentFrame (both 150) so the exception was not raised.

However, after all the baking actions, when updating PCC probes:

Code: Select all

void ParallaxCorrectedCubemap::updateExpensiveCollectedDirtyProbes( uint16 iterationThreshold )
    {
        RenderSystem *renderSystem = mSceneManager->getDestinationRenderSystem();
        HlmsManager *hlmsManager = mRoot->getHlmsManager();

        const uint32 oldVisibilityMask = mSceneManager->getVisibilityMask();
        mSceneManager->setVisibilityMask( 0xffffffff );

        for( size_t i=0; i<mNumCollectedProbes; ++i )
        {
            if( (mCollectedProbes[i]->mDirty || !mCollectedProbes[i]->mStatic) &&
                mCollectedProbes[i]->mNumIterations > iterationThreshold )
            {
                setFinalProbeTo( i );

                for( int j=0; j<mCollectedProbes[i]->mNumIterations; ++j )
                {
                    renderSystem->_beginFrameOnce();
                    mCopyWorkspace->_beginUpdate( true );
                        if( j == 0 )
                            mCollectedProbes[i]->_clearCubemap();
                        mCopyWorkspace->_update();
                        mCollectedProbes[i]->_updateRender(); //////////////////////////////////////here
                    mCopyWorkspace->_endUpdate( true );
the _updateRender() eventually enter HlmsBufferManager::mapNextTexBuffer() again, and then BufferPacked::map() and raised an exception because (int)(mLastFrameMapped - mLastFrameMappedAndAdvanced) > 0 is still true (again 150>149), BUT now currentFrame is 153 so mLastFrameMapped != currentFrame is also true.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4066
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 228
Contact:

Re: [2.2] Exception after light baking + PCC probes update

Post by dark_sylinc » Wed Jun 12, 2019 7:26 am

Looks like HlmsBufferManager::postCommandBufferExecution didn't get called, or HlmsBufferManager::frameEnded got called too early.
Alternatively, it may be possible to fix this issue by calling VaoManager::_update in between.
0 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: [2.2] Exception after light baking + PCC probes update

Post by rujialiu » Thu Aug 29, 2019 2:24 pm

dark_sylinc wrote:
Wed Jun 12, 2019 7:26 am
Looks like HlmsBufferManager::postCommandBufferExecution didn't get called, or HlmsBufferManager::frameEnded got called too early.
Alternatively, it may be possible to fix this issue by calling VaoManager::_update in between.
We managed to get a simple repro by slightly modifying the "Texture Baking" demo:

Code: Select all

 .../Tutorial_TextureBaking/Tutorial_TextureBakingGameState.cpp    | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/Samples/2.0/Tutorials/Tutorial_TextureBaking/Tutorial_TextureBakingGameState.cpp b/Samples/2.0/Tutorials/Tutorial_TextureBaking/Tutorial_TextureBakingGameState.cpp
index b61f5a66..a982d8f6 100644
--- a/Samples/2.0/Tutorials/Tutorial_TextureBaking/Tutorial_TextureBakingGameState.cpp
+++ b/Samples/2.0/Tutorials/Tutorial_TextureBaking/Tutorial_TextureBakingGameState.cpp
@@ -371,7 +371,7 @@ namespace Demo
         for( size_t i=0; i<c_numAreaLights; ++i )
         {
             createLight( Ogre::Vector3( (i - (c_numAreaLights-1u) * 0.5f) * 10, 4.0f, 0.0f ), i );
-            setupLightTexture( i );
+            //setupLightTexture( i );
         }
 
         mCameraController = new CameraController( mGraphicsSystem, false );
@@ -478,6 +478,12 @@ namespace Demo
         {
             mRenderingMode = RenderingMode::ShowSceneWithBakedTexture;
             updateBakingTexture();
+
+			for (size_t i = 0; i<c_numAreaLights; ++i)
+			{
+				//createLight(Ogre::Vector3((i - (c_numAreaLights - 1u) * 0.5f) * 10, 4.0f, 0.0f), i);
+				setupLightTexture(i);
+			}
             updateRenderingMode();
         }
         else if( arg.keysym.sym == SDLK_F4 )
We're getting the following exception:

Code: Select all

11:01:44: OGRE EXCEPTION(1:InvalidStateException): Last frame called map( bAdvanceFrame = false ) but didn't call advanceFrame!!!. in BufferPacked::map at C:\myguiogre\ogre\OgreMain\src\Vao\OgreBufferPacked.cpp (line 190)
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4066
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 228
Contact:

Re: [2.2] Exception after light baking + PCC probes update

Post by dark_sylinc » Sun Sep 01, 2019 5:15 pm

Hi!

I'm taking a look at your repro.

The problem is happening because Tutorial_TextureBakingGameState::updateBakingTexture() initiates compositor rendering (to do the baking) and HlmsBufferManager::frameEnded isn't called because it assumes more rendering will continue happening later (i.e. rendering to the main window).

But when you insert your snippet which sneakily ends up calling VaoManager::_update; this assumption breaks as it is now considered a new frame, and the following needs to be performed:

Code: Select all

sceneManager->_frameEnded();
for( size_t i=0; i<HLMS_MAX; ++i )
{
    Hlms *hlms = hlmsManager->getHlms( static_cast<HlmsTypes>( i ) );
    if( hlms )
        hlms->frameEnded();
}
I am now trying to figure out a more API friendly way to fix this mess because waiting for texture streaming can sneak calls to VaoManager::_update.
0 x

Post Reply