Terra staging texture creation bug

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

Terra staging texture creation bug

Post by Lax »

Hi,

I'm checking the newest terra version and having crashes.
I found out the following:
I'm creating a blendweight staging texture via:

Code: Select all

m_blendWeightStagingTexture = textureManager->getStagingTexture(image.getWidth(), image.getHeight(), 1u, 1u, image.getPixelFormat());

The image has a width and height of 1024.
BUT
After the m_blendWeightStagingTexture has been creating it has suddenly a width and height of 2048, which causes ugly crashes in further code.
I Found out that in the OgreTextureGPUManager in:

Code: Select all

StagingTexture *TextureGpuManager::getStagingTexture( uint32 width, uint32 height, uint32 depth,
                                                      uint32 slices, PixelFormatGpu pixelFormat,
                                                      size_t minConsumptionRatioThreshold )
{
...
   while( itor != endt )
   {
     StagingTexture *stagingTexture = *itor;

 if( stagingTexture->supportsFormat( width, height, depth, slices, pixelFormat ) &&
     ( bestCandidate == endt || stagingTexture->isSmallerThan( *bestCandidate ) ) )
 {
     if( !stagingTexture->uploadWillStall() )
         bestCandidate = itor;
 }

 ++itor;
   }
}

I hat a good canidated , which had the correct resolution, but in the code above, a new bestCandidate is set, which has now the resolution of 2048x2048. That seems no right, I thing the resolution must be taken into account.

My solution for now is, calling the staging texture twice^^, and no candidate can be found, hence a new staging texture is created with the correct resolution.

Code: Select all

if (nullptr == m_blendWeightStagingTexture)
{
    m_blendWeightStagingTexture = textureManager->getStagingTexture(image.getWidth(), image.getHeight(), 1u, 1u, image.getPixelFormat());
    m_blendWeightStagingTexture = textureManager->getStagingTexture(image.getWidth(), image.getHeight(), 1u, 1u, image.getPixelFormat());
}

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

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

Re: Terra staging texture creation bug

Post by dark_sylinc »

Hi!

The design of StagingTextures are a bit convoluted because of D3D11. We make no guarantee that the internal resolution will be an exact match. We only guarantee that the StagingTexture can hold the requested resolution.
That's why StagingTexture::mapRegion asks for the resolution again, and TextureBox::bytesPerRow and TextureBox::sliceStart will be set accordingly; and why StagingTexture::upload asks for the TextureBox returned by mapRegion.

For example if you ask for a 1024x1024 RGBA8_UNORM texture but you end up getting a 2048x2048, bytesPerRow will reflect that by being set to 2048 * 4 = 8.192 bytes.

Basically you have to write to a subregion of the StagingTexture.

See IrradianceVolume::updateIrradianceVolumeTexture implementation for an example.

Cheers
Matias

PS: If you intend to hold on to the StagingTexture for a long time because you intend to upload every frame, you could consider having N StagingTextures that are an exact match:

Code: Select all

numStagingTextures = vaoMgr->getDynamicBufferMultiplier();
for( i < numStagingTextures )
{
    stagingTex.push_back( texMgr->getStagingTexture( w, h, d, slices, pf, 100u /* see doc for minConsumptionRatioThreshold */ ) );
}

// every frame
StagingTexture *thisFrameStaging = stagingTex[vaoMgr->waitForTailFrameToFinish()];
Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

Re: Terra staging texture creation bug

Post by Lax »

ok thanks for the explanation.

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62