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_grid_info
;
52 struct pipe_fence_handle
;
53 struct pipe_framebuffer_state
;
54 struct pipe_image_view
;
55 struct pipe_index_buffer
;
57 struct pipe_poly_stipple
;
58 struct pipe_rasterizer_state
;
59 struct pipe_resolve_info
;
61 struct pipe_sampler_state
;
62 struct pipe_sampler_view
;
63 struct pipe_scissor_state
;
64 struct pipe_shader_buffer
;
65 struct pipe_shader_state
;
66 struct pipe_stencil_ref
;
67 struct pipe_stream_output_target
;
70 struct pipe_vertex_buffer
;
71 struct pipe_vertex_element
;
72 struct pipe_video_buffer
;
73 struct pipe_video_codec
;
74 struct pipe_viewport_state
;
75 struct pipe_compute_state
;
76 union pipe_color_union
;
77 union pipe_query_result
;
80 * Gallium rendering context. Basically:
81 * - state setting functions
82 * - VBO drawing functions
86 struct pipe_screen
*screen
;
88 void *priv
; /**< context private data (for DRI for example) */
89 void *draw
; /**< private, for draw module (temporary?) */
91 void (*destroy
)( struct pipe_context
* );
97 void (*draw_vbo
)( struct pipe_context
*pipe
,
98 const struct pipe_draw_info
*info
);
102 * Predicate subsequent rendering on occlusion query result
103 * \param query the query predicate, or NULL if no predicate
104 * \param condition whether to skip on FALSE or TRUE query results
105 * \param mode one of PIPE_RENDER_COND_x
107 void (*render_condition
)( struct pipe_context
*pipe
,
108 struct pipe_query
*query
,
116 struct pipe_query
*(*create_query
)( struct pipe_context
*pipe
,
121 * Create a query object that queries all given query types simultaneously.
123 * This can only be used for those query types for which
124 * get_driver_query_info indicates that it must be used. Only one batch
125 * query object may be active at a time.
127 * There may be additional constraints on which query types can be used
128 * together, in particular those that are implied by
129 * get_driver_query_group_info.
131 * \param num_queries the number of query types
132 * \param query_types array of \p num_queries query types
133 * \return a query object, or NULL on error.
135 struct pipe_query
*(*create_batch_query
)( struct pipe_context
*pipe
,
136 unsigned num_queries
,
137 unsigned *query_types
);
139 void (*destroy_query
)(struct pipe_context
*pipe
,
140 struct pipe_query
*q
);
142 boolean (*begin_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
143 bool (*end_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
146 * Get results of a query.
147 * \param wait if true, this query will block until the result is ready
148 * \return TRUE if results are ready, FALSE otherwise
150 boolean (*get_query_result
)(struct pipe_context
*pipe
,
151 struct pipe_query
*q
,
153 union pipe_query_result
*result
);
156 * Get results of a query, storing into resource. Note that this may not
157 * be used with batch queries.
159 * \param wait if true, this query will block until the result is ready
160 * \param result_type the type of the value being stored:
161 * \param index for queries that return multiple pieces of data, which
162 * item of that data to store (e.g. for
163 * PIPE_QUERY_PIPELINE_STATISTICS).
164 * When the index is -1, instead of the value of the query
165 * the driver should instead write a 1 or 0 to the appropriate
166 * location with 1 meaning that the query result is available.
168 void (*get_query_result_resource
)(struct pipe_context
*pipe
,
169 struct pipe_query
*q
,
171 enum pipe_query_value_type result_type
,
173 struct pipe_resource
*resource
,
177 * Set whether all current non-driver queries except TIME_ELAPSED are
180 void (*set_active_query_state
)(struct pipe_context
*pipe
, boolean enable
);
185 * State functions (create/bind/destroy state objects)
188 void * (*create_blend_state
)(struct pipe_context
*,
189 const struct pipe_blend_state
*);
190 void (*bind_blend_state
)(struct pipe_context
*, void *);
191 void (*delete_blend_state
)(struct pipe_context
*, void *);
193 void * (*create_sampler_state
)(struct pipe_context
*,
194 const struct pipe_sampler_state
*);
195 void (*bind_sampler_states
)(struct pipe_context
*,
196 enum pipe_shader_type shader
,
197 unsigned start_slot
, unsigned num_samplers
,
199 void (*delete_sampler_state
)(struct pipe_context
*, void *);
201 void * (*create_rasterizer_state
)(struct pipe_context
*,
202 const struct pipe_rasterizer_state
*);
203 void (*bind_rasterizer_state
)(struct pipe_context
*, void *);
204 void (*delete_rasterizer_state
)(struct pipe_context
*, void *);
206 void * (*create_depth_stencil_alpha_state
)(struct pipe_context
*,
207 const struct pipe_depth_stencil_alpha_state
*);
208 void (*bind_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
209 void (*delete_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
211 void * (*create_fs_state
)(struct pipe_context
*,
212 const struct pipe_shader_state
*);
213 void (*bind_fs_state
)(struct pipe_context
*, void *);
214 void (*delete_fs_state
)(struct pipe_context
*, void *);
216 void * (*create_vs_state
)(struct pipe_context
*,
217 const struct pipe_shader_state
*);
218 void (*bind_vs_state
)(struct pipe_context
*, void *);
219 void (*delete_vs_state
)(struct pipe_context
*, void *);
221 void * (*create_gs_state
)(struct pipe_context
*,
222 const struct pipe_shader_state
*);
223 void (*bind_gs_state
)(struct pipe_context
*, void *);
224 void (*delete_gs_state
)(struct pipe_context
*, void *);
226 void * (*create_tcs_state
)(struct pipe_context
*,
227 const struct pipe_shader_state
*);
228 void (*bind_tcs_state
)(struct pipe_context
*, void *);
229 void (*delete_tcs_state
)(struct pipe_context
*, void *);
231 void * (*create_tes_state
)(struct pipe_context
*,
232 const struct pipe_shader_state
*);
233 void (*bind_tes_state
)(struct pipe_context
*, void *);
234 void (*delete_tes_state
)(struct pipe_context
*, void *);
236 void * (*create_vertex_elements_state
)(struct pipe_context
*,
237 unsigned num_elements
,
238 const struct pipe_vertex_element
*);
239 void (*bind_vertex_elements_state
)(struct pipe_context
*, void *);
240 void (*delete_vertex_elements_state
)(struct pipe_context
*, void *);
245 * Parameter-like state (or properties)
248 void (*set_blend_color
)( struct pipe_context
*,
249 const struct pipe_blend_color
* );
251 void (*set_stencil_ref
)( struct pipe_context
*,
252 const struct pipe_stencil_ref
* );
254 void (*set_sample_mask
)( struct pipe_context
*,
255 unsigned sample_mask
);
257 void (*set_min_samples
)( struct pipe_context
*,
258 unsigned min_samples
);
260 void (*set_clip_state
)( struct pipe_context
*,
261 const struct pipe_clip_state
* );
263 void (*set_constant_buffer
)( struct pipe_context
*,
264 uint shader
, uint index
,
265 const struct pipe_constant_buffer
*buf
);
267 void (*set_framebuffer_state
)( struct pipe_context
*,
268 const struct pipe_framebuffer_state
* );
270 void (*set_polygon_stipple
)( struct pipe_context
*,
271 const struct pipe_poly_stipple
* );
273 void (*set_scissor_states
)( struct pipe_context
*,
275 unsigned num_scissors
,
276 const struct pipe_scissor_state
* );
278 void (*set_window_rectangles
)( struct pipe_context
*,
280 unsigned num_rectangles
,
281 const struct pipe_scissor_state
* );
283 void (*set_viewport_states
)( struct pipe_context
*,
285 unsigned num_viewports
,
286 const struct pipe_viewport_state
*);
288 void (*set_sampler_views
)(struct pipe_context
*,
289 enum pipe_shader_type shader
,
290 unsigned start_slot
, unsigned num_views
,
291 struct pipe_sampler_view
**);
293 void (*set_tess_state
)(struct pipe_context
*,
294 const float default_outer_level
[4],
295 const float default_inner_level
[2]);
298 * Sets the debug callback. If the pointer is null, then no callback is
299 * set, otherwise a copy of the data should be made.
301 void (*set_debug_callback
)(struct pipe_context
*,
302 const struct pipe_debug_callback
*);
305 * Bind an array of shader buffers that will be used by a shader.
306 * Any buffers that were previously bound to the specified range
309 * \param shader selects shader stage
310 * \param start_slot first buffer slot to bind.
311 * \param count number of consecutive buffers to bind.
312 * \param buffers array of pointers to the buffers to bind, it
313 * should contain at least \a count elements
314 * unless it's NULL, in which case no buffers will
317 void (*set_shader_buffers
)(struct pipe_context
*, unsigned shader
,
318 unsigned start_slot
, unsigned count
,
319 const struct pipe_shader_buffer
*buffers
);
322 * Bind an array of images that will be used by a shader.
323 * Any images that were previously bound to the specified range
326 * \param shader selects shader stage
327 * \param start_slot first image slot to bind.
328 * \param count number of consecutive images to bind.
329 * \param buffers array of the images to bind, it
330 * should contain at least \a count elements
331 * unless it's NULL, in which case no images will
334 void (*set_shader_images
)(struct pipe_context
*, unsigned shader
,
335 unsigned start_slot
, unsigned count
,
336 const struct pipe_image_view
*images
);
338 void (*set_vertex_buffers
)( struct pipe_context
*,
340 unsigned num_buffers
,
341 const struct pipe_vertex_buffer
* );
343 void (*set_index_buffer
)( struct pipe_context
*pipe
,
344 const struct pipe_index_buffer
* );
349 * Stream output functions.
353 struct pipe_stream_output_target
*(*create_stream_output_target
)(
354 struct pipe_context
*,
355 struct pipe_resource
*,
356 unsigned buffer_offset
,
357 unsigned buffer_size
);
359 void (*stream_output_target_destroy
)(struct pipe_context
*,
360 struct pipe_stream_output_target
*);
362 void (*set_stream_output_targets
)(struct pipe_context
*,
363 unsigned num_targets
,
364 struct pipe_stream_output_target
**targets
,
365 const unsigned *offsets
);
371 * Resource functions for blit-like functionality
373 * If a driver supports multisampling, blit must implement color resolve.
378 * Copy a block of pixels from one resource to another.
379 * The resource must be of the same format.
380 * Resources with nr_samples > 1 are not allowed.
382 void (*resource_copy_region
)(struct pipe_context
*pipe
,
383 struct pipe_resource
*dst
,
385 unsigned dstx
, unsigned dsty
, unsigned dstz
,
386 struct pipe_resource
*src
,
388 const struct pipe_box
*src_box
);
390 /* Optimal hardware path for blitting pixels.
391 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
393 void (*blit
)(struct pipe_context
*pipe
,
394 const struct pipe_blit_info
*info
);
399 * Clear the specified set of currently bound buffers to specified values.
400 * The entire buffers are cleared (no scissor, no colormask, etc).
402 * \param buffers bitfield of PIPE_CLEAR_* values.
403 * \param color pointer to a union of fiu array for each of r, g, b, a.
404 * \param depth depth clear value in [0,1].
405 * \param stencil stencil clear value
407 void (*clear
)(struct pipe_context
*pipe
,
409 const union pipe_color_union
*color
,
414 * Clear a color rendertarget surface.
415 * \param color pointer to an union of fiu array for each of r, g, b, a.
417 void (*clear_render_target
)(struct pipe_context
*pipe
,
418 struct pipe_surface
*dst
,
419 const union pipe_color_union
*color
,
420 unsigned dstx
, unsigned dsty
,
421 unsigned width
, unsigned height
,
422 bool render_condition_enabled
);
425 * Clear a depth-stencil surface.
426 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
427 * \param depth depth clear value in [0,1].
428 * \param stencil stencil clear value
430 void (*clear_depth_stencil
)(struct pipe_context
*pipe
,
431 struct pipe_surface
*dst
,
432 unsigned clear_flags
,
435 unsigned dstx
, unsigned dsty
,
436 unsigned width
, unsigned height
,
437 bool render_condition_enabled
);
440 * Clear the texture with the specified texel. Not guaranteed to be a
441 * renderable format. Data provided in the resource's format.
443 void (*clear_texture
)(struct pipe_context
*pipe
,
444 struct pipe_resource
*res
,
446 const struct pipe_box
*box
,
450 * Clear a buffer. Runs a memset over the specified region with the element
451 * value passed in through clear_value of size clear_value_size.
453 void (*clear_buffer
)(struct pipe_context
*pipe
,
454 struct pipe_resource
*res
,
457 const void *clear_value
,
458 int clear_value_size
);
461 * Flush draw commands
463 * NOTE: use screen->fence_reference() (or equivalent) to transfer
464 * new fence ref to **fence, to ensure that previous fence is unref'd
466 * \param fence if not NULL, an old fence to unref and transfer a
467 * new fence reference to
468 * \param flags bitfield of enum pipe_flush_flags values.
470 void (*flush
)(struct pipe_context
*pipe
,
471 struct pipe_fence_handle
**fence
,
475 * Create a view on a texture to be used by a shader stage.
477 struct pipe_sampler_view
* (*create_sampler_view
)(struct pipe_context
*ctx
,
478 struct pipe_resource
*texture
,
479 const struct pipe_sampler_view
*templat
);
481 void (*sampler_view_destroy
)(struct pipe_context
*ctx
,
482 struct pipe_sampler_view
*view
);
486 * Get a surface which is a "view" into a resource, used by
487 * render target / depth stencil stages.
489 struct pipe_surface
*(*create_surface
)(struct pipe_context
*ctx
,
490 struct pipe_resource
*resource
,
491 const struct pipe_surface
*templat
);
493 void (*surface_destroy
)(struct pipe_context
*ctx
,
494 struct pipe_surface
*);
500 * Transfers are (by default) context-private and allow uploads to be
501 * interleaved with rendering.
503 * out_transfer will contain the transfer object that must be passed
504 * to all the other transfer functions. It also contains useful
505 * information (like texture strides).
507 void *(*transfer_map
)(struct pipe_context
*,
508 struct pipe_resource
*resource
,
510 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
511 const struct pipe_box
*,
512 struct pipe_transfer
**out_transfer
);
514 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
515 * regions specified with this call are guaranteed to be written to
518 void (*transfer_flush_region
)( struct pipe_context
*,
519 struct pipe_transfer
*transfer
,
520 const struct pipe_box
*);
522 void (*transfer_unmap
)(struct pipe_context
*,
523 struct pipe_transfer
*transfer
);
525 /* One-shot transfer operation with data supplied in a user
528 void (*buffer_subdata
)(struct pipe_context
*,
529 struct pipe_resource
*,
530 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
535 void (*texture_subdata
)(struct pipe_context
*,
536 struct pipe_resource
*,
538 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
539 const struct pipe_box
*,
542 unsigned layer_stride
);
545 * Flush any pending framebuffer writes and invalidate texture caches.
547 void (*texture_barrier
)(struct pipe_context
*);
550 * Flush caches according to flags.
552 void (*memory_barrier
)(struct pipe_context
*, unsigned flags
);
555 * Creates a video codec for a specific video format/profile
557 struct pipe_video_codec
*(*create_video_codec
)( struct pipe_context
*context
,
558 const struct pipe_video_codec
*templat
);
561 * Creates a video buffer as decoding target
563 struct pipe_video_buffer
*(*create_video_buffer
)( struct pipe_context
*context
,
564 const struct pipe_video_buffer
*templat
);
567 * Compute kernel execution
571 * Define the compute program and parameters to be used by
572 * pipe_context::launch_grid.
574 void *(*create_compute_state
)(struct pipe_context
*context
,
575 const struct pipe_compute_state
*);
576 void (*bind_compute_state
)(struct pipe_context
*, void *);
577 void (*delete_compute_state
)(struct pipe_context
*, void *);
580 * Bind an array of shader resources that will be used by the
581 * compute program. Any resources that were previously bound to
582 * the specified range will be unbound after this call.
584 * \param start first resource to bind.
585 * \param count number of consecutive resources to bind.
586 * \param resources array of pointers to the resources to bind, it
587 * should contain at least \a count elements
588 * unless it's NULL, in which case no new
589 * resources will be bound.
591 void (*set_compute_resources
)(struct pipe_context
*,
592 unsigned start
, unsigned count
,
593 struct pipe_surface
**resources
);
596 * Bind an array of buffers to be mapped into the address space of
597 * the GLOBAL resource. Any buffers that were previously bound
598 * between [first, first + count - 1] are unbound after this call.
600 * \param first first buffer to map.
601 * \param count number of consecutive buffers to map.
602 * \param resources array of pointers to the buffers to map, it
603 * should contain at least \a count elements
604 * unless it's NULL, in which case no new
605 * resources will be bound.
606 * \param handles array of pointers to the memory locations that
607 * will be updated with the address each buffer
608 * will be mapped to. The base memory address of
609 * each of the buffers will be added to the value
610 * pointed to by its corresponding handle to form
611 * the final address argument. It should contain
612 * at least \a count elements, unless \a
613 * resources is NULL in which case \a handles
614 * should be NULL as well.
616 * Note that the driver isn't required to make any guarantees about
617 * the contents of the \a handles array being valid anytime except
618 * during the subsequent calls to pipe_context::launch_grid. This
619 * means that the only sensible location handles[i] may point to is
620 * somewhere within the INPUT buffer itself. This is so to
621 * accommodate implementations that lack virtual memory but
622 * nevertheless migrate buffers on the fly, leading to resource
623 * base addresses that change on each kernel invocation or are
624 * unknown to the pipe driver.
626 void (*set_global_binding
)(struct pipe_context
*context
,
627 unsigned first
, unsigned count
,
628 struct pipe_resource
**resources
,
632 * Launch the compute kernel starting from instruction \a pc of the
633 * currently bound compute program.
635 void (*launch_grid
)(struct pipe_context
*context
,
636 const struct pipe_grid_info
*info
);
640 * Get sample position for an individual sample point.
642 * \param sample_count - total number of samples
643 * \param sample_index - sample to get the position values for
644 * \param out_value - return value of 2 floats for x and y position for
647 void (*get_sample_position
)(struct pipe_context
*context
,
648 unsigned sample_count
,
649 unsigned sample_index
,
653 * Query a timestamp in nanoseconds. This is completely equivalent to
654 * pipe_screen::get_timestamp() but takes a context handle for drivers
655 * that require a context.
657 uint64_t (*get_timestamp
)(struct pipe_context
*);
660 * Flush the resource cache, so that the resource can be used
661 * by an external client. Possible usage:
662 * - flushing a resource before presenting it on the screen
663 * - flushing a resource if some other process or device wants to use it
664 * This shouldn't be used to flush caches if the resource is only managed
665 * by a single pipe_screen and is not shared with another process.
666 * (i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
667 * use the resource for texturing)
669 void (*flush_resource
)(struct pipe_context
*ctx
,
670 struct pipe_resource
*resource
);
673 * Invalidate the contents of the resource. This is used to
675 * (1) implement EGL's semantic of undefined depth/stencil
676 * contenst after a swapbuffers. This allows a tiled renderer (for
677 * example) to not store the depth buffer.
679 * (2) implement GL's InvalidateBufferData. For backwards compatibility,
680 * you must only rely on the usability for this purpose when
681 * PIPE_CAP_INVALIDATE_BUFFER is enabled.
683 void (*invalidate_resource
)(struct pipe_context
*ctx
,
684 struct pipe_resource
*resource
);
687 * Return information about unexpected device resets.
689 enum pipe_reset_status (*get_device_reset_status
)(struct pipe_context
*ctx
);
692 * Dump driver-specific debug information into a stream. This is
693 * used by debugging tools.
695 * \param ctx pipe context
696 * \param stream where the output should be written to
697 * \param flags a mask of PIPE_DUMP_* flags
699 void (*dump_debug_state
)(struct pipe_context
*ctx
, FILE *stream
,
703 * Emit string marker in cmdstream
705 void (*emit_string_marker
)(struct pipe_context
*ctx
,
711 * \return TRUE if mipmap generation succeeds, FALSE otherwise
713 boolean (*generate_mipmap
)(struct pipe_context
*ctx
,
714 struct pipe_resource
*resource
,
715 enum pipe_format format
,
718 unsigned first_layer
,
719 unsigned last_layer
);
727 #endif /* PIPE_CONTEXT_H */