1 2 /************************************************************************** 3 * 4 * Copyright 2007 VMware, Inc. 5 * All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sub license, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice (including the 16 * next paragraph) shall be included in all copies or substantial portions 17 * of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 * 27 **************************************************************************/ 28 29 /** 30 * \brief Public interface into the drawing module. 31 */ 32 33 /* Authors: Keith Whitwell <[email protected]> 34 */ 35 36 37 #ifndef DRAW_CONTEXT_H 38 #define DRAW_CONTEXT_H 39 40 41 #include "pipe/p_state.h" 42 #include "pipe/p_shader_tokens.h" 43 #include "nir.h" 44 45 struct pipe_context; 46 struct draw_context; 47 struct draw_stage; 48 struct draw_vertex_shader; 49 struct draw_geometry_shader; 50 struct draw_tess_ctrl_shader; 51 struct draw_tess_eval_shader; 52 struct draw_mesh_shader; 53 struct draw_fragment_shader; 54 struct tgsi_sampler; 55 struct tgsi_image; 56 struct tgsi_buffer; 57 struct lp_cached_code; 58 59 60 /* 61 * structure to contain driver internal information 62 * for stream out support. mapping stores the pointer 63 * to the buffer contents, and internal offset stores 64 * an internal counter to how much of the stream 65 * out buffer is used (in bytes). 66 */ 67 struct draw_so_target { 68 struct pipe_stream_output_target target; 69 void *mapping; 70 int internal_offset; 71 }; 72 73 74 struct draw_vertex_info { 75 struct vertex_header *verts; 76 unsigned vertex_size; 77 unsigned stride; 78 unsigned count; 79 }; 80 81 struct draw_prim_info { 82 bool linear; 83 unsigned start; 84 85 const uint16_t *elts; 86 unsigned count; 87 88 enum mesa_prim prim; 89 unsigned flags; 90 unsigned *primitive_lengths; 91 unsigned primitive_count; 92 }; 93 94 struct draw_context *draw_create(struct pipe_context *pipe); 95 96 #if DRAW_LLVM_AVAILABLE 97 struct draw_context *draw_create_with_llvm_context(struct pipe_context *pipe, 98 void *context); 99 #endif 100 101 struct draw_context *draw_create_no_llvm(struct pipe_context *pipe); 102 103 void draw_destroy(struct draw_context *draw); 104 105 void draw_flush(struct draw_context *draw); 106 107 void draw_set_viewport_states(struct draw_context *draw, 108 unsigned start_slot, 109 unsigned num_viewports, 110 const struct pipe_viewport_state *viewports); 111 112 void draw_set_clip_state(struct draw_context *pipe, 113 const struct pipe_clip_state *clip); 114 115 /** 116 * Sets the rasterization state used by the draw module. 117 * The rast_handle is used to pass the driver specific representation 118 * of the rasterization state. It's going to be used when the 119 * draw module sets the state back on the driver itself using the 120 * pipe::bind_rasterizer_state method. 121 * 122 * NOTE: if you're calling this function from within the pipe's 123 * bind_rasterizer_state you should always call it before binding 124 * the actual state - that's because the draw module can try to 125 * bind its own rasterizer state which would reset your newly 126 * set state. i.e. always do 127 * draw_set_rasterizer_state(driver->draw, state->pipe_state, state); 128 * driver->state.raster = state; 129 */ 130 void draw_set_rasterizer_state(struct draw_context *draw, 131 const struct pipe_rasterizer_state *raster, 132 void *rast_handle); 133 134 void draw_set_rasterize_stage(struct draw_context *draw, 135 struct draw_stage *stage); 136 137 void draw_wide_point_threshold(struct draw_context *draw, float threshold); 138 139 void draw_wide_point_sprites(struct draw_context *draw, bool draw_sprite); 140 141 void draw_wide_line_threshold(struct draw_context *draw, float threshold); 142 143 void draw_enable_line_stipple(struct draw_context *draw, bool enable); 144 145 void draw_enable_point_sprites(struct draw_context *draw, bool enable); 146 147 void draw_set_zs_format(struct draw_context *draw, enum pipe_format format); 148 149 /* for TGSI constants are 4 * sizeof(float), but for NIR they need to be sizeof(float); */ 150 void draw_set_constant_buffer_stride(struct draw_context *draw, unsigned num_bytes); 151 152 bool 153 draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe); 154 155 bool 156 draw_install_aapoint_stage(struct draw_context *draw, struct pipe_context *pipe, 157 nir_alu_type bool_type); 158 159 bool 160 draw_install_pstipple_stage(struct draw_context *draw, struct pipe_context *pipe); 161 162 163 struct tgsi_shader_info * 164 draw_get_shader_info(const struct draw_context *draw); 165 166 void 167 draw_prepare_shader_outputs(struct draw_context *draw); 168 169 int 170 draw_find_shader_output(const struct draw_context *draw, 171 enum tgsi_semantic semantic_name, 172 unsigned semantic_index); 173 174 bool 175 draw_will_inject_frontface(const struct draw_context *draw); 176 177 unsigned 178 draw_num_shader_outputs(const struct draw_context *draw); 179 180 unsigned 181 draw_total_vs_outputs(const struct draw_context *draw); 182 183 unsigned 184 draw_total_gs_outputs(const struct draw_context *draw); 185 186 unsigned 187 draw_total_tcs_outputs(const struct draw_context *draw); 188 189 unsigned 190 draw_total_tes_outputs(const struct draw_context *draw); 191 192 void 193 draw_texture_sampler(struct draw_context *draw, 194 enum pipe_shader_type shader_type, 195 struct tgsi_sampler *sampler); 196 197 void 198 draw_image(struct draw_context *draw, 199 enum pipe_shader_type shader_type, 200 struct tgsi_image *image); 201 202 void 203 draw_buffer(struct draw_context *draw, 204 enum pipe_shader_type shader_type, 205 struct tgsi_buffer *buffer); 206 207 void 208 draw_set_sampler_views(struct draw_context *draw, 209 enum pipe_shader_type shader_stage, 210 struct pipe_sampler_view **views, 211 unsigned num); 212 void 213 draw_set_samplers(struct draw_context *draw, 214 enum pipe_shader_type shader_stage, 215 struct pipe_sampler_state **samplers, 216 unsigned num); 217 218 void 219 draw_set_images(struct draw_context *draw, 220 enum pipe_shader_type shader_stage, 221 struct pipe_image_view *images, 222 unsigned num); 223 224 void 225 draw_set_mapped_texture(struct draw_context *draw, 226 enum pipe_shader_type shader_stage, 227 unsigned sview_idx, 228 uint32_t width, uint32_t height, uint32_t depth, 229 uint32_t first_level, uint32_t last_level, 230 uint32_t num_samples, 231 uint32_t sample_stride, 232 const void *base, 233 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], 234 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], 235 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]); 236 237 void 238 draw_set_mapped_image(struct draw_context *draw, 239 enum pipe_shader_type shader_stage, 240 unsigned idx, 241 uint32_t width, uint32_t height, uint32_t depth, 242 const void *base_ptr, 243 uint32_t row_stride, 244 uint32_t img_stride, 245 uint32_t num_samples, 246 uint32_t sample_stride); 247 248 /* 249 * Vertex shader functions 250 */ 251 252 struct draw_vertex_shader * 253 draw_create_vertex_shader(struct draw_context *draw, 254 const struct pipe_shader_state *shader); 255 void draw_bind_vertex_shader(struct draw_context *draw, 256 struct draw_vertex_shader *dvs); 257 void draw_delete_vertex_shader(struct draw_context *draw, 258 struct draw_vertex_shader *dvs); 259 void draw_vs_attach_so(struct draw_vertex_shader *dvs, 260 const struct pipe_stream_output_info *info); 261 void draw_vs_reset_so(struct draw_vertex_shader *dvs); 262 263 264 /* 265 * Fragment shader functions 266 */ 267 struct draw_fragment_shader * 268 draw_create_fragment_shader(struct draw_context *draw, 269 const struct pipe_shader_state *shader); 270 void draw_bind_fragment_shader(struct draw_context *draw, 271 struct draw_fragment_shader *dvs); 272 void draw_delete_fragment_shader(struct draw_context *draw, 273 struct draw_fragment_shader *dvs); 274 275 /* 276 * Geometry shader functions 277 */ 278 struct draw_geometry_shader * 279 draw_create_geometry_shader(struct draw_context *draw, 280 const struct pipe_shader_state *shader); 281 void draw_bind_geometry_shader(struct draw_context *draw, 282 struct draw_geometry_shader *dvs); 283 void draw_delete_geometry_shader(struct draw_context *draw, 284 struct draw_geometry_shader *dvs); 285 286 /* 287 * Tess shader functions 288 */ 289 struct draw_tess_ctrl_shader * 290 draw_create_tess_ctrl_shader(struct draw_context *draw, 291 const struct pipe_shader_state *shader); 292 void draw_bind_tess_ctrl_shader(struct draw_context *draw, 293 struct draw_tess_ctrl_shader *dvs); 294 void draw_delete_tess_ctrl_shader(struct draw_context *draw, 295 struct draw_tess_ctrl_shader *dvs); 296 struct draw_tess_eval_shader * 297 draw_create_tess_eval_shader(struct draw_context *draw, 298 const struct pipe_shader_state *shader); 299 void draw_bind_tess_eval_shader(struct draw_context *draw, 300 struct draw_tess_eval_shader *dvs); 301 void draw_delete_tess_eval_shader(struct draw_context *draw, 302 struct draw_tess_eval_shader *dvs); 303 void draw_set_tess_state(struct draw_context *draw, 304 const float default_outer_level[4], 305 const float default_inner_level[2]); 306 307 /* 308 * Mesh shader functions 309 */ 310 struct draw_mesh_shader * 311 draw_create_mesh_shader(struct draw_context *draw, 312 const struct pipe_shader_state *shader); 313 void draw_bind_mesh_shader(struct draw_context *draw, 314 struct draw_mesh_shader *dvs); 315 void draw_delete_mesh_shader(struct draw_context *draw, 316 struct draw_mesh_shader *dvs); 317 318 /* 319 * Vertex data functions 320 */ 321 322 void draw_set_vertex_buffers(struct draw_context *draw, 323 unsigned count, 324 const struct pipe_vertex_buffer *buffers); 325 326 void draw_set_vertex_elements(struct draw_context *draw, 327 unsigned count, 328 const struct pipe_vertex_element *elements); 329 330 void draw_set_indexes(struct draw_context *draw, 331 const void *elements, unsigned elem_size, 332 unsigned available_space); 333 334 void draw_set_mapped_vertex_buffer(struct draw_context *draw, 335 unsigned attr, const void *buffer, 336 size_t size); 337 338 void 339 draw_set_mapped_constant_buffer(struct draw_context *draw, 340 enum pipe_shader_type shader_type, 341 unsigned slot, 342 const void *buffer, 343 unsigned size); 344 345 void 346 draw_set_mapped_shader_buffer(struct draw_context *draw, 347 enum pipe_shader_type shader_type, 348 unsigned slot, 349 const void *buffer, 350 unsigned size); 351 352 void 353 draw_set_mapped_so_targets(struct draw_context *draw, 354 unsigned num_targets, 355 struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS]); 356 357 358 /*********************************************************************** 359 * draw_pt.c 360 */ 361 362 void draw_vbo(struct draw_context *draw, 363 const struct pipe_draw_info *info, 364 unsigned drawid_offset, 365 const struct pipe_draw_indirect_info *indirect, 366 const struct pipe_draw_start_count_bias *draws, 367 unsigned num_draws, 368 uint8_t patch_vertices); 369 370 void 371 draw_mesh(struct draw_context *draw, 372 struct draw_vertex_info *vert_info, 373 struct draw_prim_info *prim_info); 374 375 376 /******************************************************************************* 377 * Driver backend interface 378 */ 379 struct vbuf_render; 380 void 381 draw_set_render(struct draw_context *draw, 382 struct vbuf_render *render); 383 384 void 385 draw_set_driver_clipping(struct draw_context *draw, 386 bool bypass_clip_xy, 387 bool bypass_clip_z, 388 bool guard_band_xy, 389 bool bypass_clip_points_lines); 390 391 /******************************************************************************* 392 * Draw statistics 393 */ 394 void 395 draw_collect_pipeline_statistics(struct draw_context *draw, 396 bool enable); 397 398 void 399 draw_collect_primitives_generated(struct draw_context *draw, 400 bool eanble); 401 402 /******************************************************************************* 403 * Draw pipeline 404 */ 405 bool 406 draw_need_pipeline(const struct draw_context *draw, 407 const struct pipe_rasterizer_state *rasterizer, 408 enum mesa_prim prim); 409 410 int 411 draw_get_shader_param(enum pipe_shader_type shader, enum pipe_shader_cap param); 412 413 int 414 draw_get_shader_param_no_llvm(enum pipe_shader_type shader, 415 enum pipe_shader_cap param); 416 417 bool 418 draw_get_option_use_llvm(void); 419 420 421 void 422 draw_set_disk_cache_callbacks(struct draw_context *draw, 423 void *data_cookie, 424 void (*find_shader)(void *cookie, 425 struct lp_cached_code *cache, 426 unsigned char ir_sha1_cache_key[20]), 427 void (*insert_shader)(void *cookie, 428 struct lp_cached_code *cache, 429 unsigned char ir_sha1_cache_key[20])); 430 431 432 #endif /* DRAW_CONTEXT_H */ 433