diff options
author | Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com> | 2023-09-18 10:43:24 +0530 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2023-10-11 19:28:40 +0000 |
commit | bcc0e1e2af54a90363c5ee12448d614d12a77998 (patch) | |
tree | dabc85ea9edc2c452cd2058b1741bff3e78f1b86 /src/vulkan | |
parent | 8da85d2475da5e883c88f6cc744594a3031c25c3 (diff) | |
download | mesa-bcc0e1e2af54a90363c5ee12448d614d12a77998.tar.gz mesa-bcc0e1e2af54a90363c5ee12448d614d12a77998.tar.bz2 mesa-bcc0e1e2af54a90363c5ee12448d614d12a77998.zip |
vulkan/formats,zink: move vk_format_from_pipe_format() function
rename zink_pipe_format_to_vk_format() to vk_format_from_pipe_format()
and put it in common code.
v2: reorder vk_format.h (Chia-I Wu)
rename to vk_format_from_pipe_format (Chia-I Wu)
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24672>
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/util/vk_format.c | 194 | ||||
-rw-r--r-- | src/vulkan/util/vk_format.h | 3 |
2 files changed, 197 insertions, 0 deletions
diff --git a/src/vulkan/util/vk_format.c b/src/vulkan/util/vk_format.c index 5f18658309d..8e2a08c1baf 100644 --- a/src/vulkan/util/vk_format.c +++ b/src/vulkan/util/vk_format.c @@ -310,6 +310,200 @@ vk_format_to_pipe_format(enum VkFormat vkformat) return vk_format_map[vkformat]; } +static const VkFormat formats[PIPE_FORMAT_COUNT] = { +#define MAP_FORMAT_NORM(FMT) \ + [PIPE_FORMAT_ ## FMT ## _UNORM] = VK_FORMAT_ ## FMT ## _UNORM, \ + [PIPE_FORMAT_ ## FMT ## _SNORM] = VK_FORMAT_ ## FMT ## _SNORM, + +#define MAP_FORMAT_SCALED(FMT) \ + [PIPE_FORMAT_ ## FMT ## _USCALED] = VK_FORMAT_ ## FMT ## _USCALED, \ + [PIPE_FORMAT_ ## FMT ## _SSCALED] = VK_FORMAT_ ## FMT ## _SSCALED, + +#define MAP_FORMAT_INT(FMT) \ + [PIPE_FORMAT_ ## FMT ## _UINT] = VK_FORMAT_ ## FMT ## _UINT, \ + [PIPE_FORMAT_ ## FMT ## _SINT] = VK_FORMAT_ ## FMT ## _SINT, + +#define MAP_FORMAT_SRGB(FMT) \ + [PIPE_FORMAT_ ## FMT ## _SRGB] = VK_FORMAT_ ## FMT ## _SRGB, + +#define MAP_FORMAT_FLOAT(FMT) \ + [PIPE_FORMAT_ ## FMT ## _FLOAT] = VK_FORMAT_ ## FMT ## _SFLOAT, + + // one component + + // 8-bits + MAP_FORMAT_NORM(R8) + MAP_FORMAT_SCALED(R8) + MAP_FORMAT_INT(R8) + MAP_FORMAT_SRGB(R8) + // 16-bits + MAP_FORMAT_NORM(R16) + MAP_FORMAT_SCALED(R16) + MAP_FORMAT_INT(R16) + MAP_FORMAT_FLOAT(R16) + // 32-bits + MAP_FORMAT_INT(R32) + MAP_FORMAT_FLOAT(R32) + + // two components + + // 8-bits + MAP_FORMAT_NORM(R8G8) + MAP_FORMAT_SCALED(R8G8) + MAP_FORMAT_INT(R8G8) + MAP_FORMAT_SRGB(R8G8) + // 16-bits + MAP_FORMAT_NORM(R16G16) + MAP_FORMAT_SCALED(R16G16) + MAP_FORMAT_INT(R16G16) + MAP_FORMAT_FLOAT(R16G16) + // 32-bits + MAP_FORMAT_INT(R32G32) + MAP_FORMAT_FLOAT(R32G32) + + // three components + + // 8-bits + MAP_FORMAT_NORM(R8G8B8) + MAP_FORMAT_SCALED(R8G8B8) + MAP_FORMAT_INT(R8G8B8) + MAP_FORMAT_SRGB(R8G8B8) + MAP_FORMAT_NORM(B8G8R8) + MAP_FORMAT_SCALED(B8G8R8) + MAP_FORMAT_INT(B8G8R8) + MAP_FORMAT_SRGB(B8G8R8) + // 16-bits + MAP_FORMAT_NORM(R16G16B16) + MAP_FORMAT_SCALED(R16G16B16) + MAP_FORMAT_INT(R16G16B16) + MAP_FORMAT_FLOAT(R16G16B16) + // 32-bits + MAP_FORMAT_INT(R32G32B32) + MAP_FORMAT_FLOAT(R32G32B32) + + // four components + + // 8-bits + MAP_FORMAT_NORM(R8G8B8A8) + MAP_FORMAT_SCALED(R8G8B8A8) + MAP_FORMAT_INT(R8G8B8A8) + MAP_FORMAT_NORM(B8G8R8A8) + MAP_FORMAT_SCALED(B8G8R8A8) + MAP_FORMAT_INT(B8G8R8A8) + MAP_FORMAT_SRGB(B8G8R8A8) + [PIPE_FORMAT_RGBA8888_SRGB] = VK_FORMAT_A8B8G8R8_SRGB_PACK32, + // 16-bits + MAP_FORMAT_NORM(R16G16B16A16) + MAP_FORMAT_SCALED(R16G16B16A16) + MAP_FORMAT_INT(R16G16B16A16) + MAP_FORMAT_FLOAT(R16G16B16A16) + // 32-bits + MAP_FORMAT_INT(R32G32B32A32) + MAP_FORMAT_FLOAT(R32G32B32A32) + + // other color formats + [PIPE_FORMAT_A4B4G4R4_UNORM] = VK_FORMAT_R4G4B4A4_UNORM_PACK16, + [PIPE_FORMAT_A4R4G4B4_UNORM] = VK_FORMAT_B4G4R4A4_UNORM_PACK16, + [PIPE_FORMAT_B4G4R4A4_UNORM] = VK_FORMAT_A4R4G4B4_UNORM_PACK16, + [PIPE_FORMAT_R4G4B4A4_UNORM] = VK_FORMAT_A4B4G4R4_UNORM_PACK16, + [PIPE_FORMAT_B5G6R5_UNORM] = VK_FORMAT_R5G6B5_UNORM_PACK16, + [PIPE_FORMAT_R5G6B5_UNORM] = VK_FORMAT_B5G6R5_UNORM_PACK16, + + [PIPE_FORMAT_A1B5G5R5_UNORM] = VK_FORMAT_R5G5B5A1_UNORM_PACK16, + [PIPE_FORMAT_A1R5G5B5_UNORM] = VK_FORMAT_B5G5R5A1_UNORM_PACK16, + [PIPE_FORMAT_B5G5R5A1_UNORM] = VK_FORMAT_A1R5G5B5_UNORM_PACK16, + + [PIPE_FORMAT_R11G11B10_FLOAT] = VK_FORMAT_B10G11R11_UFLOAT_PACK32, + [PIPE_FORMAT_R9G9B9E5_FLOAT] = VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, + /* ARB_vertex_type_2_10_10_10 */ + [PIPE_FORMAT_R10G10B10A2_UNORM] = VK_FORMAT_A2B10G10R10_UNORM_PACK32, + [PIPE_FORMAT_R10G10B10A2_SNORM] = VK_FORMAT_A2B10G10R10_SNORM_PACK32, + [PIPE_FORMAT_B10G10R10A2_UNORM] = VK_FORMAT_A2R10G10B10_UNORM_PACK32, + [PIPE_FORMAT_B10G10R10A2_SNORM] = VK_FORMAT_A2R10G10B10_SNORM_PACK32, + [PIPE_FORMAT_R10G10B10A2_USCALED] = VK_FORMAT_A2B10G10R10_USCALED_PACK32, + [PIPE_FORMAT_R10G10B10A2_SSCALED] = VK_FORMAT_A2B10G10R10_SSCALED_PACK32, + [PIPE_FORMAT_B10G10R10A2_USCALED] = VK_FORMAT_A2R10G10B10_USCALED_PACK32, + [PIPE_FORMAT_B10G10R10A2_SSCALED] = VK_FORMAT_A2R10G10B10_SSCALED_PACK32, + [PIPE_FORMAT_R10G10B10A2_UINT] = VK_FORMAT_A2B10G10R10_UINT_PACK32, + [PIPE_FORMAT_B10G10R10A2_UINT] = VK_FORMAT_A2R10G10B10_UINT_PACK32, + [PIPE_FORMAT_B10G10R10A2_SINT] = VK_FORMAT_A2R10G10B10_SINT_PACK32, + + // depth/stencil formats + [PIPE_FORMAT_Z32_FLOAT] = VK_FORMAT_D32_SFLOAT, + [PIPE_FORMAT_Z32_FLOAT_S8X24_UINT] = VK_FORMAT_D32_SFLOAT_S8_UINT, + [PIPE_FORMAT_Z16_UNORM] = VK_FORMAT_D16_UNORM, + [PIPE_FORMAT_Z16_UNORM_S8_UINT] = VK_FORMAT_D16_UNORM_S8_UINT, + [PIPE_FORMAT_Z24X8_UNORM] = VK_FORMAT_X8_D24_UNORM_PACK32, + [PIPE_FORMAT_Z24_UNORM_S8_UINT] = VK_FORMAT_D24_UNORM_S8_UINT, + [PIPE_FORMAT_S8_UINT] = VK_FORMAT_S8_UINT, + + // compressed formats + [PIPE_FORMAT_DXT1_RGB] = VK_FORMAT_BC1_RGB_UNORM_BLOCK, + [PIPE_FORMAT_DXT1_RGBA] = VK_FORMAT_BC1_RGBA_UNORM_BLOCK, + [PIPE_FORMAT_DXT3_RGBA] = VK_FORMAT_BC2_UNORM_BLOCK, + [PIPE_FORMAT_DXT5_RGBA] = VK_FORMAT_BC3_UNORM_BLOCK, + [PIPE_FORMAT_DXT1_SRGB] = VK_FORMAT_BC1_RGB_SRGB_BLOCK, + [PIPE_FORMAT_DXT1_SRGBA] = VK_FORMAT_BC1_RGBA_SRGB_BLOCK, + [PIPE_FORMAT_DXT3_SRGBA] = VK_FORMAT_BC2_SRGB_BLOCK, + [PIPE_FORMAT_DXT5_SRGBA] = VK_FORMAT_BC3_SRGB_BLOCK, + + [PIPE_FORMAT_RGTC1_UNORM] = VK_FORMAT_BC4_UNORM_BLOCK, + [PIPE_FORMAT_RGTC1_SNORM] = VK_FORMAT_BC4_SNORM_BLOCK, + [PIPE_FORMAT_RGTC2_UNORM] = VK_FORMAT_BC5_UNORM_BLOCK, + [PIPE_FORMAT_RGTC2_SNORM] = VK_FORMAT_BC5_SNORM_BLOCK, + [PIPE_FORMAT_BPTC_RGBA_UNORM] = VK_FORMAT_BC7_UNORM_BLOCK, + [PIPE_FORMAT_BPTC_SRGBA] = VK_FORMAT_BC7_SRGB_BLOCK, + [PIPE_FORMAT_BPTC_RGB_FLOAT] = VK_FORMAT_BC6H_SFLOAT_BLOCK, + [PIPE_FORMAT_BPTC_RGB_UFLOAT] = VK_FORMAT_BC6H_UFLOAT_BLOCK, + + [PIPE_FORMAT_ETC1_RGB8] = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, + [PIPE_FORMAT_ETC2_RGB8] = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, + [PIPE_FORMAT_ETC2_SRGB8] = VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, + [PIPE_FORMAT_ETC2_RGB8A1] = VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, + [PIPE_FORMAT_ETC2_SRGB8A1] = VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, + [PIPE_FORMAT_ETC2_RGBA8] = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, + [PIPE_FORMAT_ETC2_SRGBA8] = VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, + [PIPE_FORMAT_ETC2_R11_UNORM] = VK_FORMAT_EAC_R11_UNORM_BLOCK, + [PIPE_FORMAT_ETC2_R11_SNORM] = VK_FORMAT_EAC_R11_SNORM_BLOCK, + [PIPE_FORMAT_ETC2_RG11_UNORM] = VK_FORMAT_EAC_R11G11_UNORM_BLOCK, + [PIPE_FORMAT_ETC2_RG11_SNORM] = VK_FORMAT_EAC_R11G11_SNORM_BLOCK, + + [PIPE_FORMAT_ASTC_4x4] = VK_FORMAT_ASTC_4x4_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_4x4_SRGB] = VK_FORMAT_ASTC_4x4_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_5x4] = VK_FORMAT_ASTC_5x4_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_5x4_SRGB] = VK_FORMAT_ASTC_5x4_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_5x5] = VK_FORMAT_ASTC_5x5_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_5x5_SRGB] = VK_FORMAT_ASTC_5x5_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_6x5] = VK_FORMAT_ASTC_6x5_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_6x5_SRGB] = VK_FORMAT_ASTC_6x5_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_6x6] = VK_FORMAT_ASTC_6x6_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_6x6_SRGB] = VK_FORMAT_ASTC_6x6_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_8x5] = VK_FORMAT_ASTC_8x5_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_8x5_SRGB] = VK_FORMAT_ASTC_8x5_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_8x6] = VK_FORMAT_ASTC_8x6_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_8x6_SRGB] = VK_FORMAT_ASTC_8x6_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_8x8] = VK_FORMAT_ASTC_8x8_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_8x8_SRGB] = VK_FORMAT_ASTC_8x8_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_10x5] = VK_FORMAT_ASTC_10x5_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_10x5_SRGB] = VK_FORMAT_ASTC_10x5_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_10x6] = VK_FORMAT_ASTC_10x6_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_10x6_SRGB] = VK_FORMAT_ASTC_10x6_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_10x8] = VK_FORMAT_ASTC_10x8_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_10x8_SRGB] = VK_FORMAT_ASTC_10x8_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_10x10] = VK_FORMAT_ASTC_10x10_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_10x10_SRGB] = VK_FORMAT_ASTC_10x10_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_12x10] = VK_FORMAT_ASTC_12x10_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_12x10_SRGB] = VK_FORMAT_ASTC_12x10_SRGB_BLOCK, + [PIPE_FORMAT_ASTC_12x12] = VK_FORMAT_ASTC_12x12_UNORM_BLOCK, + [PIPE_FORMAT_ASTC_12x12_SRGB] = VK_FORMAT_ASTC_12x12_SRGB_BLOCK, +}; + +VkFormat +vk_format_from_pipe_format(enum pipe_format format) +{ + return formats[format]; +} + VkImageAspectFlags vk_format_aspects(VkFormat format) { diff --git a/src/vulkan/util/vk_format.h b/src/vulkan/util/vk_format.h index 03297bc3601..d133f8ce798 100644 --- a/src/vulkan/util/vk_format.h +++ b/src/vulkan/util/vk_format.h @@ -38,6 +38,9 @@ extern const enum pipe_format vk_format_map[]; enum pipe_format vk_format_to_pipe_format(enum VkFormat vkformat); +VkFormat +vk_format_from_pipe_format(enum pipe_format format); + VkImageAspectFlags vk_format_aspects(VkFormat format); |