[2.2] Crash on loading BC texture with no mipmaps

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
al2950
OGRE Expert User
OGRE Expert User
Posts: 1202
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

[2.2] Crash on loading BC texture with no mipmaps

Post by al2950 » Tue Jan 29, 2019 12:21 pm

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!
1 x

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

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

Post by dark_sylinc » Tue Jan 29, 2019 5:34 pm

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!
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1202
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

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

Post by al2950 » Tue Jan 29, 2019 5:37 pm

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)
0 x

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

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

Post by dark_sylinc » Tue Jan 29, 2019 8:13 pm

Yes, please. It will help you getting familiar with the new code.
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1202
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

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

Post by al2950 » Wed Jan 30, 2019 1:34 pm

Done please see PR here
0 x

Post Reply