gallium: add support for programmable sample locations
[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 #include <stdio.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41
42 struct pipe_blend_color;
43 struct pipe_blend_state;
44 struct pipe_blit_info;
45 struct pipe_box;
46 struct pipe_clip_state;
47 struct pipe_constant_buffer;
48 struct pipe_debug_callback;
49 struct pipe_depth_stencil_alpha_state;
50 struct pipe_device_reset_callback;
51 struct pipe_draw_info;
52 struct pipe_grid_info;
53 struct pipe_fence_handle;
54 struct pipe_framebuffer_state;
55 struct pipe_image_view;
56 struct pipe_query;
57 struct pipe_poly_stipple;
58 struct pipe_rasterizer_state;
59 struct pipe_resolve_info;
60 struct pipe_resource;
61 struct pipe_sampler_state;
62 struct pipe_sampler_view;
63 struct pipe_scissor_state;
64 struct pipe_shader_buffer;
65 struct pipe_shader_state;
66 struct pipe_stencil_ref;
67 struct pipe_stream_output_target;
68 struct pipe_surface;
69 struct pipe_transfer;
70 struct pipe_vertex_buffer;
71 struct pipe_vertex_element;
72 struct pipe_video_buffer;
73 struct pipe_video_codec;
74 struct pipe_viewport_state;
75 struct pipe_compute_state;
76 union pipe_color_union;
77 union pipe_query_result;
78 struct u_log_context;
79 struct u_upload_mgr;
80
81 /**
82 * Gallium rendering context. Basically:
83 * - state setting functions
84 * - VBO drawing functions
85 * - surface functions
86 */
87 struct pipe_context {
88 struct pipe_screen *screen;
89
90 void *priv; /**< context private data (for DRI for example) */
91 void *draw; /**< private, for draw module (temporary?) */
92
93 /**
94 * Stream uploaders created by the driver. All drivers, state trackers, and
95 * modules should use them.
96 *
97 * Use u_upload_alloc or u_upload_data as many times as you want.
98 * Once you are done, use u_upload_unmap.
99 */
100 struct u_upload_mgr *stream_uploader; /* everything but shader constants */
101 struct u_upload_mgr *const_uploader; /* shader constants only */
102
103 void (*destroy)( struct pipe_context * );
104
105 /**
106 * VBO drawing
107 */
108 /*@{*/
109 void (*draw_vbo)( struct pipe_context *pipe,
110 const struct pipe_draw_info *info );
111 /*@}*/
112
113 /**
114 * Predicate subsequent rendering on occlusion query result
115 * \param query the query predicate, or NULL if no predicate
116 * \param condition whether to skip on FALSE or TRUE query results
117 * \param mode one of PIPE_RENDER_COND_x
118 */
119 void (*render_condition)( struct pipe_context *pipe,
120 struct pipe_query *query,
121 boolean condition,
122 enum pipe_render_cond_flag mode );
123
124 /**
125 * Query objects
126 */
127 /*@{*/
128 struct pipe_query *(*create_query)( struct pipe_context *pipe,
129 unsigned query_type,
130 unsigned index );
131
132 /**
133 * Create a query object that queries all given query types simultaneously.
134 *
135 * This can only be used for those query types for which
136 * get_driver_query_info indicates that it must be used. Only one batch
137 * query object may be active at a time.
138 *
139 * There may be additional constraints on which query types can be used
140 * together, in particular those that are implied by
141 * get_driver_query_group_info.
142 *
143 * \param num_queries the number of query types
144 * \param query_types array of \p num_queries query types
145 * \return a query object, or NULL on error.
146 */
147 struct pipe_query *(*create_batch_query)( struct pipe_context *pipe,
148 unsigned num_queries,
149 unsigned *query_types );
150
151 void (*destroy_query)(struct pipe_context *pipe,
152 struct pipe_query *q);
153
154 boolean (*begin_query)(struct pipe_context *pipe, struct pipe_query *q);
155 bool (*end_query)(struct pipe_context *pipe, struct pipe_query *q);
156
157 /**
158 * Get results of a query.
159 * \param wait if true, this query will block until the result is ready
160 * \return TRUE if results are ready, FALSE otherwise
161 */
162 boolean (*get_query_result)(struct pipe_context *pipe,
163 struct pipe_query *q,
164 boolean wait,
165 union pipe_query_result *result);
166
167 /**
168 * Get results of a query, storing into resource. Note that this may not
169 * be used with batch queries.
170 *
171 * \param wait if true, this query will block until the result is ready
172 * \param result_type the type of the value being stored:
173 * \param index for queries that return multiple pieces of data, which
174 * item of that data to store (e.g. for
175 * PIPE_QUERY_PIPELINE_STATISTICS).
176 * When the index is -1, instead of the value of the query
177 * the driver should instead write a 1 or 0 to the appropriate
178 * location with 1 meaning that the query result is available.
179 */
180 void (*get_query_result_resource)(struct pipe_context *pipe,
181 struct pipe_query *q,
182 boolean wait,
183 enum pipe_query_value_type result_type,
184 int index,
185 struct pipe_resource *resource,
186 unsigned offset);
187
188 /**
189 * Set whether all current non-driver queries except TIME_ELAPSED are
190 * active or paused.
191 */
192 void (*set_active_query_state)(struct pipe_context *pipe, boolean enable);
193
194 /*@}*/
195
196 /**
197 * State functions (create/bind/destroy state objects)
198 */
199 /*@{*/
200 void * (*create_blend_state)(struct pipe_context *,
201 const struct pipe_blend_state *);
202 void (*bind_blend_state)(struct pipe_context *, void *);
203 void (*delete_blend_state)(struct pipe_context *, void *);
204
205 void * (*create_sampler_state)(struct pipe_context *,
206 const struct pipe_sampler_state *);
207 void (*bind_sampler_states)(struct pipe_context *,
208 enum pipe_shader_type shader,
209 unsigned start_slot, unsigned num_samplers,
210 void **samplers);
211 void (*delete_sampler_state)(struct pipe_context *, void *);
212
213 void * (*create_rasterizer_state)(struct pipe_context *,
214 const struct pipe_rasterizer_state *);
215 void (*bind_rasterizer_state)(struct pipe_context *, void *);
216 void (*delete_rasterizer_state)(struct pipe_context *, void *);
217
218 void * (*create_depth_stencil_alpha_state)(struct pipe_context *,
219 const struct pipe_depth_stencil_alpha_state *);
220 void (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *);
221 void (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *);
222
223 void * (*create_fs_state)(struct pipe_context *,
224 const struct pipe_shader_state *);
225 void (*bind_fs_state)(struct pipe_context *, void *);
226 void (*delete_fs_state)(struct pipe_context *, void *);
227
228 void * (*create_vs_state)(struct pipe_context *,
229 const struct pipe_shader_state *);
230 void (*bind_vs_state)(struct pipe_context *, void *);
231 void (*delete_vs_state)(struct pipe_context *, void *);
232
233 void * (*create_gs_state)(struct pipe_context *,
234 const struct pipe_shader_state *);
235 void (*bind_gs_state)(struct pipe_context *, void *);
236 void (*delete_gs_state)(struct pipe_context *, void *);
237
238 void * (*create_tcs_state)(struct pipe_context *,
239 const struct pipe_shader_state *);
240 void (*bind_tcs_state)(struct pipe_context *, void *);
241 void (*delete_tcs_state)(struct pipe_context *, void *);
242
243 void * (*create_tes_state)(struct pipe_context *,
244 const struct pipe_shader_state *);
245 void (*bind_tes_state)(struct pipe_context *, void *);
246 void (*delete_tes_state)(struct pipe_context *, void *);
247
248 void * (*create_vertex_elements_state)(struct pipe_context *,
249 unsigned num_elements,
250 const struct pipe_vertex_element *);
251 void (*bind_vertex_elements_state)(struct pipe_context *, void *);
252 void (*delete_vertex_elements_state)(struct pipe_context *, void *);
253
254 /*@}*/
255
256 /**
257 * Parameter-like state (or properties)
258 */
259 /*@{*/
260 void (*set_blend_color)( struct pipe_context *,
261 const struct pipe_blend_color * );
262
263 void (*set_stencil_ref)( struct pipe_context *,
264 const struct pipe_stencil_ref * );
265
266 void (*set_sample_mask)( struct pipe_context *,
267 unsigned sample_mask );
268
269 void (*set_min_samples)( struct pipe_context *,
270 unsigned min_samples );
271
272 void (*set_clip_state)( struct pipe_context *,
273 const struct pipe_clip_state * );
274
275 void (*set_constant_buffer)( struct pipe_context *,
276 enum pipe_shader_type shader, uint index,
277 const struct pipe_constant_buffer *buf );
278
279 void (*set_framebuffer_state)( struct pipe_context *,
280 const struct pipe_framebuffer_state * );
281
282 /**
283 * Set the sample locations used during rasterization. When NULL or sized
284 * zero, the default locations are used.
285 *
286 * Note that get_sample_position() still returns the default locations.
287 *
288 * The samples are accessed with
289 * locations[(pixel_y*grid_w+pixel_x)*ms+i],
290 * where:
291 * ms = the sample count
292 * grid_w = the pixel grid width for the sample count
293 * grid_w = the pixel grid height for the sample count
294 * pixel_x = the window x coordinate modulo grid_w
295 * pixel_y = the window y coordinate modulo grid_w
296 * i = the sample index
297 * This gives a result with the x coordinate as the low 4 bits and the y
298 * coordinate as the high 4 bits. For each coordinate 0 is the left or top
299 * edge of the pixel's rectangle and 16 (not 15) is the right or bottom edge.
300 *
301 * Out of bounds accesses are return undefined values.
302 *
303 * The pixel grid is used to vary sample locations across pixels and its
304 * size can be queried with get_sample_pixel_grid().
305 */
306 void (*set_sample_locations)( struct pipe_context *,
307 size_t size, const uint8_t *locations );
308
309 void (*set_polygon_stipple)( struct pipe_context *,
310 const struct pipe_poly_stipple * );
311
312 void (*set_scissor_states)( struct pipe_context *,
313 unsigned start_slot,
314 unsigned num_scissors,
315 const struct pipe_scissor_state * );
316
317 void (*set_window_rectangles)( struct pipe_context *,
318 boolean include,
319 unsigned num_rectangles,
320 const struct pipe_scissor_state * );
321
322 void (*set_viewport_states)( struct pipe_context *,
323 unsigned start_slot,
324 unsigned num_viewports,
325 const struct pipe_viewport_state *);
326
327 void (*set_sampler_views)(struct pipe_context *,
328 enum pipe_shader_type shader,
329 unsigned start_slot, unsigned num_views,
330 struct pipe_sampler_view **);
331
332 void (*set_tess_state)(struct pipe_context *,
333 const float default_outer_level[4],
334 const float default_inner_level[2]);
335
336 /**
337 * Sets the debug callback. If the pointer is null, then no callback is
338 * set, otherwise a copy of the data should be made.
339 */
340 void (*set_debug_callback)(struct pipe_context *,
341 const struct pipe_debug_callback *);
342
343 /**
344 * Bind an array of shader buffers that will be used by a shader.
345 * Any buffers that were previously bound to the specified range
346 * will be unbound.
347 *
348 * \param shader selects shader stage
349 * \param start_slot first buffer slot to bind.
350 * \param count number of consecutive buffers to bind.
351 * \param buffers array of pointers to the buffers to bind, it
352 * should contain at least \a count elements
353 * unless it's NULL, in which case no buffers will
354 * be bound.
355 */
356 void (*set_shader_buffers)(struct pipe_context *,
357 enum pipe_shader_type shader,
358 unsigned start_slot, unsigned count,
359 const struct pipe_shader_buffer *buffers);
360
361 /**
362 * Bind an array of hw atomic buffers for use by all shaders.
363 * And buffers that were previously bound to the specified range
364 * will be unbound.
365 *
366 * \param start_slot first buffer slot to bind.
367 * \param count number of consecutive buffers to bind.
368 * \param buffers array of pointers to the buffers to bind, it
369 * should contain at least \a count elements
370 * unless it's NULL, in which case no buffers will
371 * be bound.
372 */
373 void (*set_hw_atomic_buffers)(struct pipe_context *,
374 unsigned start_slot, unsigned count,
375 const struct pipe_shader_buffer *buffers);
376
377 /**
378 * Bind an array of images that will be used by a shader.
379 * Any images that were previously bound to the specified range
380 * will be unbound.
381 *
382 * \param shader selects shader stage
383 * \param start_slot first image slot to bind.
384 * \param count number of consecutive images to bind.
385 * \param buffers array of the images to bind, it
386 * should contain at least \a count elements
387 * unless it's NULL, in which case no images will
388 * be bound.
389 */
390 void (*set_shader_images)(struct pipe_context *,
391 enum pipe_shader_type shader,
392 unsigned start_slot, unsigned count,
393 const struct pipe_image_view *images);
394
395 void (*set_vertex_buffers)( struct pipe_context *,
396 unsigned start_slot,
397 unsigned num_buffers,
398 const struct pipe_vertex_buffer * );
399
400 /*@}*/
401
402 /**
403 * Stream output functions.
404 */
405 /*@{*/
406
407 struct pipe_stream_output_target *(*create_stream_output_target)(
408 struct pipe_context *,
409 struct pipe_resource *,
410 unsigned buffer_offset,
411 unsigned buffer_size);
412
413 void (*stream_output_target_destroy)(struct pipe_context *,
414 struct pipe_stream_output_target *);
415
416 void (*set_stream_output_targets)(struct pipe_context *,
417 unsigned num_targets,
418 struct pipe_stream_output_target **targets,
419 const unsigned *offsets);
420
421 /*@}*/
422
423
424 /**
425 * Resource functions for blit-like functionality
426 *
427 * If a driver supports multisampling, blit must implement color resolve.
428 */
429 /*@{*/
430
431 /**
432 * Copy a block of pixels from one resource to another.
433 * The resource must be of the same format.
434 * Resources with nr_samples > 1 are not allowed.
435 */
436 void (*resource_copy_region)(struct pipe_context *pipe,
437 struct pipe_resource *dst,
438 unsigned dst_level,
439 unsigned dstx, unsigned dsty, unsigned dstz,
440 struct pipe_resource *src,
441 unsigned src_level,
442 const struct pipe_box *src_box);
443
444 /* Optimal hardware path for blitting pixels.
445 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
446 */
447 void (*blit)(struct pipe_context *pipe,
448 const struct pipe_blit_info *info);
449
450 /*@}*/
451
452 /**
453 * Clear the specified set of currently bound buffers to specified values.
454 * The entire buffers are cleared (no scissor, no colormask, etc).
455 *
456 * \param buffers bitfield of PIPE_CLEAR_* values.
457 * \param color pointer to a union of fiu array for each of r, g, b, a.
458 * \param depth depth clear value in [0,1].
459 * \param stencil stencil clear value
460 */
461 void (*clear)(struct pipe_context *pipe,
462 unsigned buffers,
463 const union pipe_color_union *color,
464 double depth,
465 unsigned stencil);
466
467 /**
468 * Clear a color rendertarget surface.
469 * \param color pointer to an union of fiu array for each of r, g, b, a.
470 */
471 void (*clear_render_target)(struct pipe_context *pipe,
472 struct pipe_surface *dst,
473 const union pipe_color_union *color,
474 unsigned dstx, unsigned dsty,
475 unsigned width, unsigned height,
476 bool render_condition_enabled);
477
478 /**
479 * Clear a depth-stencil surface.
480 * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
481 * \param depth depth clear value in [0,1].
482 * \param stencil stencil clear value
483 */
484 void (*clear_depth_stencil)(struct pipe_context *pipe,
485 struct pipe_surface *dst,
486 unsigned clear_flags,
487 double depth,
488 unsigned stencil,
489 unsigned dstx, unsigned dsty,
490 unsigned width, unsigned height,
491 bool render_condition_enabled);
492
493 /**
494 * Clear the texture with the specified texel. Not guaranteed to be a
495 * renderable format. Data provided in the resource's format.
496 */
497 void (*clear_texture)(struct pipe_context *pipe,
498 struct pipe_resource *res,
499 unsigned level,
500 const struct pipe_box *box,
501 const void *data);
502
503 /**
504 * Clear a buffer. Runs a memset over the specified region with the element
505 * value passed in through clear_value of size clear_value_size.
506 */
507 void (*clear_buffer)(struct pipe_context *pipe,
508 struct pipe_resource *res,
509 unsigned offset,
510 unsigned size,
511 const void *clear_value,
512 int clear_value_size);
513
514 /**
515 * If a depth buffer is rendered with different sample location state than
516 * what is current at the time of reading, the values may differ because
517 * depth buffer compression can depend the sample locations.
518 *
519 * This function is a hint to decompress the current depth buffer to avoid
520 * such problems.
521 */
522 void (*evaluate_depth_buffer)(struct pipe_context *pipe);
523
524 /**
525 * Flush draw commands.
526 *
527 * This guarantees that the new fence (if any) will finish in finite time,
528 * unless PIPE_FLUSH_DEFERRED is used.
529 *
530 * Subsequent operations on other contexts of the same screen are guaranteed
531 * to execute after the flushed commands, unless PIPE_FLUSH_ASYNC is used.
532 *
533 * NOTE: use screen->fence_reference() (or equivalent) to transfer
534 * new fence ref to **fence, to ensure that previous fence is unref'd
535 *
536 * \param fence if not NULL, an old fence to unref and transfer a
537 * new fence reference to
538 * \param flags bitfield of enum pipe_flush_flags values.
539 */
540 void (*flush)(struct pipe_context *pipe,
541 struct pipe_fence_handle **fence,
542 unsigned flags);
543
544 /**
545 * Create a fence from a fd.
546 *
547 * This is used for importing a foreign/external fence fd.
548 *
549 * \param fence if not NULL, an old fence to unref and transfer a
550 * new fence reference to
551 * \param fd fd representing the fence object
552 * \param type indicates which fence types backs fd
553 */
554 void (*create_fence_fd)(struct pipe_context *pipe,
555 struct pipe_fence_handle **fence,
556 int fd,
557 enum pipe_fd_type type);
558
559 /**
560 * Insert commands to have GPU wait for fence to be signaled.
561 */
562 void (*fence_server_sync)(struct pipe_context *pipe,
563 struct pipe_fence_handle *fence);
564
565 /**
566 * Insert commands to have the GPU signal a fence.
567 */
568 void (*fence_server_signal)(struct pipe_context *pipe,
569 struct pipe_fence_handle *fence);
570
571 /**
572 * Create a view on a texture to be used by a shader stage.
573 */
574 struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
575 struct pipe_resource *texture,
576 const struct pipe_sampler_view *templat);
577
578 /**
579 * Destroy a view on a texture.
580 *
581 * \param ctx the current context
582 * \param view the view to be destroyed
583 *
584 * \note The current context may not be the context in which the view was
585 * created (view->context). However, the caller must guarantee that
586 * the context which created the view is still alive.
587 */
588 void (*sampler_view_destroy)(struct pipe_context *ctx,
589 struct pipe_sampler_view *view);
590
591
592 /**
593 * Get a surface which is a "view" into a resource, used by
594 * render target / depth stencil stages.
595 */
596 struct pipe_surface *(*create_surface)(struct pipe_context *ctx,
597 struct pipe_resource *resource,
598 const struct pipe_surface *templat);
599
600 void (*surface_destroy)(struct pipe_context *ctx,
601 struct pipe_surface *);
602
603
604 /**
605 * Map a resource.
606 *
607 * Transfers are (by default) context-private and allow uploads to be
608 * interleaved with rendering.
609 *
610 * out_transfer will contain the transfer object that must be passed
611 * to all the other transfer functions. It also contains useful
612 * information (like texture strides).
613 */
614 void *(*transfer_map)(struct pipe_context *,
615 struct pipe_resource *resource,
616 unsigned level,
617 unsigned usage, /* a combination of PIPE_TRANSFER_x */
618 const struct pipe_box *,
619 struct pipe_transfer **out_transfer);
620
621 /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
622 * regions specified with this call are guaranteed to be written to
623 * the resource.
624 */
625 void (*transfer_flush_region)( struct pipe_context *,
626 struct pipe_transfer *transfer,
627 const struct pipe_box *);
628
629 void (*transfer_unmap)(struct pipe_context *,
630 struct pipe_transfer *transfer);
631
632 /* One-shot transfer operation with data supplied in a user
633 * pointer.
634 */
635 void (*buffer_subdata)(struct pipe_context *,
636 struct pipe_resource *,
637 unsigned usage, /* a combination of PIPE_TRANSFER_x */
638 unsigned offset,
639 unsigned size,
640 const void *data);
641
642 void (*texture_subdata)(struct pipe_context *,
643 struct pipe_resource *,
644 unsigned level,
645 unsigned usage, /* a combination of PIPE_TRANSFER_x */
646 const struct pipe_box *,
647 const void *data,
648 unsigned stride,
649 unsigned layer_stride);
650
651 /**
652 * Flush any pending framebuffer writes and invalidate texture caches.
653 */
654 void (*texture_barrier)(struct pipe_context *, unsigned flags);
655
656 /**
657 * Flush caches according to flags.
658 */
659 void (*memory_barrier)(struct pipe_context *, unsigned flags);
660
661 /**
662 * Change the commitment status of a part of the given resource, which must
663 * have been created with the PIPE_RESOURCE_FLAG_SPARSE bit.
664 *
665 * \param level The texture level whose commitment should be changed.
666 * \param box The region of the resource whose commitment should be changed.
667 * \param commit Whether memory should be committed or un-committed.
668 *
669 * \return false if out of memory, true on success.
670 */
671 bool (*resource_commit)(struct pipe_context *, struct pipe_resource *,
672 unsigned level, struct pipe_box *box, bool commit);
673
674 /**
675 * Creates a video codec for a specific video format/profile
676 */
677 struct pipe_video_codec *(*create_video_codec)( struct pipe_context *context,
678 const struct pipe_video_codec *templat );
679
680 /**
681 * Creates a video buffer as decoding target
682 */
683 struct pipe_video_buffer *(*create_video_buffer)( struct pipe_context *context,
684 const struct pipe_video_buffer *templat );
685
686 /**
687 * Compute kernel execution
688 */
689 /*@{*/
690 /**
691 * Define the compute program and parameters to be used by
692 * pipe_context::launch_grid.
693 */
694 void *(*create_compute_state)(struct pipe_context *context,
695 const struct pipe_compute_state *);
696 void (*bind_compute_state)(struct pipe_context *, void *);
697 void (*delete_compute_state)(struct pipe_context *, void *);
698
699 /**
700 * Bind an array of shader resources that will be used by the
701 * compute program. Any resources that were previously bound to
702 * the specified range will be unbound after this call.
703 *
704 * \param start first resource to bind.
705 * \param count number of consecutive resources to bind.
706 * \param resources array of pointers to the resources to bind, it
707 * should contain at least \a count elements
708 * unless it's NULL, in which case no new
709 * resources will be bound.
710 */
711 void (*set_compute_resources)(struct pipe_context *,
712 unsigned start, unsigned count,
713 struct pipe_surface **resources);
714
715 /**
716 * Bind an array of buffers to be mapped into the address space of
717 * the GLOBAL resource. Any buffers that were previously bound
718 * between [first, first + count - 1] are unbound after this call.
719 *
720 * \param first first buffer to map.
721 * \param count number of consecutive buffers to map.
722 * \param resources array of pointers to the buffers to map, it
723 * should contain at least \a count elements
724 * unless it's NULL, in which case no new
725 * resources will be bound.
726 * \param handles array of pointers to the memory locations that
727 * will be updated with the address each buffer
728 * will be mapped to. The base memory address of
729 * each of the buffers will be added to the value
730 * pointed to by its corresponding handle to form
731 * the final address argument. It should contain
732 * at least \a count elements, unless \a
733 * resources is NULL in which case \a handles
734 * should be NULL as well.
735 *
736 * Note that the driver isn't required to make any guarantees about
737 * the contents of the \a handles array being valid anytime except
738 * during the subsequent calls to pipe_context::launch_grid. This
739 * means that the only sensible location handles[i] may point to is
740 * somewhere within the INPUT buffer itself. This is so to
741 * accommodate implementations that lack virtual memory but
742 * nevertheless migrate buffers on the fly, leading to resource
743 * base addresses that change on each kernel invocation or are
744 * unknown to the pipe driver.
745 */
746 void (*set_global_binding)(struct pipe_context *context,
747 unsigned first, unsigned count,
748 struct pipe_resource **resources,
749 uint32_t **handles);
750
751 /**
752 * Launch the compute kernel starting from instruction \a pc of the
753 * currently bound compute program.
754 */
755 void (*launch_grid)(struct pipe_context *context,
756 const struct pipe_grid_info *info);
757 /*@}*/
758
759 /**
760 * Get the default sample position for an individual sample point.
761 *
762 * \param sample_count - total number of samples
763 * \param sample_index - sample to get the position values for
764 * \param out_value - return value of 2 floats for x and y position for
765 * requested sample.
766 */
767 void (*get_sample_position)(struct pipe_context *context,
768 unsigned sample_count,
769 unsigned sample_index,
770 float *out_value);
771
772 /**
773 * Query a timestamp in nanoseconds. This is completely equivalent to
774 * pipe_screen::get_timestamp() but takes a context handle for drivers
775 * that require a context.
776 */
777 uint64_t (*get_timestamp)(struct pipe_context *);
778
779 /**
780 * Flush the resource cache, so that the resource can be used
781 * by an external client. Possible usage:
782 * - flushing a resource before presenting it on the screen
783 * - flushing a resource if some other process or device wants to use it
784 * This shouldn't be used to flush caches if the resource is only managed
785 * by a single pipe_screen and is not shared with another process.
786 * (i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
787 * use the resource for texturing)
788 */
789 void (*flush_resource)(struct pipe_context *ctx,
790 struct pipe_resource *resource);
791
792 /**
793 * Invalidate the contents of the resource. This is used to
794 *
795 * (1) implement EGL's semantic of undefined depth/stencil
796 * contenst after a swapbuffers. This allows a tiled renderer (for
797 * example) to not store the depth buffer.
798 *
799 * (2) implement GL's InvalidateBufferData. For backwards compatibility,
800 * you must only rely on the usability for this purpose when
801 * PIPE_CAP_INVALIDATE_BUFFER is enabled.
802 */
803 void (*invalidate_resource)(struct pipe_context *ctx,
804 struct pipe_resource *resource);
805
806 /**
807 * Return information about unexpected device resets.
808 */
809 enum pipe_reset_status (*get_device_reset_status)(struct pipe_context *ctx);
810
811 /**
812 * Sets the reset status callback. If the pointer is null, then no callback
813 * is set, otherwise a copy of the data should be made.
814 */
815 void (*set_device_reset_callback)(struct pipe_context *ctx,
816 const struct pipe_device_reset_callback *cb);
817
818 /**
819 * Dump driver-specific debug information into a stream. This is
820 * used by debugging tools.
821 *
822 * \param ctx pipe context
823 * \param stream where the output should be written to
824 * \param flags a mask of PIPE_DUMP_* flags
825 */
826 void (*dump_debug_state)(struct pipe_context *ctx, FILE *stream,
827 unsigned flags);
828
829 /**
830 * Set the log context to which the driver should write internal debug logs
831 * (internal states, command streams).
832 *
833 * The caller must ensure that the log context is destroyed and reset to
834 * NULL before the pipe context is destroyed, and that log context functions
835 * are only called from the driver thread.
836 *
837 * \param ctx pipe context
838 * \param log logging context
839 */
840 void (*set_log_context)(struct pipe_context *ctx, struct u_log_context *log);
841
842 /**
843 * Emit string marker in cmdstream
844 */
845 void (*emit_string_marker)(struct pipe_context *ctx,
846 const char *string,
847 int len);
848
849 /**
850 * Generate mipmap.
851 * \return TRUE if mipmap generation succeeds, FALSE otherwise
852 */
853 boolean (*generate_mipmap)(struct pipe_context *ctx,
854 struct pipe_resource *resource,
855 enum pipe_format format,
856 unsigned base_level,
857 unsigned last_level,
858 unsigned first_layer,
859 unsigned last_layer);
860
861 /**
862 * Create a 64-bit texture handle.
863 *
864 * \param ctx pipe context
865 * \param view pipe sampler view object
866 * \param state pipe sampler state template
867 * \return a 64-bit texture handle if success, 0 otherwise
868 */
869 uint64_t (*create_texture_handle)(struct pipe_context *ctx,
870 struct pipe_sampler_view *view,
871 const struct pipe_sampler_state *state);
872
873 /**
874 * Delete a texture handle.
875 *
876 * \param ctx pipe context
877 * \param handle 64-bit texture handle
878 */
879 void (*delete_texture_handle)(struct pipe_context *ctx, uint64_t handle);
880
881 /**
882 * Make a texture handle resident.
883 *
884 * \param ctx pipe context
885 * \param handle 64-bit texture handle
886 * \param resident TRUE for resident, FALSE otherwise
887 */
888 void (*make_texture_handle_resident)(struct pipe_context *ctx,
889 uint64_t handle, bool resident);
890
891 /**
892 * Create a 64-bit image handle.
893 *
894 * \param ctx pipe context
895 * \param image pipe image view template
896 * \return a 64-bit image handle if success, 0 otherwise
897 */
898 uint64_t (*create_image_handle)(struct pipe_context *ctx,
899 const struct pipe_image_view *image);
900
901 /**
902 * Delete an image handle.
903 *
904 * \param ctx pipe context
905 * \param handle 64-bit image handle
906 */
907 void (*delete_image_handle)(struct pipe_context *ctx, uint64_t handle);
908
909 /**
910 * Make an image handle resident.
911 *
912 * \param ctx pipe context
913 * \param handle 64-bit image handle
914 * \param access GL_READ_ONLY, GL_WRITE_ONLY or GL_READ_WRITE
915 * \param resident TRUE for resident, FALSE otherwise
916 */
917 void (*make_image_handle_resident)(struct pipe_context *ctx, uint64_t handle,
918 unsigned access, bool resident);
919
920 /**
921 * Call the given function from the driver thread.
922 *
923 * This is set by threaded contexts for use by debugging wrappers.
924 *
925 * \param asap if true, run the callback immediately if there are no pending
926 * commands to be processed by the driver thread
927 */
928 void (*callback)(struct pipe_context *ctx, void (*fn)(void *), void *data,
929 bool asap);
930 };
931
932
933 #ifdef __cplusplus
934 }
935 #endif
936
937 #endif /* PIPE_CONTEXT_H */