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"
34 #include "p_defines.h"
41 struct pipe_blend_color
;
42 struct pipe_blend_state
;
43 struct pipe_blit_info
;
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
;
53 struct pipe_poly_stipple
;
54 struct pipe_rasterizer_state
;
55 struct pipe_resolve_info
;
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
;
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
;
75 * Gallium rendering context. Basically:
76 * - state setting functions
77 * - VBO drawing functions
81 struct pipe_screen
*screen
;
83 void *priv
; /**< context private data (for DRI for example) */
84 void *draw
; /**< private, for draw module (temporary?) */
86 void (*destroy
)( struct pipe_context
* );
92 void (*draw_vbo
)( struct pipe_context
*pipe
,
93 const struct pipe_draw_info
*info
);
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
102 void (*render_condition
)( struct pipe_context
*pipe
,
103 struct pipe_query
*query
,
111 struct pipe_query
*(*create_query
)( struct pipe_context
*pipe
,
112 unsigned query_type
);
114 void (*destroy_query
)(struct pipe_context
*pipe
,
115 struct pipe_query
*q
);
117 void (*begin_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
118 void (*end_query
)(struct pipe_context
*pipe
, struct pipe_query
*q
);
121 * Get results of a query.
122 * \param wait if true, this query will block until the result is ready
123 * \return TRUE if results are ready, FALSE otherwise
125 boolean (*get_query_result
)(struct pipe_context
*pipe
,
126 struct pipe_query
*q
,
128 union pipe_query_result
*result
);
132 * State functions (create/bind/destroy state objects)
135 void * (*create_blend_state
)(struct pipe_context
*,
136 const struct pipe_blend_state
*);
137 void (*bind_blend_state
)(struct pipe_context
*, void *);
138 void (*delete_blend_state
)(struct pipe_context
*, void *);
140 void * (*create_sampler_state
)(struct pipe_context
*,
141 const struct pipe_sampler_state
*);
142 void (*bind_fragment_sampler_states
)(struct pipe_context
*,
143 unsigned num_samplers
,
145 void (*bind_vertex_sampler_states
)(struct pipe_context
*,
146 unsigned num_samplers
,
148 void (*bind_geometry_sampler_states
)(struct pipe_context
*,
149 unsigned num_samplers
,
151 void (*bind_compute_sampler_states
)(struct pipe_context
*,
153 unsigned num_samplers
,
155 void (*delete_sampler_state
)(struct pipe_context
*, void *);
157 void * (*create_rasterizer_state
)(struct pipe_context
*,
158 const struct pipe_rasterizer_state
*);
159 void (*bind_rasterizer_state
)(struct pipe_context
*, void *);
160 void (*delete_rasterizer_state
)(struct pipe_context
*, void *);
162 void * (*create_depth_stencil_alpha_state
)(struct pipe_context
*,
163 const struct pipe_depth_stencil_alpha_state
*);
164 void (*bind_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
165 void (*delete_depth_stencil_alpha_state
)(struct pipe_context
*, void *);
167 void * (*create_fs_state
)(struct pipe_context
*,
168 const struct pipe_shader_state
*);
169 void (*bind_fs_state
)(struct pipe_context
*, void *);
170 void (*delete_fs_state
)(struct pipe_context
*, void *);
172 void * (*create_vs_state
)(struct pipe_context
*,
173 const struct pipe_shader_state
*);
174 void (*bind_vs_state
)(struct pipe_context
*, void *);
175 void (*delete_vs_state
)(struct pipe_context
*, void *);
177 void * (*create_gs_state
)(struct pipe_context
*,
178 const struct pipe_shader_state
*);
179 void (*bind_gs_state
)(struct pipe_context
*, void *);
180 void (*delete_gs_state
)(struct pipe_context
*, void *);
182 void * (*create_vertex_elements_state
)(struct pipe_context
*,
183 unsigned num_elements
,
184 const struct pipe_vertex_element
*);
185 void (*bind_vertex_elements_state
)(struct pipe_context
*, void *);
186 void (*delete_vertex_elements_state
)(struct pipe_context
*, void *);
191 * Parameter-like state (or properties)
194 void (*set_blend_color
)( struct pipe_context
*,
195 const struct pipe_blend_color
* );
197 void (*set_stencil_ref
)( struct pipe_context
*,
198 const struct pipe_stencil_ref
* );
200 void (*set_sample_mask
)( struct pipe_context
*,
201 unsigned sample_mask
);
203 void (*set_clip_state
)( struct pipe_context
*,
204 const struct pipe_clip_state
* );
206 void (*set_constant_buffer
)( struct pipe_context
*,
207 uint shader
, uint index
,
208 struct pipe_constant_buffer
*buf
);
210 void (*set_framebuffer_state
)( struct pipe_context
*,
211 const struct pipe_framebuffer_state
* );
213 void (*set_polygon_stipple
)( struct pipe_context
*,
214 const struct pipe_poly_stipple
* );
216 void (*set_scissor_states
)( struct pipe_context
*,
218 unsigned num_scissors
,
219 const struct pipe_scissor_state
* );
221 void (*set_viewport_states
)( struct pipe_context
*,
223 unsigned num_viewports
,
224 const struct pipe_viewport_state
*);
226 void (*set_fragment_sampler_views
)(struct pipe_context
*,
228 struct pipe_sampler_view
**);
230 void (*set_vertex_sampler_views
)(struct pipe_context
*,
232 struct pipe_sampler_view
**);
234 void (*set_geometry_sampler_views
)(struct pipe_context
*,
236 struct pipe_sampler_view
**);
238 void (*set_compute_sampler_views
)(struct pipe_context
*,
239 unsigned start_slot
, unsigned num_views
,
240 struct pipe_sampler_view
**);
243 * Bind an array of shader resources that will be used by the
244 * graphics pipeline. Any resources that were previously bound to
245 * the specified range will be unbound after this call.
247 * \param start first resource to bind.
248 * \param count number of consecutive resources to bind.
249 * \param resources array of pointers to the resources to bind, it
250 * should contain at least \a count elements
251 * unless it's NULL, in which case no new
252 * resources will be bound.
254 void (*set_shader_resources
)(struct pipe_context
*,
255 unsigned start
, unsigned count
,
256 struct pipe_surface
**resources
);
258 void (*set_vertex_buffers
)( struct pipe_context
*,
260 unsigned num_buffers
,
261 const struct pipe_vertex_buffer
* );
263 void (*set_index_buffer
)( struct pipe_context
*pipe
,
264 const struct pipe_index_buffer
* );
269 * Stream output functions.
273 struct pipe_stream_output_target
*(*create_stream_output_target
)(
274 struct pipe_context
*,
275 struct pipe_resource
*,
276 unsigned buffer_offset
,
277 unsigned buffer_size
);
279 void (*stream_output_target_destroy
)(struct pipe_context
*,
280 struct pipe_stream_output_target
*);
282 void (*set_stream_output_targets
)(struct pipe_context
*,
283 unsigned num_targets
,
284 struct pipe_stream_output_target
**targets
,
285 unsigned append_bitmask
);
291 * Resource functions for blit-like functionality
293 * If a driver supports multisampling, blit must implement color resolve.
298 * Copy a block of pixels from one resource to another.
299 * The resource must be of the same format.
300 * Resources with nr_samples > 1 are not allowed.
302 void (*resource_copy_region
)(struct pipe_context
*pipe
,
303 struct pipe_resource
*dst
,
305 unsigned dstx
, unsigned dsty
, unsigned dstz
,
306 struct pipe_resource
*src
,
308 const struct pipe_box
*src_box
);
310 /* Optimal hardware path for blitting pixels.
311 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
313 void (*blit
)(struct pipe_context
*pipe
,
314 const struct pipe_blit_info
*info
);
319 * Clear the specified set of currently bound buffers to specified values.
320 * The entire buffers are cleared (no scissor, no colormask, etc).
322 * \param buffers bitfield of PIPE_CLEAR_* values.
323 * \param color pointer to a union of fiu array for each of r, g, b, a.
324 * \param depth depth clear value in [0,1].
325 * \param stencil stencil clear value
327 void (*clear
)(struct pipe_context
*pipe
,
329 const union pipe_color_union
*color
,
334 * Clear a color rendertarget surface.
335 * \param color pointer to an union of fiu array for each of r, g, b, a.
337 void (*clear_render_target
)(struct pipe_context
*pipe
,
338 struct pipe_surface
*dst
,
339 const union pipe_color_union
*color
,
340 unsigned dstx
, unsigned dsty
,
341 unsigned width
, unsigned height
);
344 * Clear a depth-stencil surface.
345 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
346 * \param depth depth clear value in [0,1].
347 * \param stencil stencil clear value
349 void (*clear_depth_stencil
)(struct pipe_context
*pipe
,
350 struct pipe_surface
*dst
,
351 unsigned clear_flags
,
354 unsigned dstx
, unsigned dsty
,
355 unsigned width
, unsigned height
);
357 /** Flush draw commands
359 * \param flags bitfield of enum pipe_flush_flags values.
361 void (*flush
)(struct pipe_context
*pipe
,
362 struct pipe_fence_handle
**fence
,
366 * Create a view on a texture to be used by a shader stage.
368 struct pipe_sampler_view
* (*create_sampler_view
)(struct pipe_context
*ctx
,
369 struct pipe_resource
*texture
,
370 const struct pipe_sampler_view
*templat
);
372 void (*sampler_view_destroy
)(struct pipe_context
*ctx
,
373 struct pipe_sampler_view
*view
);
377 * Get a surface which is a "view" into a resource, used by
378 * render target / depth stencil stages.
380 struct pipe_surface
*(*create_surface
)(struct pipe_context
*ctx
,
381 struct pipe_resource
*resource
,
382 const struct pipe_surface
*templat
);
384 void (*surface_destroy
)(struct pipe_context
*ctx
,
385 struct pipe_surface
*);
390 * Transfers are (by default) context-private and allow uploads to be
391 * interleaved with rendering.
393 * out_transfer will contain the transfer object that must be passed
394 * to all the other transfer functions. It also contains useful
395 * information (like texture strides).
397 void *(*transfer_map
)(struct pipe_context
*,
398 struct pipe_resource
*resource
,
400 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
401 const struct pipe_box
*,
402 struct pipe_transfer
**out_transfer
);
404 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
405 * regions specified with this call are guaranteed to be written to
408 void (*transfer_flush_region
)( struct pipe_context
*,
409 struct pipe_transfer
*transfer
,
410 const struct pipe_box
*);
412 void (*transfer_unmap
)(struct pipe_context
*,
413 struct pipe_transfer
*transfer
);
415 /* One-shot transfer operation with data supplied in a user
416 * pointer. XXX: strides??
418 void (*transfer_inline_write
)( struct pipe_context
*,
419 struct pipe_resource
*,
421 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
422 const struct pipe_box
*,
425 unsigned layer_stride
);
428 * Flush any pending framebuffer writes and invalidate texture caches.
430 void (*texture_barrier
)(struct pipe_context
*);
433 * Creates a video codec for a specific video format/profile
435 struct pipe_video_codec
*(*create_video_codec
)( struct pipe_context
*context
,
436 const struct pipe_video_codec
*templat
);
439 * Creates a video buffer as decoding target
441 struct pipe_video_buffer
*(*create_video_buffer
)( struct pipe_context
*context
,
442 const struct pipe_video_buffer
*templat
);
445 * Compute kernel execution
449 * Define the compute program and parameters to be used by
450 * pipe_context::launch_grid.
452 void *(*create_compute_state
)(struct pipe_context
*context
,
453 const struct pipe_compute_state
*);
454 void (*bind_compute_state
)(struct pipe_context
*, void *);
455 void (*delete_compute_state
)(struct pipe_context
*, void *);
458 * Bind an array of shader resources that will be used by the
459 * compute program. Any resources that were previously bound to
460 * the specified range will be unbound after this call.
462 * \param start first resource to bind.
463 * \param count number of consecutive resources to bind.
464 * \param resources array of pointers to the resources to bind, it
465 * should contain at least \a count elements
466 * unless it's NULL, in which case no new
467 * resources will be bound.
469 void (*set_compute_resources
)(struct pipe_context
*,
470 unsigned start
, unsigned count
,
471 struct pipe_surface
**resources
);
474 * Bind an array of buffers to be mapped into the address space of
475 * the GLOBAL resource. Any buffers that were previously bound
476 * between [first, first + count - 1] are unbound after this call.
478 * \param first first buffer to map.
479 * \param count number of consecutive buffers to map.
480 * \param resources array of pointers to the buffers to map, it
481 * should contain at least \a count elements
482 * unless it's NULL, in which case no new
483 * resources will be bound.
484 * \param handles array of pointers to the memory locations that
485 * will be filled with the respective base
486 * addresses each buffer will be mapped to. It
487 * should contain at least \a count elements,
488 * unless \a resources is NULL in which case \a
489 * handles should be NULL as well.
491 * Note that the driver isn't required to make any guarantees about
492 * the contents of the \a handles array being valid anytime except
493 * during the subsequent calls to pipe_context::launch_grid. This
494 * means that the only sensible location handles[i] may point to is
495 * somewhere within the INPUT buffer itself. This is so to
496 * accommodate implementations that lack virtual memory but
497 * nevertheless migrate buffers on the fly, leading to resource
498 * base addresses that change on each kernel invocation or are
499 * unknown to the pipe driver.
501 void (*set_global_binding
)(struct pipe_context
*context
,
502 unsigned first
, unsigned count
,
503 struct pipe_resource
**resources
,
507 * Launch the compute kernel starting from instruction \a pc of the
508 * currently bound compute program.
510 * \a grid_layout and \a block_layout are arrays of size \a
511 * PIPE_COMPUTE_CAP_GRID_DIMENSION that determine the layout of the
512 * grid (in block units) and working block (in thread units) to be
513 * used, respectively.
515 * \a pc For drivers that use PIPE_SHADER_IR_LLVM as their prefered IR,
516 * this value will be the index of the kernel in the opencl.kernels
519 * \a input will be used to initialize the INPUT resource, and it
520 * should point to a buffer of at least
521 * pipe_compute_state::req_input_mem bytes.
523 void (*launch_grid
)(struct pipe_context
*context
,
524 const uint
*block_layout
, const uint
*grid_layout
,
525 uint32_t pc
, const void *input
);
529 * Get sample position for an individual sample point.
531 * \param sample_count - total number of samples
532 * \param sample_index - sample to get the position values for
533 * \param out_value - return value of 2 floats for x and y position for
536 void (*get_sample_position
)(struct pipe_context
*context
,
537 unsigned sample_count
,
538 unsigned sample_index
,
547 #endif /* PIPE_CONTEXT_H */