1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef PIPE_CONTEXT_H
29 #define PIPE_CONTEXT_H
31 #include "p_compiler.h"
33 #include "p_video_enums.h"
40 struct pipe_blend_color
;
41 struct pipe_blend_state
;
42 struct pipe_blit_info
;
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
;
52 struct pipe_poly_stipple
;
53 struct pipe_rasterizer_state
;
54 struct pipe_resolve_info
;
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
;
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
;
73 * Gallium rendering context. Basically:
74 * - state setting functions
75 * - VBO drawing functions
79 struct pipe_screen
*screen
;
81 void *priv
; /**< context private data (for DRI for example) */
82 void *draw
; /**< private, for draw module (temporary?) */
84 void (*destroy
)( struct pipe_context
* );
90 void (*draw_vbo
)( struct pipe_context
*pipe
,
91 const struct pipe_draw_info
*info
);
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
99 void (*render_condition
)( struct pipe_context
*pipe
,
100 struct pipe_query
*query
,
107 struct pipe_query
*(*create_query
)( struct pipe_context
*pipe
,
108 unsigned query_type
);
110 void (*destroy_query
)(struct pipe_context
*pipe
,
111 struct pipe_query
*q
);
113 void (*begin_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
114 void (*end_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
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
121 boolean (*get_query_result
)(struct pipe_context
*pipe
,
122 struct pipe_query
*q
,
124 union pipe_query_result
*result
);
128 * State functions (create/bind/destroy state objects)
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 *);
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
,
141 void (*bind_vertex_sampler_states
)(struct pipe_context
*,
142 unsigned num_samplers
,
144 void (*bind_geometry_sampler_states
)(struct pipe_context
*,
145 unsigned num_samplers
,
147 void (*bind_compute_sampler_states
)(struct pipe_context
*,
149 unsigned num_samplers
,
151 void (*delete_sampler_state
)(struct pipe_context
*, void *);
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 *);
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 *);
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 *);
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 *);
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 *);
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 *);
187 * Parameter-like state (or properties)
190 void (*set_blend_color
)( struct pipe_context
*,
191 const struct pipe_blend_color
* );
193 void (*set_stencil_ref
)( struct pipe_context
*,
194 const struct pipe_stencil_ref
* );
196 void (*set_sample_mask
)( struct pipe_context
*,
197 unsigned sample_mask
);
199 void (*set_clip_state
)( struct pipe_context
*,
200 const struct pipe_clip_state
* );
202 void (*set_constant_buffer
)( struct pipe_context
*,
203 uint shader
, uint index
,
204 struct pipe_constant_buffer
*buf
);
206 void (*set_framebuffer_state
)( struct pipe_context
*,
207 const struct pipe_framebuffer_state
* );
209 void (*set_polygon_stipple
)( struct pipe_context
*,
210 const struct pipe_poly_stipple
* );
212 void (*set_scissor_state
)( struct pipe_context
*,
213 const struct pipe_scissor_state
* );
215 void (*set_viewport_state
)( struct pipe_context
*,
216 const struct pipe_viewport_state
* );
218 void (*set_fragment_sampler_views
)(struct pipe_context
*,
220 struct pipe_sampler_view
**);
222 void (*set_vertex_sampler_views
)(struct pipe_context
*,
224 struct pipe_sampler_view
**);
226 void (*set_geometry_sampler_views
)(struct pipe_context
*,
228 struct pipe_sampler_view
**);
230 void (*set_compute_sampler_views
)(struct pipe_context
*,
231 unsigned start_slot
, unsigned num_views
,
232 struct pipe_sampler_view
**);
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.
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.
246 void (*set_shader_resources
)(struct pipe_context
*,
247 unsigned start
, unsigned count
,
248 struct pipe_surface
**resources
);
250 void (*set_vertex_buffers
)( struct pipe_context
*,
251 unsigned num_buffers
,
252 const struct pipe_vertex_buffer
* );
254 void (*set_index_buffer
)( struct pipe_context
*pipe
,
255 const struct pipe_index_buffer
* );
260 * Stream output functions.
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
);
270 void (*stream_output_target_destroy
)(struct pipe_context
*,
271 struct pipe_stream_output_target
*);
273 void (*set_stream_output_targets
)(struct pipe_context
*,
274 unsigned num_targets
,
275 struct pipe_stream_output_target
**targets
,
276 unsigned append_bitmask
);
282 * Resource functions for blit-like functionality
284 * If a driver supports multisampling, blit must implement color resolve.
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.
293 void (*resource_copy_region
)(struct pipe_context
*pipe
,
294 struct pipe_resource
*dst
,
296 unsigned dstx
, unsigned dsty
, unsigned dstz
,
297 struct pipe_resource
*src
,
299 const struct pipe_box
*src_box
);
301 /* Optimal hardware path for blitting pixels.
302 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
304 void (*blit
)(struct pipe_context
*pipe
,
305 const struct pipe_blit_info
*info
);
310 * Clear the specified set of currently bound buffers to specified values.
311 * The entire buffers are cleared (no scissor, no colormask, etc).
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
318 void (*clear
)(struct pipe_context
*pipe
,
320 const union pipe_color_union
*color
,
325 * Clear a color rendertarget surface.
326 * \param color pointer to an union of fiu array for each of r, g, b, a.
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
);
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
340 void (*clear_depth_stencil
)(struct pipe_context
*pipe
,
341 struct pipe_surface
*dst
,
342 unsigned clear_flags
,
345 unsigned dstx
, unsigned dsty
,
346 unsigned width
, unsigned height
);
348 /** Flush draw commands
350 void (*flush
)( struct pipe_context
*pipe
,
351 struct pipe_fence_handle
**fence
);
354 * Create a view on a texture to be used by a shader stage.
356 struct pipe_sampler_view
* (*create_sampler_view
)(struct pipe_context
*ctx
,
357 struct pipe_resource
*texture
,
358 const struct pipe_sampler_view
*templat
);
360 void (*sampler_view_destroy
)(struct pipe_context
*ctx
,
361 struct pipe_sampler_view
*view
);
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
369 struct pipe_surface
*(*create_surface
)(struct pipe_context
*ctx
,
370 struct pipe_resource
*resource
,
371 const struct pipe_surface
*templat
);
373 void (*surface_destroy
)(struct pipe_context
*ctx
,
374 struct pipe_surface
*);
377 * Get a transfer object for transferring data to/from a texture.
379 * Transfers are (by default) context-private and allow uploads to be
382 struct pipe_transfer
*(*get_transfer
)(struct pipe_context
*,
383 struct pipe_resource
*resource
,
385 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
386 const struct pipe_box
*);
388 void (*transfer_destroy
)(struct pipe_context
*,
389 struct pipe_transfer
*);
391 void *(*transfer_map
)( struct pipe_context
*,
392 struct pipe_transfer
*transfer
);
394 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
395 * regions specified with this call are guaranteed to be written to
398 void (*transfer_flush_region
)( struct pipe_context
*,
399 struct pipe_transfer
*transfer
,
400 const struct pipe_box
*);
402 void (*transfer_unmap
)( struct pipe_context
*,
403 struct pipe_transfer
*transfer
);
406 /* One-shot transfer operation with data supplied in a user
407 * pointer. XXX: strides??
409 void (*transfer_inline_write
)( struct pipe_context
*,
410 struct pipe_resource
*,
412 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
413 const struct pipe_box
*,
416 unsigned layer_stride
);
419 * Flush any pending framebuffer writes and invalidate texture caches.
421 void (*texture_barrier
)(struct pipe_context
*);
424 * Creates a video decoder for a specific video codec/profile
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
);
434 * Creates a video buffer as decoding target
436 struct pipe_video_buffer
*(*create_video_buffer
)( struct pipe_context
*context
,
437 const struct pipe_video_buffer
*templat
);
440 * Compute kernel execution
444 * Define the compute program and parameters to be used by
445 * pipe_context::launch_grid.
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 *);
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.
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.
464 void (*set_compute_resources
)(struct pipe_context
*,
465 unsigned start
, unsigned count
,
466 struct pipe_surface
**resources
);
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.
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.
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.
496 void (*set_global_binding
)(struct pipe_context
*context
,
497 unsigned first
, unsigned count
,
498 struct pipe_resource
**resources
,
502 * Launch the compute kernel starting from instruction \a pc of the
503 * currently bound compute program.
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.
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
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.
518 void (*launch_grid
)(struct pipe_context
*context
,
519 const uint
*block_layout
, const uint
*grid_layout
,
520 uint32_t pc
, const void *input
);
529 #endif /* PIPE_CONTEXT_H */