1 /*
2 * Copyright © 2016 Intel Corporation
3 * Copyright © 2019 Google LLC
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "vk_format.h"
26
27 #include "vk_enum_defines.h"
28 #include "vk_enum_to_str.h"
29 #include "vk_util.h"
30
31 /* Note that for packed formats, VK_FORMAT_ lists channels from high to low
32 * bits occupied by the channel, while MESA_FORMAT_* and PIPE_FORMAT_* are
33 * low-to-high.
34 *
35 * Also, missing entries are zero-filled, which happens to be
36 * PIPE_FORMAT_NONE.
37 */
38 const enum pipe_format vk_format_map[] = {
39 /* Missing R4G4 */
40 [VK_FORMAT_R4G4B4A4_UNORM_PACK16] = PIPE_FORMAT_A4B4G4R4_UNORM,
41 [VK_FORMAT_B4G4R4A4_UNORM_PACK16] = PIPE_FORMAT_A4R4G4B4_UNORM,
42 [VK_FORMAT_R5G6B5_UNORM_PACK16] = PIPE_FORMAT_B5G6R5_UNORM,
43 [VK_FORMAT_B5G6R5_UNORM_PACK16] = PIPE_FORMAT_R5G6B5_UNORM,
44 [VK_FORMAT_R5G5B5A1_UNORM_PACK16] = PIPE_FORMAT_A1B5G5R5_UNORM,
45 [VK_FORMAT_B5G5R5A1_UNORM_PACK16] = PIPE_FORMAT_A1R5G5B5_UNORM,
46 [VK_FORMAT_A1R5G5B5_UNORM_PACK16] = PIPE_FORMAT_B5G5R5A1_UNORM,
47
48 [VK_FORMAT_R8_UNORM] = PIPE_FORMAT_R8_UNORM,
49 [VK_FORMAT_R8_SNORM] = PIPE_FORMAT_R8_SNORM,
50 [VK_FORMAT_R8_USCALED] = PIPE_FORMAT_R8_USCALED,
51 [VK_FORMAT_R8_SSCALED] = PIPE_FORMAT_R8_SSCALED,
52 [VK_FORMAT_R8_UINT] = PIPE_FORMAT_R8_UINT,
53 [VK_FORMAT_R8_SINT] = PIPE_FORMAT_R8_SINT,
54 [VK_FORMAT_R8_SRGB] = PIPE_FORMAT_R8_SRGB,
55
56 [VK_FORMAT_R8G8_UNORM] = PIPE_FORMAT_R8G8_UNORM,
57 [VK_FORMAT_R8G8_SNORM] = PIPE_FORMAT_R8G8_SNORM,
58 [VK_FORMAT_R8G8_USCALED] = PIPE_FORMAT_R8G8_USCALED,
59 [VK_FORMAT_R8G8_SSCALED] = PIPE_FORMAT_R8G8_SSCALED,
60 [VK_FORMAT_R8G8_UINT] = PIPE_FORMAT_R8G8_UINT,
61 [VK_FORMAT_R8G8_SINT] = PIPE_FORMAT_R8G8_SINT,
62 [VK_FORMAT_R8G8_SRGB] = PIPE_FORMAT_R8G8_SRGB,
63
64 [VK_FORMAT_R8G8B8_UNORM] = PIPE_FORMAT_R8G8B8_UNORM,
65 [VK_FORMAT_R8G8B8_SNORM] = PIPE_FORMAT_R8G8B8_SNORM,
66 [VK_FORMAT_R8G8B8_USCALED] = PIPE_FORMAT_R8G8B8_USCALED,
67 [VK_FORMAT_R8G8B8_SSCALED] = PIPE_FORMAT_R8G8B8_SSCALED,
68 [VK_FORMAT_R8G8B8_UINT] = PIPE_FORMAT_R8G8B8_UINT,
69 [VK_FORMAT_R8G8B8_SINT] = PIPE_FORMAT_R8G8B8_SINT,
70 [VK_FORMAT_R8G8B8_SRGB] = PIPE_FORMAT_R8G8B8_SRGB,
71
72 [VK_FORMAT_B8G8R8_UNORM] = PIPE_FORMAT_B8G8R8_UNORM,
73 [VK_FORMAT_B8G8R8_SNORM] = PIPE_FORMAT_B8G8R8_SNORM,
74 [VK_FORMAT_B8G8R8_USCALED] = PIPE_FORMAT_B8G8R8_USCALED,
75 [VK_FORMAT_B8G8R8_SSCALED] = PIPE_FORMAT_B8G8R8_SSCALED,
76 [VK_FORMAT_B8G8R8_UINT] = PIPE_FORMAT_B8G8R8_UINT,
77 [VK_FORMAT_B8G8R8_SINT] = PIPE_FORMAT_B8G8R8_SINT,
78 [VK_FORMAT_B8G8R8_SRGB] = PIPE_FORMAT_B8G8R8_SRGB,
79
80 [VK_FORMAT_R8G8B8A8_UNORM] = PIPE_FORMAT_R8G8B8A8_UNORM,
81 [VK_FORMAT_R8G8B8A8_SNORM] = PIPE_FORMAT_R8G8B8A8_SNORM,
82 [VK_FORMAT_R8G8B8A8_USCALED] = PIPE_FORMAT_R8G8B8A8_USCALED,
83 [VK_FORMAT_R8G8B8A8_SSCALED] = PIPE_FORMAT_R8G8B8A8_SSCALED,
84 [VK_FORMAT_R8G8B8A8_UINT] = PIPE_FORMAT_R8G8B8A8_UINT,
85 [VK_FORMAT_R8G8B8A8_SINT] = PIPE_FORMAT_R8G8B8A8_SINT,
86 [VK_FORMAT_R8G8B8A8_SRGB] = PIPE_FORMAT_R8G8B8A8_SRGB,
87
88 [VK_FORMAT_B8G8R8A8_UNORM] = PIPE_FORMAT_B8G8R8A8_UNORM,
89 [VK_FORMAT_B8G8R8A8_SNORM] = PIPE_FORMAT_B8G8R8A8_SNORM,
90 [VK_FORMAT_B8G8R8A8_USCALED] = PIPE_FORMAT_B8G8R8A8_USCALED,
91 [VK_FORMAT_B8G8R8A8_SSCALED] = PIPE_FORMAT_B8G8R8A8_SSCALED,
92 [VK_FORMAT_B8G8R8A8_UINT] = PIPE_FORMAT_B8G8R8A8_UINT,
93 [VK_FORMAT_B8G8R8A8_SINT] = PIPE_FORMAT_B8G8R8A8_SINT,
94 [VK_FORMAT_B8G8R8A8_SRGB] = PIPE_FORMAT_B8G8R8A8_SRGB,
95
96 [VK_FORMAT_A8B8G8R8_UNORM_PACK32] = PIPE_FORMAT_RGBA8888_UNORM,
97 [VK_FORMAT_A8B8G8R8_SNORM_PACK32] = PIPE_FORMAT_RGBA8888_SNORM,
98 [VK_FORMAT_A8B8G8R8_USCALED_PACK32] = PIPE_FORMAT_RGBA8888_USCALED,
99 [VK_FORMAT_A8B8G8R8_SSCALED_PACK32] = PIPE_FORMAT_RGBA8888_SSCALED,
100 [VK_FORMAT_A8B8G8R8_UINT_PACK32] = PIPE_FORMAT_RGBA8888_UINT,
101 [VK_FORMAT_A8B8G8R8_SINT_PACK32] = PIPE_FORMAT_RGBA8888_SINT,
102 [VK_FORMAT_A8B8G8R8_SRGB_PACK32] = PIPE_FORMAT_RGBA8888_SRGB,
103
104 [VK_FORMAT_A2R10G10B10_UNORM_PACK32] = PIPE_FORMAT_B10G10R10A2_UNORM,
105 [VK_FORMAT_A2R10G10B10_SNORM_PACK32] = PIPE_FORMAT_B10G10R10A2_SNORM,
106 [VK_FORMAT_A2R10G10B10_USCALED_PACK32] = PIPE_FORMAT_B10G10R10A2_USCALED,
107 [VK_FORMAT_A2R10G10B10_SSCALED_PACK32] = PIPE_FORMAT_B10G10R10A2_SSCALED,
108 [VK_FORMAT_A2R10G10B10_UINT_PACK32] = PIPE_FORMAT_B10G10R10A2_UINT,
109 [VK_FORMAT_A2R10G10B10_SINT_PACK32] = PIPE_FORMAT_B10G10R10A2_SINT,
110
111 [VK_FORMAT_A2B10G10R10_UNORM_PACK32] = PIPE_FORMAT_R10G10B10A2_UNORM,
112 [VK_FORMAT_A2B10G10R10_SNORM_PACK32] = PIPE_FORMAT_R10G10B10A2_SNORM,
113 [VK_FORMAT_A2B10G10R10_USCALED_PACK32] = PIPE_FORMAT_R10G10B10A2_USCALED,
114 [VK_FORMAT_A2B10G10R10_SSCALED_PACK32] = PIPE_FORMAT_R10G10B10A2_SSCALED,
115 [VK_FORMAT_A2B10G10R10_UINT_PACK32] = PIPE_FORMAT_R10G10B10A2_UINT,
116 [VK_FORMAT_A2B10G10R10_SINT_PACK32] = PIPE_FORMAT_R10G10B10A2_SINT,
117
118 [VK_FORMAT_R16_UNORM] = PIPE_FORMAT_R16_UNORM,
119 [VK_FORMAT_R16_SNORM] = PIPE_FORMAT_R16_SNORM,
120 [VK_FORMAT_R16_USCALED] = PIPE_FORMAT_R16_USCALED,
121 [VK_FORMAT_R16_SSCALED] = PIPE_FORMAT_R16_SSCALED,
122 [VK_FORMAT_R16_UINT] = PIPE_FORMAT_R16_UINT,
123 [VK_FORMAT_R16_SINT] = PIPE_FORMAT_R16_SINT,
124 [VK_FORMAT_R16_SFLOAT] = PIPE_FORMAT_R16_FLOAT,
125
126 [VK_FORMAT_R16G16_UNORM] = PIPE_FORMAT_R16G16_UNORM,
127 [VK_FORMAT_R16G16_SNORM] = PIPE_FORMAT_R16G16_SNORM,
128 [VK_FORMAT_R16G16_USCALED] = PIPE_FORMAT_R16G16_USCALED,
129 [VK_FORMAT_R16G16_SSCALED] = PIPE_FORMAT_R16G16_SSCALED,
130 [VK_FORMAT_R16G16_UINT] = PIPE_FORMAT_R16G16_UINT,
131 [VK_FORMAT_R16G16_SINT] = PIPE_FORMAT_R16G16_SINT,
132 [VK_FORMAT_R16G16_SFLOAT] = PIPE_FORMAT_R16G16_FLOAT,
133
134 [VK_FORMAT_R16G16B16_UNORM] = PIPE_FORMAT_R16G16B16_UNORM,
135 [VK_FORMAT_R16G16B16_SNORM] = PIPE_FORMAT_R16G16B16_SNORM,
136 [VK_FORMAT_R16G16B16_USCALED] = PIPE_FORMAT_R16G16B16_USCALED,
137 [VK_FORMAT_R16G16B16_SSCALED] = PIPE_FORMAT_R16G16B16_SSCALED,
138 [VK_FORMAT_R16G16B16_UINT] = PIPE_FORMAT_R16G16B16_UINT,
139 [VK_FORMAT_R16G16B16_SINT] = PIPE_FORMAT_R16G16B16_SINT,
140 [VK_FORMAT_R16G16B16_SFLOAT] = PIPE_FORMAT_R16G16B16_FLOAT,
141
142 [VK_FORMAT_R16G16B16A16_UNORM] = PIPE_FORMAT_R16G16B16A16_UNORM,
143 [VK_FORMAT_R16G16B16A16_SNORM] = PIPE_FORMAT_R16G16B16A16_SNORM,
144 [VK_FORMAT_R16G16B16A16_USCALED] = PIPE_FORMAT_R16G16B16A16_USCALED,
145 [VK_FORMAT_R16G16B16A16_SSCALED] = PIPE_FORMAT_R16G16B16A16_SSCALED,
146 [VK_FORMAT_R16G16B16A16_UINT] = PIPE_FORMAT_R16G16B16A16_UINT,
147 [VK_FORMAT_R16G16B16A16_SINT] = PIPE_FORMAT_R16G16B16A16_SINT,
148 [VK_FORMAT_R16G16B16A16_SFLOAT] = PIPE_FORMAT_R16G16B16A16_FLOAT,
149
150 [VK_FORMAT_R32_UINT] = PIPE_FORMAT_R32_UINT,
151 [VK_FORMAT_R32_SINT] = PIPE_FORMAT_R32_SINT,
152 [VK_FORMAT_R32_SFLOAT] = PIPE_FORMAT_R32_FLOAT,
153
154 [VK_FORMAT_R32G32_UINT] = PIPE_FORMAT_R32G32_UINT,
155 [VK_FORMAT_R32G32_SINT] = PIPE_FORMAT_R32G32_SINT,
156 [VK_FORMAT_R32G32_SFLOAT] = PIPE_FORMAT_R32G32_FLOAT,
157
158 [VK_FORMAT_R32G32B32_UINT] = PIPE_FORMAT_R32G32B32_UINT,
159 [VK_FORMAT_R32G32B32_SINT] = PIPE_FORMAT_R32G32B32_SINT,
160 [VK_FORMAT_R32G32B32_SFLOAT] = PIPE_FORMAT_R32G32B32_FLOAT,
161
162 [VK_FORMAT_R32G32B32A32_UINT] = PIPE_FORMAT_R32G32B32A32_UINT,
163 [VK_FORMAT_R32G32B32A32_SINT] = PIPE_FORMAT_R32G32B32A32_SINT,
164 [VK_FORMAT_R32G32B32A32_SFLOAT] = PIPE_FORMAT_R32G32B32A32_FLOAT,
165
166 [VK_FORMAT_R64_UINT] = PIPE_FORMAT_R64_UINT,
167 [VK_FORMAT_R64_SINT] = PIPE_FORMAT_R64_SINT,
168 [VK_FORMAT_R64_SFLOAT] = PIPE_FORMAT_R64_FLOAT,
169
170 [VK_FORMAT_R64G64_UINT] = PIPE_FORMAT_R64G64_UINT,
171 [VK_FORMAT_R64G64_SINT] = PIPE_FORMAT_R64G64_SINT,
172 [VK_FORMAT_R64G64_SFLOAT] = PIPE_FORMAT_R64G64_FLOAT,
173
174 [VK_FORMAT_R64G64B64_UINT] = PIPE_FORMAT_R64G64B64_UINT,
175 [VK_FORMAT_R64G64B64_SINT] = PIPE_FORMAT_R64G64B64_SINT,
176 [VK_FORMAT_R64G64B64_SFLOAT] = PIPE_FORMAT_R64G64B64_FLOAT,
177
178 [VK_FORMAT_R64G64B64A64_UINT] = PIPE_FORMAT_R64G64B64A64_UINT,
179 [VK_FORMAT_R64G64B64A64_SINT] = PIPE_FORMAT_R64G64B64A64_SINT,
180 [VK_FORMAT_R64G64B64A64_SFLOAT] = PIPE_FORMAT_R64G64B64A64_FLOAT,
181
182 [VK_FORMAT_B10G11R11_UFLOAT_PACK32] = PIPE_FORMAT_R11G11B10_FLOAT,
183 [VK_FORMAT_E5B9G9R9_UFLOAT_PACK32] = PIPE_FORMAT_R9G9B9E5_FLOAT,
184
185 [VK_FORMAT_D16_UNORM] = PIPE_FORMAT_Z16_UNORM,
186 [VK_FORMAT_X8_D24_UNORM_PACK32] = PIPE_FORMAT_Z24X8_UNORM,
187 [VK_FORMAT_D32_SFLOAT] = PIPE_FORMAT_Z32_FLOAT,
188 [VK_FORMAT_S8_UINT] = PIPE_FORMAT_S8_UINT,
189 [VK_FORMAT_D16_UNORM_S8_UINT] = PIPE_FORMAT_Z16_UNORM_S8_UINT,
190 [VK_FORMAT_D24_UNORM_S8_UINT] = PIPE_FORMAT_Z24_UNORM_S8_UINT,
191 [VK_FORMAT_D32_SFLOAT_S8_UINT] = PIPE_FORMAT_Z32_FLOAT_S8X24_UINT,
192
193 [VK_FORMAT_BC1_RGB_UNORM_BLOCK] = PIPE_FORMAT_DXT1_RGB,
194 [VK_FORMAT_BC1_RGB_SRGB_BLOCK] = PIPE_FORMAT_DXT1_SRGB,
195 [VK_FORMAT_BC1_RGBA_UNORM_BLOCK] = PIPE_FORMAT_DXT1_RGBA,
196 [VK_FORMAT_BC1_RGBA_SRGB_BLOCK] = PIPE_FORMAT_DXT1_SRGBA,
197 [VK_FORMAT_BC2_UNORM_BLOCK] = PIPE_FORMAT_DXT3_RGBA,
198 [VK_FORMAT_BC2_SRGB_BLOCK] = PIPE_FORMAT_DXT3_SRGBA,
199 [VK_FORMAT_BC3_UNORM_BLOCK] = PIPE_FORMAT_DXT5_RGBA,
200 [VK_FORMAT_BC3_SRGB_BLOCK] = PIPE_FORMAT_DXT5_SRGBA,
201 [VK_FORMAT_BC4_UNORM_BLOCK] = PIPE_FORMAT_RGTC1_UNORM,
202 [VK_FORMAT_BC4_SNORM_BLOCK] = PIPE_FORMAT_RGTC1_SNORM,
203 [VK_FORMAT_BC5_UNORM_BLOCK] = PIPE_FORMAT_RGTC2_UNORM,
204 [VK_FORMAT_BC5_SNORM_BLOCK] = PIPE_FORMAT_RGTC2_SNORM,
205 [VK_FORMAT_BC6H_UFLOAT_BLOCK] = PIPE_FORMAT_BPTC_RGB_UFLOAT,
206 [VK_FORMAT_BC6H_SFLOAT_BLOCK] = PIPE_FORMAT_BPTC_RGB_FLOAT,
207 [VK_FORMAT_BC7_UNORM_BLOCK] = PIPE_FORMAT_BPTC_RGBA_UNORM,
208 [VK_FORMAT_BC7_SRGB_BLOCK] = PIPE_FORMAT_BPTC_SRGBA,
209
210 [VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK] = PIPE_FORMAT_ETC2_RGB8,
211 [VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK] = PIPE_FORMAT_ETC2_SRGB8,
212 [VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK] = PIPE_FORMAT_ETC2_RGB8A1,
213 [VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK] = PIPE_FORMAT_ETC2_SRGB8A1,
214 [VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK] = PIPE_FORMAT_ETC2_RGBA8,
215 [VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK] = PIPE_FORMAT_ETC2_SRGBA8,
216 [VK_FORMAT_EAC_R11_UNORM_BLOCK] = PIPE_FORMAT_ETC2_R11_UNORM,
217 [VK_FORMAT_EAC_R11_SNORM_BLOCK] = PIPE_FORMAT_ETC2_R11_SNORM,
218 [VK_FORMAT_EAC_R11G11_UNORM_BLOCK] = PIPE_FORMAT_ETC2_RG11_UNORM,
219 [VK_FORMAT_EAC_R11G11_SNORM_BLOCK] = PIPE_FORMAT_ETC2_RG11_SNORM,
220
221 [VK_FORMAT_ASTC_4x4_UNORM_BLOCK] = PIPE_FORMAT_ASTC_4x4,
222 [VK_FORMAT_ASTC_4x4_SRGB_BLOCK] = PIPE_FORMAT_ASTC_4x4_SRGB,
223 [VK_FORMAT_ASTC_5x4_UNORM_BLOCK] = PIPE_FORMAT_ASTC_5x4,
224 [VK_FORMAT_ASTC_5x4_SRGB_BLOCK] = PIPE_FORMAT_ASTC_5x4_SRGB,
225 [VK_FORMAT_ASTC_5x5_UNORM_BLOCK] = PIPE_FORMAT_ASTC_5x5,
226 [VK_FORMAT_ASTC_5x5_SRGB_BLOCK] = PIPE_FORMAT_ASTC_5x5_SRGB,
227 [VK_FORMAT_ASTC_6x5_UNORM_BLOCK] = PIPE_FORMAT_ASTC_6x5,
228 [VK_FORMAT_ASTC_6x5_SRGB_BLOCK] = PIPE_FORMAT_ASTC_6x5_SRGB,
229 [VK_FORMAT_ASTC_6x6_UNORM_BLOCK] = PIPE_FORMAT_ASTC_6x6,
230 [VK_FORMAT_ASTC_6x6_SRGB_BLOCK] = PIPE_FORMAT_ASTC_6x6_SRGB,
231 [VK_FORMAT_ASTC_8x5_UNORM_BLOCK] = PIPE_FORMAT_ASTC_8x5,
232 [VK_FORMAT_ASTC_8x5_SRGB_BLOCK] = PIPE_FORMAT_ASTC_8x5_SRGB,
233 [VK_FORMAT_ASTC_8x6_UNORM_BLOCK] = PIPE_FORMAT_ASTC_8x6,
234 [VK_FORMAT_ASTC_8x6_SRGB_BLOCK] = PIPE_FORMAT_ASTC_8x6_SRGB,
235 [VK_FORMAT_ASTC_8x8_UNORM_BLOCK] = PIPE_FORMAT_ASTC_8x8,
236 [VK_FORMAT_ASTC_8x8_SRGB_BLOCK] = PIPE_FORMAT_ASTC_8x8_SRGB,
237 [VK_FORMAT_ASTC_10x5_UNORM_BLOCK] = PIPE_FORMAT_ASTC_10x5,
238 [VK_FORMAT_ASTC_10x5_SRGB_BLOCK] = PIPE_FORMAT_ASTC_10x5_SRGB,
239 [VK_FORMAT_ASTC_10x6_UNORM_BLOCK] = PIPE_FORMAT_ASTC_10x6,
240 [VK_FORMAT_ASTC_10x6_SRGB_BLOCK] = PIPE_FORMAT_ASTC_10x6_SRGB,
241 [VK_FORMAT_ASTC_10x8_UNORM_BLOCK] = PIPE_FORMAT_ASTC_10x8,
242 [VK_FORMAT_ASTC_10x8_SRGB_BLOCK] = PIPE_FORMAT_ASTC_10x8_SRGB,
243 [VK_FORMAT_ASTC_10x10_UNORM_BLOCK] = PIPE_FORMAT_ASTC_10x10,
244 [VK_FORMAT_ASTC_10x10_SRGB_BLOCK] = PIPE_FORMAT_ASTC_10x10_SRGB,
245 [VK_FORMAT_ASTC_12x10_UNORM_BLOCK] = PIPE_FORMAT_ASTC_12x10,
246 [VK_FORMAT_ASTC_12x10_SRGB_BLOCK] = PIPE_FORMAT_ASTC_12x10_SRGB,
247 [VK_FORMAT_ASTC_12x12_UNORM_BLOCK] = PIPE_FORMAT_ASTC_12x12,
248 [VK_FORMAT_ASTC_12x12_SRGB_BLOCK] = PIPE_FORMAT_ASTC_12x12_SRGB,
249
250 /* Missing planes */
251
252 /* Missing PVRTC */
253
254 /* Missing ASTC SFLOAT */
255
256 /* Missing more planes */
257 };
258
259 enum pipe_format
vk_format_to_pipe_format(enum VkFormat vkformat)260 vk_format_to_pipe_format(enum VkFormat vkformat)
261 {
262 if (vkformat >= ARRAY_SIZE(vk_format_map)) {
263 switch (vkformat) {
264 case VK_FORMAT_R10X6_UNORM_PACK16:
265 return PIPE_FORMAT_R16_UNORM;
266 case VK_FORMAT_R10X6G10X6_UNORM_2PACK16:
267 return PIPE_FORMAT_R16G16_UNORM;
268 case VK_FORMAT_G8B8G8R8_422_UNORM:
269 return PIPE_FORMAT_G8B8_G8R8_UNORM;
270 case VK_FORMAT_B8G8R8G8_422_UNORM:
271 return PIPE_FORMAT_B8G8_R8G8_UNORM;
272 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
273 return PIPE_FORMAT_IYUV;
274 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
275 return PIPE_FORMAT_NV12;
276 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
277 return PIPE_FORMAT_Y8_U8_V8_422_UNORM;
278 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
279 return PIPE_FORMAT_Y8_U8V8_422_UNORM;
280 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
281 return PIPE_FORMAT_Y8_U8_V8_444_UNORM;
282 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
283 return PIPE_FORMAT_Y16_U16_V16_420_UNORM;
284 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
285 return PIPE_FORMAT_P016;
286 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
287 return PIPE_FORMAT_Y16_U16_V16_422_UNORM;
288 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
289 return PIPE_FORMAT_Y16_U16V16_422_UNORM;
290 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
291 return PIPE_FORMAT_Y16_U16_V16_444_UNORM;
292 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
293 return PIPE_FORMAT_P010;
294 case VK_FORMAT_A4R4G4B4_UNORM_PACK16:
295 return PIPE_FORMAT_B4G4R4A4_UNORM;
296 case VK_FORMAT_A4B4G4R4_UNORM_PACK16:
297 return PIPE_FORMAT_R4G4B4A4_UNORM;
298 case VK_FORMAT_A8_UNORM_KHR:
299 return PIPE_FORMAT_A8_UNORM;
300 case VK_FORMAT_A1B5G5R5_UNORM_PACK16_KHR:
301 return PIPE_FORMAT_R5G5B5A1_UNORM;
302 default:
303 return PIPE_FORMAT_NONE;
304 }
305 }
306
307 /* Unpopulated entries in the table must be PIPE_FORMAT_NONE */
308 STATIC_ASSERT(PIPE_FORMAT_NONE == 0);
309
310 return vk_format_map[vkformat];
311 }
312
313 VkImageAspectFlags
vk_format_aspects(VkFormat format)314 vk_format_aspects(VkFormat format)
315 {
316 switch (format) {
317 case VK_FORMAT_UNDEFINED:
318 return 0;
319
320 case VK_FORMAT_S8_UINT:
321 return VK_IMAGE_ASPECT_STENCIL_BIT;
322
323 case VK_FORMAT_D16_UNORM_S8_UINT:
324 case VK_FORMAT_D24_UNORM_S8_UINT:
325 case VK_FORMAT_D32_SFLOAT_S8_UINT:
326 return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
327
328 case VK_FORMAT_D16_UNORM:
329 case VK_FORMAT_X8_D24_UNORM_PACK32:
330 case VK_FORMAT_D32_SFLOAT:
331 return VK_IMAGE_ASPECT_DEPTH_BIT;
332
333 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
334 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
335 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
336 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16:
337 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16:
338 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16:
339 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16:
340 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16:
341 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16:
342 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
343 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
344 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
345 return (VK_IMAGE_ASPECT_PLANE_0_BIT |
346 VK_IMAGE_ASPECT_PLANE_1_BIT |
347 VK_IMAGE_ASPECT_PLANE_2_BIT);
348
349 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
350 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
351 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
352 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16:
353 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16:
354 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16:
355 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
356 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
357 case VK_FORMAT_G8_B8R8_2PLANE_444_UNORM_EXT:
358 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_444_UNORM_3PACK16_EXT:
359 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_444_UNORM_3PACK16_EXT:
360 case VK_FORMAT_G16_B16R16_2PLANE_444_UNORM_EXT:
361 return (VK_IMAGE_ASPECT_PLANE_0_BIT |
362 VK_IMAGE_ASPECT_PLANE_1_BIT);
363
364 default:
365 return VK_IMAGE_ASPECT_COLOR_BIT;
366 }
367 }
368
369 VkFormat
vk_format_get_plane_format(VkFormat format,unsigned plane_id)370 vk_format_get_plane_format(VkFormat format, unsigned plane_id)
371 {
372 assert(plane_id < vk_format_get_plane_count(format));
373 const struct vk_format_ycbcr_info *ycbcr_info =
374 vk_format_get_ycbcr_info(format);
375 if (ycbcr_info && ycbcr_info->n_planes > 1) {
376 const struct vk_format_ycbcr_plane *plane_info = &ycbcr_info->planes[plane_id];
377 return plane_info->format;
378 } else {
379 assert(vk_format_get_plane_count(format) == 1);
380 return format;
381 }
382 }
383
384 VkFormat
vk_format_get_aspect_format(VkFormat format,const VkImageAspectFlags aspect)385 vk_format_get_aspect_format(VkFormat format, const VkImageAspectFlags aspect)
386 {
387 assert(util_bitcount(aspect) == 1);
388 assert(aspect & vk_format_aspects(format));
389
390 switch (aspect) {
391 case VK_IMAGE_ASPECT_COLOR_BIT:
392 return format;
393 case VK_IMAGE_ASPECT_DEPTH_BIT:
394 return vk_format_depth_only(format);
395 case VK_IMAGE_ASPECT_STENCIL_BIT:
396 return vk_format_stencil_only(format);
397 case VK_IMAGE_ASPECT_PLANE_0_BIT:
398 return vk_format_get_plane_format(format, 0);
399 case VK_IMAGE_ASPECT_PLANE_1_BIT:
400 return vk_format_get_plane_format(format, 1);
401 case VK_IMAGE_ASPECT_PLANE_2_BIT:
402 return vk_format_get_plane_format(format, 2);
403 default:
404 unreachable("Cannot translate format aspect");
405 }
406 }
407
408 void
vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,unsigned char out_swizzle[4])409 vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,
410 unsigned char out_swizzle[4])
411 {
412 VkComponentSwizzle swizzle[4] = { mapping.r, mapping.g, mapping.b, mapping.a };
413 for (unsigned i = 0; i < 4; i++) {
414 switch (swizzle[i]) {
415 case VK_COMPONENT_SWIZZLE_R:
416 out_swizzle[i] = PIPE_SWIZZLE_X;
417 break;
418 case VK_COMPONENT_SWIZZLE_G:
419 out_swizzle[i] = PIPE_SWIZZLE_Y;
420 break;
421 case VK_COMPONENT_SWIZZLE_B:
422 out_swizzle[i] = PIPE_SWIZZLE_Z;
423 break;
424 case VK_COMPONENT_SWIZZLE_A:
425 out_swizzle[i] = PIPE_SWIZZLE_W;
426 break;
427 case VK_COMPONENT_SWIZZLE_IDENTITY:
428 out_swizzle[i] = PIPE_SWIZZLE_X + i;
429 break;
430 case VK_COMPONENT_SWIZZLE_ZERO:
431 out_swizzle[i] = PIPE_SWIZZLE_0;
432 break;
433 case VK_COMPONENT_SWIZZLE_ONE:
434 out_swizzle[i] = PIPE_SWIZZLE_1;
435 break;
436 default:
437 unreachable("unknown swizzle");
438 }
439 }
440 }
441
442 #define fmt_unsupported(__vk_fmt) \
443 [VK_ENUM_OFFSET(__vk_fmt)] = { \
444 .n_planes = 0, \
445 }
446
447 #define y_plane(__plane_fmt, __ycbcr_swizzle, dhs, dvs) \
448 { .format = __plane_fmt, \
449 .has_chroma = false, \
450 .denominator_scales = { dhs, dvs, }, \
451 .ycbcr_swizzle = __ycbcr_swizzle, \
452 }
453
454 #define c_plane(__plane_fmt, __ycbcr_swizzle, dhs, dvs) \
455 { .format = __plane_fmt, \
456 .has_chroma = true, \
457 .denominator_scales = { dhs, dvs, }, \
458 .ycbcr_swizzle = __ycbcr_swizzle, \
459 }
460
461 #define ycbcr_fmt(__vk_fmt, __n_planes, ...) \
462 [VK_ENUM_OFFSET(__vk_fmt)] = { \
463 .n_planes = __n_planes, \
464 .planes = { \
465 __VA_ARGS__, \
466 }, \
467 }
468
469 #define YCBCR_SWIZ(x, y, z, w) { \
470 VK_COMPONENT_SWIZZLE_##x, \
471 VK_COMPONENT_SWIZZLE_##y, \
472 VK_COMPONENT_SWIZZLE_##z, \
473 VK_COMPONENT_SWIZZLE_##w, \
474 }
475
476 static const struct vk_format_ycbcr_info ycbcr_infos[] = {
477 ycbcr_fmt(VK_FORMAT_G8B8G8R8_422_UNORM, 1,
478 y_plane(VK_FORMAT_G8B8G8R8_422_UNORM, YCBCR_SWIZ(R, G, B, ZERO), 1, 1)),
479 ycbcr_fmt(VK_FORMAT_B8G8R8G8_422_UNORM, 1,
480 y_plane(VK_FORMAT_B8G8R8G8_422_UNORM, YCBCR_SWIZ(R, G, B, ZERO), 1, 1)),
481 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, 3,
482 y_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
483 c_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 2),
484 c_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 2, 2)),
485 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, 2,
486 y_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
487 c_plane(VK_FORMAT_R8G8_UNORM, YCBCR_SWIZ(B, R, ZERO, ZERO), 2, 2)),
488 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM, 3,
489 y_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
490 c_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 1),
491 c_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 2, 1)),
492 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_422_UNORM, 2,
493 y_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
494 c_plane(VK_FORMAT_R8G8_UNORM, YCBCR_SWIZ(B, R, ZERO, ZERO), 2, 1)),
495 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM, 3,
496 y_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
497 c_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 1, 1),
498 c_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 1, 1)),
499
500 fmt_unsupported(VK_FORMAT_R10X6_UNORM_PACK16),
501 fmt_unsupported(VK_FORMAT_R10X6G10X6_UNORM_2PACK16),
502 fmt_unsupported(VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16),
503
504 ycbcr_fmt(VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16, 1,
505 y_plane(VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16, YCBCR_SWIZ(B, G, R, ZERO), 1, 1)),
506 ycbcr_fmt(VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16, 1,
507 y_plane(VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16, YCBCR_SWIZ(B, G, R, ZERO), 1, 1)),
508
509 ycbcr_fmt(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16, 3,
510 y_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
511 c_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 2),
512 c_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 2, 2)),
513 ycbcr_fmt(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16, 2,
514 y_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
515 c_plane(VK_FORMAT_R10X6G10X6_UNORM_2PACK16, YCBCR_SWIZ(B, R, ZERO, ZERO), 2, 2)),
516 ycbcr_fmt(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16, 3,
517 y_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
518 c_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 1),
519 c_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 2, 1)),
520 ycbcr_fmt(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16, 2,
521 y_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
522 c_plane(VK_FORMAT_R10X6G10X6_UNORM_2PACK16, YCBCR_SWIZ(B, R, ZERO, ZERO), 2, 1)),
523 ycbcr_fmt(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16, 3,
524 y_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
525 c_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 1, 1),
526 c_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 1, 1)),
527
528 fmt_unsupported(VK_FORMAT_R12X4_UNORM_PACK16),
529 fmt_unsupported(VK_FORMAT_R12X4G12X4_UNORM_2PACK16),
530 fmt_unsupported(VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16),
531
532 ycbcr_fmt(VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16, 1,
533 y_plane(VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16, YCBCR_SWIZ(B, G, R, ZERO), 1, 1)),
534 ycbcr_fmt(VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16, 1,
535 y_plane(VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16, YCBCR_SWIZ(B, G, R, ZERO), 1, 1)),
536
537 ycbcr_fmt(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16, 3,
538 y_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
539 c_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 2),
540 c_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 2, 2)),
541 ycbcr_fmt(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16, 2,
542 y_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
543 c_plane(VK_FORMAT_R12X4G12X4_UNORM_2PACK16, YCBCR_SWIZ(B, R, ZERO, ZERO), 2, 2)),
544 ycbcr_fmt(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16, 3,
545 y_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
546 c_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 1),
547 c_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 2, 1)),
548 ycbcr_fmt(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16, 2,
549 y_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
550 c_plane(VK_FORMAT_R12X4G12X4_UNORM_2PACK16, YCBCR_SWIZ(B, R, ZERO, ZERO), 2, 1)),
551 ycbcr_fmt(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16, 3,
552 y_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
553 c_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 1, 1),
554 c_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 1, 1)),
555
556 ycbcr_fmt(VK_FORMAT_G16B16G16R16_422_UNORM, 1,
557 y_plane(VK_FORMAT_G16B16G16R16_422_UNORM, YCBCR_SWIZ(B, G, R, ZERO), 1, 1)),
558 ycbcr_fmt(VK_FORMAT_B16G16R16G16_422_UNORM, 1,
559 y_plane(VK_FORMAT_B16G16R16G16_422_UNORM, YCBCR_SWIZ(B, G, R, ZERO), 1, 1)),
560
561 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM, 3,
562 y_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
563 c_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 2),
564 c_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 2, 2)),
565 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_420_UNORM, 2,
566 y_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
567 c_plane(VK_FORMAT_R16G16_UNORM, YCBCR_SWIZ(B, R, ZERO, ZERO), 2, 2)),
568 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM, 3,
569 y_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
570 c_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 1),
571 c_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 2, 1)),
572 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_422_UNORM, 2,
573 y_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
574 c_plane(VK_FORMAT_R16G16_UNORM, YCBCR_SWIZ(B, R, ZERO, ZERO), 2, 1)),
575 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM, 3,
576 y_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
577 c_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 1, 1),
578 c_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(R, ZERO, ZERO, ZERO), 1, 1)),
579 };
580
581 static const struct vk_format_ycbcr_info ycbcr_2plane_444_infos[] = {
582 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_444_UNORM_EXT, 2,
583 y_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
584 c_plane(VK_FORMAT_R8G8_UNORM, YCBCR_SWIZ(B, R, ZERO, ZERO), 1, 1)),
585
586 ycbcr_fmt(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_444_UNORM_3PACK16_EXT, 2,
587 y_plane(VK_FORMAT_R10X6_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
588 c_plane(VK_FORMAT_R10X6G10X6_UNORM_2PACK16, YCBCR_SWIZ(B, R, ZERO, ZERO), 1, 1)),
589
590 ycbcr_fmt(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_444_UNORM_3PACK16_EXT, 2,
591 y_plane(VK_FORMAT_R12X4_UNORM_PACK16, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
592 c_plane(VK_FORMAT_R12X4G12X4_UNORM_2PACK16, YCBCR_SWIZ(B, R, ZERO, ZERO), 1, 1)),
593
594 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_444_UNORM_EXT, 2,
595 y_plane(VK_FORMAT_R16_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
596 c_plane(VK_FORMAT_R16G16_UNORM, YCBCR_SWIZ(B, R, ZERO, ZERO), 1, 1)),
597 };
598
599 const struct vk_format_ycbcr_info *
vk_format_get_ycbcr_info(VkFormat format)600 vk_format_get_ycbcr_info(VkFormat format)
601 {
602 uint32_t enum_offset = VK_ENUM_OFFSET(format);
603 uint32_t ext_number = VK_ENUM_EXTENSION(format);
604 const struct vk_format_ycbcr_info *info;
605 switch (ext_number) {
606 case _VK_KHR_sampler_ycbcr_conversion_number:
607 if (enum_offset >= ARRAY_SIZE(ycbcr_infos))
608 return NULL;
609 info = &ycbcr_infos[enum_offset];
610 break;
611
612 case _VK_EXT_ycbcr_2plane_444_formats_number:
613 if (enum_offset >= ARRAY_SIZE(ycbcr_2plane_444_infos))
614 return NULL;
615 info = &ycbcr_2plane_444_infos[enum_offset];
616 break;
617
618 default:
619 return NULL;
620 }
621
622 if (info->n_planes == 0)
623 return NULL;
624
625 return info;
626 }
627
628 static uint32_t
swizzled_color_component(const VkClearColorValue * color,VkComponentSwizzle swizzle,uint32_t comp,bool is_int)629 swizzled_color_component(const VkClearColorValue *color,
630 VkComponentSwizzle swizzle,
631 uint32_t comp, bool is_int)
632 {
633 switch (swizzle) {
634 case VK_COMPONENT_SWIZZLE_IDENTITY: return color->uint32[comp];
635 case VK_COMPONENT_SWIZZLE_ZERO: return 0;
636 case VK_COMPONENT_SWIZZLE_ONE: return is_int ? 1 : 0x3f800000;
637 case VK_COMPONENT_SWIZZLE_R: return color->uint32[0];
638 case VK_COMPONENT_SWIZZLE_G: return color->uint32[1];
639 case VK_COMPONENT_SWIZZLE_B: return color->uint32[2];
640 case VK_COMPONENT_SWIZZLE_A: return color->uint32[3];
641 default: unreachable("Invalid component swizzle");
642 }
643 }
644
645 VkClearColorValue
vk_swizzle_color_value(VkClearColorValue color,VkComponentMapping swizzle,bool is_int)646 vk_swizzle_color_value(VkClearColorValue color,
647 VkComponentMapping swizzle, bool is_int)
648 {
649 return (VkClearColorValue) { .uint32 = {
650 swizzled_color_component(&color, swizzle.r, 0, is_int),
651 swizzled_color_component(&color, swizzle.g, 1, is_int),
652 swizzled_color_component(&color, swizzle.b, 2, is_int),
653 swizzled_color_component(&color, swizzle.a, 3, is_int),
654 }};
655 }
656