Merge branch 'wip/nir-vtn' 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
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40
41 struct pipe_blend_color;
42 struct pipe_blend_state;
43 struct pipe_blit_info;
44 struct pipe_box;
45 struct pipe_clip_state;
46 struct pipe_constant_buffer;
47 struct pipe_depth_stencil_alpha_state;
48 struct pipe_draw_info;
49 struct pipe_fence_handle;
50 struct pipe_framebuffer_state;
51 struct pipe_index_buffer;
52 struct pipe_query;
53 struct pipe_poly_stipple;
54 struct pipe_rasterizer_state;
55 struct pipe_resolve_info;
56 struct pipe_resource;
57 struct pipe_sampler_state;
58 struct pipe_sampler_view;
59 struct pipe_scissor_state;
60 struct pipe_shader_state;
61 struct pipe_stencil_ref;
62 struct pipe_stream_output_target;
63 struct pipe_surface;
64 struct pipe_transfer;
65 struct pipe_vertex_buffer;
66 struct pipe_vertex_element;
67 struct pipe_video_buffer;
68 struct pipe_video_codec;
69 struct pipe_viewport_state;
70 struct pipe_compute_state;
71 union pipe_color_union;
72 union pipe_query_result;
73
74 /**
75 * Gallium rendering context. Basically:
76 * - state setting functions
77 * - VBO drawing functions
78 * - surface functions
79 */
80 struct pipe_context {
81 struct pipe_screen *screen;
82
83 void *priv; /**< context private data (for DRI for example) */
84 void *draw; /**< private, for draw module (temporary?) */
85
86 void (*destroy)( struct pipe_context * );
87
88 /**
89 * VBO drawing
90 */
91 /*@{*/
92 void (*draw_vbo)( struct pipe_context *pipe,
93 const struct pipe_draw_info *info );
94 /*@}*/
95
96 /**
97 * Predicate subsequent rendering on occlusion query result
98 * \param query the query predicate, or NULL if no predicate
99 * \param condition whether to skip on FALSE or TRUE query results
100 * \param mode one of PIPE_RENDER_COND_x
101 */
102 void (*render_condition)( struct pipe_context *pipe,
103 struct pipe_query *query,
104 boolean condition,
105 uint mode );
106
107 /**
108 * Query objects
109 */
110 /*@{*/
111 struct pipe_query *(*create_query)( struct pipe_context *pipe,
112 unsigned query_type,
113 unsigned index );
114
115 void (*destroy_query)(struct pipe_context *pipe,
116 struct pipe_query *q);
117
118 boolean (*begin_query)(struct pipe_context *pipe, struct pipe_query *q);
119 void (*end_query)(struct pipe_context *pipe, struct pipe_query *q);
120
121 /**
122 * Get results of a query.
123 * \param wait if true, this query will block until the result is ready
124 * \return TRUE if results are ready, FALSE otherwise
125 */
126 boolean (*get_query_result)(struct pipe_context *pipe,
127 struct pipe_query *q,
128 boolean wait,
129 union pipe_query_result *result);
130 /*@}*/
131
132 /**
133 * State functions (create/bind/destroy state objects)
134 */
135 /*@{*/
136 void * (*create_blend_state)(struct pipe_context *,
137 const struct pipe_blend_state *);
138 void (*bind_blend_state)(struct pipe_context *, void *);
139 void (*delete_blend_state)(struct pipe_context *, void *);
140
141 void * (*create_sampler_state)(struct pipe_context *,
142 const struct pipe_sampler_state *);
143 void (*bind_sampler_states)(struct pipe_context *,
144 unsigned shader, unsigned start_slot,
145 unsigned num_samplers, void **samplers);
146 void (*delete_sampler_state)(struct pipe_context *, void *);
147
148 void * (*create_rasterizer_state)(struct pipe_context *,
149 const struct pipe_rasterizer_state *);
150 void (*bind_rasterizer_state)(struct pipe_context *, void *);
151 void (*delete_rasterizer_state)(struct pipe_context *, void *);
152
153 void * (*create_depth_stencil_alpha_state)(struct pipe_context *,
154 const struct pipe_depth_stencil_alpha_state *);
155 void (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *);
156 void (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *);
157
158 void * (*create_fs_state)(struct pipe_context *,
159 const struct pipe_shader_state *);
160 void (*bind_fs_state)(struct pipe_context *, void *);
161 void (*delete_fs_state)(struct pipe_context *, void *);
162
163 void * (*create_vs_state)(struct pipe_context *,
164 const struct pipe_shader_state *);
165 void (*bind_vs_state)(struct pipe_context *, void *);
166 void (*delete_vs_state)(struct pipe_context *, void *);
167
168 void * (*create_gs_state)(struct pipe_context *,
169 const struct pipe_shader_state *);
170 void (*bind_gs_state)(struct pipe_context *, void *);
171 void (*delete_gs_state)(struct pipe_context *, void *);
172
173 void * (*create_tcs_state)(struct pipe_context *,
174 const struct pipe_shader_state *);
175 void (*bind_tcs_state)(struct pipe_context *, void *);
176 void (*delete_tcs_state)(struct pipe_context *, void *);
177
178 void * (*create_tes_state)(struct pipe_context *,
179 const struct pipe_shader_state *);
180 void (*bind_tes_state)(struct pipe_context *, void *);
181 void (*delete_tes_state)(struct pipe_context *, void *);
182
183 void * (*create_vertex_elements_state)(struct pipe_context *,
184 unsigned num_elements,
185 const struct pipe_vertex_element *);
186 void (*bind_vertex_elements_state)(struct pipe_context *, void *);
187 void (*delete_vertex_elements_state)(struct pipe_context *, void *);
188
189 /*@}*/
190
191 /**
192 * Parameter-like state (or properties)
193 */
194 /*@{*/
195 void (*set_blend_color)( struct pipe_context *,
196 const struct pipe_blend_color * );
197
198 void (*set_stencil_ref)( struct pipe_context *,
199 const struct pipe_stencil_ref * );
200
201 void (*set_sample_mask)( struct pipe_context *,
202 unsigned sample_mask );
203
204 void (*set_min_samples)( struct pipe_context *,
205 unsigned min_samples );
206
207 void (*set_clip_state)( struct pipe_context *,
208 const struct pipe_clip_state * );
209
210 void (*set_constant_buffer)( struct pipe_context *,
211 uint shader, uint index,
212 struct pipe_constant_buffer *buf );
213
214 void (*set_framebuffer_state)( struct pipe_context *,
215 const struct pipe_framebuffer_state * );
216
217 void (*set_polygon_stipple)( struct pipe_context *,
218 const struct pipe_poly_stipple * );
219
220 void (*set_scissor_states)( struct pipe_context *,
221 unsigned start_slot,
222 unsigned num_scissors,
223 const struct pipe_scissor_state * );
224
225 void (*set_viewport_states)( struct pipe_context *,
226 unsigned start_slot,
227 unsigned num_viewports,
228 const struct pipe_viewport_state *);
229
230 void (*set_sampler_views)(struct pipe_context *, unsigned shader,
231 unsigned start_slot, unsigned num_views,
232 struct pipe_sampler_view **);
233
234 void (*set_tess_state)(struct pipe_context *,
235 const float default_outer_level[4],
236 const float default_inner_level[2]);
237
238 /**
239 * Bind an array of shader resources that will be used by the
240 * graphics pipeline. Any resources that were previously bound to
241 * the specified range will be unbound after this call.
242 *
243 * \param start first resource to bind.
244 * \param count number of consecutive resources to bind.
245 * \param resources array of pointers to the resources to bind, it
246 * should contain at least \a count elements
247 * unless it's NULL, in which case no new
248 * resources will be bound.
249 */
250 void (*set_shader_resources)(struct pipe_context *,
251 unsigned start, unsigned count,
252 struct pipe_surface **resources);
253
254 void (*set_vertex_buffers)( struct pipe_context *,
255 unsigned start_slot,
256 unsigned num_buffers,
257 const struct pipe_vertex_buffer * );
258
259 void (*set_index_buffer)( struct pipe_context *pipe,
260 const struct pipe_index_buffer * );
261
262 /*@}*/
263
264 /**
265 * Stream output functions.
266 */
267 /*@{*/
268
269 struct pipe_stream_output_target *(*create_stream_output_target)(
270 struct pipe_context *,
271 struct pipe_resource *,
272 unsigned buffer_offset,
273 unsigned buffer_size);
274
275 void (*stream_output_target_destroy)(struct pipe_context *,
276 struct pipe_stream_output_target *);
277
278 void (*set_stream_output_targets)(struct pipe_context *,
279 unsigned num_targets,
280 struct pipe_stream_output_target **targets,
281 const unsigned *offsets);
282
283 /*@}*/
284
285
286 /**
287 * Resource functions for blit-like functionality
288 *
289 * If a driver supports multisampling, blit must implement color resolve.
290 */
291 /*@{*/
292
293 /**
294 * Copy a block of pixels from one resource to another.
295 * The resource must be of the same format.
296 * Resources with nr_samples > 1 are not allowed.
297 */
298 void (*resource_copy_region)(struct pipe_context *pipe,
299 struct pipe_resource *dst,
300 unsigned dst_level,
301 unsigned dstx, unsigned dsty, unsigned dstz,
302 struct pipe_resource *src,
303 unsigned src_level,
304 const struct pipe_box *src_box);
305
306 /* Optimal hardware path for blitting pixels.
307 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
308 */
309 void (*blit)(struct pipe_context *pipe,
310 const struct pipe_blit_info *info);
311
312 /*@}*/
313
314 /**
315 * Clear the specified set of currently bound buffers to specified values.
316 * The entire buffers are cleared (no scissor, no colormask, etc).
317 *
318 * \param buffers bitfield of PIPE_CLEAR_* values.
319 * \param color pointer to a union of fiu array for each of r, g, b, a.
320 * \param depth depth clear value in [0,1].
321 * \param stencil stencil clear value
322 */
323 void (*clear)(struct pipe_context *pipe,
324 unsigned buffers,
325 const union pipe_color_union *color,
326 double depth,
327 unsigned stencil);
328
329 /**
330 * Clear a color rendertarget surface.
331 * \param color pointer to an union of fiu array for each of r, g, b, a.
332 */
333 void (*clear_render_target)(struct pipe_context *pipe,
334 struct pipe_surface *dst,
335 const union pipe_color_union *color,
336 unsigned dstx, unsigned dsty,
337 unsigned width, unsigned height);
338
339 /**
340 * Clear a depth-stencil surface.
341 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
342 * \param depth depth clear value in [0,1].
343 * \param stencil stencil clear value
344 */
345 void (*clear_depth_stencil)(struct pipe_context *pipe,
346 struct pipe_surface *dst,
347 unsigned clear_flags,
348 double depth,
349 unsigned stencil,
350 unsigned dstx, unsigned dsty,
351 unsigned width, unsigned height);
352
353 /**
354 * Clear a buffer. Runs a memset over the specified region with the element
355 * value passed in through clear_value of size clear_value_size.
356 */
357 void (*clear_buffer)(struct pipe_context *pipe,
358 struct pipe_resource *res,
359 unsigned offset,
360 unsigned size,
361 const void *clear_value,
362 int clear_value_size);
363
364 /** Flush draw commands
365 *
366 * \param flags bitfield of enum pipe_flush_flags values.
367 */
368 void (*flush)(struct pipe_context *pipe,
369 struct pipe_fence_handle **fence,
370 unsigned flags);
371
372 /**
373 * Create a view on a texture to be used by a shader stage.
374 */
375 struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
376 struct pipe_resource *texture,
377 const struct pipe_sampler_view *templat);
378
379 void (*sampler_view_destroy)(struct pipe_context *ctx,
380 struct pipe_sampler_view *view);
381
382
383 /**
384 * Get a surface which is a "view" into a resource, used by
385 * render target / depth stencil stages.
386 */
387 struct pipe_surface *(*create_surface)(struct pipe_context *ctx,
388 struct pipe_resource *resource,
389 const struct pipe_surface *templat);
390
391 void (*surface_destroy)(struct pipe_context *ctx,
392 struct pipe_surface *);
393
394 /**
395 * Map a resource.
396 *
397 * Transfers are (by default) context-private and allow uploads to be
398 * interleaved with rendering.
399 *
400 * out_transfer will contain the transfer object that must be passed
401 * to all the other transfer functions. It also contains useful
402 * information (like texture strides).
403 */
404 void *(*transfer_map)(struct pipe_context *,
405 struct pipe_resource *resource,
406 unsigned level,
407 unsigned usage, /* a combination of PIPE_TRANSFER_x */
408 const struct pipe_box *,
409 struct pipe_transfer **out_transfer);
410
411 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
412 * regions specified with this call are guaranteed to be written to
413 * the resource.
414 */
415 void (*transfer_flush_region)( struct pipe_context *,
416 struct pipe_transfer *transfer,
417 const struct pipe_box *);
418
419 void (*transfer_unmap)(struct pipe_context *,
420 struct pipe_transfer *transfer);
421
422 /* One-shot transfer operation with data supplied in a user
423 * pointer. XXX: strides??
424 */
425 void (*transfer_inline_write)( struct pipe_context *,
426 struct pipe_resource *,
427 unsigned level,
428 unsigned usage, /* a combination of PIPE_TRANSFER_x */
429 const struct pipe_box *,
430 const void *data,
431 unsigned stride,
432 unsigned layer_stride);
433
434 /**
435 * Flush any pending framebuffer writes and invalidate texture caches.
436 */
437 void (*texture_barrier)(struct pipe_context *);
438
439 /**
440 * Flush caches according to flags.
441 */
442 void (*memory_barrier)(struct pipe_context *, unsigned flags);
443
444 /**
445 * Creates a video codec for a specific video format/profile
446 */
447 struct pipe_video_codec *(*create_video_codec)( struct pipe_context *context,
448 const struct pipe_video_codec *templat );
449
450 /**
451 * Creates a video buffer as decoding target
452 */
453 struct pipe_video_buffer *(*create_video_buffer)( struct pipe_context *context,
454 const struct pipe_video_buffer *templat );
455
456 /**
457 * Compute kernel execution
458 */
459 /*@{*/
460 /**
461 * Define the compute program and parameters to be used by
462 * pipe_context::launch_grid.
463 */
464 void *(*create_compute_state)(struct pipe_context *context,
465 const struct pipe_compute_state *);
466 void (*bind_compute_state)(struct pipe_context *, void *);
467 void (*delete_compute_state)(struct pipe_context *, void *);
468
469 /**
470 * Bind an array of shader resources that will be used by the
471 * compute program. Any resources that were previously bound to
472 * the specified range will be unbound after this call.
473 *
474 * \param start first resource to bind.
475 * \param count number of consecutive resources to bind.
476 * \param resources array of pointers to the resources to bind, it
477 * should contain at least \a count elements
478 * unless it's NULL, in which case no new
479 * resources will be bound.
480 */
481 void (*set_compute_resources)(struct pipe_context *,
482 unsigned start, unsigned count,
483 struct pipe_surface **resources);
484
485 /**
486 * Bind an array of buffers to be mapped into the address space of
487 * the GLOBAL resource. Any buffers that were previously bound
488 * between [first, first + count - 1] are unbound after this call.
489 *
490 * \param first first buffer to map.
491 * \param count number of consecutive buffers to map.
492 * \param resources array of pointers to the buffers to map, it
493 * should contain at least \a count elements
494 * unless it's NULL, in which case no new
495 * resources will be bound.
496 * \param handles array of pointers to the memory locations that
497 * will be updated with the address each buffer
498 * will be mapped to. The base memory address of
499 * each of the buffers will be added to the value
500 * pointed to by its corresponding handle to form
501 * the final address argument. It should contain
502 * at least \a count elements, unless \a
503 * resources is NULL in which case \a handles
504 * should be NULL as well.
505 *
506 * Note that the driver isn't required to make any guarantees about
507 * the contents of the \a handles array being valid anytime except
508 * during the subsequent calls to pipe_context::launch_grid. This
509 * means that the only sensible location handles[i] may point to is
510 * somewhere within the INPUT buffer itself. This is so to
511 * accommodate implementations that lack virtual memory but
512 * nevertheless migrate buffers on the fly, leading to resource
513 * base addresses that change on each kernel invocation or are
514 * unknown to the pipe driver.
515 */
516 void (*set_global_binding)(struct pipe_context *context,
517 unsigned first, unsigned count,
518 struct pipe_resource **resources,
519 uint32_t **handles);
520
521 /**
522 * Launch the compute kernel starting from instruction \a pc of the
523 * currently bound compute program.
524 *
525 * \a grid_layout and \a block_layout are arrays of size \a
526 * PIPE_COMPUTE_CAP_GRID_DIMENSION that determine the layout of the
527 * grid (in block units) and working block (in thread units) to be
528 * used, respectively.
529 *
530 * \a pc For drivers that use PIPE_SHADER_IR_LLVM as their prefered IR,
531 * this value will be the index of the kernel in the opencl.kernels
532 * metadata list.
533 *
534 * \a input will be used to initialize the INPUT resource, and it
535 * should point to a buffer of at least
536 * pipe_compute_state::req_input_mem bytes.
537 */
538 void (*launch_grid)(struct pipe_context *context,
539 const uint *block_layout, const uint *grid_layout,
540 uint32_t pc, const void *input);
541 /*@}*/
542
543 /**
544 * Get sample position for an individual sample point.
545 *
546 * \param sample_count - total number of samples
547 * \param sample_index - sample to get the position values for
548 * \param out_value - return value of 2 floats for x and y position for
549 * requested sample.
550 */
551 void (*get_sample_position)(struct pipe_context *context,
552 unsigned sample_count,
553 unsigned sample_index,
554 float *out_value);
555
556 /**
557 * Flush the resource cache, so that the resource can be used
558 * by an external client. Possible usage:
559 * - flushing a resource before presenting it on the screen
560 * - flushing a resource if some other process or device wants to use it
561 * This shouldn't be used to flush caches if the resource is only managed
562 * by a single pipe_screen and is not shared with another process.
563 * (i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
564 * use the resource for texturing)
565 */
566 void (*flush_resource)(struct pipe_context *ctx,
567 struct pipe_resource *resource);
568
569 /**
570 * Invalidate the contents of the resource.
571 *
572 * This is used to implement EGL's semantic of undefined depth/stencil
573 * contenst after a swapbuffers. This allows a tiled renderer (for
574 * example) to not store the depth buffer.
575 */
576 void (*invalidate_resource)(struct pipe_context *ctx,
577 struct pipe_resource *resource);
578
579 /**
580 * Return information about unexpected device resets.
581 */
582 enum pipe_reset_status (*get_device_reset_status)(struct pipe_context *ctx);
583 };
584
585
586 #ifdef __cplusplus
587 }
588 #endif
589
590 #endif /* PIPE_CONTEXT_H */