1
2 /*
3 * Copyright © 2016 Red Hat.
4 * Copyright © 2016 Bas Nieuwenhuizen
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "tu_private.h"
27
28 #include "adreno_common.xml.h"
29 #include "a6xx.xml.h"
30
31 #include "vk_format.h"
32 #include "vk_util.h"
33 #include "drm-uapi/drm_fourcc.h"
34
35 #define TU6_FMT(vkfmt, hwfmt, swapfmt, valid) \
36 [VK_FORMAT_##vkfmt] = { \
37 .fmt = FMT6_##hwfmt, \
38 .swap = swapfmt, \
39 .supported = valid, \
40 }
41
42 #define TU6_VTC(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_VERTEX | FMT_TEXTURE | FMT_COLOR)
43 #define TU6_xTC(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_TEXTURE | FMT_COLOR)
44 #define TU6_Vxx(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_VERTEX)
45 #define TU6_xTx(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_TEXTURE)
46 #define TU6_xxx(vk, fmt, swap) TU6_FMT(vk, NONE, WZYX, 0)
47
48 static const struct tu_native_format tu6_format_table[] = {
49 TU6_xxx(UNDEFINED, x, x), /* 0 */
50
51 /* 8-bit packed */
52 TU6_xxx(R4G4_UNORM_PACK8, 4_4_UNORM, WZXY), /* 1 */
53
54 /* 16-bit packed */
55 TU6_xTC(R4G4B4A4_UNORM_PACK16, 4_4_4_4_UNORM, XYZW), /* 2 */
56 TU6_xTC(B4G4R4A4_UNORM_PACK16, 4_4_4_4_UNORM, ZYXW), /* 3 */
57 TU6_xTC(R5G6B5_UNORM_PACK16, 5_6_5_UNORM, WXYZ), /* 4 */
58 TU6_xTC(B5G6R5_UNORM_PACK16, 5_6_5_UNORM, WZYX), /* 5 */
59 TU6_xTC(R5G5B5A1_UNORM_PACK16, 5_5_5_1_UNORM, XYZW), /* 6 */
60 TU6_xTC(B5G5R5A1_UNORM_PACK16, 5_5_5_1_UNORM, ZYXW), /* 7 */
61 TU6_xTC(A1R5G5B5_UNORM_PACK16, 5_5_5_1_UNORM, WXYZ), /* 8 */
62
63 /* 8-bit R */
64 TU6_VTC(R8_UNORM, 8_UNORM, WZYX), /* 9 */
65 TU6_VTC(R8_SNORM, 8_SNORM, WZYX), /* 10 */
66 TU6_Vxx(R8_USCALED, 8_UINT, WZYX), /* 11 */
67 TU6_Vxx(R8_SSCALED, 8_SINT, WZYX), /* 12 */
68 TU6_VTC(R8_UINT, 8_UINT, WZYX), /* 13 */
69 TU6_VTC(R8_SINT, 8_SINT, WZYX), /* 14 */
70 TU6_xTC(R8_SRGB, 8_UNORM, WZYX), /* 15 */
71
72 /* 16-bit RG */
73 TU6_VTC(R8G8_UNORM, 8_8_UNORM, WZYX), /* 16 */
74 TU6_VTC(R8G8_SNORM, 8_8_SNORM, WZYX), /* 17 */
75 TU6_Vxx(R8G8_USCALED, 8_8_UINT, WZYX), /* 18 */
76 TU6_Vxx(R8G8_SSCALED, 8_8_SINT, WZYX), /* 19 */
77 TU6_VTC(R8G8_UINT, 8_8_UINT, WZYX), /* 20 */
78 TU6_VTC(R8G8_SINT, 8_8_SINT, WZYX), /* 21 */
79 TU6_xTC(R8G8_SRGB, 8_8_UNORM, WZYX), /* 22 */
80
81 /* 24-bit RGB */
82 TU6_Vxx(R8G8B8_UNORM, 8_8_8_UNORM, WZYX), /* 23 */
83 TU6_Vxx(R8G8B8_SNORM, 8_8_8_SNORM, WZYX), /* 24 */
84 TU6_Vxx(R8G8B8_USCALED, 8_8_8_UINT, WZYX), /* 25 */
85 TU6_Vxx(R8G8B8_SSCALED, 8_8_8_SINT, WZYX), /* 26 */
86 TU6_Vxx(R8G8B8_UINT, 8_8_8_UINT, WZYX), /* 27 */
87 TU6_Vxx(R8G8B8_SINT, 8_8_8_SINT, WZYX), /* 28 */
88 TU6_xxx(R8G8B8_SRGB, 8_8_8_UNORM, WZYX), /* 29 */
89
90 /* 24-bit BGR */
91 TU6_xxx(B8G8R8_UNORM, 8_8_8_UNORM, WXYZ), /* 30 */
92 TU6_xxx(B8G8R8_SNORM, 8_8_8_SNORM, WXYZ), /* 31 */
93 TU6_xxx(B8G8R8_USCALED, 8_8_8_UINT, WXYZ), /* 32 */
94 TU6_xxx(B8G8R8_SSCALED, 8_8_8_SINT, WXYZ), /* 33 */
95 TU6_xxx(B8G8R8_UINT, 8_8_8_UINT, WXYZ), /* 34 */
96 TU6_xxx(B8G8R8_SINT, 8_8_8_SINT, WXYZ), /* 35 */
97 TU6_xxx(B8G8R8_SRGB, 8_8_8_UNORM, WXYZ), /* 36 */
98
99 /* 32-bit RGBA */
100 TU6_VTC(R8G8B8A8_UNORM, 8_8_8_8_UNORM, WZYX), /* 37 */
101 TU6_VTC(R8G8B8A8_SNORM, 8_8_8_8_SNORM, WZYX), /* 38 */
102 TU6_Vxx(R8G8B8A8_USCALED, 8_8_8_8_UINT, WZYX), /* 39 */
103 TU6_Vxx(R8G8B8A8_SSCALED, 8_8_8_8_SINT, WZYX), /* 40 */
104 TU6_VTC(R8G8B8A8_UINT, 8_8_8_8_UINT, WZYX), /* 41 */
105 TU6_VTC(R8G8B8A8_SINT, 8_8_8_8_SINT, WZYX), /* 42 */
106 TU6_xTC(R8G8B8A8_SRGB, 8_8_8_8_UNORM, WZYX), /* 43 */
107
108 /* 32-bit BGRA */
109 TU6_VTC(B8G8R8A8_UNORM, 8_8_8_8_UNORM, WXYZ), /* 44 */
110 TU6_VTC(B8G8R8A8_SNORM, 8_8_8_8_SNORM, WXYZ), /* 45 */
111 TU6_Vxx(B8G8R8A8_USCALED, 8_8_8_8_UINT, WXYZ), /* 46 */
112 TU6_Vxx(B8G8R8A8_SSCALED, 8_8_8_8_SINT, WXYZ), /* 47 */
113 TU6_VTC(B8G8R8A8_UINT, 8_8_8_8_UINT, WXYZ), /* 48 */
114 TU6_VTC(B8G8R8A8_SINT, 8_8_8_8_SINT, WXYZ), /* 49 */
115 TU6_xTC(B8G8R8A8_SRGB, 8_8_8_8_UNORM, WXYZ), /* 50 */
116
117 /* 32-bit packed */
118 TU6_VTC(A8B8G8R8_UNORM_PACK32, 8_8_8_8_UNORM, WZYX), /* 51 */
119 TU6_VTC(A8B8G8R8_SNORM_PACK32, 8_8_8_8_SNORM, WZYX), /* 52 */
120 TU6_Vxx(A8B8G8R8_USCALED_PACK32, 8_8_8_8_UINT, WZYX), /* 53 */
121 TU6_Vxx(A8B8G8R8_SSCALED_PACK32, 8_8_8_8_SINT, WZYX), /* 54 */
122 TU6_VTC(A8B8G8R8_UINT_PACK32, 8_8_8_8_UINT, WZYX), /* 55 */
123 TU6_VTC(A8B8G8R8_SINT_PACK32, 8_8_8_8_SINT, WZYX), /* 56 */
124 TU6_xTC(A8B8G8R8_SRGB_PACK32, 8_8_8_8_UNORM, WZYX), /* 57 */
125 TU6_VTC(A2R10G10B10_UNORM_PACK32, 10_10_10_2_UNORM, WXYZ), /* 58 */
126 TU6_Vxx(A2R10G10B10_SNORM_PACK32, 10_10_10_2_SNORM, WXYZ), /* 59 */
127 TU6_Vxx(A2R10G10B10_USCALED_PACK32, 10_10_10_2_UINT, WXYZ), /* 60 */
128 TU6_Vxx(A2R10G10B10_SSCALED_PACK32, 10_10_10_2_SINT, WXYZ), /* 61 */
129 TU6_VTC(A2R10G10B10_UINT_PACK32, 10_10_10_2_UINT, WXYZ), /* 62 */
130 TU6_Vxx(A2R10G10B10_SINT_PACK32, 10_10_10_2_SINT, WXYZ), /* 63 */
131 TU6_VTC(A2B10G10R10_UNORM_PACK32, 10_10_10_2_UNORM, WZYX), /* 64 */
132 TU6_Vxx(A2B10G10R10_SNORM_PACK32, 10_10_10_2_SNORM, WZYX), /* 65 */
133 TU6_Vxx(A2B10G10R10_USCALED_PACK32, 10_10_10_2_UINT, WZYX), /* 66 */
134 TU6_Vxx(A2B10G10R10_SSCALED_PACK32, 10_10_10_2_SINT, WZYX), /* 67 */
135 TU6_VTC(A2B10G10R10_UINT_PACK32, 10_10_10_2_UINT, WZYX), /* 68 */
136 TU6_Vxx(A2B10G10R10_SINT_PACK32, 10_10_10_2_SINT, WZYX), /* 69 */
137
138 /* 16-bit R */
139 TU6_VTC(R16_UNORM, 16_UNORM, WZYX), /* 70 */
140 TU6_VTC(R16_SNORM, 16_SNORM, WZYX), /* 71 */
141 TU6_Vxx(R16_USCALED, 16_UINT, WZYX), /* 72 */
142 TU6_Vxx(R16_SSCALED, 16_SINT, WZYX), /* 73 */
143 TU6_VTC(R16_UINT, 16_UINT, WZYX), /* 74 */
144 TU6_VTC(R16_SINT, 16_SINT, WZYX), /* 75 */
145 TU6_VTC(R16_SFLOAT, 16_FLOAT, WZYX), /* 76 */
146
147 /* 32-bit RG */
148 TU6_VTC(R16G16_UNORM, 16_16_UNORM, WZYX), /* 77 */
149 TU6_VTC(R16G16_SNORM, 16_16_SNORM, WZYX), /* 78 */
150 TU6_Vxx(R16G16_USCALED, 16_16_UINT, WZYX), /* 79 */
151 TU6_Vxx(R16G16_SSCALED, 16_16_SINT, WZYX), /* 80 */
152 TU6_VTC(R16G16_UINT, 16_16_UINT, WZYX), /* 81 */
153 TU6_VTC(R16G16_SINT, 16_16_SINT, WZYX), /* 82 */
154 TU6_VTC(R16G16_SFLOAT, 16_16_FLOAT, WZYX), /* 83 */
155
156 /* 48-bit RGB */
157 TU6_Vxx(R16G16B16_UNORM, 16_16_16_UNORM, WZYX), /* 84 */
158 TU6_Vxx(R16G16B16_SNORM, 16_16_16_SNORM, WZYX), /* 85 */
159 TU6_Vxx(R16G16B16_USCALED, 16_16_16_UINT, WZYX), /* 86 */
160 TU6_Vxx(R16G16B16_SSCALED, 16_16_16_SINT, WZYX), /* 87 */
161 TU6_Vxx(R16G16B16_UINT, 16_16_16_UINT, WZYX), /* 88 */
162 TU6_Vxx(R16G16B16_SINT, 16_16_16_SINT, WZYX), /* 89 */
163 TU6_Vxx(R16G16B16_SFLOAT, 16_16_16_FLOAT, WZYX), /* 90 */
164
165 /* 64-bit RGBA */
166 TU6_VTC(R16G16B16A16_UNORM, 16_16_16_16_UNORM, WZYX), /* 91 */
167 TU6_VTC(R16G16B16A16_SNORM, 16_16_16_16_SNORM, WZYX), /* 92 */
168 TU6_Vxx(R16G16B16A16_USCALED, 16_16_16_16_UINT, WZYX), /* 93 */
169 TU6_Vxx(R16G16B16A16_SSCALED, 16_16_16_16_SINT, WZYX), /* 94 */
170 TU6_VTC(R16G16B16A16_UINT, 16_16_16_16_UINT, WZYX), /* 95 */
171 TU6_VTC(R16G16B16A16_SINT, 16_16_16_16_SINT, WZYX), /* 96 */
172 TU6_VTC(R16G16B16A16_SFLOAT, 16_16_16_16_FLOAT, WZYX), /* 97 */
173
174 /* 32-bit R */
175 TU6_VTC(R32_UINT, 32_UINT, WZYX), /* 98 */
176 TU6_VTC(R32_SINT, 32_SINT, WZYX), /* 99 */
177 TU6_VTC(R32_SFLOAT, 32_FLOAT, WZYX), /* 100 */
178
179 /* 64-bit RG */
180 TU6_VTC(R32G32_UINT, 32_32_UINT, WZYX), /* 101 */
181 TU6_VTC(R32G32_SINT, 32_32_SINT, WZYX), /* 102 */
182 TU6_VTC(R32G32_SFLOAT, 32_32_FLOAT, WZYX), /* 103 */
183
184 /* 96-bit RGB */
185 TU6_Vxx(R32G32B32_UINT, 32_32_32_UINT, WZYX), /* 104 */
186 TU6_Vxx(R32G32B32_SINT, 32_32_32_SINT, WZYX), /* 105 */
187 TU6_Vxx(R32G32B32_SFLOAT, 32_32_32_FLOAT, WZYX), /* 106 */
188
189 /* 128-bit RGBA */
190 TU6_VTC(R32G32B32A32_UINT, 32_32_32_32_UINT, WZYX), /* 107 */
191 TU6_VTC(R32G32B32A32_SINT, 32_32_32_32_SINT, WZYX), /* 108 */
192 TU6_VTC(R32G32B32A32_SFLOAT, 32_32_32_32_FLOAT, WZYX), /* 109 */
193
194 /* 64-bit R */
195 TU6_xxx(R64_UINT, 64_UINT, WZYX), /* 110 */
196 TU6_xxx(R64_SINT, 64_SINT, WZYX), /* 111 */
197 TU6_xxx(R64_SFLOAT, 64_FLOAT, WZYX), /* 112 */
198
199 /* 128-bit RG */
200 TU6_xxx(R64G64_UINT, 64_64_UINT, WZYX), /* 113 */
201 TU6_xxx(R64G64_SINT, 64_64_SINT, WZYX), /* 114 */
202 TU6_xxx(R64G64_SFLOAT, 64_64_FLOAT, WZYX), /* 115 */
203
204 /* 192-bit RGB */
205 TU6_xxx(R64G64B64_UINT, 64_64_64_UINT, WZYX), /* 116 */
206 TU6_xxx(R64G64B64_SINT, 64_64_64_SINT, WZYX), /* 117 */
207 TU6_xxx(R64G64B64_SFLOAT, 64_64_64_FLOAT, WZYX), /* 118 */
208
209 /* 256-bit RGBA */
210 TU6_xxx(R64G64B64A64_UINT, 64_64_64_64_UINT, WZYX), /* 119 */
211 TU6_xxx(R64G64B64A64_SINT, 64_64_64_64_SINT, WZYX), /* 120 */
212 TU6_xxx(R64G64B64A64_SFLOAT, 64_64_64_64_FLOAT, WZYX), /* 121 */
213
214 /* 32-bit packed float */
215 TU6_VTC(B10G11R11_UFLOAT_PACK32, 11_11_10_FLOAT, WZYX), /* 122 */
216 TU6_xTx(E5B9G9R9_UFLOAT_PACK32, 9_9_9_E5_FLOAT, WZYX), /* 123 */
217
218 /* depth/stencil
219 * X8_D24_UNORM/D24_UNORM_S8_UINT should be Z24_UNORM_S8_UINT_AS_R8G8B8A8
220 * but the format doesn't work on A630 when UBWC is disabled, so use
221 * 8_8_8_8_UNORM as the default and override it when UBWC is enabled
222 */
223 TU6_xTC(D16_UNORM, 16_UNORM, WZYX), /* 124 */
224 TU6_xTC(X8_D24_UNORM_PACK32, 8_8_8_8_UNORM, WZYX), /* 125 */
225 TU6_xTC(D32_SFLOAT, 32_FLOAT, WZYX), /* 126 */
226 TU6_xTC(S8_UINT, 8_UINT, WZYX), /* 127 */
227 TU6_xxx(D16_UNORM_S8_UINT, X8Z16_UNORM, WZYX), /* 128 */
228 TU6_xTC(D24_UNORM_S8_UINT, 8_8_8_8_UNORM, WZYX), /* 129 */
229 TU6_xTC(D32_SFLOAT_S8_UINT, NONE, WZYX), /* 130 */
230
231 /* compressed */
232 TU6_xTx(BC1_RGB_UNORM_BLOCK, DXT1, WZYX), /* 131 */
233 TU6_xTx(BC1_RGB_SRGB_BLOCK, DXT1, WZYX), /* 132 */
234 TU6_xTx(BC1_RGBA_UNORM_BLOCK, DXT1, WZYX), /* 133 */
235 TU6_xTx(BC1_RGBA_SRGB_BLOCK, DXT1, WZYX), /* 134 */
236 TU6_xTx(BC2_UNORM_BLOCK, DXT3, WZYX), /* 135 */
237 TU6_xTx(BC2_SRGB_BLOCK, DXT3, WZYX), /* 136 */
238 TU6_xTx(BC3_UNORM_BLOCK, DXT5, WZYX), /* 137 */
239 TU6_xTx(BC3_SRGB_BLOCK, DXT5, WZYX), /* 138 */
240 TU6_xTx(BC4_UNORM_BLOCK, RGTC1_UNORM, WZYX), /* 139 */
241 TU6_xTx(BC4_SNORM_BLOCK, RGTC1_SNORM, WZYX), /* 140 */
242 TU6_xTx(BC5_UNORM_BLOCK, RGTC2_UNORM, WZYX), /* 141 */
243 TU6_xTx(BC5_SNORM_BLOCK, RGTC2_SNORM, WZYX), /* 142 */
244 TU6_xTx(BC6H_UFLOAT_BLOCK, BPTC_UFLOAT, WZYX), /* 143 */
245 TU6_xTx(BC6H_SFLOAT_BLOCK, BPTC_FLOAT, WZYX), /* 144 */
246 TU6_xTx(BC7_UNORM_BLOCK, BPTC, WZYX), /* 145 */
247 TU6_xTx(BC7_SRGB_BLOCK, BPTC, WZYX), /* 146 */
248 TU6_xTx(ETC2_R8G8B8_UNORM_BLOCK, ETC2_RGB8, WZYX), /* 147 */
249 TU6_xTx(ETC2_R8G8B8_SRGB_BLOCK, ETC2_RGB8, WZYX), /* 148 */
250 TU6_xTx(ETC2_R8G8B8A1_UNORM_BLOCK, ETC2_RGB8A1, WZYX), /* 149 */
251 TU6_xTx(ETC2_R8G8B8A1_SRGB_BLOCK, ETC2_RGB8A1, WZYX), /* 150 */
252 TU6_xTx(ETC2_R8G8B8A8_UNORM_BLOCK, ETC2_RGBA8, WZYX), /* 151 */
253 TU6_xTx(ETC2_R8G8B8A8_SRGB_BLOCK, ETC2_RGBA8, WZYX), /* 152 */
254 TU6_xTx(EAC_R11_UNORM_BLOCK, ETC2_R11_UNORM, WZYX), /* 153 */
255 TU6_xTx(EAC_R11_SNORM_BLOCK, ETC2_R11_SNORM, WZYX), /* 154 */
256 TU6_xTx(EAC_R11G11_UNORM_BLOCK, ETC2_RG11_UNORM, WZYX), /* 155 */
257 TU6_xTx(EAC_R11G11_SNORM_BLOCK, ETC2_RG11_SNORM, WZYX), /* 156 */
258 TU6_xTx(ASTC_4x4_UNORM_BLOCK, ASTC_4x4, WZYX), /* 157 */
259 TU6_xTx(ASTC_4x4_SRGB_BLOCK, ASTC_4x4, WZYX), /* 158 */
260 TU6_xTx(ASTC_5x4_UNORM_BLOCK, ASTC_5x4, WZYX), /* 159 */
261 TU6_xTx(ASTC_5x4_SRGB_BLOCK, ASTC_5x4, WZYX), /* 160 */
262 TU6_xTx(ASTC_5x5_UNORM_BLOCK, ASTC_5x5, WZYX), /* 161 */
263 TU6_xTx(ASTC_5x5_SRGB_BLOCK, ASTC_5x5, WZYX), /* 162 */
264 TU6_xTx(ASTC_6x5_UNORM_BLOCK, ASTC_6x5, WZYX), /* 163 */
265 TU6_xTx(ASTC_6x5_SRGB_BLOCK, ASTC_6x5, WZYX), /* 164 */
266 TU6_xTx(ASTC_6x6_UNORM_BLOCK, ASTC_6x6, WZYX), /* 165 */
267 TU6_xTx(ASTC_6x6_SRGB_BLOCK, ASTC_6x6, WZYX), /* 166 */
268 TU6_xTx(ASTC_8x5_UNORM_BLOCK, ASTC_8x5, WZYX), /* 167 */
269 TU6_xTx(ASTC_8x5_SRGB_BLOCK, ASTC_8x5, WZYX), /* 168 */
270 TU6_xTx(ASTC_8x6_UNORM_BLOCK, ASTC_8x6, WZYX), /* 169 */
271 TU6_xTx(ASTC_8x6_SRGB_BLOCK, ASTC_8x6, WZYX), /* 170 */
272 TU6_xTx(ASTC_8x8_UNORM_BLOCK, ASTC_8x8, WZYX), /* 171 */
273 TU6_xTx(ASTC_8x8_SRGB_BLOCK, ASTC_8x8, WZYX), /* 172 */
274 TU6_xTx(ASTC_10x5_UNORM_BLOCK, ASTC_10x5, WZYX), /* 173 */
275 TU6_xTx(ASTC_10x5_SRGB_BLOCK, ASTC_10x5, WZYX), /* 174 */
276 TU6_xTx(ASTC_10x6_UNORM_BLOCK, ASTC_10x6, WZYX), /* 175 */
277 TU6_xTx(ASTC_10x6_SRGB_BLOCK, ASTC_10x6, WZYX), /* 176 */
278 TU6_xTx(ASTC_10x8_UNORM_BLOCK, ASTC_10x8, WZYX), /* 177 */
279 TU6_xTx(ASTC_10x8_SRGB_BLOCK, ASTC_10x8, WZYX), /* 178 */
280 TU6_xTx(ASTC_10x10_UNORM_BLOCK, ASTC_10x10, WZYX), /* 179 */
281 TU6_xTx(ASTC_10x10_SRGB_BLOCK, ASTC_10x10, WZYX), /* 180 */
282 TU6_xTx(ASTC_12x10_UNORM_BLOCK, ASTC_12x10, WZYX), /* 181 */
283 TU6_xTx(ASTC_12x10_SRGB_BLOCK, ASTC_12x10, WZYX), /* 182 */
284 TU6_xTx(ASTC_12x12_UNORM_BLOCK, ASTC_12x12, WZYX), /* 183 */
285 TU6_xTx(ASTC_12x12_SRGB_BLOCK, ASTC_12x12, WZYX), /* 184 */
286 };
287
288 #undef TU6_FMT
289 #define TU6_FMT(vkfmt, hwfmt, swapfmt, valid) \
290 case VK_FORMAT_##vkfmt: \
291 fmt = (struct tu_native_format) { \
292 .fmt = FMT6_##hwfmt, \
293 .swap = swapfmt, \
294 .supported = valid, \
295 }; break;
296
297 static struct tu_native_format
tu6_get_native_format(VkFormat format)298 tu6_get_native_format(VkFormat format)
299 {
300 struct tu_native_format fmt = {};
301
302 if (format < ARRAY_SIZE(tu6_format_table)) {
303 fmt = tu6_format_table[format];
304 } else {
305 switch (format) {
306 TU6_xTx(G8B8G8R8_422_UNORM, R8G8R8B8_422_UNORM, WZYX)
307 TU6_xTx(B8G8R8G8_422_UNORM, G8R8B8R8_422_UNORM, WZYX)
308 TU6_xTx(G8_B8_R8_3PLANE_420_UNORM, R8_G8_B8_3PLANE_420_UNORM, WZYX)
309 TU6_xTx(G8_B8R8_2PLANE_420_UNORM, R8_G8B8_2PLANE_420_UNORM, WZYX)
310 TU6_xTC(A4R4G4B4_UNORM_PACK16_EXT, 4_4_4_4_UNORM, WXYZ)
311 TU6_xTC(A4B4G4R4_UNORM_PACK16_EXT, 4_4_4_4_UNORM, WZYX)
312 default:
313 break;
314 }
315 }
316
317 if (fmt.supported && vk_format_to_pipe_format(format) == PIPE_FORMAT_NONE) {
318 tu_finishme("vk_format %d missing matching pipe format.\n", format);
319 fmt.supported = false;
320 }
321
322 return fmt;
323 }
324
325 struct tu_native_format
tu6_format_vtx(VkFormat format)326 tu6_format_vtx(VkFormat format)
327 {
328 struct tu_native_format fmt = tu6_get_native_format(format);
329 assert(fmt.supported & FMT_VERTEX);
330 return fmt;
331 }
332
333 struct tu_native_format
tu6_format_color(VkFormat format,enum a6xx_tile_mode tile_mode)334 tu6_format_color(VkFormat format, enum a6xx_tile_mode tile_mode)
335 {
336 struct tu_native_format fmt = tu6_get_native_format(format);
337 assert(fmt.supported & FMT_COLOR);
338
339 if (fmt.fmt == FMT6_10_10_10_2_UNORM)
340 fmt.fmt = FMT6_10_10_10_2_UNORM_DEST;
341
342 if (tile_mode)
343 fmt.swap = WZYX;
344
345 return fmt;
346 }
347
348 struct tu_native_format
tu6_format_texture(VkFormat format,enum a6xx_tile_mode tile_mode)349 tu6_format_texture(VkFormat format, enum a6xx_tile_mode tile_mode)
350 {
351 struct tu_native_format fmt = tu6_get_native_format(format);
352 assert(fmt.supported & FMT_TEXTURE);
353
354 if (!tile_mode) {
355 /* different from format table when used as linear src */
356 if (format == VK_FORMAT_R5G5B5A1_UNORM_PACK16)
357 fmt.fmt = FMT6_1_5_5_5_UNORM, fmt.swap = WXYZ;
358 if (format == VK_FORMAT_B5G5R5A1_UNORM_PACK16)
359 fmt.fmt = FMT6_1_5_5_5_UNORM, fmt.swap = WZYX;
360 } else {
361 fmt.swap = WZYX;
362 }
363
364 return fmt;
365 }
366
367 static void
tu_physical_device_get_format_properties(struct tu_physical_device * physical_device,VkFormat format,VkFormatProperties * out_properties)368 tu_physical_device_get_format_properties(
369 struct tu_physical_device *physical_device,
370 VkFormat format,
371 VkFormatProperties *out_properties)
372 {
373 VkFormatFeatureFlags linear = 0, optimal = 0, buffer = 0;
374 const struct util_format_description *desc = vk_format_description(format);
375 const struct tu_native_format native_fmt = tu6_get_native_format(format);
376 if (!desc || !native_fmt.supported) {
377 goto end;
378 }
379
380 buffer |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
381 if (native_fmt.supported & FMT_VERTEX)
382 buffer |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
383
384 if (native_fmt.supported & FMT_TEXTURE) {
385 optimal |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
386 VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
387 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
388 VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
389 VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT |
390 VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT |
391 VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT;
392
393 buffer |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
394
395 /* no blit src bit for YUYV/NV12/I420 formats */
396 if (desc->layout != UTIL_FORMAT_LAYOUT_SUBSAMPLED &&
397 desc->layout != UTIL_FORMAT_LAYOUT_PLANAR2 &&
398 desc->layout != UTIL_FORMAT_LAYOUT_PLANAR3)
399 optimal |= VK_FORMAT_FEATURE_BLIT_SRC_BIT;
400
401 if (desc->layout != UTIL_FORMAT_LAYOUT_SUBSAMPLED)
402 optimal |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT;
403
404 if (physical_device->supported_extensions.EXT_filter_cubic)
405 optimal |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_EXT;
406 }
407
408 if (native_fmt.supported & FMT_COLOR) {
409 assert(native_fmt.supported & FMT_TEXTURE);
410 optimal |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
411 VK_FORMAT_FEATURE_BLIT_DST_BIT;
412
413 /* IBO's don't have a swap field at all, so swapped formats can't be
414 * supported, even with linear images.
415 *
416 * TODO: See if setting the swap field from the tex descriptor works,
417 * after we enable shaderStorageImageReadWithoutFormat and there are
418 * tests for these formats.
419 */
420 if (native_fmt.swap == WZYX) {
421 optimal |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
422 buffer |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
423 }
424
425 /* TODO: The blob also exposes these for R16G16_UINT/R16G16_SINT, but we
426 * don't have any tests for those.
427 */
428 if (format == VK_FORMAT_R32_UINT || format == VK_FORMAT_R32_SINT) {
429 optimal |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
430 buffer |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
431 }
432
433 if (vk_format_is_float(format) ||
434 vk_format_is_unorm(format) ||
435 vk_format_is_snorm(format) ||
436 vk_format_is_srgb(format)) {
437 optimal |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
438 }
439 }
440
441 /* For the most part, we can do anything with a linear image that we could
442 * do with a tiled image. However, we can't support sysmem rendering with a
443 * linear depth texture, because we don't know if there's a bit to control
444 * the tiling of the depth buffer in BYPASS mode, and the blob also
445 * disables linear depth rendering, so there's no way to discover it. We
446 * also can't force GMEM mode, because there are other situations where we
447 * have to use sysmem rendering. So follow the blob here, and only enable
448 * DEPTH_STENCIL_ATTACHMENT_BIT for the optimal features.
449 */
450 linear = optimal;
451 if (tu6_pipe2depth(format) != (enum a6xx_depth_format)~0)
452 optimal |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
453
454 /* no tiling for special UBWC formats
455 * TODO: NV12 can be UBWC but has a special UBWC format for accessing the Y plane aspect
456 * for 3plane, tiling/UBWC might be supported, but the blob doesn't use tiling
457 */
458 if (format == VK_FORMAT_G8B8G8R8_422_UNORM ||
459 format == VK_FORMAT_B8G8R8G8_422_UNORM ||
460 format == VK_FORMAT_G8_B8R8_2PLANE_420_UNORM ||
461 format == VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM) {
462 optimal = 0;
463 }
464
465 /* D32_SFLOAT_S8_UINT is tiled as two images, so no linear format
466 * blob enables some linear features, but its not useful, so don't bother.
467 */
468 if (format == VK_FORMAT_D32_SFLOAT_S8_UINT)
469 linear = 0;
470
471 end:
472 out_properties->linearTilingFeatures = linear;
473 out_properties->optimalTilingFeatures = optimal;
474 out_properties->bufferFeatures = buffer;
475 }
476
477 void
tu_GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice,VkFormat format,VkFormatProperties2 * pFormatProperties)478 tu_GetPhysicalDeviceFormatProperties2(
479 VkPhysicalDevice physicalDevice,
480 VkFormat format,
481 VkFormatProperties2 *pFormatProperties)
482 {
483 TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice);
484
485 tu_physical_device_get_format_properties(
486 physical_device, format, &pFormatProperties->formatProperties);
487
488 VkDrmFormatModifierPropertiesListEXT *list =
489 vk_find_struct(pFormatProperties->pNext, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT);
490 if (list) {
491 VK_OUTARRAY_MAKE(out, list->pDrmFormatModifierProperties,
492 &list->drmFormatModifierCount);
493
494 if (pFormatProperties->formatProperties.linearTilingFeatures) {
495 vk_outarray_append(&out, mod_props) {
496 mod_props->drmFormatModifier = DRM_FORMAT_MOD_LINEAR;
497 mod_props->drmFormatModifierPlaneCount = 1;
498 }
499 }
500
501 /* note: ubwc_possible() argument values to be ignored except for format */
502 if (pFormatProperties->formatProperties.optimalTilingFeatures &&
503 ubwc_possible(format, VK_IMAGE_TYPE_2D, 0, false)) {
504 vk_outarray_append(&out, mod_props) {
505 mod_props->drmFormatModifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
506 mod_props->drmFormatModifierPlaneCount = 1;
507 }
508 }
509 }
510 }
511
512 static VkResult
tu_get_image_format_properties(struct tu_physical_device * physical_device,const VkPhysicalDeviceImageFormatInfo2 * info,VkImageFormatProperties * pImageFormatProperties,VkFormatFeatureFlags * p_feature_flags)513 tu_get_image_format_properties(
514 struct tu_physical_device *physical_device,
515 const VkPhysicalDeviceImageFormatInfo2 *info,
516 VkImageFormatProperties *pImageFormatProperties,
517 VkFormatFeatureFlags *p_feature_flags)
518 {
519 VkFormatProperties format_props;
520 VkFormatFeatureFlags format_feature_flags;
521 VkExtent3D maxExtent;
522 uint32_t maxMipLevels;
523 uint32_t maxArraySize;
524 VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;
525
526 tu_physical_device_get_format_properties(physical_device, info->format,
527 &format_props);
528
529 switch (info->tiling) {
530 case VK_IMAGE_TILING_LINEAR:
531 format_feature_flags = format_props.linearTilingFeatures;
532 break;
533
534 case VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT: {
535 const VkPhysicalDeviceImageDrmFormatModifierInfoEXT *drm_info =
536 vk_find_struct_const(info->pNext, PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT);
537
538 switch (drm_info->drmFormatModifier) {
539 case DRM_FORMAT_MOD_QCOM_COMPRESSED:
540 /* falling back to linear/non-UBWC isn't possible with explicit modifier */
541
542 /* formats which don't support tiling */
543 if (!format_props.optimalTilingFeatures)
544 return VK_ERROR_FORMAT_NOT_SUPPORTED;
545
546 /* for mutable formats, its very unlikely to be possible to use UBWC */
547 if (info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)
548 return VK_ERROR_FORMAT_NOT_SUPPORTED;
549
550 if (!ubwc_possible(info->format, info->type, info->usage, physical_device->limited_z24s8))
551 return VK_ERROR_FORMAT_NOT_SUPPORTED;
552
553 format_feature_flags = format_props.optimalTilingFeatures;
554 break;
555 case DRM_FORMAT_MOD_LINEAR:
556 format_feature_flags = format_props.linearTilingFeatures;
557 break;
558 default:
559 return VK_ERROR_FORMAT_NOT_SUPPORTED;
560 }
561 } break;
562 case VK_IMAGE_TILING_OPTIMAL:
563 format_feature_flags = format_props.optimalTilingFeatures;
564 break;
565 default:
566 unreachable("bad VkPhysicalDeviceImageFormatInfo2");
567 }
568
569 if (format_feature_flags == 0)
570 goto unsupported;
571
572 if (info->type != VK_IMAGE_TYPE_2D &&
573 vk_format_is_depth_or_stencil(info->format))
574 goto unsupported;
575
576 switch (info->type) {
577 default:
578 unreachable("bad vkimage type\n");
579 case VK_IMAGE_TYPE_1D:
580 maxExtent.width = 16384;
581 maxExtent.height = 1;
582 maxExtent.depth = 1;
583 maxMipLevels = 15; /* log2(maxWidth) + 1 */
584 maxArraySize = 2048;
585 break;
586 case VK_IMAGE_TYPE_2D:
587 maxExtent.width = 16384;
588 maxExtent.height = 16384;
589 maxExtent.depth = 1;
590 maxMipLevels = 15; /* log2(maxWidth) + 1 */
591 maxArraySize = 2048;
592 break;
593 case VK_IMAGE_TYPE_3D:
594 maxExtent.width = 2048;
595 maxExtent.height = 2048;
596 maxExtent.depth = 2048;
597 maxMipLevels = 12; /* log2(maxWidth) + 1 */
598 maxArraySize = 1;
599 break;
600 }
601
602 if (info->tiling == VK_IMAGE_TILING_OPTIMAL &&
603 info->type == VK_IMAGE_TYPE_2D &&
604 (format_feature_flags &
605 (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
606 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) &&
607 !(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
608 !(info->usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
609 sampleCounts |= VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT;
610 /* note: most operations support 8 samples (GMEM render/resolve do at least)
611 * but some do not (which ones?), just disable 8 samples completely,
612 * (no 8x msaa matches the blob driver behavior)
613 */
614 }
615
616 if (info->usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
617 if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
618 goto unsupported;
619 }
620 }
621
622 if (info->usage & VK_IMAGE_USAGE_STORAGE_BIT) {
623 if (!(format_feature_flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) {
624 goto unsupported;
625 }
626 }
627
628 if (info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
629 if (!(format_feature_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) {
630 goto unsupported;
631 }
632 }
633
634 if (info->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
635 if (!(format_feature_flags &
636 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
637 goto unsupported;
638 }
639 }
640
641 *pImageFormatProperties = (VkImageFormatProperties) {
642 .maxExtent = maxExtent,
643 .maxMipLevels = maxMipLevels,
644 .maxArrayLayers = maxArraySize,
645 .sampleCounts = sampleCounts,
646
647 /* FINISHME: Accurately calculate
648 * VkImageFormatProperties::maxResourceSize.
649 */
650 .maxResourceSize = UINT32_MAX,
651 };
652
653 if (p_feature_flags)
654 *p_feature_flags = format_feature_flags;
655
656 return VK_SUCCESS;
657 unsupported:
658 *pImageFormatProperties = (VkImageFormatProperties) {
659 .maxExtent = { 0, 0, 0 },
660 .maxMipLevels = 0,
661 .maxArrayLayers = 0,
662 .sampleCounts = 0,
663 .maxResourceSize = 0,
664 };
665
666 return VK_ERROR_FORMAT_NOT_SUPPORTED;
667 }
668
669 static VkResult
tu_get_external_image_format_properties(const struct tu_physical_device * physical_device,const VkPhysicalDeviceImageFormatInfo2 * pImageFormatInfo,VkExternalMemoryHandleTypeFlagBits handleType,VkExternalMemoryProperties * external_properties)670 tu_get_external_image_format_properties(
671 const struct tu_physical_device *physical_device,
672 const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
673 VkExternalMemoryHandleTypeFlagBits handleType,
674 VkExternalMemoryProperties *external_properties)
675 {
676 VkExternalMemoryFeatureFlagBits flags = 0;
677 VkExternalMemoryHandleTypeFlags export_flags = 0;
678 VkExternalMemoryHandleTypeFlags compat_flags = 0;
679
680 /* From the Vulkan 1.1.98 spec:
681 *
682 * If handleType is not compatible with the format, type, tiling,
683 * usage, and flags specified in VkPhysicalDeviceImageFormatInfo2,
684 * then vkGetPhysicalDeviceImageFormatProperties2 returns
685 * VK_ERROR_FORMAT_NOT_SUPPORTED.
686 */
687
688 switch (handleType) {
689 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
690 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
691 switch (pImageFormatInfo->type) {
692 case VK_IMAGE_TYPE_2D:
693 flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT |
694 VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
695 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
696 compat_flags = export_flags =
697 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
698 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
699 break;
700 default:
701 return vk_errorf(physical_device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
702 "VkExternalMemoryTypeFlagBits(0x%x) unsupported for VkImageType(%d)",
703 handleType, pImageFormatInfo->type);
704 }
705 break;
706 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
707 flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
708 compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
709 break;
710 default:
711 return vk_errorf(physical_device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
712 "VkExternalMemoryTypeFlagBits(0x%x) unsupported",
713 handleType);
714 }
715
716 *external_properties = (VkExternalMemoryProperties) {
717 .externalMemoryFeatures = flags,
718 .exportFromImportedHandleTypes = export_flags,
719 .compatibleHandleTypes = compat_flags,
720 };
721
722 return VK_SUCCESS;
723 }
724
725 VkResult
tu_GetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceImageFormatInfo2 * base_info,VkImageFormatProperties2 * base_props)726 tu_GetPhysicalDeviceImageFormatProperties2(
727 VkPhysicalDevice physicalDevice,
728 const VkPhysicalDeviceImageFormatInfo2 *base_info,
729 VkImageFormatProperties2 *base_props)
730 {
731 TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice);
732 const VkPhysicalDeviceExternalImageFormatInfo *external_info = NULL;
733 const VkPhysicalDeviceImageViewImageFormatInfoEXT *image_view_info = NULL;
734 VkExternalImageFormatProperties *external_props = NULL;
735 VkFilterCubicImageViewImageFormatPropertiesEXT *cubic_props = NULL;
736 VkFormatFeatureFlags format_feature_flags;
737 VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL;
738 VkResult result;
739
740 result = tu_get_image_format_properties(physical_device,
741 base_info, &base_props->imageFormatProperties, &format_feature_flags);
742 if (result != VK_SUCCESS)
743 return result;
744
745 /* Extract input structs */
746 vk_foreach_struct_const(s, base_info->pNext)
747 {
748 switch (s->sType) {
749 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO:
750 external_info = (const void *) s;
751 break;
752 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_IMAGE_FORMAT_INFO_EXT:
753 image_view_info = (const void *) s;
754 break;
755 default:
756 break;
757 }
758 }
759
760 /* Extract output structs */
761 vk_foreach_struct(s, base_props->pNext)
762 {
763 switch (s->sType) {
764 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES:
765 external_props = (void *) s;
766 break;
767 case VK_STRUCTURE_TYPE_FILTER_CUBIC_IMAGE_VIEW_IMAGE_FORMAT_PROPERTIES_EXT:
768 cubic_props = (void *) s;
769 break;
770 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES:
771 ycbcr_props = (void *) s;
772 break;
773 default:
774 break;
775 }
776 }
777
778 /* From the Vulkan 1.0.42 spec:
779 *
780 * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
781 * behave as if VkPhysicalDeviceExternalImageFormatInfo was not
782 * present and VkExternalImageFormatProperties will be ignored.
783 */
784 if (external_info && external_info->handleType != 0) {
785 result = tu_get_external_image_format_properties(
786 physical_device, base_info, external_info->handleType,
787 &external_props->externalMemoryProperties);
788 if (result != VK_SUCCESS)
789 goto fail;
790 }
791
792 if (cubic_props) {
793 /* note: blob only allows cubic filtering for 2D and 2D array views
794 * its likely we can enable it for 1D and CUBE, needs testing however
795 */
796 if ((image_view_info->imageViewType == VK_IMAGE_VIEW_TYPE_2D ||
797 image_view_info->imageViewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY) &&
798 (format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_EXT)) {
799 cubic_props->filterCubic = true;
800 cubic_props->filterCubicMinmax = true;
801 } else {
802 cubic_props->filterCubic = false;
803 cubic_props->filterCubicMinmax = false;
804 }
805 }
806
807 if (ycbcr_props)
808 ycbcr_props->combinedImageSamplerDescriptorCount = 1;
809
810 return VK_SUCCESS;
811
812 fail:
813 if (result == VK_ERROR_FORMAT_NOT_SUPPORTED) {
814 /* From the Vulkan 1.0.42 spec:
815 *
816 * If the combination of parameters to
817 * vkGetPhysicalDeviceImageFormatProperties2 is not supported by
818 * the implementation for use in vkCreateImage, then all members of
819 * imageFormatProperties will be filled with zero.
820 */
821 base_props->imageFormatProperties = (VkImageFormatProperties) {};
822 }
823
824 return result;
825 }
826
827 void
tu_GetPhysicalDeviceSparseImageFormatProperties2(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSparseImageFormatInfo2 * pFormatInfo,uint32_t * pPropertyCount,VkSparseImageFormatProperties2 * pProperties)828 tu_GetPhysicalDeviceSparseImageFormatProperties2(
829 VkPhysicalDevice physicalDevice,
830 const VkPhysicalDeviceSparseImageFormatInfo2 *pFormatInfo,
831 uint32_t *pPropertyCount,
832 VkSparseImageFormatProperties2 *pProperties)
833 {
834 /* Sparse images are not yet supported. */
835 *pPropertyCount = 0;
836 }
837
838 void
tu_GetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceExternalBufferInfo * pExternalBufferInfo,VkExternalBufferProperties * pExternalBufferProperties)839 tu_GetPhysicalDeviceExternalBufferProperties(
840 VkPhysicalDevice physicalDevice,
841 const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo,
842 VkExternalBufferProperties *pExternalBufferProperties)
843 {
844 VkExternalMemoryFeatureFlagBits flags = 0;
845 VkExternalMemoryHandleTypeFlags export_flags = 0;
846 VkExternalMemoryHandleTypeFlags compat_flags = 0;
847 switch (pExternalBufferInfo->handleType) {
848 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
849 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
850 flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
851 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
852 compat_flags = export_flags =
853 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
854 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
855 break;
856 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
857 flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
858 compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
859 break;
860 default:
861 break;
862 }
863 pExternalBufferProperties->externalMemoryProperties =
864 (VkExternalMemoryProperties) {
865 .externalMemoryFeatures = flags,
866 .exportFromImportedHandleTypes = export_flags,
867 .compatibleHandleTypes = compat_flags,
868 };
869 }
870