Fix texture streaming minimum mips to load for block compressed textures

This commit is contained in:
Wojtek Figat
2021-06-18 14:42:09 +02:00
parent f582ca5051
commit 4681d8da56
3 changed files with 13 additions and 11 deletions

View File

@@ -110,6 +110,14 @@ bool StreamingTexture::Create(const TextureHeader& header)
// That's one of the main advantages of the current resources streaming system.
_header = header;
_isBlockCompressed = PixelFormatExtensions::IsCompressed(_header.Format);
if (_isBlockCompressed)
{
// Ensure that streaming doesn't go too low because the hardware expects the texture to be min in size of compressed texture block
int32 lastMip = header.MipLevels - 1;
while (header.Width >> lastMip < 4 && header.Height >> lastMip < 4)
lastMip--;
_minMipCountBlockCompressed = header.MipLevels - lastMip + 1;
}
// Request resource streaming
#if GPU_ENABLE_TEXTURES_STREAMING

View File

@@ -12,6 +12,7 @@
class FLAXENGINE_API StreamingTexture : public Object, public StreamableResource
{
friend class TextureBase;
friend class TexturesStreamingHandler;
friend class StreamTextureMipTask;
friend class StreamTextureResizeTask;
protected:
@@ -20,6 +21,7 @@ protected:
GPUTexture* _texture;
TextureHeader _header;
volatile mutable int64 _streamingTasksCount;
int32 _minMipCountBlockCompressed;
bool _isBlockCompressed;
public:
@@ -122,14 +124,6 @@ public:
return &_header;
}
/// <summary>
/// Gets a boolean indicating whether this <see cref="StreamingTexture"/> is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7).
/// </summary>
FORCE_INLINE bool IsBlockCompressed() const
{
return _isBlockCompressed;
}
public:
/// <summary>

View File

@@ -57,10 +57,10 @@ int32 TexturesStreamingHandler::CalculateResidency(StreamableResource* resource,
#endif
}
if (mipLevels > 0 && mipLevels < 3 && totalMipLevels > 1 && texture.IsBlockCompressed())
if (mipLevels > 0 && mipLevels < texture._minMipCountBlockCompressed && texture._isBlockCompressed)
{
// Block compressed textures require minimum size of 4 (3 mips or more)
mipLevels = 3;
// Block compressed textures require minimum size of 4
mipLevels = texture._minMipCountBlockCompressed;
}
return Math::Clamp(mipLevels, 0, totalMipLevels);