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 /* Note that for packed formats, VK_FORMAT_ lists channels from high to low
28 * bits occupied by the channel, while MESA_FORMAT_* and PIPE_FORMAT_* are
29 * low-to-high.
30 *
31 * Also, missing entries are zero-filled, which happens to be
32 * PIPE_FORMAT_NONE.
33 */
34 static const enum pipe_format vk_format_map[] = {
35 /* Missing R4G4 */
36 [VK_FORMAT_R4G4B4A4_UNORM_PACK16] = PIPE_FORMAT_A4B4G4R4_UNORM,
37 [VK_FORMAT_B4G4R4A4_UNORM_PACK16] = PIPE_FORMAT_A4R4G4B4_UNORM,
38 [VK_FORMAT_R5G6B5_UNORM_PACK16] = PIPE_FORMAT_B5G6R5_UNORM,
39 [VK_FORMAT_B5G6R5_UNORM_PACK16] = PIPE_FORMAT_R5G6B5_UNORM,
40 [VK_FORMAT_R5G5B5A1_UNORM_PACK16] = PIPE_FORMAT_A1B5G5R5_UNORM,
41 [VK_FORMAT_B5G5R5A1_UNORM_PACK16] = PIPE_FORMAT_A1R5G5B5_UNORM,
42 [VK_FORMAT_A1R5G5B5_UNORM_PACK16] = PIPE_FORMAT_B5G5R5A1_UNORM,
43
44 [VK_FORMAT_R8_UNORM] = PIPE_FORMAT_R8_UNORM,
45 [VK_FORMAT_R8_SNORM] = PIPE_FORMAT_R8_SNORM,
46 [VK_FORMAT_R8_USCALED] = PIPE_FORMAT_R8_USCALED,
47 [VK_FORMAT_R8_SSCALED] = PIPE_FORMAT_R8_SSCALED,
48 [VK_FORMAT_R8_UINT] = PIPE_FORMAT_R8_UINT,
49 [VK_FORMAT_R8_SINT] = PIPE_FORMAT_R8_SINT,
50 [VK_FORMAT_R8_SRGB] = PIPE_FORMAT_R8_SRGB,
51
52 [VK_FORMAT_R8G8_UNORM] = PIPE_FORMAT_R8G8_UNORM,
53 [VK_FORMAT_R8G8_SNORM] = PIPE_FORMAT_R8G8_SNORM,
54 [VK_FORMAT_R8G8_USCALED] = PIPE_FORMAT_R8G8_USCALED,
55 [VK_FORMAT_R8G8_SSCALED] = PIPE_FORMAT_R8G8_SSCALED,
56 [VK_FORMAT_R8G8_UINT] = PIPE_FORMAT_R8G8_UINT,
57 [VK_FORMAT_R8G8_SINT] = PIPE_FORMAT_R8G8_SINT,
58 [VK_FORMAT_R8G8_SRGB] = PIPE_FORMAT_R8G8_SRGB,
59
60 [VK_FORMAT_R8G8B8_UNORM] = PIPE_FORMAT_R8G8B8_UNORM,
61 [VK_FORMAT_R8G8B8_SNORM] = PIPE_FORMAT_R8G8B8_SNORM,
62 [VK_FORMAT_R8G8B8_USCALED] = PIPE_FORMAT_R8G8B8_USCALED,
63 [VK_FORMAT_R8G8B8_SSCALED] = PIPE_FORMAT_R8G8B8_SSCALED,
64 [VK_FORMAT_R8G8B8_UINT] = PIPE_FORMAT_R8G8B8_UINT,
65 [VK_FORMAT_R8G8B8_SINT] = PIPE_FORMAT_R8G8B8_SINT,
66 [VK_FORMAT_R8G8B8_SRGB] = PIPE_FORMAT_R8G8B8_SRGB,
67
68 [VK_FORMAT_B8G8R8_UNORM] = PIPE_FORMAT_B8G8R8_UNORM,
69 [VK_FORMAT_B8G8R8_SNORM] = PIPE_FORMAT_B8G8R8_SNORM,
70 [VK_FORMAT_B8G8R8_USCALED] = PIPE_FORMAT_B8G8R8_USCALED,
71 [VK_FORMAT_B8G8R8_SSCALED] = PIPE_FORMAT_B8G8R8_SSCALED,
72 [VK_FORMAT_B8G8R8_UINT] = PIPE_FORMAT_B8G8R8_UINT,
73 [VK_FORMAT_B8G8R8_SINT] = PIPE_FORMAT_B8G8R8_SINT,
74 [VK_FORMAT_B8G8R8_SRGB] = PIPE_FORMAT_B8G8R8_SRGB,
75
76 [VK_FORMAT_R8G8B8A8_UNORM] = PIPE_FORMAT_R8G8B8A8_UNORM,
77 [VK_FORMAT_R8G8B8A8_SNORM] = PIPE_FORMAT_R8G8B8A8_SNORM,
78 [VK_FORMAT_R8G8B8A8_USCALED] = PIPE_FORMAT_R8G8B8A8_USCALED,
79 [VK_FORMAT_R8G8B8A8_SSCALED] = PIPE_FORMAT_R8G8B8A8_SSCALED,
80 [VK_FORMAT_R8G8B8A8_UINT] = PIPE_FORMAT_R8G8B8A8_UINT,
81 [VK_FORMAT_R8G8B8A8_SINT] = PIPE_FORMAT_R8G8B8A8_SINT,
82 [VK_FORMAT_R8G8B8A8_SRGB] = PIPE_FORMAT_R8G8B8A8_SRGB,
83
84 [VK_FORMAT_B8G8R8A8_UNORM] = PIPE_FORMAT_B8G8R8A8_UNORM,
85 [VK_FORMAT_B8G8R8A8_SNORM] = PIPE_FORMAT_B8G8R8A8_SNORM,
86 [VK_FORMAT_B8G8R8A8_USCALED] = PIPE_FORMAT_B8G8R8A8_USCALED,
87 [VK_FORMAT_B8G8R8A8_SSCALED] = PIPE_FORMAT_B8G8R8A8_SSCALED,
88 [VK_FORMAT_B8G8R8A8_UINT] = PIPE_FORMAT_B8G8R8A8_UINT,
89 [VK_FORMAT_B8G8R8A8_SINT] = PIPE_FORMAT_B8G8R8A8_SINT,
90 [VK_FORMAT_B8G8R8A8_SRGB] = PIPE_FORMAT_B8G8R8A8_SRGB,
91
92 [VK_FORMAT_A8B8G8R8_UNORM_PACK32] = PIPE_FORMAT_RGBA8888_UNORM,
93 [VK_FORMAT_A8B8G8R8_SNORM_PACK32] = PIPE_FORMAT_RGBA8888_SNORM,
94 [VK_FORMAT_A8B8G8R8_USCALED_PACK32] = PIPE_FORMAT_RGBA8888_USCALED,
95 [VK_FORMAT_A8B8G8R8_SSCALED_PACK32] = PIPE_FORMAT_RGBA8888_SSCALED,
96 [VK_FORMAT_A8B8G8R8_UINT_PACK32] = PIPE_FORMAT_RGBA8888_UINT,
97 [VK_FORMAT_A8B8G8R8_SINT_PACK32] = PIPE_FORMAT_RGBA8888_SINT,
98 [VK_FORMAT_A8B8G8R8_SRGB_PACK32] = PIPE_FORMAT_RGBA8888_SRGB,
99
100 [VK_FORMAT_A2R10G10B10_UNORM_PACK32] = PIPE_FORMAT_B10G10R10A2_UNORM,
101 [VK_FORMAT_A2R10G10B10_SNORM_PACK32] = PIPE_FORMAT_B10G10R10A2_SNORM,
102 [VK_FORMAT_A2R10G10B10_USCALED_PACK32] = PIPE_FORMAT_B10G10R10A2_USCALED,
103 [VK_FORMAT_A2R10G10B10_SSCALED_PACK32] = PIPE_FORMAT_B10G10R10A2_SSCALED,
104 [VK_FORMAT_A2R10G10B10_UINT_PACK32] = PIPE_FORMAT_B10G10R10A2_UINT,
105 [VK_FORMAT_A2R10G10B10_SINT_PACK32] = PIPE_FORMAT_B10G10R10A2_SINT,
106
107 [VK_FORMAT_A2B10G10R10_UNORM_PACK32] = PIPE_FORMAT_R10G10B10A2_UNORM,
108 [VK_FORMAT_A2B10G10R10_SNORM_PACK32] = PIPE_FORMAT_R10G10B10A2_SNORM,
109 [VK_FORMAT_A2B10G10R10_USCALED_PACK32] = PIPE_FORMAT_R10G10B10A2_USCALED,
110 [VK_FORMAT_A2B10G10R10_SSCALED_PACK32] = PIPE_FORMAT_R10G10B10A2_SSCALED,
111 [VK_FORMAT_A2B10G10R10_UINT_PACK32] = PIPE_FORMAT_R10G10B10A2_UINT,
112 [VK_FORMAT_A2B10G10R10_SINT_PACK32] = PIPE_FORMAT_R10G10B10A2_SINT,
113
114 [VK_FORMAT_R16_UNORM] = PIPE_FORMAT_R16_UNORM,
115 [VK_FORMAT_R16_SNORM] = PIPE_FORMAT_R16_SNORM,
116 [VK_FORMAT_R16_USCALED] = PIPE_FORMAT_R16_USCALED,
117 [VK_FORMAT_R16_SSCALED] = PIPE_FORMAT_R16_SSCALED,
118 [VK_FORMAT_R16_UINT] = PIPE_FORMAT_R16_UINT,
119 [VK_FORMAT_R16_SINT] = PIPE_FORMAT_R16_SINT,
120 [VK_FORMAT_R16_SFLOAT] = PIPE_FORMAT_R16_FLOAT,
121
122 [VK_FORMAT_R16G16_UNORM] = PIPE_FORMAT_R16G16_UNORM,
123 [VK_FORMAT_R16G16_SNORM] = PIPE_FORMAT_R16G16_SNORM,
124 [VK_FORMAT_R16G16_USCALED] = PIPE_FORMAT_R16G16_USCALED,
125 [VK_FORMAT_R16G16_SSCALED] = PIPE_FORMAT_R16G16_SSCALED,
126 [VK_FORMAT_R16G16_UINT] = PIPE_FORMAT_R16G16_UINT,
127 [VK_FORMAT_R16G16_SINT] = PIPE_FORMAT_R16G16_SINT,
128 [VK_FORMAT_R16G16_SFLOAT] = PIPE_FORMAT_R16G16_FLOAT,
129
130 [VK_FORMAT_R16G16B16_UNORM] = PIPE_FORMAT_R16G16B16_UNORM,
131 [VK_FORMAT_R16G16B16_SNORM] = PIPE_FORMAT_R16G16B16_SNORM,
132 [VK_FORMAT_R16G16B16_USCALED] = PIPE_FORMAT_R16G16B16_USCALED,
133 [VK_FORMAT_R16G16B16_SSCALED] = PIPE_FORMAT_R16G16B16_SSCALED,
134 [VK_FORMAT_R16G16B16_UINT] = PIPE_FORMAT_R16G16B16_UINT,
135 [VK_FORMAT_R16G16B16_SINT] = PIPE_FORMAT_R16G16B16_SINT,
136 [VK_FORMAT_R16G16B16_SFLOAT] = PIPE_FORMAT_R16G16B16_FLOAT,
137
138 [VK_FORMAT_R16G16B16A16_UNORM] = PIPE_FORMAT_R16G16B16A16_UNORM,
139 [VK_FORMAT_R16G16B16A16_SNORM] = PIPE_FORMAT_R16G16B16A16_SNORM,
140 [VK_FORMAT_R16G16B16A16_USCALED] = PIPE_FORMAT_R16G16B16A16_USCALED,
141 [VK_FORMAT_R16G16B16A16_SSCALED] = PIPE_FORMAT_R16G16B16A16_SSCALED,
142 [VK_FORMAT_R16G16B16A16_UINT] = PIPE_FORMAT_R16G16B16A16_UINT,
143 [VK_FORMAT_R16G16B16A16_SINT] = PIPE_FORMAT_R16G16B16A16_SINT,
144 [VK_FORMAT_R16G16B16A16_SFLOAT] = PIPE_FORMAT_R16G16B16A16_FLOAT,
145
146 [VK_FORMAT_R32_UINT] = PIPE_FORMAT_R32_UINT,
147 [VK_FORMAT_R32_SINT] = PIPE_FORMAT_R32_SINT,
148 [VK_FORMAT_R32_SFLOAT] = PIPE_FORMAT_R32_FLOAT,
149
150 [VK_FORMAT_R32G32_UINT] = PIPE_FORMAT_R32G32_UINT,
151 [VK_FORMAT_R32G32_SINT] = PIPE_FORMAT_R32G32_SINT,
152 [VK_FORMAT_R32G32_SFLOAT] = PIPE_FORMAT_R32G32_FLOAT,
153
154 [VK_FORMAT_R32G32B32_UINT] = PIPE_FORMAT_R32G32B32_UINT,
155 [VK_FORMAT_R32G32B32_SINT] = PIPE_FORMAT_R32G32B32_SINT,
156 [VK_FORMAT_R32G32B32_SFLOAT] = PIPE_FORMAT_R32G32B32_FLOAT,
157
158 [VK_FORMAT_R32G32B32A32_UINT] = PIPE_FORMAT_R32G32B32A32_UINT,
159 [VK_FORMAT_R32G32B32A32_SINT] = PIPE_FORMAT_R32G32B32A32_SINT,
160 [VK_FORMAT_R32G32B32A32_SFLOAT] = PIPE_FORMAT_R32G32B32A32_FLOAT,
161
162 [VK_FORMAT_R64_UINT] = PIPE_FORMAT_R64_UINT,
163 [VK_FORMAT_R64_SINT] = PIPE_FORMAT_R64_SINT,
164 /* Missing rest of 64-bit uint/sint formats */
165 [VK_FORMAT_R64_SFLOAT] = PIPE_FORMAT_R64_FLOAT,
166 [VK_FORMAT_R64G64_SFLOAT] = PIPE_FORMAT_R64G64_FLOAT,
167 [VK_FORMAT_R64G64B64_SFLOAT] = PIPE_FORMAT_R64G64B64_FLOAT,
168 [VK_FORMAT_R64G64B64A64_SFLOAT] = PIPE_FORMAT_R64G64B64A64_FLOAT,
169
170 [VK_FORMAT_B10G11R11_UFLOAT_PACK32] = PIPE_FORMAT_R11G11B10_FLOAT,
171 [VK_FORMAT_E5B9G9R9_UFLOAT_PACK32] = PIPE_FORMAT_R9G9B9E5_FLOAT,
172
173 [VK_FORMAT_D16_UNORM] = PIPE_FORMAT_Z16_UNORM,
174 [VK_FORMAT_X8_D24_UNORM_PACK32] = PIPE_FORMAT_Z24X8_UNORM,
175 [VK_FORMAT_D32_SFLOAT] = PIPE_FORMAT_Z32_FLOAT,
176 [VK_FORMAT_S8_UINT] = PIPE_FORMAT_S8_UINT,
177 [VK_FORMAT_D16_UNORM_S8_UINT] = PIPE_FORMAT_Z16_UNORM_S8_UINT,
178 [VK_FORMAT_D24_UNORM_S8_UINT] = PIPE_FORMAT_Z24_UNORM_S8_UINT,
179 [VK_FORMAT_D32_SFLOAT_S8_UINT] = PIPE_FORMAT_Z32_FLOAT_S8X24_UINT,
180
181 [VK_FORMAT_BC1_RGB_UNORM_BLOCK] = PIPE_FORMAT_DXT1_RGB,
182 [VK_FORMAT_BC1_RGB_SRGB_BLOCK] = PIPE_FORMAT_DXT1_SRGB,
183 [VK_FORMAT_BC1_RGBA_UNORM_BLOCK] = PIPE_FORMAT_DXT1_RGBA,
184 [VK_FORMAT_BC1_RGBA_SRGB_BLOCK] = PIPE_FORMAT_DXT1_SRGBA,
185 [VK_FORMAT_BC2_UNORM_BLOCK] = PIPE_FORMAT_DXT3_RGBA,
186 [VK_FORMAT_BC2_SRGB_BLOCK] = PIPE_FORMAT_DXT3_SRGBA,
187 [VK_FORMAT_BC3_UNORM_BLOCK] = PIPE_FORMAT_DXT5_RGBA,
188 [VK_FORMAT_BC3_SRGB_BLOCK] = PIPE_FORMAT_DXT5_SRGBA,
189 [VK_FORMAT_BC4_UNORM_BLOCK] = PIPE_FORMAT_RGTC1_UNORM,
190 [VK_FORMAT_BC4_SNORM_BLOCK] = PIPE_FORMAT_RGTC1_SNORM,
191 [VK_FORMAT_BC5_UNORM_BLOCK] = PIPE_FORMAT_RGTC2_UNORM,
192 [VK_FORMAT_BC5_SNORM_BLOCK] = PIPE_FORMAT_RGTC2_SNORM,
193 [VK_FORMAT_BC6H_UFLOAT_BLOCK] = PIPE_FORMAT_BPTC_RGB_UFLOAT,
194 [VK_FORMAT_BC6H_SFLOAT_BLOCK] = PIPE_FORMAT_BPTC_RGB_FLOAT,
195 [VK_FORMAT_BC7_UNORM_BLOCK] = PIPE_FORMAT_BPTC_RGBA_UNORM,
196 [VK_FORMAT_BC7_SRGB_BLOCK] = PIPE_FORMAT_BPTC_SRGBA,
197
198 [VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK] = PIPE_FORMAT_ETC2_RGB8,
199 [VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK] = PIPE_FORMAT_ETC2_SRGB8,
200 [VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK] = PIPE_FORMAT_ETC2_RGB8A1,
201 [VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK] = PIPE_FORMAT_ETC2_SRGB8A1,
202 [VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK] = PIPE_FORMAT_ETC2_RGBA8,
203 [VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK] = PIPE_FORMAT_ETC2_SRGBA8,
204 [VK_FORMAT_EAC_R11_UNORM_BLOCK] = PIPE_FORMAT_ETC2_R11_UNORM,
205 [VK_FORMAT_EAC_R11_SNORM_BLOCK] = PIPE_FORMAT_ETC2_R11_SNORM,
206 [VK_FORMAT_EAC_R11G11_UNORM_BLOCK] = PIPE_FORMAT_ETC2_RG11_UNORM,
207 [VK_FORMAT_EAC_R11G11_SNORM_BLOCK] = PIPE_FORMAT_ETC2_RG11_SNORM,
208
209 [VK_FORMAT_ASTC_4x4_UNORM_BLOCK] = PIPE_FORMAT_ASTC_4x4,
210 [VK_FORMAT_ASTC_4x4_SRGB_BLOCK] = PIPE_FORMAT_ASTC_4x4_SRGB,
211 [VK_FORMAT_ASTC_5x4_UNORM_BLOCK] = PIPE_FORMAT_ASTC_5x4,
212 [VK_FORMAT_ASTC_5x4_SRGB_BLOCK] = PIPE_FORMAT_ASTC_5x4_SRGB,
213 [VK_FORMAT_ASTC_5x5_UNORM_BLOCK] = PIPE_FORMAT_ASTC_5x5,
214 [VK_FORMAT_ASTC_5x5_SRGB_BLOCK] = PIPE_FORMAT_ASTC_5x5_SRGB,
215 [VK_FORMAT_ASTC_6x5_UNORM_BLOCK] = PIPE_FORMAT_ASTC_6x5,
216 [VK_FORMAT_ASTC_6x5_SRGB_BLOCK] = PIPE_FORMAT_ASTC_6x5_SRGB,
217 [VK_FORMAT_ASTC_6x6_UNORM_BLOCK] = PIPE_FORMAT_ASTC_6x6,
218 [VK_FORMAT_ASTC_6x6_SRGB_BLOCK] = PIPE_FORMAT_ASTC_6x6_SRGB,
219 [VK_FORMAT_ASTC_8x5_UNORM_BLOCK] = PIPE_FORMAT_ASTC_8x5,
220 [VK_FORMAT_ASTC_8x5_SRGB_BLOCK] = PIPE_FORMAT_ASTC_8x5_SRGB,
221 [VK_FORMAT_ASTC_8x6_UNORM_BLOCK] = PIPE_FORMAT_ASTC_8x6,
222 [VK_FORMAT_ASTC_8x6_SRGB_BLOCK] = PIPE_FORMAT_ASTC_8x6_SRGB,
223 [VK_FORMAT_ASTC_8x8_UNORM_BLOCK] = PIPE_FORMAT_ASTC_8x8,
224 [VK_FORMAT_ASTC_8x8_SRGB_BLOCK] = PIPE_FORMAT_ASTC_8x8_SRGB,
225 [VK_FORMAT_ASTC_10x5_UNORM_BLOCK] = PIPE_FORMAT_ASTC_10x5,
226 [VK_FORMAT_ASTC_10x5_SRGB_BLOCK] = PIPE_FORMAT_ASTC_10x5_SRGB,
227 [VK_FORMAT_ASTC_10x6_UNORM_BLOCK] = PIPE_FORMAT_ASTC_10x6,
228 [VK_FORMAT_ASTC_10x6_SRGB_BLOCK] = PIPE_FORMAT_ASTC_10x6_SRGB,
229 [VK_FORMAT_ASTC_10x8_UNORM_BLOCK] = PIPE_FORMAT_ASTC_10x8,
230 [VK_FORMAT_ASTC_10x8_SRGB_BLOCK] = PIPE_FORMAT_ASTC_10x8_SRGB,
231 [VK_FORMAT_ASTC_10x10_UNORM_BLOCK] = PIPE_FORMAT_ASTC_10x10,
232 [VK_FORMAT_ASTC_10x10_SRGB_BLOCK] = PIPE_FORMAT_ASTC_10x10_SRGB,
233 [VK_FORMAT_ASTC_12x10_UNORM_BLOCK] = PIPE_FORMAT_ASTC_12x10,
234 [VK_FORMAT_ASTC_12x10_SRGB_BLOCK] = PIPE_FORMAT_ASTC_12x10_SRGB,
235 [VK_FORMAT_ASTC_12x12_UNORM_BLOCK] = PIPE_FORMAT_ASTC_12x12,
236 [VK_FORMAT_ASTC_12x12_SRGB_BLOCK] = PIPE_FORMAT_ASTC_12x12_SRGB,
237
238 /* Missing planes */
239
240 /* Missing PVRTC */
241
242 /* Missing ASTC SFLOAT */
243
244 /* Missing more planes */
245 };
246
247 enum pipe_format
vk_format_to_pipe_format(enum VkFormat vkformat)248 vk_format_to_pipe_format(enum VkFormat vkformat)
249 {
250 if (vkformat >= ARRAY_SIZE(vk_format_map)) {
251 switch (vkformat) {
252 case VK_FORMAT_G8B8G8R8_422_UNORM:
253 return PIPE_FORMAT_YUYV;
254 case VK_FORMAT_B8G8R8G8_422_UNORM:
255 return PIPE_FORMAT_UYVY;
256 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
257 return PIPE_FORMAT_IYUV;
258 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
259 return PIPE_FORMAT_NV12;
260 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
261 return PIPE_FORMAT_Y8_U8_V8_422_UNORM;
262 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
263 return PIPE_FORMAT_Y8_U8V8_422_UNORM;
264 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
265 return PIPE_FORMAT_Y8_U8_V8_444_UNORM;
266 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
267 return PIPE_FORMAT_Y16_U16_V16_420_UNORM;
268 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
269 return PIPE_FORMAT_P016;
270 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
271 return PIPE_FORMAT_Y16_U16_V16_422_UNORM;
272 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
273 return PIPE_FORMAT_Y16_U16V16_422_UNORM;
274 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
275 return PIPE_FORMAT_Y16_U16_V16_444_UNORM;
276 case VK_FORMAT_A4R4G4B4_UNORM_PACK16:
277 return PIPE_FORMAT_B4G4R4A4_UNORM;
278 case VK_FORMAT_A4B4G4R4_UNORM_PACK16:
279 return PIPE_FORMAT_R4G4B4A4_UNORM;
280 default:
281 return PIPE_FORMAT_NONE;
282 }
283 }
284
285 /* Unpopulated entries in the table must be PIPE_FORMAT_NONE */
286 STATIC_ASSERT(PIPE_FORMAT_NONE == 0);
287
288 return vk_format_map[vkformat];
289 }
290
291 VkImageAspectFlags
vk_format_aspects(VkFormat format)292 vk_format_aspects(VkFormat format)
293 {
294 switch (format) {
295 case VK_FORMAT_UNDEFINED:
296 return 0;
297
298 case VK_FORMAT_S8_UINT:
299 return VK_IMAGE_ASPECT_STENCIL_BIT;
300
301 case VK_FORMAT_D16_UNORM_S8_UINT:
302 case VK_FORMAT_D24_UNORM_S8_UINT:
303 case VK_FORMAT_D32_SFLOAT_S8_UINT:
304 return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
305
306 case VK_FORMAT_D16_UNORM:
307 case VK_FORMAT_X8_D24_UNORM_PACK32:
308 case VK_FORMAT_D32_SFLOAT:
309 return VK_IMAGE_ASPECT_DEPTH_BIT;
310
311 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
312 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
313 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
314 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16:
315 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16:
316 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16:
317 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16:
318 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16:
319 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16:
320 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
321 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
322 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
323 return (VK_IMAGE_ASPECT_PLANE_0_BIT |
324 VK_IMAGE_ASPECT_PLANE_1_BIT |
325 VK_IMAGE_ASPECT_PLANE_2_BIT);
326
327 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
328 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
329 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
330 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16:
331 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16:
332 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16:
333 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
334 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
335 return (VK_IMAGE_ASPECT_PLANE_0_BIT |
336 VK_IMAGE_ASPECT_PLANE_1_BIT);
337
338 default:
339 return VK_IMAGE_ASPECT_COLOR_BIT;
340 }
341 }
342
343 VkFormat
vk_format_get_plane_format(VkFormat format,unsigned plane_id)344 vk_format_get_plane_format(VkFormat format, unsigned plane_id)
345 {
346 assert(plane_id < vk_format_get_plane_count(format));
347
348 switch (format) {
349 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
350 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
351 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
352 return VK_FORMAT_R8_UNORM;
353 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
354 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
355 return plane_id ? VK_FORMAT_R8G8_UNORM : VK_FORMAT_R8_UNORM;
356 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
357 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
358 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
359 return VK_FORMAT_R16_UNORM;
360 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
361 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
362 return plane_id ? VK_FORMAT_R16G16_UNORM : VK_FORMAT_R16_UNORM;
363 default:
364 assert(vk_format_get_plane_count(format) == 1);
365 return format;
366 }
367 }
368
369 VkFormat
vk_format_get_aspect_format(VkFormat format,const VkImageAspectFlags aspect)370 vk_format_get_aspect_format(VkFormat format, const VkImageAspectFlags aspect)
371 {
372 assert(util_bitcount(aspect) == 1);
373 assert(aspect & vk_format_aspects(format));
374
375 switch (aspect) {
376 case VK_IMAGE_ASPECT_COLOR_BIT:
377 return format;
378 case VK_IMAGE_ASPECT_DEPTH_BIT:
379 return vk_format_depth_only(format);
380 case VK_IMAGE_ASPECT_STENCIL_BIT:
381 return vk_format_stencil_only(format);
382 case VK_IMAGE_ASPECT_PLANE_0_BIT:
383 return vk_format_get_plane_format(format, 0);
384 case VK_IMAGE_ASPECT_PLANE_1_BIT:
385 return vk_format_get_plane_format(format, 1);
386 case VK_IMAGE_ASPECT_PLANE_2_BIT:
387 return vk_format_get_plane_format(format, 2);
388 default:
389 unreachable("Cannot translate format aspect");
390 }
391 }
392
393 void
vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,unsigned char out_swizzle[4])394 vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,
395 unsigned char out_swizzle[4])
396 {
397 VkComponentSwizzle swizzle[4] = { mapping.r, mapping.g, mapping.b, mapping.a };
398 for (unsigned i = 0; i < 4; i++) {
399 switch (swizzle[i]) {
400 case VK_COMPONENT_SWIZZLE_R:
401 out_swizzle[i] = PIPE_SWIZZLE_X;
402 break;
403 case VK_COMPONENT_SWIZZLE_G:
404 out_swizzle[i] = PIPE_SWIZZLE_Y;
405 break;
406 case VK_COMPONENT_SWIZZLE_B:
407 out_swizzle[i] = PIPE_SWIZZLE_Z;
408 break;
409 case VK_COMPONENT_SWIZZLE_A:
410 out_swizzle[i] = PIPE_SWIZZLE_W;
411 break;
412 case VK_COMPONENT_SWIZZLE_IDENTITY:
413 out_swizzle[i] = PIPE_SWIZZLE_X + i;
414 break;
415 case VK_COMPONENT_SWIZZLE_ZERO:
416 out_swizzle[i] = PIPE_SWIZZLE_0;
417 break;
418 case VK_COMPONENT_SWIZZLE_ONE:
419 out_swizzle[i] = PIPE_SWIZZLE_1;
420 break;
421 default:
422 unreachable("unknown swizzle");
423 }
424 }
425 }
426