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