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