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