xref: /aosp_15_r20/external/mesa3d/src/intel/isl/isl_priv.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 bool
217 _isl_surf_info_supports_ccs(const struct isl_device *dev,
218                             enum isl_format format,
219                             isl_surf_usage_flags_t usage);
220 
221 void
222 _isl_memcpy_linear_to_tiled(uint32_t xt1, uint32_t xt2,
223                             uint32_t yt1, uint32_t yt2,
224                             char *dst, const char *src,
225                             uint32_t dst_pitch, int32_t src_pitch,
226                             bool has_swizzling,
227                             enum isl_tiling tiling,
228                             isl_memcpy_type copy_type);
229 
230 void
231 _isl_memcpy_tiled_to_linear(uint32_t xt1, uint32_t xt2,
232                             uint32_t yt1, uint32_t yt2,
233                             char *dst, const char *src,
234                             int32_t dst_pitch, uint32_t src_pitch,
235                             bool has_swizzling,
236                             enum isl_tiling tiling,
237                             isl_memcpy_type copy_type);
238 
239 void
240 _isl_memcpy_linear_to_tiled_sse41(uint32_t xt1, uint32_t xt2,
241                                   uint32_t yt1, uint32_t yt2,
242                                   char *dst, const char *src,
243                                   uint32_t dst_pitch, int32_t src_pitch,
244                                   bool has_swizzling,
245                                   enum isl_tiling tiling,
246                                   isl_memcpy_type copy_type);
247 
248 void
249 _isl_memcpy_tiled_to_linear_sse41(uint32_t xt1, uint32_t xt2,
250                                   uint32_t yt1, uint32_t yt2,
251                                   char *dst, const char *src,
252                                   int32_t dst_pitch, uint32_t src_pitch,
253                                   bool has_swizzling,
254                                   enum isl_tiling tiling,
255                                   isl_memcpy_type copy_type);
256 
257 void PRINTFLIKE(4, 5)
258 _isl_notify_failure(const struct isl_surf_init_info *surf_info,
259                     const char *file, int line, const char *fmt, ...);
260 
261 #define notify_failure(surf_info, ...) \
262    (_isl_notify_failure(surf_info, __FILE__, __LINE__, __VA_ARGS__), false)
263 
264 
265 /* This is useful for adding the isl_prefix to genX functions */
266 #define isl_genX(x) CONCAT2(isl_, genX(x))
267 
268 #ifdef genX
269 #  include "isl_genX_priv.h"
270 #else
271 #  define genX(x) gfx4_##x
272 #  include "isl_genX_priv.h"
273 #  undef genX
274 #  define genX(x) gfx5_##x
275 #  include "isl_genX_priv.h"
276 #  undef genX
277 #  define genX(x) gfx6_##x
278 #  include "isl_genX_priv.h"
279 #  undef genX
280 #  define genX(x) gfx7_##x
281 #  include "isl_genX_priv.h"
282 #  undef genX
283 #  define genX(x) gfx75_##x
284 #  include "isl_genX_priv.h"
285 #  undef genX
286 #  define genX(x) gfx8_##x
287 #  include "isl_genX_priv.h"
288 #  undef genX
289 #  define genX(x) gfx9_##x
290 #  include "isl_genX_priv.h"
291 #  undef genX
292 #  define genX(x) gfx11_##x
293 #  include "isl_genX_priv.h"
294 #  undef genX
295 #  define genX(x) gfx12_##x
296 #  include "isl_genX_priv.h"
297 #  undef genX
298 #  define genX(x) gfx125_##x
299 #  include "isl_genX_priv.h"
300 #  undef genX
301 #  define genX(x) gfx20_##x
302 #  include "isl_genX_priv.h"
303 #  undef genX
304 #endif
305 
306 #endif /* ISL_PRIV_H */
307