1 /*
2 * Copyright 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef ISL_PRIV_H
25 #define ISL_PRIV_H
26
27 #include <assert.h>
28 #include <stddef.h>
29 #include <strings.h>
30
31 #include "dev/intel_device_info.h"
32 #include "util/macros.h"
33
34 #include "isl.h"
35
36 typedef void (*isl_surf_fill_state_s_func)(
37 const struct isl_device *dev, void *state,
38 const struct isl_surf_fill_state_info *restrict info);
39
40 typedef void (*isl_buffer_fill_state_s_func)(
41 const struct isl_device *dev, void *state,
42 const struct isl_buffer_fill_state_info *restrict info);
43
44 typedef void (*isl_emit_depth_stencil_hiz_s_func)(
45 const struct isl_device *dev, void *state,
46 const struct isl_depth_stencil_hiz_emit_info *restrict info);
47
48 typedef void (*isl_null_fill_state_s_func)(const struct isl_device *dev, void *state,
49 const struct isl_null_fill_state_info *restrict info);
50
51 typedef void (*isl_emit_cpb_control_s_func)(const struct isl_device *dev, void *batch,
52 const struct isl_cpb_emit_info *restrict info);
53
54 #define isl_genX_declare_get_func(func) \
55 static inline isl_##func##_func \
56 isl_##func##_get_func(const struct isl_device *dev) { \
57 switch (ISL_GFX_VERX10(dev)) { \
58 case 40: \
59 return isl_gfx4_##func; \
60 case 45: \
61 /* G45 surface state is the same as gfx5 */ \
62 case 50: \
63 return isl_gfx5_##func; \
64 case 60: \
65 return isl_gfx6_##func; \
66 case 70: \
67 return isl_gfx7_##func; \
68 case 75: \
69 return isl_gfx75_##func; \
70 case 80: \
71 return isl_gfx8_##func; \
72 case 90: \
73 return isl_gfx9_##func; \
74 case 110: \
75 return isl_gfx11_##func; \
76 case 120: \
77 return isl_gfx12_##func; \
78 case 125: \
79 return isl_gfx125_##func; \
80 case 200: \
81 return isl_gfx20_##func; \
82 case 300: \
83 return isl_gfx30_##func; \
84 default: \
85 assert(!"Unknown hardware generation"); \
86 return NULL; \
87 } \
88 }
89
90 #define isl_finishme(format, ...) \
91 do { \
92 static bool reported = false; \
93 if (!reported) { \
94 __isl_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
95 reported = true; \
96 } \
97 } while (0)
98
99 void PRINTFLIKE(3, 4) UNUSED
100 __isl_finishme(const char *file, int line, const char *fmt, ...);
101
102 #define MIN(a, b) ((a) < (b) ? (a) : (b))
103 #define MAX(a, b) ((a) > (b) ? (a) : (b))
104
105 typedef void *(*isl_mem_copy_fn)(void *dest, const void *src, size_t n);
106
107 static inline bool
isl_is_pow2(uintmax_t n)108 isl_is_pow2(uintmax_t n)
109 {
110 return !(n & (n - 1));
111 }
112
113 /**
114 * Alignment must be a power of 2.
115 */
116 static inline bool
isl_is_aligned(uintmax_t n,uintmax_t a)117 isl_is_aligned(uintmax_t n, uintmax_t a)
118 {
119 assert(isl_is_pow2(a));
120 return (n & (a - 1)) == 0;
121 }
122
123 /**
124 * Alignment must be a power of 2.
125 */
126 static inline uintmax_t
isl_align(uintmax_t n,uintmax_t a)127 isl_align(uintmax_t n, uintmax_t a)
128 {
129 assert(a != 0 && isl_is_pow2(a));
130 return (n + a - 1) & ~(a - 1);
131 }
132
133 static inline uintmax_t
isl_align_npot(uintmax_t n,uintmax_t a)134 isl_align_npot(uintmax_t n, uintmax_t a)
135 {
136 assert(a > 0);
137 return ((n + a - 1) / a) * a;
138 }
139
140 static inline uintmax_t
isl_assert_div(uintmax_t n,uintmax_t a)141 isl_assert_div(uintmax_t n, uintmax_t a)
142 {
143 assert(n % a == 0);
144 return n / a;
145 }
146
147 /**
148 * Alignment must be a power of 2.
149 */
150 static inline uintmax_t
isl_align_div(uintmax_t n,uintmax_t a)151 isl_align_div(uintmax_t n, uintmax_t a)
152 {
153 return isl_align(n, a) / a;
154 }
155
156 static inline uintmax_t
isl_align_div_npot(uintmax_t n,uintmax_t a)157 isl_align_div_npot(uintmax_t n, uintmax_t a)
158 {
159 return isl_align_npot(n, a) / a;
160 }
161
162 /**
163 * Log base 2, rounding towards zero.
164 */
165 static inline uint32_t
isl_log2u(uint32_t n)166 isl_log2u(uint32_t n)
167 {
168 assert(n != 0);
169 return 31 - __builtin_clz(n);
170 }
171
172 static inline uint32_t
isl_round_up_to_power_of_two(uint32_t value)173 isl_round_up_to_power_of_two(uint32_t value)
174 {
175 if (value <= 1)
176 return value;
177
178 return 1 << (32 - __builtin_clz(value - 1));
179 }
180
181 static inline uint32_t
isl_minify(uint32_t n,uint32_t levels)182 isl_minify(uint32_t n, uint32_t levels)
183 {
184 if (unlikely(n == 0))
185 return 0;
186 else
187 return MAX(n >> levels, 1);
188 }
189
190 static inline struct isl_extent3d
isl_extent3d_sa_to_el(enum isl_format fmt,struct isl_extent3d extent_sa)191 isl_extent3d_sa_to_el(enum isl_format fmt, struct isl_extent3d extent_sa)
192 {
193 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
194
195 assert(extent_sa.w % fmtl->bw == 0);
196 assert(extent_sa.h % fmtl->bh == 0);
197 assert(extent_sa.d % fmtl->bd == 0);
198
199 return (struct isl_extent3d) {
200 .w = extent_sa.w / fmtl->bw,
201 .h = extent_sa.h / fmtl->bh,
202 .d = extent_sa.d / fmtl->bd,
203 };
204 }
205
206 static inline struct isl_extent3d
isl_extent3d_el_to_sa(enum isl_format fmt,struct isl_extent3d extent_el)207 isl_extent3d_el_to_sa(enum isl_format fmt, struct isl_extent3d extent_el)
208 {
209 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
210
211 return (struct isl_extent3d) {
212 .w = extent_el.w * fmtl->bw,
213 .h = extent_el.h * fmtl->bh,
214 .d = extent_el.d * fmtl->bd,
215 };
216 }
217
218 bool
219 _isl_surf_info_supports_ccs(const struct isl_device *dev,
220 enum isl_format format,
221 isl_surf_usage_flags_t usage);
222
223 void
224 _isl_memcpy_linear_to_tiled(uint32_t xt1, uint32_t xt2,
225 uint32_t yt1, uint32_t yt2,
226 char *dst, const char *src,
227 uint32_t dst_pitch, int32_t src_pitch,
228 bool has_swizzling,
229 enum isl_tiling tiling,
230 isl_memcpy_type copy_type);
231
232 void
233 _isl_memcpy_tiled_to_linear(uint32_t xt1, uint32_t xt2,
234 uint32_t yt1, uint32_t yt2,
235 char *dst, const char *src,
236 int32_t dst_pitch, uint32_t src_pitch,
237 bool has_swizzling,
238 enum isl_tiling tiling,
239 isl_memcpy_type copy_type);
240
241 void
242 _isl_memcpy_linear_to_tiled_sse41(uint32_t xt1, uint32_t xt2,
243 uint32_t yt1, uint32_t yt2,
244 char *dst, const char *src,
245 uint32_t dst_pitch, int32_t src_pitch,
246 bool has_swizzling,
247 enum isl_tiling tiling,
248 isl_memcpy_type copy_type);
249
250 void
251 _isl_memcpy_tiled_to_linear_sse41(uint32_t xt1, uint32_t xt2,
252 uint32_t yt1, uint32_t yt2,
253 char *dst, const char *src,
254 int32_t dst_pitch, uint32_t src_pitch,
255 bool has_swizzling,
256 enum isl_tiling tiling,
257 isl_memcpy_type copy_type);
258
259 void PRINTFLIKE(4, 5)
260 _isl_notify_failure(const struct isl_surf_init_info *surf_info,
261 const char *file, int line, const char *fmt, ...);
262
263 #define notify_failure(surf_info, ...) \
264 (_isl_notify_failure(surf_info, __FILE__, __LINE__, __VA_ARGS__), false)
265
266
267 /* This is useful for adding the isl_prefix to genX functions */
268 #define isl_genX(x) CONCAT2(isl_, genX(x))
269
270 #ifdef genX
271 # include "isl_genX_priv.h"
272 #else
273 # define genX(x) gfx4_##x
274 # include "isl_genX_priv.h"
275 # undef genX
276 # define genX(x) gfx5_##x
277 # include "isl_genX_priv.h"
278 # undef genX
279 # define genX(x) gfx6_##x
280 # include "isl_genX_priv.h"
281 # undef genX
282 # define genX(x) gfx7_##x
283 # include "isl_genX_priv.h"
284 # undef genX
285 # define genX(x) gfx75_##x
286 # include "isl_genX_priv.h"
287 # undef genX
288 # define genX(x) gfx8_##x
289 # include "isl_genX_priv.h"
290 # undef genX
291 # define genX(x) gfx9_##x
292 # include "isl_genX_priv.h"
293 # undef genX
294 # define genX(x) gfx11_##x
295 # include "isl_genX_priv.h"
296 # undef genX
297 # define genX(x) gfx12_##x
298 # include "isl_genX_priv.h"
299 # undef genX
300 # define genX(x) gfx125_##x
301 # include "isl_genX_priv.h"
302 # undef genX
303 # define genX(x) gfx20_##x
304 # include "isl_genX_priv.h"
305 # undef genX
306 # define genX(x) gfx30_##x
307 # include "isl_genX_priv.h"
308 # undef genX
309 #endif
310
311 #endif /* ISL_PRIV_H */
312