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