Skip to content

Commit

Permalink
Improve TextureGpuManager::checkSupport
Browse files Browse the repository at this point in the history
Reuses the hardcoded known filters from
PixelFormatGpuUtils::supportsHwMipmaps

Also TextureFilters was not properly selecting HW/SW filters for
mipmapping if other filters were going to be applied earlier
  • Loading branch information
darksylinc committed Sep 11, 2020
1 parent fef202a commit 1cebf78
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
2 changes: 2 additions & 0 deletions OgreMain/include/OgreTextureFilters.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ namespace TextureFilter
See DefaultMipmapGen::DefaultMipmapGen
*/
static uint8 selectMipmapGen( uint32 filters, const Image2 &image,
PixelFormatGpu finalPixelFormat,
const TextureGpuManager *textureManager );

public:
static void createFilters( uint32 filters, FilterBaseArray &outFilters,
const TextureGpu *texture, const Image2 &image,
Expand Down
40 changes: 21 additions & 19 deletions OgreMain/src/OgreTextureFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace TextureFilter
}
//-----------------------------------------------------------------------------------
uint8 FilterBase::selectMipmapGen( uint32 filters, const Image2 &image,
PixelFormatGpu finalPixelFormat,
const TextureGpuManager *textureManager )
{
DefaultMipmapGen::DefaultMipmapGen retVal = DefaultMipmapGen::NoMipmaps;
Expand All @@ -64,7 +65,7 @@ namespace TextureFilter
defaultMipmapGeneration :
defaultMipmapGenerationCubemaps;

if( PixelFormatGpuUtils::supportsHwMipmaps( image.getPixelFormat() ) )
if( textureManager->checkSupport( finalPixelFormat, TextureFlags::AllowAutomipmaps ) )
retVal = mipmapGen;
else
retVal = DefaultMipmapGen::SwMode;
Expand All @@ -73,15 +74,6 @@ namespace TextureFilter
retVal = DefaultMipmapGen::HwMode;
else
retVal = DefaultMipmapGen::SwMode;

if( retVal == DefaultMipmapGen::HwMode )
{
if( !textureManager->checkSupport( image.getPixelFormat(),
TextureFlags::AllowAutomipmaps ) )
{
retVal = DefaultMipmapGen::SwMode;
}
}
}

return retVal;
Expand All @@ -93,15 +85,24 @@ namespace TextureFilter
FilterBaseArray filtersVec;
filtersVec.swap( outFilters );

PixelFormatGpu finalPixelFormat = image.getPixelFormat();

if( filters & TextureFilter::TypePrepareForNormalMapping )
{
finalPixelFormat = PrepareForNormalMapping::getDestinationFormat( finalPixelFormat );
filtersVec.push_back( OGRE_NEW TextureFilter::PrepareForNormalMapping() );
}
if( filters & TextureFilter::TypeLeaveChannelR )
{
finalPixelFormat = LeaveChannelR::getDestinationFormat( finalPixelFormat );
filtersVec.push_back( OGRE_NEW TextureFilter::LeaveChannelR() );
}

//Add mipmap generation as one of the last steps
if( filters & TextureFilter::TypeGenerateDefaultMipmaps )
{
const uint8 mipmapGen = selectMipmapGen( filters, image, texture->getTextureManager() );
const uint8 mipmapGen =
selectMipmapGen( filters, image, finalPixelFormat, texture->getTextureManager() );
//If the user wants Mipmaps when loading OnStorage -> OnSystemRam
//then he should either explicitly ask only for SW filters, or
//load the texture to Resident first, then download to OnSystemRam.
Expand Down Expand Up @@ -141,16 +142,17 @@ namespace TextureFilter
//Add mipmap generation as one of the last steps
if( filters & TextureFilter::TypeGenerateDefaultMipmaps )
{
const uint8 mipmapGen = selectMipmapGen( filters, image, textureGpuManager );
const uint8 mipmapGen =
selectMipmapGen( filters, image, inOutPixelFormat, textureGpuManager );

const bool canDoMipmaps =
(mipmapGen == DefaultMipmapGen::HwMode &&
PixelFormatGpuUtils::supportsHwMipmaps( image.getPixelFormat() )) ||
(mipmapGen == DefaultMipmapGen::SwMode &&
Image2::supportsSwMipmaps( image.getPixelFormat(), image.getDepthOrSlices(),
image.getTextureType(),
static_cast<Image2::Filter>(
GenerateSwMipmaps::getFilter( image ) ) ) );
( mipmapGen == DefaultMipmapGen::HwMode &&
textureGpuManager->checkSupport( inOutPixelFormat,
TextureFlags::AllowAutomipmaps ) ) ||
( mipmapGen == DefaultMipmapGen::SwMode &&
Image2::supportsSwMipmaps(
inOutPixelFormat, image.getDepthOrSlices(), image.getTextureType(),
static_cast<Image2::Filter>( GenerateSwMipmaps::getFilter( image ) ) ) );

if( canDoMipmaps && inOutNumMipmaps <= 1u)
{
Expand Down
7 changes: 7 additions & 0 deletions OgreMain/src/OgreTextureGpuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,13 @@ namespace Ogre
OGRE_ASSERT_LOW(
textureFlags != TextureFlags::NotTexture &&
"Invalid textureFlags combination. Asking to check if format is supported to do nothing" );

if( textureFlags & TextureFlags::AllowAutomipmaps )
{
if( !PixelFormatGpuUtils::supportsHwMipmaps( format ) )
return false;
}

return true;
}
//-----------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions RenderSystems/Metal/src/OgreMetalTextureGpuManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ OGRE_NEW MetalStagingTexture( mVaoManager,
break;
}
#endif

if( textureFlags & TextureFlags::AllowAutomipmaps )
{
if( !PixelFormatGpuUtils::supportsHwMipmaps( format ) )
return false;
}

return true;
}
}
4 changes: 4 additions & 0 deletions RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,11 @@ namespace Ogre
}

if( textureFlags & TextureFlags::AllowAutomipmaps )
{
features |= VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
if( !PixelFormatGpuUtils::supportsHwMipmaps( format ) )
return false;
}

if( ( props.optimalTilingFeatures & features ) == features )
return true;
Expand Down

0 comments on commit 1cebf78

Please sign in to comment.