From c6c53baff2417b6dfc16de68664502b7840b90d7 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 18 Dec 2023 09:59:29 +0100 Subject: [PATCH] Improvements for astc format --- Source/Engine/Graphics/PixelFormatExtensions.cpp | 2 ++ Source/Engine/Graphics/RenderTools.cpp | 4 ++-- .../Engine/Tools/TextureTool/TextureTool.astc.cpp | 15 +++------------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Source/Engine/Graphics/PixelFormatExtensions.cpp b/Source/Engine/Graphics/PixelFormatExtensions.cpp index fafda87bf..4431870ee 100644 --- a/Source/Engine/Graphics/PixelFormatExtensions.cpp +++ b/Source/Engine/Graphics/PixelFormatExtensions.cpp @@ -666,6 +666,8 @@ int32 PixelFormatExtensions::ComputeBlockSize(PixelFormat format) case PixelFormat::BC7_Typeless: case PixelFormat::BC7_UNorm: case PixelFormat::BC7_UNorm_sRGB: + case PixelFormat::ASTC_4x4_UNorm: + case PixelFormat::ASTC_4x4_UNorm_sRGB: return 4; default: return 1; diff --git a/Source/Engine/Graphics/RenderTools.cpp b/Source/Engine/Graphics/RenderTools.cpp index 7ffecd62c..5fc6c7d65 100644 --- a/Source/Engine/Graphics/RenderTools.cpp +++ b/Source/Engine/Graphics/RenderTools.cpp @@ -332,10 +332,10 @@ void RenderTools::ComputePitch(PixelFormat format, int32 width, int32 height, ui case PixelFormat::ASTC_4x4_UNorm: case PixelFormat::ASTC_4x4_UNorm_sRGB: { - const int32 blockSize = 4; // TODO: use PixelFormatExtensions to get block size for a format and handle different astc + const int32 blockSize = PixelFormatExtensions::ComputeBlockSize(format); uint32 nbw = Math::Max(1, Math::DivideAndRoundUp(width, blockSize)); uint32 nbh = Math::Max(1, Math::DivideAndRoundUp(height, blockSize)); - rowPitch = nbw * 16; + rowPitch = nbw * 16; // All ASTC blocks use 128 bits slicePitch = rowPitch * nbh; } break; diff --git a/Source/Engine/Tools/TextureTool/TextureTool.astc.cpp b/Source/Engine/Tools/TextureTool/TextureTool.astc.cpp index a175d679b..3dcd8bb72 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.astc.cpp +++ b/Source/Engine/Tools/TextureTool/TextureTool.astc.cpp @@ -12,18 +12,9 @@ bool TextureTool::ConvertAstc(TextureData& dst, const TextureData& src, const PixelFormat dstFormat) { - int32 blockSize, bytesPerBlock = 16; - // TODO: use block size from PixelFormatExtensions - switch (dstFormat) - { - case PixelFormat::ASTC_4x4_UNorm: - case PixelFormat::ASTC_4x4_UNorm_sRGB: - blockSize = 4; - break; - default: - LOG(Warning, "Cannot compress image. Unsupported format {0}", static_cast(dstFormat)); - return true; - } + ASSERT(PixelFormatExtensions::IsCompressedASTC(dstFormat)); + const int32 blockSize = PixelFormatExtensions::ComputeBlockSize(dstFormat); + const int32 bytesPerBlock = 16; // All ASTC blocks use 128 bits // Configure the compressor run const bool isSRGB = PixelFormatExtensions::IsSRGB(dstFormat);