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 "vk_enum_to_str.h"
26 #include "vk_format_info.h"
30 * gcc-4 and earlier don't allow compound literals where a constant
31 * is required in -std=c99/gnu99 mode, so we can't use ISL_SWIZZLE()
32 * here. -std=c89/gnu89 would allow it, but we depend on c99 features
33 * so using -std=c89/gnu89 is not an option. Starting from gcc-5
34 * compound literals can also be considered constant in -std=c99/gnu99
37 #define _ISL_SWIZZLE(r, g, b, a) { \
38 ISL_CHANNEL_SELECT_##r, \
39 ISL_CHANNEL_SELECT_##g, \
40 ISL_CHANNEL_SELECT_##b, \
41 ISL_CHANNEL_SELECT_##a, \
44 #define RGBA _ISL_SWIZZLE(RED, GREEN, BLUE, ALPHA)
45 #define BGRA _ISL_SWIZZLE(BLUE, GREEN, RED, ALPHA)
46 #define RGB1 _ISL_SWIZZLE(RED, GREEN, BLUE, ONE)
48 #define swiz_fmt1(__vk_fmt, __hw_fmt, __swizzle) \
49 [VK_ENUM_OFFSET(__vk_fmt)] = { \
51 { .isl_format = __hw_fmt, .swizzle = __swizzle, \
52 .denominator_scales = { 1, 1, }, \
58 #define fmt1(__vk_fmt, __hw_fmt) \
59 swiz_fmt1(__vk_fmt, __hw_fmt, RGBA)
61 #define fmt2(__vk_fmt, __fmt1, __fmt2) \
62 [VK_ENUM_OFFSET(__vk_fmt)] = { \
64 { .isl_format = __fmt1, \
66 .denominator_scales = { 1, 1, }, \
68 { .isl_format = __fmt2, \
70 .denominator_scales = { 1, 1, }, \
76 #define fmt_unsupported(__vk_fmt) \
77 [VK_ENUM_OFFSET(__vk_fmt)] = { \
79 { .isl_format = ISL_FORMAT_UNSUPPORTED, }, \
83 #define y_plane(__hw_fmt, __swizzle, __ycbcr_swizzle, dhs, dvs) \
84 { .isl_format = __hw_fmt, \
85 .swizzle = __swizzle, \
86 .ycbcr_swizzle = __ycbcr_swizzle, \
87 .denominator_scales = { dhs, dvs, }, \
88 .has_chroma = false, \
91 #define chroma_plane(__hw_fmt, __swizzle, __ycbcr_swizzle, dhs, dvs) \
92 { .isl_format = __hw_fmt, \
93 .swizzle = __swizzle, \
94 .ycbcr_swizzle = __ycbcr_swizzle, \
95 .denominator_scales = { dhs, dvs, }, \
99 #define ycbcr_fmt(__vk_fmt, __n_planes, ...) \
100 [VK_ENUM_OFFSET(__vk_fmt)] = { \
104 .n_planes = __n_planes, \
108 /* HINT: For array formats, the ISL name should match the VK name. For
109 * packed formats, they should have the channels in reverse order from each
110 * other. The reason for this is that, for packed formats, the ISL (and
111 * bspec) names are in LSB -> MSB order while VK formats are MSB -> LSB.
113 static const struct anv_format main_formats
[] = {
114 fmt_unsupported(VK_FORMAT_UNDEFINED
),
115 fmt_unsupported(VK_FORMAT_R4G4_UNORM_PACK8
),
116 fmt1(VK_FORMAT_R4G4B4A4_UNORM_PACK16
, ISL_FORMAT_A4B4G4R4_UNORM
),
117 swiz_fmt1(VK_FORMAT_B4G4R4A4_UNORM_PACK16
, ISL_FORMAT_A4B4G4R4_UNORM
, BGRA
),
118 fmt1(VK_FORMAT_R5G6B5_UNORM_PACK16
, ISL_FORMAT_B5G6R5_UNORM
),
119 swiz_fmt1(VK_FORMAT_B5G6R5_UNORM_PACK16
, ISL_FORMAT_B5G6R5_UNORM
, BGRA
),
120 fmt1(VK_FORMAT_R5G5B5A1_UNORM_PACK16
, ISL_FORMAT_A1B5G5R5_UNORM
),
121 fmt_unsupported(VK_FORMAT_B5G5R5A1_UNORM_PACK16
),
122 fmt1(VK_FORMAT_A1R5G5B5_UNORM_PACK16
, ISL_FORMAT_B5G5R5A1_UNORM
),
123 fmt1(VK_FORMAT_R8_UNORM
, ISL_FORMAT_R8_UNORM
),
124 fmt1(VK_FORMAT_R8_SNORM
, ISL_FORMAT_R8_SNORM
),
125 fmt1(VK_FORMAT_R8_USCALED
, ISL_FORMAT_R8_USCALED
),
126 fmt1(VK_FORMAT_R8_SSCALED
, ISL_FORMAT_R8_SSCALED
),
127 fmt1(VK_FORMAT_R8_UINT
, ISL_FORMAT_R8_UINT
),
128 fmt1(VK_FORMAT_R8_SINT
, ISL_FORMAT_R8_SINT
),
129 swiz_fmt1(VK_FORMAT_R8_SRGB
, ISL_FORMAT_L8_UNORM_SRGB
,
130 _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ONE
)),
131 fmt1(VK_FORMAT_R8G8_UNORM
, ISL_FORMAT_R8G8_UNORM
),
132 fmt1(VK_FORMAT_R8G8_SNORM
, ISL_FORMAT_R8G8_SNORM
),
133 fmt1(VK_FORMAT_R8G8_USCALED
, ISL_FORMAT_R8G8_USCALED
),
134 fmt1(VK_FORMAT_R8G8_SSCALED
, ISL_FORMAT_R8G8_SSCALED
),
135 fmt1(VK_FORMAT_R8G8_UINT
, ISL_FORMAT_R8G8_UINT
),
136 fmt1(VK_FORMAT_R8G8_SINT
, ISL_FORMAT_R8G8_SINT
),
137 fmt_unsupported(VK_FORMAT_R8G8_SRGB
), /* L8A8_UNORM_SRGB */
138 fmt1(VK_FORMAT_R8G8B8_UNORM
, ISL_FORMAT_R8G8B8_UNORM
),
139 fmt1(VK_FORMAT_R8G8B8_SNORM
, ISL_FORMAT_R8G8B8_SNORM
),
140 fmt1(VK_FORMAT_R8G8B8_USCALED
, ISL_FORMAT_R8G8B8_USCALED
),
141 fmt1(VK_FORMAT_R8G8B8_SSCALED
, ISL_FORMAT_R8G8B8_SSCALED
),
142 fmt1(VK_FORMAT_R8G8B8_UINT
, ISL_FORMAT_R8G8B8_UINT
),
143 fmt1(VK_FORMAT_R8G8B8_SINT
, ISL_FORMAT_R8G8B8_SINT
),
144 fmt1(VK_FORMAT_R8G8B8_SRGB
, ISL_FORMAT_R8G8B8_UNORM_SRGB
),
145 fmt1(VK_FORMAT_R8G8B8A8_UNORM
, ISL_FORMAT_R8G8B8A8_UNORM
),
146 fmt1(VK_FORMAT_R8G8B8A8_SNORM
, ISL_FORMAT_R8G8B8A8_SNORM
),
147 fmt1(VK_FORMAT_R8G8B8A8_USCALED
, ISL_FORMAT_R8G8B8A8_USCALED
),
148 fmt1(VK_FORMAT_R8G8B8A8_SSCALED
, ISL_FORMAT_R8G8B8A8_SSCALED
),
149 fmt1(VK_FORMAT_R8G8B8A8_UINT
, ISL_FORMAT_R8G8B8A8_UINT
),
150 fmt1(VK_FORMAT_R8G8B8A8_SINT
, ISL_FORMAT_R8G8B8A8_SINT
),
151 fmt1(VK_FORMAT_R8G8B8A8_SRGB
, ISL_FORMAT_R8G8B8A8_UNORM_SRGB
),
152 fmt1(VK_FORMAT_A8B8G8R8_UNORM_PACK32
, ISL_FORMAT_R8G8B8A8_UNORM
),
153 fmt1(VK_FORMAT_A8B8G8R8_SNORM_PACK32
, ISL_FORMAT_R8G8B8A8_SNORM
),
154 fmt1(VK_FORMAT_A8B8G8R8_USCALED_PACK32
, ISL_FORMAT_R8G8B8A8_USCALED
),
155 fmt1(VK_FORMAT_A8B8G8R8_SSCALED_PACK32
, ISL_FORMAT_R8G8B8A8_SSCALED
),
156 fmt1(VK_FORMAT_A8B8G8R8_UINT_PACK32
, ISL_FORMAT_R8G8B8A8_UINT
),
157 fmt1(VK_FORMAT_A8B8G8R8_SINT_PACK32
, ISL_FORMAT_R8G8B8A8_SINT
),
158 fmt1(VK_FORMAT_A8B8G8R8_SRGB_PACK32
, ISL_FORMAT_R8G8B8A8_UNORM_SRGB
),
159 fmt1(VK_FORMAT_A2R10G10B10_UNORM_PACK32
, ISL_FORMAT_B10G10R10A2_UNORM
),
160 fmt1(VK_FORMAT_A2R10G10B10_SNORM_PACK32
, ISL_FORMAT_B10G10R10A2_SNORM
),
161 fmt1(VK_FORMAT_A2R10G10B10_USCALED_PACK32
, ISL_FORMAT_B10G10R10A2_USCALED
),
162 fmt1(VK_FORMAT_A2R10G10B10_SSCALED_PACK32
, ISL_FORMAT_B10G10R10A2_SSCALED
),
163 fmt1(VK_FORMAT_A2R10G10B10_UINT_PACK32
, ISL_FORMAT_B10G10R10A2_UINT
),
164 fmt1(VK_FORMAT_A2R10G10B10_SINT_PACK32
, ISL_FORMAT_B10G10R10A2_SINT
),
165 fmt1(VK_FORMAT_A2B10G10R10_UNORM_PACK32
, ISL_FORMAT_R10G10B10A2_UNORM
),
166 fmt1(VK_FORMAT_A2B10G10R10_SNORM_PACK32
, ISL_FORMAT_R10G10B10A2_SNORM
),
167 fmt1(VK_FORMAT_A2B10G10R10_USCALED_PACK32
, ISL_FORMAT_R10G10B10A2_USCALED
),
168 fmt1(VK_FORMAT_A2B10G10R10_SSCALED_PACK32
, ISL_FORMAT_R10G10B10A2_SSCALED
),
169 fmt1(VK_FORMAT_A2B10G10R10_UINT_PACK32
, ISL_FORMAT_R10G10B10A2_UINT
),
170 fmt1(VK_FORMAT_A2B10G10R10_SINT_PACK32
, ISL_FORMAT_R10G10B10A2_SINT
),
171 fmt1(VK_FORMAT_R16_UNORM
, ISL_FORMAT_R16_UNORM
),
172 fmt1(VK_FORMAT_R16_SNORM
, ISL_FORMAT_R16_SNORM
),
173 fmt1(VK_FORMAT_R16_USCALED
, ISL_FORMAT_R16_USCALED
),
174 fmt1(VK_FORMAT_R16_SSCALED
, ISL_FORMAT_R16_SSCALED
),
175 fmt1(VK_FORMAT_R16_UINT
, ISL_FORMAT_R16_UINT
),
176 fmt1(VK_FORMAT_R16_SINT
, ISL_FORMAT_R16_SINT
),
177 fmt1(VK_FORMAT_R16_SFLOAT
, ISL_FORMAT_R16_FLOAT
),
178 fmt1(VK_FORMAT_R16G16_UNORM
, ISL_FORMAT_R16G16_UNORM
),
179 fmt1(VK_FORMAT_R16G16_SNORM
, ISL_FORMAT_R16G16_SNORM
),
180 fmt1(VK_FORMAT_R16G16_USCALED
, ISL_FORMAT_R16G16_USCALED
),
181 fmt1(VK_FORMAT_R16G16_SSCALED
, ISL_FORMAT_R16G16_SSCALED
),
182 fmt1(VK_FORMAT_R16G16_UINT
, ISL_FORMAT_R16G16_UINT
),
183 fmt1(VK_FORMAT_R16G16_SINT
, ISL_FORMAT_R16G16_SINT
),
184 fmt1(VK_FORMAT_R16G16_SFLOAT
, ISL_FORMAT_R16G16_FLOAT
),
185 fmt1(VK_FORMAT_R16G16B16_UNORM
, ISL_FORMAT_R16G16B16_UNORM
),
186 fmt1(VK_FORMAT_R16G16B16_SNORM
, ISL_FORMAT_R16G16B16_SNORM
),
187 fmt1(VK_FORMAT_R16G16B16_USCALED
, ISL_FORMAT_R16G16B16_USCALED
),
188 fmt1(VK_FORMAT_R16G16B16_SSCALED
, ISL_FORMAT_R16G16B16_SSCALED
),
189 fmt1(VK_FORMAT_R16G16B16_UINT
, ISL_FORMAT_R16G16B16_UINT
),
190 fmt1(VK_FORMAT_R16G16B16_SINT
, ISL_FORMAT_R16G16B16_SINT
),
191 fmt1(VK_FORMAT_R16G16B16_SFLOAT
, ISL_FORMAT_R16G16B16_FLOAT
),
192 fmt1(VK_FORMAT_R16G16B16A16_UNORM
, ISL_FORMAT_R16G16B16A16_UNORM
),
193 fmt1(VK_FORMAT_R16G16B16A16_SNORM
, ISL_FORMAT_R16G16B16A16_SNORM
),
194 fmt1(VK_FORMAT_R16G16B16A16_USCALED
, ISL_FORMAT_R16G16B16A16_USCALED
),
195 fmt1(VK_FORMAT_R16G16B16A16_SSCALED
, ISL_FORMAT_R16G16B16A16_SSCALED
),
196 fmt1(VK_FORMAT_R16G16B16A16_UINT
, ISL_FORMAT_R16G16B16A16_UINT
),
197 fmt1(VK_FORMAT_R16G16B16A16_SINT
, ISL_FORMAT_R16G16B16A16_SINT
),
198 fmt1(VK_FORMAT_R16G16B16A16_SFLOAT
, ISL_FORMAT_R16G16B16A16_FLOAT
),
199 fmt1(VK_FORMAT_R32_UINT
, ISL_FORMAT_R32_UINT
),
200 fmt1(VK_FORMAT_R32_SINT
, ISL_FORMAT_R32_SINT
),
201 fmt1(VK_FORMAT_R32_SFLOAT
, ISL_FORMAT_R32_FLOAT
),
202 fmt1(VK_FORMAT_R32G32_UINT
, ISL_FORMAT_R32G32_UINT
),
203 fmt1(VK_FORMAT_R32G32_SINT
, ISL_FORMAT_R32G32_SINT
),
204 fmt1(VK_FORMAT_R32G32_SFLOAT
, ISL_FORMAT_R32G32_FLOAT
),
205 fmt1(VK_FORMAT_R32G32B32_UINT
, ISL_FORMAT_R32G32B32_UINT
),
206 fmt1(VK_FORMAT_R32G32B32_SINT
, ISL_FORMAT_R32G32B32_SINT
),
207 fmt1(VK_FORMAT_R32G32B32_SFLOAT
, ISL_FORMAT_R32G32B32_FLOAT
),
208 fmt1(VK_FORMAT_R32G32B32A32_UINT
, ISL_FORMAT_R32G32B32A32_UINT
),
209 fmt1(VK_FORMAT_R32G32B32A32_SINT
, ISL_FORMAT_R32G32B32A32_SINT
),
210 fmt1(VK_FORMAT_R32G32B32A32_SFLOAT
, ISL_FORMAT_R32G32B32A32_FLOAT
),
211 fmt1(VK_FORMAT_R64_UINT
, ISL_FORMAT_R64_PASSTHRU
),
212 fmt1(VK_FORMAT_R64_SINT
, ISL_FORMAT_R64_PASSTHRU
),
213 fmt1(VK_FORMAT_R64_SFLOAT
, ISL_FORMAT_R64_PASSTHRU
),
214 fmt1(VK_FORMAT_R64G64_UINT
, ISL_FORMAT_R64G64_PASSTHRU
),
215 fmt1(VK_FORMAT_R64G64_SINT
, ISL_FORMAT_R64G64_PASSTHRU
),
216 fmt1(VK_FORMAT_R64G64_SFLOAT
, ISL_FORMAT_R64G64_PASSTHRU
),
217 fmt1(VK_FORMAT_R64G64B64_UINT
, ISL_FORMAT_R64G64B64_PASSTHRU
),
218 fmt1(VK_FORMAT_R64G64B64_SINT
, ISL_FORMAT_R64G64B64_PASSTHRU
),
219 fmt1(VK_FORMAT_R64G64B64_SFLOAT
, ISL_FORMAT_R64G64B64_PASSTHRU
),
220 fmt1(VK_FORMAT_R64G64B64A64_UINT
, ISL_FORMAT_R64G64B64A64_PASSTHRU
),
221 fmt1(VK_FORMAT_R64G64B64A64_SINT
, ISL_FORMAT_R64G64B64A64_PASSTHRU
),
222 fmt1(VK_FORMAT_R64G64B64A64_SFLOAT
, ISL_FORMAT_R64G64B64A64_PASSTHRU
),
223 fmt1(VK_FORMAT_B10G11R11_UFLOAT_PACK32
, ISL_FORMAT_R11G11B10_FLOAT
),
224 fmt1(VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
, ISL_FORMAT_R9G9B9E5_SHAREDEXP
),
226 fmt1(VK_FORMAT_D16_UNORM
, ISL_FORMAT_R16_UNORM
),
227 fmt1(VK_FORMAT_X8_D24_UNORM_PACK32
, ISL_FORMAT_R24_UNORM_X8_TYPELESS
),
228 fmt1(VK_FORMAT_D32_SFLOAT
, ISL_FORMAT_R32_FLOAT
),
229 fmt1(VK_FORMAT_S8_UINT
, ISL_FORMAT_R8_UINT
),
230 fmt_unsupported(VK_FORMAT_D16_UNORM_S8_UINT
),
231 fmt2(VK_FORMAT_D24_UNORM_S8_UINT
, ISL_FORMAT_R24_UNORM_X8_TYPELESS
, ISL_FORMAT_R8_UINT
),
232 fmt2(VK_FORMAT_D32_SFLOAT_S8_UINT
, ISL_FORMAT_R32_FLOAT
, ISL_FORMAT_R8_UINT
),
234 swiz_fmt1(VK_FORMAT_BC1_RGB_UNORM_BLOCK
, ISL_FORMAT_BC1_UNORM
, RGB1
),
235 swiz_fmt1(VK_FORMAT_BC1_RGB_SRGB_BLOCK
, ISL_FORMAT_BC1_UNORM_SRGB
, RGB1
),
236 fmt1(VK_FORMAT_BC1_RGBA_UNORM_BLOCK
, ISL_FORMAT_BC1_UNORM
),
237 fmt1(VK_FORMAT_BC1_RGBA_SRGB_BLOCK
, ISL_FORMAT_BC1_UNORM_SRGB
),
238 fmt1(VK_FORMAT_BC2_UNORM_BLOCK
, ISL_FORMAT_BC2_UNORM
),
239 fmt1(VK_FORMAT_BC2_SRGB_BLOCK
, ISL_FORMAT_BC2_UNORM_SRGB
),
240 fmt1(VK_FORMAT_BC3_UNORM_BLOCK
, ISL_FORMAT_BC3_UNORM
),
241 fmt1(VK_FORMAT_BC3_SRGB_BLOCK
, ISL_FORMAT_BC3_UNORM_SRGB
),
242 fmt1(VK_FORMAT_BC4_UNORM_BLOCK
, ISL_FORMAT_BC4_UNORM
),
243 fmt1(VK_FORMAT_BC4_SNORM_BLOCK
, ISL_FORMAT_BC4_SNORM
),
244 fmt1(VK_FORMAT_BC5_UNORM_BLOCK
, ISL_FORMAT_BC5_UNORM
),
245 fmt1(VK_FORMAT_BC5_SNORM_BLOCK
, ISL_FORMAT_BC5_SNORM
),
246 fmt1(VK_FORMAT_BC6H_UFLOAT_BLOCK
, ISL_FORMAT_BC6H_UF16
),
247 fmt1(VK_FORMAT_BC6H_SFLOAT_BLOCK
, ISL_FORMAT_BC6H_SF16
),
248 fmt1(VK_FORMAT_BC7_UNORM_BLOCK
, ISL_FORMAT_BC7_UNORM
),
249 fmt1(VK_FORMAT_BC7_SRGB_BLOCK
, ISL_FORMAT_BC7_UNORM_SRGB
),
250 fmt1(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
, ISL_FORMAT_ETC2_RGB8
),
251 fmt1(VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK
, ISL_FORMAT_ETC2_SRGB8
),
252 fmt1(VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK
, ISL_FORMAT_ETC2_RGB8_PTA
),
253 fmt1(VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK
, ISL_FORMAT_ETC2_SRGB8_PTA
),
254 fmt1(VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK
, ISL_FORMAT_ETC2_EAC_RGBA8
),
255 fmt1(VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK
, ISL_FORMAT_ETC2_EAC_SRGB8_A8
),
256 fmt1(VK_FORMAT_EAC_R11_UNORM_BLOCK
, ISL_FORMAT_EAC_R11
),
257 fmt1(VK_FORMAT_EAC_R11_SNORM_BLOCK
, ISL_FORMAT_EAC_SIGNED_R11
),
258 fmt1(VK_FORMAT_EAC_R11G11_UNORM_BLOCK
, ISL_FORMAT_EAC_RG11
),
259 fmt1(VK_FORMAT_EAC_R11G11_SNORM_BLOCK
, ISL_FORMAT_EAC_SIGNED_RG11
),
260 fmt1(VK_FORMAT_ASTC_4x4_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_4X4_U8SRGB
),
261 fmt1(VK_FORMAT_ASTC_5x4_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_5X4_U8SRGB
),
262 fmt1(VK_FORMAT_ASTC_5x5_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_5X5_U8SRGB
),
263 fmt1(VK_FORMAT_ASTC_6x5_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_6X5_U8SRGB
),
264 fmt1(VK_FORMAT_ASTC_6x6_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_6X6_U8SRGB
),
265 fmt1(VK_FORMAT_ASTC_8x5_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X5_U8SRGB
),
266 fmt1(VK_FORMAT_ASTC_8x6_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X6_U8SRGB
),
267 fmt1(VK_FORMAT_ASTC_8x8_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X8_U8SRGB
),
268 fmt1(VK_FORMAT_ASTC_10x5_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X5_U8SRGB
),
269 fmt1(VK_FORMAT_ASTC_10x6_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X6_U8SRGB
),
270 fmt1(VK_FORMAT_ASTC_10x8_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X8_U8SRGB
),
271 fmt1(VK_FORMAT_ASTC_10x10_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X10_U8SRGB
),
272 fmt1(VK_FORMAT_ASTC_12x10_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_12X10_U8SRGB
),
273 fmt1(VK_FORMAT_ASTC_12x12_SRGB_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_12X12_U8SRGB
),
274 fmt1(VK_FORMAT_ASTC_4x4_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_4X4_FLT16
),
275 fmt1(VK_FORMAT_ASTC_5x4_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_5X4_FLT16
),
276 fmt1(VK_FORMAT_ASTC_5x5_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_5X5_FLT16
),
277 fmt1(VK_FORMAT_ASTC_6x5_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_6X5_FLT16
),
278 fmt1(VK_FORMAT_ASTC_6x6_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_6X6_FLT16
),
279 fmt1(VK_FORMAT_ASTC_8x5_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X5_FLT16
),
280 fmt1(VK_FORMAT_ASTC_8x6_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X6_FLT16
),
281 fmt1(VK_FORMAT_ASTC_8x8_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_8X8_FLT16
),
282 fmt1(VK_FORMAT_ASTC_10x5_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X5_FLT16
),
283 fmt1(VK_FORMAT_ASTC_10x6_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X6_FLT16
),
284 fmt1(VK_FORMAT_ASTC_10x8_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X8_FLT16
),
285 fmt1(VK_FORMAT_ASTC_10x10_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_10X10_FLT16
),
286 fmt1(VK_FORMAT_ASTC_12x10_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_12X10_FLT16
),
287 fmt1(VK_FORMAT_ASTC_12x12_UNORM_BLOCK
, ISL_FORMAT_ASTC_LDR_2D_12X12_FLT16
),
288 fmt_unsupported(VK_FORMAT_B8G8R8_UNORM
),
289 fmt_unsupported(VK_FORMAT_B8G8R8_SNORM
),
290 fmt_unsupported(VK_FORMAT_B8G8R8_USCALED
),
291 fmt_unsupported(VK_FORMAT_B8G8R8_SSCALED
),
292 fmt_unsupported(VK_FORMAT_B8G8R8_UINT
),
293 fmt_unsupported(VK_FORMAT_B8G8R8_SINT
),
294 fmt_unsupported(VK_FORMAT_B8G8R8_SRGB
),
295 fmt1(VK_FORMAT_B8G8R8A8_UNORM
, ISL_FORMAT_B8G8R8A8_UNORM
),
296 fmt_unsupported(VK_FORMAT_B8G8R8A8_SNORM
),
297 fmt_unsupported(VK_FORMAT_B8G8R8A8_USCALED
),
298 fmt_unsupported(VK_FORMAT_B8G8R8A8_SSCALED
),
299 fmt_unsupported(VK_FORMAT_B8G8R8A8_UINT
),
300 fmt_unsupported(VK_FORMAT_B8G8R8A8_SINT
),
301 fmt1(VK_FORMAT_B8G8R8A8_SRGB
, ISL_FORMAT_B8G8R8A8_UNORM_SRGB
),
304 static const struct anv_format ycbcr_formats
[] = {
305 ycbcr_fmt(VK_FORMAT_G8B8G8R8_422_UNORM_KHR
, 1,
306 y_plane(ISL_FORMAT_YCRCB_SWAPUV
, RGBA
, _ISL_SWIZZLE(BLUE
, GREEN
, RED
, ZERO
), 1, 1)),
307 ycbcr_fmt(VK_FORMAT_B8G8R8G8_422_UNORM_KHR
, 1,
308 y_plane(ISL_FORMAT_YCRCB_SWAPUVY
, RGBA
, _ISL_SWIZZLE(BLUE
, GREEN
, RED
, ZERO
), 1, 1)),
309 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR
, 3,
310 y_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
311 chroma_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 2, 2),
312 chroma_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 2, 2)),
313 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR
, 2,
314 y_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
315 chroma_plane(ISL_FORMAT_R8G8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, RED
, ZERO
, ZERO
), 2, 2)),
316 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR
, 3,
317 y_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
318 chroma_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 2, 1),
319 chroma_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 2, 1)),
320 ycbcr_fmt(VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR
, 2,
321 y_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
322 chroma_plane(ISL_FORMAT_R8G8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, RED
, ZERO
, ZERO
), 2, 1)),
323 ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR
, 3,
324 y_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
325 chroma_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 1, 1),
326 chroma_plane(ISL_FORMAT_R8_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 1, 1)),
328 fmt_unsupported(VK_FORMAT_R10X6_UNORM_PACK16_KHR
),
329 fmt_unsupported(VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR
),
330 fmt_unsupported(VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR
),
331 fmt_unsupported(VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR
),
332 fmt_unsupported(VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR
),
333 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR
),
334 fmt_unsupported(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR
),
335 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR
),
336 fmt_unsupported(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR
),
337 fmt_unsupported(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR
),
338 fmt_unsupported(VK_FORMAT_R12X4_UNORM_PACK16_KHR
),
339 fmt_unsupported(VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR
),
340 fmt_unsupported(VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR
),
341 fmt_unsupported(VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR
),
342 fmt_unsupported(VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR
),
343 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR
),
344 fmt_unsupported(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR
),
345 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR
),
346 fmt_unsupported(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR
),
347 fmt_unsupported(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR
),
348 /* TODO: it is possible to enable the following 2 formats, but that
349 * requires further refactoring of how we handle multiplanar formats.
351 fmt_unsupported(VK_FORMAT_G16B16G16R16_422_UNORM_KHR
),
352 fmt_unsupported(VK_FORMAT_B16G16R16G16_422_UNORM_KHR
),
354 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR
, 3,
355 y_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
356 chroma_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 2, 2),
357 chroma_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 2, 2)),
358 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR
, 2,
359 y_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
360 chroma_plane(ISL_FORMAT_R16G16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, RED
, ZERO
, ZERO
), 2, 2)),
361 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR
, 3,
362 y_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
363 chroma_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 2, 1),
364 chroma_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 2, 1)),
365 ycbcr_fmt(VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR
, 2,
366 y_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
367 chroma_plane(ISL_FORMAT_R16G16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, RED
, ZERO
, ZERO
), 2, 1)),
368 ycbcr_fmt(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR
, 3,
369 y_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(GREEN
, ZERO
, ZERO
, ZERO
), 1, 1),
370 chroma_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(BLUE
, ZERO
, ZERO
, ZERO
), 1, 1),
371 chroma_plane(ISL_FORMAT_R16_UNORM
, RGBA
, _ISL_SWIZZLE(RED
, ZERO
, ZERO
, ZERO
), 1, 1)),
379 static const struct {
380 const struct anv_format
*formats
;
383 [0] = { .formats
= main_formats
,
384 .n_formats
= ARRAY_SIZE(main_formats
), },
385 [_VK_KHR_sampler_ycbcr_conversion_number
] = { .formats
= ycbcr_formats
,
386 .n_formats
= ARRAY_SIZE(ycbcr_formats
), },
389 const struct anv_format
*
390 anv_get_format(VkFormat vk_format
)
392 uint32_t enum_offset
= VK_ENUM_OFFSET(vk_format
);
393 uint32_t ext_number
= VK_ENUM_EXTENSION(vk_format
);
395 if (ext_number
>= ARRAY_SIZE(anv_formats
) ||
396 enum_offset
>= anv_formats
[ext_number
].n_formats
)
399 const struct anv_format
*format
=
400 &anv_formats
[ext_number
].formats
[enum_offset
];
401 if (format
->planes
[0].isl_format
== ISL_FORMAT_UNSUPPORTED
)
408 * Exactly one bit must be set in \a aspect.
410 struct anv_format_plane
411 anv_get_format_plane(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
412 VkImageAspectFlagBits aspect
, VkImageTiling tiling
)
414 const struct anv_format
*format
= anv_get_format(vk_format
);
415 struct anv_format_plane plane_format
= {
416 .isl_format
= ISL_FORMAT_UNSUPPORTED
,
422 uint32_t plane
= anv_image_aspect_to_plane(vk_format_aspects(vk_format
), aspect
);
423 plane_format
= format
->planes
[plane
];
424 if (plane_format
.isl_format
== ISL_FORMAT_UNSUPPORTED
)
427 if (aspect
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
428 assert(vk_format_aspects(vk_format
) &
429 (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
));
433 assert((aspect
& ~VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) == 0);
435 const struct isl_format_layout
*isl_layout
=
436 isl_format_get_layout(plane_format
.isl_format
);
438 if (tiling
== VK_IMAGE_TILING_OPTIMAL
&&
439 !util_is_power_of_two(isl_layout
->bpb
)) {
440 /* Tiled formats *must* be power-of-two because we need up upload
441 * them with the render pipeline. For 3-channel formats, we fix
442 * this by switching them over to RGBX or RGBA formats under the
445 enum isl_format rgbx
= isl_format_rgb_to_rgbx(plane_format
.isl_format
);
446 if (rgbx
!= ISL_FORMAT_UNSUPPORTED
&&
447 isl_format_supports_rendering(devinfo
, rgbx
)) {
448 plane_format
.isl_format
= rgbx
;
450 plane_format
.isl_format
=
451 isl_format_rgb_to_rgba(plane_format
.isl_format
);
452 plane_format
.swizzle
= ISL_SWIZZLE(RED
, GREEN
, BLUE
, ONE
);
456 /* The B4G4R4A4 format isn't available prior to Broadwell so we have to fall
457 * back to a format with a more complex swizzle.
459 if (vk_format
== VK_FORMAT_B4G4R4A4_UNORM_PACK16
&& devinfo
->gen
< 8) {
460 plane_format
.isl_format
= ISL_FORMAT_B4G4R4A4_UNORM
;
461 plane_format
.swizzle
= ISL_SWIZZLE(GREEN
, RED
, ALPHA
, BLUE
);
467 // Format capabilities
469 static VkFormatFeatureFlags
470 get_image_format_properties(const struct gen_device_info
*devinfo
,
472 const struct anv_format
*anv_format
,
473 VkImageTiling vk_tiling
)
475 VkFormatFeatureFlags flags
= 0;
477 if (anv_format
== NULL
)
480 const VkImageAspectFlags aspects
= vk_format_aspects(vk_format
);
482 if (aspects
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
483 if (vk_tiling
== VK_IMAGE_TILING_LINEAR
)
486 flags
|= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
;
488 if (aspects
== VK_IMAGE_ASPECT_DEPTH_BIT
|| devinfo
->gen
>= 8)
489 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
;
491 flags
|= VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
492 VK_FORMAT_FEATURE_BLIT_DST_BIT
|
493 VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR
|
494 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR
;
499 const struct anv_format_plane plane_format
=
500 anv_get_format_plane(devinfo
, vk_format
, VK_IMAGE_ASPECT_COLOR_BIT
,
503 if (plane_format
.isl_format
== ISL_FORMAT_UNSUPPORTED
)
506 struct anv_format_plane base_plane_format
= plane_format
;
507 if (vk_tiling
== VK_IMAGE_TILING_OPTIMAL
) {
508 base_plane_format
= anv_get_format_plane(devinfo
, vk_format
,
509 VK_IMAGE_ASPECT_COLOR_BIT
,
510 VK_IMAGE_TILING_LINEAR
);
513 enum isl_format base_isl_format
= base_plane_format
.isl_format
;
515 /* ASTC textures must be in Y-tiled memory */
516 if (vk_tiling
== VK_IMAGE_TILING_LINEAR
&&
517 isl_format_get_layout(plane_format
.isl_format
)->txc
== ISL_TXC_ASTC
)
520 if (isl_format_supports_sampling(devinfo
, plane_format
.isl_format
)) {
521 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
522 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
524 if (isl_format_supports_filtering(devinfo
, plane_format
.isl_format
))
525 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
528 /* We can render to swizzled formats. However, if the alpha channel is
529 * moved, then blending won't work correctly. The PRM tells us
530 * straight-up not to render to such a surface.
532 if (isl_format_supports_rendering(devinfo
, plane_format
.isl_format
) &&
533 plane_format
.swizzle
.a
== ISL_CHANNEL_SELECT_ALPHA
) {
534 flags
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
535 VK_FORMAT_FEATURE_BLIT_DST_BIT
;
537 if (isl_format_supports_alpha_blending(devinfo
, plane_format
.isl_format
))
538 flags
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
541 /* Load/store is determined based on base format. This prevents RGB
542 * formats from showing up as load/store capable.
544 if (isl_is_storage_image_format(base_isl_format
))
545 flags
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
547 if (base_isl_format
== ISL_FORMAT_R32_SINT
||
548 base_isl_format
== ISL_FORMAT_R32_UINT
)
549 flags
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
552 flags
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR
|
553 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR
;
556 /* XXX: We handle 3-channel formats by switching them out for RGBX or
557 * RGBA formats behind-the-scenes. This works fine for textures
558 * because the upload process will fill in the extra channel.
559 * We could also support it for render targets, but it will take
560 * substantially more work and we have enough RGBX formats to handle
561 * what most clients will want.
563 if (vk_tiling
== VK_IMAGE_TILING_OPTIMAL
&&
564 base_isl_format
!= ISL_FORMAT_UNSUPPORTED
&&
565 !util_is_power_of_two(isl_format_layouts
[base_isl_format
].bpb
) &&
566 isl_format_rgb_to_rgbx(base_isl_format
) == ISL_FORMAT_UNSUPPORTED
) {
567 flags
&= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
;
568 flags
&= ~VK_FORMAT_FEATURE_BLIT_DST_BIT
;
571 if (anv_format
->can_ycbcr
) {
572 /* The sampler doesn't have support for mid point when it handles YUV on
575 if (isl_format_is_yuv(anv_format
->planes
[0].isl_format
)) {
576 /* TODO: We've disabled linear implicit reconstruction with the
577 * sampler. The failures show a slightly out of range values on the
578 * bottom left of the sampled image.
580 flags
|= VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT_KHR
;
582 flags
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT_KHR
|
583 VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT_KHR
|
584 VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT_KHR
;
587 /* We can support cosited chroma locations when handle planes with our
588 * own shader snippets.
590 for (unsigned p
= 0; p
< anv_format
->n_planes
; p
++) {
591 if (anv_format
->planes
[p
].denominator_scales
[0] > 1 ||
592 anv_format
->planes
[p
].denominator_scales
[1] > 1) {
593 flags
|= VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT_KHR
;
598 if (anv_format
->n_planes
> 1)
599 flags
|= VK_FORMAT_FEATURE_DISJOINT_BIT_KHR
;
601 const VkFormatFeatureFlags disallowed_ycbcr_image_features
=
602 VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
603 VK_FORMAT_FEATURE_BLIT_DST_BIT
|
604 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
605 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
|
606 VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
608 flags
&= ~disallowed_ycbcr_image_features
;
614 static VkFormatFeatureFlags
615 get_buffer_format_properties(const struct gen_device_info
*devinfo
,
617 const struct anv_format
*anv_format
)
619 VkFormatFeatureFlags flags
= 0;
621 if (anv_format
== NULL
)
624 const enum isl_format isl_format
= anv_format
->planes
[0].isl_format
;
626 if (isl_format
== ISL_FORMAT_UNSUPPORTED
)
629 if (anv_format
->n_planes
> 1)
632 if (anv_format
->can_ycbcr
)
635 if (vk_format_is_depth_or_stencil(vk_format
))
638 if (isl_format_supports_sampling(devinfo
, isl_format
) &&
639 !isl_format_is_compressed(isl_format
))
640 flags
|= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
;
642 if (isl_format_supports_vertex_fetch(devinfo
, isl_format
))
643 flags
|= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
;
645 if (isl_is_storage_image_format(isl_format
))
646 flags
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
;
648 if (isl_format
== ISL_FORMAT_R32_SINT
|| isl_format
== ISL_FORMAT_R32_UINT
)
649 flags
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
;
655 anv_physical_device_get_format_properties(struct anv_physical_device
*physical_device
,
657 VkFormatProperties
*out_properties
)
659 const struct gen_device_info
*devinfo
= &physical_device
->info
;
660 const struct anv_format
*format
= anv_get_format(vk_format
);
661 VkFormatFeatureFlags linear
= 0, tiled
= 0;
663 if (format
== NULL
) {
664 /* Nothing to do here */
666 linear
= get_image_format_properties(&physical_device
->info
, vk_format
,
667 format
, VK_IMAGE_TILING_LINEAR
);
668 tiled
= get_image_format_properties(&physical_device
->info
, vk_format
,
669 format
, VK_IMAGE_TILING_OPTIMAL
);
672 out_properties
->linearTilingFeatures
= linear
;
673 out_properties
->optimalTilingFeatures
= tiled
;
674 out_properties
->bufferFeatures
=
675 get_buffer_format_properties(devinfo
, vk_format
, format
);
679 void anv_GetPhysicalDeviceFormatProperties(
680 VkPhysicalDevice physicalDevice
,
682 VkFormatProperties
* pFormatProperties
)
684 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
686 anv_physical_device_get_format_properties(
692 void anv_GetPhysicalDeviceFormatProperties2KHR(
693 VkPhysicalDevice physicalDevice
,
695 VkFormatProperties2KHR
* pFormatProperties
)
697 anv_GetPhysicalDeviceFormatProperties(physicalDevice
, format
,
698 &pFormatProperties
->formatProperties
);
700 vk_foreach_struct(ext
, pFormatProperties
->pNext
) {
701 switch (ext
->sType
) {
703 anv_debug_ignored_stype(ext
->sType
);
710 anv_get_image_format_properties(
711 struct anv_physical_device
*physical_device
,
712 const VkPhysicalDeviceImageFormatInfo2KHR
*info
,
713 VkImageFormatProperties
*pImageFormatProperties
,
714 VkSamplerYcbcrConversionImageFormatPropertiesKHR
*pYcbcrImageFormatProperties
)
716 VkFormatProperties format_props
;
717 VkFormatFeatureFlags format_feature_flags
;
718 VkExtent3D maxExtent
;
719 uint32_t maxMipLevels
;
720 uint32_t maxArraySize
;
721 VkSampleCountFlags sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
722 const struct anv_format
*format
= anv_get_format(info
->format
);
727 anv_physical_device_get_format_properties(physical_device
, info
->format
,
730 /* Extract the VkFormatFeatureFlags that are relevant for the queried
733 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
) {
734 format_feature_flags
= format_props
.linearTilingFeatures
;
735 } else if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
) {
736 format_feature_flags
= format_props
.optimalTilingFeatures
;
738 unreachable("bad VkImageTiling");
741 switch (info
->type
) {
743 unreachable("bad VkImageType");
744 case VK_IMAGE_TYPE_1D
:
745 maxExtent
.width
= 16384;
746 maxExtent
.height
= 1;
748 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
750 sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
752 case VK_IMAGE_TYPE_2D
:
753 /* FINISHME: Does this really differ for cube maps? The documentation
754 * for RENDER_SURFACE_STATE suggests so.
756 maxExtent
.width
= 16384;
757 maxExtent
.height
= 16384;
759 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
762 case VK_IMAGE_TYPE_3D
:
763 maxExtent
.width
= 2048;
764 maxExtent
.height
= 2048;
765 maxExtent
.depth
= 2048;
766 maxMipLevels
= 12; /* log2(maxWidth) + 1 */
771 /* Our hardware doesn't support 1D compressed textures.
772 * From the SKL PRM, RENDER_SURFACE_STATE::SurfaceFormat:
773 * * This field cannot be a compressed (BC*, DXT*, FXT*, ETC*, EAC*) format
774 * if the Surface Type is SURFTYPE_1D.
775 * * This field cannot be ASTC format if the Surface Type is SURFTYPE_1D.
777 if (info
->type
== VK_IMAGE_TYPE_1D
&&
778 isl_format_is_compressed(format
->planes
[0].isl_format
)) {
782 if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
&&
783 info
->type
== VK_IMAGE_TYPE_2D
&&
784 (format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
785 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) &&
786 !(info
->flags
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
) &&
787 !(info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
)) {
788 sampleCounts
= isl_device_get_sample_counts(&physical_device
->isl_dev
);
791 if (info
->usage
& (VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
792 VK_IMAGE_USAGE_TRANSFER_DST_BIT
)) {
793 /* Accept transfers on anything we can sample from or renderer to. */
794 if (!(format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
795 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
|
796 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
))) {
801 if (info
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
802 if (!(format_feature_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)) {
807 if (info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
808 if (!(format_feature_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)) {
813 if (info
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
814 if (!(format_feature_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)) {
819 if (info
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
) {
820 if (!(format_feature_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) {
825 if (info
->usage
& VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
) {
826 /* Nothing to check. */
829 if (info
->usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
) {
830 /* Ignore this flag because it was removed from the
831 * provisional_I_20150910 header.
835 *pImageFormatProperties
= (VkImageFormatProperties
) {
836 .maxExtent
= maxExtent
,
837 .maxMipLevels
= maxMipLevels
,
838 .maxArrayLayers
= maxArraySize
,
839 .sampleCounts
= sampleCounts
,
841 /* FINISHME: Accurately calculate
842 * VkImageFormatProperties::maxResourceSize.
844 .maxResourceSize
= UINT32_MAX
,
847 if (pYcbcrImageFormatProperties
) {
848 pYcbcrImageFormatProperties
->combinedImageSamplerDescriptorCount
=
855 *pImageFormatProperties
= (VkImageFormatProperties
) {
856 .maxExtent
= { 0, 0, 0 },
860 .maxResourceSize
= 0,
863 return VK_ERROR_FORMAT_NOT_SUPPORTED
;
866 VkResult
anv_GetPhysicalDeviceImageFormatProperties(
867 VkPhysicalDevice physicalDevice
,
870 VkImageTiling tiling
,
871 VkImageUsageFlags usage
,
872 VkImageCreateFlags createFlags
,
873 VkImageFormatProperties
* pImageFormatProperties
)
875 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
877 const VkPhysicalDeviceImageFormatInfo2KHR info
= {
878 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR
,
884 .flags
= createFlags
,
887 return anv_get_image_format_properties(physical_device
, &info
,
888 pImageFormatProperties
, NULL
);
891 static const VkExternalMemoryPropertiesKHR prime_fd_props
= {
892 /* If we can handle external, then we can both import and export it. */
893 .externalMemoryFeatures
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR
|
894 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR
,
895 /* For the moment, let's not support mixing and matching */
896 .exportFromImportedHandleTypes
=
897 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
,
898 .compatibleHandleTypes
=
899 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
,
902 VkResult
anv_GetPhysicalDeviceImageFormatProperties2KHR(
903 VkPhysicalDevice physicalDevice
,
904 const VkPhysicalDeviceImageFormatInfo2KHR
* base_info
,
905 VkImageFormatProperties2KHR
* base_props
)
907 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
908 const VkPhysicalDeviceExternalImageFormatInfoKHR
*external_info
= NULL
;
909 VkExternalImageFormatPropertiesKHR
*external_props
= NULL
;
910 VkSamplerYcbcrConversionImageFormatPropertiesKHR
*ycbcr_props
= NULL
;
913 /* Extract input structs */
914 vk_foreach_struct_const(s
, base_info
->pNext
) {
916 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHR
:
917 external_info
= (const void *) s
;
920 anv_debug_ignored_stype(s
->sType
);
925 /* Extract output structs */
926 vk_foreach_struct(s
, base_props
->pNext
) {
928 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR
:
929 external_props
= (void *) s
;
931 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES_KHR
:
932 ycbcr_props
= (void *) s
;
935 anv_debug_ignored_stype(s
->sType
);
940 result
= anv_get_image_format_properties(physical_device
, base_info
,
941 &base_props
->imageFormatProperties
, ycbcr_props
);
942 if (result
!= VK_SUCCESS
)
945 /* From the Vulkan 1.0.42 spec:
947 * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2KHR will
948 * behave as if VkPhysicalDeviceExternalImageFormatInfoKHR was not
949 * present and VkExternalImageFormatPropertiesKHR will be ignored.
951 if (external_info
&& external_info
->handleType
!= 0) {
952 switch (external_info
->handleType
) {
953 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
955 external_props
->externalMemoryProperties
= prime_fd_props
;
958 /* From the Vulkan 1.0.42 spec:
960 * If handleType is not compatible with the [parameters] specified
961 * in VkPhysicalDeviceImageFormatInfo2KHR, then
962 * vkGetPhysicalDeviceImageFormatProperties2KHR returns
963 * VK_ERROR_FORMAT_NOT_SUPPORTED.
965 result
= vk_errorf(physical_device
->instance
, physical_device
,
966 VK_ERROR_FORMAT_NOT_SUPPORTED
,
967 "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
968 external_info
->handleType
);
976 if (result
== VK_ERROR_FORMAT_NOT_SUPPORTED
) {
977 /* From the Vulkan 1.0.42 spec:
979 * If the combination of parameters to
980 * vkGetPhysicalDeviceImageFormatProperties2KHR is not supported by
981 * the implementation for use in vkCreateImage, then all members of
982 * imageFormatProperties will be filled with zero.
984 base_props
->imageFormatProperties
= (VkImageFormatProperties
) {};
990 void anv_GetPhysicalDeviceSparseImageFormatProperties(
991 VkPhysicalDevice physicalDevice
,
995 VkImageUsageFlags usage
,
996 VkImageTiling tiling
,
997 uint32_t* pNumProperties
,
998 VkSparseImageFormatProperties
* pProperties
)
1000 /* Sparse images are not yet supported. */
1001 *pNumProperties
= 0;
1004 void anv_GetPhysicalDeviceSparseImageFormatProperties2KHR(
1005 VkPhysicalDevice physicalDevice
,
1006 const VkPhysicalDeviceSparseImageFormatInfo2KHR
* pFormatInfo
,
1007 uint32_t* pPropertyCount
,
1008 VkSparseImageFormatProperties2KHR
* pProperties
)
1010 /* Sparse images are not yet supported. */
1011 *pPropertyCount
= 0;
1014 void anv_GetPhysicalDeviceExternalBufferPropertiesKHR(
1015 VkPhysicalDevice physicalDevice
,
1016 const VkPhysicalDeviceExternalBufferInfoKHR
* pExternalBufferInfo
,
1017 VkExternalBufferPropertiesKHR
* pExternalBufferProperties
)
1019 /* The Vulkan 1.0.42 spec says "handleType must be a valid
1020 * VkExternalMemoryHandleTypeFlagBitsKHR value" in
1021 * VkPhysicalDeviceExternalBufferInfoKHR. This differs from
1022 * VkPhysicalDeviceExternalImageFormatInfoKHR, which surprisingly permits
1025 assert(pExternalBufferInfo
->handleType
!= 0);
1027 /* All of the current flags are for sparse which we don't support yet.
1028 * Even when we do support it, doing sparse on external memory sounds
1029 * sketchy. Also, just disallowing flags is the safe option.
1031 if (pExternalBufferInfo
->flags
)
1034 switch (pExternalBufferInfo
->handleType
) {
1035 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
1036 pExternalBufferProperties
->externalMemoryProperties
= prime_fd_props
;
1043 pExternalBufferProperties
->externalMemoryProperties
=
1044 (VkExternalMemoryPropertiesKHR
) {0};
1047 VkResult
anv_CreateSamplerYcbcrConversionKHR(
1049 const VkSamplerYcbcrConversionCreateInfoKHR
* pCreateInfo
,
1050 const VkAllocationCallbacks
* pAllocator
,
1051 VkSamplerYcbcrConversionKHR
* pYcbcrConversion
)
1053 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1054 struct anv_ycbcr_conversion
*conversion
;
1056 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO_KHR
);
1058 conversion
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*conversion
), 8,
1059 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1061 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1063 memset(conversion
, 0, sizeof(*conversion
));
1065 conversion
->format
= anv_get_format(pCreateInfo
->format
);
1066 conversion
->ycbcr_model
= pCreateInfo
->ycbcrModel
;
1067 conversion
->ycbcr_range
= pCreateInfo
->ycbcrRange
;
1068 conversion
->mapping
[0] = pCreateInfo
->components
.r
;
1069 conversion
->mapping
[1] = pCreateInfo
->components
.g
;
1070 conversion
->mapping
[2] = pCreateInfo
->components
.b
;
1071 conversion
->mapping
[3] = pCreateInfo
->components
.a
;
1072 conversion
->chroma_offsets
[0] = pCreateInfo
->xChromaOffset
;
1073 conversion
->chroma_offsets
[1] = pCreateInfo
->yChromaOffset
;
1074 conversion
->chroma_filter
= pCreateInfo
->chromaFilter
;
1076 bool has_chroma_subsampled
= false;
1077 for (uint32_t p
= 0; p
< conversion
->format
->n_planes
; p
++) {
1078 if (conversion
->format
->planes
[p
].has_chroma
&&
1079 (conversion
->format
->planes
[p
].denominator_scales
[0] > 1 ||
1080 conversion
->format
->planes
[p
].denominator_scales
[1] > 1))
1081 has_chroma_subsampled
= true;
1083 conversion
->chroma_reconstruction
= has_chroma_subsampled
&&
1084 (conversion
->chroma_offsets
[0] == VK_CHROMA_LOCATION_COSITED_EVEN_KHR
||
1085 conversion
->chroma_offsets
[1] == VK_CHROMA_LOCATION_COSITED_EVEN_KHR
);
1087 *pYcbcrConversion
= anv_ycbcr_conversion_to_handle(conversion
);
1092 void anv_DestroySamplerYcbcrConversionKHR(
1094 VkSamplerYcbcrConversionKHR YcbcrConversion
,
1095 const VkAllocationCallbacks
* pAllocator
)
1097 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1098 ANV_FROM_HANDLE(anv_ycbcr_conversion
, conversion
, YcbcrConversion
);
1103 vk_free2(&device
->alloc
, pAllocator
, conversion
);