1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef PIPE_CONTEXT_H
29 #define PIPE_CONTEXT_H
31 #include "p_compiler.h"
33 #include "p_video_enums.h"
34 #include "p_defines.h"
42 struct pipe_blend_color
;
43 struct pipe_blend_state
;
44 struct pipe_blit_info
;
46 struct pipe_clip_state
;
47 struct pipe_constant_buffer
;
48 struct pipe_debug_callback
;
49 struct pipe_depth_stencil_alpha_state
;
50 struct pipe_draw_info
;
51 struct pipe_fence_handle
;
52 struct pipe_framebuffer_state
;
53 struct pipe_image_view
;
54 struct pipe_index_buffer
;
56 struct pipe_poly_stipple
;
57 struct pipe_rasterizer_state
;
58 struct pipe_resolve_info
;
60 struct pipe_sampler_state
;
61 struct pipe_sampler_view
;
62 struct pipe_scissor_state
;
63 struct pipe_shader_buffer
;
64 struct pipe_shader_state
;
65 struct pipe_stencil_ref
;
66 struct pipe_stream_output_target
;
69 struct pipe_vertex_buffer
;
70 struct pipe_vertex_element
;
71 struct pipe_video_buffer
;
72 struct pipe_video_codec
;
73 struct pipe_viewport_state
;
74 struct pipe_compute_state
;
75 union pipe_color_union
;
76 union pipe_query_result
;
79 * Gallium rendering context. Basically:
80 * - state setting functions
81 * - VBO drawing functions
85 struct pipe_screen
*screen
;
87 void *priv
; /**< context private data (for DRI for example) */
88 void *draw
; /**< private, for draw module (temporary?) */
90 void (*destroy
)( struct pipe_context
* );
96 void (*draw_vbo
)( struct pipe_context
*pipe
,
97 const struct pipe_draw_info
*info
);
101 * Predicate subsequent rendering on occlusion query result
102 * \param query the query predicate, or NULL if no predicate
103 * \param condition whether to skip on FALSE or TRUE query results
104 * \param mode one of PIPE_RENDER_COND_x
106 void (*render_condition
)( struct pipe_context
*pipe
,
107 struct pipe_query
*query
,
115 struct pipe_query
*(*create_query
)( struct pipe_context
*pipe
,
120 * Create a query object that queries all given query types simultaneously.
122 * This can only be used for those query types for which
123 * get_driver_query_info indicates that it must be used. Only one batch
124 * query object may be active at a time.
126 * There may be additional constraints on which query types can be used
127 * together, in particular those that are implied by
128 * get_driver_query_group_info.
130 * \param num_queries the number of query types
131 * \param query_types array of \p num_queries query types
132 * \return a query object, or NULL on error.
134 struct pipe_query
*(*create_batch_query
)( struct pipe_context
*pipe
,
135 unsigned num_queries
,
136 unsigned *query_types
);
138 void (*destroy_query
)(struct pipe_context
*pipe
,
139 struct pipe_query
*q
);
141 boolean (*begin_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
142 void (*end_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
145 * Get results of a query.
146 * \param wait if true, this query will block until the result is ready
147 * \return TRUE if results are ready, FALSE otherwise
149 boolean (*get_query_result
)(struct pipe_context
*pipe
,
150 struct pipe_query
*q
,
152 union pipe_query_result
*result
);
155 * Get results of a query, storing into resource. Note that this may not
156 * be used with batch queries.
158 * \param wait if true, this query will block until the result is ready
159 * \param result_type the type of the value being stored:
160 * \param index for queries that return multiple pieces of data, which
161 * item of that data to store (e.g. for
162 * PIPE_QUERY_PIPELINE_STATISTICS).
163 * When the index is -1, instead of the value of the query
164 * the driver should instead write a 1/0 to the appropriate
165 * location with 1 meaning that the query result is available.
167 void (*get_query_result_resource
)(struct pipe_context
*pipe
,
168 struct pipe_query
*q
,
170 enum pipe_query_value_type result_type
,
172 struct pipe_resource
*resource
,
178 * State functions (create/bind/destroy state objects)
181 void * (*create_blend_state
)(struct pipe_context
*,
182 const struct pipe_blend_state
*);
183 void (*bind_blend_state
)(struct pipe_context
*, void *);
184 void (*delete_blend_state
)(struct pipe_context
*, void *);
186 void * (*create_sampler_state
)(struct pipe_context
*,
187 const struct pipe_sampler_state
*);
188 void (*bind_sampler_states
)(struct pipe_context
*,
189 unsigned shader
, unsigned start_slot
,
190 unsigned num_samplers
, void **samplers
);
191 void (*delete_sampler_state
)(struct pipe_context
*, void *);
193 void * (*create_rasterizer_state
)(struct pipe_context
*,
194 const struct pipe_rasterizer_state
*);
195 void (*bind_rasterizer_state
)(struct pipe_context
*, void *);
196 void (*delete_rasterizer_state
)(struct pipe_context
*, void *);
198 void * (*create_depth_stencil_alpha_state
)(struct pipe_context
*,
199 const struct pipe_depth_stencil_alpha_state
*);
200 void (*bind_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
201 void (*delete_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
203 void * (*create_fs_state
)(struct pipe_context
*,
204 const struct pipe_shader_state
*);
205 void (*bind_fs_state
)(struct pipe_context
*, void *);
206 void (*delete_fs_state
)(struct pipe_context
*, void *);
208 void * (*create_vs_state
)(struct pipe_context
*,
209 const struct pipe_shader_state
*);
210 void (*bind_vs_state
)(struct pipe_context
*, void *);
211 void (*delete_vs_state
)(struct pipe_context
*, void *);
213 void * (*create_gs_state
)(struct pipe_context
*,
214 const struct pipe_shader_state
*);
215 void (*bind_gs_state
)(struct pipe_context
*, void *);
216 void (*delete_gs_state
)(struct pipe_context
*, void *);
218 void * (*create_tcs_state
)(struct pipe_context
*,
219 const struct pipe_shader_state
*);
220 void (*bind_tcs_state
)(struct pipe_context
*, void *);
221 void (*delete_tcs_state
)(struct pipe_context
*, void *);
223 void * (*create_tes_state
)(struct pipe_context
*,
224 const struct pipe_shader_state
*);
225 void (*bind_tes_state
)(struct pipe_context
*, void *);
226 void (*delete_tes_state
)(struct pipe_context
*, void *);
228 void * (*create_vertex_elements_state
)(struct pipe_context
*,
229 unsigned num_elements
,
230 const struct pipe_vertex_element
*);
231 void (*bind_vertex_elements_state
)(struct pipe_context
*, void *);
232 void (*delete_vertex_elements_state
)(struct pipe_context
*, void *);
237 * Parameter-like state (or properties)
240 void (*set_blend_color
)( struct pipe_context
*,
241 const struct pipe_blend_color
* );
243 void (*set_stencil_ref
)( struct pipe_context
*,
244 const struct pipe_stencil_ref
* );
246 void (*set_sample_mask
)( struct pipe_context
*,
247 unsigned sample_mask
);
249 void (*set_min_samples
)( struct pipe_context
*,
250 unsigned min_samples
);
252 void (*set_clip_state
)( struct pipe_context
*,
253 const struct pipe_clip_state
* );
255 void (*set_constant_buffer
)( struct pipe_context
*,
256 uint shader
, uint index
,
257 struct pipe_constant_buffer
*buf
);
259 void (*set_framebuffer_state
)( struct pipe_context
*,
260 const struct pipe_framebuffer_state
* );
262 void (*set_polygon_stipple
)( struct pipe_context
*,
263 const struct pipe_poly_stipple
* );
265 void (*set_scissor_states
)( struct pipe_context
*,
267 unsigned num_scissors
,
268 const struct pipe_scissor_state
* );
270 void (*set_viewport_states
)( struct pipe_context
*,
272 unsigned num_viewports
,
273 const struct pipe_viewport_state
*);
275 void (*set_sampler_views
)(struct pipe_context
*, unsigned shader
,
276 unsigned start_slot
, unsigned num_views
,
277 struct pipe_sampler_view
**);
279 void (*set_tess_state
)(struct pipe_context
*,
280 const float default_outer_level
[4],
281 const float default_inner_level
[2]);
284 * Sets the debug callback. If the pointer is null, then no callback is
285 * set, otherwise a copy of the data should be made.
287 void (*set_debug_callback
)(struct pipe_context
*,
288 const struct pipe_debug_callback
*);
291 * Bind an array of shader buffers that will be used by a shader.
292 * Any buffers that were previously bound to the specified range
295 * \param shader selects shader stage
296 * \param start_slot first buffer slot to bind.
297 * \param count number of consecutive buffers to bind.
298 * \param buffers array of pointers to the buffers to bind, it
299 * should contain at least \a count elements
300 * unless it's NULL, in which case no buffers will
303 void (*set_shader_buffers
)(struct pipe_context
*, unsigned shader
,
304 unsigned start_slot
, unsigned count
,
305 struct pipe_shader_buffer
*buffers
);
308 * Bind an array of images that will be used by a shader.
309 * Any images that were previously bound to the specified range
312 * \param shader selects shader stage
313 * \param start_slot first image slot to bind.
314 * \param count number of consecutive images to bind.
315 * \param buffers array of pointers to the images to bind, it
316 * should contain at least \a count elements
317 * unless it's NULL, in which case no images will
320 void (*set_shader_images
)(struct pipe_context
*, unsigned shader
,
321 unsigned start_slot
, unsigned count
,
322 struct pipe_image_view
**images
);
324 void (*set_vertex_buffers
)( struct pipe_context
*,
326 unsigned num_buffers
,
327 const struct pipe_vertex_buffer
* );
329 void (*set_index_buffer
)( struct pipe_context
*pipe
,
330 const struct pipe_index_buffer
* );
335 * Stream output functions.
339 struct pipe_stream_output_target
*(*create_stream_output_target
)(
340 struct pipe_context
*,
341 struct pipe_resource
*,
342 unsigned buffer_offset
,
343 unsigned buffer_size
);
345 void (*stream_output_target_destroy
)(struct pipe_context
*,
346 struct pipe_stream_output_target
*);
348 void (*set_stream_output_targets
)(struct pipe_context
*,
349 unsigned num_targets
,
350 struct pipe_stream_output_target
**targets
,
351 const unsigned *offsets
);
357 * Resource functions for blit-like functionality
359 * If a driver supports multisampling, blit must implement color resolve.
364 * Copy a block of pixels from one resource to another.
365 * The resource must be of the same format.
366 * Resources with nr_samples > 1 are not allowed.
368 void (*resource_copy_region
)(struct pipe_context
*pipe
,
369 struct pipe_resource
*dst
,
371 unsigned dstx
, unsigned dsty
, unsigned dstz
,
372 struct pipe_resource
*src
,
374 const struct pipe_box
*src_box
);
376 /* Optimal hardware path for blitting pixels.
377 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
379 void (*blit
)(struct pipe_context
*pipe
,
380 const struct pipe_blit_info
*info
);
385 * Clear the specified set of currently bound buffers to specified values.
386 * The entire buffers are cleared (no scissor, no colormask, etc).
388 * \param buffers bitfield of PIPE_CLEAR_* values.
389 * \param color pointer to a union of fiu array for each of r, g, b, a.
390 * \param depth depth clear value in [0,1].
391 * \param stencil stencil clear value
393 void (*clear
)(struct pipe_context
*pipe
,
395 const union pipe_color_union
*color
,
400 * Clear a color rendertarget surface.
401 * \param color pointer to an union of fiu array for each of r, g, b, a.
403 void (*clear_render_target
)(struct pipe_context
*pipe
,
404 struct pipe_surface
*dst
,
405 const union pipe_color_union
*color
,
406 unsigned dstx
, unsigned dsty
,
407 unsigned width
, unsigned height
);
410 * Clear a depth-stencil surface.
411 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
412 * \param depth depth clear value in [0,1].
413 * \param stencil stencil clear value
415 void (*clear_depth_stencil
)(struct pipe_context
*pipe
,
416 struct pipe_surface
*dst
,
417 unsigned clear_flags
,
420 unsigned dstx
, unsigned dsty
,
421 unsigned width
, unsigned height
);
424 * Clear the texture with the specified texel. Not guaranteed to be a
425 * renderable format. Data provided in the resource's format.
427 void (*clear_texture
)(struct pipe_context
*pipe
,
428 struct pipe_resource
*res
,
430 const struct pipe_box
*box
,
434 * Clear a buffer. Runs a memset over the specified region with the element
435 * value passed in through clear_value of size clear_value_size.
437 void (*clear_buffer
)(struct pipe_context
*pipe
,
438 struct pipe_resource
*res
,
441 const void *clear_value
,
442 int clear_value_size
);
445 * Flush draw commands
447 * NOTE: use screen->fence_reference() (or equivalent) to transfer
448 * new fence ref to **fence, to ensure that previous fence is unref'd
450 * \param fence if not NULL, an old fence to unref and transfer a
451 * new fence reference to
452 * \param flags bitfield of enum pipe_flush_flags values.
454 void (*flush
)(struct pipe_context
*pipe
,
455 struct pipe_fence_handle
**fence
,
459 * Create a view on a texture to be used by a shader stage.
461 struct pipe_sampler_view
* (*create_sampler_view
)(struct pipe_context
*ctx
,
462 struct pipe_resource
*texture
,
463 const struct pipe_sampler_view
*templat
);
465 void (*sampler_view_destroy
)(struct pipe_context
*ctx
,
466 struct pipe_sampler_view
*view
);
470 * Get a surface which is a "view" into a resource, used by
471 * render target / depth stencil stages.
473 struct pipe_surface
*(*create_surface
)(struct pipe_context
*ctx
,
474 struct pipe_resource
*resource
,
475 const struct pipe_surface
*templat
);
477 void (*surface_destroy
)(struct pipe_context
*ctx
,
478 struct pipe_surface
*);
481 * Create an image view into a buffer or texture to be used with load,
482 * store, and atomic instructions by a shader stage.
484 struct pipe_image_view
* (*create_image_view
)(struct pipe_context
*ctx
,
485 struct pipe_resource
*texture
,
486 const struct pipe_image_view
*templat
);
488 void (*image_view_destroy
)(struct pipe_context
*ctx
,
489 struct pipe_image_view
*view
);
494 * Transfers are (by default) context-private and allow uploads to be
495 * interleaved with rendering.
497 * out_transfer will contain the transfer object that must be passed
498 * to all the other transfer functions. It also contains useful
499 * information (like texture strides).
501 void *(*transfer_map
)(struct pipe_context
*,
502 struct pipe_resource
*resource
,
504 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
505 const struct pipe_box
*,
506 struct pipe_transfer
**out_transfer
);
508 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
509 * regions specified with this call are guaranteed to be written to
512 void (*transfer_flush_region
)( struct pipe_context
*,
513 struct pipe_transfer
*transfer
,
514 const struct pipe_box
*);
516 void (*transfer_unmap
)(struct pipe_context
*,
517 struct pipe_transfer
*transfer
);
519 /* One-shot transfer operation with data supplied in a user
520 * pointer. XXX: strides??
522 void (*transfer_inline_write
)( struct pipe_context
*,
523 struct pipe_resource
*,
525 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
526 const struct pipe_box
*,
529 unsigned layer_stride
);
532 * Flush any pending framebuffer writes and invalidate texture caches.
534 void (*texture_barrier
)(struct pipe_context
*);
537 * Flush caches according to flags.
539 void (*memory_barrier
)(struct pipe_context
*, unsigned flags
);
542 * Creates a video codec for a specific video format/profile
544 struct pipe_video_codec
*(*create_video_codec
)( struct pipe_context
*context
,
545 const struct pipe_video_codec
*templat
);
548 * Creates a video buffer as decoding target
550 struct pipe_video_buffer
*(*create_video_buffer
)( struct pipe_context
*context
,
551 const struct pipe_video_buffer
*templat
);
554 * Compute kernel execution
558 * Define the compute program and parameters to be used by
559 * pipe_context::launch_grid.
561 void *(*create_compute_state
)(struct pipe_context
*context
,
562 const struct pipe_compute_state
*);
563 void (*bind_compute_state
)(struct pipe_context
*, void *);
564 void (*delete_compute_state
)(struct pipe_context
*, void *);
567 * Bind an array of shader resources that will be used by the
568 * compute program. Any resources that were previously bound to
569 * the specified range will be unbound after this call.
571 * \param start first resource to bind.
572 * \param count number of consecutive resources to bind.
573 * \param resources array of pointers to the resources to bind, it
574 * should contain at least \a count elements
575 * unless it's NULL, in which case no new
576 * resources will be bound.
578 void (*set_compute_resources
)(struct pipe_context
*,
579 unsigned start
, unsigned count
,
580 struct pipe_surface
**resources
);
583 * Bind an array of buffers to be mapped into the address space of
584 * the GLOBAL resource. Any buffers that were previously bound
585 * between [first, first + count - 1] are unbound after this call.
587 * \param first first buffer to map.
588 * \param count number of consecutive buffers to map.
589 * \param resources array of pointers to the buffers to map, it
590 * should contain at least \a count elements
591 * unless it's NULL, in which case no new
592 * resources will be bound.
593 * \param handles array of pointers to the memory locations that
594 * will be updated with the address each buffer
595 * will be mapped to. The base memory address of
596 * each of the buffers will be added to the value
597 * pointed to by its corresponding handle to form
598 * the final address argument. It should contain
599 * at least \a count elements, unless \a
600 * resources is NULL in which case \a handles
601 * should be NULL as well.
603 * Note that the driver isn't required to make any guarantees about
604 * the contents of the \a handles array being valid anytime except
605 * during the subsequent calls to pipe_context::launch_grid. This
606 * means that the only sensible location handles[i] may point to is
607 * somewhere within the INPUT buffer itself. This is so to
608 * accommodate implementations that lack virtual memory but
609 * nevertheless migrate buffers on the fly, leading to resource
610 * base addresses that change on each kernel invocation or are
611 * unknown to the pipe driver.
613 void (*set_global_binding
)(struct pipe_context
*context
,
614 unsigned first
, unsigned count
,
615 struct pipe_resource
**resources
,
619 * Launch the compute kernel starting from instruction \a pc of the
620 * currently bound compute program.
622 * \a grid_layout and \a block_layout are arrays of size \a
623 * PIPE_COMPUTE_CAP_GRID_DIMENSION that determine the layout of the
624 * grid (in block units) and working block (in thread units) to be
625 * used, respectively.
627 * \a pc For drivers that use PIPE_SHADER_IR_LLVM as their prefered IR,
628 * this value will be the index of the kernel in the opencl.kernels
631 * \a input will be used to initialize the INPUT resource, and it
632 * should point to a buffer of at least
633 * pipe_compute_state::req_input_mem bytes.
635 void (*launch_grid
)(struct pipe_context
*context
,
636 const uint
*block_layout
, const uint
*grid_layout
,
637 uint32_t pc
, const void *input
);
641 * Get sample position for an individual sample point.
643 * \param sample_count - total number of samples
644 * \param sample_index - sample to get the position values for
645 * \param out_value - return value of 2 floats for x and y position for
648 void (*get_sample_position
)(struct pipe_context
*context
,
649 unsigned sample_count
,
650 unsigned sample_index
,
654 * Query a timestamp in nanoseconds. This is completely equivalent to
655 * pipe_screen::get_timestamp() but takes a context handle for drivers
656 * that require a context.
658 uint64_t (*get_timestamp
)(struct pipe_context
*);
661 * Flush the resource cache, so that the resource can be used
662 * by an external client. Possible usage:
663 * - flushing a resource before presenting it on the screen
664 * - flushing a resource if some other process or device wants to use it
665 * This shouldn't be used to flush caches if the resource is only managed
666 * by a single pipe_screen and is not shared with another process.
667 * (i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
668 * use the resource for texturing)
670 void (*flush_resource
)(struct pipe_context
*ctx
,
671 struct pipe_resource
*resource
);
674 * Invalidate the contents of the resource. This is used to
676 * (1) implement EGL's semantic of undefined depth/stencil
677 * contenst after a swapbuffers. This allows a tiled renderer (for
678 * example) to not store the depth buffer.
680 * (2) implement GL's InvalidateBufferData. For backwards compatibility,
681 * you must only rely on the usability for this purpose when
682 * PIPE_CAP_INVALIDATE_BUFFER is enabled.
684 void (*invalidate_resource
)(struct pipe_context
*ctx
,
685 struct pipe_resource
*resource
);
688 * Return information about unexpected device resets.
690 enum pipe_reset_status (*get_device_reset_status
)(struct pipe_context
*ctx
);
693 * Dump driver-specific debug information into a stream. This is
694 * used by debugging tools.
696 * \param ctx pipe context
697 * \param stream where the output should be written to
698 * \param flags a mask of PIPE_DEBUG_* flags
700 void (*dump_debug_state
)(struct pipe_context
*ctx
, FILE *stream
,
704 * Emit string marker in cmdstream
706 void (*emit_string_marker
)(struct pipe_context
*ctx
,
712 * \return TRUE if mipmap generation succeeds, FALSE otherwise
714 boolean (*generate_mipmap
)(struct pipe_context
*ctx
,
715 struct pipe_resource
*resource
,
716 enum pipe_format format
,
719 unsigned first_layer
,
720 unsigned last_layer
);
728 #endif /* PIPE_CONTEXT_H */