1 /*
2 * Copyright © 2012 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 BLORP_H
25 #define BLORP_H
26
27 #include <stdint.h>
28 #include <stdbool.h>
29
30 #include "isl/isl.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 struct brw_compiler;
37 struct elk_compiler;
38
39 enum blorp_op {
40 BLORP_OP_BLIT,
41 BLORP_OP_COPY,
42 BLORP_OP_CCS_AMBIGUATE,
43 BLORP_OP_CCS_COLOR_CLEAR,
44 BLORP_OP_CCS_PARTIAL_RESOLVE,
45 BLORP_OP_CCS_RESOLVE,
46 BLORP_OP_HIZ_AMBIGUATE,
47 BLORP_OP_HIZ_CLEAR,
48 BLORP_OP_HIZ_RESOLVE,
49 BLORP_OP_MCS_AMBIGUATE,
50 BLORP_OP_MCS_COLOR_CLEAR,
51 BLORP_OP_MCS_PARTIAL_RESOLVE,
52 BLORP_OP_SLOW_COLOR_CLEAR,
53 BLORP_OP_SLOW_DEPTH_CLEAR,
54 };
55
56 struct blorp_batch;
57 struct blorp_params;
58
59 struct blorp_config {
60 bool use_mesh_shading;
61 bool use_unrestricted_depth_range;
62 };
63
64 struct blorp_context {
65 void *driver_ctx;
66
67 const struct isl_device *isl_dev;
68
69 struct blorp_compiler *compiler;
70
71 bool enable_tbimr;
72
73 bool (*lookup_shader)(struct blorp_batch *batch,
74 const void *key, uint32_t key_size,
75 uint32_t *kernel_out, void *prog_data_out);
76 bool (*upload_shader)(struct blorp_batch *batch,
77 uint32_t stage,
78 const void *key, uint32_t key_size,
79 const void *kernel, uint32_t kernel_size,
80 const void *prog_data,
81 uint32_t prog_data_size,
82 uint32_t *kernel_out, void *prog_data_out);
83 void (*exec)(struct blorp_batch *batch, const struct blorp_params *params);
84
85 struct blorp_config config;
86 };
87
88 void blorp_init_brw(struct blorp_context *blorp, void *driver_ctx,
89 struct isl_device *isl_dev, const struct brw_compiler *brw,
90 const struct blorp_config *config);
91
92 void blorp_init_elk(struct blorp_context *blorp, void *driver_ctx,
93 struct isl_device *isl_dev, const struct elk_compiler *brw,
94 const struct blorp_config *config);
95
96 void blorp_finish(struct blorp_context *blorp);
97
98
99 enum blorp_batch_flags {
100 /**
101 * This flag indicates that blorp should *not* re-emit the depth and
102 * stencil buffer packets. Instead, the driver guarantees that all depth
103 * and stencil images passed in will match what is currently set in the
104 * hardware.
105 */
106 BLORP_BATCH_NO_EMIT_DEPTH_STENCIL = (1 << 0),
107
108 /* This flag indicates that the blorp call should be predicated. */
109 BLORP_BATCH_PREDICATE_ENABLE = (1 << 1),
110
111 /* This flag indicates that blorp should *not* update the indirect clear
112 * color buffer.
113 */
114 BLORP_BATCH_NO_UPDATE_CLEAR_COLOR = (1 << 2),
115
116 /* This flag indicates that blorp should use a compute program for the
117 * operation.
118 */
119 BLORP_BATCH_USE_COMPUTE = (1 << 3),
120
121 /** Use the hardware blitter to perform any operations in this batch */
122 BLORP_BATCH_USE_BLITTER = (1 << 4),
123 };
124
125 struct blorp_batch {
126 struct blorp_context *blorp;
127 void *driver_batch;
128 enum blorp_batch_flags flags;
129 };
130
131 void blorp_batch_init(struct blorp_context *blorp, struct blorp_batch *batch,
132 void *driver_batch, enum blorp_batch_flags flags);
133 void blorp_batch_finish(struct blorp_batch *batch);
134
135 struct blorp_address {
136 void *buffer;
137 int64_t offset;
138 unsigned reloc_flags;
139 uint32_t mocs;
140
141 /**
142 * True if this buffer is intended to live in device-local memory.
143 * This is only a performance hint; it's OK to set it to true even
144 * if eviction has temporarily forced the buffer to system memory.
145 */
146 bool local_hint;
147 };
148
149 static inline bool
blorp_address_is_null(struct blorp_address address)150 blorp_address_is_null(struct blorp_address address)
151 {
152 return address.buffer == NULL && address.offset == 0;
153 }
154
155 struct blorp_surf
156 {
157 const struct isl_surf *surf;
158 struct blorp_address addr;
159
160 const struct isl_surf *aux_surf;
161 struct blorp_address aux_addr;
162 enum isl_aux_usage aux_usage;
163
164 union isl_color_value clear_color;
165
166 /**
167 * If set (bo != NULL), clear_color is ignored and the actual clear color
168 * is fetched from this address. On gfx7-8, this is all of dword 7 of
169 * RENDER_SURFACE_STATE and is the responsibility of the caller to ensure
170 * that it contains a swizzle of RGBA and resource min LOD of 0.
171 */
172 struct blorp_address clear_color_addr;
173
174 /* Only allowed for simple 2D non-MSAA surfaces */
175 uint32_t tile_x_sa, tile_y_sa;
176 };
177
178 enum blorp_filter {
179 BLORP_FILTER_NONE,
180 BLORP_FILTER_NEAREST,
181 BLORP_FILTER_BILINEAR,
182 BLORP_FILTER_SAMPLE_0,
183 BLORP_FILTER_AVERAGE,
184 BLORP_FILTER_MIN_SAMPLE,
185 BLORP_FILTER_MAX_SAMPLE,
186 };
187
188 void
189 blorp_blit(struct blorp_batch *batch,
190 const struct blorp_surf *src_surf,
191 unsigned src_level, float src_layer,
192 enum isl_format src_format, struct isl_swizzle src_swizzle,
193 const struct blorp_surf *dst_surf,
194 unsigned dst_level, unsigned dst_layer,
195 enum isl_format dst_format, struct isl_swizzle dst_swizzle,
196 float src_x0, float src_y0,
197 float src_x1, float src_y1,
198 float dst_x0, float dst_y0,
199 float dst_x1, float dst_y1,
200 enum blorp_filter filter,
201 bool mirror_x, bool mirror_y);
202
203 void
204 blorp_copy_get_formats(const struct isl_device *isl_dev,
205 const struct isl_surf *src_surf,
206 const struct isl_surf *dst_surf,
207 enum isl_format *src_view_format,
208 enum isl_format *dst_view_format);
209
210 void
211 blorp_copy(struct blorp_batch *batch,
212 const struct blorp_surf *src_surf,
213 unsigned src_level, unsigned src_layer,
214 const struct blorp_surf *dst_surf,
215 unsigned dst_level, unsigned dst_layer,
216 uint32_t src_x, uint32_t src_y,
217 uint32_t dst_x, uint32_t dst_y,
218 uint32_t src_width, uint32_t src_height);
219
220 void
221 blorp_buffer_copy(struct blorp_batch *batch,
222 struct blorp_address src,
223 struct blorp_address dst,
224 uint64_t size);
225
226 void
227 blorp_fast_clear(struct blorp_batch *batch,
228 const struct blorp_surf *surf,
229 enum isl_format format, struct isl_swizzle swizzle,
230 uint32_t level, uint32_t start_layer, uint32_t num_layers,
231 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1);
232
233 bool
234 blorp_clear_supports_compute(struct blorp_context *blorp,
235 uint8_t color_write_disable, bool blend_enabled,
236 enum isl_aux_usage aux_usage);
237
238 bool
239 blorp_clear_supports_blitter(struct blorp_context *blorp,
240 const struct blorp_surf *surf,
241 uint8_t color_write_disable, bool blend_enabled);
242
243 bool
244 blorp_copy_supports_compute(struct blorp_context *blorp,
245 const struct isl_surf *src_surf,
246 const struct isl_surf *dst_surf,
247 enum isl_aux_usage dst_aux_usage);
248
249 bool
250 blorp_blit_supports_compute(struct blorp_context *blorp,
251 const struct isl_surf *src_surf,
252 const struct isl_surf *dst_surf,
253 enum isl_aux_usage dst_aux_usage);
254
255 bool
256 blorp_copy_supports_blitter(struct blorp_context *blorp,
257 const struct isl_surf *src_surf,
258 const struct isl_surf *dst_surf,
259 enum isl_aux_usage src_aux_usage,
260 enum isl_aux_usage dst_aux_usage);
261
262 void
263 blorp_clear(struct blorp_batch *batch,
264 const struct blorp_surf *surf,
265 enum isl_format format, struct isl_swizzle swizzle,
266 uint32_t level, uint32_t start_layer, uint32_t num_layers,
267 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
268 union isl_color_value clear_color,
269 uint8_t color_write_disable);
270
271 void
272 blorp_clear_depth_stencil(struct blorp_batch *batch,
273 const struct blorp_surf *depth,
274 const struct blorp_surf *stencil,
275 uint32_t level, uint32_t start_layer,
276 uint32_t num_layers,
277 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
278 bool clear_depth, float depth_value,
279 uint8_t stencil_mask, uint8_t stencil_value);
280 bool
281 blorp_can_hiz_clear_depth(const struct intel_device_info *devinfo,
282 const struct isl_surf *surf,
283 enum isl_aux_usage aux_usage,
284 uint32_t level, uint32_t layer,
285 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1);
286 void
287 blorp_hiz_clear_depth_stencil(struct blorp_batch *batch,
288 const struct blorp_surf *depth,
289 const struct blorp_surf *stencil,
290 uint32_t level,
291 uint32_t start_layer, uint32_t num_layers,
292 uint32_t x0, uint32_t y0,
293 uint32_t x1, uint32_t y1,
294 bool clear_depth, float depth_value,
295 bool clear_stencil, uint8_t stencil_value);
296
297
298 void
299 blorp_gfx8_hiz_clear_attachments(struct blorp_batch *batch,
300 uint32_t num_samples,
301 uint32_t x0, uint32_t y0,
302 uint32_t x1, uint32_t y1,
303 bool clear_depth, bool clear_stencil,
304 uint8_t stencil_value);
305 void
306 blorp_clear_attachments(struct blorp_batch *batch,
307 uint32_t binding_table_offset,
308 enum isl_format depth_format,
309 uint32_t num_samples,
310 uint32_t start_layer, uint32_t num_layers,
311 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
312 bool clear_color, union isl_color_value color_value,
313 bool clear_depth, float depth_value,
314 uint8_t stencil_mask, uint8_t stencil_value);
315
316 void
317 blorp_ccs_resolve(struct blorp_batch *batch,
318 struct blorp_surf *surf, uint32_t level,
319 uint32_t start_layer, uint32_t num_layers,
320 enum isl_format format,
321 enum isl_aux_op resolve_op);
322
323 void
324 blorp_ccs_ambiguate(struct blorp_batch *batch,
325 struct blorp_surf *surf,
326 uint32_t level, uint32_t layer);
327
328 void
329 blorp_mcs_partial_resolve(struct blorp_batch *batch,
330 struct blorp_surf *surf,
331 enum isl_format format,
332 uint32_t start_layer, uint32_t num_layers);
333
334 void
335 blorp_mcs_ambiguate(struct blorp_batch *batch,
336 struct blorp_surf *surf,
337 uint32_t start_layer, uint32_t num_layers);
338
339 void
340 blorp_hiz_op(struct blorp_batch *batch, struct blorp_surf *surf,
341 uint32_t level, uint32_t start_layer, uint32_t num_layers,
342 enum isl_aux_op op);
343
344 #ifdef __cplusplus
345 } /* end extern "C" */
346 #endif /* __cplusplus */
347
348 #endif /* BLORP_H */
349