Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / gallium / include / pipe / p_context.h
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 #include <stdio.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41
42 struct pipe_blend_color;
43 struct pipe_blend_state;
44 struct pipe_blit_info;
45 struct pipe_box;
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;
55 struct pipe_query;
56 struct pipe_poly_stipple;
57 struct pipe_rasterizer_state;
58 struct pipe_resolve_info;
59 struct pipe_resource;
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;
67 struct pipe_surface;
68 struct pipe_transfer;
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;
77
78 /**
79 * Gallium rendering context. Basically:
80 * - state setting functions
81 * - VBO drawing functions
82 * - surface functions
83 */
84 struct pipe_context {
85 struct pipe_screen *screen;
86
87 void *priv; /**< context private data (for DRI for example) */
88 void *draw; /**< private, for draw module (temporary?) */
89
90 void (*destroy)( struct pipe_context * );
91
92 /**
93 * VBO drawing
94 */
95 /*@{*/
96 void (*draw_vbo)( struct pipe_context *pipe,
97 const struct pipe_draw_info *info );
98 /*@}*/
99
100 /**
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
105 */
106 void (*render_condition)( struct pipe_context *pipe,
107 struct pipe_query *query,
108 boolean condition,
109 uint mode );
110
111 /**
112 * Query objects
113 */
114 /*@{*/
115 struct pipe_query *(*create_query)( struct pipe_context *pipe,
116 unsigned query_type,
117 unsigned index );
118
119 /**
120 * Create a query object that queries all given query types simultaneously.
121 *
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.
125 *
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.
129 *
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.
133 */
134 struct pipe_query *(*create_batch_query)( struct pipe_context *pipe,
135 unsigned num_queries,
136 unsigned *query_types );
137
138 void (*destroy_query)(struct pipe_context *pipe,
139 struct pipe_query *q);
140
141 boolean (*begin_query)(struct pipe_context *pipe, struct pipe_query *q);
142 void (*end_query)(struct pipe_context *pipe, struct pipe_query *q);
143
144 /**
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
148 */
149 boolean (*get_query_result)(struct pipe_context *pipe,
150 struct pipe_query *q,
151 boolean wait,
152 union pipe_query_result *result);
153 /*@}*/
154
155 /**
156 * State functions (create/bind/destroy state objects)
157 */
158 /*@{*/
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 *);
163
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 *);
170
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 *);
175
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 *);
180
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 *);
185
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 *);
190
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 *);
195
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 *);
200
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 *);
205
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 *);
211
212 /*@}*/
213
214 /**
215 * Parameter-like state (or properties)
216 */
217 /*@{*/
218 void (*set_blend_color)( struct pipe_context *,
219 const struct pipe_blend_color * );
220
221 void (*set_stencil_ref)( struct pipe_context *,
222 const struct pipe_stencil_ref * );
223
224 void (*set_sample_mask)( struct pipe_context *,
225 unsigned sample_mask );
226
227 void (*set_min_samples)( struct pipe_context *,
228 unsigned min_samples );
229
230 void (*set_clip_state)( struct pipe_context *,
231 const struct pipe_clip_state * );
232
233 void (*set_constant_buffer)( struct pipe_context *,
234 uint shader, uint index,
235 struct pipe_constant_buffer *buf );
236
237 void (*set_framebuffer_state)( struct pipe_context *,
238 const struct pipe_framebuffer_state * );
239
240 void (*set_polygon_stipple)( struct pipe_context *,
241 const struct pipe_poly_stipple * );
242
243 void (*set_scissor_states)( struct pipe_context *,
244 unsigned start_slot,
245 unsigned num_scissors,
246 const struct pipe_scissor_state * );
247
248 void (*set_viewport_states)( struct pipe_context *,
249 unsigned start_slot,
250 unsigned num_viewports,
251 const struct pipe_viewport_state *);
252
253 void (*set_sampler_views)(struct pipe_context *, unsigned shader,
254 unsigned start_slot, unsigned num_views,
255 struct pipe_sampler_view **);
256
257 void (*set_tess_state)(struct pipe_context *,
258 const float default_outer_level[4],
259 const float default_inner_level[2]);
260
261 /**
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.
264 */
265 void (*set_debug_callback)(struct pipe_context *,
266 const struct pipe_debug_callback *);
267
268 /**
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
271 * will be unbound.
272 *
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
279 * be bound.
280 */
281 void (*set_shader_buffers)(struct pipe_context *, unsigned shader,
282 unsigned start_slot, unsigned count,
283 struct pipe_shader_buffer *buffers);
284
285 /**
286 * Bind an array of images that will be used by a shader.
287 * Any images that were previously bound to the specified range
288 * will be unbound.
289 *
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
296 * be bound.
297 */
298 void (*set_shader_images)(struct pipe_context *, unsigned shader,
299 unsigned start_slot, unsigned count,
300 struct pipe_image_view **images);
301
302 void (*set_vertex_buffers)( struct pipe_context *,
303 unsigned start_slot,
304 unsigned num_buffers,
305 const struct pipe_vertex_buffer * );
306
307 void (*set_index_buffer)( struct pipe_context *pipe,
308 const struct pipe_index_buffer * );
309
310 /*@}*/
311
312 /**
313 * Stream output functions.
314 */
315 /*@{*/
316
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);
322
323 void (*stream_output_target_destroy)(struct pipe_context *,
324 struct pipe_stream_output_target *);
325
326 void (*set_stream_output_targets)(struct pipe_context *,
327 unsigned num_targets,
328 struct pipe_stream_output_target **targets,
329 const unsigned *offsets);
330
331 /*@}*/
332
333
334 /**
335 * Resource functions for blit-like functionality
336 *
337 * If a driver supports multisampling, blit must implement color resolve.
338 */
339 /*@{*/
340
341 /**
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.
345 */
346 void (*resource_copy_region)(struct pipe_context *pipe,
347 struct pipe_resource *dst,
348 unsigned dst_level,
349 unsigned dstx, unsigned dsty, unsigned dstz,
350 struct pipe_resource *src,
351 unsigned src_level,
352 const struct pipe_box *src_box);
353
354 /* Optimal hardware path for blitting pixels.
355 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
356 */
357 void (*blit)(struct pipe_context *pipe,
358 const struct pipe_blit_info *info);
359
360 /*@}*/
361
362 /**
363 * Clear the specified set of currently bound buffers to specified values.
364 * The entire buffers are cleared (no scissor, no colormask, etc).
365 *
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
370 */
371 void (*clear)(struct pipe_context *pipe,
372 unsigned buffers,
373 const union pipe_color_union *color,
374 double depth,
375 unsigned stencil);
376
377 /**
378 * Clear a color rendertarget surface.
379 * \param color pointer to an union of fiu array for each of r, g, b, a.
380 */
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);
386
387 /**
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
392 */
393 void (*clear_depth_stencil)(struct pipe_context *pipe,
394 struct pipe_surface *dst,
395 unsigned clear_flags,
396 double depth,
397 unsigned stencil,
398 unsigned dstx, unsigned dsty,
399 unsigned width, unsigned height);
400
401 /**
402 * Clear the texture with the specified texel. Not guaranteed to be a
403 * renderable format. Data provided in the resource's format.
404 */
405 void (*clear_texture)(struct pipe_context *pipe,
406 struct pipe_resource *res,
407 unsigned level,
408 const struct pipe_box *box,
409 const void *data);
410
411 /**
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.
414 */
415 void (*clear_buffer)(struct pipe_context *pipe,
416 struct pipe_resource *res,
417 unsigned offset,
418 unsigned size,
419 const void *clear_value,
420 int clear_value_size);
421
422 /**
423 * Flush draw commands
424 *
425 * NOTE: use screen->fence_reference() (or equivalent) to transfer
426 * new fence ref to **fence, to ensure that previous fence is unref'd
427 *
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.
431 */
432 void (*flush)(struct pipe_context *pipe,
433 struct pipe_fence_handle **fence,
434 unsigned flags);
435
436 /**
437 * Create a view on a texture to be used by a shader stage.
438 */
439 struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
440 struct pipe_resource *texture,
441 const struct pipe_sampler_view *templat);
442
443 void (*sampler_view_destroy)(struct pipe_context *ctx,
444 struct pipe_sampler_view *view);
445
446
447 /**
448 * Get a surface which is a "view" into a resource, used by
449 * render target / depth stencil stages.
450 */
451 struct pipe_surface *(*create_surface)(struct pipe_context *ctx,
452 struct pipe_resource *resource,
453 const struct pipe_surface *templat);
454
455 void (*surface_destroy)(struct pipe_context *ctx,
456 struct pipe_surface *);
457
458 /**
459 * Create an image view into a buffer or texture to be used with load,
460 * store, and atomic instructions by a shader stage.
461 */
462 struct pipe_image_view * (*create_image_view)(struct pipe_context *ctx,
463 struct pipe_resource *texture,
464 const struct pipe_image_view *templat);
465
466 void (*image_view_destroy)(struct pipe_context *ctx,
467 struct pipe_image_view *view);
468
469 /**
470 * Map a resource.
471 *
472 * Transfers are (by default) context-private and allow uploads to be
473 * interleaved with rendering.
474 *
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).
478 */
479 void *(*transfer_map)(struct pipe_context *,
480 struct pipe_resource *resource,
481 unsigned level,
482 unsigned usage, /* a combination of PIPE_TRANSFER_x */
483 const struct pipe_box *,
484 struct pipe_transfer **out_transfer);
485
486 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
487 * regions specified with this call are guaranteed to be written to
488 * the resource.
489 */
490 void (*transfer_flush_region)( struct pipe_context *,
491 struct pipe_transfer *transfer,
492 const struct pipe_box *);
493
494 void (*transfer_unmap)(struct pipe_context *,
495 struct pipe_transfer *transfer);
496
497 /* One-shot transfer operation with data supplied in a user
498 * pointer. XXX: strides??
499 */
500 void (*transfer_inline_write)( struct pipe_context *,
501 struct pipe_resource *,
502 unsigned level,
503 unsigned usage, /* a combination of PIPE_TRANSFER_x */
504 const struct pipe_box *,
505 const void *data,
506 unsigned stride,
507 unsigned layer_stride);
508
509 /**
510 * Flush any pending framebuffer writes and invalidate texture caches.
511 */
512 void (*texture_barrier)(struct pipe_context *);
513
514 /**
515 * Flush caches according to flags.
516 */
517 void (*memory_barrier)(struct pipe_context *, unsigned flags);
518
519 /**
520 * Creates a video codec for a specific video format/profile
521 */
522 struct pipe_video_codec *(*create_video_codec)( struct pipe_context *context,
523 const struct pipe_video_codec *templat );
524
525 /**
526 * Creates a video buffer as decoding target
527 */
528 struct pipe_video_buffer *(*create_video_buffer)( struct pipe_context *context,
529 const struct pipe_video_buffer *templat );
530
531 /**
532 * Compute kernel execution
533 */
534 /*@{*/
535 /**
536 * Define the compute program and parameters to be used by
537 * pipe_context::launch_grid.
538 */
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 *);
543
544 /**
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.
548 *
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.
555 */
556 void (*set_compute_resources)(struct pipe_context *,
557 unsigned start, unsigned count,
558 struct pipe_surface **resources);
559
560 /**
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.
564 *
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.
580 *
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.
590 */
591 void (*set_global_binding)(struct pipe_context *context,
592 unsigned first, unsigned count,
593 struct pipe_resource **resources,
594 uint32_t **handles);
595
596 /**
597 * Launch the compute kernel starting from instruction \a pc of the
598 * currently bound compute program.
599 *
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.
604 *
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
607 * metadata list.
608 *
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.
612 */
613 void (*launch_grid)(struct pipe_context *context,
614 const uint *block_layout, const uint *grid_layout,
615 uint32_t pc, const void *input);
616 /*@}*/
617
618 /**
619 * Get sample position for an individual sample point.
620 *
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
624 * requested sample.
625 */
626 void (*get_sample_position)(struct pipe_context *context,
627 unsigned sample_count,
628 unsigned sample_index,
629 float *out_value);
630
631 /**
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.
635 */
636 uint64_t (*get_timestamp)(struct pipe_context *);
637
638 /**
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)
647 */
648 void (*flush_resource)(struct pipe_context *ctx,
649 struct pipe_resource *resource);
650
651 /**
652 * Invalidate the contents of the resource.
653 *
654 * This is used to 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.
657 */
658 void (*invalidate_resource)(struct pipe_context *ctx,
659 struct pipe_resource *resource);
660
661 /**
662 * Return information about unexpected device resets.
663 */
664 enum pipe_reset_status (*get_device_reset_status)(struct pipe_context *ctx);
665
666 /**
667 * Dump driver-specific debug information into a stream. This is
668 * used by debugging tools.
669 *
670 * \param ctx pipe context
671 * \param stream where the output should be written to
672 * \param flags a mask of PIPE_DEBUG_* flags
673 */
674 void (*dump_debug_state)(struct pipe_context *ctx, FILE *stream,
675 unsigned flags);
676 };
677
678
679 #ifdef __cplusplus
680 }
681 #endif
682
683 #endif /* PIPE_CONTEXT_H */