2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "anv_private.h"
25 #include "drm-uapi/drm_fourcc.h"
26 #include "vk_enum_to_str.h"
27 #include "vk_format_info.h"
31 * gcc-4 and earlier don't allow compound literals where a constant
32 * is required in -std=c99/gnu99 mode, so we can't use ISL_SWIZZLE()
33 * here. -std=c89/gnu89 would allow it, but we depend on c99 features
34 * so using -std=c89/gnu89 is not an option. Starting from gcc-5
35 * compound literals can also be considered constant in -std=c99/gnu99
38 #define _ISL_SWIZZLE(r, g, b, a) { \
39 ISL_CHANNEL_SELECT_##r, \
40 ISL_CHANNEL_SELECT_##g, \
41 ISL_CHANNEL_SELECT_##b, \
42 ISL_CHANNEL_SELECT_##a, \
45 #define RGBA _ISL_SWIZZLE(RED, GREEN, BLUE, ALPHA)
46 #define BGRA _ISL_SWIZZLE(BLUE, GREEN, RED, ALPHA)
47 #define RGB1 _ISL_SWIZZLE(RED, GREEN, BLUE, ONE)
49 #define swiz_fmt1(__vk_fmt, __hw_fmt, __swizzle) \
50 [VK_ENUM_OFFSET(__vk_fmt)] = { \
52 { .isl_format = __hw_fmt, .swizzle = __swizzle, \
53 .denominator_scales = { 1, 1, }, \
54 .aspect = VK_IMAGE_ASPECT_COLOR_BIT, \
57 .vk_format = __vk_fmt, \
61 #define fmt1(__vk_fmt, __hw_fmt) \
62 swiz_fmt1(__vk_fmt, __hw_fmt, RGBA)
64 #define d_fmt(__vk_fmt, __hw_fmt) \
65 [VK_ENUM_OFFSET(__vk_fmt)] = { \
67 { .isl_format = __hw_fmt, .swizzle = RGBA, \
68 .denominator_scales = { 1, 1, }, \
69 .aspect = VK_IMAGE_ASPECT_DEPTH_BIT, \
72 .vk_format = __vk_fmt, \
76 #define s_fmt(__vk_fmt, __hw_fmt) \
77 [VK_ENUM_OFFSET(__vk_fmt)] = { \
79 { .isl_format = __hw_fmt, .swizzle = RGBA, \
80 .denominator_scales = { 1, 1, }, \
81 .aspect = VK_IMAGE_ASPECT_STENCIL_BIT, \
84 .vk_format = __vk_fmt, \
88 #define ds_fmt2(__vk_fmt, __fmt1, __fmt2) \
89 [VK_ENUM_OFFSET(__vk_fmt)] = { \
91 { .isl_format = __fmt1, .swizzle = RGBA, \
92 .denominator_scales = { 1, 1, }, \
93 .aspect = VK_IMAGE_ASPECT_DEPTH_BIT, \
95 { .isl_format = __fmt2, .swizzle = RGBA, \
96 .denominator_scales = { 1, 1, }, \
97 .aspect = VK_IMAGE_ASPECT_STENCIL_BIT, \
100 .vk_format = __vk_fmt, \
104 #define fmt_unsupported(__vk_fmt) \
105 [VK_ENUM_OFFSET(__vk_fmt)] = { \
107 { .isl_format = ISL_FORMAT_UNSUPPORTED, }, \
109 .vk_format = VK_FORMAT_UNDEFINED, \
112 #define y_plane(__plane, __hw_fmt, __swizzle, __ycbcr_swizzle, dhs, dvs) \
113 { .isl_format = __hw_fmt, \
114 .swizzle = __swizzle, \
115 .ycbcr_swizzle = __ycbcr_swizzle, \
116 .denominator_scales = { dhs, dvs, }, \
117 .has_chroma = false, \
118 .aspect = VK_IMAGE_ASPECT_PLANE_0_BIT, /* Y plane is always plane 0 */ \
121 #define chroma_plane(__plane, __hw_fmt, __swizzle, __ycbcr_swizzle, dhs, dvs) \
122 { .isl_format = __hw_fmt, \
123 .swizzle = __swizzle, \
124 .ycbcr_swizzle = __ycbcr_swizzle, \
125 .denominator_scales = { dhs, dvs, }, \
126 .has_chroma = true, \
127 .aspect = VK_IMAGE_ASPECT_PLANE_ ## __plane ## _BIT, \
130 #define ycbcr_fmt(__vk_fmt, __n_planes, ...) \
131 [VK_ENUM_OFFSET(__vk_fmt)] = { \
135 .vk_format = __vk_fmt, \
136 .n_planes = __n_planes, \
140 /* HINT: For array formats, the ISL name should match the VK name. For
141 * packed formats, they should have the channels in reverse order from each
142 * other. The reason for this is that, for packed formats, the ISL (and
143 * bspec) names are in LSB -> MSB order while VK formats are MSB -> LSB.
145 static const struct anv_format main_formats
[] = {
146 fmt_unsupported(VK_FORMAT_UNDEFINED
),
147 fmt_unsupported(VK_FORMAT_R4G4_UNORM_PACK8
),
148 fmt1(VK_FORMAT_R4G4B4A4_UNORM_PACK16
, ISL_FORMAT_A4B4G4R4_UNORM
),
149 swiz_fmt1(VK_FORMAT_B4G4R4A4_UNORM_PACK16
, ISL_FORMAT_A4B4G4R4_UNORM
, BGRA
),
150 fmt1(VK_FORMAT_R5G6B5_UNORM_PACK16
, ISL_FORMAT_B5G6R5_UNORM
),
151 swiz_fmt1(VK_FORMAT_B5G6R5_UNORM_PACK16
, ISL_FORMAT_B5G6R5_UNORM
, BGRA
),
152 fmt1(VK_FORMAT_R5G5B5A1_UNORM_PACK16
, ISL_FORMAT_A1B5G5R5_UNORM
),
153 fmt_unsupported(VK_FORMAT_B5G5R5A1_UNORM_PACK16
),
154 fmt1(VK_FORMAT_A1R5G5B5_UNORM_PACK16
, ISL_FORMAT_B5G5R5A1_UNORM
),
155 fmt1(VK_FORMAT_R8_UNORM
, ISL_FORMAT_R8_UNORM
),
156 fmt1(VK_FORMAT_R8_SNORM
, ISL_FORMAT_R8_SNORM
),
157 fmt1(VK_FORMAT_R8_USCALED
, ISL_FORMAT_R8_USCALED
),
158 fmt1(VK_FORMAT_R8_SSCALED
, ISL_FORMAT_R8_SSCALED
),
159 fmt1(VK_FORMAT_R8_UINT
, ISL_FORMAT_R8_UINT
),
160 fmt1(VK_FORMAT_R8_SINT
, ISL_FORMAT_R8_SINT
),
161 swiz_fmt1(VK_FORMAT_R8_SRGB
, ISL_FORMAT_L8_UNORM_SRGB
,
162 _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ONE
)),
163 fmt1(VK_FORMAT_R8G8_UNORM
, ISL_FORMAT_R8G8_UNORM
),
164 fmt1(VK_FORMAT_R8G8_SNORM
, ISL_FORMAT_R8G8_SNORM
),
165 fmt1(VK_FORMAT_R8G8_USCALED
, ISL_FORMAT_R8G8_USCALED
),
166 fmt1(VK_FORMAT_R8G8_SSCALED
, ISL_FORMAT_R8G8_SSCALED
),
167 fmt1(VK_FORMAT_R8G8_UINT
, ISL_FORMAT_R8G8_UINT
),
168 fmt1(VK_FORMAT_R8G8_SINT
, ISL_FORMAT_R8G8_SINT
),
169 fmt_unsupported(VK_FORMAT_R8G8_SRGB
), /* L8A8_UNORM_SRGB */
170 fmt1(VK_FORMAT_R8G8B8_UNORM
, ISL_FORMAT_R8G8B8_UNORM
),
171 fmt1(VK_FORMAT_R8G8B8_SNORM
, ISL_FORMAT_R8G8B8_SNORM
),
172 fmt1(VK_FORMAT_R8G8B8_USCALED
, ISL_FORMAT_R8G8B8_USCALED
),
173 fmt1(VK_FORMAT_R8G8B8_SSCALED
, ISL_FORMAT_R8G8B8_SSCALED
),
174 fmt1(VK_FORMAT_R8G8B8_UINT
, ISL_FORMAT_R8G8B8_UINT
),
175 fmt1(VK_FORMAT_R8G8B8_SINT
, ISL_FORMAT_R8G8B8_SINT
),
176 fmt1(VK_FORMAT_R8G8B8_SRGB
, ISL_FORMAT_R8G8B8_UNORM_SRGB
),
177 fmt1(VK_FORMAT_R8G8B8A8_UNORM
, ISL_FORMAT_R8G8B8A8_UNORM
),
178 fmt1(VK_FORMAT_R8G8B8A8_SNORM
, ISL_FORMAT_R8G8B8A8_SNORM
),
179 fmt1(VK_FORMAT_R8G8B8A8_USCALED
, ISL_FORMAT_R8G8B8A8_USCALED
),
180 fmt1(VK_FORMAT_R8G8B8A8_SSCALED
, ISL_FORMAT_R8G8B8A8_SSCALED
),
181 fmt1(VK_FORMAT_R8G8B8A8_UINT
, ISL_FORMAT_R8G8B8A8_UINT
),
182 fmt1(VK_FORMAT_R8G8B8A8_SINT
, ISL_FORMAT_R8G8B8A8_SINT
),
183 fmt1(VK_FORMAT_R8G8B8A8_SRGB
, ISL_FORMAT_R8G8B8A8_UNORM_SRGB
),
184 fmt1(VK_FORMAT_A8B8G8R8_UNORM_PACK32
, ISL_FORMAT_R8G8B8A8_UNORM
),
185 fmt1(VK_FORMAT_A8B8G8R8_SNORM_PACK32
, ISL_FORMAT_R8G8B8A8_SNORM
),
186 fmt1(VK_FORMAT_A8B8G8R8_USCALED_PACK32
, ISL_FORMAT_R8G8B8A8_USCALED
),
187 fmt1(VK_FORMAT_A8B8G8R8_SSCALED_PACK32
, ISL_FORMAT_R8G8B8A8_SSCALED
),
188 fmt1(VK_FORMAT_A8B8G8R8_UINT_PACK32
, ISL_FORMAT_R8G8B8A8_UINT
),
189 fmt1(VK_FORMAT_A8B8G8R8_SINT_PACK32
, ISL_FORMAT_R8G8B8A8_SINT
),
190 fmt1(VK_FORMAT_A8B8G8R8_SRGB_PACK32
, ISL_FORMAT_R8G8B8A8_UNORM_SRGB
),
191 fmt1(VK_FORMAT_A2R10G10B10_UNORM_PACK32
, ISL_FORMAT_B10G10R10A2_UNORM
),
192 fmt1(VK_FORMAT_A2R10G10B10_SNORM_PACK32
, ISL_FORMAT_B10G10R10A2_SNORM
),
193 fmt1(VK_FORMAT_A2R10G10B10_USCALED_PACK32
, ISL_FORMAT_B10G10R10A2_USCALED
),
194 fmt1(VK_FORMAT_A2R10G10B10_SSCALED_PACK32
, ISL_FORMAT_B10G10R10A2_SSCALED
),
195 fmt1(VK_FORMAT_A2R10G10B10_UINT_PACK32
, ISL_FORMAT_B10G10R10A2_UINT
),
196 fmt1(VK_FORMAT_A2R10G10B10_SINT_PACK32
, ISL_FORMAT_B10G10R10A2_SINT
),
197 fmt1(VK_FORMAT_A2B10G10R10_UNORM_PACK32
, ISL_FORMAT_R10G10B10A2_UNORM
),
198 fmt1(VK_FORMAT_A2B10G10R10_SNORM_PACK32
, ISL_FORMAT_R10G10B10A2_SNORM
),
199 fmt1(VK_FORMAT_A2B10G10R10_USCALED_PACK32
, ISL_FORMAT_R10G10B10A2_USCALED
),
200 fmt1(VK_FORMAT_A2B10G10R10_SSCALED_PACK32
, ISL_FORMAT_R10G10B10A2_SSCALED
),
201 fmt1(VK_FORMAT_A2B10G10R10_UINT_PACK32
, ISL_FORMAT_R10G10B10A2_UINT
),
202 fmt1(VK_FORMAT_A2B10G10R10_SINT_PACK32
, ISL_FORMAT_R10G10B10A2_SINT
),
203 fmt1(VK_FORMAT_R16_UNORM
, ISL_FORMAT_R16_UNORM
),
204 fmt1(VK_FORMAT_R16_SNORM
, ISL_FORMAT_R16_SNORM
),
205 fmt1(VK_FORMAT_R16_USCALED
, ISL_FORMAT_R16_USCALED
),
206 fmt1(VK_FORMAT_R16_SSCALED
, ISL_FORMAT_R16_SSCALED
),
207 fmt1(VK_FORMAT_R16_UINT
, ISL_FORMAT_R16_UINT
),
208 fmt1(VK_FORMAT_R16_SINT
, ISL_FORMAT_R16_SINT
),
209 fmt1(VK_FORMAT_R16_SFLOAT
, ISL_FORMAT_R16_FLOAT
),
210 fmt1(VK_FORMAT_R16G16_UNORM
, ISL_FORMAT_R16G16_UNORM
),
211 fmt1(VK_FORMAT_R16G16_SNORM
, ISL_FORMAT_R16G16_SNORM
),
212 fmt1(VK_FORMAT_R16G16_USCALED
, ISL_FORMAT_R16G16_USCALED
),
213 fmt1(VK_FORMAT_R16G16_SSCALED
, ISL_FORMAT_R16G16_SSCALED
),
214 fmt1(VK_FORMAT_R16G16_UINT
, ISL_FORMAT_R16G16_UINT
),
215 fmt1(VK_FORMAT_R16G16_SINT
, ISL_FORMAT_R16G16_SINT
),
216 fmt1(VK_FORMAT_R16G16_SFLOAT
, ISL_FORMAT_R16G16_FLOAT
),
217 fmt1(VK_FORMAT_R16G16B16_UNORM
, ISL_FORMAT_R16G16B16_UNORM
),
218 fmt1(VK_FORMAT_R16G16B16_SNORM
, ISL_FORMAT_R16G16B16_SNORM
),
219 fmt1(VK_FORMAT_R16G16B16_USCALED
, ISL_FORMAT_R16G16B16_USCALED
),
220 fmt1(VK_FORMAT_R16G16B16_SSCALED
, ISL_FORMAT_R16G16B16_SSCALED
),
221 fmt1(VK_FORMAT_R16G16B16_UINT
, ISL_FORMAT_R16G16B16_UINT
),
222 fmt1(VK_FORMAT_R16G16B16_SINT
, ISL_FORMAT_R16G16B16_SINT
),
223 fmt1(VK_FORMAT_R16G16B16_SFLOAT
, ISL_FORMAT_R16G16B16_FLOAT
),
224 fmt1(VK_FORMAT_R16G16B16A16_UNORM
, ISL_FORMAT_R16G16B16A16_UNORM
),
225 fmt1(VK_FORMAT_R16G16B16A16_SNORM
, ISL_FORMAT_R16G16B16A16_SNORM
),
226 fmt1(VK_FORMAT_R16G16B16A16_USCALED
, ISL_FORMAT_R16G16B16A16_USCALED
),
227 fmt1(VK_FORMAT_R16G16B16A16_SSCALED
, ISL_FORMAT_R16G16B16A16_SSCALED
),
228 fmt1(VK_FORMAT_R16G16B16A16_UINT
, ISL_FORMAT_R16G16B16A16_UINT
),
229 fmt1(VK_FORMAT_R16G16B16A16_SINT
, ISL_FORMAT_R16G16B16A16_SINT
),
230 fmt1(VK_FORMAT_R16G16B16A16_SFLOAT
, ISL_FORMAT_R16G16B16A16_FLOAT
),
231 fmt1(VK_FORMAT_R32_UINT
, ISL_FORMAT_R32_UINT
),
232 fmt1(VK_FORMAT_R32_SINT
, ISL_FORMAT_R32_SINT
),
233 fmt1(VK_FORMAT_R32_SFLOAT
, ISL_FORMAT_R32_FLOAT
),
234 fmt1(VK_FORMAT_R32G32_UINT
, ISL_FORMAT_R32G32_UINT
),
235 fmt1(VK_FORMAT_R32G32_SINT
, ISL_FORMAT_R32G32_SINT
),
236 fmt1(VK_FORMAT_R32G32_SFLOAT
, ISL_FORMAT_R32G32_FLOAT
),
237 fmt1(VK_FORMAT_R32G32B32_UINT
, ISL_FORMAT_R32G32B32_UINT
),
238 fmt1(VK_FORMAT_R32G32B32_SINT
, ISL_FORMAT_R32G32B32_SINT
),
239 fmt1(VK_FORMAT_R32G32B32_SFLOAT
, ISL_FORMAT_R32G32B32_FLOAT
),
240 fmt1(VK_FORMAT_R32G32B32A32_UINT
, ISL_FORMAT_R32G32B32A32_UINT
),
241 fmt1(VK_FORMAT_R32G32B32A32_SINT
, ISL_FORMAT_R32G32B32A32_SINT
),
242 fmt1(VK_FORMAT_R32G32B32A32_SFLOAT
, ISL_FORMAT_R32G32B32A32_FLOAT
),
243 fmt1(VK_FORMAT_R64_UINT
, ISL_FORMAT_R64_PASSTHRU
),
244 fmt1(VK_FORMAT_R64_SINT
, ISL_FORMAT_R64_PASSTHRU
),
245 fmt1(VK_FORMAT_R64_SFLOAT
, ISL_FORMAT_R64_PASSTHRU
),
246 fmt1(VK_FORMAT_R64G64_UINT
, ISL_FORMAT_R64G64_PASSTHRU
),
247 fmt1(VK_FORMAT_R64G64_SINT
, ISL_FORMAT_R64G64_PASSTHRU
),
248 fmt1(VK_FORMAT_R64G64_SFLOAT
, ISL_FORMAT_R64G64_PASSTHRU
),
249 fmt1(VK_FORMAT_R64G64B64_UINT
, ISL_FORMAT_R64G64B64_PASSTHRU
),
250 fmt1(VK_FORMAT_R64G64B64_SINT
, ISL_FORMAT_R64G64B64_PASSTHRU
),
251 fmt1(VK_FORMAT_R64G64B64_SFLOAT
, ISL_FORMAT_R64G64B64_PASSTHRU
),
252 fmt1(VK_FORMAT_R64G64B64A64_UINT
, ISL_FORMAT_R64G64B64A64_PASSTHRU
),
253 fmt1(VK_FORMAT_R64G64B64A64_SINT
, ISL_FORMAT_R64G64B64A64_PASSTHRU
),
254 fmt1(VK_FORMAT_R64G64B64A64_SFLOAT
, ISL_FORMAT_R64G64B64A64_PASSTHRU
),
255 fmt1(VK_FORMAT_B10G11R11_UFLOAT_PACK32
, ISL_FORMAT_R11G11B10_FLOAT
),
256 fmt1(VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
, ISL_FORMAT_R9G9B9E5_SHAREDEXP
),
258 d_fmt(VK_FORMAT_D16_UNORM
, ISL_FORMAT_R16_UNORM
),
259 d_fmt(VK_FORMAT_X8_D24_UNORM_PACK32
, ISL_FORMAT_R24_UNORM_X8_TYPELESS
),
260 d_fmt(VK_FORMAT_D32_SFLOAT
, ISL_FORMAT_R32_FLOAT
),
261 s_fmt(VK_FORMAT_S8_UINT
, ISL_FORMAT_R8_UINT
),
262 fmt_unsupported(VK_FORMAT_D16_UNORM_S8_UINT
),
263 ds_fmt2(VK_FORMAT_D24_UNORM_S8_UINT
, ISL_FORMAT_R24_UNORM_X8_TYPELESS
, ISL_FORMAT_R8_UINT
),
264 ds_fmt2(VK_FORMAT_D32_SFLOAT_S8_UINT
, ISL_FORMAT_R32_FLOAT
, ISL_FORMAT_R8_UINT
),
266 swiz_fmt1(VK_FORMAT_BC1_RGB_UNORM_BLOCK
, ISL_FORMAT_BC1_UNORM
, RGB1
),
267 swiz_fmt1(VK_FORMAT_BC1_RGB_SRGB_BLOCK
, ISL_FORMAT_BC1_UNORM_SRGB
, RGB1
),
268 fmt1(VK_FORMAT_BC1_RGBA_UNORM_BLOCK
, ISL_FORMAT_BC1_UNORM
),
269 fmt1(VK_FORMAT_BC1_RGBA_SRGB_BLOCK
, ISL_FORMAT_BC1_UNORM_SRGB
),
270 fmt1(VK_FORMAT_BC2_UNORM_BLOCK
, ISL_FORMAT_BC2_UNORM
),
271 fmt1(VK_FORMAT_BC2_SRGB_BLOCK
, ISL_FORMAT_BC2_UNORM_SRGB
),
272 fmt1(VK_FORMAT_BC3_UNORM_BLOCK
, ISL_FORMAT_BC3_UNORM
),
273 fmt1(VK_FORMAT_BC3_SRGB_BLOCK
, ISL_FORMAT_BC3_UNORM_SRGB
),
274 fmt1(VK_FORMAT_BC4_UNORM_BLOCK
, ISL_FORMAT_BC4_UNORM
),
275 fmt1(VK_FORMAT_BC4_SNORM_BLOCK
, ISL_FORMAT_BC4_SNORM
),
276 fmt1(VK_FORMAT_BC5_UNORM_BLOCK
, ISL_FORMAT_BC5_UNORM
),
277 fmt1(VK_FORMAT_BC5_SNORM_BLOCK
, ISL_FORMAT_BC5_SNORM
),
278 fmt1(VK_FORMAT_BC6H_UFLOAT_BLOCK
, ISL_FORMAT_BC6H_UF16
),
279 fmt1(VK_FORMAT_BC6H_SFLOAT_BLOCK
, ISL_FORMAT_BC6H_SF16
),
280 fmt1(VK_FORMAT_BC7_UNORM_BLOCK
, ISL_FORMAT_BC7_UNORM
),
281 fmt1(VK_FORMAT_BC7_SRGB_BLOCK
, ISL_FORMAT_BC7_UNORM_SRGB
),
282 fmt1(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
, ISL_FORMAT_ETC2_RGB8
),
283 fmt1(VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK
, ISL_FORMAT_ETC2_SRGB8
),
284 fmt1(VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK
, ISL_FORMAT_ETC2_RGB8_PTA
),
285 fmt1(VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK
, ISL_FORMAT_ETC2_SRGB8_PTA
),
286 fmt1(VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK
, ISL_FORMAT_ETC2_EAC_RGBA8
),
287 fmt1(VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK
, ISL_FORMAT_ETC2_EAC_SRGB8_A8
),
288 fmt1(VK_FORMAT_EAC_R11_UNORM_BLOCK
, ISL_FORMAT_EAC_R11
),
289 fmt1(VK_FORMAT_EAC_R11_SNORM_BLOCK
, ISL_FORMAT_EAC_SIGNED_R11
),
290 fmt1(VK_FORMAT_EAC_R11G11_UNORM_BLOCK
, ISL_FORMAT_EAC_RG11
),
291 fmt1(VK_FORMAT_EAC_R11G11_SNORM_BLOCK
, ISL_FORMAT_EAC_SIGNED_RG11
),
292 fmt1(VK_FORMAT_ASTC_4x4_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_4X4_U8SRGB
),
293 fmt1(VK_FORMAT_ASTC_5x4_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_5X4_U8SRGB
),
294 fmt1(VK_FORMAT_ASTC_5x5_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_5X5_U8SRGB
),
295 fmt1(VK_FORMAT_ASTC_6x5_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_6X5_U8SRGB
),
296 fmt1(VK_FORMAT_ASTC_6x6_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_6X6_U8SRGB
),
297 fmt1(VK_FORMAT_ASTC_8x5_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X5_U8SRGB
),
298 fmt1(VK_FORMAT_ASTC_8x6_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X6_U8SRGB
),
299 fmt1(VK_FORMAT_ASTC_8x8_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X8_U8SRGB
),
300 fmt1(VK_FORMAT_ASTC_10x5_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X5_U8SRGB
),
301 fmt1(VK_FORMAT_ASTC_10x6_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X6_U8SRGB
),
302 fmt1(VK_FORMAT_ASTC_10x8_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X8_U8SRGB
),
303 fmt1(VK_FORMAT_ASTC_10x10_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X10_U8SRGB
),
304 fmt1(VK_FORMAT_ASTC_12x10_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_12X10_U8SRGB
),
305 fmt1(VK_FORMAT_ASTC_12x12_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_12X12_U8SRGB
),
306 fmt1(VK_FORMAT_ASTC_4x4_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_4X4_FLT16
),
307 fmt1(VK_FORMAT_ASTC_5x4_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_5X4_FLT16
),
308 fmt1(VK_FORMAT_ASTC_5x5_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_5X5_FLT16
),
309 fmt1(VK_FORMAT_ASTC_6x5_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_6X5_FLT16
),
310 fmt1(VK_FORMAT_ASTC_6x6_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_6X6_FLT16
),
311 fmt1(VK_FORMAT_ASTC_8x5_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X5_FLT16
),
312 fmt1(VK_FORMAT_ASTC_8x6_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X6_FLT16
),
313 fmt1(VK_FORMAT_ASTC_8x8_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X8_FLT16
),
314 fmt1(VK_FORMAT_ASTC_10x5_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X5_FLT16
),
315 fmt1(VK_FORMAT_ASTC_10x6_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X6_FLT16
),
316 fmt1(VK_FORMAT_ASTC_10x8_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X8_FLT16
),
317 fmt1(VK_FORMAT_ASTC_10x10_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X10_FLT16
),
318 fmt1(VK_FORMAT_ASTC_12x10_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_12X10_FLT16
),
319 fmt1(VK_FORMAT_ASTC_12x12_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_12X12_FLT16
),
320 fmt_unsupported(VK_FORMAT_B8G8R8_UNORM
),
321 fmt_unsupported(VK_FORMAT_B8G8R8_SNORM
),
322 fmt_unsupported(VK_FORMAT_B8G8R8_USCALED
),
323 fmt_unsupported(VK_FORMAT_B8G8R8_SSCALED
),
324 fmt_unsupported(VK_FORMAT_B8G8R8_UINT
),
325 fmt_unsupported(VK_FORMAT_B8G8R8_SINT
),
326 fmt_unsupported(VK_FORMAT_B8G8R8_SRGB
),
327 fmt1(VK_FORMAT_B8G8R8A8_UNORM
, ISL_FORMAT_B8G8R8A8_UNORM
),
328 fmt_unsupported(VK_FORMAT_B8G8R8A8_SNORM
),
329 fmt_unsupported(VK_FORMAT_B8G8R8A8_USCALED
),
330 fmt_unsupported(VK_FORMAT_B8G8R8A8_SSCALED
),
331 fmt_unsupported(VK_FORMAT_B8G8R8A8_UINT
),
332 fmt_unsupported(VK_FORMAT_B8G8R8A8_SINT
),
333 fmt1(VK_FORMAT_B8G8R8A8_SRGB
, ISL_FORMAT_B8G8R8A8_UNORM_SRGB
),
336 static const struct anv_format ycbcr_formats
[] = {
337 ycbcr_fmt(VK_FORMAT_G8B8G8R8_422_UNORM
, 1,
338 y_plane(0, ISL_FORMAT_YCRCB_SWAPUV
, RGBA
, _ISL_SWIZZLE(BLUE
, GREEN
, RED
, ZERO
), 1, 1)),
339 ycbcr_fmt(VK_FORMAT_B8G8R8G8_422_UNORM
, 1,
340 y_plane(0, ISL_FORMAT_YCRCB_SWAPUVY
, RGBA
, _ISL_SWIZZLE(BLUE
, GREEN
, RED
, ZERO
), 1, 1)),
341 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM
, 3,
342 y_plane(0, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
343 chroma_plane(1, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 2, 2),
344 chroma_plane(2, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 2, 2)),
345 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_420_UNORM
, 2,
346 y_plane(0, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
347 chroma_plane(1, ISL_FORMAT_R8G8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, RED
, ZERO
, ZERO
), 2, 2)),
348 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM
, 3,
349 y_plane(0, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
350 chroma_plane(1, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 2, 1),
351 chroma_plane(2, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 2, 1)),
352 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_422_UNORM
, 2,
353 y_plane(0, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
354 chroma_plane(1, ISL_FORMAT_R8G8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, RED
, ZERO
, ZERO
), 2, 1)),
355 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM
, 3,
356 y_plane(0, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
357 chroma_plane(1, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 1, 1),
358 chroma_plane(2, ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 1, 1)),
360 fmt_unsupported(VK_FORMAT_R10X6_UNORM_PACK16
),
361 fmt_unsupported(VK_FORMAT_R10X6G10X6_UNORM_2PACK16
),
362 fmt_unsupported(VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16
),
363 fmt_unsupported(VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16
),
364 fmt_unsupported(VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16
),
365 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16
),
366 fmt_unsupported(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16
),
367 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16
),
368 fmt_unsupported(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16
),
369 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16
),
370 fmt_unsupported(VK_FORMAT_R12X4_UNORM_PACK16
),
371 fmt_unsupported(VK_FORMAT_R12X4G12X4_UNORM_2PACK16
),
372 fmt_unsupported(VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16
),
373 fmt_unsupported(VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16
),
374 fmt_unsupported(VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16
),
375 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16
),
376 fmt_unsupported(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16
),
377 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16
),
378 fmt_unsupported(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16
),
379 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16
),
380 /* TODO: it is possible to enable the following 2 formats, but that
381 * requires further refactoring of how we handle multiplanar formats.
383 fmt_unsupported(VK_FORMAT_G16B16G16R16_422_UNORM
),
384 fmt_unsupported(VK_FORMAT_B16G16R16G16_422_UNORM
),
386 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM
, 3,
387 y_plane(0, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
388 chroma_plane(1, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 2, 2),
389 chroma_plane(2, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 2, 2)),
390 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_420_UNORM
, 2,
391 y_plane(0, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
392 chroma_plane(1, ISL_FORMAT_R16G16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, RED
, ZERO
, ZERO
), 2, 2)),
393 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM
, 3,
394 y_plane(0, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
395 chroma_plane(1, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 2, 1),
396 chroma_plane(2, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 2, 1)),
397 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_422_UNORM
, 2,
398 y_plane(0, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
399 chroma_plane(1, ISL_FORMAT_R16G16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, RED
, ZERO
, ZERO
), 2, 1)),
400 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM
, 3,
401 y_plane(0, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
402 chroma_plane(1, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 1, 1),
403 chroma_plane(2, ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 1, 1)),
411 static const struct {
412 const struct anv_format
*formats
;
415 [0] = { .formats
= main_formats
,
416 .n_formats
= ARRAY_SIZE(main_formats
), },
417 [_VK_KHR_sampler_ycbcr_conversion_number
] = { .formats
= ycbcr_formats
,
418 .n_formats
= ARRAY_SIZE(ycbcr_formats
), },
421 const struct anv_format
*
422 anv_get_format(VkFormat vk_format
)
424 uint32_t enum_offset
= VK_ENUM_OFFSET(vk_format
);
425 uint32_t ext_number
= VK_ENUM_EXTENSION(vk_format
);
427 if (ext_number
>= ARRAY_SIZE(anv_formats
) ||
428 enum_offset
>= anv_formats
[ext_number
].n_formats
)
431 const struct anv_format
*format
=
432 &anv_formats
[ext_number
].formats
[enum_offset
];
433 if (format
->planes
[0].isl_format
== ISL_FORMAT_UNSUPPORTED
)
440 * Exactly one bit must be set in \a aspect.
442 struct anv_format_plane
443 anv_get_format_plane(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
444 VkImageAspectFlagBits aspect
, VkImageTiling tiling
)
446 const struct anv_format
*format
= anv_get_format(vk_format
);
447 const struct anv_format_plane unsupported
= {
448 .isl_format
= ISL_FORMAT_UNSUPPORTED
,
454 uint32_t plane
= anv_image_aspect_to_plane(vk_format_aspects(vk_format
), aspect
);
455 struct anv_format_plane plane_format
= format
->planes
[plane
];
456 if (plane_format
.isl_format
== ISL_FORMAT_UNSUPPORTED
)
459 if (aspect
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
460 assert(vk_format_aspects(vk_format
) &
461 (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
));
465 assert((aspect
& ~VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) == 0);
467 const struct isl_format_layout
*isl_layout
=
468 isl_format_get_layout(plane_format
.isl_format
);
470 /* On Ivy Bridge we don't even have enough 24 and 48-bit formats that we
471 * can reliably do texture upload with BLORP so just don't claim support
474 if (devinfo
->gen
== 7 && !devinfo
->is_haswell
&&
475 (isl_layout
->bpb
== 24 || isl_layout
->bpb
== 48))
478 if (tiling
== VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT
) {
479 /* No non-power-of-two fourcc formats exist */
480 if (!util_is_power_of_two_or_zero(isl_layout
->bpb
))
483 if (vk_format_is_depth_or_stencil(vk_format
))
486 if (isl_format_is_compressed(plane_format
.isl_format
))
490 if (tiling
== VK_IMAGE_TILING_OPTIMAL
&&
491 !util_is_power_of_two_or_zero(isl_layout
->bpb
)) {
492 /* Tiled formats *must* be power-of-two because we need up upload
493 * them with the render pipeline. For 3-channel formats, we fix
494 * this by switching them over to RGBX or RGBA formats under the
497 enum isl_format rgbx
= isl_format_rgb_to_rgbx(plane_format
.isl_format
);
498 if (rgbx
!= ISL_FORMAT_UNSUPPORTED
&&
499 isl_format_supports_rendering(devinfo
, rgbx
)) {
500 plane_format
.isl_format
= rgbx
;
502 plane_format
.isl_format
=
503 isl_format_rgb_to_rgba(plane_format
.isl_format
);
504 plane_format
.swizzle
= ISL_SWIZZLE(RED
, GREEN
, BLUE
, ONE
);
508 /* The B4G4R4A4 format isn't available prior to Broadwell so we have to fall
509 * back to a format with a more complex swizzle.
511 if (vk_format
== VK_FORMAT_B4G4R4A4_UNORM_PACK16
&& devinfo
->gen
< 8) {
512 plane_format
.isl_format
= ISL_FORMAT_B4G4R4A4_UNORM
;
513 plane_format
.swizzle
= ISL_SWIZZLE(GREEN
, RED
, ALPHA
, BLUE
);
519 // Format capabilities
522 anv_get_image_format_features(const struct gen_device_info
*devinfo
,
524 const struct anv_format
*anv_format
,
525 VkImageTiling vk_tiling
)
527 VkFormatFeatureFlags flags
= 0;
529 if (anv_format
== NULL
)
532 const VkImageAspectFlags aspects
= vk_format_aspects(vk_format
);
534 if (aspects
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
535 if (vk_tiling
== VK_IMAGE_TILING_LINEAR
)
538 flags
|= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
|
539 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
540 VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
541 VK_FORMAT_FEATURE_BLIT_DST_BIT
|
542 VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
543 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
545 if ((aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) && devinfo
->gen
>= 9)
546 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT
;
551 const struct anv_format_plane plane_format
=
552 anv_get_format_plane(devinfo
, vk_format
, VK_IMAGE_ASPECT_COLOR_BIT
,
555 if (plane_format
.isl_format
== ISL_FORMAT_UNSUPPORTED
)
558 struct anv_format_plane base_plane_format
= plane_format
;
559 if (vk_tiling
!= VK_IMAGE_TILING_LINEAR
) {
560 base_plane_format
= anv_get_format_plane(devinfo
, vk_format
,
561 VK_IMAGE_ASPECT_COLOR_BIT
,
562 VK_IMAGE_TILING_LINEAR
);
565 enum isl_format base_isl_format
= base_plane_format
.isl_format
;
567 /* ASTC textures must be in Y-tiled memory */
568 if (vk_tiling
== VK_IMAGE_TILING_LINEAR
&&
569 isl_format_get_layout(plane_format
.isl_format
)->txc
== ISL_TXC_ASTC
)
572 /* ASTC requires nasty workarounds on BSW so we just disable it for now.
574 * TODO: Figure out the ASTC workarounds and re-enable on BSW.
576 if (devinfo
->gen
< 9 &&
577 isl_format_get_layout(plane_format
.isl_format
)->txc
== ISL_TXC_ASTC
)
580 if (isl_format_supports_sampling(devinfo
, plane_format
.isl_format
)) {
581 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
;
583 if (devinfo
->gen
>= 9)
584 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT
;
586 if (isl_format_supports_filtering(devinfo
, plane_format
.isl_format
))
587 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
590 /* We can render to swizzled formats. However, if the alpha channel is
591 * moved, then blending won't work correctly. The PRM tells us
592 * straight-up not to render to such a surface.
594 if (isl_format_supports_rendering(devinfo
, plane_format
.isl_format
) &&
595 plane_format
.swizzle
.a
== ISL_CHANNEL_SELECT_ALPHA
) {
596 flags
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
;
598 if (isl_format_supports_alpha_blending(devinfo
, plane_format
.isl_format
))
599 flags
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
602 /* Load/store is determined based on base format. This prevents RGB
603 * formats from showing up as load/store capable.
605 if (isl_is_storage_image_format(base_isl_format
))
606 flags
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
608 if (base_isl_format
== ISL_FORMAT_R32_SINT
||
609 base_isl_format
== ISL_FORMAT_R32_UINT
)
610 flags
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
613 flags
|= VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
614 VK_FORMAT_FEATURE_BLIT_DST_BIT
|
615 VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
616 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
619 /* XXX: We handle 3-channel formats by switching them out for RGBX or
620 * RGBA formats behind-the-scenes. This works fine for textures
621 * because the upload process will fill in the extra channel.
622 * We could also support it for render targets, but it will take
623 * substantially more work and we have enough RGBX formats to handle
624 * what most clients will want.
626 if (vk_tiling
== VK_IMAGE_TILING_OPTIMAL
&&
627 base_isl_format
!= ISL_FORMAT_UNSUPPORTED
&&
628 !util_is_power_of_two_or_zero(isl_format_layouts
[base_isl_format
].bpb
) &&
629 isl_format_rgb_to_rgbx(base_isl_format
) == ISL_FORMAT_UNSUPPORTED
) {
630 flags
&= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
;
631 flags
&= ~VK_FORMAT_FEATURE_BLIT_DST_BIT
;
634 if (anv_format
->can_ycbcr
) {
635 /* The sampler doesn't have support for mid point when it handles YUV on
638 if (isl_format_is_yuv(anv_format
->planes
[0].isl_format
)) {
639 /* TODO: We've disabled linear implicit reconstruction with the
640 * sampler. The failures show a slightly out of range values on the
641 * bottom left of the sampled image.
643 flags
|= VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT
;
645 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT
|
646 VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT
|
647 VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT
;
650 /* We can support cosited chroma locations when handle planes with our
651 * own shader snippets.
653 for (unsigned p
= 0; p
< anv_format
->n_planes
; p
++) {
654 if (anv_format
->planes
[p
].denominator_scales
[0] > 1 ||
655 anv_format
->planes
[p
].denominator_scales
[1] > 1) {
656 flags
|= VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT
;
661 if (anv_format
->n_planes
> 1)
662 flags
|= VK_FORMAT_FEATURE_DISJOINT_BIT
;
664 const VkFormatFeatureFlags disallowed_ycbcr_image_features
=
665 VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
666 VK_FORMAT_FEATURE_BLIT_DST_BIT
|
667 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
668 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
|
669 VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
671 flags
&= ~disallowed_ycbcr_image_features
;
677 static VkFormatFeatureFlags
678 get_buffer_format_features(const struct gen_device_info
*devinfo
,
680 const struct anv_format
*anv_format
)
682 VkFormatFeatureFlags flags
= 0;
684 if (anv_format
== NULL
)
687 const enum isl_format isl_format
= anv_format
->planes
[0].isl_format
;
689 if (isl_format
== ISL_FORMAT_UNSUPPORTED
)
692 if (anv_format
->n_planes
> 1)
695 if (anv_format
->can_ycbcr
)
698 if (vk_format_is_depth_or_stencil(vk_format
))
701 if (isl_format_supports_sampling(devinfo
, isl_format
) &&
702 !isl_format_is_compressed(isl_format
))
703 flags
|= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
;
705 if (isl_format_supports_vertex_fetch(devinfo
, isl_format
))
706 flags
|= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
;
708 if (isl_is_storage_image_format(isl_format
))
709 flags
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
;
711 if (isl_format
== ISL_FORMAT_R32_SINT
|| isl_format
== ISL_FORMAT_R32_UINT
)
712 flags
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
;
718 get_wsi_format_modifier_properties_list(const struct anv_physical_device
*physical_device
,
720 VkDrmFormatModifierPropertiesListEXT
*list
)
722 const struct anv_format
*anv_format
= anv_get_format(vk_format
);
724 VK_OUTARRAY_MAKE(out
, list
->pDrmFormatModifierProperties
,
725 &list
->drmFormatModifierCount
);
727 /* This is a simplified list where all the modifiers are available */
728 assert(vk_format
== VK_FORMAT_B8G8R8_SRGB
||
729 vk_format
== VK_FORMAT_B8G8R8_UNORM
||
730 vk_format
== VK_FORMAT_B8G8R8A8_SRGB
||
731 vk_format
== VK_FORMAT_B8G8R8A8_UNORM
);
733 uint64_t modifiers
[] = {
734 DRM_FORMAT_MOD_LINEAR
,
735 I915_FORMAT_MOD_X_TILED
,
736 I915_FORMAT_MOD_Y_TILED
,
737 I915_FORMAT_MOD_Y_TILED_CCS
,
740 for (uint32_t i
= 0; i
< ARRAY_SIZE(modifiers
); i
++) {
741 const struct isl_drm_modifier_info
*mod_info
=
742 isl_drm_modifier_get_info(modifiers
[i
]);
744 if (mod_info
->aux_usage
== ISL_AUX_USAGE_CCS_E
&&
745 !isl_format_supports_ccs_e(&physical_device
->info
,
746 anv_format
->planes
[0].isl_format
))
749 /* Gen12's CCS layout changes compared to Gen9-11. */
750 if (mod_info
->modifier
== I915_FORMAT_MOD_Y_TILED_CCS
&&
751 physical_device
->info
.gen
>= 12)
754 vk_outarray_append(&out
, mod_props
) {
755 mod_props
->drmFormatModifier
= modifiers
[i
];
756 if (isl_drm_modifier_has_aux(modifiers
[i
]))
757 mod_props
->drmFormatModifierPlaneCount
= 2;
759 mod_props
->drmFormatModifierPlaneCount
= anv_format
->n_planes
;
764 void anv_GetPhysicalDeviceFormatProperties(
765 VkPhysicalDevice physicalDevice
,
767 VkFormatProperties
* pFormatProperties
)
769 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
770 const struct gen_device_info
*devinfo
= &physical_device
->info
;
771 const struct anv_format
*anv_format
= anv_get_format(vk_format
);
773 *pFormatProperties
= (VkFormatProperties
) {
774 .linearTilingFeatures
=
775 anv_get_image_format_features(devinfo
, vk_format
, anv_format
,
776 VK_IMAGE_TILING_LINEAR
),
777 .optimalTilingFeatures
=
778 anv_get_image_format_features(devinfo
, vk_format
, anv_format
,
779 VK_IMAGE_TILING_OPTIMAL
),
781 get_buffer_format_features(devinfo
, vk_format
, anv_format
),
785 void anv_GetPhysicalDeviceFormatProperties2(
786 VkPhysicalDevice physicalDevice
,
788 VkFormatProperties2
* pFormatProperties
)
790 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
791 anv_GetPhysicalDeviceFormatProperties(physicalDevice
, format
,
792 &pFormatProperties
->formatProperties
);
794 vk_foreach_struct(ext
, pFormatProperties
->pNext
) {
795 /* Use unsigned since some cases are not in the VkStructureType enum. */
796 switch ((unsigned)ext
->sType
) {
797 case VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT
:
798 get_wsi_format_modifier_properties_list(physical_device
, format
,
802 anv_debug_ignored_stype(ext
->sType
);
809 anv_get_image_format_properties(
810 struct anv_physical_device
*physical_device
,
811 const VkPhysicalDeviceImageFormatInfo2
*info
,
812 VkImageFormatProperties
*pImageFormatProperties
,
813 VkSamplerYcbcrConversionImageFormatProperties
*pYcbcrImageFormatProperties
)
815 VkFormatFeatureFlags format_feature_flags
;
816 VkExtent3D maxExtent
;
817 uint32_t maxMipLevels
;
818 uint32_t maxArraySize
;
819 VkSampleCountFlags sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
820 const struct gen_device_info
*devinfo
= &physical_device
->info
;
821 const struct anv_format
*format
= anv_get_format(info
->format
);
826 assert(format
->vk_format
== info
->format
);
827 format_feature_flags
= anv_get_image_format_features(devinfo
, info
->format
,
828 format
, info
->tiling
);
830 switch (info
->type
) {
832 unreachable("bad VkImageType");
833 case VK_IMAGE_TYPE_1D
:
834 maxExtent
.width
= 16384;
835 maxExtent
.height
= 1;
837 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
839 sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
841 case VK_IMAGE_TYPE_2D
:
842 /* FINISHME: Does this really differ for cube maps? The documentation
843 * for RENDER_SURFACE_STATE suggests so.
845 maxExtent
.width
= 16384;
846 maxExtent
.height
= 16384;
848 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
851 case VK_IMAGE_TYPE_3D
:
852 maxExtent
.width
= 2048;
853 maxExtent
.height
= 2048;
854 maxExtent
.depth
= 2048;
855 maxMipLevels
= 12; /* log2(maxWidth) + 1 */
860 /* Our hardware doesn't support 1D compressed textures.
861 * From the SKL PRM, RENDER_SURFACE_STATE::SurfaceFormat:
862 * * This field cannot be a compressed (BC*, DXT*, FXT*, ETC*, EAC*) format
863 * if the Surface Type is SURFTYPE_1D.
864 * * This field cannot be ASTC format if the Surface Type is SURFTYPE_1D.
866 if (info
->type
== VK_IMAGE_TYPE_1D
&&
867 isl_format_is_compressed(format
->planes
[0].isl_format
)) {
871 if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
&&
872 info
->type
== VK_IMAGE_TYPE_2D
&&
873 (format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
874 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) &&
875 !(info
->flags
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
) &&
876 !(info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
)) {
877 sampleCounts
= isl_device_get_sample_counts(&physical_device
->isl_dev
);
880 if (info
->usage
& (VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
881 VK_IMAGE_USAGE_TRANSFER_DST_BIT
)) {
882 /* Accept transfers on anything we can sample from or renderer to. */
883 if (!(format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
884 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
|
885 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
))) {
890 if (info
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
891 if (!(format_feature_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)) {
896 if (info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
897 if (!(format_feature_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)) {
902 if (info
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
903 if (!(format_feature_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)) {
908 if (info
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
) {
909 if (!(format_feature_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) {
914 if (info
->usage
& VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
) {
915 /* Nothing to check. */
918 if (info
->usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
) {
919 /* Ignore this flag because it was removed from the
920 * provisional_I_20150910 header.
924 if (info
->tiling
== VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT
) {
925 const VkPhysicalDeviceImageDrmFormatModifierInfoEXT
*modifier_info
=
926 vk_find_struct_const(info
->pNext
,
927 PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT
);
929 /* Modifiers are only supported on simple 2D images */
930 if (info
->type
!= VK_IMAGE_TYPE_2D
)
934 assert(sampleCounts
== VK_SAMPLE_COUNT_1_BIT
);
936 /* Modifiers are not yet supported for YCbCr */
937 const struct anv_format
*format
= anv_get_format(info
->format
);
938 if (format
->n_planes
> 1)
941 const struct isl_drm_modifier_info
*isl_mod_info
=
942 isl_drm_modifier_get_info(modifier_info
->drmFormatModifier
);
943 if (isl_mod_info
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
944 /* If we have a CCS modifier, ensure that the format supports CCS
945 * and, if VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT is set, all of the
946 * formats in the format list are CCS compatible.
948 const VkImageFormatListCreateInfoKHR
*fmt_list
=
949 vk_find_struct_const(info
->pNext
,
950 IMAGE_FORMAT_LIST_CREATE_INFO_KHR
);
951 if (!anv_formats_ccs_e_compatible(devinfo
, info
->flags
,
952 info
->format
, info
->tiling
,
958 /* From the bspec section entitled "Surface Layout and Tiling",
959 * pre-gen9 has a 2 GB limitation of the size in bytes,
960 * gen9 and gen10 have a 256 GB limitation and gen11+
961 * has a 16 TB limitation.
963 uint64_t maxResourceSize
= 0;
964 if (devinfo
->gen
< 9)
965 maxResourceSize
= (uint64_t) 1 << 31;
966 else if (devinfo
->gen
< 11)
967 maxResourceSize
= (uint64_t) 1 << 38;
969 maxResourceSize
= (uint64_t) 1 << 44;
971 *pImageFormatProperties
= (VkImageFormatProperties
) {
972 .maxExtent
= maxExtent
,
973 .maxMipLevels
= maxMipLevels
,
974 .maxArrayLayers
= maxArraySize
,
975 .sampleCounts
= sampleCounts
,
977 /* FINISHME: Accurately calculate
978 * VkImageFormatProperties::maxResourceSize.
980 .maxResourceSize
= maxResourceSize
,
983 if (pYcbcrImageFormatProperties
) {
984 pYcbcrImageFormatProperties
->combinedImageSamplerDescriptorCount
=
991 *pImageFormatProperties
= (VkImageFormatProperties
) {
992 .maxExtent
= { 0, 0, 0 },
996 .maxResourceSize
= 0,
999 return VK_ERROR_FORMAT_NOT_SUPPORTED
;
1002 VkResult
anv_GetPhysicalDeviceImageFormatProperties(
1003 VkPhysicalDevice physicalDevice
,
1006 VkImageTiling tiling
,
1007 VkImageUsageFlags usage
,
1008 VkImageCreateFlags createFlags
,
1009 VkImageFormatProperties
* pImageFormatProperties
)
1011 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1013 const VkPhysicalDeviceImageFormatInfo2 info
= {
1014 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2
,
1020 .flags
= createFlags
,
1023 return anv_get_image_format_properties(physical_device
, &info
,
1024 pImageFormatProperties
, NULL
);
1027 static const VkExternalMemoryProperties prime_fd_props
= {
1028 /* If we can handle external, then we can both import and export it. */
1029 .externalMemoryFeatures
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|
1030 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
,
1031 /* For the moment, let's not support mixing and matching */
1032 .exportFromImportedHandleTypes
=
1033 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
|
1034 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
,
1035 .compatibleHandleTypes
=
1036 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
|
1037 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
,
1040 static const VkExternalMemoryProperties userptr_props
= {
1041 .externalMemoryFeatures
= VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
,
1042 .exportFromImportedHandleTypes
= 0,
1043 .compatibleHandleTypes
=
1044 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
,
1047 static const VkExternalMemoryProperties android_buffer_props
= {
1048 .externalMemoryFeatures
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|
1049 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
,
1050 .exportFromImportedHandleTypes
=
1051 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
,
1052 .compatibleHandleTypes
=
1053 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
,
1057 static const VkExternalMemoryProperties android_image_props
= {
1058 .externalMemoryFeatures
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|
1059 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
|
1060 VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT
,
1061 .exportFromImportedHandleTypes
=
1062 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
,
1063 .compatibleHandleTypes
=
1064 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
,
1067 VkResult
anv_GetPhysicalDeviceImageFormatProperties2(
1068 VkPhysicalDevice physicalDevice
,
1069 const VkPhysicalDeviceImageFormatInfo2
* base_info
,
1070 VkImageFormatProperties2
* base_props
)
1072 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1073 const VkPhysicalDeviceExternalImageFormatInfo
*external_info
= NULL
;
1074 VkExternalImageFormatProperties
*external_props
= NULL
;
1075 VkSamplerYcbcrConversionImageFormatProperties
*ycbcr_props
= NULL
;
1076 VkAndroidHardwareBufferUsageANDROID
*android_usage
= NULL
;
1079 /* Extract input structs */
1080 vk_foreach_struct_const(s
, base_info
->pNext
) {
1082 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO
:
1083 external_info
= (const void *) s
;
1085 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT
:
1086 /* anv_get_image_format_properties will handle this */
1088 case VK_STRUCTURE_TYPE_IMAGE_STENCIL_USAGE_CREATE_INFO_EXT
:
1089 /* Ignore but don't warn */
1092 anv_debug_ignored_stype(s
->sType
);
1097 /* Extract output structs */
1098 vk_foreach_struct(s
, base_props
->pNext
) {
1100 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES
:
1101 external_props
= (void *) s
;
1103 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES
:
1104 ycbcr_props
= (void *) s
;
1106 case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID
:
1107 android_usage
= (void *) s
;
1110 anv_debug_ignored_stype(s
->sType
);
1115 result
= anv_get_image_format_properties(physical_device
, base_info
,
1116 &base_props
->imageFormatProperties
, ycbcr_props
);
1117 if (result
!= VK_SUCCESS
)
1120 bool ahw_supported
=
1121 physical_device
->supported_extensions
.ANDROID_external_memory_android_hardware_buffer
;
1123 if (ahw_supported
&& android_usage
) {
1124 android_usage
->androidHardwareBufferUsage
=
1125 anv_ahw_usage_from_vk_usage(base_info
->flags
,
1128 /* Limit maxArrayLayers to 1 for AHardwareBuffer based images for now. */
1129 base_props
->imageFormatProperties
.maxArrayLayers
= 1;
1132 /* From the Vulkan 1.0.42 spec:
1134 * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
1135 * behave as if VkPhysicalDeviceExternalImageFormatInfo was not
1136 * present and VkExternalImageFormatProperties will be ignored.
1138 if (external_info
&& external_info
->handleType
!= 0) {
1139 switch (external_info
->handleType
) {
1140 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
:
1141 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1143 external_props
->externalMemoryProperties
= prime_fd_props
;
1145 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1147 external_props
->externalMemoryProperties
= userptr_props
;
1149 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
:
1150 if (ahw_supported
&& external_props
) {
1151 external_props
->externalMemoryProperties
= android_image_props
;
1154 /* fallthrough if ahw not supported */
1156 /* From the Vulkan 1.0.42 spec:
1158 * If handleType is not compatible with the [parameters] specified
1159 * in VkPhysicalDeviceImageFormatInfo2, then
1160 * vkGetPhysicalDeviceImageFormatProperties2 returns
1161 * VK_ERROR_FORMAT_NOT_SUPPORTED.
1163 result
= vk_errorfi(physical_device
->instance
, physical_device
,
1164 VK_ERROR_FORMAT_NOT_SUPPORTED
,
1165 "unsupported VkExternalMemoryTypeFlagBits 0x%x",
1166 external_info
->handleType
);
1174 if (result
== VK_ERROR_FORMAT_NOT_SUPPORTED
) {
1175 /* From the Vulkan 1.0.42 spec:
1177 * If the combination of parameters to
1178 * vkGetPhysicalDeviceImageFormatProperties2 is not supported by
1179 * the implementation for use in vkCreateImage, then all members of
1180 * imageFormatProperties will be filled with zero.
1182 base_props
->imageFormatProperties
= (VkImageFormatProperties
) {};
1188 void anv_GetPhysicalDeviceSparseImageFormatProperties(
1189 VkPhysicalDevice physicalDevice
,
1193 VkImageUsageFlags usage
,
1194 VkImageTiling tiling
,
1195 uint32_t* pNumProperties
,
1196 VkSparseImageFormatProperties
* pProperties
)
1198 /* Sparse images are not yet supported. */
1199 *pNumProperties
= 0;
1202 void anv_GetPhysicalDeviceSparseImageFormatProperties2(
1203 VkPhysicalDevice physicalDevice
,
1204 const VkPhysicalDeviceSparseImageFormatInfo2
* pFormatInfo
,
1205 uint32_t* pPropertyCount
,
1206 VkSparseImageFormatProperties2
* pProperties
)
1208 /* Sparse images are not yet supported. */
1209 *pPropertyCount
= 0;
1212 void anv_GetPhysicalDeviceExternalBufferProperties(
1213 VkPhysicalDevice physicalDevice
,
1214 const VkPhysicalDeviceExternalBufferInfo
* pExternalBufferInfo
,
1215 VkExternalBufferProperties
* pExternalBufferProperties
)
1217 /* The Vulkan 1.0.42 spec says "handleType must be a valid
1218 * VkExternalMemoryHandleTypeFlagBits value" in
1219 * VkPhysicalDeviceExternalBufferInfo. This differs from
1220 * VkPhysicalDeviceExternalImageFormatInfo, which surprisingly permits
1223 assert(pExternalBufferInfo
->handleType
!= 0);
1225 /* All of the current flags are for sparse which we don't support yet.
1226 * Even when we do support it, doing sparse on external memory sounds
1227 * sketchy. Also, just disallowing flags is the safe option.
1229 if (pExternalBufferInfo
->flags
)
1232 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1234 switch (pExternalBufferInfo
->handleType
) {
1235 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
:
1236 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1237 pExternalBufferProperties
->externalMemoryProperties
= prime_fd_props
;
1239 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1240 pExternalBufferProperties
->externalMemoryProperties
= userptr_props
;
1242 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
:
1243 if (physical_device
->supported_extensions
.ANDROID_external_memory_android_hardware_buffer
) {
1244 pExternalBufferProperties
->externalMemoryProperties
= android_buffer_props
;
1247 /* fallthrough if ahw not supported */
1253 /* From the Vulkan 1.1.113 spec:
1255 * compatibleHandleTypes must include at least handleType.
1257 pExternalBufferProperties
->externalMemoryProperties
=
1258 (VkExternalMemoryProperties
) {
1259 .compatibleHandleTypes
= pExternalBufferInfo
->handleType
,
1263 VkResult
anv_CreateSamplerYcbcrConversion(
1265 const VkSamplerYcbcrConversionCreateInfo
* pCreateInfo
,
1266 const VkAllocationCallbacks
* pAllocator
,
1267 VkSamplerYcbcrConversion
* pYcbcrConversion
)
1269 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1270 struct anv_ycbcr_conversion
*conversion
;
1272 /* Search for VkExternalFormatANDROID and resolve the format. */
1273 struct anv_format
*ext_format
= NULL
;
1274 const VkExternalFormatANDROID
*ext_info
=
1275 vk_find_struct_const(pCreateInfo
->pNext
, EXTERNAL_FORMAT_ANDROID
);
1277 uint64_t format
= ext_info
? ext_info
->externalFormat
: 0;
1279 assert(pCreateInfo
->format
== VK_FORMAT_UNDEFINED
);
1280 ext_format
= (struct anv_format
*) (uintptr_t) format
;
1283 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO
);
1285 conversion
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*conversion
), 8,
1286 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1288 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1290 memset(conversion
, 0, sizeof(*conversion
));
1292 conversion
->format
= anv_get_format(pCreateInfo
->format
);
1293 conversion
->ycbcr_model
= pCreateInfo
->ycbcrModel
;
1294 conversion
->ycbcr_range
= pCreateInfo
->ycbcrRange
;
1296 /* The Vulkan 1.1.95 spec says "When creating an external format conversion,
1297 * the value of components if ignored."
1300 conversion
->mapping
[0] = pCreateInfo
->components
.r
;
1301 conversion
->mapping
[1] = pCreateInfo
->components
.g
;
1302 conversion
->mapping
[2] = pCreateInfo
->components
.b
;
1303 conversion
->mapping
[3] = pCreateInfo
->components
.a
;
1306 conversion
->chroma_offsets
[0] = pCreateInfo
->xChromaOffset
;
1307 conversion
->chroma_offsets
[1] = pCreateInfo
->yChromaOffset
;
1308 conversion
->chroma_filter
= pCreateInfo
->chromaFilter
;
1310 /* Setup external format. */
1312 conversion
->format
= ext_format
;
1314 bool has_chroma_subsampled
= false;
1315 for (uint32_t p
= 0; p
< conversion
->format
->n_planes
; p
++) {
1316 if (conversion
->format
->planes
[p
].has_chroma
&&
1317 (conversion
->format
->planes
[p
].denominator_scales
[0] > 1 ||
1318 conversion
->format
->planes
[p
].denominator_scales
[1] > 1))
1319 has_chroma_subsampled
= true;
1321 conversion
->chroma_reconstruction
= has_chroma_subsampled
&&
1322 (conversion
->chroma_offsets
[0] == VK_CHROMA_LOCATION_COSITED_EVEN
||
1323 conversion
->chroma_offsets
[1] == VK_CHROMA_LOCATION_COSITED_EVEN
);
1325 *pYcbcrConversion
= anv_ycbcr_conversion_to_handle(conversion
);
1330 void anv_DestroySamplerYcbcrConversion(
1332 VkSamplerYcbcrConversion YcbcrConversion
,
1333 const VkAllocationCallbacks
* pAllocator
)
1335 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1336 ANV_FROM_HANDLE(anv_ycbcr_conversion
, conversion
, YcbcrConversion
);
1341 vk_free2(&device
->alloc
, pAllocator
, conversion
);