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 <strings.h> 29 30 #include "common/gen_device_info.h" 31 #include "util/macros.h" 32 33 #include "isl.h" 34 35 #define isl_finishme(format, ...) \ 36 do { \ 37 static bool reported = false; \ 38 if (!reported) { \ 39 __isl_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \ 40 reported = true; \ 41 } \ 42 } while (0) 43 44 void PRINTFLIKE(3, 4) UNUSED 45 __isl_finishme(const char *file, int line, const char *fmt, ...); 46 47 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 48 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 49 50 static inline bool 51 isl_is_pow2(uintmax_t n) 52 { 53 return !(n & (n - 1)); 54 } 55 56 /** 57 * Alignment must be a power of 2. 58 */ 59 static inline bool 60 isl_is_aligned(uintmax_t n, uintmax_t a) 61 { 62 assert(isl_is_pow2(a)); 63 return (n & (a - 1)) == 0; 64 } 65 66 /** 67 * Alignment must be a power of 2. 68 */ 69 static inline uintmax_t 70 isl_align(uintmax_t n, uintmax_t a) 71 { 72 assert(a != 0 && isl_is_pow2(a)); 73 return (n + a - 1) & ~(a - 1); 74 } 75 76 static inline uintmax_t 77 isl_align_npot(uintmax_t n, uintmax_t a) 78 { 79 assert(a > 0); 80 return ((n + a - 1) / a) * a; 81 } 82 83 /** 84 * Alignment must be a power of 2. 85 */ 86 static inline uintmax_t 87 isl_align_div(uintmax_t n, uintmax_t a) 88 { 89 return isl_align(n, a) / a; 90 } 91 92 static inline uintmax_t 93 isl_align_div_npot(uintmax_t n, uintmax_t a) 94 { 95 return isl_align_npot(n, a) / a; 96 } 97 98 /** 99 * Log base 2, rounding towards zero. 100 */ 101 static inline uint32_t 102 isl_log2u(uint32_t n) 103 { 104 assert(n != 0); 105 return 31 - __builtin_clz(n); 106 } 107 108 static inline uint32_t 109 isl_round_up_to_power_of_two(uint32_t value) 110 { 111 if (value <= 1) 112 return value; 113 114 return 1 << (32 - __builtin_clz(value - 1)); 115 } 116 117 static inline uint32_t 118 isl_minify(uint32_t n, uint32_t levels) 119 { 120 if (unlikely(n == 0)) 121 return 0; 122 else 123 return MAX(n >> levels, 1); 124 } 125 126 static inline struct isl_extent3d 127 isl_extent3d_sa_to_el(enum isl_format fmt, struct isl_extent3d extent_sa) 128 { 129 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt); 130 131 assert(extent_sa.w % fmtl->bw == 0); 132 assert(extent_sa.h % fmtl->bh == 0); 133 assert(extent_sa.d % fmtl->bd == 0); 134 135 return (struct isl_extent3d) { 136 .w = extent_sa.w / fmtl->bw, 137 .h = extent_sa.h / fmtl->bh, 138 .d = extent_sa.d / fmtl->bd, 139 }; 140 } 141 142 static inline struct isl_extent3d 143 isl_extent3d_el_to_sa(enum isl_format fmt, struct isl_extent3d extent_el) 144 { 145 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt); 146 147 return (struct isl_extent3d) { 148 .w = extent_el.w * fmtl->bw, 149 .h = extent_el.h * fmtl->bh, 150 .d = extent_el.d * fmtl->bd, 151 }; 152 } 153 154 void 155 isl_gen4_surf_fill_state_s(const struct isl_device *dev, void *state, 156 const struct isl_surf_fill_state_info *restrict info); 157 158 void 159 isl_gen5_surf_fill_state_s(const struct isl_device *dev, void *state, 160 const struct isl_surf_fill_state_info *restrict info); 161 162 void 163 isl_gen6_surf_fill_state_s(const struct isl_device *dev, void *state, 164 const struct isl_surf_fill_state_info *restrict info); 165 166 void 167 isl_gen7_surf_fill_state_s(const struct isl_device *dev, void *state, 168 const struct isl_surf_fill_state_info *restrict info); 169 170 void 171 isl_gen75_surf_fill_state_s(const struct isl_device *dev, void *state, 172 const struct isl_surf_fill_state_info *restrict info); 173 void 174 isl_gen8_surf_fill_state_s(const struct isl_device *dev, void *state, 175 const struct isl_surf_fill_state_info *restrict info); 176 void 177 isl_gen9_surf_fill_state_s(const struct isl_device *dev, void *state, 178 const struct isl_surf_fill_state_info *restrict info); 179 180 void 181 isl_gen4_buffer_fill_state_s(void *state, 182 const struct isl_buffer_fill_state_info *restrict info); 183 184 void 185 isl_gen5_buffer_fill_state_s(void *state, 186 const struct isl_buffer_fill_state_info *restrict info); 187 188 void 189 isl_gen6_buffer_fill_state_s(void *state, 190 const struct isl_buffer_fill_state_info *restrict info); 191 192 void 193 isl_gen7_buffer_fill_state_s(void *state, 194 const struct isl_buffer_fill_state_info *restrict info); 195 196 void 197 isl_gen75_buffer_fill_state_s(void *state, 198 const struct isl_buffer_fill_state_info *restrict info); 199 200 void 201 isl_gen8_buffer_fill_state_s(void *state, 202 const struct isl_buffer_fill_state_info *restrict info); 203 204 void 205 isl_gen9_buffer_fill_state_s(void *state, 206 const struct isl_buffer_fill_state_info *restrict info); 207 208 #endif /* ISL_PRIV_H */ 209