Page 1 of 1

[2.2] Crash on loading BC texture with no mipmaps

Posted: Tue Jan 29, 2019 12:21 pm
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!

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

Posted: Tue Jan 29, 2019 5:34 pm
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!

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

Posted: Tue Jan 29, 2019 5:37 pm
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)

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

Posted: Tue Jan 29, 2019 8:13 pm
by dark_sylinc
Yes, please. It will help you getting familiar with the new code.

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

Posted: Wed Jan 30, 2019 1:34 pm
by al2950
Done please see PR here