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
;
559 static VkFormatFeatureFlags
560 get_buffer_format_properties(const struct gen_device_info
*devinfo
,
562 const struct anv_format
*anv_format
)
564 VkFormatFeatureFlags flags
= 0;
566 if (anv_format
== NULL
)
569 const enum isl_format isl_format
= anv_format
->planes
[0].isl_format
;
571 if (isl_format
== ISL_FORMAT_UNSUPPORTED
)
574 if (anv_format
->n_planes
> 1)
577 if (anv_format
->can_ycbcr
)
580 if (vk_format_is_depth_or_stencil(vk_format
))
583 if (isl_format_supports_sampling(devinfo
, isl_format
) &&
584 !isl_format_is_compressed(isl_format
))
585 flags
|= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
;
587 if (isl_format_supports_vertex_fetch(devinfo
, isl_format
))
588 flags
|= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
;
590 if (isl_is_storage_image_format(isl_format
))
591 flags
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
;
593 if (isl_format
== ISL_FORMAT_R32_SINT
|| isl_format
== ISL_FORMAT_R32_UINT
)
594 flags
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
;
600 anv_physical_device_get_format_properties(struct anv_physical_device
*physical_device
,
602 VkFormatProperties
*out_properties
)
604 const struct gen_device_info
*devinfo
= &physical_device
->info
;
605 const struct anv_format
*format
= anv_get_format(vk_format
);
606 VkFormatFeatureFlags linear
= 0, tiled
= 0;
608 if (format
== NULL
) {
609 /* Nothing to do here */
611 struct anv_format_plane linear_fmt
;
612 linear_fmt
= anv_get_format_plane(&physical_device
->info
, vk_format
,
613 VK_IMAGE_ASPECT_COLOR_BIT
,
614 VK_IMAGE_TILING_LINEAR
);
616 linear
= get_image_format_properties(&physical_device
->info
, vk_format
,
617 format
, VK_IMAGE_TILING_LINEAR
);
618 tiled
= get_image_format_properties(&physical_device
->info
, vk_format
,
619 format
, VK_IMAGE_TILING_OPTIMAL
);
621 /* XXX: We handle 3-channel formats by switching them out for RGBX or
622 * RGBA formats behind-the-scenes. This works fine for textures
623 * because the upload process will fill in the extra channel.
624 * We could also support it for render targets, but it will take
625 * substantially more work and we have enough RGBX formats to handle
626 * what most clients will want.
628 if (linear_fmt
.isl_format
!= ISL_FORMAT_UNSUPPORTED
&&
629 !util_is_power_of_two(isl_format_layouts
[linear_fmt
.isl_format
].bpb
) &&
630 isl_format_rgb_to_rgbx(linear_fmt
.isl_format
) == ISL_FORMAT_UNSUPPORTED
) {
631 tiled
&= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
&
632 ~VK_FORMAT_FEATURE_BLIT_DST_BIT
;
636 if (format
&& format
->can_ycbcr
) {
637 VkFormatFeatureFlags ycbcr_features
= 0;
639 /* The sampler doesn't have support for mid point when it handles YUV on
642 if (isl_format_is_yuv(format
->planes
[0].isl_format
)) {
643 /* TODO: We've disabled linear implicit reconstruction with the
644 * sampler. The failures show a slightly out of range values on the
645 * bottom left of the sampled image.
647 ycbcr_features
|= VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT_KHR
;
649 ycbcr_features
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT_KHR
|
650 VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT_KHR
|
651 VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT_KHR
;
654 /* We can support cosited chroma locations when handle planes with our
655 * own shader snippets.
657 for (unsigned p
= 0; p
< format
->n_planes
; p
++) {
658 if (format
->planes
[p
].denominator_scales
[0] > 1 ||
659 format
->planes
[p
].denominator_scales
[1] > 1) {
660 ycbcr_features
|= VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT_KHR
;
665 if (format
->n_planes
> 1)
666 ycbcr_features
|= VK_FORMAT_FEATURE_DISJOINT_BIT_KHR
;
668 linear
|= ycbcr_features
;
669 tiled
|= ycbcr_features
;
671 const VkFormatFeatureFlags disallowed_ycbcr_image_features
=
672 VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
673 VK_FORMAT_FEATURE_BLIT_DST_BIT
|
674 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
675 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
|
676 VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
678 linear
&= ~disallowed_ycbcr_image_features
;
679 tiled
&= ~disallowed_ycbcr_image_features
;
682 out_properties
->linearTilingFeatures
= linear
;
683 out_properties
->optimalTilingFeatures
= tiled
;
684 out_properties
->bufferFeatures
=
685 get_buffer_format_properties(devinfo
, vk_format
, format
);
689 void anv_GetPhysicalDeviceFormatProperties(
690 VkPhysicalDevice physicalDevice
,
692 VkFormatProperties
* pFormatProperties
)
694 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
696 anv_physical_device_get_format_properties(
702 void anv_GetPhysicalDeviceFormatProperties2KHR(
703 VkPhysicalDevice physicalDevice
,
705 VkFormatProperties2KHR
* pFormatProperties
)
707 anv_GetPhysicalDeviceFormatProperties(physicalDevice
, format
,
708 &pFormatProperties
->formatProperties
);
710 vk_foreach_struct(ext
, pFormatProperties
->pNext
) {
711 switch (ext
->sType
) {
713 anv_debug_ignored_stype(ext
->sType
);
720 anv_get_image_format_properties(
721 struct anv_physical_device
*physical_device
,
722 const VkPhysicalDeviceImageFormatInfo2KHR
*info
,
723 VkImageFormatProperties
*pImageFormatProperties
,
724 VkSamplerYcbcrConversionImageFormatPropertiesKHR
*pYcbcrImageFormatProperties
)
726 VkFormatProperties format_props
;
727 VkFormatFeatureFlags format_feature_flags
;
728 VkExtent3D maxExtent
;
729 uint32_t maxMipLevels
;
730 uint32_t maxArraySize
;
731 VkSampleCountFlags sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
732 const struct anv_format
*format
= anv_get_format(info
->format
);
737 anv_physical_device_get_format_properties(physical_device
, info
->format
,
740 /* Extract the VkFormatFeatureFlags that are relevant for the queried
743 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
) {
744 format_feature_flags
= format_props
.linearTilingFeatures
;
745 } else if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
) {
746 format_feature_flags
= format_props
.optimalTilingFeatures
;
748 unreachable("bad VkImageTiling");
751 switch (info
->type
) {
753 unreachable("bad VkImageType");
754 case VK_IMAGE_TYPE_1D
:
755 maxExtent
.width
= 16384;
756 maxExtent
.height
= 1;
758 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
760 sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
762 case VK_IMAGE_TYPE_2D
:
763 /* FINISHME: Does this really differ for cube maps? The documentation
764 * for RENDER_SURFACE_STATE suggests so.
766 maxExtent
.width
= 16384;
767 maxExtent
.height
= 16384;
769 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
772 case VK_IMAGE_TYPE_3D
:
773 maxExtent
.width
= 2048;
774 maxExtent
.height
= 2048;
775 maxExtent
.depth
= 2048;
776 maxMipLevels
= 12; /* log2(maxWidth) + 1 */
781 /* Our hardware doesn't support 1D compressed textures.
782 * From the SKL PRM, RENDER_SURFACE_STATE::SurfaceFormat:
783 * * This field cannot be a compressed (BC*, DXT*, FXT*, ETC*, EAC*) format
784 * if the Surface Type is SURFTYPE_1D.
785 * * This field cannot be ASTC format if the Surface Type is SURFTYPE_1D.
787 if (info
->type
== VK_IMAGE_TYPE_1D
&&
788 isl_format_is_compressed(format
->planes
[0].isl_format
)) {
792 if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
&&
793 info
->type
== VK_IMAGE_TYPE_2D
&&
794 (format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
795 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) &&
796 !(info
->flags
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
) &&
797 !(info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
)) {
798 sampleCounts
= isl_device_get_sample_counts(&physical_device
->isl_dev
);
801 if (info
->usage
& (VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
802 VK_IMAGE_USAGE_TRANSFER_DST_BIT
)) {
803 /* Accept transfers on anything we can sample from or renderer to. */
804 if (!(format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
805 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
|
806 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
))) {
811 if (info
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
812 if (!(format_feature_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)) {
817 if (info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
818 if (!(format_feature_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)) {
823 if (info
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
824 if (!(format_feature_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)) {
829 if (info
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
) {
830 if (!(format_feature_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) {
835 if (info
->usage
& VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
) {
836 /* Nothing to check. */
839 if (info
->usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
) {
840 /* Ignore this flag because it was removed from the
841 * provisional_I_20150910 header.
845 *pImageFormatProperties
= (VkImageFormatProperties
) {
846 .maxExtent
= maxExtent
,
847 .maxMipLevels
= maxMipLevels
,
848 .maxArrayLayers
= maxArraySize
,
849 .sampleCounts
= sampleCounts
,
851 /* FINISHME: Accurately calculate
852 * VkImageFormatProperties::maxResourceSize.
854 .maxResourceSize
= UINT32_MAX
,
857 if (pYcbcrImageFormatProperties
) {
858 pYcbcrImageFormatProperties
->combinedImageSamplerDescriptorCount
=
865 *pImageFormatProperties
= (VkImageFormatProperties
) {
866 .maxExtent
= { 0, 0, 0 },
870 .maxResourceSize
= 0,
873 return VK_ERROR_FORMAT_NOT_SUPPORTED
;
876 VkResult
anv_GetPhysicalDeviceImageFormatProperties(
877 VkPhysicalDevice physicalDevice
,
880 VkImageTiling tiling
,
881 VkImageUsageFlags usage
,
882 VkImageCreateFlags createFlags
,
883 VkImageFormatProperties
* pImageFormatProperties
)
885 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
887 const VkPhysicalDeviceImageFormatInfo2KHR info
= {
888 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR
,
894 .flags
= createFlags
,
897 return anv_get_image_format_properties(physical_device
, &info
,
898 pImageFormatProperties
, NULL
);
901 static const VkExternalMemoryPropertiesKHR prime_fd_props
= {
902 /* If we can handle external, then we can both import and export it. */
903 .externalMemoryFeatures
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR
|
904 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR
,
905 /* For the moment, let's not support mixing and matching */
906 .exportFromImportedHandleTypes
=
907 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
,
908 .compatibleHandleTypes
=
909 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
,
912 VkResult
anv_GetPhysicalDeviceImageFormatProperties2KHR(
913 VkPhysicalDevice physicalDevice
,
914 const VkPhysicalDeviceImageFormatInfo2KHR
* base_info
,
915 VkImageFormatProperties2KHR
* base_props
)
917 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
918 const VkPhysicalDeviceExternalImageFormatInfoKHR
*external_info
= NULL
;
919 VkExternalImageFormatPropertiesKHR
*external_props
= NULL
;
920 VkSamplerYcbcrConversionImageFormatPropertiesKHR
*ycbcr_props
= NULL
;
923 /* Extract input structs */
924 vk_foreach_struct_const(s
, base_info
->pNext
) {
926 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHR
:
927 external_info
= (const void *) s
;
930 anv_debug_ignored_stype(s
->sType
);
935 /* Extract output structs */
936 vk_foreach_struct(s
, base_props
->pNext
) {
938 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR
:
939 external_props
= (void *) s
;
941 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES_KHR
:
942 ycbcr_props
= (void *) s
;
945 anv_debug_ignored_stype(s
->sType
);
950 result
= anv_get_image_format_properties(physical_device
, base_info
,
951 &base_props
->imageFormatProperties
, ycbcr_props
);
952 if (result
!= VK_SUCCESS
)
955 /* From the Vulkan 1.0.42 spec:
957 * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2KHR will
958 * behave as if VkPhysicalDeviceExternalImageFormatInfoKHR was not
959 * present and VkExternalImageFormatPropertiesKHR will be ignored.
961 if (external_info
&& external_info
->handleType
!= 0) {
962 switch (external_info
->handleType
) {
963 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
965 external_props
->externalMemoryProperties
= prime_fd_props
;
968 /* From the Vulkan 1.0.42 spec:
970 * If handleType is not compatible with the [parameters] specified
971 * in VkPhysicalDeviceImageFormatInfo2KHR, then
972 * vkGetPhysicalDeviceImageFormatProperties2KHR returns
973 * VK_ERROR_FORMAT_NOT_SUPPORTED.
975 result
= vk_errorf(physical_device
->instance
, physical_device
,
976 VK_ERROR_FORMAT_NOT_SUPPORTED
,
977 "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
978 external_info
->handleType
);
986 if (result
== VK_ERROR_FORMAT_NOT_SUPPORTED
) {
987 /* From the Vulkan 1.0.42 spec:
989 * If the combination of parameters to
990 * vkGetPhysicalDeviceImageFormatProperties2KHR is not supported by
991 * the implementation for use in vkCreateImage, then all members of
992 * imageFormatProperties will be filled with zero.
994 base_props
->imageFormatProperties
= (VkImageFormatProperties
) {};
1000 void anv_GetPhysicalDeviceSparseImageFormatProperties(
1001 VkPhysicalDevice physicalDevice
,
1005 VkImageUsageFlags usage
,
1006 VkImageTiling tiling
,
1007 uint32_t* pNumProperties
,
1008 VkSparseImageFormatProperties
* pProperties
)
1010 /* Sparse images are not yet supported. */
1011 *pNumProperties
= 0;
1014 void anv_GetPhysicalDeviceSparseImageFormatProperties2KHR(
1015 VkPhysicalDevice physicalDevice
,
1016 const VkPhysicalDeviceSparseImageFormatInfo2KHR
* pFormatInfo
,
1017 uint32_t* pPropertyCount
,
1018 VkSparseImageFormatProperties2KHR
* pProperties
)
1020 /* Sparse images are not yet supported. */
1021 *pPropertyCount
= 0;
1024 void anv_GetPhysicalDeviceExternalBufferPropertiesKHR(
1025 VkPhysicalDevice physicalDevice
,
1026 const VkPhysicalDeviceExternalBufferInfoKHR
* pExternalBufferInfo
,
1027 VkExternalBufferPropertiesKHR
* pExternalBufferProperties
)
1029 /* The Vulkan 1.0.42 spec says "handleType must be a valid
1030 * VkExternalMemoryHandleTypeFlagBitsKHR value" in
1031 * VkPhysicalDeviceExternalBufferInfoKHR. This differs from
1032 * VkPhysicalDeviceExternalImageFormatInfoKHR, which surprisingly permits
1035 assert(pExternalBufferInfo
->handleType
!= 0);
1037 /* All of the current flags are for sparse which we don't support yet.
1038 * Even when we do support it, doing sparse on external memory sounds
1039 * sketchy. Also, just disallowing flags is the safe option.
1041 if (pExternalBufferInfo
->flags
)
1044 switch (pExternalBufferInfo
->handleType
) {
1045 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
1046 pExternalBufferProperties
->externalMemoryProperties
= prime_fd_props
;
1053 pExternalBufferProperties
->externalMemoryProperties
=
1054 (VkExternalMemoryPropertiesKHR
) {0};
1057 VkResult
anv_CreateSamplerYcbcrConversionKHR(
1059 const VkSamplerYcbcrConversionCreateInfoKHR
* pCreateInfo
,
1060 const VkAllocationCallbacks
* pAllocator
,
1061 VkSamplerYcbcrConversionKHR
* pYcbcrConversion
)
1063 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1064 struct anv_ycbcr_conversion
*conversion
;
1066 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO_KHR
);
1068 conversion
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*conversion
), 8,
1069 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1071 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1073 memset(conversion
, 0, sizeof(*conversion
));
1075 conversion
->format
= anv_get_format(pCreateInfo
->format
);
1076 conversion
->ycbcr_model
= pCreateInfo
->ycbcrModel
;
1077 conversion
->ycbcr_range
= pCreateInfo
->ycbcrRange
;
1078 conversion
->mapping
[0] = pCreateInfo
->components
.r
;
1079 conversion
->mapping
[1] = pCreateInfo
->components
.g
;
1080 conversion
->mapping
[2] = pCreateInfo
->components
.b
;
1081 conversion
->mapping
[3] = pCreateInfo
->components
.a
;
1082 conversion
->chroma_offsets
[0] = pCreateInfo
->xChromaOffset
;
1083 conversion
->chroma_offsets
[1] = pCreateInfo
->yChromaOffset
;
1084 conversion
->chroma_filter
= pCreateInfo
->chromaFilter
;
1086 bool has_chroma_subsampled
= false;
1087 for (uint32_t p
= 0; p
< conversion
->format
->n_planes
; p
++) {
1088 if (conversion
->format
->planes
[p
].has_chroma
&&
1089 (conversion
->format
->planes
[p
].denominator_scales
[0] > 1 ||
1090 conversion
->format
->planes
[p
].denominator_scales
[1] > 1))
1091 has_chroma_subsampled
= true;
1093 conversion
->chroma_reconstruction
= has_chroma_subsampled
&&
1094 (conversion
->chroma_offsets
[0] == VK_CHROMA_LOCATION_COSITED_EVEN_KHR
||
1095 conversion
->chroma_offsets
[1] == VK_CHROMA_LOCATION_COSITED_EVEN_KHR
);
1097 *pYcbcrConversion
= anv_ycbcr_conversion_to_handle(conversion
);
1102 void anv_DestroySamplerYcbcrConversionKHR(
1104 VkSamplerYcbcrConversionKHR YcbcrConversion
,
1105 const VkAllocationCallbacks
* pAllocator
)
1107 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1108 ANV_FROM_HANDLE(anv_ycbcr_conversion
, conversion
, YcbcrConversion
);
1113 vk_free2(&device
->alloc
, pAllocator
, conversion
);