From c26e0f5923bd44a0356dab8064db3e2fadecd972 Mon Sep 17 00:00:00 2001 From: Preben Eriksen Date: Thu, 10 Nov 2022 13:41:40 +0100 Subject: [PATCH] PE: DDS - Improve import time if source already has mipmaps and are compressed. --- .../TextureTool/TextureTool.DirectXTex.cpp | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp b/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp index b58dd878a..540c8e186 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp +++ b/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp @@ -623,8 +623,21 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path sliceData.Mips.Resize(mipLevels); } + bool bKeepAsIs = false; + if (!options.FlipY &&options.Compress && type == ImageType::DDS && mipLevels == sourceMipLevels && DirectX::IsCompressed(sourceDxgiFormat)) + { + if (!DirectX::IsSRGB(sourceDxgiFormat)) + { + // PE: Keep image in the current compressed format (artist choice) so we dont have to run the slow mipmap generation. + // PE: Also converting a BC1 normal map to BC5 will not improve it but just use double gpu mem. + bKeepAsIs = true; + targetDxgiFormat = sourceDxgiFormat; + targetFormat = ToPixelFormat(currentImage->GetMetadata().format); + } + } + // Decompress if texture is compressed (next steps need decompressed input data, for eg. mip maps generation or format changing) - if (DirectX::IsCompressed(sourceDxgiFormat)) + if (!bKeepAsIs && DirectX::IsCompressed(sourceDxgiFormat)) { auto& tmpImg = GET_TMP_IMG(); @@ -640,7 +653,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Fix sRGB problem - if (DirectX::IsSRGB(sourceDxgiFormat)) + if (!bKeepAsIs && DirectX::IsSRGB(sourceDxgiFormat)) { sourceDxgiFormat = ToDxgiFormat(PixelFormatExtensions::ToNonsRGB(ToPixelFormat(sourceDxgiFormat))); ((DirectX::TexMetadata&)currentImage->GetMetadata()).format = sourceDxgiFormat; @@ -649,7 +662,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Remove alpha if source texture has it but output should not, valid for compressed output only (DirectX seams to use alpha to pre-multiply colors because BC1 format has no place for alpha) - if (DirectX::HasAlpha(sourceDxgiFormat) && options.Type == TextureFormatType::ColorRGB && options.Compress) + if (!bKeepAsIs && DirectX::HasAlpha(sourceDxgiFormat) && options.Type == TextureFormatType::ColorRGB && options.Compress) { auto& tmpImg = GET_TMP_IMG(); @@ -674,7 +687,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Check flip/rotate source image - if (options.FlipY) + if (!bKeepAsIs && options.FlipY) { auto& tmpImg = GET_TMP_IMG(); @@ -691,7 +704,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Generate mip maps chain - if (useMipLevels && options.GenerateMipMaps) + if (!bKeepAsIs && useMipLevels && options.GenerateMipMaps) { auto& tmpImg = GET_TMP_IMG(); @@ -714,7 +727,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Preserve mipmap alpha coverage (if requested) - if (DirectX::HasAlpha(currentImage->GetMetadata().format) && options.PreserveAlphaCoverage && useMipLevels) + if (!bKeepAsIs && DirectX::HasAlpha(currentImage->GetMetadata().format) && options.PreserveAlphaCoverage && useMipLevels) { auto& tmpImg = GET_TMP_IMG(); @@ -746,7 +759,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path ASSERT((int32)currentImage->GetMetadata().mipLevels >= mipLevels); // Compress mip maps or convert image - if (targetDxgiFormat != sourceDxgiFormat) + if (!bKeepAsIs && targetDxgiFormat != sourceDxgiFormat) { auto& tmpImg = GET_TMP_IMG();