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
29 #include "brw_device_info.h"
30 #include "util/macros.h"
34 #define isl_finishme(format, ...) \
35 __isl_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__)
37 void PRINTFLIKE(3, 4) UNUSED
38 __isl_finishme(const char *file
, int line
, const char *fmt
, ...);
40 #define MIN(a, b) ((a) < (b) ? (a) : (b))
41 #define MAX(a, b) ((a) > (b) ? (a) : (b))
44 isl_is_pow2(uintmax_t n
)
46 return !(n
& (n
- 1));
50 * Alignment must be a power of 2.
53 isl_is_aligned(uintmax_t n
, uintmax_t a
)
55 assert(isl_is_pow2(a
));
56 return (n
& (a
- 1)) == 0;
60 * Alignment must be a power of 2.
62 static inline uintmax_t
63 isl_align(uintmax_t n
, uintmax_t a
)
65 assert(a
!= 0 && isl_is_pow2(a
));
66 return (n
+ a
- 1) & ~(a
- 1);
69 static inline uintmax_t
70 isl_align_npot(uintmax_t n
, uintmax_t a
)
73 return ((n
+ a
- 1) / a
) * a
;
77 * Alignment must be a power of 2.
79 static inline uintmax_t
80 isl_align_div(uintmax_t n
, uintmax_t a
)
82 return isl_align(n
, a
) / a
;
85 static inline uintmax_t
86 isl_align_div_npot(uintmax_t n
, uintmax_t a
)
88 return isl_align_npot(n
, a
) / a
;
92 * Log base 2, rounding towards zero.
94 static inline uint32_t
98 return 31 - __builtin_clz(n
);
101 static inline uint32_t
102 isl_minify(uint32_t n
, uint32_t levels
)
104 if (unlikely(n
== 0))
107 return MAX(n
>> levels
, 1);
110 static inline struct isl_extent3d
111 isl_extent3d_sa_to_el(enum isl_format fmt
, struct isl_extent3d extent_sa
)
113 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
115 assert(extent_sa
.w
% fmtl
->bw
== 0);
116 assert(extent_sa
.h
% fmtl
->bh
== 0);
117 assert(extent_sa
.d
% fmtl
->bd
== 0);
119 return (struct isl_extent3d
) {
120 .w
= extent_sa
.w
/ fmtl
->bw
,
121 .h
= extent_sa
.h
/ fmtl
->bh
,
122 .d
= extent_sa
.d
/ fmtl
->bd
,
126 static inline struct isl_extent3d
127 isl_extent3d_el_to_sa(enum isl_format fmt
, struct isl_extent3d extent_el
)
129 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
131 return (struct isl_extent3d
) {
132 .w
= extent_el
.w
* fmtl
->bw
,
133 .h
= extent_el
.h
* fmtl
->bh
,
134 .d
= extent_el
.d
* fmtl
->bd
,
139 isl_gen7_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
140 const struct isl_surf_fill_state_info
*restrict info
);
143 isl_gen75_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
144 const struct isl_surf_fill_state_info
*restrict info
);
146 isl_gen8_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
147 const struct isl_surf_fill_state_info
*restrict info
);
149 isl_gen9_surf_fill_state_s(const struct isl_device
*dev
, void *state
,
150 const struct isl_surf_fill_state_info
*restrict info
);
153 isl_gen7_buffer_fill_state_s(void *state
,
154 const struct isl_buffer_fill_state_info
*restrict info
);
157 isl_gen75_buffer_fill_state_s(void *state
,
158 const struct isl_buffer_fill_state_info
*restrict info
);
161 isl_gen8_buffer_fill_state_s(void *state
,
162 const struct isl_buffer_fill_state_info
*restrict info
);
165 isl_gen9_buffer_fill_state_s(void *state
,
166 const struct isl_buffer_fill_state_info
*restrict info
);