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