p_context.h revision 588fa884d212eba5ffbc69fda75db37d7c77214c
1/**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#ifndef PIPE_CONTEXT_H
29#define PIPE_CONTEXT_H
30
31#include "p_compiler.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37
38struct pipe_blend_color;
39struct pipe_blend_state;
40struct pipe_box;
41struct pipe_clip_state;
42struct pipe_depth_stencil_alpha_state;
43struct pipe_draw_info;
44struct pipe_fence_handle;
45struct pipe_framebuffer_state;
46struct pipe_index_buffer;
47struct pipe_query;
48struct pipe_poly_stipple;
49struct pipe_rasterizer_state;
50struct pipe_resource;
51struct pipe_sampler_state;
52struct pipe_sampler_view;
53struct pipe_scissor_state;
54struct pipe_shader_state;
55struct pipe_stencil_ref;
56struct pipe_stream_output_state;
57struct pipe_surface;
58struct pipe_vertex_buffer;
59struct pipe_vertex_element;
60struct pipe_viewport_state;
61
62/**
63 * Gallium rendering context.  Basically:
64 *  - state setting functions
65 *  - VBO drawing functions
66 *  - surface functions
67 */
68struct pipe_context {
69   struct pipe_winsys *winsys;
70   struct pipe_screen *screen;
71
72   void *priv;  /**< context private data (for DRI for example) */
73   void *draw;  /**< private, for draw module (temporary?) */
74
75   void (*destroy)( struct pipe_context * );
76
77   /**
78    * VBO drawing
79    */
80   /*@{*/
81   void (*draw_vbo)( struct pipe_context *pipe,
82                     const struct pipe_draw_info *info );
83
84   /**
85    * Draw the stream output buffer at index 0
86    */
87   void (*draw_stream_output)( struct pipe_context *pipe, unsigned mode );
88   /*@}*/
89
90   /**
91    * Predicate subsequent rendering on occlusion query result
92    * \param query  the query predicate, or NULL if no predicate
93    * \param mode  one of PIPE_RENDER_COND_x
94    */
95   void (*render_condition)( struct pipe_context *pipe,
96                             struct pipe_query *query,
97                             uint mode );
98
99   /**
100    * Query objects
101    */
102   /*@{*/
103   struct pipe_query *(*create_query)( struct pipe_context *pipe,
104                                       unsigned query_type );
105
106   void (*destroy_query)(struct pipe_context *pipe,
107                         struct pipe_query *q);
108
109   void (*begin_query)(struct pipe_context *pipe, struct pipe_query *q);
110   void (*end_query)(struct pipe_context *pipe, struct pipe_query *q);
111
112   /**
113    * Get results of a query.
114    * \param wait  if true, this query will block until the result is ready
115    * \return TRUE if results are ready, FALSE otherwise
116    */
117   boolean (*get_query_result)(struct pipe_context *pipe,
118                               struct pipe_query *q,
119                               boolean wait,
120                               void *result);
121   /*@}*/
122
123   /**
124    * State functions (create/bind/destroy state objects)
125    */
126   /*@{*/
127   void * (*create_blend_state)(struct pipe_context *,
128                                const struct pipe_blend_state *);
129   void   (*bind_blend_state)(struct pipe_context *, void *);
130   void   (*delete_blend_state)(struct pipe_context *, void  *);
131
132   void * (*create_sampler_state)(struct pipe_context *,
133                                  const struct pipe_sampler_state *);
134   void   (*bind_fragment_sampler_states)(struct pipe_context *,
135                                          unsigned num_samplers,
136                                          void **samplers);
137   void   (*bind_vertex_sampler_states)(struct pipe_context *,
138                                        unsigned num_samplers,
139                                        void **samplers);
140   void   (*bind_geometry_sampler_states)(struct pipe_context *,
141                                          unsigned num_samplers,
142                                          void **samplers);
143   void   (*delete_sampler_state)(struct pipe_context *, void *);
144
145   void * (*create_rasterizer_state)(struct pipe_context *,
146                                     const struct pipe_rasterizer_state *);
147   void   (*bind_rasterizer_state)(struct pipe_context *, void *);
148   void   (*delete_rasterizer_state)(struct pipe_context *, void *);
149
150   void * (*create_depth_stencil_alpha_state)(struct pipe_context *,
151                                        const struct pipe_depth_stencil_alpha_state *);
152   void   (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *);
153   void   (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *);
154
155   void * (*create_fs_state)(struct pipe_context *,
156                             const struct pipe_shader_state *);
157   void   (*bind_fs_state)(struct pipe_context *, void *);
158   void   (*delete_fs_state)(struct pipe_context *, void *);
159
160   void * (*create_vs_state)(struct pipe_context *,
161                             const struct pipe_shader_state *);
162   void   (*bind_vs_state)(struct pipe_context *, void *);
163   void   (*delete_vs_state)(struct pipe_context *, void *);
164
165   void * (*create_gs_state)(struct pipe_context *,
166                             const struct pipe_shader_state *);
167   void   (*bind_gs_state)(struct pipe_context *, void *);
168   void   (*delete_gs_state)(struct pipe_context *, void *);
169
170   void * (*create_vertex_elements_state)(struct pipe_context *,
171                                          unsigned num_elements,
172                                          const struct pipe_vertex_element *);
173   void   (*bind_vertex_elements_state)(struct pipe_context *, void *);
174   void   (*delete_vertex_elements_state)(struct pipe_context *, void *);
175
176   void * (*create_stream_output_state)(struct pipe_context *,
177                                        const struct pipe_stream_output_state *);
178   void   (*bind_stream_output_state)(struct pipe_context *, void *);
179   void   (*delete_stream_output_state)(struct pipe_context*, void*);
180
181   /*@}*/
182
183   /**
184    * Parameter-like state (or properties)
185    */
186   /*@{*/
187   void (*set_blend_color)( struct pipe_context *,
188                            const struct pipe_blend_color * );
189
190   void (*set_stencil_ref)( struct pipe_context *,
191                            const struct pipe_stencil_ref * );
192
193   void (*set_sample_mask)( struct pipe_context *,
194                            unsigned sample_mask );
195
196   void (*set_clip_state)( struct pipe_context *,
197                            const struct pipe_clip_state * );
198
199   void (*set_constant_buffer)( struct pipe_context *,
200                                uint shader, uint index,
201                                struct pipe_resource *buf );
202
203   void (*set_framebuffer_state)( struct pipe_context *,
204                                  const struct pipe_framebuffer_state * );
205
206   void (*set_polygon_stipple)( struct pipe_context *,
207				const struct pipe_poly_stipple * );
208
209   void (*set_scissor_state)( struct pipe_context *,
210                              const struct pipe_scissor_state * );
211
212   void (*set_viewport_state)( struct pipe_context *,
213                               const struct pipe_viewport_state * );
214
215   void (*set_fragment_sampler_views)(struct pipe_context *,
216                                      unsigned num_views,
217                                      struct pipe_sampler_view **);
218
219   void (*set_vertex_sampler_views)(struct pipe_context *,
220                                    unsigned num_views,
221                                    struct pipe_sampler_view **);
222
223   void (*set_geometry_sampler_views)(struct pipe_context *,
224                                      unsigned num_views,
225                                      struct pipe_sampler_view **);
226
227   void (*set_vertex_buffers)( struct pipe_context *,
228                               unsigned num_buffers,
229                               const struct pipe_vertex_buffer * );
230
231   void (*set_index_buffer)( struct pipe_context *pipe,
232                             const struct pipe_index_buffer * );
233
234   void (*set_stream_output_buffers)(struct pipe_context *,
235                                     struct pipe_resource **buffers,
236                                     int *offsets, /*array of offsets
237                                                     from the start of each
238                                                     of the buffers */
239                                     int num_buffers);
240
241   /*@}*/
242
243
244   /**
245    * Resource functions for blit-like functionality
246    *
247    * If a driver supports multisampling, resource_resolve must be available.
248    */
249   /*@{*/
250
251   /**
252    * Copy a block of pixels from one resource to another.
253    * The resource must be of the same format.
254    * Resources with nr_samples > 1 are not allowed.
255    */
256   void (*resource_copy_region)(struct pipe_context *pipe,
257                                struct pipe_resource *dst,
258                                unsigned dst_level,
259                                unsigned dstx, unsigned dsty, unsigned dstz,
260                                struct pipe_resource *src,
261                                unsigned src_level,
262                                const struct pipe_box *src_box);
263
264   /**
265    * Resolve a multisampled resource into a non-multisampled one.
266    * Source and destination must have the same size and same format.
267    */
268   void (*resource_resolve)(struct pipe_context *pipe,
269                            struct pipe_resource *dst,
270                            unsigned dst_layer,
271                            struct pipe_resource *src,
272                            unsigned src_layer);
273
274   /*@}*/
275
276   /**
277    * Clear the specified set of currently bound buffers to specified values.
278    * The entire buffers are cleared (no scissor, no colormask, etc).
279    *
280    * \param buffers  bitfield of PIPE_CLEAR_* values.
281    * \param rgba  pointer to an array of one float for each of r, g, b, a.
282    * \param depth  depth clear value in [0,1].
283    * \param stencil  stencil clear value
284    */
285   void (*clear)(struct pipe_context *pipe,
286                 unsigned buffers,
287                 const float *rgba,
288                 double depth,
289                 unsigned stencil);
290
291   /**
292    * Clear a color rendertarget surface.
293    * \param rgba  pointer to an array of one float for each of r, g, b, a.
294    */
295   void (*clear_render_target)(struct pipe_context *pipe,
296                               struct pipe_surface *dst,
297                               const float *rgba,
298                               unsigned dstx, unsigned dsty,
299                               unsigned width, unsigned height);
300
301   /**
302    * Clear a depth-stencil surface.
303    * \param clear_flags  bitfield of PIPE_CLEAR_DEPTH/STENCIL values.
304    * \param depth  depth clear value in [0,1].
305    * \param stencil  stencil clear value
306    */
307   void (*clear_depth_stencil)(struct pipe_context *pipe,
308                               struct pipe_surface *dst,
309                               unsigned clear_flags,
310                               double depth,
311                               unsigned stencil,
312                               unsigned dstx, unsigned dsty,
313                               unsigned width, unsigned height);
314
315   /** Flush rendering
316    * \param flags  bitmask of PIPE_FLUSH_x tokens)
317    */
318   void (*flush)( struct pipe_context *pipe,
319                  unsigned flags,
320                  struct pipe_fence_handle **fence );
321
322   /**
323    * Check whether a texture is referenced by an unflushed hw command.
324    * The state-tracker uses this function to avoid unnecessary flushes.
325    * It is safe (but wasteful) to always return
326    * PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE.
327    * \param pipe  context whose unflushed hw commands will be checked.
328    * \param texture  texture to check.
329    * \param level  mipmap level.
330    * \param layer  cubemap face, 2d array or 3d slice, 0 otherwise. Use -1 for any layer.
331    * \return mask of PIPE_REFERENCED_FOR_READ/WRITE or PIPE_UNREFERENCED
332    */
333   unsigned int (*is_resource_referenced)(struct pipe_context *pipe,
334                                          struct pipe_resource *texture,
335                                          unsigned level, int layer);
336
337   /**
338    * Create a view on a texture to be used by a shader stage.
339    */
340   struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
341                                                     struct pipe_resource *texture,
342                                                     const struct pipe_sampler_view *templat);
343
344   void (*sampler_view_destroy)(struct pipe_context *ctx,
345                                struct pipe_sampler_view *view);
346
347
348   /**
349    * Get a surface which is a "view" into a resource, used by
350    * render target / depth stencil stages.
351    * \param usage  bitmaks of PIPE_BIND_* flags
352    */
353   struct pipe_surface *(*create_surface)(struct pipe_context *ctx,
354                                          struct pipe_resource *resource,
355                                          const struct pipe_surface *templat);
356
357   void (*surface_destroy)(struct pipe_context *ctx,
358                           struct pipe_surface *);
359
360   /**
361    * Get a transfer object for transferring data to/from a texture.
362    *
363    * Transfers are (by default) context-private and allow uploads to be
364    * interleaved with
365    */
366   struct pipe_transfer *(*get_transfer)(struct pipe_context *,
367                                         struct pipe_resource *resource,
368                                         unsigned level,
369                                         unsigned usage,  /* a combination of PIPE_TRANSFER_x */
370                                         const struct pipe_box *);
371
372   void (*transfer_destroy)(struct pipe_context *,
373                            struct pipe_transfer *);
374
375   void *(*transfer_map)( struct pipe_context *,
376                          struct pipe_transfer *transfer );
377
378   /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
379    * regions specified with this call are guaranteed to be written to
380    * the resource.
381    */
382   void (*transfer_flush_region)( struct pipe_context *,
383				  struct pipe_transfer *transfer,
384				  const struct pipe_box *);
385
386   void (*transfer_unmap)( struct pipe_context *,
387                           struct pipe_transfer *transfer );
388
389
390   /* One-shot transfer operation with data supplied in a user
391    * pointer.  XXX: strides??
392    */
393   void (*transfer_inline_write)( struct pipe_context *,
394                                  struct pipe_resource *,
395                                  unsigned level,
396                                  unsigned usage, /* a combination of PIPE_TRANSFER_x */
397                                  const struct pipe_box *,
398                                  const void *data,
399                                  unsigned stride,
400                                  unsigned layer_stride);
401
402
403   /* Notify a driver that a content of a user buffer has been changed.
404    * The changed range is [offset, offset+size-1].
405    * The new width0 of the buffer is offset+size. */
406   void (*redefine_user_buffer)(struct pipe_context *,
407                                struct pipe_resource *,
408                                unsigned offset,
409                                unsigned size);
410};
411
412
413#ifdef __cplusplus
414}
415#endif
416
417#endif /* PIPE_CONTEXT_H */
418