formats: Add vkuFormatTexelsPerBlock

This commit is contained in:
spencer-lunarg 2025-01-21 13:16:07 -05:00 committed by Spencer Fricke
parent 9cf0d32399
commit f07e27717a
3 changed files with 26 additions and 2 deletions

View file

@ -274,6 +274,10 @@ inline VkExtent3D vkuFormatTexelBlockExtent(VkFormat format);
// Returns the Compatibility Class of a VkFormat as defined by the spec
inline enum VKU_FORMAT_COMPATIBILITY_CLASS vkuFormatCompatibilityClass(VkFormat format);
// Returns the number of texels inside a texel block
// Will always be 1 when not using compressed block formats
inline uint32_t vkuFormatTexelsPerBlock(VkFormat format);
// Returns the number of bytes in a single Texel Block.
// When dealing with a depth/stencil format, need to consider using vkuFormatStencilSize or vkuFormatDepthSize.
// When dealing with mulit-planar formats, need to consider using vkuGetPlaneIndex.
@ -360,7 +364,7 @@ struct VKU_FORMAT_COMPONENT_INFO {
struct VKU_FORMAT_INFO {
enum VKU_FORMAT_COMPATIBILITY_CLASS compatibility;
uint32_t texel_block_size; // bytes
uint32_t texel_per_block;
uint32_t texels_per_block;
VkExtent3D block_extent;
uint32_t component_count;
struct VKU_FORMAT_COMPONENT_INFO components[VKU_FORMAT_MAX_COMPONENTS];
@ -2068,6 +2072,8 @@ inline VkExtent3D vkuFormatTexelBlockExtent(VkFormat format) { return vkuGetForm
inline enum VKU_FORMAT_COMPATIBILITY_CLASS vkuFormatCompatibilityClass(VkFormat format) { return vkuGetFormatInfo(format).compatibility; }
inline uint32_t vkuFormatTexelsPerBlock(VkFormat format) { return vkuGetFormatInfo(format).texels_per_block; }
inline uint32_t vkuFormatTexelBlockSize(VkFormat format) { return vkuGetFormatInfo(format).texel_block_size; }
// Deprecated - Use vkuFormatTexelBlockSize

View file

@ -220,6 +220,10 @@ inline VkExtent3D vkuFormatTexelBlockExtent(VkFormat format);
// Returns the Compatibility Class of a VkFormat as defined by the spec
inline enum VKU_FORMAT_COMPATIBILITY_CLASS vkuFormatCompatibilityClass(VkFormat format);
// Returns the number of texels inside a texel block
// Will always be 1 when not using compressed block formats
inline uint32_t vkuFormatTexelsPerBlock(VkFormat format);
// Returns the number of bytes in a single Texel Block.
// When dealing with a depth/stencil format, need to consider using vkuFormatStencilSize or vkuFormatDepthSize.
// When dealing with mulit-planar formats, need to consider using vkuGetPlaneIndex.
@ -299,7 +303,7 @@ struct VKU_FORMAT_COMPONENT_INFO {
struct VKU_FORMAT_INFO {
enum VKU_FORMAT_COMPATIBILITY_CLASS compatibility;
uint32_t texel_block_size; // bytes
uint32_t texel_per_block;
uint32_t texels_per_block;
VkExtent3D block_extent;
uint32_t component_count;
struct VKU_FORMAT_COMPONENT_INFO components[VKU_FORMAT_MAX_COMPONENTS];
@ -592,6 +596,8 @@ inline VkExtent3D vkuFormatTexelBlockExtent(VkFormat format) { return vkuGetForm
inline enum VKU_FORMAT_COMPATIBILITY_CLASS vkuFormatCompatibilityClass(VkFormat format) { return vkuGetFormatInfo(format).compatibility; }
inline uint32_t vkuFormatTexelsPerBlock(VkFormat format) { return vkuGetFormatInfo(format).texels_per_block; }
inline uint32_t vkuFormatTexelBlockSize(VkFormat format) { return vkuGetFormatInfo(format).texel_block_size; }
// Deprecated - Use vkuFormatTexelBlockSize

View file

@ -516,6 +516,18 @@ TEST(format_utils, vkuFormatCompatibilityClass) {
}
}
TEST(format_utils, vkuFormatTexelsPerBlock) {
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_R64G64_SFLOAT), 1u);
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_BC6H_UFLOAT_BLOCK), 16u);
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_ASTC_5x4_SRGB_BLOCK), 20u);
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_ASTC_5x5_SRGB_BLOCK), 25u);
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_ASTC_12x12_SRGB_BLOCK), 144u);
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM), 1u);
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_D32_SFLOAT), 1u);
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_D32_SFLOAT_S8_UINT), 1u);
EXPECT_EQ(vkuFormatTexelsPerBlock(VK_FORMAT_S8_UINT), 1u);
}
TEST(format_utils, vkuFormatTexelBlockSize) {
EXPECT_EQ(vkuFormatTexelBlockSize(VK_FORMAT_R64G64_SFLOAT), 16u);
EXPECT_EQ(vkuFormatTexelBlockSize(VK_FORMAT_ASTC_5x4_SRGB_BLOCK), 16u);