gallium: fix type of flags in pipe_context::flush()
[mesa.git] / src / gallium / include / pipe / p_context.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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_decoder;
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 mode one of PIPE_RENDER_COND_x
100 */
101 void (*render_condition)( struct pipe_context *pipe,
102 struct pipe_query *query,
103 uint mode );
104
105 /**
106 * Query objects
107 */
108 /*@{*/
109 struct pipe_query *(*create_query)( struct pipe_context *pipe,
110 unsigned query_type );
111
112 void (*destroy_query)(struct pipe_context *pipe,
113 struct pipe_query *q);
114
115 void (*begin_query)(struct pipe_context *pipe, struct pipe_query *q);
116 void (*end_query)(struct pipe_context *pipe, struct pipe_query *q);
117
118 /**
119 * Get results of a query.
120 * \param wait if true, this query will block until the result is ready
121 * \return TRUE if results are ready, FALSE otherwise
122 */
123 boolean (*get_query_result)(struct pipe_context *pipe,
124 struct pipe_query *q,
125 boolean wait,
126 union pipe_query_result *result);
127 /*@}*/
128
129 /**
130 * State functions (create/bind/destroy state objects)
131 */
132 /*@{*/
133 void * (*create_blend_state)(struct pipe_context *,
134 const struct pipe_blend_state *);
135 void (*bind_blend_state)(struct pipe_context *, void *);
136 void (*delete_blend_state)(struct pipe_context *, void *);
137
138 void * (*create_sampler_state)(struct pipe_context *,
139 const struct pipe_sampler_state *);
140 void (*bind_fragment_sampler_states)(struct pipe_context *,
141 unsigned num_samplers,
142 void **samplers);
143 void (*bind_vertex_sampler_states)(struct pipe_context *,
144 unsigned num_samplers,
145 void **samplers);
146 void (*bind_geometry_sampler_states)(struct pipe_context *,
147 unsigned num_samplers,
148 void **samplers);
149 void (*bind_compute_sampler_states)(struct pipe_context *,
150 unsigned start_slot,
151 unsigned num_samplers,
152 void **samplers);
153 void (*delete_sampler_state)(struct pipe_context *, void *);
154
155 void * (*create_rasterizer_state)(struct pipe_context *,
156 const struct pipe_rasterizer_state *);
157 void (*bind_rasterizer_state)(struct pipe_context *, void *);
158 void (*delete_rasterizer_state)(struct pipe_context *, void *);
159
160 void * (*create_depth_stencil_alpha_state)(struct pipe_context *,
161 const struct pipe_depth_stencil_alpha_state *);
162 void (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *);
163 void (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *);
164
165 void * (*create_fs_state)(struct pipe_context *,
166 const struct pipe_shader_state *);
167 void (*bind_fs_state)(struct pipe_context *, void *);
168 void (*delete_fs_state)(struct pipe_context *, void *);
169
170 void * (*create_vs_state)(struct pipe_context *,
171 const struct pipe_shader_state *);
172 void (*bind_vs_state)(struct pipe_context *, void *);
173 void (*delete_vs_state)(struct pipe_context *, void *);
174
175 void * (*create_gs_state)(struct pipe_context *,
176 const struct pipe_shader_state *);
177 void (*bind_gs_state)(struct pipe_context *, void *);
178 void (*delete_gs_state)(struct pipe_context *, void *);
179
180 void * (*create_vertex_elements_state)(struct pipe_context *,
181 unsigned num_elements,
182 const struct pipe_vertex_element *);
183 void (*bind_vertex_elements_state)(struct pipe_context *, void *);
184 void (*delete_vertex_elements_state)(struct pipe_context *, void *);
185
186 /*@}*/
187
188 /**
189 * Parameter-like state (or properties)
190 */
191 /*@{*/
192 void (*set_blend_color)( struct pipe_context *,
193 const struct pipe_blend_color * );
194
195 void (*set_stencil_ref)( struct pipe_context *,
196 const struct pipe_stencil_ref * );
197
198 void (*set_sample_mask)( struct pipe_context *,
199 unsigned sample_mask );
200
201 void (*set_clip_state)( struct pipe_context *,
202 const struct pipe_clip_state * );
203
204 void (*set_constant_buffer)( struct pipe_context *,
205 uint shader, uint index,
206 struct pipe_constant_buffer *buf );
207
208 void (*set_framebuffer_state)( struct pipe_context *,
209 const struct pipe_framebuffer_state * );
210
211 void (*set_polygon_stipple)( struct pipe_context *,
212 const struct pipe_poly_stipple * );
213
214 void (*set_scissor_state)( struct pipe_context *,
215 const struct pipe_scissor_state * );
216
217 void (*set_viewport_state)( struct pipe_context *,
218 const struct pipe_viewport_state * );
219
220 void (*set_fragment_sampler_views)(struct pipe_context *,
221 unsigned num_views,
222 struct pipe_sampler_view **);
223
224 void (*set_vertex_sampler_views)(struct pipe_context *,
225 unsigned num_views,
226 struct pipe_sampler_view **);
227
228 void (*set_geometry_sampler_views)(struct pipe_context *,
229 unsigned num_views,
230 struct pipe_sampler_view **);
231
232 void (*set_compute_sampler_views)(struct pipe_context *,
233 unsigned start_slot, unsigned num_views,
234 struct pipe_sampler_view **);
235
236 /**
237 * Bind an array of shader resources that will be used by the
238 * graphics pipeline. Any resources that were previously bound to
239 * the specified range will be unbound after this call.
240 *
241 * \param start first resource to bind.
242 * \param count number of consecutive resources to bind.
243 * \param resources array of pointers to the resources to bind, it
244 * should contain at least \a count elements
245 * unless it's NULL, in which case no new
246 * resources will be bound.
247 */
248 void (*set_shader_resources)(struct pipe_context *,
249 unsigned start, unsigned count,
250 struct pipe_surface **resources);
251
252 void (*set_vertex_buffers)( struct pipe_context *,
253 unsigned start_slot,
254 unsigned num_buffers,
255 const struct pipe_vertex_buffer * );
256
257 void (*set_index_buffer)( struct pipe_context *pipe,
258 const struct pipe_index_buffer * );
259
260 /*@}*/
261
262 /**
263 * Stream output functions.
264 */
265 /*@{*/
266
267 struct pipe_stream_output_target *(*create_stream_output_target)(
268 struct pipe_context *,
269 struct pipe_resource *,
270 unsigned buffer_offset,
271 unsigned buffer_size);
272
273 void (*stream_output_target_destroy)(struct pipe_context *,
274 struct pipe_stream_output_target *);
275
276 void (*set_stream_output_targets)(struct pipe_context *,
277 unsigned num_targets,
278 struct pipe_stream_output_target **targets,
279 unsigned append_bitmask);
280
281 /*@}*/
282
283
284 /**
285 * Resource functions for blit-like functionality
286 *
287 * If a driver supports multisampling, blit must implement color resolve.
288 */
289 /*@{*/
290
291 /**
292 * Copy a block of pixels from one resource to another.
293 * The resource must be of the same format.
294 * Resources with nr_samples > 1 are not allowed.
295 */
296 void (*resource_copy_region)(struct pipe_context *pipe,
297 struct pipe_resource *dst,
298 unsigned dst_level,
299 unsigned dstx, unsigned dsty, unsigned dstz,
300 struct pipe_resource *src,
301 unsigned src_level,
302 const struct pipe_box *src_box);
303
304 /* Optimal hardware path for blitting pixels.
305 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
306 */
307 void (*blit)(struct pipe_context *pipe,
308 const struct pipe_blit_info *info);
309
310 /*@}*/
311
312 /**
313 * Clear the specified set of currently bound buffers to specified values.
314 * The entire buffers are cleared (no scissor, no colormask, etc).
315 *
316 * \param buffers bitfield of PIPE_CLEAR_* values.
317 * \param color pointer to a union of fiu array for each of r, g, b, a.
318 * \param depth depth clear value in [0,1].
319 * \param stencil stencil clear value
320 */
321 void (*clear)(struct pipe_context *pipe,
322 unsigned buffers,
323 const union pipe_color_union *color,
324 double depth,
325 unsigned stencil);
326
327 /**
328 * Clear a color rendertarget surface.
329 * \param color pointer to an union of fiu array for each of r, g, b, a.
330 */
331 void (*clear_render_target)(struct pipe_context *pipe,
332 struct pipe_surface *dst,
333 const union pipe_color_union *color,
334 unsigned dstx, unsigned dsty,
335 unsigned width, unsigned height);
336
337 /**
338 * Clear a depth-stencil surface.
339 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
340 * \param depth depth clear value in [0,1].
341 * \param stencil stencil clear value
342 */
343 void (*clear_depth_stencil)(struct pipe_context *pipe,
344 struct pipe_surface *dst,
345 unsigned clear_flags,
346 double depth,
347 unsigned stencil,
348 unsigned dstx, unsigned dsty,
349 unsigned width, unsigned height);
350
351 /** Flush draw commands
352 *
353 * \param flags bitfield of enum pipe_flush_flags values.
354 */
355 void (*flush)(struct pipe_context *pipe,
356 struct pipe_fence_handle **fence,
357 unsigned flags);
358
359 /**
360 * Create a view on a texture to be used by a shader stage.
361 */
362 struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
363 struct pipe_resource *texture,
364 const struct pipe_sampler_view *templat);
365
366 void (*sampler_view_destroy)(struct pipe_context *ctx,
367 struct pipe_sampler_view *view);
368
369
370 /**
371 * Get a surface which is a "view" into a resource, used by
372 * render target / depth stencil stages.
373 */
374 struct pipe_surface *(*create_surface)(struct pipe_context *ctx,
375 struct pipe_resource *resource,
376 const struct pipe_surface *templat);
377
378 void (*surface_destroy)(struct pipe_context *ctx,
379 struct pipe_surface *);
380
381 /**
382 * Map a resource.
383 *
384 * Transfers are (by default) context-private and allow uploads to be
385 * interleaved with rendering.
386 *
387 * out_transfer will contain the transfer object that must be passed
388 * to all the other transfer functions. It also contains useful
389 * information (like texture strides).
390 */
391 void *(*transfer_map)(struct pipe_context *,
392 struct pipe_resource *resource,
393 unsigned level,
394 unsigned usage, /* a combination of PIPE_TRANSFER_x */
395 const struct pipe_box *,
396 struct pipe_transfer **out_transfer);
397
398 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
399 * regions specified with this call are guaranteed to be written to
400 * the resource.
401 */
402 void (*transfer_flush_region)( struct pipe_context *,
403 struct pipe_transfer *transfer,
404 const struct pipe_box *);
405
406 void (*transfer_unmap)(struct pipe_context *,
407 struct pipe_transfer *transfer);
408
409 /* One-shot transfer operation with data supplied in a user
410 * pointer. XXX: strides??
411 */
412 void (*transfer_inline_write)( struct pipe_context *,
413 struct pipe_resource *,
414 unsigned level,
415 unsigned usage, /* a combination of PIPE_TRANSFER_x */
416 const struct pipe_box *,
417 const void *data,
418 unsigned stride,
419 unsigned layer_stride);
420
421 /**
422 * Flush any pending framebuffer writes and invalidate texture caches.
423 */
424 void (*texture_barrier)(struct pipe_context *);
425
426 /**
427 * Creates a video decoder for a specific video codec/profile
428 */
429 struct pipe_video_decoder *(*create_video_decoder)( struct pipe_context *context,
430 enum pipe_video_profile profile,
431 enum pipe_video_entrypoint entrypoint,
432 enum pipe_video_chroma_format chroma_format,
433 unsigned width, unsigned height, unsigned max_references,
434 bool expect_chunked_decode);
435
436 /**
437 * Creates a video buffer as decoding target
438 */
439 struct pipe_video_buffer *(*create_video_buffer)( struct pipe_context *context,
440 const struct pipe_video_buffer *templat );
441
442 /**
443 * Compute kernel execution
444 */
445 /*@{*/
446 /**
447 * Define the compute program and parameters to be used by
448 * pipe_context::launch_grid.
449 */
450 void *(*create_compute_state)(struct pipe_context *context,
451 const struct pipe_compute_state *);
452 void (*bind_compute_state)(struct pipe_context *, void *);
453 void (*delete_compute_state)(struct pipe_context *, void *);
454
455 /**
456 * Bind an array of shader resources that will be used by the
457 * compute program. Any resources that were previously bound to
458 * the specified range will be unbound after this call.
459 *
460 * \param start first resource to bind.
461 * \param count number of consecutive resources to bind.
462 * \param resources array of pointers to the resources to bind, it
463 * should contain at least \a count elements
464 * unless it's NULL, in which case no new
465 * resources will be bound.
466 */
467 void (*set_compute_resources)(struct pipe_context *,
468 unsigned start, unsigned count,
469 struct pipe_surface **resources);
470
471 /**
472 * Bind an array of buffers to be mapped into the address space of
473 * the GLOBAL resource. Any buffers that were previously bound
474 * between [first, first + count - 1] are unbound after this call.
475 *
476 * \param first first buffer to map.
477 * \param count number of consecutive buffers to map.
478 * \param resources array of pointers to the buffers to map, it
479 * should contain at least \a count elements
480 * unless it's NULL, in which case no new
481 * resources will be bound.
482 * \param handles array of pointers to the memory locations that
483 * will be filled with the respective base
484 * addresses each buffer will be mapped to. It
485 * should contain at least \a count elements,
486 * unless \a resources is NULL in which case \a
487 * handles should be NULL as well.
488 *
489 * Note that the driver isn't required to make any guarantees about
490 * the contents of the \a handles array being valid anytime except
491 * during the subsequent calls to pipe_context::launch_grid. This
492 * means that the only sensible location handles[i] may point to is
493 * somewhere within the INPUT buffer itself. This is so to
494 * accommodate implementations that lack virtual memory but
495 * nevertheless migrate buffers on the fly, leading to resource
496 * base addresses that change on each kernel invocation or are
497 * unknown to the pipe driver.
498 */
499 void (*set_global_binding)(struct pipe_context *context,
500 unsigned first, unsigned count,
501 struct pipe_resource **resources,
502 uint32_t **handles);
503
504 /**
505 * Launch the compute kernel starting from instruction \a pc of the
506 * currently bound compute program.
507 *
508 * \a grid_layout and \a block_layout are arrays of size \a
509 * PIPE_COMPUTE_CAP_GRID_DIMENSION that determine the layout of the
510 * grid (in block units) and working block (in thread units) to be
511 * used, respectively.
512 *
513 * \a pc For drivers that use PIPE_SHADER_IR_LLVM as their prefered IR,
514 * this value will be the index of the kernel in the opencl.kernels
515 * metadata list.
516 *
517 * \a input will be used to initialize the INPUT resource, and it
518 * should point to a buffer of at least
519 * pipe_compute_state::req_input_mem bytes.
520 */
521 void (*launch_grid)(struct pipe_context *context,
522 const uint *block_layout, const uint *grid_layout,
523 uint32_t pc, const void *input);
524 /*@}*/
525
526 /**
527 * Get sample position for an individual sample point.
528 *
529 * \param sample_count - total number of samples
530 * \param sample_index - sample to get the position values for
531 * \param out_value - return value of 2 floats for x and y position for
532 * requested sample.
533 */
534 void (*get_sample_position)(struct pipe_context *context,
535 unsigned sample_count,
536 unsigned sample_index,
537 float *out_value);
538 };
539
540
541 #ifdef __cplusplus
542 }
543 #endif
544
545 #endif /* PIPE_CONTEXT_H */