1 /************************************************************************** 2 * 3 * Copyright 2007 VMware, Inc. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 #ifndef PIPE_CONTEXT_H 29 #define PIPE_CONTEXT_H 30 31 #include "p_compiler.h" 32 #include "p_format.h" 33 #include "p_video_enums.h" 34 #include "p_defines.h" 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 41 struct pipe_blend_color; 42 struct pipe_blend_state; 43 struct pipe_blit_info; 44 struct pipe_box; 45 struct pipe_clip_state; 46 struct pipe_constant_buffer; 47 struct pipe_depth_stencil_alpha_state; 48 struct pipe_draw_info; 49 struct pipe_fence_handle; 50 struct pipe_framebuffer_state; 51 struct pipe_index_buffer; 52 struct pipe_query; 53 struct pipe_poly_stipple; 54 struct pipe_rasterizer_state; 55 struct pipe_resolve_info; 56 struct pipe_resource; 57 struct pipe_sampler_state; 58 struct pipe_sampler_view; 59 struct pipe_scissor_state; 60 struct pipe_shader_state; 61 struct pipe_stencil_ref; 62 struct pipe_stream_output_target; 63 struct pipe_surface; 64 struct pipe_transfer; 65 struct pipe_vertex_buffer; 66 struct pipe_vertex_element; 67 struct pipe_video_buffer; 68 struct pipe_video_codec; 69 struct pipe_viewport_state; 70 struct pipe_compute_state; 71 union pipe_color_union; 72 union pipe_query_result; 73 74 /** 75 * Gallium rendering context. Basically: 76 * - state setting functions 77 * - VBO drawing functions 78 * - surface functions 79 */ 80 struct pipe_context { 81 struct pipe_screen *screen; 82 83 void *priv; /**< context private data (for DRI for example) */ 84 void *draw; /**< private, for draw module (temporary?) */ 85 86 void (*destroy)( struct pipe_context * ); 87 88 /** 89 * VBO drawing 90 */ 91 /*@{*/ 92 void (*draw_vbo)( struct pipe_context *pipe, 93 const struct pipe_draw_info *info ); 94 /*@}*/ 95 96 /** 97 * Predicate subsequent rendering on occlusion query result 98 * \param query the query predicate, or NULL if no predicate 99 * \param condition whether to skip on FALSE or TRUE query results 100 * \param mode one of PIPE_RENDER_COND_x 101 */ 102 void (*render_condition)( struct pipe_context *pipe, 103 struct pipe_query *query, 104 boolean condition, 105 uint mode ); 106 107 /** 108 * Query objects 109 */ 110 /*@{*/ 111 struct pipe_query *(*create_query)( struct pipe_context *pipe, 112 unsigned query_type ); 113 114 void (*destroy_query)(struct pipe_context *pipe, 115 struct pipe_query *q); 116 117 void (*begin_query)(struct pipe_context *pipe, struct pipe_query *q); 118 void (*end_query)(struct pipe_context *pipe, struct pipe_query *q); 119 120 /** 121 * Get results of a query. 122 * \param wait if true, this query will block until the result is ready 123 * \return TRUE if results are ready, FALSE otherwise 124 */ 125 boolean (*get_query_result)(struct pipe_context *pipe, 126 struct pipe_query *q, 127 boolean wait, 128 union pipe_query_result *result); 129 /*@}*/ 130 131 /** 132 * State functions (create/bind/destroy state objects) 133 */ 134 /*@{*/ 135 void * (*create_blend_state)(struct pipe_context *, 136 const struct pipe_blend_state *); 137 void (*bind_blend_state)(struct pipe_context *, void *); 138 void (*delete_blend_state)(struct pipe_context *, void *); 139 140 void * (*create_sampler_state)(struct pipe_context *, 141 const struct pipe_sampler_state *); 142 void (*bind_sampler_states)(struct pipe_context *, 143 unsigned shader, unsigned start_slot, 144 unsigned num_samplers, void **samplers); 145 void (*delete_sampler_state)(struct pipe_context *, void *); 146 147 void * (*create_rasterizer_state)(struct pipe_context *, 148 const struct pipe_rasterizer_state *); 149 void (*bind_rasterizer_state)(struct pipe_context *, void *); 150 void (*delete_rasterizer_state)(struct pipe_context *, void *); 151 152 void * (*create_depth_stencil_alpha_state)(struct pipe_context *, 153 const struct pipe_depth_stencil_alpha_state *); 154 void (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *); 155 void (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *); 156 157 void * (*create_fs_state)(struct pipe_context *, 158 const struct pipe_shader_state *); 159 void (*bind_fs_state)(struct pipe_context *, void *); 160 void (*delete_fs_state)(struct pipe_context *, void *); 161 162 void * (*create_vs_state)(struct pipe_context *, 163 const struct pipe_shader_state *); 164 void (*bind_vs_state)(struct pipe_context *, void *); 165 void (*delete_vs_state)(struct pipe_context *, void *); 166 167 void * (*create_gs_state)(struct pipe_context *, 168 const struct pipe_shader_state *); 169 void (*bind_gs_state)(struct pipe_context *, void *); 170 void (*delete_gs_state)(struct pipe_context *, void *); 171 172 void * (*create_vertex_elements_state)(struct pipe_context *, 173 unsigned num_elements, 174 const struct pipe_vertex_element *); 175 void (*bind_vertex_elements_state)(struct pipe_context *, void *); 176 void (*delete_vertex_elements_state)(struct pipe_context *, void *); 177 178 /*@}*/ 179 180 /** 181 * Parameter-like state (or properties) 182 */ 183 /*@{*/ 184 void (*set_blend_color)( struct pipe_context *, 185 const struct pipe_blend_color * ); 186 187 void (*set_stencil_ref)( struct pipe_context *, 188 const struct pipe_stencil_ref * ); 189 190 void (*set_sample_mask)( struct pipe_context *, 191 unsigned sample_mask ); 192 193 void (*set_clip_state)( struct pipe_context *, 194 const struct pipe_clip_state * ); 195 196 void (*set_constant_buffer)( struct pipe_context *, 197 uint shader, uint index, 198 struct pipe_constant_buffer *buf ); 199 200 void (*set_framebuffer_state)( struct pipe_context *, 201 const struct pipe_framebuffer_state * ); 202 203 void (*set_polygon_stipple)( struct pipe_context *, 204 const struct pipe_poly_stipple * ); 205 206 void (*set_scissor_states)( struct pipe_context *, 207 unsigned start_slot, 208 unsigned num_scissors, 209 const struct pipe_scissor_state * ); 210 211 void (*set_viewport_states)( struct pipe_context *, 212 unsigned start_slot, 213 unsigned num_viewports, 214 const struct pipe_viewport_state *); 215 216 void (*set_sampler_views)(struct pipe_context *, unsigned shader, 217 unsigned start_slot, unsigned num_views, 218 struct pipe_sampler_view **); 219 220 /** 221 * Bind an array of shader resources that will be used by the 222 * graphics pipeline. Any resources that were previously bound to 223 * the specified range will be unbound after this call. 224 * 225 * \param start first resource to bind. 226 * \param count number of consecutive resources to bind. 227 * \param resources array of pointers to the resources to bind, it 228 * should contain at least \a count elements 229 * unless it's NULL, in which case no new 230 * resources will be bound. 231 */ 232 void (*set_shader_resources)(struct pipe_context *, 233 unsigned start, unsigned count, 234 struct pipe_surface **resources); 235 236 void (*set_vertex_buffers)( struct pipe_context *, 237 unsigned start_slot, 238 unsigned num_buffers, 239 const struct pipe_vertex_buffer * ); 240 241 void (*set_index_buffer)( struct pipe_context *pipe, 242 const struct pipe_index_buffer * ); 243 244 /*@}*/ 245 246 /** 247 * Stream output functions. 248 */ 249 /*@{*/ 250 251 struct pipe_stream_output_target *(*create_stream_output_target)( 252 struct pipe_context *, 253 struct pipe_resource *, 254 unsigned buffer_offset, 255 unsigned buffer_size); 256 257 void (*stream_output_target_destroy)(struct pipe_context *, 258 struct pipe_stream_output_target *); 259 260 void (*set_stream_output_targets)(struct pipe_context *, 261 unsigned num_targets, 262 struct pipe_stream_output_target **targets, 263 unsigned append_bitmask); 264 265 /*@}*/ 266 267 268 /** 269 * Resource functions for blit-like functionality 270 * 271 * If a driver supports multisampling, blit must implement color resolve. 272 */ 273 /*@{*/ 274 275 /** 276 * Copy a block of pixels from one resource to another. 277 * The resource must be of the same format. 278 * Resources with nr_samples > 1 are not allowed. 279 */ 280 void (*resource_copy_region)(struct pipe_context *pipe, 281 struct pipe_resource *dst, 282 unsigned dst_level, 283 unsigned dstx, unsigned dsty, unsigned dstz, 284 struct pipe_resource *src, 285 unsigned src_level, 286 const struct pipe_box *src_box); 287 288 /* Optimal hardware path for blitting pixels. 289 * Scaling, format conversion, up- and downsampling (resolve) are allowed. 290 */ 291 void (*blit)(struct pipe_context *pipe, 292 const struct pipe_blit_info *info); 293 294 /*@}*/ 295 296 /** 297 * Clear the specified set of currently bound buffers to specified values. 298 * The entire buffers are cleared (no scissor, no colormask, etc). 299 * 300 * \param buffers bitfield of PIPE_CLEAR_* values. 301 * \param color pointer to a union of fiu array for each of r, g, b, a. 302 * \param depth depth clear value in [0,1]. 303 * \param stencil stencil clear value 304 */ 305 void (*clear)(struct pipe_context *pipe, 306 unsigned buffers, 307 const union pipe_color_union *color, 308 double depth, 309 unsigned stencil); 310 311 /** 312 * Clear a color rendertarget surface. 313 * \param color pointer to an union of fiu array for each of r, g, b, a. 314 */ 315 void (*clear_render_target)(struct pipe_context *pipe, 316 struct pipe_surface *dst, 317 const union pipe_color_union *color, 318 unsigned dstx, unsigned dsty, 319 unsigned width, unsigned height); 320 321 /** 322 * Clear a depth-stencil surface. 323 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values. 324 * \param depth depth clear value in [0,1]. 325 * \param stencil stencil clear value 326 */ 327 void (*clear_depth_stencil)(struct pipe_context *pipe, 328 struct pipe_surface *dst, 329 unsigned clear_flags, 330 double depth, 331 unsigned stencil, 332 unsigned dstx, unsigned dsty, 333 unsigned width, unsigned height); 334 335 /** Flush draw commands 336 * 337 * \param flags bitfield of enum pipe_flush_flags values. 338 */ 339 void (*flush)(struct pipe_context *pipe, 340 struct pipe_fence_handle **fence, 341 unsigned flags); 342 343 /** 344 * Create a view on a texture to be used by a shader stage. 345 */ 346 struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx, 347 struct pipe_resource *texture, 348 const struct pipe_sampler_view *templat); 349 350 void (*sampler_view_destroy)(struct pipe_context *ctx, 351 struct pipe_sampler_view *view); 352 353 354 /** 355 * Get a surface which is a "view" into a resource, used by 356 * render target / depth stencil stages. 357 */ 358 struct pipe_surface *(*create_surface)(struct pipe_context *ctx, 359 struct pipe_resource *resource, 360 const struct pipe_surface *templat); 361 362 void (*surface_destroy)(struct pipe_context *ctx, 363 struct pipe_surface *); 364 365 /** 366 * Map a resource. 367 * 368 * Transfers are (by default) context-private and allow uploads to be 369 * interleaved with rendering. 370 * 371 * out_transfer will contain the transfer object that must be passed 372 * to all the other transfer functions. It also contains useful 373 * information (like texture strides). 374 */ 375 void *(*transfer_map)(struct pipe_context *, 376 struct pipe_resource *resource, 377 unsigned level, 378 unsigned usage, /* a combination of PIPE_TRANSFER_x */ 379 const struct pipe_box *, 380 struct pipe_transfer **out_transfer); 381 382 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the 383 * regions specified with this call are guaranteed to be written to 384 * the resource. 385 */ 386 void (*transfer_flush_region)( struct pipe_context *, 387 struct pipe_transfer *transfer, 388 const struct pipe_box *); 389 390 void (*transfer_unmap)(struct pipe_context *, 391 struct pipe_transfer *transfer); 392 393 /* One-shot transfer operation with data supplied in a user 394 * pointer. XXX: strides?? 395 */ 396 void (*transfer_inline_write)( struct pipe_context *, 397 struct pipe_resource *, 398 unsigned level, 399 unsigned usage, /* a combination of PIPE_TRANSFER_x */ 400 const struct pipe_box *, 401 const void *data, 402 unsigned stride, 403 unsigned layer_stride); 404 405 /** 406 * Flush any pending framebuffer writes and invalidate texture caches. 407 */ 408 void (*texture_barrier)(struct pipe_context *); 409 410 /** 411 * Flush caches according to flags. 412 */ 413 void (*memory_barrier)(struct pipe_context *, unsigned flags); 414 415 /** 416 * Creates a video codec for a specific video format/profile 417 */ 418 struct pipe_video_codec *(*create_video_codec)( struct pipe_context *context, 419 const struct pipe_video_codec *templat ); 420 421 /** 422 * Creates a video buffer as decoding target 423 */ 424 struct pipe_video_buffer *(*create_video_buffer)( struct pipe_context *context, 425 const struct pipe_video_buffer *templat ); 426 427 /** 428 * Compute kernel execution 429 */ 430 /*@{*/ 431 /** 432 * Define the compute program and parameters to be used by 433 * pipe_context::launch_grid. 434 */ 435 void *(*create_compute_state)(struct pipe_context *context, 436 const struct pipe_compute_state *); 437 void (*bind_compute_state)(struct pipe_context *, void *); 438 void (*delete_compute_state)(struct pipe_context *, void *); 439 440 /** 441 * Bind an array of shader resources that will be used by the 442 * compute program. Any resources that were previously bound to 443 * the specified range will be unbound after this call. 444 * 445 * \param start first resource to bind. 446 * \param count number of consecutive resources to bind. 447 * \param resources array of pointers to the resources to bind, it 448 * should contain at least \a count elements 449 * unless it's NULL, in which case no new 450 * resources will be bound. 451 */ 452 void (*set_compute_resources)(struct pipe_context *, 453 unsigned start, unsigned count, 454 struct pipe_surface **resources); 455 456 /** 457 * Bind an array of buffers to be mapped into the address space of 458 * the GLOBAL resource. Any buffers that were previously bound 459 * between [first, first + count - 1] are unbound after this call. 460 * 461 * \param first first buffer to map. 462 * \param count number of consecutive buffers to map. 463 * \param resources array of pointers to the buffers to map, it 464 * should contain at least \a count elements 465 * unless it's NULL, in which case no new 466 * resources will be bound. 467 * \param handles array of pointers to the memory locations that 468 * will be updated with the address each buffer 469 * will be mapped to. The base memory address of 470 * each of the buffers will be added to the value 471 * pointed to by its corresponding handle to form 472 * the final address argument. It should contain 473 * at least \a count elements, unless \a 474 * resources is NULL in which case \a handles 475 * should be NULL as well. 476 * 477 * Note that the driver isn't required to make any guarantees about 478 * the contents of the \a handles array being valid anytime except 479 * during the subsequent calls to pipe_context::launch_grid. This 480 * means that the only sensible location handles[i] may point to is 481 * somewhere within the INPUT buffer itself. This is so to 482 * accommodate implementations that lack virtual memory but 483 * nevertheless migrate buffers on the fly, leading to resource 484 * base addresses that change on each kernel invocation or are 485 * unknown to the pipe driver. 486 */ 487 void (*set_global_binding)(struct pipe_context *context, 488 unsigned first, unsigned count, 489 struct pipe_resource **resources, 490 uint32_t **handles); 491 492 /** 493 * Launch the compute kernel starting from instruction \a pc of the 494 * currently bound compute program. 495 * 496 * \a grid_layout and \a block_layout are arrays of size \a 497 * PIPE_COMPUTE_CAP_GRID_DIMENSION that determine the layout of the 498 * grid (in block units) and working block (in thread units) to be 499 * used, respectively. 500 * 501 * \a pc For drivers that use PIPE_SHADER_IR_LLVM as their prefered IR, 502 * this value will be the index of the kernel in the opencl.kernels 503 * metadata list. 504 * 505 * \a input will be used to initialize the INPUT resource, and it 506 * should point to a buffer of at least 507 * pipe_compute_state::req_input_mem bytes. 508 */ 509 void (*launch_grid)(struct pipe_context *context, 510 const uint *block_layout, const uint *grid_layout, 511 uint32_t pc, const void *input); 512 /*@}*/ 513 514 /** 515 * Get sample position for an individual sample point. 516 * 517 * \param sample_count - total number of samples 518 * \param sample_index - sample to get the position values for 519 * \param out_value - return value of 2 floats for x and y position for 520 * requested sample. 521 */ 522 void (*get_sample_position)(struct pipe_context *context, 523 unsigned sample_count, 524 unsigned sample_index, 525 float *out_value); 526 527 /** 528 * Flush the resource cache, so that the resource can be used 529 * by an external client. Possible usage: 530 * - flushing a resource before presenting it on the screen 531 * - flushing a resource if some other process or device wants to use it 532 * This shouldn't be used to flush caches if the resource is only managed 533 * by a single pipe_screen and is not shared with another process. 534 * (i.e. you shouldn't use it to flush caches explicitly if you want to e.g. 535 * use the resource for texturing) 536 */ 537 void (*flush_resource)(struct pipe_context *ctx, 538 struct pipe_resource *resource); 539 }; 540 541 542 #ifdef __cplusplus 543 } 544 #endif 545 546 #endif /* PIPE_CONTEXT_H */ 547