xref: /third_party/mesa3d/src/mesa/main/dd.h (revision bf215546)
1/**
2 * \file dd.h
3 * Device driver interfaces.
4 */
5
6/*
7 * Mesa 3-D graphics library
8 *
9 * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30
31#ifndef DD_INCLUDED
32#define DD_INCLUDED
33
34#include "glheader.h"
35#include "formats.h"
36#include "menums.h"
37#include "compiler/shader_enums.h"
38
39/* Windows winnt.h defines MemoryBarrier as a macro on some platforms,
40 * including as a function-like macro in some cases. That either causes
41 * the table entry below to have a weird name, or fail to compile.
42 */
43#ifdef MemoryBarrier
44#undef MemoryBarrier
45#endif
46
47struct gl_bitmap_atlas;
48struct gl_buffer_object;
49struct gl_context;
50struct gl_display_list;
51struct gl_framebuffer;
52struct gl_image_unit;
53struct gl_pixelstore_attrib;
54struct gl_program;
55struct gl_renderbuffer;
56struct gl_renderbuffer_attachment;
57struct gl_shader;
58struct gl_shader_program;
59struct gl_texture_image;
60struct gl_texture_object;
61struct gl_memory_info;
62struct gl_memory_object;
63struct gl_query_object;
64struct gl_sampler_object;
65struct gl_transform_feedback_object;
66struct gl_vertex_array_object;
67struct ati_fragment_shader;
68struct util_queue_monitoring;
69struct _mesa_prim;
70struct _mesa_index_buffer;
71struct pipe_draw_info;
72struct pipe_draw_start_count_bias;
73struct pipe_vertex_state;
74struct pipe_draw_vertex_state_info;
75struct pipe_vertex_buffer;
76struct pipe_vertex_element;
77
78/* GL_ARB_vertex_buffer_object */
79/* Modifies GL_MAP_UNSYNCHRONIZED_BIT to allow driver to fail (return
80 * NULL) if buffer is unavailable for immediate mapping.
81 *
82 * Does GL_MAP_INVALIDATE_RANGE_BIT do this?  It seems so, but it
83 * would require more book-keeping in the driver than seems necessary
84 * at this point.
85 *
86 * Does GL_MAP_INVALDIATE_BUFFER_BIT do this?  Not really -- we don't
87 * want to provoke the driver to throw away the old storage, we will
88 * respect the contents of already referenced data.
89 */
90#define MESA_MAP_NOWAIT_BIT       0x4000
91
92/* Mapping a buffer is allowed from any thread. */
93#define MESA_MAP_THREAD_SAFE_BIT  0x8000
94
95/* This buffer will only be mapped/unmapped once */
96#define MESA_MAP_ONCE            0x10000
97
98/* This BufferStorage flag indicates that the buffer will be used
99 * by pipe_vertex_state, which doesn't track buffer busyness and doesn't
100 * support invalidations.
101 */
102#define MESA_GALLIUM_VERTEX_STATE_STORAGE 0x20000
103
104
105/**
106 * Device driver function table.
107 * Core Mesa uses these function pointers to call into device drivers.
108 * Most of these functions directly correspond to OpenGL state commands.
109 * Core Mesa will call these functions after error checking has been done
110 * so that the drivers don't have to worry about error testing.
111 *
112 * Vertex transformation/clipping/lighting is patched into the T&L module.
113 * Rasterization functions are patched into the swrast module.
114 *
115 * Note: when new functions are added here, the drivers/common/driverfuncs.c
116 * file should be updated too!!!
117 */
118struct dd_function_table {
119   /**
120    * \name Vertex/fragment program functions
121    */
122   /** Allocate a new program */
123   struct gl_program * (*NewProgram)(struct gl_context *ctx,
124                                     gl_shader_stage stage,
125                                     GLuint id, bool is_arb_asm);
126   /**
127    * \name Draw functions.
128    */
129   /*@{*/
130   /**
131    * For indirect array drawing:
132    *
133    *    typedef struct {
134    *       GLuint count;
135    *       GLuint primCount;
136    *       GLuint first;
137    *       GLuint baseInstance; // in GL 4.2 and later, must be zero otherwise
138    *    } DrawArraysIndirectCommand;
139    *
140    * For indirect indexed drawing:
141    *
142    *    typedef struct {
143    *       GLuint count;
144    *       GLuint primCount;
145    *       GLuint firstIndex;
146    *       GLint  baseVertex;
147    *       GLuint baseInstance; // in GL 4.2 and later, must be zero otherwise
148    *    } DrawElementsIndirectCommand;
149    */
150
151   /**
152    * Optimal Gallium version of Draw() that doesn't require translation
153    * of draw info in the state tracker.
154    *
155    * The interface is identical to pipe_context::draw_vbo
156    * with indirect == NULL.
157    *
158    * "info" is not const and the following fields can be changed by
159    * the callee, so callers should be aware:
160    * - info->index_bounds_valid (if false)
161    * - info->min_index (if index_bounds_valid is false)
162    * - info->max_index (if index_bounds_valid is false)
163    * - info->drawid (if increment_draw_id is true)
164    * - info->index.gl_bo (if index_size && !has_user_indices)
165    */
166   void (*DrawGallium)(struct gl_context *ctx,
167                       struct pipe_draw_info *info,
168                       unsigned drawid_offset,
169                       const struct pipe_draw_start_count_bias *draws,
170                       unsigned num_draws);
171
172   /**
173    * Same as DrawGallium, but mode can also change between draws.
174    *
175    * "info" is not const and the following fields can be changed by
176    * the callee in addition to the fields listed by DrawGallium:
177    * - info->mode
178    *
179    * This function exists to decrease complexity of DrawGallium.
180    */
181   void (*DrawGalliumMultiMode)(struct gl_context *ctx,
182                                struct pipe_draw_info *info,
183                                const struct pipe_draw_start_count_bias *draws,
184                                const unsigned char *mode,
185                                unsigned num_draws);
186
187   void (*DrawGalliumVertexState)(struct gl_context *ctx,
188                                  struct pipe_vertex_state *state,
189                                  struct pipe_draw_vertex_state_info info,
190                                  const struct pipe_draw_start_count_bias *draws,
191                                  const uint8_t *mode,
192                                  unsigned num_draws,
193                                  bool per_vertex_edgeflags);
194   /*@}*/
195
196   struct pipe_vertex_state *
197      (*CreateGalliumVertexState)(struct gl_context *ctx,
198                                  const struct gl_vertex_array_object *vao,
199                                  struct gl_buffer_object *indexbuf,
200                                  uint32_t enabled_attribs);
201
202   /**
203    * \name Support for multiple T&L engines
204    */
205   /*@{*/
206
207   /**
208    * Set by the driver-supplied T&L engine.
209    *
210    * Set to PRIM_OUTSIDE_BEGIN_END when outside glBegin()/glEnd().
211    */
212   GLuint CurrentExecPrimitive;
213
214   /**
215    * Current glBegin state of an in-progress compilation.  May be
216    * GL_POINTS, GL_TRIANGLE_STRIP, etc. or PRIM_OUTSIDE_BEGIN_END
217    * or PRIM_UNKNOWN.
218    */
219   GLuint CurrentSavePrimitive;
220
221
222#define FLUSH_STORED_VERTICES 0x1
223#define FLUSH_UPDATE_CURRENT  0x2
224   /**
225    * Set by the driver-supplied T&L engine whenever vertices are buffered
226    * between glBegin()/glEnd() objects or __struct gl_contextRec::Current
227    * is not updated.  A bitmask of the FLUSH_x values above.
228    *
229    * The dd_function_table::FlushVertices call below may be used to resolve
230    * these conditions.
231    */
232   GLbitfield NeedFlush;
233
234   /** Need to call vbo_save_SaveFlushVertices() upon state change? */
235   GLboolean SaveNeedFlush;
236
237   /**@}*/
238
239   /**
240    * Query reset status for GL_ARB_robustness
241    *
242    * Per \c glGetGraphicsResetStatusARB, this function should return a
243    * non-zero value once after a reset.  If a reset is non-atomic, the
244    * non-zero status should be returned for the duration of the reset.
245    */
246   GLenum (*GetGraphicsResetStatus)(struct gl_context *ctx);
247
248   /**
249    * \name GL_ARB_get_program_binary
250    */
251   /*@{*/
252   /**
253    * Calls to retrieve/store a binary serialized copy of the current program.
254    */
255   void (*ProgramBinarySerializeDriverBlob)(struct gl_context *ctx,
256                                            struct gl_shader_program *shProg,
257                                            struct gl_program *prog);
258
259   void (*ProgramBinaryDeserializeDriverBlob)(struct gl_context *ctx,
260                                              struct gl_shader_program *shProg,
261                                              struct gl_program *prog);
262   /*@}*/
263
264   /**
265    * \name Disk shader cache functions
266    */
267   /*@{*/
268   /**
269    * Called to initialize gl_program::driver_cache_blob (and size) with a
270    * ralloc allocated buffer.
271    *
272    * This buffer will be saved and restored as part of the gl_program
273    * serialization and deserialization.
274    */
275   void (*ShaderCacheSerializeDriverBlob)(struct gl_context *ctx,
276                                          struct gl_program *prog);
277   /*@}*/
278
279   GLboolean (*ValidateEGLImage)(struct gl_context *ctx, GLeglImageOES image_handle);
280};
281
282#endif /* DD_INCLUDED */
283