Merge remote-tracking branch 'origin/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_grid_info;
52 struct pipe_fence_handle;
53 struct pipe_framebuffer_state;
54 struct pipe_image_view;
55 struct pipe_index_buffer;
56 struct pipe_query;
57 struct pipe_poly_stipple;
58 struct pipe_rasterizer_state;
59 struct pipe_resolve_info;
60 struct pipe_resource;
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;
68 struct pipe_surface;
69 struct pipe_transfer;
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;
78
79 /**
80 * Gallium rendering context. Basically:
81 * - state setting functions
82 * - VBO drawing functions
83 * - surface functions
84 */
85 struct pipe_context {
86 struct pipe_screen *screen;
87
88 void *priv; /**< context private data (for DRI for example) */
89 void *draw; /**< private, for draw module (temporary?) */
90
91 void (*destroy)( struct pipe_context * );
92
93 /**
94 * VBO drawing
95 */
96 /*@{*/
97 void (*draw_vbo)( struct pipe_context *pipe,
98 const struct pipe_draw_info *info );
99 /*@}*/
100
101 /**
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
106 */
107 void (*render_condition)( struct pipe_context *pipe,
108 struct pipe_query *query,
109 boolean condition,
110 uint mode );
111
112 /**
113 * Query objects
114 */
115 /*@{*/
116 struct pipe_query *(*create_query)( struct pipe_context *pipe,
117 unsigned query_type,
118 unsigned index );
119
120 /**
121 * Create a query object that queries all given query types simultaneously.
122 *
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.
126 *
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.
130 *
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.
134 */
135 struct pipe_query *(*create_batch_query)( struct pipe_context *pipe,
136 unsigned num_queries,
137 unsigned *query_types );
138
139 void (*destroy_query)(struct pipe_context *pipe,
140 struct pipe_query *q);
141
142 boolean (*begin_query)(struct pipe_context *pipe, struct pipe_query *q);
143 void (*end_query)(struct pipe_context *pipe, struct pipe_query *q);
144
145 /**
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
149 */
150 boolean (*get_query_result)(struct pipe_context *pipe,
151 struct pipe_query *q,
152 boolean wait,
153 union pipe_query_result *result);
154
155 /**
156 * Get results of a query, storing into resource. Note that this may not
157 * be used with batch queries.
158 *
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/0 to the appropriate
166 * location with 1 meaning that the query result is available.
167 */
168 void (*get_query_result_resource)(struct pipe_context *pipe,
169 struct pipe_query *q,
170 boolean wait,
171 enum pipe_query_value_type result_type,
172 int index,
173 struct pipe_resource *resource,
174 unsigned offset);
175
176 /*@}*/
177
178 /**
179 * State functions (create/bind/destroy state objects)
180 */
181 /*@{*/
182 void * (*create_blend_state)(struct pipe_context *,
183 const struct pipe_blend_state *);
184 void (*bind_blend_state)(struct pipe_context *, void *);
185 void (*delete_blend_state)(struct pipe_context *, void *);
186
187 void * (*create_sampler_state)(struct pipe_context *,
188 const struct pipe_sampler_state *);
189 void (*bind_sampler_states)(struct pipe_context *,
190 unsigned shader, unsigned start_slot,
191 unsigned num_samplers, void **samplers);
192 void (*delete_sampler_state)(struct pipe_context *, void *);
193
194 void * (*create_rasterizer_state)(struct pipe_context *,
195 const struct pipe_rasterizer_state *);
196 void (*bind_rasterizer_state)(struct pipe_context *, void *);
197 void (*delete_rasterizer_state)(struct pipe_context *, void *);
198
199 void * (*create_depth_stencil_alpha_state)(struct pipe_context *,
200 const struct pipe_depth_stencil_alpha_state *);
201 void (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *);
202 void (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *);
203
204 void * (*create_fs_state)(struct pipe_context *,
205 const struct pipe_shader_state *);
206 void (*bind_fs_state)(struct pipe_context *, void *);
207 void (*delete_fs_state)(struct pipe_context *, void *);
208
209 void * (*create_vs_state)(struct pipe_context *,
210 const struct pipe_shader_state *);
211 void (*bind_vs_state)(struct pipe_context *, void *);
212 void (*delete_vs_state)(struct pipe_context *, void *);
213
214 void * (*create_gs_state)(struct pipe_context *,
215 const struct pipe_shader_state *);
216 void (*bind_gs_state)(struct pipe_context *, void *);
217 void (*delete_gs_state)(struct pipe_context *, void *);
218
219 void * (*create_tcs_state)(struct pipe_context *,
220 const struct pipe_shader_state *);
221 void (*bind_tcs_state)(struct pipe_context *, void *);
222 void (*delete_tcs_state)(struct pipe_context *, void *);
223
224 void * (*create_tes_state)(struct pipe_context *,
225 const struct pipe_shader_state *);
226 void (*bind_tes_state)(struct pipe_context *, void *);
227 void (*delete_tes_state)(struct pipe_context *, void *);
228
229 void * (*create_vertex_elements_state)(struct pipe_context *,
230 unsigned num_elements,
231 const struct pipe_vertex_element *);
232 void (*bind_vertex_elements_state)(struct pipe_context *, void *);
233 void (*delete_vertex_elements_state)(struct pipe_context *, void *);
234
235 /*@}*/
236
237 /**
238 * Parameter-like state (or properties)
239 */
240 /*@{*/
241 void (*set_blend_color)( struct pipe_context *,
242 const struct pipe_blend_color * );
243
244 void (*set_stencil_ref)( struct pipe_context *,
245 const struct pipe_stencil_ref * );
246
247 void (*set_sample_mask)( struct pipe_context *,
248 unsigned sample_mask );
249
250 void (*set_min_samples)( struct pipe_context *,
251 unsigned min_samples );
252
253 void (*set_clip_state)( struct pipe_context *,
254 const struct pipe_clip_state * );
255
256 void (*set_constant_buffer)( struct pipe_context *,
257 uint shader, uint index,
258 struct pipe_constant_buffer *buf );
259
260 void (*set_framebuffer_state)( struct pipe_context *,
261 const struct pipe_framebuffer_state * );
262
263 void (*set_polygon_stipple)( struct pipe_context *,
264 const struct pipe_poly_stipple * );
265
266 void (*set_scissor_states)( struct pipe_context *,
267 unsigned start_slot,
268 unsigned num_scissors,
269 const struct pipe_scissor_state * );
270
271 void (*set_viewport_states)( struct pipe_context *,
272 unsigned start_slot,
273 unsigned num_viewports,
274 const struct pipe_viewport_state *);
275
276 void (*set_sampler_views)(struct pipe_context *, unsigned shader,
277 unsigned start_slot, unsigned num_views,
278 struct pipe_sampler_view **);
279
280 void (*set_tess_state)(struct pipe_context *,
281 const float default_outer_level[4],
282 const float default_inner_level[2]);
283
284 /**
285 * Sets the debug callback. If the pointer is null, then no callback is
286 * set, otherwise a copy of the data should be made.
287 */
288 void (*set_debug_callback)(struct pipe_context *,
289 const struct pipe_debug_callback *);
290
291 /**
292 * Bind an array of shader buffers that will be used by a shader.
293 * Any buffers that were previously bound to the specified range
294 * will be unbound.
295 *
296 * \param shader selects shader stage
297 * \param start_slot first buffer slot to bind.
298 * \param count number of consecutive buffers to bind.
299 * \param buffers array of pointers to the buffers to bind, it
300 * should contain at least \a count elements
301 * unless it's NULL, in which case no buffers will
302 * be bound.
303 */
304 void (*set_shader_buffers)(struct pipe_context *, unsigned shader,
305 unsigned start_slot, unsigned count,
306 struct pipe_shader_buffer *buffers);
307
308 /**
309 * Bind an array of images that will be used by a shader.
310 * Any images that were previously bound to the specified range
311 * will be unbound.
312 *
313 * \param shader selects shader stage
314 * \param start_slot first image slot to bind.
315 * \param count number of consecutive images to bind.
316 * \param buffers array of the images to bind, it
317 * should contain at least \a count elements
318 * unless it's NULL, in which case no images will
319 * be bound.
320 */
321 void (*set_shader_images)(struct pipe_context *, unsigned shader,
322 unsigned start_slot, unsigned count,
323 struct pipe_image_view *images);
324
325 void (*set_vertex_buffers)( struct pipe_context *,
326 unsigned start_slot,
327 unsigned num_buffers,
328 const struct pipe_vertex_buffer * );
329
330 void (*set_index_buffer)( struct pipe_context *pipe,
331 const struct pipe_index_buffer * );
332
333 /*@}*/
334
335 /**
336 * Stream output functions.
337 */
338 /*@{*/
339
340 struct pipe_stream_output_target *(*create_stream_output_target)(
341 struct pipe_context *,
342 struct pipe_resource *,
343 unsigned buffer_offset,
344 unsigned buffer_size);
345
346 void (*stream_output_target_destroy)(struct pipe_context *,
347 struct pipe_stream_output_target *);
348
349 void (*set_stream_output_targets)(struct pipe_context *,
350 unsigned num_targets,
351 struct pipe_stream_output_target **targets,
352 const unsigned *offsets);
353
354 /*@}*/
355
356
357 /**
358 * Resource functions for blit-like functionality
359 *
360 * If a driver supports multisampling, blit must implement color resolve.
361 */
362 /*@{*/
363
364 /**
365 * Copy a block of pixels from one resource to another.
366 * The resource must be of the same format.
367 * Resources with nr_samples > 1 are not allowed.
368 */
369 void (*resource_copy_region)(struct pipe_context *pipe,
370 struct pipe_resource *dst,
371 unsigned dst_level,
372 unsigned dstx, unsigned dsty, unsigned dstz,
373 struct pipe_resource *src,
374 unsigned src_level,
375 const struct pipe_box *src_box);
376
377 /* Optimal hardware path for blitting pixels.
378 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
379 */
380 void (*blit)(struct pipe_context *pipe,
381 const struct pipe_blit_info *info);
382
383 /*@}*/
384
385 /**
386 * Clear the specified set of currently bound buffers to specified values.
387 * The entire buffers are cleared (no scissor, no colormask, etc).
388 *
389 * \param buffers bitfield of PIPE_CLEAR_* values.
390 * \param color pointer to a union of fiu array for each of r, g, b, a.
391 * \param depth depth clear value in [0,1].
392 * \param stencil stencil clear value
393 */
394 void (*clear)(struct pipe_context *pipe,
395 unsigned buffers,
396 const union pipe_color_union *color,
397 double depth,
398 unsigned stencil);
399
400 /**
401 * Clear a color rendertarget surface.
402 * \param color pointer to an union of fiu array for each of r, g, b, a.
403 */
404 void (*clear_render_target)(struct pipe_context *pipe,
405 struct pipe_surface *dst,
406 const union pipe_color_union *color,
407 unsigned dstx, unsigned dsty,
408 unsigned width, unsigned height);
409
410 /**
411 * Clear a depth-stencil surface.
412 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
413 * \param depth depth clear value in [0,1].
414 * \param stencil stencil clear value
415 */
416 void (*clear_depth_stencil)(struct pipe_context *pipe,
417 struct pipe_surface *dst,
418 unsigned clear_flags,
419 double depth,
420 unsigned stencil,
421 unsigned dstx, unsigned dsty,
422 unsigned width, unsigned height);
423
424 /**
425 * Clear the texture with the specified texel. Not guaranteed to be a
426 * renderable format. Data provided in the resource's format.
427 */
428 void (*clear_texture)(struct pipe_context *pipe,
429 struct pipe_resource *res,
430 unsigned level,
431 const struct pipe_box *box,
432 const void *data);
433
434 /**
435 * Clear a buffer. Runs a memset over the specified region with the element
436 * value passed in through clear_value of size clear_value_size.
437 */
438 void (*clear_buffer)(struct pipe_context *pipe,
439 struct pipe_resource *res,
440 unsigned offset,
441 unsigned size,
442 const void *clear_value,
443 int clear_value_size);
444
445 /**
446 * Flush draw commands
447 *
448 * NOTE: use screen->fence_reference() (or equivalent) to transfer
449 * new fence ref to **fence, to ensure that previous fence is unref'd
450 *
451 * \param fence if not NULL, an old fence to unref and transfer a
452 * new fence reference to
453 * \param flags bitfield of enum pipe_flush_flags values.
454 */
455 void (*flush)(struct pipe_context *pipe,
456 struct pipe_fence_handle **fence,
457 unsigned flags);
458
459 /**
460 * Create a view on a texture to be used by a shader stage.
461 */
462 struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
463 struct pipe_resource *texture,
464 const struct pipe_sampler_view *templat);
465
466 void (*sampler_view_destroy)(struct pipe_context *ctx,
467 struct pipe_sampler_view *view);
468
469
470 /**
471 * Get a surface which is a "view" into a resource, used by
472 * render target / depth stencil stages.
473 */
474 struct pipe_surface *(*create_surface)(struct pipe_context *ctx,
475 struct pipe_resource *resource,
476 const struct pipe_surface *templat);
477
478 void (*surface_destroy)(struct pipe_context *ctx,
479 struct pipe_surface *);
480
481
482 /**
483 * Map a resource.
484 *
485 * Transfers are (by default) context-private and allow uploads to be
486 * interleaved with rendering.
487 *
488 * out_transfer will contain the transfer object that must be passed
489 * to all the other transfer functions. It also contains useful
490 * information (like texture strides).
491 */
492 void *(*transfer_map)(struct pipe_context *,
493 struct pipe_resource *resource,
494 unsigned level,
495 unsigned usage, /* a combination of PIPE_TRANSFER_x */
496 const struct pipe_box *,
497 struct pipe_transfer **out_transfer);
498
499 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
500 * regions specified with this call are guaranteed to be written to
501 * the resource.
502 */
503 void (*transfer_flush_region)( struct pipe_context *,
504 struct pipe_transfer *transfer,
505 const struct pipe_box *);
506
507 void (*transfer_unmap)(struct pipe_context *,
508 struct pipe_transfer *transfer);
509
510 /* One-shot transfer operation with data supplied in a user
511 * pointer. XXX: strides??
512 */
513 void (*transfer_inline_write)( struct pipe_context *,
514 struct pipe_resource *,
515 unsigned level,
516 unsigned usage, /* a combination of PIPE_TRANSFER_x */
517 const struct pipe_box *,
518 const void *data,
519 unsigned stride,
520 unsigned layer_stride);
521
522 /**
523 * Flush any pending framebuffer writes and invalidate texture caches.
524 */
525 void (*texture_barrier)(struct pipe_context *);
526
527 /**
528 * Flush caches according to flags.
529 */
530 void (*memory_barrier)(struct pipe_context *, unsigned flags);
531
532 /**
533 * Creates a video codec for a specific video format/profile
534 */
535 struct pipe_video_codec *(*create_video_codec)( struct pipe_context *context,
536 const struct pipe_video_codec *templat );
537
538 /**
539 * Creates a video buffer as decoding target
540 */
541 struct pipe_video_buffer *(*create_video_buffer)( struct pipe_context *context,
542 const struct pipe_video_buffer *templat );
543
544 /**
545 * Compute kernel execution
546 */
547 /*@{*/
548 /**
549 * Define the compute program and parameters to be used by
550 * pipe_context::launch_grid.
551 */
552 void *(*create_compute_state)(struct pipe_context *context,
553 const struct pipe_compute_state *);
554 void (*bind_compute_state)(struct pipe_context *, void *);
555 void (*delete_compute_state)(struct pipe_context *, void *);
556
557 /**
558 * Bind an array of shader resources that will be used by the
559 * compute program. Any resources that were previously bound to
560 * the specified range will be unbound after this call.
561 *
562 * \param start first resource to bind.
563 * \param count number of consecutive resources to bind.
564 * \param resources array of pointers to the resources to bind, it
565 * should contain at least \a count elements
566 * unless it's NULL, in which case no new
567 * resources will be bound.
568 */
569 void (*set_compute_resources)(struct pipe_context *,
570 unsigned start, unsigned count,
571 struct pipe_surface **resources);
572
573 /**
574 * Bind an array of buffers to be mapped into the address space of
575 * the GLOBAL resource. Any buffers that were previously bound
576 * between [first, first + count - 1] are unbound after this call.
577 *
578 * \param first first buffer to map.
579 * \param count number of consecutive buffers to map.
580 * \param resources array of pointers to the buffers to map, it
581 * should contain at least \a count elements
582 * unless it's NULL, in which case no new
583 * resources will be bound.
584 * \param handles array of pointers to the memory locations that
585 * will be updated with the address each buffer
586 * will be mapped to. The base memory address of
587 * each of the buffers will be added to the value
588 * pointed to by its corresponding handle to form
589 * the final address argument. It should contain
590 * at least \a count elements, unless \a
591 * resources is NULL in which case \a handles
592 * should be NULL as well.
593 *
594 * Note that the driver isn't required to make any guarantees about
595 * the contents of the \a handles array being valid anytime except
596 * during the subsequent calls to pipe_context::launch_grid. This
597 * means that the only sensible location handles[i] may point to is
598 * somewhere within the INPUT buffer itself. This is so to
599 * accommodate implementations that lack virtual memory but
600 * nevertheless migrate buffers on the fly, leading to resource
601 * base addresses that change on each kernel invocation or are
602 * unknown to the pipe driver.
603 */
604 void (*set_global_binding)(struct pipe_context *context,
605 unsigned first, unsigned count,
606 struct pipe_resource **resources,
607 uint32_t **handles);
608
609 /**
610 * Launch the compute kernel starting from instruction \a pc of the
611 * currently bound compute program.
612 */
613 void (*launch_grid)(struct pipe_context *context,
614 const struct pipe_grid_info *info);
615 /*@}*/
616
617 /**
618 * Get sample position for an individual sample point.
619 *
620 * \param sample_count - total number of samples
621 * \param sample_index - sample to get the position values for
622 * \param out_value - return value of 2 floats for x and y position for
623 * requested sample.
624 */
625 void (*get_sample_position)(struct pipe_context *context,
626 unsigned sample_count,
627 unsigned sample_index,
628 float *out_value);
629
630 /**
631 * Query a timestamp in nanoseconds. This is completely equivalent to
632 * pipe_screen::get_timestamp() but takes a context handle for drivers
633 * that require a context.
634 */
635 uint64_t (*get_timestamp)(struct pipe_context *);
636
637 /**
638 * Flush the resource cache, so that the resource can be used
639 * by an external client. Possible usage:
640 * - flushing a resource before presenting it on the screen
641 * - flushing a resource if some other process or device wants to use it
642 * This shouldn't be used to flush caches if the resource is only managed
643 * by a single pipe_screen and is not shared with another process.
644 * (i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
645 * use the resource for texturing)
646 */
647 void (*flush_resource)(struct pipe_context *ctx,
648 struct pipe_resource *resource);
649
650 /**
651 * Invalidate the contents of the resource. This is used to
652 *
653 * (1) implement EGL's semantic of undefined depth/stencil
654 * contenst after a swapbuffers. This allows a tiled renderer (for
655 * example) to not store the depth buffer.
656 *
657 * (2) implement GL's InvalidateBufferData. For backwards compatibility,
658 * you must only rely on the usability for this purpose when
659 * PIPE_CAP_INVALIDATE_BUFFER is enabled.
660 */
661 void (*invalidate_resource)(struct pipe_context *ctx,
662 struct pipe_resource *resource);
663
664 /**
665 * Return information about unexpected device resets.
666 */
667 enum pipe_reset_status (*get_device_reset_status)(struct pipe_context *ctx);
668
669 /**
670 * Dump driver-specific debug information into a stream. This is
671 * used by debugging tools.
672 *
673 * \param ctx pipe context
674 * \param stream where the output should be written to
675 * \param flags a mask of PIPE_DEBUG_* flags
676 */
677 void (*dump_debug_state)(struct pipe_context *ctx, FILE *stream,
678 unsigned flags);
679
680 /**
681 * Emit string marker in cmdstream
682 */
683 void (*emit_string_marker)(struct pipe_context *ctx,
684 const char *string,
685 int len);
686
687 /**
688 * Generate mipmap.
689 * \return TRUE if mipmap generation succeeds, FALSE otherwise
690 */
691 boolean (*generate_mipmap)(struct pipe_context *ctx,
692 struct pipe_resource *resource,
693 enum pipe_format format,
694 unsigned base_level,
695 unsigned last_level,
696 unsigned first_layer,
697 unsigned last_layer);
698 };
699
700
701 #ifdef __cplusplus
702 }
703 #endif
704
705 #endif /* PIPE_CONTEXT_H */