1b8e80941Smrg
2b8e80941Smrg/*
3b8e80941Smrg * Copyright © 2016 Red Hat.
4b8e80941Smrg * Copyright © 2016 Bas Nieuwenhuizen
5b8e80941Smrg *
6b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7b8e80941Smrg * copy of this software and associated documentation files (the "Software"),
8b8e80941Smrg * to deal in the Software without restriction, including without limitation
9b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the
11b8e80941Smrg * Software is furnished to do so, subject to the following conditions:
12b8e80941Smrg *
13b8e80941Smrg * The above copyright notice and this permission notice (including the next
14b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the
15b8e80941Smrg * Software.
16b8e80941Smrg *
17b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23b8e80941Smrg * DEALINGS IN THE SOFTWARE.
24b8e80941Smrg */
25b8e80941Smrg
26b8e80941Smrg#include "tu_private.h"
27b8e80941Smrg
28b8e80941Smrg#include "registers/adreno_common.xml.h"
29b8e80941Smrg#include "registers/a6xx.xml.h"
30b8e80941Smrg
31b8e80941Smrg#include "util/format_r11g11b10f.h"
32b8e80941Smrg#include "util/format_srgb.h"
33b8e80941Smrg#include "util/u_half.h"
34b8e80941Smrg#include "vk_format.h"
35b8e80941Smrg#include "vk_util.h"
36b8e80941Smrg
37b8e80941Smrg/**
38b8e80941Smrg * Declare a format table.  A format table is an array of tu_native_format.
39b8e80941Smrg * It can map a consecutive range of VkFormat to the corresponding
40b8e80941Smrg * tu_native_format.
41b8e80941Smrg *
42b8e80941Smrg * TU_FORMAT_TABLE_FIRST and TU_FORMAT_TABLE_LAST must already be defined and
43b8e80941Smrg * have the values of the first and last VkFormat of the array respectively.
44b8e80941Smrg */
45b8e80941Smrg#define TU_FORMAT_TABLE(var)                                                 \
46b8e80941Smrg   static const VkFormat var##_first = TU_FORMAT_TABLE_FIRST;                \
47b8e80941Smrg   static const VkFormat var##_last = TU_FORMAT_TABLE_LAST;                  \
48b8e80941Smrg   static const struct tu_native_format var[TU_FORMAT_TABLE_LAST - TU_FORMAT_TABLE_FIRST + 1]
49b8e80941Smrg#undef TU_FORMAT_TABLE_FIRST
50b8e80941Smrg#undef TU_FORMAT_TABLE_LAST
51b8e80941Smrg
52b8e80941Smrg#define VFMT6_x -1
53b8e80941Smrg#define TFMT6_x -1
54b8e80941Smrg#define RB6_x -1
55b8e80941Smrg
56b8e80941Smrg#define TU6_FMT(vkfmt, vtxfmt, texfmt, rbfmt, swapfmt, valid)                \
57b8e80941Smrg   [VK_FORMAT_##vkfmt - TU_FORMAT_TABLE_FIRST] = {                           \
58b8e80941Smrg      .vtx = VFMT6_##vtxfmt,                                                 \
59b8e80941Smrg      .tex = TFMT6_##texfmt,                                                 \
60b8e80941Smrg      .rb = RB6_##rbfmt,                                                     \
61b8e80941Smrg      .swap = swapfmt,                                                       \
62b8e80941Smrg      .present = valid,                                                      \
63b8e80941Smrg   }
64b8e80941Smrg
65b8e80941Smrg/**
66b8e80941Smrg * fmt/alias/swap are derived from VkFormat mechanically (and might not even
67b8e80941Smrg * exist).  It is the macro of choice that decides whether a VkFormat is
68b8e80941Smrg * supported and how.
69b8e80941Smrg */
70b8e80941Smrg#define TU6_VTC(vk, fmt, alias, swap) TU6_FMT(vk, fmt, fmt, alias, swap, true)
71b8e80941Smrg#define TU6_xTC(vk, fmt, alias, swap) TU6_FMT(vk, x, fmt, alias, swap, true)
72b8e80941Smrg#define TU6_VTx(vk, fmt, alias, swap) TU6_FMT(vk, fmt, fmt, x, swap, true)
73b8e80941Smrg#define TU6_Vxx(vk, fmt, alias, swap) TU6_FMT(vk, fmt, x, x, swap, true)
74b8e80941Smrg#define TU6_xTx(vk, fmt, alias, swap) TU6_FMT(vk, x, fmt, x, swap, true)
75b8e80941Smrg#define TU6_xxx(vk, fmt, alias, swap) TU6_FMT(vk, x, x, x, WZYX, false)
76b8e80941Smrg
77b8e80941Smrg#define TU_FORMAT_TABLE_FIRST VK_FORMAT_UNDEFINED
78b8e80941Smrg#define TU_FORMAT_TABLE_LAST VK_FORMAT_ASTC_12x12_SRGB_BLOCK
79b8e80941SmrgTU_FORMAT_TABLE(tu6_format_table0) = {
80b8e80941Smrg   TU6_xxx(UNDEFINED,                  x,                 x,                  x),    /* 0 */
81b8e80941Smrg
82b8e80941Smrg   /* 8-bit packed */
83b8e80941Smrg   TU6_xxx(R4G4_UNORM_PACK8,           4_4_UNORM,         R4G4_UNORM,         WZXY), /* 1 */
84b8e80941Smrg
85b8e80941Smrg   /* 16-bit packed */
86b8e80941Smrg   TU6_xTC(R4G4B4A4_UNORM_PACK16,      4_4_4_4_UNORM,     R4G4B4A4_UNORM,     XYZW), /* 2 */
87b8e80941Smrg   TU6_xTC(B4G4R4A4_UNORM_PACK16,      4_4_4_4_UNORM,     R4G4B4A4_UNORM,     ZYXW), /* 3 */
88b8e80941Smrg   TU6_xTC(R5G6B5_UNORM_PACK16,        5_6_5_UNORM,       R5G6B5_UNORM,       WXYZ), /* 4 */
89b8e80941Smrg   TU6_xTC(B5G6R5_UNORM_PACK16,        5_6_5_UNORM,       R5G6B5_UNORM,       WXYZ), /* 5 */
90b8e80941Smrg   TU6_xxx(R5G5B5A1_UNORM_PACK16,      1_5_5_5_UNORM,     A1R5G5B5_UNORM,     XYZW), /* 6 */
91b8e80941Smrg   TU6_xxx(B5G5R5A1_UNORM_PACK16,      1_5_5_5_UNORM,     A1R5G5B5_UNORM,     XYZW), /* 7 */
92b8e80941Smrg   TU6_xTC(A1R5G5B5_UNORM_PACK16,      5_5_5_1_UNORM,     R5G5B5A1_UNORM,     WXYZ), /* 8 */
93b8e80941Smrg
94b8e80941Smrg   /* 8-bit R */
95b8e80941Smrg   TU6_VTC(R8_UNORM,                   8_UNORM,           R8_UNORM,           WZYX), /* 9 */
96b8e80941Smrg   TU6_VTC(R8_SNORM,                   8_SNORM,           R8_SNORM,           WZYX), /* 10 */
97b8e80941Smrg   TU6_Vxx(R8_USCALED,                 8_UINT,            R8_UINT,            WZYX), /* 11 */
98b8e80941Smrg   TU6_Vxx(R8_SSCALED,                 8_SINT,            R8_SINT,            WZYX), /* 12 */
99b8e80941Smrg   TU6_VTC(R8_UINT,                    8_UINT,            R8_UINT,            WZYX), /* 13 */
100b8e80941Smrg   TU6_VTC(R8_SINT,                    8_SINT,            R8_SINT,            WZYX), /* 14 */
101b8e80941Smrg   TU6_xTC(R8_SRGB,                    8_UNORM,           R8_UNORM,           WZYX), /* 15 */
102b8e80941Smrg
103b8e80941Smrg   /* 16-bit RG */
104b8e80941Smrg   TU6_VTC(R8G8_UNORM,                 8_8_UNORM,         R8G8_UNORM,         WZYX), /* 16 */
105b8e80941Smrg   TU6_VTC(R8G8_SNORM,                 8_8_SNORM,         R8G8_SNORM,         WZYX), /* 17 */
106b8e80941Smrg   TU6_Vxx(R8G8_USCALED,               8_8_UINT,          R8G8_UINT,          WZYX), /* 18 */
107b8e80941Smrg   TU6_Vxx(R8G8_SSCALED,               8_8_SINT,          R8G8_SINT,          WZYX), /* 19 */
108b8e80941Smrg   TU6_VTC(R8G8_UINT,                  8_8_UINT,          R8G8_UINT,          WZYX), /* 20 */
109b8e80941Smrg   TU6_VTC(R8G8_SINT,                  8_8_SINT,          R8G8_SINT,          WZYX), /* 21 */
110b8e80941Smrg   TU6_xTC(R8G8_SRGB,                  8_8_UNORM,         R8G8_UNORM,         WZYX), /* 22 */
111b8e80941Smrg
112b8e80941Smrg   /* 24-bit RGB */
113b8e80941Smrg   TU6_Vxx(R8G8B8_UNORM,               8_8_8_UNORM,       R8G8B8_UNORM,       WZYX), /* 23 */
114b8e80941Smrg   TU6_Vxx(R8G8B8_SNORM,               8_8_8_SNORM,       R8G8B8_SNORM,       WZYX), /* 24 */
115b8e80941Smrg   TU6_Vxx(R8G8B8_USCALED,             8_8_8_UINT,        R8G8B8_UINT,        WZYX), /* 25 */
116b8e80941Smrg   TU6_Vxx(R8G8B8_SSCALED,             8_8_8_SINT,        R8G8B8_SINT,        WZYX), /* 26 */
117b8e80941Smrg   TU6_Vxx(R8G8B8_UINT,                8_8_8_UINT,        R8G8B8_UINT,        WZYX), /* 27 */
118b8e80941Smrg   TU6_Vxx(R8G8B8_SINT,                8_8_8_SINT,        R8G8B8_SINT,        WZYX), /* 28 */
119b8e80941Smrg   TU6_xxx(R8G8B8_SRGB,                8_8_8_UNORM,       R8G8B8_UNORM,       WZYX), /* 29 */
120b8e80941Smrg
121b8e80941Smrg   /* 24-bit BGR */
122b8e80941Smrg   TU6_Vxx(B8G8R8_UNORM,               8_8_8_UNORM,       R8G8B8_UNORM,       WXYZ), /* 30 */
123b8e80941Smrg   TU6_Vxx(B8G8R8_SNORM,               8_8_8_SNORM,       R8G8B8_SNORM,       WXYZ), /* 31 */
124b8e80941Smrg   TU6_Vxx(B8G8R8_USCALED,             8_8_8_UINT,        R8G8B8_UINT,        WXYZ), /* 32 */
125b8e80941Smrg   TU6_Vxx(B8G8R8_SSCALED,             8_8_8_SINT,        R8G8B8_SINT,        WXYZ), /* 33 */
126b8e80941Smrg   TU6_Vxx(B8G8R8_UINT,                8_8_8_UINT,        R8G8B8_UINT,        WXYZ), /* 34 */
127b8e80941Smrg   TU6_Vxx(B8G8R8_SINT,                8_8_8_SINT,        R8G8B8_SINT,        WXYZ), /* 35 */
128b8e80941Smrg   TU6_xxx(B8G8R8_SRGB,                8_8_8_UNORM,       R8G8B8_UNORM,       WXYZ), /* 36 */
129b8e80941Smrg
130b8e80941Smrg   /* 32-bit RGBA */
131b8e80941Smrg   TU6_VTC(R8G8B8A8_UNORM,             8_8_8_8_UNORM,     R8G8B8A8_UNORM,     WZYX), /* 37 */
132b8e80941Smrg   TU6_VTC(R8G8B8A8_SNORM,             8_8_8_8_SNORM,     R8G8B8A8_SNORM,     WZYX), /* 38 */
133b8e80941Smrg   TU6_Vxx(R8G8B8A8_USCALED,           8_8_8_8_UINT,      R8G8B8A8_UINT,      WZYX), /* 39 */
134b8e80941Smrg   TU6_Vxx(R8G8B8A8_SSCALED,           8_8_8_8_SINT,      R8G8B8A8_SINT,      WZYX), /* 40 */
135b8e80941Smrg   TU6_VTC(R8G8B8A8_UINT,              8_8_8_8_UINT,      R8G8B8A8_UINT,      WZYX), /* 41 */
136b8e80941Smrg   TU6_VTC(R8G8B8A8_SINT,              8_8_8_8_SINT,      R8G8B8A8_SINT,      WZYX), /* 42 */
137b8e80941Smrg   TU6_xTC(R8G8B8A8_SRGB,              8_8_8_8_UNORM,     R8G8B8A8_UNORM,     WZYX), /* 43 */
138b8e80941Smrg
139b8e80941Smrg   /* 32-bit BGRA */
140b8e80941Smrg   TU6_VTC(B8G8R8A8_UNORM,             8_8_8_8_UNORM,     R8G8B8A8_UNORM,     WXYZ), /* 44 */
141b8e80941Smrg   TU6_VTC(B8G8R8A8_SNORM,             8_8_8_8_SNORM,     R8G8B8A8_SNORM,     WXYZ), /* 45 */
142b8e80941Smrg   TU6_Vxx(B8G8R8A8_USCALED,           8_8_8_8_UINT,      R8G8B8A8_UINT,      WXYZ), /* 46 */
143b8e80941Smrg   TU6_Vxx(B8G8R8A8_SSCALED,           8_8_8_8_SINT,      R8G8B8A8_SINT,      WXYZ), /* 47 */
144b8e80941Smrg   TU6_VTC(B8G8R8A8_UINT,              8_8_8_8_UINT,      R8G8B8A8_UINT,      WXYZ), /* 48 */
145b8e80941Smrg   TU6_VTC(B8G8R8A8_SINT,              8_8_8_8_SINT,      R8G8B8A8_SINT,      WXYZ), /* 49 */
146b8e80941Smrg   TU6_xTC(B8G8R8A8_SRGB,              8_8_8_8_UNORM,     R8G8B8A8_UNORM,     WXYZ), /* 50 */
147b8e80941Smrg
148b8e80941Smrg   /* 32-bit packed */
149b8e80941Smrg   TU6_VTC(A8B8G8R8_UNORM_PACK32,      8_8_8_8_UNORM,     R8G8B8A8_UNORM,     WZYX), /* 51 */
150b8e80941Smrg   TU6_VTC(A8B8G8R8_SNORM_PACK32,      8_8_8_8_SNORM,     R8G8B8A8_SNORM,     WZYX), /* 52 */
151b8e80941Smrg   TU6_Vxx(A8B8G8R8_USCALED_PACK32,    8_8_8_8_UINT,      R8G8B8A8_UINT,      WZYX), /* 53 */
152b8e80941Smrg   TU6_Vxx(A8B8G8R8_SSCALED_PACK32,    8_8_8_8_SINT,      R8G8B8A8_SINT,      WZYX), /* 54 */
153b8e80941Smrg   TU6_VTC(A8B8G8R8_UINT_PACK32,       8_8_8_8_UINT,      R8G8B8A8_UINT,      WZYX), /* 55 */
154b8e80941Smrg   TU6_VTC(A8B8G8R8_SINT_PACK32,       8_8_8_8_SINT,      R8G8B8A8_SINT,      WZYX), /* 56 */
155b8e80941Smrg   TU6_xTC(A8B8G8R8_SRGB_PACK32,       8_8_8_8_UNORM,     R8G8B8A8_UNORM,     WZYX), /* 57 */
156b8e80941Smrg   TU6_VTC(A2R10G10B10_UNORM_PACK32,   10_10_10_2_UNORM,  R10G10B10A2_UNORM,  WXYZ), /* 58 */
157b8e80941Smrg   TU6_Vxx(A2R10G10B10_SNORM_PACK32,   10_10_10_2_SNORM,  R10G10B10A2_SNORM,  WXYZ), /* 59 */
158b8e80941Smrg   TU6_Vxx(A2R10G10B10_USCALED_PACK32, 10_10_10_2_UINT,   R10G10B10A2_UINT,   WXYZ), /* 60 */
159b8e80941Smrg   TU6_Vxx(A2R10G10B10_SSCALED_PACK32, 10_10_10_2_SINT,   R10G10B10A2_SINT,   WXYZ), /* 61 */
160b8e80941Smrg   TU6_VTC(A2R10G10B10_UINT_PACK32,    10_10_10_2_UINT,   R10G10B10A2_UINT,   WXYZ), /* 62 */
161b8e80941Smrg   TU6_Vxx(A2R10G10B10_SINT_PACK32,    10_10_10_2_SINT,   R10G10B10A2_SINT,   WXYZ), /* 63 */
162b8e80941Smrg   TU6_VTC(A2B10G10R10_UNORM_PACK32,   10_10_10_2_UNORM,  R10G10B10A2_UNORM,  WZYX), /* 64 */
163b8e80941Smrg   TU6_Vxx(A2B10G10R10_SNORM_PACK32,   10_10_10_2_SNORM,  R10G10B10A2_SNORM,  WZYX), /* 65 */
164b8e80941Smrg   TU6_Vxx(A2B10G10R10_USCALED_PACK32, 10_10_10_2_UINT,   R10G10B10A2_UINT,   WZYX), /* 66 */
165b8e80941Smrg   TU6_Vxx(A2B10G10R10_SSCALED_PACK32, 10_10_10_2_SINT,   R10G10B10A2_SINT,   WZYX), /* 67 */
166b8e80941Smrg   TU6_VTC(A2B10G10R10_UINT_PACK32,    10_10_10_2_UINT,   R10G10B10A2_UINT,   WZYX), /* 68 */
167b8e80941Smrg   TU6_Vxx(A2B10G10R10_SINT_PACK32,    10_10_10_2_SINT,   R10G10B10A2_SINT,   WZYX), /* 69 */
168b8e80941Smrg
169b8e80941Smrg   /* 16-bit R */
170b8e80941Smrg   TU6_VTC(R16_UNORM,                  16_UNORM,          R16_UNORM,          WZYX), /* 70 */
171b8e80941Smrg   TU6_VTC(R16_SNORM,                  16_SNORM,          R16_SNORM,          WZYX), /* 71 */
172b8e80941Smrg   TU6_Vxx(R16_USCALED,                16_UINT,           R16_UINT,           WZYX), /* 72 */
173b8e80941Smrg   TU6_Vxx(R16_SSCALED,                16_SINT,           R16_SINT,           WZYX), /* 73 */
174b8e80941Smrg   TU6_VTC(R16_UINT,                   16_UINT,           R16_UINT,           WZYX), /* 74 */
175b8e80941Smrg   TU6_VTC(R16_SINT,                   16_SINT,           R16_SINT,           WZYX), /* 75 */
176b8e80941Smrg   TU6_VTC(R16_SFLOAT,                 16_FLOAT,          R16_FLOAT,          WZYX), /* 76 */
177b8e80941Smrg
178b8e80941Smrg   /* 32-bit RG */
179b8e80941Smrg   TU6_VTC(R16G16_UNORM,               16_16_UNORM,       R16G16_UNORM,       WZYX), /* 77 */
180b8e80941Smrg   TU6_VTC(R16G16_SNORM,               16_16_SNORM,       R16G16_SNORM,       WZYX), /* 78 */
181b8e80941Smrg   TU6_VTx(R16G16_USCALED,             16_16_UINT,        R16G16_UINT,        WZYX), /* 79 */
182b8e80941Smrg   TU6_VTx(R16G16_SSCALED,             16_16_SINT,        R16G16_SINT,        WZYX), /* 80 */
183b8e80941Smrg   TU6_VTC(R16G16_UINT,                16_16_UINT,        R16G16_UINT,        WZYX), /* 81 */
184b8e80941Smrg   TU6_VTC(R16G16_SINT,                16_16_SINT,        R16G16_SINT,        WZYX), /* 82 */
185b8e80941Smrg   TU6_VTC(R16G16_SFLOAT,              16_16_FLOAT,       R16G16_FLOAT,       WZYX), /* 83 */
186b8e80941Smrg
187b8e80941Smrg   /* 48-bit RGB */
188b8e80941Smrg   TU6_Vxx(R16G16B16_UNORM,            16_16_16_UNORM,    R16G16B16_UNORM,    WZYX), /* 84 */
189b8e80941Smrg   TU6_Vxx(R16G16B16_SNORM,            16_16_16_SNORM,    R16G16B16_SNORM,    WZYX), /* 85 */
190b8e80941Smrg   TU6_Vxx(R16G16B16_USCALED,          16_16_16_UINT,     R16G16B16_UINT,     WZYX), /* 86 */
191b8e80941Smrg   TU6_Vxx(R16G16B16_SSCALED,          16_16_16_SINT,     R16G16B16_SINT,     WZYX), /* 87 */
192b8e80941Smrg   TU6_Vxx(R16G16B16_UINT,             16_16_16_UINT,     R16G16B16_UINT,     WZYX), /* 88 */
193b8e80941Smrg   TU6_Vxx(R16G16B16_SINT,             16_16_16_SINT,     R16G16B16_SINT,     WZYX), /* 89 */
194b8e80941Smrg   TU6_Vxx(R16G16B16_SFLOAT,           16_16_16_FLOAT,    R16G16B16_FLOAT,    WZYX), /* 90 */
195b8e80941Smrg
196b8e80941Smrg   /* 64-bit RGBA */
197b8e80941Smrg   TU6_VTC(R16G16B16A16_UNORM,         16_16_16_16_UNORM, R16G16B16A16_UNORM, WZYX), /* 91 */
198b8e80941Smrg   TU6_VTC(R16G16B16A16_SNORM,         16_16_16_16_SNORM, R16G16B16A16_SNORM, WZYX), /* 92 */
199b8e80941Smrg   TU6_VTx(R16G16B16A16_USCALED,       16_16_16_16_UINT,  R16G16B16A16_UINT,  WZYX), /* 93 */
200b8e80941Smrg   TU6_VTx(R16G16B16A16_SSCALED,       16_16_16_16_SINT,  R16G16B16A16_SINT,  WZYX), /* 94 */
201b8e80941Smrg   TU6_VTC(R16G16B16A16_UINT,          16_16_16_16_UINT,  R16G16B16A16_UINT,  WZYX), /* 95 */
202b8e80941Smrg   TU6_VTC(R16G16B16A16_SINT,          16_16_16_16_SINT,  R16G16B16A16_SINT,  WZYX), /* 96 */
203b8e80941Smrg   TU6_VTC(R16G16B16A16_SFLOAT,        16_16_16_16_FLOAT, R16G16B16A16_FLOAT, WZYX), /* 97 */
204b8e80941Smrg
205b8e80941Smrg   /* 32-bit R */
206b8e80941Smrg   TU6_VTC(R32_UINT,                   32_UINT,           R32_UINT,           WZYX), /* 98 */
207b8e80941Smrg   TU6_VTC(R32_SINT,                   32_SINT,           R32_SINT,           WZYX), /* 99 */
208b8e80941Smrg   TU6_VTC(R32_SFLOAT,                 32_FLOAT,          R32_FLOAT,          WZYX), /* 100 */
209b8e80941Smrg
210b8e80941Smrg   /* 64-bit RG */
211b8e80941Smrg   TU6_VTC(R32G32_UINT,                32_32_UINT,        R32G32_UINT,        WZYX), /* 101 */
212b8e80941Smrg   TU6_VTC(R32G32_SINT,                32_32_SINT,        R32G32_SINT,        WZYX), /* 102 */
213b8e80941Smrg   TU6_VTC(R32G32_SFLOAT,              32_32_FLOAT,       R32G32_FLOAT,       WZYX), /* 103 */
214b8e80941Smrg
215b8e80941Smrg   /* 96-bit RGB */
216b8e80941Smrg   TU6_VTx(R32G32B32_UINT,             32_32_32_UINT,     R32G32B32_UINT,     WZYX), /* 104 */
217b8e80941Smrg   TU6_VTx(R32G32B32_SINT,             32_32_32_SINT,     R32G32B32_SINT,     WZYX), /* 105 */
218b8e80941Smrg   TU6_VTx(R32G32B32_SFLOAT,           32_32_32_FLOAT,    R32G32B32_FLOAT,    WZYX), /* 106 */
219b8e80941Smrg
220b8e80941Smrg   /* 128-bit RGBA */
221b8e80941Smrg   TU6_VTC(R32G32B32A32_UINT,          32_32_32_32_UINT,  R32G32B32A32_UINT,  WZYX), /* 107 */
222b8e80941Smrg   TU6_VTC(R32G32B32A32_SINT,          32_32_32_32_SINT,  R32G32B32A32_SINT,  WZYX), /* 108 */
223b8e80941Smrg   TU6_VTC(R32G32B32A32_SFLOAT,        32_32_32_32_FLOAT, R32G32B32A32_FLOAT, WZYX), /* 109 */
224b8e80941Smrg
225b8e80941Smrg   /* 64-bit R */
226b8e80941Smrg   TU6_xxx(R64_UINT,                   64_UINT,           R64_UINT,           WZYX), /* 110 */
227b8e80941Smrg   TU6_xxx(R64_SINT,                   64_SINT,           R64_SINT,           WZYX), /* 111 */
228b8e80941Smrg   TU6_xxx(R64_SFLOAT,                 64_FLOAT,          R64_FLOAT,          WZYX), /* 112 */
229b8e80941Smrg
230b8e80941Smrg   /* 128-bit RG */
231b8e80941Smrg   TU6_xxx(R64G64_UINT,                64_64_UINT,        R64G64_UINT,        WZYX), /* 113 */
232b8e80941Smrg   TU6_xxx(R64G64_SINT,                64_64_SINT,        R64G64_SINT,        WZYX), /* 114 */
233b8e80941Smrg   TU6_xxx(R64G64_SFLOAT,              64_64_FLOAT,       R64G64_FLOAT,       WZYX), /* 115 */
234b8e80941Smrg
235b8e80941Smrg   /* 192-bit RGB */
236b8e80941Smrg   TU6_xxx(R64G64B64_UINT,             64_64_64_UINT,     R64G64B64_UINT,     WZYX), /* 116 */
237b8e80941Smrg   TU6_xxx(R64G64B64_SINT,             64_64_64_SINT,     R64G64B64_SINT,     WZYX), /* 117 */
238b8e80941Smrg   TU6_xxx(R64G64B64_SFLOAT,           64_64_64_FLOAT,    R64G64B64_FLOAT,    WZYX), /* 118 */
239b8e80941Smrg
240b8e80941Smrg   /* 256-bit RGBA */
241b8e80941Smrg   TU6_xxx(R64G64B64A64_UINT,          64_64_64_64_UINT,  R64G64B64A64_UINT,  WZYX), /* 119 */
242b8e80941Smrg   TU6_xxx(R64G64B64A64_SINT,          64_64_64_64_SINT,  R64G64B64A64_SINT,  WZYX), /* 120 */
243b8e80941Smrg   TU6_xxx(R64G64B64A64_SFLOAT,        64_64_64_64_FLOAT, R64G64B64A64_FLOAT, WZYX), /* 121 */
244b8e80941Smrg
245b8e80941Smrg   /* 32-bit packed float */
246b8e80941Smrg   TU6_VTC(B10G11R11_UFLOAT_PACK32,    11_11_10_FLOAT,    R11G11B10_FLOAT,    WZYX), /* 122 */
247b8e80941Smrg   TU6_xTx(E5B9G9R9_UFLOAT_PACK32,     9_9_9_E5_FLOAT,    R9G9B9E5_FLOAT,     WZYX), /* 123 */
248b8e80941Smrg
249b8e80941Smrg   /* depth/stencil */
250b8e80941Smrg   TU6_xTC(D16_UNORM,                  16_UNORM,          R16_UNORM,          WZYX), /* 124 */
251b8e80941Smrg   TU6_xTC(X8_D24_UNORM_PACK32,        X8Z24_UNORM,       X8Z24_UNORM,        WZYX), /* 125 */
252b8e80941Smrg   TU6_xTC(D32_SFLOAT,                 32_FLOAT,          R32_FLOAT,          WZYX), /* 126 */
253b8e80941Smrg   TU6_xTC(S8_UINT,                    8_UINT,            R8_UNORM,           WZYX), /* 127 */
254b8e80941Smrg   TU6_xxx(D16_UNORM_S8_UINT,          X8Z16_UNORM,       X8Z16_UNORM,        WZYX), /* 128 */
255b8e80941Smrg   TU6_xTC(D24_UNORM_S8_UINT,          X8Z24_UNORM,       X8Z24_UNORM,        WZYX), /* 129 */
256b8e80941Smrg   TU6_xTC(D32_SFLOAT_S8_UINT,         32_FLOAT,          R32_FLOAT,          WZYX), /* 130 */
257b8e80941Smrg
258b8e80941Smrg   /* compressed */
259b8e80941Smrg   TU6_xTx(BC1_RGB_UNORM_BLOCK,        DXT1,              DXT1,               WZYX), /* 131 */
260b8e80941Smrg   TU6_xTx(BC1_RGB_SRGB_BLOCK,         DXT1,              DXT1,               WZYX), /* 132 */
261b8e80941Smrg   TU6_xTx(BC1_RGBA_UNORM_BLOCK,       DXT1,              DXT1,               WZYX), /* 133 */
262b8e80941Smrg   TU6_xTx(BC1_RGBA_SRGB_BLOCK,        DXT1,              DXT1,               WZYX), /* 134 */
263b8e80941Smrg   TU6_xTx(BC2_UNORM_BLOCK,            DXT3,              DXT3,               WZYX), /* 135 */
264b8e80941Smrg   TU6_xTx(BC2_SRGB_BLOCK,             DXT3,              DXT3,               WZYX), /* 136 */
265b8e80941Smrg   TU6_xTx(BC3_UNORM_BLOCK,            DXT5,              DXT5,               WZYX), /* 137 */
266b8e80941Smrg   TU6_xTx(BC3_SRGB_BLOCK,             DXT5,              DXT5,               WZYX), /* 138 */
267b8e80941Smrg   TU6_xTx(BC4_UNORM_BLOCK,            RGTC1_UNORM,       RGTC1_UNORM,        WZYX), /* 139 */
268b8e80941Smrg   TU6_xTx(BC4_SNORM_BLOCK,            RGTC1_SNORM,       RGTC1_SNORM,        WZYX), /* 140 */
269b8e80941Smrg   TU6_xTx(BC5_UNORM_BLOCK,            RGTC2_UNORM,       RGTC2_UNORM,        WZYX), /* 141 */
270b8e80941Smrg   TU6_xTx(BC5_SNORM_BLOCK,            RGTC2_SNORM,       RGTC2_SNORM,        WZYX), /* 142 */
271b8e80941Smrg   TU6_xTx(BC6H_UFLOAT_BLOCK,          BPTC_UFLOAT,       BPTC_UFLOAT,        WZYX), /* 143 */
272b8e80941Smrg   TU6_xTx(BC6H_SFLOAT_BLOCK,          BPTC_FLOAT,        BPTC_FLOAT,         WZYX), /* 144 */
273b8e80941Smrg   TU6_xTx(BC7_UNORM_BLOCK,            BPTC,              BPTC,               WZYX), /* 145 */
274b8e80941Smrg   TU6_xTx(BC7_SRGB_BLOCK,             BPTC,              BPTC,               WZYX), /* 146 */
275b8e80941Smrg   TU6_xTx(ETC2_R8G8B8_UNORM_BLOCK,    ETC2_RGB8,         ETC2_RGB8,          WZYX), /* 147 */
276b8e80941Smrg   TU6_xTx(ETC2_R8G8B8_SRGB_BLOCK,     ETC2_RGB8,         ETC2_RGB8,          WZYX), /* 148 */
277b8e80941Smrg   TU6_xTx(ETC2_R8G8B8A1_UNORM_BLOCK,  ETC2_RGB8A1,       ETC2_RGB8A1,        WZYX), /* 149 */
278b8e80941Smrg   TU6_xTx(ETC2_R8G8B8A1_SRGB_BLOCK,   ETC2_RGB8A1,       ETC2_RGB8A1,        WZYX), /* 150 */
279b8e80941Smrg   TU6_xTx(ETC2_R8G8B8A8_UNORM_BLOCK,  ETC2_RGBA8,        ETC2_RGBA8,         WZYX), /* 151 */
280b8e80941Smrg   TU6_xTx(ETC2_R8G8B8A8_SRGB_BLOCK,   ETC2_RGBA8,        ETC2_RGBA8,         WZYX), /* 152 */
281b8e80941Smrg   TU6_xTx(EAC_R11_UNORM_BLOCK,        ETC2_R11_UNORM,    ETC2_R11_UNORM,     WZYX), /* 153 */
282b8e80941Smrg   TU6_xTx(EAC_R11_SNORM_BLOCK,        ETC2_R11_SNORM,    ETC2_R11_SNORM,     WZYX), /* 154 */
283b8e80941Smrg   TU6_xTx(EAC_R11G11_UNORM_BLOCK,     ETC2_RG11_UNORM,   ETC2_RG11_UNORM,    WZYX), /* 155 */
284b8e80941Smrg   TU6_xTx(EAC_R11G11_SNORM_BLOCK,     ETC2_RG11_SNORM,   ETC2_RG11_SNORM,    WZYX), /* 156 */
285b8e80941Smrg   TU6_xTx(ASTC_4x4_UNORM_BLOCK,       ASTC_4x4,          ASTC_4x4,           WZYX), /* 157 */
286b8e80941Smrg   TU6_xTx(ASTC_4x4_SRGB_BLOCK,        ASTC_4x4,          ASTC_4x4,           WZYX), /* 158 */
287b8e80941Smrg   TU6_xTx(ASTC_5x4_UNORM_BLOCK,       ASTC_5x4,          ASTC_5x4,           WZYX), /* 159 */
288b8e80941Smrg   TU6_xTx(ASTC_5x4_SRGB_BLOCK,        ASTC_5x4,          ASTC_5x4,           WZYX), /* 160 */
289b8e80941Smrg   TU6_xTx(ASTC_5x5_UNORM_BLOCK,       ASTC_5x5,          ASTC_5x5,           WZYX), /* 161 */
290b8e80941Smrg   TU6_xTx(ASTC_5x5_SRGB_BLOCK,        ASTC_5x5,          ASTC_5x5,           WZYX), /* 162 */
291b8e80941Smrg   TU6_xTx(ASTC_6x5_UNORM_BLOCK,       ASTC_6x5,          ASTC_6x5,           WZYX), /* 163 */
292b8e80941Smrg   TU6_xTx(ASTC_6x5_SRGB_BLOCK,        ASTC_6x5,          ASTC_6x5,           WZYX), /* 164 */
293b8e80941Smrg   TU6_xTx(ASTC_6x6_UNORM_BLOCK,       ASTC_6x6,          ASTC_6x6,           WZYX), /* 165 */
294b8e80941Smrg   TU6_xTx(ASTC_6x6_SRGB_BLOCK,        ASTC_6x6,          ASTC_6x6,           WZYX), /* 166 */
295b8e80941Smrg   TU6_xTx(ASTC_8x5_UNORM_BLOCK,       ASTC_8x5,          ASTC_8x5,           WZYX), /* 167 */
296b8e80941Smrg   TU6_xTx(ASTC_8x5_SRGB_BLOCK,        ASTC_8x5,          ASTC_8x5,           WZYX), /* 168 */
297b8e80941Smrg   TU6_xTx(ASTC_8x6_UNORM_BLOCK,       ASTC_8x6,          ASTC_8x6,           WZYX), /* 169 */
298b8e80941Smrg   TU6_xTx(ASTC_8x6_SRGB_BLOCK,        ASTC_8x6,          ASTC_8x6,           WZYX), /* 170 */
299b8e80941Smrg   TU6_xTx(ASTC_8x8_UNORM_BLOCK,       ASTC_8x8,          ASTC_8x8,           WZYX), /* 171 */
300b8e80941Smrg   TU6_xTx(ASTC_8x8_SRGB_BLOCK,        ASTC_8x8,          ASTC_8x8,           WZYX), /* 172 */
301b8e80941Smrg   TU6_xTx(ASTC_10x5_UNORM_BLOCK,      ASTC_10x5,         ASTC_10x5,          WZYX), /* 173 */
302b8e80941Smrg   TU6_xTx(ASTC_10x5_SRGB_BLOCK,       ASTC_10x5,         ASTC_10x5,          WZYX), /* 174 */
303b8e80941Smrg   TU6_xTx(ASTC_10x6_UNORM_BLOCK,      ASTC_10x6,         ASTC_10x6,          WZYX), /* 175 */
304b8e80941Smrg   TU6_xTx(ASTC_10x6_SRGB_BLOCK,       ASTC_10x6,         ASTC_10x6,          WZYX), /* 176 */
305b8e80941Smrg   TU6_xTx(ASTC_10x8_UNORM_BLOCK,      ASTC_10x8,         ASTC_10x8,          WZYX), /* 177 */
306b8e80941Smrg   TU6_xTx(ASTC_10x8_SRGB_BLOCK,       ASTC_10x8,         ASTC_10x8,          WZYX), /* 178 */
307b8e80941Smrg   TU6_xTx(ASTC_10x10_UNORM_BLOCK,     ASTC_10x10,        ASTC_10x10,         WZYX), /* 179 */
308b8e80941Smrg   TU6_xTx(ASTC_10x10_SRGB_BLOCK,      ASTC_10x10,        ASTC_10x10,         WZYX), /* 180 */
309b8e80941Smrg   TU6_xTx(ASTC_12x10_UNORM_BLOCK,     ASTC_12x10,        ASTC_12x10,         WZYX), /* 181 */
310b8e80941Smrg   TU6_xTx(ASTC_12x10_SRGB_BLOCK,      ASTC_12x10,        ASTC_12x10,         WZYX), /* 182 */
311b8e80941Smrg   TU6_xTx(ASTC_12x12_UNORM_BLOCK,     ASTC_12x12,        ASTC_12x12,         WZYX), /* 183 */
312b8e80941Smrg   TU6_xTx(ASTC_12x12_SRGB_BLOCK,      ASTC_12x12,        ASTC_12x12,         WZYX), /* 184 */
313b8e80941Smrg};
314b8e80941Smrg#undef TU_FORMAT_TABLE_FIRST
315b8e80941Smrg#undef TU_FORMAT_TABLE_LAST
316b8e80941Smrg
317b8e80941Smrgconst struct tu_native_format *
318b8e80941Smrgtu6_get_native_format(VkFormat format)
319b8e80941Smrg{
320b8e80941Smrg   const struct tu_native_format *fmt = NULL;
321b8e80941Smrg
322b8e80941Smrg   if (format >= tu6_format_table0_first && format <= tu6_format_table0_last)
323b8e80941Smrg      fmt = &tu6_format_table0[format - tu6_format_table0_first];
324b8e80941Smrg
325b8e80941Smrg   return (fmt && fmt->present) ? fmt : NULL;
326b8e80941Smrg}
327b8e80941Smrg
328b8e80941Smrgenum a6xx_2d_ifmt
329b8e80941Smrgtu6_rb_fmt_to_ifmt(enum a6xx_color_fmt fmt)
330b8e80941Smrg{
331b8e80941Smrg   switch (fmt) {
332b8e80941Smrg   case RB6_A8_UNORM:
333b8e80941Smrg   case RB6_R8_UNORM:
334b8e80941Smrg   case RB6_R8_SNORM:
335b8e80941Smrg   case RB6_R8G8_UNORM:
336b8e80941Smrg   case RB6_R8G8_SNORM:
337b8e80941Smrg   case RB6_R8G8B8A8_UNORM:
338b8e80941Smrg   case RB6_R8G8B8_UNORM:
339b8e80941Smrg   case RB6_R8G8B8A8_SNORM:
340b8e80941Smrg      return R2D_UNORM8;
341b8e80941Smrg
342b8e80941Smrg   case RB6_R32_UINT:
343b8e80941Smrg   case RB6_R32_SINT:
344b8e80941Smrg   case RB6_R32G32_UINT:
345b8e80941Smrg   case RB6_R32G32_SINT:
346b8e80941Smrg   case RB6_R32G32B32A32_UINT:
347b8e80941Smrg   case RB6_R32G32B32A32_SINT:
348b8e80941Smrg      return R2D_INT32;
349b8e80941Smrg
350b8e80941Smrg   case RB6_R16_UINT:
351b8e80941Smrg   case RB6_R16_SINT:
352b8e80941Smrg   case RB6_R16G16_UINT:
353b8e80941Smrg   case RB6_R16G16_SINT:
354b8e80941Smrg   case RB6_R16G16B16A16_UINT:
355b8e80941Smrg   case RB6_R16G16B16A16_SINT:
356b8e80941Smrg      return R2D_INT16;
357b8e80941Smrg
358b8e80941Smrg   case RB6_R8_UINT:
359b8e80941Smrg   case RB6_R8_SINT:
360b8e80941Smrg   case RB6_R8G8_UINT:
361b8e80941Smrg   case RB6_R8G8_SINT:
362b8e80941Smrg   case RB6_R8G8B8A8_UINT:
363b8e80941Smrg   case RB6_R8G8B8A8_SINT:
364b8e80941Smrg      return R2D_INT8;
365b8e80941Smrg
366b8e80941Smrg   case RB6_R16_UNORM:
367b8e80941Smrg   case RB6_R16_SNORM:
368b8e80941Smrg   case RB6_R16G16_UNORM:
369b8e80941Smrg   case RB6_R16G16_SNORM:
370b8e80941Smrg   case RB6_R16G16B16A16_UNORM:
371b8e80941Smrg   case RB6_R16G16B16A16_SNORM:
372b8e80941Smrg   case RB6_R32_FLOAT:
373b8e80941Smrg   case RB6_R32G32_FLOAT:
374b8e80941Smrg   case RB6_R32G32B32A32_FLOAT:
375b8e80941Smrg      return R2D_FLOAT32;
376b8e80941Smrg
377b8e80941Smrg   case RB6_R16_FLOAT:
378b8e80941Smrg   case RB6_R16G16_FLOAT:
379b8e80941Smrg   case RB6_R16G16B16A16_FLOAT:
380b8e80941Smrg      return R2D_FLOAT16;
381b8e80941Smrg
382b8e80941Smrg   case RB6_R4G4B4A4_UNORM:
383b8e80941Smrg   case RB6_R5G5B5A1_UNORM:
384b8e80941Smrg   case RB6_R5G6B5_UNORM:
385b8e80941Smrg   case RB6_R10G10B10A2_UNORM:
386b8e80941Smrg   case RB6_R10G10B10A2_UINT:
387b8e80941Smrg   case RB6_R11G11B10_FLOAT:
388b8e80941Smrg   case RB6_X8Z24_UNORM:
389b8e80941Smrg      // ???
390b8e80941Smrg      return 0;
391b8e80941Smrg   default:
392b8e80941Smrg      unreachable("bad format");
393b8e80941Smrg      return 0;
394b8e80941Smrg   }
395b8e80941Smrg}
396b8e80941Smrg
397b8e80941Smrgstatic uint32_t
398b8e80941Smrgtu_pack_mask(int bits)
399b8e80941Smrg{
400b8e80941Smrg   assert(bits <= 32);
401b8e80941Smrg   return (1ull << bits) - 1;
402b8e80941Smrg}
403b8e80941Smrg
404b8e80941Smrgstatic uint32_t
405b8e80941Smrgtu_pack_float32_for_unorm(float val, int bits)
406b8e80941Smrg{
407b8e80941Smrg   const uint32_t max = tu_pack_mask(bits);
408b8e80941Smrg   if (val < 0.0f)
409b8e80941Smrg      return 0;
410b8e80941Smrg   else if (val > 1.0f)
411b8e80941Smrg      return max;
412b8e80941Smrg   else
413b8e80941Smrg      return _mesa_lroundevenf(val * (float) max);
414b8e80941Smrg}
415b8e80941Smrg
416b8e80941Smrgstatic uint32_t
417b8e80941Smrgtu_pack_float32_for_snorm(float val, int bits)
418b8e80941Smrg{
419b8e80941Smrg   const int32_t max = tu_pack_mask(bits - 1);
420b8e80941Smrg   int32_t tmp;
421b8e80941Smrg   if (val < -1.0f)
422b8e80941Smrg      tmp = -max;
423b8e80941Smrg   else if (val > 1.0f)
424b8e80941Smrg      tmp = max;
425b8e80941Smrg   else
426b8e80941Smrg      tmp = _mesa_lroundevenf(val * (float) max);
427b8e80941Smrg
428b8e80941Smrg   return tmp & tu_pack_mask(bits);
429b8e80941Smrg}
430b8e80941Smrg
431b8e80941Smrgstatic uint32_t
432b8e80941Smrgtu_pack_float32_for_uscaled(float val, int bits)
433b8e80941Smrg{
434b8e80941Smrg   const uint32_t max = tu_pack_mask(bits);
435b8e80941Smrg   if (val < 0.0f)
436b8e80941Smrg      return 0;
437b8e80941Smrg   else if (val > (float) max)
438b8e80941Smrg      return max;
439b8e80941Smrg   else
440b8e80941Smrg      return (uint32_t) val;
441b8e80941Smrg}
442b8e80941Smrg
443b8e80941Smrgstatic uint32_t
444b8e80941Smrgtu_pack_float32_for_sscaled(float val, int bits)
445b8e80941Smrg{
446b8e80941Smrg   const int32_t max = tu_pack_mask(bits - 1);
447b8e80941Smrg   const int32_t min = -max - 1;
448b8e80941Smrg   int32_t tmp;
449b8e80941Smrg   if (val < (float) min)
450b8e80941Smrg      tmp = min;
451b8e80941Smrg   else if (val > (float) max)
452b8e80941Smrg      tmp = max;
453b8e80941Smrg   else
454b8e80941Smrg      tmp = (int32_t) val;
455b8e80941Smrg
456b8e80941Smrg   return tmp & tu_pack_mask(bits);
457b8e80941Smrg}
458b8e80941Smrg
459b8e80941Smrgstatic uint32_t
460b8e80941Smrgtu_pack_uint32_for_uint(uint32_t val, int bits)
461b8e80941Smrg{
462b8e80941Smrg   return val & tu_pack_mask(bits);
463b8e80941Smrg}
464b8e80941Smrg
465b8e80941Smrgstatic uint32_t
466b8e80941Smrgtu_pack_int32_for_sint(int32_t val, int bits)
467b8e80941Smrg{
468b8e80941Smrg   return val & tu_pack_mask(bits);
469b8e80941Smrg}
470b8e80941Smrg
471b8e80941Smrgstatic uint32_t
472b8e80941Smrgtu_pack_float32_for_sfloat(float val, int bits)
473b8e80941Smrg{
474b8e80941Smrg   assert(bits == 16 || bits == 32);
475b8e80941Smrg   return bits == 16 ? util_float_to_half(val) : fui(val);
476b8e80941Smrg}
477b8e80941Smrg
478b8e80941Smrgunion tu_clear_component_value {
479b8e80941Smrg   float float32;
480b8e80941Smrg   int32_t int32;
481b8e80941Smrg   uint32_t uint32;
482b8e80941Smrg};
483b8e80941Smrg
484b8e80941Smrgstatic uint32_t
485b8e80941Smrgtu_pack_clear_component_value(union tu_clear_component_value val,
486b8e80941Smrg                              const struct vk_format_channel_description *ch)
487b8e80941Smrg{
488b8e80941Smrg   uint32_t packed;
489b8e80941Smrg
490b8e80941Smrg   switch (ch->type) {
491b8e80941Smrg   case VK_FORMAT_TYPE_UNSIGNED:
492b8e80941Smrg      /* normalized, scaled, or pure integer */
493b8e80941Smrg      assert(ch->normalized + ch->scaled + ch->pure_integer == 1);
494b8e80941Smrg      if (ch->normalized)
495b8e80941Smrg         packed = tu_pack_float32_for_unorm(val.float32, ch->size);
496b8e80941Smrg      else if (ch->scaled)
497b8e80941Smrg         packed = tu_pack_float32_for_uscaled(val.float32, ch->size);
498b8e80941Smrg      else
499b8e80941Smrg         packed = tu_pack_uint32_for_uint(val.uint32, ch->size);
500b8e80941Smrg      break;
501b8e80941Smrg   case VK_FORMAT_TYPE_SIGNED:
502b8e80941Smrg      /* normalized, scaled, or pure integer */
503b8e80941Smrg      assert(ch->normalized + ch->scaled + ch->pure_integer == 1);
504b8e80941Smrg      if (ch->normalized)
505b8e80941Smrg         packed = tu_pack_float32_for_snorm(val.float32, ch->size);
506b8e80941Smrg      else if (ch->scaled)
507b8e80941Smrg         packed = tu_pack_float32_for_sscaled(val.float32, ch->size);
508b8e80941Smrg      else
509b8e80941Smrg         packed = tu_pack_int32_for_sint(val.int32, ch->size);
510b8e80941Smrg      break;
511b8e80941Smrg   case VK_FORMAT_TYPE_FLOAT:
512b8e80941Smrg      packed = tu_pack_float32_for_sfloat(val.float32, ch->size);
513b8e80941Smrg      break;
514b8e80941Smrg   default:
515b8e80941Smrg      unreachable("unexpected channel type");
516b8e80941Smrg      packed = 0;
517b8e80941Smrg      break;
518b8e80941Smrg   }
519b8e80941Smrg
520b8e80941Smrg   assert((packed & tu_pack_mask(ch->size)) == packed);
521b8e80941Smrg   return packed;
522b8e80941Smrg}
523b8e80941Smrg
524b8e80941Smrgstatic const struct vk_format_channel_description *
525b8e80941Smrgtu_get_format_channel_description(const struct vk_format_description *desc,
526b8e80941Smrg                                  int comp)
527b8e80941Smrg{
528b8e80941Smrg   switch (desc->swizzle[comp]) {
529b8e80941Smrg   case VK_SWIZZLE_X:
530b8e80941Smrg      return &desc->channel[0];
531b8e80941Smrg   case VK_SWIZZLE_Y:
532b8e80941Smrg      return &desc->channel[1];
533b8e80941Smrg   case VK_SWIZZLE_Z:
534b8e80941Smrg      return &desc->channel[2];
535b8e80941Smrg   case VK_SWIZZLE_W:
536b8e80941Smrg      return &desc->channel[3];
537b8e80941Smrg   default:
538b8e80941Smrg      return NULL;
539b8e80941Smrg   }
540b8e80941Smrg}
541b8e80941Smrg
542b8e80941Smrgstatic union tu_clear_component_value
543b8e80941Smrgtu_get_clear_component_value(const VkClearValue *val, int comp, bool color)
544b8e80941Smrg{
545b8e80941Smrg   union tu_clear_component_value tmp;
546b8e80941Smrg   if (color) {
547b8e80941Smrg      assert(comp < 4);
548b8e80941Smrg      tmp.uint32 = val->color.uint32[comp];
549b8e80941Smrg   } else {
550b8e80941Smrg      assert(comp < 2);
551b8e80941Smrg      if (comp == 0)
552b8e80941Smrg         tmp.float32 = val->depthStencil.depth;
553b8e80941Smrg      else
554b8e80941Smrg         tmp.uint32 = val->depthStencil.stencil;
555b8e80941Smrg   }
556b8e80941Smrg
557b8e80941Smrg   return tmp;
558b8e80941Smrg}
559b8e80941Smrg
560b8e80941Smrg/**
561b8e80941Smrg * Pack a VkClearValue into a 128-bit buffer.  \a format is respected except
562b8e80941Smrg * for the component order.  The components are always packed in WZYX order
563b8e80941Smrg * (i.e., msb is white and lsb is red).
564b8e80941Smrg *
565b8e80941Smrg * Return the number of uint32_t's used.
566b8e80941Smrg */
567b8e80941Smrgint
568b8e80941Smrgtu_pack_clear_value(const VkClearValue *val, VkFormat format, uint32_t buf[4])
569b8e80941Smrg{
570b8e80941Smrg   const struct vk_format_description *desc = vk_format_description(format);
571b8e80941Smrg   assert(desc && desc->layout == VK_FORMAT_LAYOUT_PLAIN);
572b8e80941Smrg
573b8e80941Smrg   /* S8_UINT is special and has no depth */
574b8e80941Smrg   const int max_components =
575b8e80941Smrg      format == VK_FORMAT_S8_UINT ? 2 : desc->nr_channels;
576b8e80941Smrg
577b8e80941Smrg   int buf_offset = 0;
578b8e80941Smrg   int bit_shift = 0;
579b8e80941Smrg   for (int comp = 0; comp < max_components; comp++) {
580b8e80941Smrg      const struct vk_format_channel_description *ch =
581b8e80941Smrg         tu_get_format_channel_description(desc, comp);
582b8e80941Smrg      if (!ch) {
583b8e80941Smrg         assert(format == VK_FORMAT_S8_UINT && comp == 0);
584b8e80941Smrg         continue;
585b8e80941Smrg      }
586b8e80941Smrg
587b8e80941Smrg      union tu_clear_component_value v = tu_get_clear_component_value(
588b8e80941Smrg         val, comp, desc->colorspace != VK_FORMAT_COLORSPACE_ZS);
589b8e80941Smrg
590b8e80941Smrg      /* move to the next uint32_t when there is not enough space */
591b8e80941Smrg      assert(ch->size <= 32);
592b8e80941Smrg      if (bit_shift + ch->size > 32) {
593b8e80941Smrg         buf_offset++;
594b8e80941Smrg         bit_shift = 0;
595b8e80941Smrg      }
596b8e80941Smrg
597b8e80941Smrg      if (bit_shift == 0)
598b8e80941Smrg         buf[buf_offset] = 0;
599b8e80941Smrg
600b8e80941Smrg      buf[buf_offset] |= tu_pack_clear_component_value(v, ch) << bit_shift;
601b8e80941Smrg      bit_shift += ch->size;
602b8e80941Smrg   }
603b8e80941Smrg
604b8e80941Smrg   return buf_offset + 1;
605b8e80941Smrg}
606b8e80941Smrg
607b8e80941Smrgstatic void
608b8e80941Smrgtu_physical_device_get_format_properties(
609b8e80941Smrg   struct tu_physical_device *physical_device,
610b8e80941Smrg   VkFormat format,
611b8e80941Smrg   VkFormatProperties *out_properties)
612b8e80941Smrg{
613b8e80941Smrg   VkFormatFeatureFlags linear = 0, tiled = 0, buffer = 0;
614b8e80941Smrg   const struct vk_format_description *desc = vk_format_description(format);
615b8e80941Smrg   const struct tu_native_format *native_fmt = tu6_get_native_format(format);
616b8e80941Smrg   if (!desc || !native_fmt) {
617b8e80941Smrg      out_properties->linearTilingFeatures = linear;
618b8e80941Smrg      out_properties->optimalTilingFeatures = tiled;
619b8e80941Smrg      out_properties->bufferFeatures = buffer;
620b8e80941Smrg      return;
621b8e80941Smrg   }
622b8e80941Smrg
623b8e80941Smrg   linear |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
624b8e80941Smrg   tiled |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
625b8e80941Smrg   buffer |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
626b8e80941Smrg
627b8e80941Smrg   if (native_fmt->tex >= 0) {
628b8e80941Smrg      linear |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
629b8e80941Smrg      tiled |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
630b8e80941Smrg      buffer |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
631b8e80941Smrg   }
632b8e80941Smrg
633b8e80941Smrg   if (native_fmt->rb >= 0) {
634b8e80941Smrg      linear |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
635b8e80941Smrg      tiled |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
636b8e80941Smrg   }
637b8e80941Smrg
638b8e80941Smrg   if (native_fmt->vtx >= 0) {
639b8e80941Smrg      buffer |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
640b8e80941Smrg   }
641b8e80941Smrg
642b8e80941Smrg   out_properties->linearTilingFeatures = linear;
643b8e80941Smrg   out_properties->optimalTilingFeatures = tiled;
644b8e80941Smrg   out_properties->bufferFeatures = buffer;
645b8e80941Smrg}
646b8e80941Smrg
647b8e80941Smrgvoid
648b8e80941Smrgtu_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
649b8e80941Smrg                                     VkFormat format,
650b8e80941Smrg                                     VkFormatProperties *pFormatProperties)
651b8e80941Smrg{
652b8e80941Smrg   TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice);
653b8e80941Smrg
654b8e80941Smrg   tu_physical_device_get_format_properties(physical_device, format,
655b8e80941Smrg                                            pFormatProperties);
656b8e80941Smrg}
657b8e80941Smrg
658b8e80941Smrgvoid
659b8e80941Smrgtu_GetPhysicalDeviceFormatProperties2(
660b8e80941Smrg   VkPhysicalDevice physicalDevice,
661b8e80941Smrg   VkFormat format,
662b8e80941Smrg   VkFormatProperties2 *pFormatProperties)
663b8e80941Smrg{
664b8e80941Smrg   TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice);
665b8e80941Smrg
666b8e80941Smrg   tu_physical_device_get_format_properties(
667b8e80941Smrg      physical_device, format, &pFormatProperties->formatProperties);
668b8e80941Smrg}
669b8e80941Smrg
670b8e80941Smrgstatic VkResult
671b8e80941Smrgtu_get_image_format_properties(
672b8e80941Smrg   struct tu_physical_device *physical_device,
673b8e80941Smrg   const VkPhysicalDeviceImageFormatInfo2 *info,
674b8e80941Smrg   VkImageFormatProperties *pImageFormatProperties)
675b8e80941Smrg
676b8e80941Smrg{
677b8e80941Smrg   VkFormatProperties format_props;
678b8e80941Smrg   VkFormatFeatureFlags format_feature_flags;
679b8e80941Smrg   VkExtent3D maxExtent;
680b8e80941Smrg   uint32_t maxMipLevels;
681b8e80941Smrg   uint32_t maxArraySize;
682b8e80941Smrg   VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;
683b8e80941Smrg
684b8e80941Smrg   tu_physical_device_get_format_properties(physical_device, info->format,
685b8e80941Smrg                                            &format_props);
686b8e80941Smrg   if (info->tiling == VK_IMAGE_TILING_LINEAR) {
687b8e80941Smrg      format_feature_flags = format_props.linearTilingFeatures;
688b8e80941Smrg   } else if (info->tiling == VK_IMAGE_TILING_OPTIMAL) {
689b8e80941Smrg      format_feature_flags = format_props.optimalTilingFeatures;
690b8e80941Smrg   } else {
691b8e80941Smrg      unreachable("bad VkImageTiling");
692b8e80941Smrg   }
693b8e80941Smrg
694b8e80941Smrg   if (format_feature_flags == 0)
695b8e80941Smrg      goto unsupported;
696b8e80941Smrg
697b8e80941Smrg   if (info->type != VK_IMAGE_TYPE_2D &&
698b8e80941Smrg       vk_format_is_depth_or_stencil(info->format))
699b8e80941Smrg      goto unsupported;
700b8e80941Smrg
701b8e80941Smrg   switch (info->type) {
702b8e80941Smrg   default:
703b8e80941Smrg      unreachable("bad vkimage type\n");
704b8e80941Smrg   case VK_IMAGE_TYPE_1D:
705b8e80941Smrg      maxExtent.width = 16384;
706b8e80941Smrg      maxExtent.height = 1;
707b8e80941Smrg      maxExtent.depth = 1;
708b8e80941Smrg      maxMipLevels = 15; /* log2(maxWidth) + 1 */
709b8e80941Smrg      maxArraySize = 2048;
710b8e80941Smrg      break;
711b8e80941Smrg   case VK_IMAGE_TYPE_2D:
712b8e80941Smrg      maxExtent.width = 16384;
713b8e80941Smrg      maxExtent.height = 16384;
714b8e80941Smrg      maxExtent.depth = 1;
715b8e80941Smrg      maxMipLevels = 15; /* log2(maxWidth) + 1 */
716b8e80941Smrg      maxArraySize = 2048;
717b8e80941Smrg      break;
718b8e80941Smrg   case VK_IMAGE_TYPE_3D:
719b8e80941Smrg      maxExtent.width = 2048;
720b8e80941Smrg      maxExtent.height = 2048;
721b8e80941Smrg      maxExtent.depth = 2048;
722b8e80941Smrg      maxMipLevels = 12; /* log2(maxWidth) + 1 */
723b8e80941Smrg      maxArraySize = 1;
724b8e80941Smrg      break;
725b8e80941Smrg   }
726b8e80941Smrg
727b8e80941Smrg   if (info->tiling == VK_IMAGE_TILING_OPTIMAL &&
728b8e80941Smrg       info->type == VK_IMAGE_TYPE_2D &&
729b8e80941Smrg       (format_feature_flags &
730b8e80941Smrg        (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
731b8e80941Smrg         VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) &&
732b8e80941Smrg       !(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
733b8e80941Smrg       !(info->usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
734b8e80941Smrg      sampleCounts |= VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT |
735b8e80941Smrg                      VK_SAMPLE_COUNT_8_BIT;
736b8e80941Smrg   }
737b8e80941Smrg
738b8e80941Smrg   if (info->usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
739b8e80941Smrg      if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
740b8e80941Smrg         goto unsupported;
741b8e80941Smrg      }
742b8e80941Smrg   }
743b8e80941Smrg
744b8e80941Smrg   if (info->usage & VK_IMAGE_USAGE_STORAGE_BIT) {
745b8e80941Smrg      if (!(format_feature_flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) {
746b8e80941Smrg         goto unsupported;
747b8e80941Smrg      }
748b8e80941Smrg   }
749b8e80941Smrg
750b8e80941Smrg   if (info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
751b8e80941Smrg      if (!(format_feature_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) {
752b8e80941Smrg         goto unsupported;
753b8e80941Smrg      }
754b8e80941Smrg   }
755b8e80941Smrg
756b8e80941Smrg   if (info->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
757b8e80941Smrg      if (!(format_feature_flags &
758b8e80941Smrg            VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
759b8e80941Smrg         goto unsupported;
760b8e80941Smrg      }
761b8e80941Smrg   }
762b8e80941Smrg
763b8e80941Smrg   *pImageFormatProperties = (VkImageFormatProperties) {
764b8e80941Smrg      .maxExtent = maxExtent,
765b8e80941Smrg      .maxMipLevels = maxMipLevels,
766b8e80941Smrg      .maxArrayLayers = maxArraySize,
767b8e80941Smrg      .sampleCounts = sampleCounts,
768b8e80941Smrg
769b8e80941Smrg      /* FINISHME: Accurately calculate
770b8e80941Smrg       * VkImageFormatProperties::maxResourceSize.
771b8e80941Smrg       */
772b8e80941Smrg      .maxResourceSize = UINT32_MAX,
773b8e80941Smrg   };
774b8e80941Smrg
775b8e80941Smrg   return VK_SUCCESS;
776b8e80941Smrgunsupported:
777b8e80941Smrg   *pImageFormatProperties = (VkImageFormatProperties) {
778b8e80941Smrg      .maxExtent = { 0, 0, 0 },
779b8e80941Smrg      .maxMipLevels = 0,
780b8e80941Smrg      .maxArrayLayers = 0,
781b8e80941Smrg      .sampleCounts = 0,
782b8e80941Smrg      .maxResourceSize = 0,
783b8e80941Smrg   };
784b8e80941Smrg
785b8e80941Smrg   return VK_ERROR_FORMAT_NOT_SUPPORTED;
786b8e80941Smrg}
787b8e80941Smrg
788b8e80941SmrgVkResult
789b8e80941Smrgtu_GetPhysicalDeviceImageFormatProperties(
790b8e80941Smrg   VkPhysicalDevice physicalDevice,
791b8e80941Smrg   VkFormat format,
792b8e80941Smrg   VkImageType type,
793b8e80941Smrg   VkImageTiling tiling,
794b8e80941Smrg   VkImageUsageFlags usage,
795b8e80941Smrg   VkImageCreateFlags createFlags,
796b8e80941Smrg   VkImageFormatProperties *pImageFormatProperties)
797b8e80941Smrg{
798b8e80941Smrg   TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice);
799b8e80941Smrg
800b8e80941Smrg   const VkPhysicalDeviceImageFormatInfo2 info = {
801b8e80941Smrg      .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
802b8e80941Smrg      .pNext = NULL,
803b8e80941Smrg      .format = format,
804b8e80941Smrg      .type = type,
805b8e80941Smrg      .tiling = tiling,
806b8e80941Smrg      .usage = usage,
807b8e80941Smrg      .flags = createFlags,
808b8e80941Smrg   };
809b8e80941Smrg
810b8e80941Smrg   return tu_get_image_format_properties(physical_device, &info,
811b8e80941Smrg                                         pImageFormatProperties);
812b8e80941Smrg}
813b8e80941Smrg
814b8e80941Smrgstatic VkResult
815b8e80941Smrgtu_get_external_image_format_properties(
816b8e80941Smrg   const struct tu_physical_device *physical_device,
817b8e80941Smrg   const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
818b8e80941Smrg   VkExternalMemoryHandleTypeFlagBits handleType,
819b8e80941Smrg   VkExternalMemoryProperties *external_properties)
820b8e80941Smrg{
821b8e80941Smrg   VkExternalMemoryFeatureFlagBits flags = 0;
822b8e80941Smrg   VkExternalMemoryHandleTypeFlags export_flags = 0;
823b8e80941Smrg   VkExternalMemoryHandleTypeFlags compat_flags = 0;
824b8e80941Smrg
825b8e80941Smrg   /* From the Vulkan 1.1.98 spec:
826b8e80941Smrg    *
827b8e80941Smrg    *    If handleType is not compatible with the format, type, tiling,
828b8e80941Smrg    *    usage, and flags specified in VkPhysicalDeviceImageFormatInfo2,
829b8e80941Smrg    *    then vkGetPhysicalDeviceImageFormatProperties2 returns
830b8e80941Smrg    *    VK_ERROR_FORMAT_NOT_SUPPORTED.
831b8e80941Smrg    */
832b8e80941Smrg
833b8e80941Smrg   switch (handleType) {
834b8e80941Smrg   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
835b8e80941Smrg   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
836b8e80941Smrg      switch (pImageFormatInfo->type) {
837b8e80941Smrg      case VK_IMAGE_TYPE_2D:
838b8e80941Smrg         flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT |
839b8e80941Smrg                 VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
840b8e80941Smrg                 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
841b8e80941Smrg         compat_flags = export_flags =
842b8e80941Smrg            VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
843b8e80941Smrg            VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
844b8e80941Smrg         break;
845b8e80941Smrg      default:
846b8e80941Smrg         return vk_errorf(physical_device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
847b8e80941Smrg                          "VkExternalMemoryTypeFlagBits(0x%x) unsupported for VkImageType(%d)",
848b8e80941Smrg                          handleType, pImageFormatInfo->type);
849b8e80941Smrg      }
850b8e80941Smrg      break;
851b8e80941Smrg   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
852b8e80941Smrg      flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
853b8e80941Smrg      compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
854b8e80941Smrg      break;
855b8e80941Smrg   default:
856b8e80941Smrg      return vk_errorf(physical_device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
857b8e80941Smrg                       "VkExternalMemoryTypeFlagBits(0x%x) unsupported",
858b8e80941Smrg                       handleType);
859b8e80941Smrg   }
860b8e80941Smrg
861b8e80941Smrg   *external_properties = (VkExternalMemoryProperties) {
862b8e80941Smrg      .externalMemoryFeatures = flags,
863b8e80941Smrg      .exportFromImportedHandleTypes = export_flags,
864b8e80941Smrg      .compatibleHandleTypes = compat_flags,
865b8e80941Smrg   };
866b8e80941Smrg
867b8e80941Smrg   return VK_SUCCESS;
868b8e80941Smrg}
869b8e80941Smrg
870b8e80941SmrgVkResult
871b8e80941Smrgtu_GetPhysicalDeviceImageFormatProperties2(
872b8e80941Smrg   VkPhysicalDevice physicalDevice,
873b8e80941Smrg   const VkPhysicalDeviceImageFormatInfo2 *base_info,
874b8e80941Smrg   VkImageFormatProperties2 *base_props)
875b8e80941Smrg{
876b8e80941Smrg   TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice);
877b8e80941Smrg   const VkPhysicalDeviceExternalImageFormatInfo *external_info = NULL;
878b8e80941Smrg   VkExternalImageFormatProperties *external_props = NULL;
879b8e80941Smrg   VkResult result;
880b8e80941Smrg
881b8e80941Smrg   result = tu_get_image_format_properties(
882b8e80941Smrg      physical_device, base_info, &base_props->imageFormatProperties);
883b8e80941Smrg   if (result != VK_SUCCESS)
884b8e80941Smrg      return result;
885b8e80941Smrg
886b8e80941Smrg   /* Extract input structs */
887b8e80941Smrg   vk_foreach_struct_const(s, base_info->pNext)
888b8e80941Smrg   {
889b8e80941Smrg      switch (s->sType) {
890b8e80941Smrg      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO:
891b8e80941Smrg         external_info = (const void *) s;
892b8e80941Smrg         break;
893b8e80941Smrg      default:
894b8e80941Smrg         break;
895b8e80941Smrg      }
896b8e80941Smrg   }
897b8e80941Smrg
898b8e80941Smrg   /* Extract output structs */
899b8e80941Smrg   vk_foreach_struct(s, base_props->pNext)
900b8e80941Smrg   {
901b8e80941Smrg      switch (s->sType) {
902b8e80941Smrg      case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES:
903b8e80941Smrg         external_props = (void *) s;
904b8e80941Smrg         break;
905b8e80941Smrg      default:
906b8e80941Smrg         break;
907b8e80941Smrg      }
908b8e80941Smrg   }
909b8e80941Smrg
910b8e80941Smrg   /* From the Vulkan 1.0.42 spec:
911b8e80941Smrg    *
912b8e80941Smrg    *    If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
913b8e80941Smrg    *    behave as if VkPhysicalDeviceExternalImageFormatInfo was not
914b8e80941Smrg    *    present and VkExternalImageFormatProperties will be ignored.
915b8e80941Smrg    */
916b8e80941Smrg   if (external_info && external_info->handleType != 0) {
917b8e80941Smrg      result = tu_get_external_image_format_properties(
918b8e80941Smrg         physical_device, base_info, external_info->handleType,
919b8e80941Smrg         &external_props->externalMemoryProperties);
920b8e80941Smrg      if (result != VK_SUCCESS)
921b8e80941Smrg         goto fail;
922b8e80941Smrg   }
923b8e80941Smrg
924b8e80941Smrg   return VK_SUCCESS;
925b8e80941Smrg
926b8e80941Smrgfail:
927b8e80941Smrg   if (result == VK_ERROR_FORMAT_NOT_SUPPORTED) {
928b8e80941Smrg      /* From the Vulkan 1.0.42 spec:
929b8e80941Smrg       *
930b8e80941Smrg       *    If the combination of parameters to
931b8e80941Smrg       *    vkGetPhysicalDeviceImageFormatProperties2 is not supported by
932b8e80941Smrg       *    the implementation for use in vkCreateImage, then all members of
933b8e80941Smrg       *    imageFormatProperties will be filled with zero.
934b8e80941Smrg       */
935b8e80941Smrg      base_props->imageFormatProperties = (VkImageFormatProperties) { 0 };
936b8e80941Smrg   }
937b8e80941Smrg
938b8e80941Smrg   return result;
939b8e80941Smrg}
940b8e80941Smrg
941b8e80941Smrgvoid
942b8e80941Smrgtu_GetPhysicalDeviceSparseImageFormatProperties(
943b8e80941Smrg   VkPhysicalDevice physicalDevice,
944b8e80941Smrg   VkFormat format,
945b8e80941Smrg   VkImageType type,
946b8e80941Smrg   uint32_t samples,
947b8e80941Smrg   VkImageUsageFlags usage,
948b8e80941Smrg   VkImageTiling tiling,
949b8e80941Smrg   uint32_t *pNumProperties,
950b8e80941Smrg   VkSparseImageFormatProperties *pProperties)
951b8e80941Smrg{
952b8e80941Smrg   /* Sparse images are not yet supported. */
953b8e80941Smrg   *pNumProperties = 0;
954b8e80941Smrg}
955b8e80941Smrg
956b8e80941Smrgvoid
957b8e80941Smrgtu_GetPhysicalDeviceSparseImageFormatProperties2(
958b8e80941Smrg   VkPhysicalDevice physicalDevice,
959b8e80941Smrg   const VkPhysicalDeviceSparseImageFormatInfo2 *pFormatInfo,
960b8e80941Smrg   uint32_t *pPropertyCount,
961b8e80941Smrg   VkSparseImageFormatProperties2 *pProperties)
962b8e80941Smrg{
963b8e80941Smrg   /* Sparse images are not yet supported. */
964b8e80941Smrg   *pPropertyCount = 0;
965b8e80941Smrg}
966b8e80941Smrg
967b8e80941Smrgvoid
968b8e80941Smrgtu_GetPhysicalDeviceExternalBufferProperties(
969b8e80941Smrg   VkPhysicalDevice physicalDevice,
970b8e80941Smrg   const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo,
971b8e80941Smrg   VkExternalBufferProperties *pExternalBufferProperties)
972b8e80941Smrg{
973b8e80941Smrg   VkExternalMemoryFeatureFlagBits flags = 0;
974b8e80941Smrg   VkExternalMemoryHandleTypeFlags export_flags = 0;
975b8e80941Smrg   VkExternalMemoryHandleTypeFlags compat_flags = 0;
976b8e80941Smrg   switch (pExternalBufferInfo->handleType) {
977b8e80941Smrg   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
978b8e80941Smrg   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
979b8e80941Smrg      flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
980b8e80941Smrg              VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
981b8e80941Smrg      compat_flags = export_flags =
982b8e80941Smrg         VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
983b8e80941Smrg         VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
984b8e80941Smrg      break;
985b8e80941Smrg   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
986b8e80941Smrg      flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
987b8e80941Smrg      compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
988b8e80941Smrg      break;
989b8e80941Smrg   default:
990b8e80941Smrg      break;
991b8e80941Smrg   }
992b8e80941Smrg   pExternalBufferProperties->externalMemoryProperties =
993b8e80941Smrg      (VkExternalMemoryProperties) {
994b8e80941Smrg         .externalMemoryFeatures = flags,
995b8e80941Smrg         .exportFromImportedHandleTypes = export_flags,
996b8e80941Smrg         .compatibleHandleTypes = compat_flags,
997b8e80941Smrg      };
998b8e80941Smrg}
999