PE: DDS - Improve import time if source already has mipmaps and are compressed.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user