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_depth_stencil_alpha_state
;
49 struct pipe_draw_info
;
50 struct pipe_fence_handle
;
51 struct pipe_framebuffer_state
;
52 struct pipe_image_view
;
53 struct pipe_index_buffer
;
55 struct pipe_poly_stipple
;
56 struct pipe_rasterizer_state
;
57 struct pipe_resolve_info
;
59 struct pipe_sampler_state
;
60 struct pipe_sampler_view
;
61 struct pipe_scissor_state
;
62 struct pipe_shader_buffer
;
63 struct pipe_shader_state
;
64 struct pipe_stencil_ref
;
65 struct pipe_stream_output_target
;
68 struct pipe_vertex_buffer
;
69 struct pipe_vertex_element
;
70 struct pipe_video_buffer
;
71 struct pipe_video_codec
;
72 struct pipe_viewport_state
;
73 struct pipe_compute_state
;
74 union pipe_color_union
;
75 union pipe_query_result
;
78 * Gallium rendering context. Basically:
79 * - state setting functions
80 * - VBO drawing functions
84 struct pipe_screen
*screen
;
86 void *priv
; /**< context private data (for DRI for example) */
87 void *draw
; /**< private, for draw module (temporary?) */
89 void (*destroy
)( struct pipe_context
* );
95 void (*draw_vbo
)( struct pipe_context
*pipe
,
96 const struct pipe_draw_info
*info
);
100 * Predicate subsequent rendering on occlusion query result
101 * \param query the query predicate, or NULL if no predicate
102 * \param condition whether to skip on FALSE or TRUE query results
103 * \param mode one of PIPE_RENDER_COND_x
105 void (*render_condition
)( struct pipe_context
*pipe
,
106 struct pipe_query
*query
,
114 struct pipe_query
*(*create_query
)( struct pipe_context
*pipe
,
118 void (*destroy_query
)(struct pipe_context
*pipe
,
119 struct pipe_query
*q
);
121 boolean (*begin_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
122 void (*end_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
125 * Get results of a query.
126 * \param wait if true, this query will block until the result is ready
127 * \return TRUE if results are ready, FALSE otherwise
129 boolean (*get_query_result
)(struct pipe_context
*pipe
,
130 struct pipe_query
*q
,
132 union pipe_query_result
*result
);
136 * State functions (create/bind/destroy state objects)
139 void * (*create_blend_state
)(struct pipe_context
*,
140 const struct pipe_blend_state
*);
141 void (*bind_blend_state
)(struct pipe_context
*, void *);
142 void (*delete_blend_state
)(struct pipe_context
*, void *);
144 void * (*create_sampler_state
)(struct pipe_context
*,
145 const struct pipe_sampler_state
*);
146 void (*bind_sampler_states
)(struct pipe_context
*,
147 unsigned shader
, unsigned start_slot
,
148 unsigned num_samplers
, void **samplers
);
149 void (*delete_sampler_state
)(struct pipe_context
*, void *);
151 void * (*create_rasterizer_state
)(struct pipe_context
*,
152 const struct pipe_rasterizer_state
*);
153 void (*bind_rasterizer_state
)(struct pipe_context
*, void *);
154 void (*delete_rasterizer_state
)(struct pipe_context
*, void *);
156 void * (*create_depth_stencil_alpha_state
)(struct pipe_context
*,
157 const struct pipe_depth_stencil_alpha_state
*);
158 void (*bind_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
159 void (*delete_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
161 void * (*create_fs_state
)(struct pipe_context
*,
162 const struct pipe_shader_state
*);
163 void (*bind_fs_state
)(struct pipe_context
*, void *);
164 void (*delete_fs_state
)(struct pipe_context
*, void *);
166 void * (*create_vs_state
)(struct pipe_context
*,
167 const struct pipe_shader_state
*);
168 void (*bind_vs_state
)(struct pipe_context
*, void *);
169 void (*delete_vs_state
)(struct pipe_context
*, void *);
171 void * (*create_gs_state
)(struct pipe_context
*,
172 const struct pipe_shader_state
*);
173 void (*bind_gs_state
)(struct pipe_context
*, void *);
174 void (*delete_gs_state
)(struct pipe_context
*, void *);
176 void * (*create_tcs_state
)(struct pipe_context
*,
177 const struct pipe_shader_state
*);
178 void (*bind_tcs_state
)(struct pipe_context
*, void *);
179 void (*delete_tcs_state
)(struct pipe_context
*, void *);
181 void * (*create_tes_state
)(struct pipe_context
*,
182 const struct pipe_shader_state
*);
183 void (*bind_tes_state
)(struct pipe_context
*, void *);
184 void (*delete_tes_state
)(struct pipe_context
*, void *);
186 void * (*create_vertex_elements_state
)(struct pipe_context
*,
187 unsigned num_elements
,
188 const struct pipe_vertex_element
*);
189 void (*bind_vertex_elements_state
)(struct pipe_context
*, void *);
190 void (*delete_vertex_elements_state
)(struct pipe_context
*, void *);
195 * Parameter-like state (or properties)
198 void (*set_blend_color
)( struct pipe_context
*,
199 const struct pipe_blend_color
* );
201 void (*set_stencil_ref
)( struct pipe_context
*,
202 const struct pipe_stencil_ref
* );
204 void (*set_sample_mask
)( struct pipe_context
*,
205 unsigned sample_mask
);
207 void (*set_min_samples
)( struct pipe_context
*,
208 unsigned min_samples
);
210 void (*set_clip_state
)( struct pipe_context
*,
211 const struct pipe_clip_state
* );
213 void (*set_constant_buffer
)( struct pipe_context
*,
214 uint shader
, uint index
,
215 struct pipe_constant_buffer
*buf
);
217 void (*set_framebuffer_state
)( struct pipe_context
*,
218 const struct pipe_framebuffer_state
* );
220 void (*set_polygon_stipple
)( struct pipe_context
*,
221 const struct pipe_poly_stipple
* );
223 void (*set_scissor_states
)( struct pipe_context
*,
225 unsigned num_scissors
,
226 const struct pipe_scissor_state
* );
228 void (*set_viewport_states
)( struct pipe_context
*,
230 unsigned num_viewports
,
231 const struct pipe_viewport_state
*);
233 void (*set_sampler_views
)(struct pipe_context
*, unsigned shader
,
234 unsigned start_slot
, unsigned num_views
,
235 struct pipe_sampler_view
**);
237 void (*set_tess_state
)(struct pipe_context
*,
238 const float default_outer_level
[4],
239 const float default_inner_level
[2]);
242 * Bind an array of shader buffers that will be used by a shader.
243 * Any buffers that were previously bound to the specified range
246 * \param shader selects shader stage
247 * \param start_slot first buffer slot to bind.
248 * \param count number of consecutive buffers to bind.
249 * \param buffers array of pointers to the buffers to bind, it
250 * should contain at least \a count elements
251 * unless it's NULL, in which case no buffers will
254 void (*set_shader_buffers
)(struct pipe_context
*, unsigned shader
,
255 unsigned start_slot
, unsigned count
,
256 struct pipe_shader_buffer
*buffers
);
259 * Bind an array of images that will be used by a shader.
260 * Any images that were previously bound to the specified range
263 * \param shader selects shader stage
264 * \param start_slot first image slot to bind.
265 * \param count number of consecutive images to bind.
266 * \param buffers array of pointers to the images to bind, it
267 * should contain at least \a count elements
268 * unless it's NULL, in which case no images will
271 void (*set_shader_images
)(struct pipe_context
*, unsigned shader
,
272 unsigned start_slot
, unsigned count
,
273 struct pipe_image_view
**images
);
275 void (*set_vertex_buffers
)( struct pipe_context
*,
277 unsigned num_buffers
,
278 const struct pipe_vertex_buffer
* );
280 void (*set_index_buffer
)( struct pipe_context
*pipe
,
281 const struct pipe_index_buffer
* );
286 * Stream output functions.
290 struct pipe_stream_output_target
*(*create_stream_output_target
)(
291 struct pipe_context
*,
292 struct pipe_resource
*,
293 unsigned buffer_offset
,
294 unsigned buffer_size
);
296 void (*stream_output_target_destroy
)(struct pipe_context
*,
297 struct pipe_stream_output_target
*);
299 void (*set_stream_output_targets
)(struct pipe_context
*,
300 unsigned num_targets
,
301 struct pipe_stream_output_target
**targets
,
302 const unsigned *offsets
);
308 * Resource functions for blit-like functionality
310 * If a driver supports multisampling, blit must implement color resolve.
315 * Copy a block of pixels from one resource to another.
316 * The resource must be of the same format.
317 * Resources with nr_samples > 1 are not allowed.
319 void (*resource_copy_region
)(struct pipe_context
*pipe
,
320 struct pipe_resource
*dst
,
322 unsigned dstx
, unsigned dsty
, unsigned dstz
,
323 struct pipe_resource
*src
,
325 const struct pipe_box
*src_box
);
327 /* Optimal hardware path for blitting pixels.
328 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
330 void (*blit
)(struct pipe_context
*pipe
,
331 const struct pipe_blit_info
*info
);
336 * Clear the specified set of currently bound buffers to specified values.
337 * The entire buffers are cleared (no scissor, no colormask, etc).
339 * \param buffers bitfield of PIPE_CLEAR_* values.
340 * \param color pointer to a union of fiu array for each of r, g, b, a.
341 * \param depth depth clear value in [0,1].
342 * \param stencil stencil clear value
344 void (*clear
)(struct pipe_context
*pipe
,
346 const union pipe_color_union
*color
,
351 * Clear a color rendertarget surface.
352 * \param color pointer to an union of fiu array for each of r, g, b, a.
354 void (*clear_render_target
)(struct pipe_context
*pipe
,
355 struct pipe_surface
*dst
,
356 const union pipe_color_union
*color
,
357 unsigned dstx
, unsigned dsty
,
358 unsigned width
, unsigned height
);
361 * Clear a depth-stencil surface.
362 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
363 * \param depth depth clear value in [0,1].
364 * \param stencil stencil clear value
366 void (*clear_depth_stencil
)(struct pipe_context
*pipe
,
367 struct pipe_surface
*dst
,
368 unsigned clear_flags
,
371 unsigned dstx
, unsigned dsty
,
372 unsigned width
, unsigned height
);
375 * Clear a buffer. Runs a memset over the specified region with the element
376 * value passed in through clear_value of size clear_value_size.
378 void (*clear_buffer
)(struct pipe_context
*pipe
,
379 struct pipe_resource
*res
,
382 const void *clear_value
,
383 int clear_value_size
);
386 * Flush draw commands
388 * NOTE: use screen->fence_reference() (or equivalent) to transfer
389 * new fence ref to **fence, to ensure that previous fence is unref'd
391 * \param fence if not NULL, an old fence to unref and transfer a
392 * new fence reference to
393 * \param flags bitfield of enum pipe_flush_flags values.
395 void (*flush
)(struct pipe_context
*pipe
,
396 struct pipe_fence_handle
**fence
,
400 * Create a view on a texture to be used by a shader stage.
402 struct pipe_sampler_view
* (*create_sampler_view
)(struct pipe_context
*ctx
,
403 struct pipe_resource
*texture
,
404 const struct pipe_sampler_view
*templat
);
406 void (*sampler_view_destroy
)(struct pipe_context
*ctx
,
407 struct pipe_sampler_view
*view
);
411 * Get a surface which is a "view" into a resource, used by
412 * render target / depth stencil stages.
414 struct pipe_surface
*(*create_surface
)(struct pipe_context
*ctx
,
415 struct pipe_resource
*resource
,
416 const struct pipe_surface
*templat
);
418 void (*surface_destroy
)(struct pipe_context
*ctx
,
419 struct pipe_surface
*);
422 * Create an image view into a buffer or texture to be used with load,
423 * store, and atomic instructions by a shader stage.
425 struct pipe_image_view
* (*create_image_view
)(struct pipe_context
*ctx
,
426 struct pipe_resource
*texture
,
427 const struct pipe_image_view
*templat
);
429 void (*image_view_destroy
)(struct pipe_context
*ctx
,
430 struct pipe_image_view
*view
);
435 * Transfers are (by default) context-private and allow uploads to be
436 * interleaved with rendering.
438 * out_transfer will contain the transfer object that must be passed
439 * to all the other transfer functions. It also contains useful
440 * information (like texture strides).
442 void *(*transfer_map
)(struct pipe_context
*,
443 struct pipe_resource
*resource
,
445 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
446 const struct pipe_box
*,
447 struct pipe_transfer
**out_transfer
);
449 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
450 * regions specified with this call are guaranteed to be written to
453 void (*transfer_flush_region
)( struct pipe_context
*,
454 struct pipe_transfer
*transfer
,
455 const struct pipe_box
*);
457 void (*transfer_unmap
)(struct pipe_context
*,
458 struct pipe_transfer
*transfer
);
460 /* One-shot transfer operation with data supplied in a user
461 * pointer. XXX: strides??
463 void (*transfer_inline_write
)( struct pipe_context
*,
464 struct pipe_resource
*,
466 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
467 const struct pipe_box
*,
470 unsigned layer_stride
);
473 * Flush any pending framebuffer writes and invalidate texture caches.
475 void (*texture_barrier
)(struct pipe_context
*);
478 * Flush caches according to flags.
480 void (*memory_barrier
)(struct pipe_context
*, unsigned flags
);
483 * Creates a video codec for a specific video format/profile
485 struct pipe_video_codec
*(*create_video_codec
)( struct pipe_context
*context
,
486 const struct pipe_video_codec
*templat
);
489 * Creates a video buffer as decoding target
491 struct pipe_video_buffer
*(*create_video_buffer
)( struct pipe_context
*context
,
492 const struct pipe_video_buffer
*templat
);
495 * Compute kernel execution
499 * Define the compute program and parameters to be used by
500 * pipe_context::launch_grid.
502 void *(*create_compute_state
)(struct pipe_context
*context
,
503 const struct pipe_compute_state
*);
504 void (*bind_compute_state
)(struct pipe_context
*, void *);
505 void (*delete_compute_state
)(struct pipe_context
*, void *);
508 * Bind an array of shader resources that will be used by the
509 * compute program. Any resources that were previously bound to
510 * the specified range will be unbound after this call.
512 * \param start first resource to bind.
513 * \param count number of consecutive resources to bind.
514 * \param resources array of pointers to the resources to bind, it
515 * should contain at least \a count elements
516 * unless it's NULL, in which case no new
517 * resources will be bound.
519 void (*set_compute_resources
)(struct pipe_context
*,
520 unsigned start
, unsigned count
,
521 struct pipe_surface
**resources
);
524 * Bind an array of buffers to be mapped into the address space of
525 * the GLOBAL resource. Any buffers that were previously bound
526 * between [first, first + count - 1] are unbound after this call.
528 * \param first first buffer to map.
529 * \param count number of consecutive buffers to map.
530 * \param resources array of pointers to the buffers to map, it
531 * should contain at least \a count elements
532 * unless it's NULL, in which case no new
533 * resources will be bound.
534 * \param handles array of pointers to the memory locations that
535 * will be updated with the address each buffer
536 * will be mapped to. The base memory address of
537 * each of the buffers will be added to the value
538 * pointed to by its corresponding handle to form
539 * the final address argument. It should contain
540 * at least \a count elements, unless \a
541 * resources is NULL in which case \a handles
542 * should be NULL as well.
544 * Note that the driver isn't required to make any guarantees about
545 * the contents of the \a handles array being valid anytime except
546 * during the subsequent calls to pipe_context::launch_grid. This
547 * means that the only sensible location handles[i] may point to is
548 * somewhere within the INPUT buffer itself. This is so to
549 * accommodate implementations that lack virtual memory but
550 * nevertheless migrate buffers on the fly, leading to resource
551 * base addresses that change on each kernel invocation or are
552 * unknown to the pipe driver.
554 void (*set_global_binding
)(struct pipe_context
*context
,
555 unsigned first
, unsigned count
,
556 struct pipe_resource
**resources
,
560 * Launch the compute kernel starting from instruction \a pc of the
561 * currently bound compute program.
563 * \a grid_layout and \a block_layout are arrays of size \a
564 * PIPE_COMPUTE_CAP_GRID_DIMENSION that determine the layout of the
565 * grid (in block units) and working block (in thread units) to be
566 * used, respectively.
568 * \a pc For drivers that use PIPE_SHADER_IR_LLVM as their prefered IR,
569 * this value will be the index of the kernel in the opencl.kernels
572 * \a input will be used to initialize the INPUT resource, and it
573 * should point to a buffer of at least
574 * pipe_compute_state::req_input_mem bytes.
576 void (*launch_grid
)(struct pipe_context
*context
,
577 const uint
*block_layout
, const uint
*grid_layout
,
578 uint32_t pc
, const void *input
);
582 * Get sample position for an individual sample point.
584 * \param sample_count - total number of samples
585 * \param sample_index - sample to get the position values for
586 * \param out_value - return value of 2 floats for x and y position for
589 void (*get_sample_position
)(struct pipe_context
*context
,
590 unsigned sample_count
,
591 unsigned sample_index
,
595 * Flush the resource cache, so that the resource can be used
596 * by an external client. Possible usage:
597 * - flushing a resource before presenting it on the screen
598 * - flushing a resource if some other process or device wants to use it
599 * This shouldn't be used to flush caches if the resource is only managed
600 * by a single pipe_screen and is not shared with another process.
601 * (i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
602 * use the resource for texturing)
604 void (*flush_resource
)(struct pipe_context
*ctx
,
605 struct pipe_resource
*resource
);
608 * Invalidate the contents of the resource.
610 * This is used to implement EGL's semantic of undefined depth/stencil
611 * contenst after a swapbuffers. This allows a tiled renderer (for
612 * example) to not store the depth buffer.
614 void (*invalidate_resource
)(struct pipe_context
*ctx
,
615 struct pipe_resource
*resource
);
618 * Return information about unexpected device resets.
620 enum pipe_reset_status (*get_device_reset_status
)(struct pipe_context
*ctx
);
623 * Dump driver-specific debug information into a stream. This is
624 * used by debugging tools.
626 * \param ctx pipe context
627 * \param stream where the output should be written to
628 * \param flags a mask of PIPE_DEBUG_* flags
630 void (*dump_debug_state
)(struct pipe_context
*ctx
, FILE *stream
,
639 #endif /* PIPE_CONTEXT_H */