1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 LunarG, Inc.
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 shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "genhw/genhw.h"
29 #include "ilo_state_surface.h"
30
31 static bool
surface_valid_sampler_format(const struct ilo_dev * dev,enum ilo_state_surface_access access,enum gen_surface_format format)32 surface_valid_sampler_format(const struct ilo_dev *dev,
33 enum ilo_state_surface_access access,
34 enum gen_surface_format format)
35 {
36 /*
37 * This table is based on:
38 *
39 * - the Sandy Bridge PRM, volume 4 part 1, page 88-97
40 * - the Ivy Bridge PRM, volume 4 part 1, page 84-87
41 */
42 static const struct sampler_cap {
43 int sampling;
44 int filtering;
45 int shadow_map;
46 int chroma_key;
47 } caps[] = {
48 #define CAP(sampling, filtering, shadow_map, chroma_key) \
49 { ILO_GEN(sampling), ILO_GEN(filtering), ILO_GEN(shadow_map), ILO_GEN(chroma_key) }
50 [GEN6_FORMAT_R32G32B32A32_FLOAT] = CAP( 1, 5, 0, 0),
51 [GEN6_FORMAT_R32G32B32A32_SINT] = CAP( 1, 0, 0, 0),
52 [GEN6_FORMAT_R32G32B32A32_UINT] = CAP( 1, 0, 0, 0),
53 [GEN6_FORMAT_R32G32B32X32_FLOAT] = CAP( 1, 5, 0, 0),
54 [GEN6_FORMAT_R32G32B32_FLOAT] = CAP( 1, 5, 0, 0),
55 [GEN6_FORMAT_R32G32B32_SINT] = CAP( 1, 0, 0, 0),
56 [GEN6_FORMAT_R32G32B32_UINT] = CAP( 1, 0, 0, 0),
57 [GEN6_FORMAT_R16G16B16A16_UNORM] = CAP( 1, 1, 0, 0),
58 [GEN6_FORMAT_R16G16B16A16_SNORM] = CAP( 1, 1, 0, 0),
59 [GEN6_FORMAT_R16G16B16A16_SINT] = CAP( 1, 0, 0, 0),
60 [GEN6_FORMAT_R16G16B16A16_UINT] = CAP( 1, 0, 0, 0),
61 [GEN6_FORMAT_R16G16B16A16_FLOAT] = CAP( 1, 1, 0, 0),
62 [GEN6_FORMAT_R32G32_FLOAT] = CAP( 1, 5, 0, 0),
63 [GEN6_FORMAT_R32G32_SINT] = CAP( 1, 0, 0, 0),
64 [GEN6_FORMAT_R32G32_UINT] = CAP( 1, 0, 0, 0),
65 [GEN6_FORMAT_R32_FLOAT_X8X24_TYPELESS] = CAP( 1, 5, 1, 0),
66 [GEN6_FORMAT_X32_TYPELESS_G8X24_UINT] = CAP( 1, 0, 0, 0),
67 [GEN6_FORMAT_L32A32_FLOAT] = CAP( 1, 5, 0, 0),
68 [GEN6_FORMAT_R16G16B16X16_UNORM] = CAP( 1, 1, 0, 0),
69 [GEN6_FORMAT_R16G16B16X16_FLOAT] = CAP( 1, 1, 0, 0),
70 [GEN6_FORMAT_A32X32_FLOAT] = CAP( 1, 5, 0, 0),
71 [GEN6_FORMAT_L32X32_FLOAT] = CAP( 1, 5, 0, 0),
72 [GEN6_FORMAT_I32X32_FLOAT] = CAP( 1, 5, 0, 0),
73 [GEN6_FORMAT_B8G8R8A8_UNORM] = CAP( 1, 1, 0, 1),
74 [GEN6_FORMAT_B8G8R8A8_UNORM_SRGB] = CAP( 1, 1, 0, 0),
75 [GEN6_FORMAT_R10G10B10A2_UNORM] = CAP( 1, 1, 0, 0),
76 [GEN6_FORMAT_R10G10B10A2_UNORM_SRGB] = CAP( 1, 1, 0, 0),
77 [GEN6_FORMAT_R10G10B10A2_UINT] = CAP( 1, 0, 0, 0),
78 [GEN6_FORMAT_R10G10B10_SNORM_A2_UNORM] = CAP( 1, 1, 0, 0),
79 [GEN6_FORMAT_R8G8B8A8_UNORM] = CAP( 1, 1, 0, 0),
80 [GEN6_FORMAT_R8G8B8A8_UNORM_SRGB] = CAP( 1, 1, 0, 0),
81 [GEN6_FORMAT_R8G8B8A8_SNORM] = CAP( 1, 1, 0, 0),
82 [GEN6_FORMAT_R8G8B8A8_SINT] = CAP( 1, 0, 0, 0),
83 [GEN6_FORMAT_R8G8B8A8_UINT] = CAP( 1, 0, 0, 0),
84 [GEN6_FORMAT_R16G16_UNORM] = CAP( 1, 1, 0, 0),
85 [GEN6_FORMAT_R16G16_SNORM] = CAP( 1, 1, 0, 0),
86 [GEN6_FORMAT_R16G16_SINT] = CAP( 1, 0, 0, 0),
87 [GEN6_FORMAT_R16G16_UINT] = CAP( 1, 0, 0, 0),
88 [GEN6_FORMAT_R16G16_FLOAT] = CAP( 1, 1, 0, 0),
89 [GEN6_FORMAT_B10G10R10A2_UNORM] = CAP( 1, 1, 0, 0),
90 [GEN6_FORMAT_B10G10R10A2_UNORM_SRGB] = CAP( 1, 1, 0, 0),
91 [GEN6_FORMAT_R11G11B10_FLOAT] = CAP( 1, 1, 0, 0),
92 [GEN6_FORMAT_R32_SINT] = CAP( 1, 0, 0, 0),
93 [GEN6_FORMAT_R32_UINT] = CAP( 1, 0, 0, 0),
94 [GEN6_FORMAT_R32_FLOAT] = CAP( 1, 5, 1, 0),
95 [GEN6_FORMAT_R24_UNORM_X8_TYPELESS] = CAP( 1, 5, 1, 0),
96 [GEN6_FORMAT_X24_TYPELESS_G8_UINT] = CAP( 1, 0, 0, 0),
97 [GEN6_FORMAT_L16A16_UNORM] = CAP( 1, 1, 0, 0),
98 [GEN6_FORMAT_I24X8_UNORM] = CAP( 1, 5, 1, 0),
99 [GEN6_FORMAT_L24X8_UNORM] = CAP( 1, 5, 1, 0),
100 [GEN6_FORMAT_A24X8_UNORM] = CAP( 1, 5, 1, 0),
101 [GEN6_FORMAT_I32_FLOAT] = CAP( 1, 5, 1, 0),
102 [GEN6_FORMAT_L32_FLOAT] = CAP( 1, 5, 1, 0),
103 [GEN6_FORMAT_A32_FLOAT] = CAP( 1, 5, 1, 0),
104 [GEN6_FORMAT_B8G8R8X8_UNORM] = CAP( 1, 1, 0, 1),
105 [GEN6_FORMAT_B8G8R8X8_UNORM_SRGB] = CAP( 1, 1, 0, 0),
106 [GEN6_FORMAT_R8G8B8X8_UNORM] = CAP( 1, 1, 0, 0),
107 [GEN6_FORMAT_R8G8B8X8_UNORM_SRGB] = CAP( 1, 1, 0, 0),
108 [GEN6_FORMAT_R9G9B9E5_SHAREDEXP] = CAP( 1, 1, 0, 0),
109 [GEN6_FORMAT_B10G10R10X2_UNORM] = CAP( 1, 1, 0, 0),
110 [GEN6_FORMAT_L16A16_FLOAT] = CAP( 1, 1, 0, 0),
111 [GEN6_FORMAT_B5G6R5_UNORM] = CAP( 1, 1, 0, 1),
112 [GEN6_FORMAT_B5G6R5_UNORM_SRGB] = CAP( 1, 1, 0, 0),
113 [GEN6_FORMAT_B5G5R5A1_UNORM] = CAP( 1, 1, 0, 1),
114 [GEN6_FORMAT_B5G5R5A1_UNORM_SRGB] = CAP( 1, 1, 0, 0),
115 [GEN6_FORMAT_B4G4R4A4_UNORM] = CAP( 1, 1, 0, 1),
116 [GEN6_FORMAT_B4G4R4A4_UNORM_SRGB] = CAP( 1, 1, 0, 0),
117 [GEN6_FORMAT_R8G8_UNORM] = CAP( 1, 1, 0, 0),
118 [GEN6_FORMAT_R8G8_SNORM] = CAP( 1, 1, 0, 1),
119 [GEN6_FORMAT_R8G8_SINT] = CAP( 1, 0, 0, 0),
120 [GEN6_FORMAT_R8G8_UINT] = CAP( 1, 0, 0, 0),
121 [GEN6_FORMAT_R16_UNORM] = CAP( 1, 1, 1, 0),
122 [GEN6_FORMAT_R16_SNORM] = CAP( 1, 1, 0, 0),
123 [GEN6_FORMAT_R16_SINT] = CAP( 1, 0, 0, 0),
124 [GEN6_FORMAT_R16_UINT] = CAP( 1, 0, 0, 0),
125 [GEN6_FORMAT_R16_FLOAT] = CAP( 1, 1, 0, 0),
126 [GEN6_FORMAT_A8P8_UNORM_PALETTE0] = CAP( 5, 5, 0, 0),
127 [GEN6_FORMAT_A8P8_UNORM_PALETTE1] = CAP( 5, 5, 0, 0),
128 [GEN6_FORMAT_I16_UNORM] = CAP( 1, 1, 1, 0),
129 [GEN6_FORMAT_L16_UNORM] = CAP( 1, 1, 1, 0),
130 [GEN6_FORMAT_A16_UNORM] = CAP( 1, 1, 1, 0),
131 [GEN6_FORMAT_L8A8_UNORM] = CAP( 1, 1, 0, 1),
132 [GEN6_FORMAT_I16_FLOAT] = CAP( 1, 1, 1, 0),
133 [GEN6_FORMAT_L16_FLOAT] = CAP( 1, 1, 1, 0),
134 [GEN6_FORMAT_A16_FLOAT] = CAP( 1, 1, 1, 0),
135 [GEN6_FORMAT_L8A8_UNORM_SRGB] = CAP(4.5, 4.5, 0, 0),
136 [GEN6_FORMAT_R5G5_SNORM_B6_UNORM] = CAP( 1, 1, 0, 1),
137 [GEN6_FORMAT_P8A8_UNORM_PALETTE0] = CAP( 5, 5, 0, 0),
138 [GEN6_FORMAT_P8A8_UNORM_PALETTE1] = CAP( 5, 5, 0, 0),
139 [GEN6_FORMAT_R8_UNORM] = CAP( 1, 1, 0, 4.5),
140 [GEN6_FORMAT_R8_SNORM] = CAP( 1, 1, 0, 0),
141 [GEN6_FORMAT_R8_SINT] = CAP( 1, 0, 0, 0),
142 [GEN6_FORMAT_R8_UINT] = CAP( 1, 0, 0, 0),
143 [GEN6_FORMAT_A8_UNORM] = CAP( 1, 1, 0, 1),
144 [GEN6_FORMAT_I8_UNORM] = CAP( 1, 1, 0, 0),
145 [GEN6_FORMAT_L8_UNORM] = CAP( 1, 1, 0, 1),
146 [GEN6_FORMAT_P4A4_UNORM_PALETTE0] = CAP( 1, 1, 0, 0),
147 [GEN6_FORMAT_A4P4_UNORM_PALETTE0] = CAP( 1, 1, 0, 0),
148 [GEN6_FORMAT_P8_UNORM_PALETTE0] = CAP(4.5, 4.5, 0, 0),
149 [GEN6_FORMAT_L8_UNORM_SRGB] = CAP(4.5, 4.5, 0, 0),
150 [GEN6_FORMAT_P8_UNORM_PALETTE1] = CAP(4.5, 4.5, 0, 0),
151 [GEN6_FORMAT_P4A4_UNORM_PALETTE1] = CAP(4.5, 4.5, 0, 0),
152 [GEN6_FORMAT_A4P4_UNORM_PALETTE1] = CAP(4.5, 4.5, 0, 0),
153 [GEN6_FORMAT_DXT1_RGB_SRGB] = CAP(4.5, 4.5, 0, 0),
154 [GEN6_FORMAT_R1_UNORM] = CAP( 1, 1, 0, 0),
155 [GEN6_FORMAT_YCRCB_NORMAL] = CAP( 1, 1, 0, 1),
156 [GEN6_FORMAT_YCRCB_SWAPUVY] = CAP( 1, 1, 0, 1),
157 [GEN6_FORMAT_P2_UNORM_PALETTE0] = CAP(4.5, 4.5, 0, 0),
158 [GEN6_FORMAT_P2_UNORM_PALETTE1] = CAP(4.5, 4.5, 0, 0),
159 [GEN6_FORMAT_BC1_UNORM] = CAP( 1, 1, 0, 1),
160 [GEN6_FORMAT_BC2_UNORM] = CAP( 1, 1, 0, 1),
161 [GEN6_FORMAT_BC3_UNORM] = CAP( 1, 1, 0, 1),
162 [GEN6_FORMAT_BC4_UNORM] = CAP( 1, 1, 0, 0),
163 [GEN6_FORMAT_BC5_UNORM] = CAP( 1, 1, 0, 0),
164 [GEN6_FORMAT_BC1_UNORM_SRGB] = CAP( 1, 1, 0, 0),
165 [GEN6_FORMAT_BC2_UNORM_SRGB] = CAP( 1, 1, 0, 0),
166 [GEN6_FORMAT_BC3_UNORM_SRGB] = CAP( 1, 1, 0, 0),
167 [GEN6_FORMAT_MONO8] = CAP( 1, 0, 0, 0),
168 [GEN6_FORMAT_YCRCB_SWAPUV] = CAP( 1, 1, 0, 0),
169 [GEN6_FORMAT_YCRCB_SWAPY] = CAP( 1, 1, 0, 0),
170 [GEN6_FORMAT_DXT1_RGB] = CAP( 1, 1, 0, 0),
171 [GEN6_FORMAT_FXT1] = CAP( 1, 1, 0, 0),
172 [GEN6_FORMAT_BC4_SNORM] = CAP( 1, 1, 0, 0),
173 [GEN6_FORMAT_BC5_SNORM] = CAP( 1, 1, 0, 0),
174 [GEN6_FORMAT_R16G16B16_FLOAT] = CAP( 5, 5, 0, 0),
175 [GEN6_FORMAT_BC6H_SF16] = CAP( 7, 7, 0, 0),
176 [GEN6_FORMAT_BC7_UNORM] = CAP( 7, 7, 0, 0),
177 [GEN6_FORMAT_BC7_UNORM_SRGB] = CAP( 7, 7, 0, 0),
178 [GEN6_FORMAT_BC6H_UF16] = CAP( 7, 7, 0, 0),
179 #undef CAP
180 };
181
182 ILO_DEV_ASSERT(dev, 6, 8);
183
184 return (format < ARRAY_SIZE(caps) && caps[format].sampling &&
185 ilo_dev_gen(dev) >= caps[format].sampling);
186 }
187
188 static bool
surface_valid_dp_format(const struct ilo_dev * dev,enum ilo_state_surface_access access,enum gen_surface_format format)189 surface_valid_dp_format(const struct ilo_dev *dev,
190 enum ilo_state_surface_access access,
191 enum gen_surface_format format)
192 {
193 /*
194 * This table is based on:
195 *
196 * - the Sandy Bridge PRM, volume 4 part 1, page 88-97
197 * - the Ivy Bridge PRM, volume 4 part 1, page 172, 252-253, and 277-278
198 * - the Haswell PRM, volume 7, page 262-264
199 */
200 static const struct dp_cap {
201 int rt_write;
202 int rt_write_blending;
203 int typed_write;
204 int media_color_processing;
205 } caps[] = {
206 #define CAP(rt_write, rt_write_blending, typed_write, media_color_processing) \
207 { ILO_GEN(rt_write), ILO_GEN(rt_write_blending), ILO_GEN(typed_write), ILO_GEN(media_color_processing) }
208 [GEN6_FORMAT_R32G32B32A32_FLOAT] = CAP( 1, 1, 7, 0),
209 [GEN6_FORMAT_R32G32B32A32_SINT] = CAP( 1, 0, 7, 0),
210 [GEN6_FORMAT_R32G32B32A32_UINT] = CAP( 1, 0, 7, 0),
211 [GEN6_FORMAT_R16G16B16A16_UNORM] = CAP( 1, 4.5, 7, 6),
212 [GEN6_FORMAT_R16G16B16A16_SNORM] = CAP( 1, 6, 7, 0),
213 [GEN6_FORMAT_R16G16B16A16_SINT] = CAP( 1, 0, 7, 0),
214 [GEN6_FORMAT_R16G16B16A16_UINT] = CAP( 1, 0, 7, 0),
215 [GEN6_FORMAT_R16G16B16A16_FLOAT] = CAP( 1, 1, 7, 0),
216 [GEN6_FORMAT_R32G32_FLOAT] = CAP( 1, 1, 7, 0),
217 [GEN6_FORMAT_R32G32_SINT] = CAP( 1, 0, 7, 0),
218 [GEN6_FORMAT_R32G32_UINT] = CAP( 1, 0, 7, 0),
219 [GEN6_FORMAT_B8G8R8A8_UNORM] = CAP( 1, 1, 7, 6),
220 [GEN6_FORMAT_B8G8R8A8_UNORM_SRGB] = CAP( 1, 1, 0, 0),
221 [GEN6_FORMAT_R10G10B10A2_UNORM] = CAP( 1, 1, 7, 6),
222 [GEN6_FORMAT_R10G10B10A2_UNORM_SRGB] = CAP( 0, 0, 0, 6),
223 [GEN6_FORMAT_R10G10B10A2_UINT] = CAP( 1, 0, 7, 0),
224 [GEN6_FORMAT_R8G8B8A8_UNORM] = CAP( 1, 1, 7, 6),
225 [GEN6_FORMAT_R8G8B8A8_UNORM_SRGB] = CAP( 1, 1, 0, 6),
226 [GEN6_FORMAT_R8G8B8A8_SNORM] = CAP( 1, 6, 7, 0),
227 [GEN6_FORMAT_R8G8B8A8_SINT] = CAP( 1, 0, 7, 0),
228 [GEN6_FORMAT_R8G8B8A8_UINT] = CAP( 1, 0, 7, 0),
229 [GEN6_FORMAT_R16G16_UNORM] = CAP( 1, 4.5, 7, 0),
230 [GEN6_FORMAT_R16G16_SNORM] = CAP( 1, 6, 7, 0),
231 [GEN6_FORMAT_R16G16_SINT] = CAP( 1, 0, 7, 0),
232 [GEN6_FORMAT_R16G16_UINT] = CAP( 1, 0, 7, 0),
233 [GEN6_FORMAT_R16G16_FLOAT] = CAP( 1, 1, 7, 0),
234 [GEN6_FORMAT_B10G10R10A2_UNORM] = CAP( 1, 1, 7, 6),
235 [GEN6_FORMAT_B10G10R10A2_UNORM_SRGB] = CAP( 1, 1, 0, 6),
236 [GEN6_FORMAT_R11G11B10_FLOAT] = CAP( 1, 1, 7, 0),
237 [GEN6_FORMAT_R32_SINT] = CAP( 1, 0, 7, 0),
238 [GEN6_FORMAT_R32_UINT] = CAP( 1, 0, 7, 0),
239 [GEN6_FORMAT_R32_FLOAT] = CAP( 1, 1, 7, 0),
240 [GEN6_FORMAT_B8G8R8X8_UNORM] = CAP( 0, 0, 0, 6),
241 [GEN6_FORMAT_B5G6R5_UNORM] = CAP( 1, 1, 7, 0),
242 [GEN6_FORMAT_B5G6R5_UNORM_SRGB] = CAP( 1, 1, 0, 0),
243 [GEN6_FORMAT_B5G5R5A1_UNORM] = CAP( 1, 1, 7, 0),
244 [GEN6_FORMAT_B5G5R5A1_UNORM_SRGB] = CAP( 1, 1, 0, 0),
245 [GEN6_FORMAT_B4G4R4A4_UNORM] = CAP( 1, 1, 7, 0),
246 [GEN6_FORMAT_B4G4R4A4_UNORM_SRGB] = CAP( 1, 1, 0, 0),
247 [GEN6_FORMAT_R8G8_UNORM] = CAP( 1, 1, 7, 0),
248 [GEN6_FORMAT_R8G8_SNORM] = CAP( 1, 6, 7, 0),
249 [GEN6_FORMAT_R8G8_SINT] = CAP( 1, 0, 7, 0),
250 [GEN6_FORMAT_R8G8_UINT] = CAP( 1, 0, 7, 0),
251 [GEN6_FORMAT_R16_UNORM] = CAP( 1, 4.5, 7, 7),
252 [GEN6_FORMAT_R16_SNORM] = CAP( 1, 6, 7, 0),
253 [GEN6_FORMAT_R16_SINT] = CAP( 1, 0, 7, 0),
254 [GEN6_FORMAT_R16_UINT] = CAP( 1, 0, 7, 0),
255 [GEN6_FORMAT_R16_FLOAT] = CAP( 1, 1, 7, 0),
256 [GEN6_FORMAT_B5G5R5X1_UNORM] = CAP( 1, 1, 7, 0),
257 [GEN6_FORMAT_B5G5R5X1_UNORM_SRGB] = CAP( 1, 1, 0, 0),
258 [GEN6_FORMAT_R8_UNORM] = CAP( 1, 1, 7, 0),
259 [GEN6_FORMAT_R8_SNORM] = CAP( 1, 6, 7, 0),
260 [GEN6_FORMAT_R8_SINT] = CAP( 1, 0, 7, 0),
261 [GEN6_FORMAT_R8_UINT] = CAP( 1, 0, 7, 0),
262 [GEN6_FORMAT_A8_UNORM] = CAP( 1, 1, 7, 0),
263 [GEN6_FORMAT_YCRCB_NORMAL] = CAP( 1, 0, 0, 6),
264 [GEN6_FORMAT_YCRCB_SWAPUVY] = CAP( 1, 0, 0, 6),
265 [GEN6_FORMAT_YCRCB_SWAPUV] = CAP( 1, 0, 0, 6),
266 [GEN6_FORMAT_YCRCB_SWAPY] = CAP( 1, 0, 0, 6),
267 #undef CAP
268 };
269
270 ILO_DEV_ASSERT(dev, 6, 8);
271
272 if (format >= ARRAY_SIZE(caps))
273 return false;
274
275 switch (access) {
276 case ILO_STATE_SURFACE_ACCESS_DP_RENDER:
277 return (caps[format].rt_write &&
278 ilo_dev_gen(dev) >= caps[format].rt_write);
279 case ILO_STATE_SURFACE_ACCESS_DP_TYPED:
280 return (caps[format].typed_write &&
281 ilo_dev_gen(dev) >= caps[format].typed_write);
282 case ILO_STATE_SURFACE_ACCESS_DP_UNTYPED:
283 return (format == GEN6_FORMAT_RAW);
284 case ILO_STATE_SURFACE_ACCESS_DP_DATA:
285 /* ignored, but can it be raw? */
286 assert(format != GEN6_FORMAT_RAW);
287 return true;
288 default:
289 return false;
290 }
291 }
292
293 static bool
surface_valid_svb_format(const struct ilo_dev * dev,enum gen_surface_format format)294 surface_valid_svb_format(const struct ilo_dev *dev,
295 enum gen_surface_format format)
296 {
297 ILO_DEV_ASSERT(dev, 6, 8);
298
299 /*
300 * This table is based on:
301 *
302 * - the Sandy Bridge PRM, volume 4 part 1, page 88-97
303 * - the Ivy Bridge PRM, volume 2 part 1, page 195
304 * - the Haswell PRM, volume 7, page 535
305 */
306 switch (format) {
307 case GEN6_FORMAT_R32G32B32A32_FLOAT:
308 case GEN6_FORMAT_R32G32B32A32_SINT:
309 case GEN6_FORMAT_R32G32B32A32_UINT:
310 case GEN6_FORMAT_R32G32B32_FLOAT:
311 case GEN6_FORMAT_R32G32B32_SINT:
312 case GEN6_FORMAT_R32G32B32_UINT:
313 case GEN6_FORMAT_R32G32_FLOAT:
314 case GEN6_FORMAT_R32G32_SINT:
315 case GEN6_FORMAT_R32G32_UINT:
316 case GEN6_FORMAT_R32_SINT:
317 case GEN6_FORMAT_R32_UINT:
318 case GEN6_FORMAT_R32_FLOAT:
319 return true;
320 default:
321 return false;
322 }
323 }
324
325 bool
ilo_state_surface_valid_format(const struct ilo_dev * dev,enum ilo_state_surface_access access,enum gen_surface_format format)326 ilo_state_surface_valid_format(const struct ilo_dev *dev,
327 enum ilo_state_surface_access access,
328 enum gen_surface_format format)
329 {
330 bool valid;
331
332 switch (access) {
333 case ILO_STATE_SURFACE_ACCESS_SAMPLER:
334 valid = surface_valid_sampler_format(dev, access, format);
335 break;
336 case ILO_STATE_SURFACE_ACCESS_DP_RENDER:
337 case ILO_STATE_SURFACE_ACCESS_DP_TYPED:
338 case ILO_STATE_SURFACE_ACCESS_DP_UNTYPED:
339 case ILO_STATE_SURFACE_ACCESS_DP_DATA:
340 valid = surface_valid_dp_format(dev, access, format);
341 break;
342 case ILO_STATE_SURFACE_ACCESS_DP_SVB:
343 valid = surface_valid_svb_format(dev, format);
344 break;
345 default:
346 valid = false;
347 break;
348 }
349
350 return valid;
351 }
352