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
32struct brw_stage_prog_data;
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38struct blorp_batch;
39struct blorp_params;
40
41struct blorp_context {
42   void *driver_ctx;
43
44   const struct isl_device *isl_dev;
45
46   const struct brw_compiler *compiler;
47
48   bool (*lookup_shader)(struct blorp_batch *batch,
49                         const void *key, uint32_t key_size,
50                         uint32_t *kernel_out, void *prog_data_out);
51   bool (*upload_shader)(struct blorp_batch *batch,
52                         uint32_t stage,
53                         const void *key, uint32_t key_size,
54                         const void *kernel, uint32_t kernel_size,
55                         const struct brw_stage_prog_data *prog_data,
56                         uint32_t prog_data_size,
57                         uint32_t *kernel_out, void *prog_data_out);
58   void (*exec)(struct blorp_batch *batch, const struct blorp_params *params);
59};
60
61void blorp_init(struct blorp_context *blorp, void *driver_ctx,
62                struct isl_device *isl_dev);
63void blorp_finish(struct blorp_context *blorp);
64
65enum blorp_batch_flags {
66   /**
67    * This flag indicates that blorp should *not* re-emit the depth and
68    * stencil buffer packets.  Instead, the driver guarantees that all depth
69    * and stencil images passed in will match what is currently set in the
70    * hardware.
71    */
72   BLORP_BATCH_NO_EMIT_DEPTH_STENCIL = (1 << 0),
73
74   /* This flag indicates that the blorp call should be predicated. */
75   BLORP_BATCH_PREDICATE_ENABLE      = (1 << 1),
76
77   /* This flag indicates that blorp should *not* update the indirect clear
78    * color buffer.
79    */
80   BLORP_BATCH_NO_UPDATE_CLEAR_COLOR = (1 << 2),
81
82   /* This flag indicates that blorp should use a compute program for the
83    * operation.
84    */
85   BLORP_BATCH_USE_COMPUTE = (1 << 3),
86};
87
88struct blorp_batch {
89   struct blorp_context *blorp;
90   void *driver_batch;
91   enum blorp_batch_flags flags;
92};
93
94void blorp_batch_init(struct blorp_context *blorp, struct blorp_batch *batch,
95                      void *driver_batch, enum blorp_batch_flags flags);
96void blorp_batch_finish(struct blorp_batch *batch);
97
98struct blorp_address {
99   void *buffer;
100   uint64_t offset;
101   unsigned reloc_flags;
102   uint32_t mocs;
103};
104
105struct blorp_surf
106{
107   const struct isl_surf *surf;
108   struct blorp_address addr;
109
110   const struct isl_surf *aux_surf;
111   struct blorp_address aux_addr;
112   enum isl_aux_usage aux_usage;
113
114   union isl_color_value clear_color;
115
116   /**
117    * If set (bo != NULL), clear_color is ignored and the actual clear color
118    * is fetched from this address.  On gfx7-8, this is all of dword 7 of
119    * RENDER_SURFACE_STATE and is the responsibility of the caller to ensure
120    * that it contains a swizzle of RGBA and resource min LOD of 0.
121    */
122   struct blorp_address clear_color_addr;
123
124   /* Only allowed for simple 2D non-MSAA surfaces */
125   uint32_t tile_x_sa, tile_y_sa;
126};
127
128enum blorp_filter {
129   BLORP_FILTER_NONE,
130   BLORP_FILTER_NEAREST,
131   BLORP_FILTER_BILINEAR,
132   BLORP_FILTER_SAMPLE_0,
133   BLORP_FILTER_AVERAGE,
134   BLORP_FILTER_MIN_SAMPLE,
135   BLORP_FILTER_MAX_SAMPLE,
136};
137
138void
139blorp_blit(struct blorp_batch *batch,
140           const struct blorp_surf *src_surf,
141           unsigned src_level, float src_layer,
142           enum isl_format src_format, struct isl_swizzle src_swizzle,
143           const struct blorp_surf *dst_surf,
144           unsigned dst_level, unsigned dst_layer,
145           enum isl_format dst_format, struct isl_swizzle dst_swizzle,
146           float src_x0, float src_y0,
147           float src_x1, float src_y1,
148           float dst_x0, float dst_y0,
149           float dst_x1, float dst_y1,
150           enum blorp_filter filter,
151           bool mirror_x, bool mirror_y);
152
153void
154blorp_copy(struct blorp_batch *batch,
155           const struct blorp_surf *src_surf,
156           unsigned src_level, unsigned src_layer,
157           const struct blorp_surf *dst_surf,
158           unsigned dst_level, unsigned dst_layer,
159           uint32_t src_x, uint32_t src_y,
160           uint32_t dst_x, uint32_t dst_y,
161           uint32_t src_width, uint32_t src_height);
162
163void
164blorp_buffer_copy(struct blorp_batch *batch,
165                  struct blorp_address src,
166                  struct blorp_address dst,
167                  uint64_t size);
168
169void
170blorp_fast_clear(struct blorp_batch *batch,
171                 const struct blorp_surf *surf,
172                 enum isl_format format, struct isl_swizzle swizzle,
173                 uint32_t level, uint32_t start_layer, uint32_t num_layers,
174                 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1);
175
176bool
177blorp_clear_supports_compute(struct blorp_context *blorp,
178                             uint8_t color_write_disable, bool blend_enabled,
179                             enum isl_aux_usage aux_usage);
180
181bool
182blorp_copy_supports_compute(struct blorp_context *blorp,
183                            enum isl_aux_usage dst_aux_usage);
184
185bool
186blorp_blit_supports_compute(struct blorp_context *blorp,
187                            enum isl_aux_usage dst_aux_usage);
188
189void
190blorp_clear(struct blorp_batch *batch,
191            const struct blorp_surf *surf,
192            enum isl_format format, struct isl_swizzle swizzle,
193            uint32_t level, uint32_t start_layer, uint32_t num_layers,
194            uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
195            union isl_color_value clear_color,
196            uint8_t color_write_disable);
197
198void
199blorp_clear_depth_stencil(struct blorp_batch *batch,
200                          const struct blorp_surf *depth,
201                          const struct blorp_surf *stencil,
202                          uint32_t level, uint32_t start_layer,
203                          uint32_t num_layers,
204                          uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
205                          bool clear_depth, float depth_value,
206                          uint8_t stencil_mask, uint8_t stencil_value);
207bool
208blorp_can_hiz_clear_depth(const struct intel_device_info *devinfo,
209                          const struct isl_surf *surf,
210                          enum isl_aux_usage aux_usage,
211                          uint32_t level, uint32_t layer,
212                          uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1);
213void
214blorp_hiz_clear_depth_stencil(struct blorp_batch *batch,
215                              const struct blorp_surf *depth,
216                              const struct blorp_surf *stencil,
217                              uint32_t level,
218                              uint32_t start_layer, uint32_t num_layers,
219                              uint32_t x0, uint32_t y0,
220                              uint32_t x1, uint32_t y1,
221                              bool clear_depth, float depth_value,
222                              bool clear_stencil, uint8_t stencil_value);
223
224
225void
226blorp_gfx8_hiz_clear_attachments(struct blorp_batch *batch,
227                                 uint32_t num_samples,
228                                 uint32_t x0, uint32_t y0,
229                                 uint32_t x1, uint32_t y1,
230                                 bool clear_depth, bool clear_stencil,
231                                 uint8_t stencil_value);
232void
233blorp_clear_attachments(struct blorp_batch *batch,
234                        uint32_t binding_table_offset,
235                        enum isl_format depth_format,
236                        uint32_t num_samples,
237                        uint32_t start_layer, uint32_t num_layers,
238                        uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
239                        bool clear_color, union isl_color_value color_value,
240                        bool clear_depth, float depth_value,
241                        uint8_t stencil_mask, uint8_t stencil_value);
242
243void
244blorp_ccs_resolve(struct blorp_batch *batch,
245                  struct blorp_surf *surf, uint32_t level,
246                  uint32_t start_layer, uint32_t num_layers,
247                  enum isl_format format,
248                  enum isl_aux_op resolve_op);
249
250void
251blorp_ccs_ambiguate(struct blorp_batch *batch,
252                    struct blorp_surf *surf,
253                    uint32_t level, uint32_t layer);
254
255void
256blorp_mcs_partial_resolve(struct blorp_batch *batch,
257                          struct blorp_surf *surf,
258                          enum isl_format format,
259                          uint32_t start_layer, uint32_t num_layers);
260
261void
262blorp_hiz_op(struct blorp_batch *batch, struct blorp_surf *surf,
263             uint32_t level, uint32_t start_layer, uint32_t num_layers,
264             enum isl_aux_op op);
265
266#ifdef __cplusplus
267} /* end extern "C" */
268#endif /* __cplusplus */
269
270#endif /* BLORP_H */
271