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