1 #include "zink_screen.h"
2
3 static const VkFormat formats[PIPE_FORMAT_COUNT] = {
4 #define MAP_FORMAT_NORM(FMT) \
5 [PIPE_FORMAT_ ## FMT ## _UNORM] = VK_FORMAT_ ## FMT ## _UNORM, \
6 [PIPE_FORMAT_ ## FMT ## _SNORM] = VK_FORMAT_ ## FMT ## _SNORM,
7
8 #define MAP_FORMAT_SCALED(FMT) \
9 [PIPE_FORMAT_ ## FMT ## _USCALED] = VK_FORMAT_ ## FMT ## _USCALED, \
10 [PIPE_FORMAT_ ## FMT ## _SSCALED] = VK_FORMAT_ ## FMT ## _SSCALED,
11
12 #define MAP_FORMAT_INT(FMT) \
13 [PIPE_FORMAT_ ## FMT ## _UINT] = VK_FORMAT_ ## FMT ## _UINT, \
14 [PIPE_FORMAT_ ## FMT ## _SINT] = VK_FORMAT_ ## FMT ## _SINT,
15
16 #define MAP_FORMAT_SRGB(FMT) \
17 [PIPE_FORMAT_ ## FMT ## _SRGB] = VK_FORMAT_ ## FMT ## _SRGB,
18
19 #define MAP_FORMAT_FLOAT(FMT) \
20 [PIPE_FORMAT_ ## FMT ## _FLOAT] = VK_FORMAT_ ## FMT ## _SFLOAT,
21
22 // one component
23
24 // 8-bits
25 MAP_FORMAT_NORM(R8)
26 MAP_FORMAT_SCALED(R8)
27 MAP_FORMAT_INT(R8)
28 // 16-bits
29 MAP_FORMAT_NORM(R16)
30 MAP_FORMAT_SCALED(R16)
31 MAP_FORMAT_INT(R16)
32 MAP_FORMAT_FLOAT(R16)
33 // 32-bits
34 MAP_FORMAT_INT(R32)
35 MAP_FORMAT_FLOAT(R32)
36
37 // two components
38
39 // 8-bits
40 MAP_FORMAT_NORM(R8G8)
41 MAP_FORMAT_SCALED(R8G8)
42 MAP_FORMAT_INT(R8G8)
43 // 16-bits
44 MAP_FORMAT_NORM(R16G16)
45 MAP_FORMAT_SCALED(R16G16)
46 MAP_FORMAT_INT(R16G16)
47 MAP_FORMAT_FLOAT(R16G16)
48 // 32-bits
49 MAP_FORMAT_INT(R32G32)
50 MAP_FORMAT_FLOAT(R32G32)
51
52 // three components
53
54 // 8-bits
55 MAP_FORMAT_NORM(R8G8B8)
56 MAP_FORMAT_SCALED(R8G8B8)
57 MAP_FORMAT_INT(R8G8B8)
58 MAP_FORMAT_SRGB(R8G8B8)
59 // 16-bits
60 MAP_FORMAT_NORM(R16G16B16)
61 MAP_FORMAT_SCALED(R16G16B16)
62 MAP_FORMAT_INT(R16G16B16)
63 MAP_FORMAT_FLOAT(R16G16B16)
64 // 32-bits
65 MAP_FORMAT_INT(R32G32B32)
66 MAP_FORMAT_FLOAT(R32G32B32)
67
68 // four components
69
70 // 8-bits
71 MAP_FORMAT_NORM(R8G8B8A8)
72 MAP_FORMAT_SCALED(R8G8B8A8)
73 MAP_FORMAT_INT(R8G8B8A8)
74 MAP_FORMAT_SRGB(R8G8B8A8)
75 [PIPE_FORMAT_B8G8R8A8_UNORM] = VK_FORMAT_B8G8R8A8_UNORM,
76 [PIPE_FORMAT_B8G8R8X8_UNORM] = VK_FORMAT_B8G8R8A8_UNORM,
77 MAP_FORMAT_SRGB(B8G8R8A8)
78 [PIPE_FORMAT_B8G8R8X8_SRGB] = VK_FORMAT_B8G8R8A8_SRGB,
79 [PIPE_FORMAT_R8G8B8A8_SRGB] = VK_FORMAT_A8B8G8R8_SRGB_PACK32,
80 // 16-bits
81 MAP_FORMAT_NORM(R16G16B16A16)
82 MAP_FORMAT_SCALED(R16G16B16A16)
83 MAP_FORMAT_INT(R16G16B16A16)
84 MAP_FORMAT_FLOAT(R16G16B16A16)
85 // 32-bits
86 MAP_FORMAT_INT(R32G32B32A32)
87 MAP_FORMAT_FLOAT(R32G32B32A32)
88
89 // other color formats
90 [PIPE_FORMAT_B5G6R5_UNORM] = VK_FORMAT_R5G6B5_UNORM_PACK16,
91 [PIPE_FORMAT_A1R5G5B5_UNORM] = VK_FORMAT_B5G5R5A1_UNORM_PACK16,
92 [PIPE_FORMAT_R11G11B10_FLOAT] = VK_FORMAT_B10G11R11_UFLOAT_PACK32,
93 [PIPE_FORMAT_R9G9B9E5_FLOAT] = VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
94 /* ARB_vertex_type_2_10_10_10 */
95 [PIPE_FORMAT_R10G10B10A2_UNORM] = VK_FORMAT_A2B10G10R10_UNORM_PACK32,
96 [PIPE_FORMAT_R10G10B10A2_SNORM] = VK_FORMAT_A2B10G10R10_SNORM_PACK32,
97 [PIPE_FORMAT_B10G10R10A2_UNORM] = VK_FORMAT_A2R10G10B10_UNORM_PACK32,
98 [PIPE_FORMAT_B10G10R10A2_SNORM] = VK_FORMAT_A2R10G10B10_SNORM_PACK32,
99 [PIPE_FORMAT_R10G10B10A2_USCALED] = VK_FORMAT_A2B10G10R10_USCALED_PACK32,
100 [PIPE_FORMAT_R10G10B10A2_SSCALED] = VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
101 [PIPE_FORMAT_B10G10R10A2_USCALED] = VK_FORMAT_A2R10G10B10_USCALED_PACK32,
102 [PIPE_FORMAT_B10G10R10A2_SSCALED] = VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
103 [PIPE_FORMAT_R10G10B10A2_UINT] = VK_FORMAT_A2B10G10R10_UINT_PACK32,
104 [PIPE_FORMAT_B10G10R10A2_UINT] = VK_FORMAT_A2R10G10B10_UINT_PACK32,
105
106 // depth/stencil formats
107 [PIPE_FORMAT_Z32_FLOAT] = VK_FORMAT_D32_SFLOAT,
108 [PIPE_FORMAT_Z32_FLOAT_S8X24_UINT] = VK_FORMAT_D32_SFLOAT_S8_UINT,
109 [PIPE_FORMAT_Z16_UNORM] = VK_FORMAT_D16_UNORM,
110 [PIPE_FORMAT_Z24X8_UNORM] = VK_FORMAT_X8_D24_UNORM_PACK32,
111 [PIPE_FORMAT_Z24_UNORM_S8_UINT] = VK_FORMAT_D24_UNORM_S8_UINT,
112 [PIPE_FORMAT_S8_UINT] = VK_FORMAT_S8_UINT,
113
114 // compressed formats
115 [PIPE_FORMAT_DXT1_RGB] = VK_FORMAT_BC1_RGB_UNORM_BLOCK,
116 [PIPE_FORMAT_DXT1_RGBA] = VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
117 [PIPE_FORMAT_DXT3_RGBA] = VK_FORMAT_BC2_UNORM_BLOCK,
118 [PIPE_FORMAT_DXT5_RGBA] = VK_FORMAT_BC3_UNORM_BLOCK,
119 [PIPE_FORMAT_DXT1_SRGB] = VK_FORMAT_BC1_RGB_SRGB_BLOCK,
120 [PIPE_FORMAT_DXT1_SRGBA] = VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
121 [PIPE_FORMAT_DXT3_SRGBA] = VK_FORMAT_BC2_SRGB_BLOCK,
122 [PIPE_FORMAT_DXT5_SRGBA] = VK_FORMAT_BC3_SRGB_BLOCK,
123
124 [PIPE_FORMAT_RGTC1_UNORM] = VK_FORMAT_BC4_UNORM_BLOCK,
125 [PIPE_FORMAT_RGTC1_SNORM] = VK_FORMAT_BC4_SNORM_BLOCK,
126 [PIPE_FORMAT_RGTC2_UNORM] = VK_FORMAT_BC5_UNORM_BLOCK,
127 [PIPE_FORMAT_RGTC2_SNORM] = VK_FORMAT_BC5_SNORM_BLOCK,
128 [PIPE_FORMAT_BPTC_RGBA_UNORM] = VK_FORMAT_BC7_UNORM_BLOCK,
129 [PIPE_FORMAT_BPTC_SRGBA] = VK_FORMAT_BC7_SRGB_BLOCK,
130 [PIPE_FORMAT_BPTC_RGB_FLOAT] = VK_FORMAT_BC6H_SFLOAT_BLOCK,
131 [PIPE_FORMAT_BPTC_RGB_UFLOAT] = VK_FORMAT_BC6H_UFLOAT_BLOCK,
132 };
133
134 bool
zink_is_depth_format_supported(struct zink_screen * screen,VkFormat format)135 zink_is_depth_format_supported(struct zink_screen *screen, VkFormat format)
136 {
137 VkFormatProperties props;
138 vkGetPhysicalDeviceFormatProperties(screen->pdev, format, &props);
139 return (props.linearTilingFeatures | props.optimalTilingFeatures) &
140 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
141 }
142
143 VkFormat
zink_get_format(struct zink_screen * screen,enum pipe_format format)144 zink_get_format(struct zink_screen *screen, enum pipe_format format)
145 {
146 VkFormat ret = formats[format];
147
148 if (ret == VK_FORMAT_X8_D24_UNORM_PACK32 &&
149 !screen->have_X8_D24_UNORM_PACK32) {
150 assert(zink_is_depth_format_supported(screen, VK_FORMAT_D32_SFLOAT));
151 return VK_FORMAT_D32_SFLOAT;
152 }
153
154 if (ret == VK_FORMAT_D24_UNORM_S8_UINT &&
155 !screen->have_D24_UNORM_S8_UINT) {
156 assert(zink_is_depth_format_supported(screen,
157 VK_FORMAT_D32_SFLOAT_S8_UINT));
158 return VK_FORMAT_D32_SFLOAT_S8_UINT;
159 }
160
161 return ret;
162 }
163