• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2015 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  */
23 
24 #include "anv_private.h"
25 #include "vk_enum_to_str.h"
26 #include "vk_format_info.h"
27 #include "vk_util.h"
28 
29 /*
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
35  * mode.
36  */
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, \
42 }
43 
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)
47 
48 #define swiz_fmt1(__vk_fmt, __hw_fmt, __swizzle) \
49    [VK_ENUM_OFFSET(__vk_fmt)] = { \
50       .planes = { \
51          { .isl_format = __hw_fmt, .swizzle = __swizzle, \
52            .denominator_scales = { 1, 1, }, \
53          }, \
54       }, \
55       .n_planes = 1, \
56    }
57 
58 #define fmt1(__vk_fmt, __hw_fmt) \
59    swiz_fmt1(__vk_fmt, __hw_fmt, RGBA)
60 
61 #define fmt2(__vk_fmt, __fmt1, __fmt2) \
62    [VK_ENUM_OFFSET(__vk_fmt)] = { \
63       .planes = { \
64          { .isl_format = __fmt1, \
65            .swizzle = RGBA,       \
66            .denominator_scales = { 1, 1, }, \
67          }, \
68          { .isl_format = __fmt2, \
69            .swizzle = RGBA,       \
70            .denominator_scales = { 1, 1, }, \
71          }, \
72       }, \
73       .n_planes = 2, \
74    }
75 
76 #define fmt_unsupported(__vk_fmt) \
77    [VK_ENUM_OFFSET(__vk_fmt)] = { \
78       .planes = { \
79          { .isl_format = ISL_FORMAT_UNSUPPORTED, }, \
80       }, \
81    }
82 
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, \
89    }
90 
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, }, \
96      .has_chroma = true, \
97    }
98 
99 #define ycbcr_fmt(__vk_fmt, __n_planes, ...) \
100    [VK_ENUM_OFFSET(__vk_fmt)] = { \
101       .planes = { \
102          __VA_ARGS__, \
103       }, \
104       .n_planes = __n_planes, \
105       .can_ycbcr = true, \
106    }
107 
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.
112  */
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),
225 
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),
233 
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),
302 };
303 
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)),
327 
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.
350     */
351    fmt_unsupported(VK_FORMAT_G16B16G16R16_422_UNORM_KHR),
352    fmt_unsupported(VK_FORMAT_B16G16R16G16_422_UNORM_KHR),
353 
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)),
372 };
373 
374 #undef _fmt
375 #undef swiz_fmt1
376 #undef fmt1
377 #undef fmt
378 
379 static const struct {
380    const struct anv_format *formats;
381    uint32_t n_formats;
382 } anv_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), },
387 };
388 
389 const struct anv_format *
anv_get_format(VkFormat vk_format)390 anv_get_format(VkFormat vk_format)
391 {
392    uint32_t enum_offset = VK_ENUM_OFFSET(vk_format);
393    uint32_t ext_number = VK_ENUM_EXTENSION(vk_format);
394 
395    if (ext_number >= ARRAY_SIZE(anv_formats) ||
396        enum_offset >= anv_formats[ext_number].n_formats)
397       return NULL;
398 
399    const struct anv_format *format =
400       &anv_formats[ext_number].formats[enum_offset];
401    if (format->planes[0].isl_format == ISL_FORMAT_UNSUPPORTED)
402       return NULL;
403 
404    return format;
405 }
406 
407 /**
408  * Exactly one bit must be set in \a aspect.
409  */
410 struct anv_format_plane
anv_get_format_plane(const struct gen_device_info * devinfo,VkFormat vk_format,VkImageAspectFlagBits aspect,VkImageTiling tiling)411 anv_get_format_plane(const struct gen_device_info *devinfo, VkFormat vk_format,
412                      VkImageAspectFlagBits aspect, VkImageTiling tiling)
413 {
414    const struct anv_format *format = anv_get_format(vk_format);
415    const struct anv_format_plane unsupported = {
416       .isl_format = ISL_FORMAT_UNSUPPORTED,
417    };
418 
419    if (format == NULL)
420       return unsupported;
421 
422    uint32_t plane = anv_image_aspect_to_plane(vk_format_aspects(vk_format), aspect);
423    struct anv_format_plane plane_format = format->planes[plane];
424    if (plane_format.isl_format == ISL_FORMAT_UNSUPPORTED)
425       return unsupported;
426 
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));
430       return plane_format;
431    }
432 
433    assert((aspect & ~VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) == 0);
434 
435    const struct isl_format_layout *isl_layout =
436       isl_format_get_layout(plane_format.isl_format);
437 
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
443        * hood.
444        */
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;
449       } else {
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);
453       }
454    }
455 
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.
458     */
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);
462    }
463 
464    return plane_format;
465 }
466 
467 // Format capabilities
468 
469 static VkFormatFeatureFlags
get_image_format_features(const struct gen_device_info * devinfo,VkFormat vk_format,const struct anv_format * anv_format,VkImageTiling vk_tiling)470 get_image_format_features(const struct gen_device_info *devinfo,
471                           VkFormat vk_format,
472                           const struct anv_format *anv_format,
473                           VkImageTiling vk_tiling)
474 {
475    VkFormatFeatureFlags flags = 0;
476 
477    if (anv_format == NULL)
478       return 0;
479 
480    const VkImageAspectFlags aspects = vk_format_aspects(vk_format);
481 
482    if (aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
483       if (vk_tiling == VK_IMAGE_TILING_LINEAR)
484          return 0;
485 
486       flags |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
487 
488       if (aspects == VK_IMAGE_ASPECT_DEPTH_BIT || devinfo->gen >= 8)
489          flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
490 
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;
495 
496       return flags;
497    }
498 
499    const struct anv_format_plane plane_format =
500       anv_get_format_plane(devinfo, vk_format, VK_IMAGE_ASPECT_COLOR_BIT,
501                            vk_tiling);
502 
503    if (plane_format.isl_format == ISL_FORMAT_UNSUPPORTED)
504       return 0;
505 
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);
511    }
512 
513    enum isl_format base_isl_format = base_plane_format.isl_format;
514 
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)
518       return 0;
519 
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;
523 
524       if (isl_format_supports_filtering(devinfo, plane_format.isl_format))
525          flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
526    }
527 
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.
531     */
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;
536 
537       if (isl_format_supports_alpha_blending(devinfo, plane_format.isl_format))
538          flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
539    }
540 
541    /* Load/store is determined based on base format.  This prevents RGB
542     * formats from showing up as load/store capable.
543     */
544    if (isl_is_storage_image_format(base_isl_format))
545       flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
546 
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;
550 
551    if (flags) {
552       flags |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR |
553                VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR;
554    }
555 
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.
562     */
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;
569    }
570 
571    if (anv_format->can_ycbcr) {
572       /* The sampler doesn't have support for mid point when it handles YUV on
573        * its own.
574        */
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.
579           */
580          flags |= VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT_KHR;
581       } else {
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;
585       }
586 
587       /* We can support cosited chroma locations when handle planes with our
588        * own shader snippets.
589        */
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;
594             break;
595          }
596       }
597 
598       if (anv_format->n_planes > 1)
599          flags |= VK_FORMAT_FEATURE_DISJOINT_BIT_KHR;
600 
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;
607 
608       flags &= ~disallowed_ycbcr_image_features;
609    }
610 
611    return flags;
612 }
613 
614 static VkFormatFeatureFlags
get_buffer_format_features(const struct gen_device_info * devinfo,VkFormat vk_format,const struct anv_format * anv_format)615 get_buffer_format_features(const struct gen_device_info *devinfo,
616                            VkFormat vk_format,
617                            const struct anv_format *anv_format)
618 {
619    VkFormatFeatureFlags flags = 0;
620 
621    if (anv_format == NULL)
622       return 0;
623 
624    const enum isl_format isl_format = anv_format->planes[0].isl_format;
625 
626    if (isl_format == ISL_FORMAT_UNSUPPORTED)
627       return 0;
628 
629    if (anv_format->n_planes > 1)
630       return 0;
631 
632    if (anv_format->can_ycbcr)
633       return 0;
634 
635    if (vk_format_is_depth_or_stencil(vk_format))
636       return 0;
637 
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;
641 
642    if (isl_format_supports_vertex_fetch(devinfo, isl_format))
643       flags |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
644 
645    if (isl_is_storage_image_format(isl_format))
646       flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
647 
648    if (isl_format == ISL_FORMAT_R32_SINT || isl_format == ISL_FORMAT_R32_UINT)
649       flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
650 
651    return flags;
652 }
653 
anv_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,VkFormat vk_format,VkFormatProperties * pFormatProperties)654 void anv_GetPhysicalDeviceFormatProperties(
655     VkPhysicalDevice                            physicalDevice,
656     VkFormat                                    vk_format,
657     VkFormatProperties*                         pFormatProperties)
658 {
659    ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
660    const struct gen_device_info *devinfo = &physical_device->info;
661    const struct anv_format *anv_format = anv_get_format(vk_format);
662 
663    *pFormatProperties = (VkFormatProperties) {
664       .linearTilingFeatures =
665          get_image_format_features(devinfo, vk_format, anv_format,
666                                    VK_IMAGE_TILING_LINEAR),
667       .optimalTilingFeatures =
668          get_image_format_features(devinfo, vk_format, anv_format,
669                                    VK_IMAGE_TILING_OPTIMAL),
670       .bufferFeatures =
671          get_buffer_format_features(devinfo, vk_format, anv_format),
672    };
673 }
674 
anv_GetPhysicalDeviceFormatProperties2KHR(VkPhysicalDevice physicalDevice,VkFormat format,VkFormatProperties2KHR * pFormatProperties)675 void anv_GetPhysicalDeviceFormatProperties2KHR(
676     VkPhysicalDevice                            physicalDevice,
677     VkFormat                                    format,
678     VkFormatProperties2KHR*                     pFormatProperties)
679 {
680    anv_GetPhysicalDeviceFormatProperties(physicalDevice, format,
681                                          &pFormatProperties->formatProperties);
682 
683    vk_foreach_struct(ext, pFormatProperties->pNext) {
684       switch (ext->sType) {
685       default:
686          anv_debug_ignored_stype(ext->sType);
687          break;
688       }
689    }
690 }
691 
692 static VkResult
anv_get_image_format_properties(struct anv_physical_device * physical_device,const VkPhysicalDeviceImageFormatInfo2KHR * info,VkImageFormatProperties * pImageFormatProperties,VkSamplerYcbcrConversionImageFormatPropertiesKHR * pYcbcrImageFormatProperties)693 anv_get_image_format_properties(
694    struct anv_physical_device *physical_device,
695    const VkPhysicalDeviceImageFormatInfo2KHR *info,
696    VkImageFormatProperties *pImageFormatProperties,
697    VkSamplerYcbcrConversionImageFormatPropertiesKHR *pYcbcrImageFormatProperties)
698 {
699    VkFormatFeatureFlags format_feature_flags;
700    VkExtent3D maxExtent;
701    uint32_t maxMipLevels;
702    uint32_t maxArraySize;
703    VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;
704    const struct gen_device_info *devinfo = &physical_device->info;
705    const struct anv_format *format = anv_get_format(info->format);
706 
707    if (format == NULL)
708       goto unsupported;
709 
710    format_feature_flags = get_image_format_features(devinfo, info->format,
711                                                     format, info->tiling);
712 
713    switch (info->type) {
714    default:
715       unreachable("bad VkImageType");
716    case VK_IMAGE_TYPE_1D:
717       maxExtent.width = 16384;
718       maxExtent.height = 1;
719       maxExtent.depth = 1;
720       maxMipLevels = 15; /* log2(maxWidth) + 1 */
721       maxArraySize = 2048;
722       sampleCounts = VK_SAMPLE_COUNT_1_BIT;
723       break;
724    case VK_IMAGE_TYPE_2D:
725       /* FINISHME: Does this really differ for cube maps? The documentation
726        * for RENDER_SURFACE_STATE suggests so.
727        */
728       maxExtent.width = 16384;
729       maxExtent.height = 16384;
730       maxExtent.depth = 1;
731       maxMipLevels = 15; /* log2(maxWidth) + 1 */
732       maxArraySize = 2048;
733       break;
734    case VK_IMAGE_TYPE_3D:
735       maxExtent.width = 2048;
736       maxExtent.height = 2048;
737       maxExtent.depth = 2048;
738       maxMipLevels = 12; /* log2(maxWidth) + 1 */
739       maxArraySize = 1;
740       break;
741    }
742 
743    /* Our hardware doesn't support 1D compressed textures.
744     *    From the SKL PRM, RENDER_SURFACE_STATE::SurfaceFormat:
745     *    * This field cannot be a compressed (BC*, DXT*, FXT*, ETC*, EAC*) format
746     *       if the Surface Type is SURFTYPE_1D.
747     *    * This field cannot be ASTC format if the Surface Type is SURFTYPE_1D.
748     */
749    if (info->type == VK_IMAGE_TYPE_1D &&
750        isl_format_is_compressed(format->planes[0].isl_format)) {
751        goto unsupported;
752    }
753 
754    if (info->tiling == VK_IMAGE_TILING_OPTIMAL &&
755        info->type == VK_IMAGE_TYPE_2D &&
756        (format_feature_flags & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
757                                 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) &&
758        !(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
759        !(info->usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
760       sampleCounts = isl_device_get_sample_counts(&physical_device->isl_dev);
761    }
762 
763    if (info->usage & (VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
764                       VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
765       /* Accept transfers on anything we can sample from or renderer to. */
766       if (!(format_feature_flags & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
767                                     VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT |
768                                     VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))) {
769          goto unsupported;
770       }
771    }
772 
773    if (info->usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
774       if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
775          goto unsupported;
776       }
777    }
778 
779    if (info->usage & VK_IMAGE_USAGE_STORAGE_BIT) {
780       if (!(format_feature_flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) {
781          goto unsupported;
782       }
783    }
784 
785    if (info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
786       if (!(format_feature_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) {
787          goto unsupported;
788       }
789    }
790 
791    if (info->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
792       if (!(format_feature_flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
793          goto unsupported;
794       }
795    }
796 
797    if (info->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) {
798       /* Nothing to check. */
799    }
800 
801    if (info->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
802       /* Ignore this flag because it was removed from the
803        * provisional_I_20150910 header.
804        */
805    }
806 
807    *pImageFormatProperties = (VkImageFormatProperties) {
808       .maxExtent = maxExtent,
809       .maxMipLevels = maxMipLevels,
810       .maxArrayLayers = maxArraySize,
811       .sampleCounts = sampleCounts,
812 
813       /* FINISHME: Accurately calculate
814        * VkImageFormatProperties::maxResourceSize.
815        */
816       .maxResourceSize = UINT32_MAX,
817    };
818 
819    if (pYcbcrImageFormatProperties) {
820       pYcbcrImageFormatProperties->combinedImageSamplerDescriptorCount =
821          format->n_planes;
822    }
823 
824    return VK_SUCCESS;
825 
826 unsupported:
827    *pImageFormatProperties = (VkImageFormatProperties) {
828       .maxExtent = { 0, 0, 0 },
829       .maxMipLevels = 0,
830       .maxArrayLayers = 0,
831       .sampleCounts = 0,
832       .maxResourceSize = 0,
833    };
834 
835    return VK_ERROR_FORMAT_NOT_SUPPORTED;
836 }
837 
anv_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice,VkFormat format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags createFlags,VkImageFormatProperties * pImageFormatProperties)838 VkResult anv_GetPhysicalDeviceImageFormatProperties(
839     VkPhysicalDevice                            physicalDevice,
840     VkFormat                                    format,
841     VkImageType                                 type,
842     VkImageTiling                               tiling,
843     VkImageUsageFlags                           usage,
844     VkImageCreateFlags                          createFlags,
845     VkImageFormatProperties*                    pImageFormatProperties)
846 {
847    ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
848 
849    const VkPhysicalDeviceImageFormatInfo2KHR info = {
850       .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR,
851       .pNext = NULL,
852       .format = format,
853       .type = type,
854       .tiling = tiling,
855       .usage = usage,
856       .flags = createFlags,
857    };
858 
859    return anv_get_image_format_properties(physical_device, &info,
860                                           pImageFormatProperties, NULL);
861 }
862 
863 static const VkExternalMemoryPropertiesKHR prime_fd_props = {
864    /* If we can handle external, then we can both import and export it. */
865    .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR |
866                              VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR,
867    /* For the moment, let's not support mixing and matching */
868    .exportFromImportedHandleTypes =
869       VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR |
870       VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
871    .compatibleHandleTypes =
872       VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR |
873       VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
874 };
875 
anv_GetPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceImageFormatInfo2KHR * base_info,VkImageFormatProperties2KHR * base_props)876 VkResult anv_GetPhysicalDeviceImageFormatProperties2KHR(
877     VkPhysicalDevice                            physicalDevice,
878     const VkPhysicalDeviceImageFormatInfo2KHR*  base_info,
879     VkImageFormatProperties2KHR*                base_props)
880 {
881    ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
882    const VkPhysicalDeviceExternalImageFormatInfoKHR *external_info = NULL;
883    VkExternalImageFormatPropertiesKHR *external_props = NULL;
884    VkSamplerYcbcrConversionImageFormatPropertiesKHR *ycbcr_props = NULL;
885    VkResult result;
886 
887    /* Extract input structs */
888    vk_foreach_struct_const(s, base_info->pNext) {
889       switch (s->sType) {
890       case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHR:
891          external_info = (const void *) s;
892          break;
893       default:
894          anv_debug_ignored_stype(s->sType);
895          break;
896       }
897    }
898 
899    /* Extract output structs */
900    vk_foreach_struct(s, base_props->pNext) {
901       switch (s->sType) {
902       case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR:
903          external_props = (void *) s;
904          break;
905       case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES_KHR:
906          ycbcr_props = (void *) s;
907          break;
908       default:
909          anv_debug_ignored_stype(s->sType);
910          break;
911       }
912    }
913 
914    result = anv_get_image_format_properties(physical_device, base_info,
915                &base_props->imageFormatProperties, ycbcr_props);
916    if (result != VK_SUCCESS)
917       goto fail;
918 
919    /* From the Vulkan 1.0.42 spec:
920     *
921     *    If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2KHR will
922     *    behave as if VkPhysicalDeviceExternalImageFormatInfoKHR was not
923     *    present and VkExternalImageFormatPropertiesKHR will be ignored.
924     */
925    if (external_info && external_info->handleType != 0) {
926       switch (external_info->handleType) {
927       case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
928       case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
929          if (external_props)
930             external_props->externalMemoryProperties = prime_fd_props;
931          break;
932       default:
933          /* From the Vulkan 1.0.42 spec:
934           *
935           *    If handleType is not compatible with the [parameters] specified
936           *    in VkPhysicalDeviceImageFormatInfo2KHR, then
937           *    vkGetPhysicalDeviceImageFormatProperties2KHR returns
938           *    VK_ERROR_FORMAT_NOT_SUPPORTED.
939           */
940          result = vk_errorf(physical_device->instance, physical_device,
941                             VK_ERROR_FORMAT_NOT_SUPPORTED,
942                             "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
943                             external_info->handleType);
944          goto fail;
945       }
946    }
947 
948    return VK_SUCCESS;
949 
950  fail:
951    if (result == VK_ERROR_FORMAT_NOT_SUPPORTED) {
952       /* From the Vulkan 1.0.42 spec:
953        *
954        *    If the combination of parameters to
955        *    vkGetPhysicalDeviceImageFormatProperties2KHR is not supported by
956        *    the implementation for use in vkCreateImage, then all members of
957        *    imageFormatProperties will be filled with zero.
958        */
959       base_props->imageFormatProperties = (VkImageFormatProperties) {};
960    }
961 
962    return result;
963 }
964 
anv_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice,VkFormat format,VkImageType type,uint32_t samples,VkImageUsageFlags usage,VkImageTiling tiling,uint32_t * pNumProperties,VkSparseImageFormatProperties * pProperties)965 void anv_GetPhysicalDeviceSparseImageFormatProperties(
966     VkPhysicalDevice                            physicalDevice,
967     VkFormat                                    format,
968     VkImageType                                 type,
969     uint32_t                                    samples,
970     VkImageUsageFlags                           usage,
971     VkImageTiling                               tiling,
972     uint32_t*                                   pNumProperties,
973     VkSparseImageFormatProperties*              pProperties)
974 {
975    /* Sparse images are not yet supported. */
976    *pNumProperties = 0;
977 }
978 
anv_GetPhysicalDeviceSparseImageFormatProperties2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSparseImageFormatInfo2KHR * pFormatInfo,uint32_t * pPropertyCount,VkSparseImageFormatProperties2KHR * pProperties)979 void anv_GetPhysicalDeviceSparseImageFormatProperties2KHR(
980     VkPhysicalDevice                            physicalDevice,
981     const VkPhysicalDeviceSparseImageFormatInfo2KHR* pFormatInfo,
982     uint32_t*                                   pPropertyCount,
983     VkSparseImageFormatProperties2KHR*          pProperties)
984 {
985    /* Sparse images are not yet supported. */
986    *pPropertyCount = 0;
987 }
988 
anv_GetPhysicalDeviceExternalBufferPropertiesKHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceExternalBufferInfoKHR * pExternalBufferInfo,VkExternalBufferPropertiesKHR * pExternalBufferProperties)989 void anv_GetPhysicalDeviceExternalBufferPropertiesKHR(
990     VkPhysicalDevice                             physicalDevice,
991     const VkPhysicalDeviceExternalBufferInfoKHR* pExternalBufferInfo,
992     VkExternalBufferPropertiesKHR*               pExternalBufferProperties)
993 {
994    /* The Vulkan 1.0.42 spec says "handleType must be a valid
995     * VkExternalMemoryHandleTypeFlagBitsKHR value" in
996     * VkPhysicalDeviceExternalBufferInfoKHR. This differs from
997     * VkPhysicalDeviceExternalImageFormatInfoKHR, which surprisingly permits
998     * handleType == 0.
999     */
1000    assert(pExternalBufferInfo->handleType != 0);
1001 
1002    /* All of the current flags are for sparse which we don't support yet.
1003     * Even when we do support it, doing sparse on external memory sounds
1004     * sketchy.  Also, just disallowing flags is the safe option.
1005     */
1006    if (pExternalBufferInfo->flags)
1007       goto unsupported;
1008 
1009    switch (pExternalBufferInfo->handleType) {
1010    case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
1011    case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
1012       pExternalBufferProperties->externalMemoryProperties = prime_fd_props;
1013       return;
1014    default:
1015       goto unsupported;
1016    }
1017 
1018  unsupported:
1019    pExternalBufferProperties->externalMemoryProperties =
1020       (VkExternalMemoryPropertiesKHR) {0};
1021 }
1022 
anv_CreateSamplerYcbcrConversionKHR(VkDevice _device,const VkSamplerYcbcrConversionCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSamplerYcbcrConversionKHR * pYcbcrConversion)1023 VkResult anv_CreateSamplerYcbcrConversionKHR(
1024     VkDevice                                    _device,
1025     const VkSamplerYcbcrConversionCreateInfoKHR* pCreateInfo,
1026     const VkAllocationCallbacks*                pAllocator,
1027     VkSamplerYcbcrConversionKHR*                pYcbcrConversion)
1028 {
1029    ANV_FROM_HANDLE(anv_device, device, _device);
1030    struct anv_ycbcr_conversion *conversion;
1031 
1032    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO_KHR);
1033 
1034    conversion = vk_alloc2(&device->alloc, pAllocator, sizeof(*conversion), 8,
1035                           VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
1036    if (!conversion)
1037       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1038 
1039    memset(conversion, 0, sizeof(*conversion));
1040 
1041    conversion->format = anv_get_format(pCreateInfo->format);
1042    conversion->ycbcr_model = pCreateInfo->ycbcrModel;
1043    conversion->ycbcr_range = pCreateInfo->ycbcrRange;
1044    conversion->mapping[0] = pCreateInfo->components.r;
1045    conversion->mapping[1] = pCreateInfo->components.g;
1046    conversion->mapping[2] = pCreateInfo->components.b;
1047    conversion->mapping[3] = pCreateInfo->components.a;
1048    conversion->chroma_offsets[0] = pCreateInfo->xChromaOffset;
1049    conversion->chroma_offsets[1] = pCreateInfo->yChromaOffset;
1050    conversion->chroma_filter = pCreateInfo->chromaFilter;
1051 
1052    bool has_chroma_subsampled = false;
1053    for (uint32_t p = 0; p < conversion->format->n_planes; p++) {
1054       if (conversion->format->planes[p].has_chroma &&
1055           (conversion->format->planes[p].denominator_scales[0] > 1 ||
1056            conversion->format->planes[p].denominator_scales[1] > 1))
1057          has_chroma_subsampled = true;
1058    }
1059    conversion->chroma_reconstruction = has_chroma_subsampled &&
1060       (conversion->chroma_offsets[0] == VK_CHROMA_LOCATION_COSITED_EVEN_KHR ||
1061        conversion->chroma_offsets[1] == VK_CHROMA_LOCATION_COSITED_EVEN_KHR);
1062 
1063    *pYcbcrConversion = anv_ycbcr_conversion_to_handle(conversion);
1064 
1065    return VK_SUCCESS;
1066 }
1067 
anv_DestroySamplerYcbcrConversionKHR(VkDevice _device,VkSamplerYcbcrConversionKHR YcbcrConversion,const VkAllocationCallbacks * pAllocator)1068 void anv_DestroySamplerYcbcrConversionKHR(
1069     VkDevice                                    _device,
1070     VkSamplerYcbcrConversionKHR                 YcbcrConversion,
1071     const VkAllocationCallbacks*                pAllocator)
1072 {
1073    ANV_FROM_HANDLE(anv_device, device, _device);
1074    ANV_FROM_HANDLE(anv_ycbcr_conversion, conversion, YcbcrConversion);
1075 
1076    if (!conversion)
1077       return;
1078 
1079    vk_free2(&device->alloc, pAllocator, conversion);
1080 }
1081