2 * Copyright 2015 Intel Corporation
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:
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
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
30 #include "common/gen_device_info.h"
31 #include "util/macros.h"
35 #define isl_finishme(format, ...) \
37 static bool reported = false; \
39 __isl_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
44 void PRINTFLIKE(3, 4) UNUSED
45 __isl_finishme(const char *file
, int line
, const char *fmt
, ...);
47 #define MIN(a, b) ((a) < (b) ? (a) : (b))
48 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 isl_is_pow2(uintmax_t n
)
53 return !(n
& (n
- 1));
57 * Alignment must be a power of 2.
60 isl_is_aligned(uintmax_t n
, uintmax_t a
)
62 assert(isl_is_pow2(a
));
63 return (n
& (a
- 1)) == 0;
67 * Alignment must be a power of 2.
69 static inline uintmax_t
70 isl_align(uintmax_t n
, uintmax_t a
)
72 assert(a
!= 0 && isl_is_pow2(a
));
73 return (n
+ a
- 1) & ~(a
- 1);
76 static inline uintmax_t
77 isl_align_npot(uintmax_t n
, uintmax_t a
)
80 return ((n
+ a
- 1) / a
) * a
;
83 static inline uintmax_t
84 isl_assert_div(uintmax_t n
, uintmax_t a
)
91 * Alignment must be a power of 2.
93 static inline uintmax_t
94 isl_align_div(uintmax_t n
, uintmax_t a
)
96 return isl_align(n
, a
) / a
;
99 static inline uintmax_t
100 isl_align_div_npot(uintmax_t n
, uintmax_t a
)
102 return isl_align_npot(n
, a
) / a
;
106 * Log base 2, rounding towards zero.
108 static inline uint32_t
109 isl_log2u(uint32_t n
)
112 return 31 - __builtin_clz(n
);
115 static inline uint32_t
116 isl_round_up_to_power_of_two(uint32_t value
)
121 return 1 << (32 - __builtin_clz(value
- 1));
124 static inline uint32_t
125 isl_minify(uint32_t n
, uint32_t levels
)
127 if (unlikely(n
== 0))
130 return MAX(n
>> levels
, 1);
133 static inline struct isl_extent3d
134 isl_extent3d_sa_to_el(enum isl_format fmt
, struct isl_extent3d extent_sa
)
136 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
138 assert(extent_sa
.w
% fmtl
->bw
== 0);
139 assert(extent_sa
.h
% fmtl
->bh
== 0);
140 assert(extent_sa
.d
% fmtl
->bd
== 0);
142 return (struct isl_extent3d
) {
143 .w
= extent_sa
.w
/ fmtl
->bw
,
144 .h
= extent_sa
.h
/ fmtl
->bh
,
145 .d
= extent_sa
.d
/ fmtl
->bd
,
149 static inline struct isl_extent3d
150 isl_extent3d_el_to_sa(enum isl_format fmt
, struct isl_extent3d extent_el
)
152 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
154 return (struct isl_extent3d
) {
155 .w
= extent_el
.w
* fmtl
->bw
,
156 .h
= extent_el
.h
* fmtl
->bh
,
157 .d
= extent_el
.d
* fmtl
->bd
,
162 isl_gen4_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
163 const struct isl_surf_fill_state_info
*restrict info
);
166 isl_gen5_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
167 const struct isl_surf_fill_state_info
*restrict info
);
170 isl_gen6_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
171 const struct isl_surf_fill_state_info
*restrict info
);
174 isl_gen7_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
175 const struct isl_surf_fill_state_info
*restrict info
);
178 isl_gen75_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
179 const struct isl_surf_fill_state_info
*restrict info
);
181 isl_gen8_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
182 const struct isl_surf_fill_state_info
*restrict info
);
184 isl_gen9_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
185 const struct isl_surf_fill_state_info
*restrict info
);
188 isl_gen4_buffer_fill_state_s(void *state
,
189 const struct isl_buffer_fill_state_info
*restrict info
);
192 isl_gen5_buffer_fill_state_s(void *state
,
193 const struct isl_buffer_fill_state_info
*restrict info
);
196 isl_gen6_buffer_fill_state_s(void *state
,
197 const struct isl_buffer_fill_state_info
*restrict info
);
200 isl_gen7_buffer_fill_state_s(void *state
,
201 const struct isl_buffer_fill_state_info
*restrict info
);
204 isl_gen75_buffer_fill_state_s(void *state
,
205 const struct isl_buffer_fill_state_info
*restrict info
);
208 isl_gen8_buffer_fill_state_s(void *state
,
209 const struct isl_buffer_fill_state_info
*restrict info
);
212 isl_gen9_buffer_fill_state_s(void *state
,
213 const struct isl_buffer_fill_state_info
*restrict info
);
216 isl_gen4_emit_depth_stencil_hiz_s(const struct isl_device
*dev
, void *batch
,
217 const struct isl_depth_stencil_hiz_emit_info
*restrict info
);
220 isl_gen5_emit_depth_stencil_hiz_s(const struct isl_device
*dev
, void *batch
,
221 const struct isl_depth_stencil_hiz_emit_info
*restrict info
);
224 isl_gen6_emit_depth_stencil_hiz_s(const struct isl_device
*dev
, void *batch
,
225 const struct isl_depth_stencil_hiz_emit_info
*restrict info
);
228 isl_gen7_emit_depth_stencil_hiz_s(const struct isl_device
*dev
, void *batch
,
229 const struct isl_depth_stencil_hiz_emit_info
*restrict info
);
232 isl_gen75_emit_depth_stencil_hiz_s(const struct isl_device
*dev
, void *batch
,
233 const struct isl_depth_stencil_hiz_emit_info
*restrict info
);
236 isl_gen8_emit_depth_stencil_hiz_s(const struct isl_device
*dev
, void *batch
,
237 const struct isl_depth_stencil_hiz_emit_info
*restrict info
);
240 isl_gen9_emit_depth_stencil_hiz_s(const struct isl_device
*dev
, void *batch
,
241 const struct isl_depth_stencil_hiz_emit_info
*restrict info
);
243 #endif /* ISL_PRIV_H */