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
);
156 * State functions (create/bind/destroy state objects)
159 void * (*create_blend_state
)(struct pipe_context
*,
160 const struct pipe_blend_state
*);
161 void (*bind_blend_state
)(struct pipe_context
*, void *);
162 void (*delete_blend_state
)(struct pipe_context
*, void *);
164 void * (*create_sampler_state
)(struct pipe_context
*,
165 const struct pipe_sampler_state
*);
166 void (*bind_sampler_states
)(struct pipe_context
*,
167 unsigned shader
, unsigned start_slot
,
168 unsigned num_samplers
, void **samplers
);
169 void (*delete_sampler_state
)(struct pipe_context
*, void *);
171 void * (*create_rasterizer_state
)(struct pipe_context
*,
172 const struct pipe_rasterizer_state
*);
173 void (*bind_rasterizer_state
)(struct pipe_context
*, void *);
174 void (*delete_rasterizer_state
)(struct pipe_context
*, void *);
176 void * (*create_depth_stencil_alpha_state
)(struct pipe_context
*,
177 const struct pipe_depth_stencil_alpha_state
*);
178 void (*bind_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
179 void (*delete_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
181 void * (*create_fs_state
)(struct pipe_context
*,
182 const struct pipe_shader_state
*);
183 void (*bind_fs_state
)(struct pipe_context
*, void *);
184 void (*delete_fs_state
)(struct pipe_context
*, void *);
186 void * (*create_vs_state
)(struct pipe_context
*,
187 const struct pipe_shader_state
*);
188 void (*bind_vs_state
)(struct pipe_context
*, void *);
189 void (*delete_vs_state
)(struct pipe_context
*, void *);
191 void * (*create_gs_state
)(struct pipe_context
*,
192 const struct pipe_shader_state
*);
193 void (*bind_gs_state
)(struct pipe_context
*, void *);
194 void (*delete_gs_state
)(struct pipe_context
*, void *);
196 void * (*create_tcs_state
)(struct pipe_context
*,
197 const struct pipe_shader_state
*);
198 void (*bind_tcs_state
)(struct pipe_context
*, void *);
199 void (*delete_tcs_state
)(struct pipe_context
*, void *);
201 void * (*create_tes_state
)(struct pipe_context
*,
202 const struct pipe_shader_state
*);
203 void (*bind_tes_state
)(struct pipe_context
*, void *);
204 void (*delete_tes_state
)(struct pipe_context
*, void *);
206 void * (*create_vertex_elements_state
)(struct pipe_context
*,
207 unsigned num_elements
,
208 const struct pipe_vertex_element
*);
209 void (*bind_vertex_elements_state
)(struct pipe_context
*, void *);
210 void (*delete_vertex_elements_state
)(struct pipe_context
*, void *);
215 * Parameter-like state (or properties)
218 void (*set_blend_color
)( struct pipe_context
*,
219 const struct pipe_blend_color
* );
221 void (*set_stencil_ref
)( struct pipe_context
*,
222 const struct pipe_stencil_ref
* );
224 void (*set_sample_mask
)( struct pipe_context
*,
225 unsigned sample_mask
);
227 void (*set_min_samples
)( struct pipe_context
*,
228 unsigned min_samples
);
230 void (*set_clip_state
)( struct pipe_context
*,
231 const struct pipe_clip_state
* );
233 void (*set_constant_buffer
)( struct pipe_context
*,
234 uint shader
, uint index
,
235 struct pipe_constant_buffer
*buf
);
237 void (*set_framebuffer_state
)( struct pipe_context
*,
238 const struct pipe_framebuffer_state
* );
240 void (*set_polygon_stipple
)( struct pipe_context
*,
241 const struct pipe_poly_stipple
* );
243 void (*set_scissor_states
)( struct pipe_context
*,
245 unsigned num_scissors
,
246 const struct pipe_scissor_state
* );
248 void (*set_viewport_states
)( struct pipe_context
*,
250 unsigned num_viewports
,
251 const struct pipe_viewport_state
*);
253 void (*set_sampler_views
)(struct pipe_context
*, unsigned shader
,
254 unsigned start_slot
, unsigned num_views
,
255 struct pipe_sampler_view
**);
257 void (*set_tess_state
)(struct pipe_context
*,
258 const float default_outer_level
[4],
259 const float default_inner_level
[2]);
262 * Sets the debug callback. If the pointer is null, then no callback is
263 * set, otherwise a copy of the data should be made.
265 void (*set_debug_callback
)(struct pipe_context
*,
266 const struct pipe_debug_callback
*);
269 * Bind an array of shader buffers that will be used by a shader.
270 * Any buffers that were previously bound to the specified range
273 * \param shader selects shader stage
274 * \param start_slot first buffer slot to bind.
275 * \param count number of consecutive buffers to bind.
276 * \param buffers array of pointers to the buffers to bind, it
277 * should contain at least \a count elements
278 * unless it's NULL, in which case no buffers will
281 void (*set_shader_buffers
)(struct pipe_context
*, unsigned shader
,
282 unsigned start_slot
, unsigned count
,
283 struct pipe_shader_buffer
*buffers
);
286 * Bind an array of images that will be used by a shader.
287 * Any images that were previously bound to the specified range
290 * \param shader selects shader stage
291 * \param start_slot first image slot to bind.
292 * \param count number of consecutive images to bind.
293 * \param buffers array of pointers to the images to bind, it
294 * should contain at least \a count elements
295 * unless it's NULL, in which case no images will
298 void (*set_shader_images
)(struct pipe_context
*, unsigned shader
,
299 unsigned start_slot
, unsigned count
,
300 struct pipe_image_view
**images
);
302 void (*set_vertex_buffers
)( struct pipe_context
*,
304 unsigned num_buffers
,
305 const struct pipe_vertex_buffer
* );
307 void (*set_index_buffer
)( struct pipe_context
*pipe
,
308 const struct pipe_index_buffer
* );
313 * Stream output functions.
317 struct pipe_stream_output_target
*(*create_stream_output_target
)(
318 struct pipe_context
*,
319 struct pipe_resource
*,
320 unsigned buffer_offset
,
321 unsigned buffer_size
);
323 void (*stream_output_target_destroy
)(struct pipe_context
*,
324 struct pipe_stream_output_target
*);
326 void (*set_stream_output_targets
)(struct pipe_context
*,
327 unsigned num_targets
,
328 struct pipe_stream_output_target
**targets
,
329 const unsigned *offsets
);
335 * Resource functions for blit-like functionality
337 * If a driver supports multisampling, blit must implement color resolve.
342 * Copy a block of pixels from one resource to another.
343 * The resource must be of the same format.
344 * Resources with nr_samples > 1 are not allowed.
346 void (*resource_copy_region
)(struct pipe_context
*pipe
,
347 struct pipe_resource
*dst
,
349 unsigned dstx
, unsigned dsty
, unsigned dstz
,
350 struct pipe_resource
*src
,
352 const struct pipe_box
*src_box
);
354 /* Optimal hardware path for blitting pixels.
355 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
357 void (*blit
)(struct pipe_context
*pipe
,
358 const struct pipe_blit_info
*info
);
363 * Clear the specified set of currently bound buffers to specified values.
364 * The entire buffers are cleared (no scissor, no colormask, etc).
366 * \param buffers bitfield of PIPE_CLEAR_* values.
367 * \param color pointer to a union of fiu array for each of r, g, b, a.
368 * \param depth depth clear value in [0,1].
369 * \param stencil stencil clear value
371 void (*clear
)(struct pipe_context
*pipe
,
373 const union pipe_color_union
*color
,
378 * Clear a color rendertarget surface.
379 * \param color pointer to an union of fiu array for each of r, g, b, a.
381 void (*clear_render_target
)(struct pipe_context
*pipe
,
382 struct pipe_surface
*dst
,
383 const union pipe_color_union
*color
,
384 unsigned dstx
, unsigned dsty
,
385 unsigned width
, unsigned height
);
388 * Clear a depth-stencil surface.
389 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
390 * \param depth depth clear value in [0,1].
391 * \param stencil stencil clear value
393 void (*clear_depth_stencil
)(struct pipe_context
*pipe
,
394 struct pipe_surface
*dst
,
395 unsigned clear_flags
,
398 unsigned dstx
, unsigned dsty
,
399 unsigned width
, unsigned height
);
402 * Clear the texture with the specified texel. Not guaranteed to be a
403 * renderable format. Data provided in the resource's format.
405 void (*clear_texture
)(struct pipe_context
*pipe
,
406 struct pipe_resource
*res
,
408 const struct pipe_box
*box
,
412 * Clear a buffer. Runs a memset over the specified region with the element
413 * value passed in through clear_value of size clear_value_size.
415 void (*clear_buffer
)(struct pipe_context
*pipe
,
416 struct pipe_resource
*res
,
419 const void *clear_value
,
420 int clear_value_size
);
423 * Flush draw commands
425 * NOTE: use screen->fence_reference() (or equivalent) to transfer
426 * new fence ref to **fence, to ensure that previous fence is unref'd
428 * \param fence if not NULL, an old fence to unref and transfer a
429 * new fence reference to
430 * \param flags bitfield of enum pipe_flush_flags values.
432 void (*flush
)(struct pipe_context
*pipe
,
433 struct pipe_fence_handle
**fence
,
437 * Create a view on a texture to be used by a shader stage.
439 struct pipe_sampler_view
* (*create_sampler_view
)(struct pipe_context
*ctx
,
440 struct pipe_resource
*texture
,
441 const struct pipe_sampler_view
*templat
);
443 void (*sampler_view_destroy
)(struct pipe_context
*ctx
,
444 struct pipe_sampler_view
*view
);
448 * Get a surface which is a "view" into a resource, used by
449 * render target / depth stencil stages.
451 struct pipe_surface
*(*create_surface
)(struct pipe_context
*ctx
,
452 struct pipe_resource
*resource
,
453 const struct pipe_surface
*templat
);
455 void (*surface_destroy
)(struct pipe_context
*ctx
,
456 struct pipe_surface
*);
459 * Create an image view into a buffer or texture to be used with load,
460 * store, and atomic instructions by a shader stage.
462 struct pipe_image_view
* (*create_image_view
)(struct pipe_context
*ctx
,
463 struct pipe_resource
*texture
,
464 const struct pipe_image_view
*templat
);
466 void (*image_view_destroy
)(struct pipe_context
*ctx
,
467 struct pipe_image_view
*view
);
472 * Transfers are (by default) context-private and allow uploads to be
473 * interleaved with rendering.
475 * out_transfer will contain the transfer object that must be passed
476 * to all the other transfer functions. It also contains useful
477 * information (like texture strides).
479 void *(*transfer_map
)(struct pipe_context
*,
480 struct pipe_resource
*resource
,
482 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
483 const struct pipe_box
*,
484 struct pipe_transfer
**out_transfer
);
486 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
487 * regions specified with this call are guaranteed to be written to
490 void (*transfer_flush_region
)( struct pipe_context
*,
491 struct pipe_transfer
*transfer
,
492 const struct pipe_box
*);
494 void (*transfer_unmap
)(struct pipe_context
*,
495 struct pipe_transfer
*transfer
);
497 /* One-shot transfer operation with data supplied in a user
498 * pointer. XXX: strides??
500 void (*transfer_inline_write
)( struct pipe_context
*,
501 struct pipe_resource
*,
503 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
504 const struct pipe_box
*,
507 unsigned layer_stride
);
510 * Flush any pending framebuffer writes and invalidate texture caches.
512 void (*texture_barrier
)(struct pipe_context
*);
515 * Flush caches according to flags.
517 void (*memory_barrier
)(struct pipe_context
*, unsigned flags
);
520 * Creates a video codec for a specific video format/profile
522 struct pipe_video_codec
*(*create_video_codec
)( struct pipe_context
*context
,
523 const struct pipe_video_codec
*templat
);
526 * Creates a video buffer as decoding target
528 struct pipe_video_buffer
*(*create_video_buffer
)( struct pipe_context
*context
,
529 const struct pipe_video_buffer
*templat
);
532 * Compute kernel execution
536 * Define the compute program and parameters to be used by
537 * pipe_context::launch_grid.
539 void *(*create_compute_state
)(struct pipe_context
*context
,
540 const struct pipe_compute_state
*);
541 void (*bind_compute_state
)(struct pipe_context
*, void *);
542 void (*delete_compute_state
)(struct pipe_context
*, void *);
545 * Bind an array of shader resources that will be used by the
546 * compute program. Any resources that were previously bound to
547 * the specified range will be unbound after this call.
549 * \param start first resource to bind.
550 * \param count number of consecutive resources to bind.
551 * \param resources array of pointers to the resources to bind, it
552 * should contain at least \a count elements
553 * unless it's NULL, in which case no new
554 * resources will be bound.
556 void (*set_compute_resources
)(struct pipe_context
*,
557 unsigned start
, unsigned count
,
558 struct pipe_surface
**resources
);
561 * Bind an array of buffers to be mapped into the address space of
562 * the GLOBAL resource. Any buffers that were previously bound
563 * between [first, first + count - 1] are unbound after this call.
565 * \param first first buffer to map.
566 * \param count number of consecutive buffers to map.
567 * \param resources array of pointers to the buffers to map, it
568 * should contain at least \a count elements
569 * unless it's NULL, in which case no new
570 * resources will be bound.
571 * \param handles array of pointers to the memory locations that
572 * will be updated with the address each buffer
573 * will be mapped to. The base memory address of
574 * each of the buffers will be added to the value
575 * pointed to by its corresponding handle to form
576 * the final address argument. It should contain
577 * at least \a count elements, unless \a
578 * resources is NULL in which case \a handles
579 * should be NULL as well.
581 * Note that the driver isn't required to make any guarantees about
582 * the contents of the \a handles array being valid anytime except
583 * during the subsequent calls to pipe_context::launch_grid. This
584 * means that the only sensible location handles[i] may point to is
585 * somewhere within the INPUT buffer itself. This is so to
586 * accommodate implementations that lack virtual memory but
587 * nevertheless migrate buffers on the fly, leading to resource
588 * base addresses that change on each kernel invocation or are
589 * unknown to the pipe driver.
591 void (*set_global_binding
)(struct pipe_context
*context
,
592 unsigned first
, unsigned count
,
593 struct pipe_resource
**resources
,
597 * Launch the compute kernel starting from instruction \a pc of the
598 * currently bound compute program.
600 * \a grid_layout and \a block_layout are arrays of size \a
601 * PIPE_COMPUTE_CAP_GRID_DIMENSION that determine the layout of the
602 * grid (in block units) and working block (in thread units) to be
603 * used, respectively.
605 * \a pc For drivers that use PIPE_SHADER_IR_LLVM as their prefered IR,
606 * this value will be the index of the kernel in the opencl.kernels
609 * \a input will be used to initialize the INPUT resource, and it
610 * should point to a buffer of at least
611 * pipe_compute_state::req_input_mem bytes.
613 void (*launch_grid
)(struct pipe_context
*context
,
614 const uint
*block_layout
, const uint
*grid_layout
,
615 uint32_t pc
, const void *input
);
619 * Get sample position for an individual sample point.
621 * \param sample_count - total number of samples
622 * \param sample_index - sample to get the position values for
623 * \param out_value - return value of 2 floats for x and y position for
626 void (*get_sample_position
)(struct pipe_context
*context
,
627 unsigned sample_count
,
628 unsigned sample_index
,
632 * Query a timestamp in nanoseconds. This is completely equivalent to
633 * pipe_screen::get_timestamp() but takes a context handle for drivers
634 * that require a context.
636 uint64_t (*get_timestamp
)(struct pipe_context
*);
639 * Flush the resource cache, so that the resource can be used
640 * by an external client. Possible usage:
641 * - flushing a resource before presenting it on the screen
642 * - flushing a resource if some other process or device wants to use it
643 * This shouldn't be used to flush caches if the resource is only managed
644 * by a single pipe_screen and is not shared with another process.
645 * (i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
646 * use the resource for texturing)
648 void (*flush_resource
)(struct pipe_context
*ctx
,
649 struct pipe_resource
*resource
);
652 * Invalidate the contents of the resource. This is used to
654 * (1) implement EGL's semantic of undefined depth/stencil
655 * contenst after a swapbuffers. This allows a tiled renderer (for
656 * example) to not store the depth buffer.
658 * (2) implement GL's InvalidateBufferData. For backwards compatibility,
659 * you must only rely on the usability for this purpose when
660 * PIPE_CAP_INVALIDATE_BUFFER is enabled.
662 void (*invalidate_resource
)(struct pipe_context
*ctx
,
663 struct pipe_resource
*resource
);
666 * Return information about unexpected device resets.
668 enum pipe_reset_status (*get_device_reset_status
)(struct pipe_context
*ctx
);
671 * Dump driver-specific debug information into a stream. This is
672 * used by debugging tools.
674 * \param ctx pipe context
675 * \param stream where the output should be written to
676 * \param flags a mask of PIPE_DEBUG_* flags
678 void (*dump_debug_state
)(struct pipe_context
*ctx
, FILE *stream
,
682 * Emit string marker in cmdstream
684 void (*emit_string_marker
)(struct pipe_context
*ctx
,
690 * \return TRUE if mipmap generation succeeds, FALSE otherwise
692 boolean (*generate_mipmap
)(struct pipe_context
*ctx
,
693 struct pipe_resource
*resource
,
694 enum pipe_format format
,
697 unsigned first_layer
,
698 unsigned last_layer
);
706 #endif /* PIPE_CONTEXT_H */