• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 enum isl_format
236 blorp_copy_get_color_format(const struct isl_device *isl_dev,
237                             enum isl_format surf_format);
238 void
239 blorp_copy_get_formats(const struct isl_device *isl_dev,
240                        const struct isl_surf *src_surf,
241                        const struct isl_surf *dst_surf,
242                        enum isl_format *src_view_format,
243                        enum isl_format *dst_view_format);
244 
245 void
246 blorp_copy(struct blorp_batch *batch,
247            const struct blorp_surf *src_surf,
248            unsigned src_level, unsigned src_layer,
249            const struct blorp_surf *dst_surf,
250            unsigned dst_level, unsigned dst_layer,
251            uint32_t src_x, uint32_t src_y,
252            uint32_t dst_x, uint32_t dst_y,
253            uint32_t src_width, uint32_t src_height);
254 
255 void
256 blorp_buffer_copy(struct blorp_batch *batch,
257                   struct blorp_address src,
258                   struct blorp_address dst,
259                   uint64_t size);
260 
261 void
262 blorp_fast_clear(struct blorp_batch *batch,
263                  const struct blorp_surf *surf,
264                  enum isl_format format, struct isl_swizzle swizzle,
265                  uint32_t level, uint32_t start_layer, uint32_t num_layers,
266                  uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1);
267 
268 bool
269 blorp_clear_supports_compute(struct blorp_context *blorp,
270                              uint8_t color_write_disable, bool blend_enabled,
271                              enum isl_aux_usage aux_usage);
272 
273 bool
274 blorp_clear_supports_blitter(struct blorp_context *blorp,
275                              const struct blorp_surf *surf,
276                              uint8_t color_write_disable, bool blend_enabled);
277 
278 bool
279 blorp_copy_supports_compute(struct blorp_context *blorp,
280                             const struct isl_surf *src_surf,
281                             const struct isl_surf *dst_surf,
282                             enum isl_aux_usage dst_aux_usage);
283 
284 bool
285 blorp_blit_supports_compute(struct blorp_context *blorp,
286                             const struct isl_surf *src_surf,
287                             const struct isl_surf *dst_surf,
288                             enum isl_aux_usage dst_aux_usage);
289 
290 bool
291 blorp_copy_supports_blitter(struct blorp_context *blorp,
292                             const struct isl_surf *src_surf,
293                             const struct isl_surf *dst_surf,
294                             enum isl_aux_usage src_aux_usage,
295                             enum isl_aux_usage dst_aux_usage);
296 
297 void
298 blorp_clear(struct blorp_batch *batch,
299             const struct blorp_surf *surf,
300             enum isl_format format, struct isl_swizzle swizzle,
301             uint32_t level, uint32_t start_layer, uint32_t num_layers,
302             uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
303             union isl_color_value clear_color,
304             uint8_t color_write_disable);
305 
306 void
307 blorp_clear_depth_stencil(struct blorp_batch *batch,
308                           const struct blorp_surf *depth,
309                           const struct blorp_surf *stencil,
310                           uint32_t level, uint32_t start_layer,
311                           uint32_t num_layers,
312                           uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
313                           bool clear_depth, float depth_value,
314                           uint8_t stencil_mask, uint8_t stencil_value);
315 
316 void
317 blorp_hiz_clear_depth_stencil(struct blorp_batch *batch,
318                               const struct blorp_surf *depth,
319                               const struct blorp_surf *stencil,
320                               uint32_t level,
321                               uint32_t start_layer, uint32_t num_layers,
322                               uint32_t x0, uint32_t y0,
323                               uint32_t x1, uint32_t y1,
324                               bool clear_depth, float depth_value,
325                               bool clear_stencil, uint8_t stencil_value);
326 
327 
328 void
329 blorp_gfx8_hiz_clear_attachments(struct blorp_batch *batch,
330                                  uint32_t num_samples,
331                                  uint32_t x0, uint32_t y0,
332                                  uint32_t x1, uint32_t y1,
333                                  bool clear_depth, bool clear_stencil,
334                                  uint8_t stencil_value);
335 void
336 blorp_clear_attachments(struct blorp_batch *batch,
337                         uint32_t binding_table_offset,
338                         enum isl_format depth_format,
339                         uint32_t num_samples,
340                         uint32_t start_layer, uint32_t num_layers,
341                         uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
342                         bool clear_color, union isl_color_value color_value,
343                         bool clear_depth, float depth_value,
344                         uint8_t stencil_mask, uint8_t stencil_value);
345 
346 void
347 blorp_ccs_resolve(struct blorp_batch *batch,
348                   struct blorp_surf *surf, uint32_t level,
349                   uint32_t start_layer, uint32_t num_layers,
350                   enum isl_format format,
351                   enum isl_aux_op resolve_op);
352 
353 void
354 blorp_ccs_ambiguate(struct blorp_batch *batch,
355                     struct blorp_surf *surf,
356                     uint32_t level, uint32_t layer);
357 
358 void
359 blorp_mcs_partial_resolve(struct blorp_batch *batch,
360                           struct blorp_surf *surf,
361                           enum isl_format format,
362                           uint32_t start_layer, uint32_t num_layers);
363 
364 void
365 blorp_mcs_ambiguate(struct blorp_batch *batch,
366                     struct blorp_surf *surf,
367                     uint32_t start_layer, uint32_t num_layers);
368 
369 void
370 blorp_hiz_op(struct blorp_batch *batch, struct blorp_surf *surf,
371              uint32_t level, uint32_t start_layer, uint32_t num_layers,
372              enum isl_aux_op op);
373 
374 #ifdef __cplusplus
375 } /* end extern "C" */
376 #endif /* __cplusplus */
377 
378 #endif /* BLORP_H */
379