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