Add more ASTC texture formats with larger block sizes

This commit is contained in:
Wojtek Figat
2023-12-20 15:12:12 +01:00
parent e4df1fc756
commit 53a2ebbd17
5 changed files with 80 additions and 25 deletions

View File

@@ -29,6 +29,21 @@ void PixelFormatExtensions::Init()
PixelFormat::R8_Typeless,
PixelFormat::R8_UInt,
PixelFormat::R8_UNorm,
PixelFormat::BC2_Typeless,
PixelFormat::BC2_UNorm,
PixelFormat::BC2_UNorm_sRGB,
PixelFormat::BC3_Typeless,
PixelFormat::BC3_UNorm,
PixelFormat::BC3_UNorm_sRGB,
PixelFormat::BC5_SNorm,
PixelFormat::BC5_Typeless,
PixelFormat::BC5_UNorm,
PixelFormat::BC6H_Sf16,
PixelFormat::BC6H_Typeless,
PixelFormat::BC6H_Uf16,
PixelFormat::BC7_Typeless,
PixelFormat::BC7_UNorm,
PixelFormat::BC7_UNorm_sRGB,
PixelFormat::ASTC_4x4_UNorm,
PixelFormat::ASTC_4x4_UNorm_sRGB,
};
@@ -134,25 +149,6 @@ void PixelFormatExtensions::Init()
PixelFormat::BC4_UNorm,
};
InitFormat(formats8, 4);
PixelFormat formats9[] = {
PixelFormat::BC2_Typeless,
PixelFormat::BC2_UNorm,
PixelFormat::BC2_UNorm_sRGB,
PixelFormat::BC3_Typeless,
PixelFormat::BC3_UNorm,
PixelFormat::BC3_UNorm_sRGB,
PixelFormat::BC5_SNorm,
PixelFormat::BC5_Typeless,
PixelFormat::BC5_UNorm,
PixelFormat::BC6H_Sf16,
PixelFormat::BC6H_Typeless,
PixelFormat::BC6H_Uf16,
PixelFormat::BC7_Typeless,
PixelFormat::BC7_UNorm,
PixelFormat::BC7_UNorm_sRGB,
};
InitFormat(formats9, 8);
}
int32 PixelFormatExtensions::SizeInBits(PixelFormat format)
@@ -315,6 +311,12 @@ bool PixelFormatExtensions::IsCompressed(const PixelFormat format)
case PixelFormat::BC7_UNorm_sRGB:
case PixelFormat::ASTC_4x4_UNorm:
case PixelFormat::ASTC_4x4_UNorm_sRGB:
case PixelFormat::ASTC_6x6_UNorm:
case PixelFormat::ASTC_6x6_UNorm_sRGB:
case PixelFormat::ASTC_8x8_UNorm:
case PixelFormat::ASTC_8x8_UNorm_sRGB:
case PixelFormat::ASTC_10x10_UNorm:
case PixelFormat::ASTC_10x10_UNorm_sRGB:
return true;
default:
return false;
@@ -358,6 +360,12 @@ bool PixelFormatExtensions::IsCompressedASTC(PixelFormat format)
{
case PixelFormat::ASTC_4x4_UNorm:
case PixelFormat::ASTC_4x4_UNorm_sRGB:
case PixelFormat::ASTC_6x6_UNorm:
case PixelFormat::ASTC_6x6_UNorm_sRGB:
case PixelFormat::ASTC_8x8_UNorm:
case PixelFormat::ASTC_8x8_UNorm_sRGB:
case PixelFormat::ASTC_10x10_UNorm:
case PixelFormat::ASTC_10x10_UNorm_sRGB:
return true;
default:
return false;
@@ -391,6 +399,9 @@ bool PixelFormatExtensions::IsSRGB(const PixelFormat format)
case PixelFormat::B8G8R8X8_UNorm_sRGB:
case PixelFormat::BC7_UNorm_sRGB:
case PixelFormat::ASTC_4x4_UNorm_sRGB:
case PixelFormat::ASTC_6x6_UNorm_sRGB:
case PixelFormat::ASTC_8x8_UNorm_sRGB:
case PixelFormat::ASTC_10x10_UNorm_sRGB:
return true;
default:
return false;
@@ -580,6 +591,12 @@ int32 PixelFormatExtensions::ComputeComponentsCount(const PixelFormat format)
case PixelFormat::B8G8R8X8_UNorm_sRGB:
case PixelFormat::ASTC_4x4_UNorm:
case PixelFormat::ASTC_4x4_UNorm_sRGB:
case PixelFormat::ASTC_6x6_UNorm:
case PixelFormat::ASTC_6x6_UNorm_sRGB:
case PixelFormat::ASTC_8x8_UNorm:
case PixelFormat::ASTC_8x8_UNorm_sRGB:
case PixelFormat::ASTC_10x10_UNorm:
case PixelFormat::ASTC_10x10_UNorm_sRGB:
return 4;
case PixelFormat::R32G32B32_Typeless:
case PixelFormat::R32G32B32_Float:
@@ -669,6 +686,15 @@ int32 PixelFormatExtensions::ComputeBlockSize(PixelFormat format)
case PixelFormat::ASTC_4x4_UNorm:
case PixelFormat::ASTC_4x4_UNorm_sRGB:
return 4;
case PixelFormat::ASTC_6x6_UNorm:
case PixelFormat::ASTC_6x6_UNorm_sRGB:
return 6;
case PixelFormat::ASTC_8x8_UNorm:
case PixelFormat::ASTC_8x8_UNorm_sRGB:
return 8;
case PixelFormat::ASTC_10x10_UNorm:
case PixelFormat::ASTC_10x10_UNorm_sRGB:
return 10;
default:
return 1;
}
@@ -694,6 +720,12 @@ PixelFormat PixelFormatExtensions::TosRGB(const PixelFormat format)
return PixelFormat::BC7_UNorm_sRGB;
case PixelFormat::ASTC_4x4_UNorm:
return PixelFormat::ASTC_4x4_UNorm_sRGB;
case PixelFormat::ASTC_6x6_UNorm:
return PixelFormat::ASTC_6x6_UNorm_sRGB;
case PixelFormat::ASTC_8x8_UNorm:
return PixelFormat::ASTC_8x8_UNorm_sRGB;
case PixelFormat::ASTC_10x10_UNorm:
return PixelFormat::ASTC_10x10_UNorm_sRGB;
default:
return format;
}
@@ -719,6 +751,12 @@ PixelFormat PixelFormatExtensions::ToNonsRGB(const PixelFormat format)
return PixelFormat::BC7_UNorm;
case PixelFormat::ASTC_4x4_UNorm_sRGB:
return PixelFormat::ASTC_4x4_UNorm;
case PixelFormat::ASTC_6x6_UNorm_sRGB:
return PixelFormat::ASTC_6x6_UNorm;
case PixelFormat::ASTC_8x8_UNorm_sRGB:
return PixelFormat::ASTC_8x8_UNorm;
case PixelFormat::ASTC_10x10_UNorm_sRGB:
return PixelFormat::ASTC_10x10_UNorm;
default:
return format;
}

View File

@@ -331,6 +331,12 @@ void RenderTools::ComputePitch(PixelFormat format, int32 width, int32 height, ui
break;
case PixelFormat::ASTC_4x4_UNorm:
case PixelFormat::ASTC_4x4_UNorm_sRGB:
case PixelFormat::ASTC_6x6_UNorm:
case PixelFormat::ASTC_6x6_UNorm_sRGB:
case PixelFormat::ASTC_8x8_UNorm:
case PixelFormat::ASTC_8x8_UNorm_sRGB:
case PixelFormat::ASTC_10x10_UNorm:
case PixelFormat::ASTC_10x10_UNorm_sRGB:
{
const int32 blockSize = PixelFormatExtensions::ComputeBlockSize(format);
uint32 nbw = Math::Max<uint32>(1, Math::DivideAndRoundUp(width, blockSize));

View File

@@ -337,14 +337,12 @@ int32 GPUTexture::ComputeBufferOffset(int32 subresource, int32 rowAlign, int32 s
int32 GPUTexture::ComputeBufferTotalSize(int32 rowAlign, int32 sliceAlign) const
{
int32 result = 0;
for (int32 mipLevel = 0; mipLevel < MipLevels(); mipLevel++)
{
const int32 slicePitch = ComputeSlicePitch(mipLevel, rowAlign);
const int32 depth = CalculateMipSize(Depth(), mipLevel);
result += Math::AlignUp<int32>(slicePitch * depth, sliceAlign);
}
return result * ArraySize();
}
@@ -355,8 +353,11 @@ int32 GPUTexture::ComputeSlicePitch(int32 mipLevel, int32 rowAlign) const
int32 GPUTexture::ComputeRowPitch(int32 mipLevel, int32 rowAlign) const
{
const int32 formatSize = PixelFormatExtensions::SizeInBytes(Format());
return Math::AlignUp<int32>(CalculateMipSize(Width(), mipLevel) * formatSize, rowAlign);
int32 mipWidth = CalculateMipSize(Width(), mipLevel);
int32 mipHeight = CalculateMipSize(Height(), mipLevel);
uint32 rowPitch, slicePitch;
RenderTools::ComputePitch(Format(), mipWidth, mipHeight, rowPitch, slicePitch);
return Math::AlignUp<int32>(rowPitch, rowAlign);
}
bool GPUTexture::Init(const GPUTextureDescription& desc)

View File

@@ -6,7 +6,7 @@
#include "Engine/Core/Types/StringBuilder.h"
#include "Engine/Core/Log.h"
VkFormat RenderToolsVulkan::PixelFormatToVkFormat[102] =
VkFormat RenderToolsVulkan::PixelFormatToVkFormat[108] =
{
VK_FORMAT_UNDEFINED,
VK_FORMAT_R32G32B32A32_SFLOAT,
@@ -110,6 +110,12 @@ VkFormat RenderToolsVulkan::PixelFormatToVkFormat[102] =
VK_FORMAT_BC7_SRGB_BLOCK,
VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
};
VkBlendFactor RenderToolsVulkan::BlendToVkBlendFactor[20] =

View File

@@ -8,6 +8,7 @@
#include "Engine/Core/Math/Color32.h"
#include "Engine/Graphics/Textures/TextureData.h"
#include "Engine/Graphics/PixelFormatExtensions.h"
#include "Engine/Graphics/RenderTools.h"
#include <ThirdParty/astc/astcenc.h>
bool TextureTool::ConvertAstc(TextureData& dst, const TextureData& src, const PixelFormat dstFormat)
@@ -87,7 +88,10 @@ bool TextureTool::ConvertAstc(TextureData& dst, const TextureData& src, const Pi
auto mipHeight = Math::Max(textureData->Height >> mipIndex, 1);
auto blocksWidth = Math::Max(Math::DivideAndRoundUp(mipWidth, blockSize), 1);
auto blocksHeight = Math::Max(Math::DivideAndRoundUp(mipHeight, blockSize), 1);
ASSERT(srcMip.RowPitch == mipWidth * PixelFormatExtensions::SizeInBytes(textureData->Format));
uint32 mipRowPitch, mipSlicePitch;
RenderTools::ComputePitch(textureData->Format, mipWidth, mipHeight, mipRowPitch, mipSlicePitch);
ASSERT(srcMip.RowPitch == mipRowPitch);
ASSERT(srcMip.DepthPitch == mipSlicePitch);
ASSERT(srcMip.Lines == mipHeight);
// Allocate memory