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 default: \
83 assert(!"Unknown hardware generation"); \
84 return NULL; \
85 } \
86 }
87
88 #define isl_finishme(format, ...) \
89 do { \
90 static bool reported = false; \
91 if (!reported) { \
92 __isl_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
93 reported = true; \
94 } \
95 } while (0)
96
97 void PRINTFLIKE(3, 4) UNUSED
98 __isl_finishme(const char *file, int line, const char *fmt, ...);
99
100 #define MIN(a, b) ((a) < (b) ? (a) : (b))
101 #define MAX(a, b) ((a) > (b) ? (a) : (b))
102
103 typedef void *(*isl_mem_copy_fn)(void *dest, const void *src, size_t n);
104
105 static inline bool
isl_is_pow2(uintmax_t n)106 isl_is_pow2(uintmax_t n)
107 {
108 return !(n & (n - 1));
109 }
110
111 /**
112 * Alignment must be a power of 2.
113 */
114 static inline bool
isl_is_aligned(uintmax_t n,uintmax_t a)115 isl_is_aligned(uintmax_t n, uintmax_t a)
116 {
117 assert(isl_is_pow2(a));
118 return (n & (a - 1)) == 0;
119 }
120
121 /**
122 * Alignment must be a power of 2.
123 */
124 static inline uintmax_t
isl_align(uintmax_t n,uintmax_t a)125 isl_align(uintmax_t n, uintmax_t a)
126 {
127 assert(a != 0 && isl_is_pow2(a));
128 return (n + a - 1) & ~(a - 1);
129 }
130
131 static inline uintmax_t
isl_align_npot(uintmax_t n,uintmax_t a)132 isl_align_npot(uintmax_t n, uintmax_t a)
133 {
134 assert(a > 0);
135 return ((n + a - 1) / a) * a;
136 }
137
138 static inline uintmax_t
isl_assert_div(uintmax_t n,uintmax_t a)139 isl_assert_div(uintmax_t n, uintmax_t a)
140 {
141 assert(n % a == 0);
142 return n / a;
143 }
144
145 /**
146 * Alignment must be a power of 2.
147 */
148 static inline uintmax_t
isl_align_div(uintmax_t n,uintmax_t a)149 isl_align_div(uintmax_t n, uintmax_t a)
150 {
151 return isl_align(n, a) / a;
152 }
153
154 static inline uintmax_t
isl_align_div_npot(uintmax_t n,uintmax_t a)155 isl_align_div_npot(uintmax_t n, uintmax_t a)
156 {
157 return isl_align_npot(n, a) / a;
158 }
159
160 /**
161 * Log base 2, rounding towards zero.
162 */
163 static inline uint32_t
isl_log2u(uint32_t n)164 isl_log2u(uint32_t n)
165 {
166 assert(n != 0);
167 return 31 - __builtin_clz(n);
168 }
169
170 static inline uint32_t
isl_round_up_to_power_of_two(uint32_t value)171 isl_round_up_to_power_of_two(uint32_t value)
172 {
173 if (value <= 1)
174 return value;
175
176 return 1 << (32 - __builtin_clz(value - 1));
177 }
178
179 static inline uint32_t
isl_minify(uint32_t n,uint32_t levels)180 isl_minify(uint32_t n, uint32_t levels)
181 {
182 if (unlikely(n == 0))
183 return 0;
184 else
185 return MAX(n >> levels, 1);
186 }
187
188 static inline struct isl_extent3d
isl_extent3d_sa_to_el(enum isl_format fmt,struct isl_extent3d extent_sa)189 isl_extent3d_sa_to_el(enum isl_format fmt, struct isl_extent3d extent_sa)
190 {
191 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
192
193 assert(extent_sa.w % fmtl->bw == 0);
194 assert(extent_sa.h % fmtl->bh == 0);
195 assert(extent_sa.d % fmtl->bd == 0);
196
197 return (struct isl_extent3d) {
198 .w = extent_sa.w / fmtl->bw,
199 .h = extent_sa.h / fmtl->bh,
200 .d = extent_sa.d / fmtl->bd,
201 };
202 }
203
204 static inline struct isl_extent3d
isl_extent3d_el_to_sa(enum isl_format fmt,struct isl_extent3d extent_el)205 isl_extent3d_el_to_sa(enum isl_format fmt, struct isl_extent3d extent_el)
206 {
207 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
208
209 return (struct isl_extent3d) {
210 .w = extent_el.w * fmtl->bw,
211 .h = extent_el.h * fmtl->bh,
212 .d = extent_el.d * fmtl->bd,
213 };
214 }
215
216 void
217 _isl_memcpy_linear_to_tiled(uint32_t xt1, uint32_t xt2,
218 uint32_t yt1, uint32_t yt2,
219 char *dst, const char *src,
220 uint32_t dst_pitch, int32_t src_pitch,
221 bool has_swizzling,
222 enum isl_tiling tiling,
223 isl_memcpy_type copy_type);
224
225 void
226 _isl_memcpy_tiled_to_linear(uint32_t xt1, uint32_t xt2,
227 uint32_t yt1, uint32_t yt2,
228 char *dst, const char *src,
229 int32_t dst_pitch, uint32_t src_pitch,
230 bool has_swizzling,
231 enum isl_tiling tiling,
232 isl_memcpy_type copy_type);
233
234 void
235 _isl_memcpy_linear_to_tiled_sse41(uint32_t xt1, uint32_t xt2,
236 uint32_t yt1, uint32_t yt2,
237 char *dst, const char *src,
238 uint32_t dst_pitch, int32_t src_pitch,
239 bool has_swizzling,
240 enum isl_tiling tiling,
241 isl_memcpy_type copy_type);
242
243 void
244 _isl_memcpy_tiled_to_linear_sse41(uint32_t xt1, uint32_t xt2,
245 uint32_t yt1, uint32_t yt2,
246 char *dst, const char *src,
247 int32_t dst_pitch, uint32_t src_pitch,
248 bool has_swizzling,
249 enum isl_tiling tiling,
250 isl_memcpy_type copy_type);
251
252 void PRINTFLIKE(4, 5)
253 _isl_notify_failure(const struct isl_surf_init_info *surf_info,
254 const char *file, int line, const char *fmt, ...);
255
256 #define notify_failure(surf_info, ...) \
257 (_isl_notify_failure(surf_info, __FILE__, __LINE__, __VA_ARGS__), false)
258
259
260 /* This is useful for adding the isl_prefix to genX functions */
261 #define isl_genX(x) CONCAT2(isl_, genX(x))
262
263 #ifdef genX
264 # include "isl_genX_priv.h"
265 #else
266 # define genX(x) gfx4_##x
267 # include "isl_genX_priv.h"
268 # undef genX
269 # define genX(x) gfx5_##x
270 # include "isl_genX_priv.h"
271 # undef genX
272 # define genX(x) gfx6_##x
273 # include "isl_genX_priv.h"
274 # undef genX
275 # define genX(x) gfx7_##x
276 # include "isl_genX_priv.h"
277 # undef genX
278 # define genX(x) gfx75_##x
279 # include "isl_genX_priv.h"
280 # undef genX
281 # define genX(x) gfx8_##x
282 # include "isl_genX_priv.h"
283 # undef genX
284 # define genX(x) gfx9_##x
285 # include "isl_genX_priv.h"
286 # undef genX
287 # define genX(x) gfx11_##x
288 # include "isl_genX_priv.h"
289 # undef genX
290 # define genX(x) gfx12_##x
291 # include "isl_genX_priv.h"
292 # undef genX
293 # define genX(x) gfx125_##x
294 # include "isl_genX_priv.h"
295 # undef genX
296 # define genX(x) gfx20_##x
297 # include "isl_genX_priv.h"
298 # undef genX
299 #endif
300
301 #endif /* ISL_PRIV_H */
302