[2.2] Crash on loading BC texture with no mipmaps

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


Post Reply
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

[2.2] Crash on loading BC texture with no mipmaps

Post by al2950 »

I am still working on the detailed normal maps fixes, however this has caught me out as well.

Basically if you use the default functionality to load a texture (ie createOrRetrieve), it will request mipmaps are auto generated. However if its a poorly made DDS (which I apparently have lots) it will try and generate mipmaps for it, which requires creating a RenderTarget with a BC format, which causes DX11 and therefore Ogre to fall over. So I think there should be a check somewhere to exclude or ignore the TypeGenerateDefaultMipmaps filter flag if its a compressed format.... Will create a PR, but need some direction please!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5292
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.2] Crash on loading BC texture with no mipmaps

Post by dark_sylinc »

Ouch! Good catch.

GenerateHwMipmaps::_executeStreaming is the place.

The function should check if generating mipmaps is possible at all, and if not, then ensure mNeedsMipmaps is false:

Code: Select all

void GenerateHwMipmaps::_executeStreaming( Image2 &image, TextureGpu *texture )
{
    //Cubemaps may be loaded as 6 separate images.
    //If one of them needs HW generation, then all faces need it.
    mNeedsMipmaps |= image.getNumMipmaps() <= 1u;
    
    if( invalidFormatForMips() )
        mNeedsMipmaps = false;

    if( mNeedsMipmaps && texture->getNumMipmaps() <= 1u )
    {
        texture->setNumMipmaps( PixelFormatGpuUtils::getMaxMipmapCount( texture->getWidth(),
                                                                        texture->getHeight(),
                                                                        texture->getDepth() ) );
    }
}
GenerateSwMipmaps is not affected because on invalid formats image.generateMipmaps will do nothing, thus "if( texture->getNumMipmaps() != image.getNumMipmaps() )" will be if( 1 != 1 )

However this revealed another side effect: FilterBase::simulateFilters should account for this too, for both HW and SW mipmaps, and the reasons why SW mipmaps failed (Image2::generateMipmaps) may be different than why HW mipmaps can fail.

Good catch!
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.2] Crash on loading BC texture with no mipmaps

Post by al2950 »

I was just writing a reply saying that was the function I had 'hacked', but apparently its not a hack :D. Would you like me to create a PR for that or will you update? (I have not looked at the FilterBase::simulateFilters yet)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5292
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.2] Crash on loading BC texture with no mipmaps

Post by dark_sylinc »

Yes, please. It will help you getting familiar with the new code.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.2] Crash on loading BC texture with no mipmaps

Post by al2950 »

Done please see PR here
Post Reply