[Mesa-dev] [PATCH 3/5] anv: add util functions to query max bpc & integer formats

Lionel Landwerlin llandwerlin at gmail.com
Mon Oct 17 15:46:57 UTC 2016


Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/intel/vulkan/vk_format_info.h | 300 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 300 insertions(+)

diff --git a/src/intel/vulkan/vk_format_info.h b/src/intel/vulkan/vk_format_info.h
index 5c5a1f3..0c1d865 100644
--- a/src/intel/vulkan/vk_format_info.h
+++ b/src/intel/vulkan/vk_format_info.h
@@ -53,6 +53,306 @@ vk_format_aspects(VkFormat format)
 }
 
 static inline bool
+vk_format_is_integer(VkFormat format)
+{
+   switch (format) {
+   case VK_FORMAT_R8_UINT:
+   case VK_FORMAT_R8_SINT:
+   case VK_FORMAT_R8G8_UINT:
+   case VK_FORMAT_R8G8_SINT:
+   case VK_FORMAT_R8G8B8_UINT:
+   case VK_FORMAT_R8G8B8_SINT:
+   case VK_FORMAT_B8G8R8_UINT:
+   case VK_FORMAT_B8G8R8_SINT:
+   case VK_FORMAT_R8G8B8A8_UINT:
+   case VK_FORMAT_R8G8B8A8_SINT:
+   case VK_FORMAT_B8G8R8A8_UINT:
+   case VK_FORMAT_B8G8R8A8_SINT:
+   case VK_FORMAT_A8B8G8R8_UINT_PACK32:
+   case VK_FORMAT_A8B8G8R8_SINT_PACK32:
+   case VK_FORMAT_A2R10G10B10_UINT_PACK32:
+   case VK_FORMAT_A2R10G10B10_SINT_PACK32:
+   case VK_FORMAT_A2B10G10R10_UINT_PACK32:
+   case VK_FORMAT_A2B10G10R10_SINT_PACK32:
+   case VK_FORMAT_R16_UINT:
+   case VK_FORMAT_R16_SINT:
+   case VK_FORMAT_R16G16_UINT:
+   case VK_FORMAT_R16G16_SINT:
+   case VK_FORMAT_R16G16B16_UINT:
+   case VK_FORMAT_R16G16B16_SINT:
+   case VK_FORMAT_R16G16B16A16_UINT:
+   case VK_FORMAT_R16G16B16A16_SINT:
+   case VK_FORMAT_R32_UINT:
+   case VK_FORMAT_R32_SINT:
+   case VK_FORMAT_R32G32_UINT:
+   case VK_FORMAT_R32G32_SINT:
+   case VK_FORMAT_R32G32B32_UINT:
+   case VK_FORMAT_R32G32B32_SINT:
+   case VK_FORMAT_R32G32B32A32_UINT:
+   case VK_FORMAT_R32G32B32A32_SINT:
+   case VK_FORMAT_R64_UINT:
+   case VK_FORMAT_R64_SINT:
+   case VK_FORMAT_R64G64_UINT:
+   case VK_FORMAT_R64G64_SINT:
+   case VK_FORMAT_R64G64B64_UINT:
+   case VK_FORMAT_R64G64B64_SINT:
+   case VK_FORMAT_R64G64B64A64_UINT:
+   case VK_FORMAT_R64G64B64A64_SINT:
+   case VK_FORMAT_S8_UINT:
+   case VK_FORMAT_D16_UNORM_S8_UINT:
+   case VK_FORMAT_D24_UNORM_S8_UINT:
+   case VK_FORMAT_D32_SFLOAT_S8_UINT:
+      return true;
+
+   default:
+      return false;
+   }
+}
+
+static inline uint32_t
+vk_format_max_bpc(VkFormat format)
+{
+   switch (format) {
+   case VK_FORMAT_R4G4_UNORM_PACK8:
+   case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
+   case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
+      return 4;
+
+   case VK_FORMAT_R5G6B5_UNORM_PACK16:
+   case VK_FORMAT_B5G6R5_UNORM_PACK16:
+      return 6;
+
+   case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
+   case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
+   case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
+      return 5;
+
+   case VK_FORMAT_R8_UNORM:
+   case VK_FORMAT_R8_SNORM:
+   case VK_FORMAT_R8_USCALED:
+   case VK_FORMAT_R8_SSCALED:
+   case VK_FORMAT_R8_UINT:
+   case VK_FORMAT_R8_SINT:
+   case VK_FORMAT_R8_SRGB:
+   case VK_FORMAT_R8G8_UNORM:
+   case VK_FORMAT_R8G8_SNORM:
+   case VK_FORMAT_R8G8_USCALED:
+   case VK_FORMAT_R8G8_SSCALED:
+   case VK_FORMAT_R8G8_UINT:
+   case VK_FORMAT_R8G8_SINT:
+   case VK_FORMAT_R8G8_SRGB:
+   case VK_FORMAT_R8G8B8_UNORM:
+   case VK_FORMAT_R8G8B8_SNORM:
+   case VK_FORMAT_R8G8B8_USCALED:
+   case VK_FORMAT_R8G8B8_SSCALED:
+   case VK_FORMAT_R8G8B8_UINT:
+   case VK_FORMAT_R8G8B8_SINT:
+   case VK_FORMAT_R8G8B8_SRGB:
+   case VK_FORMAT_B8G8R8_UNORM:
+   case VK_FORMAT_B8G8R8_SNORM:
+   case VK_FORMAT_B8G8R8_USCALED:
+   case VK_FORMAT_B8G8R8_SSCALED:
+   case VK_FORMAT_B8G8R8_UINT:
+   case VK_FORMAT_B8G8R8_SINT:
+   case VK_FORMAT_B8G8R8_SRGB:
+   case VK_FORMAT_R8G8B8A8_UNORM:
+   case VK_FORMAT_R8G8B8A8_SNORM:
+   case VK_FORMAT_R8G8B8A8_USCALED:
+   case VK_FORMAT_R8G8B8A8_SSCALED:
+   case VK_FORMAT_R8G8B8A8_UINT:
+   case VK_FORMAT_R8G8B8A8_SINT:
+   case VK_FORMAT_R8G8B8A8_SRGB:
+   case VK_FORMAT_B8G8R8A8_UNORM:
+   case VK_FORMAT_B8G8R8A8_SNORM:
+   case VK_FORMAT_B8G8R8A8_USCALED:
+   case VK_FORMAT_B8G8R8A8_SSCALED:
+   case VK_FORMAT_B8G8R8A8_UINT:
+   case VK_FORMAT_B8G8R8A8_SINT:
+   case VK_FORMAT_B8G8R8A8_SRGB:
+   case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
+   case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
+   case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
+   case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
+   case VK_FORMAT_A8B8G8R8_UINT_PACK32:
+   case VK_FORMAT_A8B8G8R8_SINT_PACK32:
+   case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
+      return 8;
+
+   case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
+   case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
+   case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
+   case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
+   case VK_FORMAT_A2R10G10B10_UINT_PACK32:
+   case VK_FORMAT_A2R10G10B10_SINT_PACK32:
+   case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
+   case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
+   case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
+   case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
+   case VK_FORMAT_A2B10G10R10_UINT_PACK32:
+   case VK_FORMAT_A2B10G10R10_SINT_PACK32:
+      return 10;
+
+   case VK_FORMAT_R16_UNORM:
+   case VK_FORMAT_R16_SNORM:
+   case VK_FORMAT_R16_USCALED:
+   case VK_FORMAT_R16_SSCALED:
+   case VK_FORMAT_R16_UINT:
+   case VK_FORMAT_R16_SINT:
+   case VK_FORMAT_R16_SFLOAT:
+   case VK_FORMAT_R16G16_UNORM:
+   case VK_FORMAT_R16G16_SNORM:
+   case VK_FORMAT_R16G16_USCALED:
+   case VK_FORMAT_R16G16_SSCALED:
+   case VK_FORMAT_R16G16_UINT:
+   case VK_FORMAT_R16G16_SINT:
+   case VK_FORMAT_R16G16_SFLOAT:
+   case VK_FORMAT_R16G16B16_UNORM:
+   case VK_FORMAT_R16G16B16_SNORM:
+   case VK_FORMAT_R16G16B16_USCALED:
+   case VK_FORMAT_R16G16B16_SSCALED:
+   case VK_FORMAT_R16G16B16_UINT:
+   case VK_FORMAT_R16G16B16_SINT:
+   case VK_FORMAT_R16G16B16_SFLOAT:
+   case VK_FORMAT_R16G16B16A16_UNORM:
+   case VK_FORMAT_R16G16B16A16_SNORM:
+   case VK_FORMAT_R16G16B16A16_USCALED:
+   case VK_FORMAT_R16G16B16A16_SSCALED:
+   case VK_FORMAT_R16G16B16A16_UINT:
+   case VK_FORMAT_R16G16B16A16_SINT:
+   case VK_FORMAT_R16G16B16A16_SFLOAT:
+      return 16;
+
+   case VK_FORMAT_R32_UINT:
+   case VK_FORMAT_R32_SINT:
+   case VK_FORMAT_R32_SFLOAT:
+   case VK_FORMAT_R32G32_UINT:
+   case VK_FORMAT_R32G32_SINT:
+   case VK_FORMAT_R32G32_SFLOAT:
+   case VK_FORMAT_R32G32B32_UINT:
+   case VK_FORMAT_R32G32B32_SINT:
+   case VK_FORMAT_R32G32B32_SFLOAT:
+   case VK_FORMAT_R32G32B32A32_UINT:
+   case VK_FORMAT_R32G32B32A32_SINT:
+   case VK_FORMAT_R32G32B32A32_SFLOAT:
+      return 32;
+
+   case VK_FORMAT_R64_UINT:
+   case VK_FORMAT_R64_SINT:
+   case VK_FORMAT_R64_SFLOAT:
+   case VK_FORMAT_R64G64_UINT:
+   case VK_FORMAT_R64G64_SINT:
+   case VK_FORMAT_R64G64_SFLOAT:
+   case VK_FORMAT_R64G64B64_UINT:
+   case VK_FORMAT_R64G64B64_SINT:
+   case VK_FORMAT_R64G64B64_SFLOAT:
+   case VK_FORMAT_R64G64B64A64_UINT:
+   case VK_FORMAT_R64G64B64A64_SINT:
+   case VK_FORMAT_R64G64B64A64_SFLOAT:
+      return 64;
+
+   case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
+      return 11;
+
+   case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
+      return 9;
+
+   case VK_FORMAT_D16_UNORM:
+      return 16;
+
+   case VK_FORMAT_X8_D24_UNORM_PACK32:
+      return 24;
+
+   case VK_FORMAT_D32_SFLOAT:
+      return 32;
+
+   case VK_FORMAT_S8_UINT:
+      return 8;
+
+   case VK_FORMAT_D16_UNORM_S8_UINT:
+      return 16;
+
+   case VK_FORMAT_D24_UNORM_S8_UINT:
+      return 24;
+
+   case VK_FORMAT_D32_SFLOAT_S8_UINT:
+      return 32;
+
+   case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
+   case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
+   case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
+   case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
+   case VK_FORMAT_BC2_UNORM_BLOCK:
+   case VK_FORMAT_BC2_SRGB_BLOCK:
+      return 6;
+
+   case VK_FORMAT_BC3_UNORM_BLOCK:
+   case VK_FORMAT_BC3_SRGB_BLOCK:
+      return 8;
+
+   case VK_FORMAT_BC4_UNORM_BLOCK:
+   case VK_FORMAT_BC4_SNORM_BLOCK:
+   case VK_FORMAT_BC5_UNORM_BLOCK:
+   case VK_FORMAT_BC5_SNORM_BLOCK:
+      return 8;
+
+   case VK_FORMAT_BC6H_UFLOAT_BLOCK:
+   case VK_FORMAT_BC6H_SFLOAT_BLOCK:
+      return 16;
+
+   case VK_FORMAT_BC7_UNORM_BLOCK:
+   case VK_FORMAT_BC7_SRGB_BLOCK:
+      return 8;
+
+   case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
+   case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
+   case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
+   case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
+   case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
+   case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
+      return 8;
+
+   case VK_FORMAT_EAC_R11_UNORM_BLOCK:
+   case VK_FORMAT_EAC_R11_SNORM_BLOCK:
+   case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
+   case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
+      return 11;
+
+   case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
+   case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
+   case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
+      return 8;
+
+   default:
+      unreachable("invalid format");
+   }
+}
+
+static inline bool
 vk_format_is_color(VkFormat format)
 {
    return vk_format_aspects(format) == VK_IMAGE_ASPECT_COLOR_BIT;
-- 
2.9.3



More information about the mesa-dev mailing list