Add initial ASTC pixel format support
This commit is contained in:
@@ -513,6 +513,16 @@ API_ENUM() enum class PixelFormat : uint32
|
||||
/// </summary>
|
||||
BC7_UNorm_sRGB = 99,
|
||||
|
||||
/// <summary>
|
||||
/// A four-component ASTC (4x4 pixel block in 128 bits) block-compression format that supports RGBA channels.
|
||||
/// </summary>
|
||||
ASTC_4x4_UNorm = 100,
|
||||
|
||||
/// <summary>
|
||||
/// A four-component ASTC (4x4 pixel block in 128 bits) block-compression format that supports RGBA channels.
|
||||
/// </summary>
|
||||
ASTC_4x4_UNorm_sRGB = 101,
|
||||
|
||||
/// <summary>
|
||||
/// The maximum format value (for internal use only).
|
||||
/// </summary>
|
||||
|
||||
@@ -5,19 +5,12 @@
|
||||
|
||||
// ReSharper disable CppClangTidyClangDiagnosticSwitchEnum
|
||||
|
||||
#define MAX_PIXEL_FORMATS 256
|
||||
|
||||
namespace
|
||||
{
|
||||
int32 sizeOfInBits[MAX_PIXEL_FORMATS];
|
||||
|
||||
int32 GetIndex(const PixelFormat format)
|
||||
{
|
||||
return (int32)format;
|
||||
}
|
||||
int32 sizeOfInBits[(int32)PixelFormat::MAX];
|
||||
}
|
||||
|
||||
#define InitFormat(formats, bitCount) for(int i = 0; i < ARRAY_COUNT(formats); i++) { sizeOfInBits[GetIndex(formats[i])] = bitCount; }
|
||||
#define InitFormat(formats, bitCount) for(int i = 0; i < ARRAY_COUNT(formats); i++) { sizeOfInBits[(int32)formats[i]] = bitCount; }
|
||||
|
||||
void PixelFormatExtensions::Init()
|
||||
{
|
||||
@@ -35,7 +28,9 @@ void PixelFormatExtensions::Init()
|
||||
PixelFormat::R8_SNorm,
|
||||
PixelFormat::R8_Typeless,
|
||||
PixelFormat::R8_UInt,
|
||||
PixelFormat::R8_UNorm
|
||||
PixelFormat::R8_UNorm,
|
||||
PixelFormat::ASTC_4x4_UNorm,
|
||||
PixelFormat::ASTC_4x4_UNorm_sRGB,
|
||||
};
|
||||
InitFormat(formats2, 8);
|
||||
|
||||
@@ -53,8 +48,7 @@ void PixelFormatExtensions::Init()
|
||||
PixelFormat::R8G8_SNorm,
|
||||
PixelFormat::R8G8_Typeless,
|
||||
PixelFormat::R8G8_UInt,
|
||||
PixelFormat::R8G8_UNorm
|
||||
|
||||
PixelFormat::R8G8_UNorm,
|
||||
};
|
||||
InitFormat(formats3, 16);
|
||||
|
||||
@@ -163,7 +157,7 @@ void PixelFormatExtensions::Init()
|
||||
|
||||
int32 PixelFormatExtensions::SizeInBits(PixelFormat format)
|
||||
{
|
||||
return sizeOfInBits[GetIndex(format)];
|
||||
return sizeOfInBits[(int32)format];
|
||||
}
|
||||
|
||||
int32 PixelFormatExtensions::AlphaSizeInBits(const PixelFormat format)
|
||||
@@ -319,6 +313,8 @@ bool PixelFormatExtensions::IsCompressed(const 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 true;
|
||||
default:
|
||||
return false;
|
||||
@@ -356,6 +352,18 @@ bool PixelFormatExtensions::IsCompressedBC(PixelFormat format)
|
||||
}
|
||||
}
|
||||
|
||||
bool PixelFormatExtensions::IsCompressedASTC(PixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case PixelFormat::ASTC_4x4_UNorm:
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool PixelFormatExtensions::IsPacked(const PixelFormat format)
|
||||
{
|
||||
return format == PixelFormat::R8G8_B8G8_UNorm || format == PixelFormat::G8R8_G8B8_UNorm;
|
||||
@@ -382,6 +390,7 @@ bool PixelFormatExtensions::IsSRGB(const PixelFormat format)
|
||||
case PixelFormat::B8G8R8A8_UNorm_sRGB:
|
||||
case PixelFormat::B8G8R8X8_UNorm_sRGB:
|
||||
case PixelFormat::BC7_UNorm_sRGB:
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -392,6 +401,8 @@ bool PixelFormatExtensions::IsHDR(const PixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case PixelFormat::R11G11B10_Float:
|
||||
case PixelFormat::R10G10B10A2_UNorm:
|
||||
case PixelFormat::R16G16B16A16_Float:
|
||||
case PixelFormat::R32G32B32A32_Float:
|
||||
case PixelFormat::R16G16_Float:
|
||||
@@ -399,7 +410,6 @@ bool PixelFormatExtensions::IsHDR(const PixelFormat format)
|
||||
case PixelFormat::BC6H_Sf16:
|
||||
case PixelFormat::BC6H_Uf16:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -527,7 +537,7 @@ bool PixelFormatExtensions::IsInteger(const PixelFormat format)
|
||||
}
|
||||
}
|
||||
|
||||
int PixelFormatExtensions::ComputeScanlineCount(const PixelFormat format, int32 height)
|
||||
int32 PixelFormatExtensions::ComputeScanlineCount(const PixelFormat format, int32 height)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
@@ -552,13 +562,15 @@ int PixelFormatExtensions::ComputeScanlineCount(const PixelFormat format, int32
|
||||
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 Math::Max(1, (height + 3) / 4);
|
||||
default:
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
int PixelFormatExtensions::ComputeComponentsCount(const PixelFormat format)
|
||||
int32 PixelFormatExtensions::ComputeComponentsCount(const PixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
@@ -599,6 +611,8 @@ int PixelFormatExtensions::ComputeComponentsCount(const PixelFormat format)
|
||||
case PixelFormat::B8G8R8A8_UNorm_sRGB:
|
||||
case PixelFormat::B8G8R8X8_Typeless:
|
||||
case PixelFormat::B8G8R8X8_UNorm_sRGB:
|
||||
case PixelFormat::ASTC_4x4_UNorm:
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return 4;
|
||||
case PixelFormat::R32G32B32_Typeless:
|
||||
case PixelFormat::R32G32B32_Float:
|
||||
@@ -678,6 +692,8 @@ PixelFormat PixelFormatExtensions::TosRGB(const PixelFormat format)
|
||||
return PixelFormat::B8G8R8X8_UNorm_sRGB;
|
||||
case PixelFormat::BC7_UNorm:
|
||||
return PixelFormat::BC7_UNorm_sRGB;
|
||||
case PixelFormat::ASTC_4x4_UNorm:
|
||||
return PixelFormat::ASTC_4x4_UNorm_sRGB;
|
||||
default:
|
||||
return format;
|
||||
}
|
||||
@@ -701,6 +717,8 @@ PixelFormat PixelFormatExtensions::ToNonsRGB(const PixelFormat format)
|
||||
return PixelFormat::B8G8R8X8_UNorm;
|
||||
case PixelFormat::BC7_UNorm_sRGB:
|
||||
return PixelFormat::BC7_UNorm;
|
||||
case PixelFormat::ASTC_4x4_UNorm_sRGB:
|
||||
return PixelFormat::ASTC_4x4_UNorm;
|
||||
default:
|
||||
return format;
|
||||
}
|
||||
|
||||
@@ -95,6 +95,13 @@ public:
|
||||
/// <returns>True if the <see cref="PixelFormat"/> is a compressed format from BC formats family.</returns>
|
||||
API_FUNCTION() static bool IsCompressedBC(PixelFormat format);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the <see cref="PixelFormat"/> is a compressed format from ASTC formats family (various block sizes).
|
||||
/// </summary>
|
||||
/// <param name="format">The format to check for compressed.</param>
|
||||
/// <returns>True if the <see cref="PixelFormat"/> is a compressed format from ASTC formats family.</returns>
|
||||
API_FUNCTION() static bool IsCompressedASTC(PixelFormat format);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified <see cref="PixelFormat"/> is packed.
|
||||
/// </summary>
|
||||
@@ -164,14 +171,14 @@ public:
|
||||
/// <param name="format">The <see cref="PixelFormat"/>.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
/// <returns>The scanline count.</returns>
|
||||
API_FUNCTION() static int ComputeScanlineCount(PixelFormat format, int32 height);
|
||||
API_FUNCTION() static int32 ComputeScanlineCount(PixelFormat format, int32 height);
|
||||
|
||||
/// <summary>
|
||||
/// Computes the format components count (number of R, G, B, A channels).
|
||||
/// </summary>
|
||||
/// <param name="format">The <see cref="PixelFormat"/>.</param>
|
||||
/// <returns>The components count.</returns>
|
||||
API_FUNCTION() static int ComputeComponentsCount(PixelFormat format);
|
||||
API_FUNCTION() static int32 ComputeComponentsCount(PixelFormat format);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the equivalent sRGB format to the provided format.
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include "Engine/Core/Types/StringBuilder.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
|
||||
VkFormat RenderToolsVulkan::PixelFormatToVkFormat[static_cast<int32>(PixelFormat::MAX)] = {
|
||||
|
||||
VkFormat RenderToolsVulkan::PixelFormatToVkFormat[102] =
|
||||
{
|
||||
VK_FORMAT_UNDEFINED,
|
||||
VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||
VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||
@@ -27,13 +27,10 @@ VkFormat RenderToolsVulkan::PixelFormatToVkFormat[static_cast<int32>(PixelFormat
|
||||
VK_FORMAT_R32G32_SFLOAT,
|
||||
VK_FORMAT_R32G32_UINT,
|
||||
VK_FORMAT_R32G32_SINT,
|
||||
VK_FORMAT_UNDEFINED,
|
||||
// TODO: R32G8X24_Typeless
|
||||
VK_FORMAT_UNDEFINED, // TODO: R32G8X24_Typeless
|
||||
VK_FORMAT_D32_SFLOAT_S8_UINT,
|
||||
VK_FORMAT_UNDEFINED,
|
||||
// TODO: R32_Float_X8X24_Typeless
|
||||
VK_FORMAT_UNDEFINED,
|
||||
// TODO: X32_Typeless_G8X24_UInt
|
||||
VK_FORMAT_UNDEFINED, // TODO: R32_Float_X8X24_Typeless
|
||||
VK_FORMAT_UNDEFINED, // TODO: X32_Typeless_G8X24_UInt
|
||||
VK_FORMAT_A2B10G10R10_UNORM_PACK32,
|
||||
VK_FORMAT_A2B10G10R10_UNORM_PACK32,
|
||||
VK_FORMAT_A2B10G10R10_UINT_PACK32,
|
||||
@@ -76,15 +73,11 @@ VkFormat RenderToolsVulkan::PixelFormatToVkFormat[static_cast<int32>(PixelFormat
|
||||
VK_FORMAT_R8_UINT,
|
||||
VK_FORMAT_R8_SNORM,
|
||||
VK_FORMAT_R8_SINT,
|
||||
VK_FORMAT_UNDEFINED,
|
||||
// TODO: A8_UNorm
|
||||
VK_FORMAT_UNDEFINED,
|
||||
// TODO: R1_UNorm
|
||||
VK_FORMAT_UNDEFINED, // TODO: A8_UNorm
|
||||
VK_FORMAT_UNDEFINED, // TODO: R1_UNorm
|
||||
VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
|
||||
VK_FORMAT_UNDEFINED,
|
||||
// TODO: R8G8_B8G8_UNorm
|
||||
VK_FORMAT_UNDEFINED,
|
||||
// TODO: G8R8_G8B8_UNorm
|
||||
VK_FORMAT_UNDEFINED, // TODO: R8G8_B8G8_UNorm
|
||||
VK_FORMAT_UNDEFINED, // TODO: G8R8_G8B8_UNorm
|
||||
VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
|
||||
VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
|
||||
VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
|
||||
@@ -104,8 +97,7 @@ VkFormat RenderToolsVulkan::PixelFormatToVkFormat[static_cast<int32>(PixelFormat
|
||||
VK_FORMAT_B5G5R5A1_UNORM_PACK16,
|
||||
VK_FORMAT_B8G8R8A8_UNORM,
|
||||
VK_FORMAT_B8G8R8A8_UNORM,
|
||||
VK_FORMAT_UNDEFINED,
|
||||
// TODO: R10G10B10_Xr_Bias_A2_UNorm
|
||||
VK_FORMAT_UNDEFINED, // TODO: R10G10B10_Xr_Bias_A2_UNorm
|
||||
VK_FORMAT_B8G8R8A8_UNORM,
|
||||
VK_FORMAT_B8G8R8A8_SRGB,
|
||||
VK_FORMAT_B8G8R8A8_UNORM,
|
||||
@@ -116,81 +108,53 @@ VkFormat RenderToolsVulkan::PixelFormatToVkFormat[static_cast<int32>(PixelFormat
|
||||
VK_FORMAT_BC7_UNORM_BLOCK,
|
||||
VK_FORMAT_BC7_UNORM_BLOCK,
|
||||
VK_FORMAT_BC7_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
|
||||
};
|
||||
|
||||
VkBlendFactor RenderToolsVulkan::BlendToVkBlendFactor[static_cast<int32>(BlendingMode::Blend::MAX)] =
|
||||
VkBlendFactor RenderToolsVulkan::BlendToVkBlendFactor[20] =
|
||||
{
|
||||
VK_BLEND_FACTOR_MAX_ENUM,
|
||||
VK_BLEND_FACTOR_ZERO,
|
||||
// Zero
|
||||
VK_BLEND_FACTOR_ONE,
|
||||
// One
|
||||
VK_BLEND_FACTOR_SRC_COLOR,
|
||||
// SrcColor
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
|
||||
// InvSrcColor
|
||||
VK_BLEND_FACTOR_SRC_ALPHA,
|
||||
// SrcAlpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
// InvSrcAlpha
|
||||
VK_BLEND_FACTOR_DST_ALPHA,
|
||||
// DestAlpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
|
||||
// InvDestAlpha
|
||||
VK_BLEND_FACTOR_DST_COLOR,
|
||||
// DestColor,
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR,
|
||||
// InvDestColor
|
||||
VK_BLEND_FACTOR_SRC_ALPHA_SATURATE,
|
||||
// SrcAlphaSat
|
||||
VK_BLEND_FACTOR_CONSTANT_ALPHA,
|
||||
// BlendFactor
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
|
||||
// BlendInvFactor
|
||||
VK_BLEND_FACTOR_SRC1_COLOR,
|
||||
// Src1Color
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR,
|
||||
// InvSrc1Color
|
||||
VK_BLEND_FACTOR_SRC1_ALPHA,
|
||||
// Src1Alpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA,
|
||||
// InvSrc1Alpha
|
||||
VK_BLEND_FACTOR_ZERO, // Zero
|
||||
VK_BLEND_FACTOR_ONE, // One
|
||||
VK_BLEND_FACTOR_SRC_COLOR, // SrcColor
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR, // InvSrcColor
|
||||
VK_BLEND_FACTOR_SRC_ALPHA, // SrcAlpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // InvSrcAlpha
|
||||
VK_BLEND_FACTOR_DST_ALPHA, // DestAlpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA, // InvDestAlpha
|
||||
VK_BLEND_FACTOR_DST_COLOR, // DestColor,
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR, // InvDestColor
|
||||
VK_BLEND_FACTOR_SRC_ALPHA_SATURATE, // SrcAlphaSat
|
||||
VK_BLEND_FACTOR_CONSTANT_ALPHA, // BlendFactor
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA, // BlendInvFactor
|
||||
VK_BLEND_FACTOR_SRC1_COLOR, // Src1Color
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR, // InvSrc1Color
|
||||
VK_BLEND_FACTOR_SRC1_ALPHA, // Src1Alpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA, // InvSrc1Alpha
|
||||
};
|
||||
|
||||
VkBlendOp RenderToolsVulkan::OperationToVkBlendOp[static_cast<int32>(BlendingMode::Operation::MAX)] =
|
||||
VkBlendOp RenderToolsVulkan::OperationToVkBlendOp[6] =
|
||||
{
|
||||
VK_BLEND_OP_MAX_ENUM,
|
||||
VK_BLEND_OP_ADD,
|
||||
// Add
|
||||
VK_BLEND_OP_SUBTRACT,
|
||||
// Subtract
|
||||
VK_BLEND_OP_REVERSE_SUBTRACT,
|
||||
// RevSubtract
|
||||
VK_BLEND_OP_MIN,
|
||||
// Min
|
||||
VK_BLEND_OP_MAX,
|
||||
// Max
|
||||
VK_BLEND_OP_ADD, // Add
|
||||
VK_BLEND_OP_SUBTRACT, // Subtract
|
||||
VK_BLEND_OP_REVERSE_SUBTRACT, // RevSubtract
|
||||
VK_BLEND_OP_MIN, // Min
|
||||
VK_BLEND_OP_MAX, // Max
|
||||
};
|
||||
|
||||
VkCompareOp RenderToolsVulkan::ComparisonFuncToVkCompareOp[static_cast<int32>(ComparisonFunc::MAX)] =
|
||||
VkCompareOp RenderToolsVulkan::ComparisonFuncToVkCompareOp[9] =
|
||||
{
|
||||
VK_COMPARE_OP_MAX_ENUM,
|
||||
VK_COMPARE_OP_NEVER,
|
||||
// Never
|
||||
VK_COMPARE_OP_LESS,
|
||||
// Less
|
||||
VK_COMPARE_OP_EQUAL,
|
||||
// Equal
|
||||
VK_COMPARE_OP_LESS_OR_EQUAL,
|
||||
// LessEqual
|
||||
VK_COMPARE_OP_GREATER,
|
||||
// Grather
|
||||
VK_COMPARE_OP_NOT_EQUAL,
|
||||
// NotEqual
|
||||
VK_COMPARE_OP_GREATER_OR_EQUAL,
|
||||
// GratherEqual
|
||||
VK_COMPARE_OP_ALWAYS,
|
||||
// Always
|
||||
VK_COMPARE_OP_NEVER, // Never
|
||||
VK_COMPARE_OP_LESS, // Less
|
||||
VK_COMPARE_OP_EQUAL, // Equal
|
||||
VK_COMPARE_OP_LESS_OR_EQUAL, // LessEqual
|
||||
VK_COMPARE_OP_GREATER, // Grather
|
||||
VK_COMPARE_OP_NOT_EQUAL, // NotEqual
|
||||
VK_COMPARE_OP_GREATER_OR_EQUAL, // GratherEqual
|
||||
VK_COMPARE_OP_ALWAYS, // Always
|
||||
};
|
||||
|
||||
#define VKERR(x) case x: sb.Append(TEXT(#x)); break
|
||||
|
||||
Reference in New Issue
Block a user