xref: /aosp_15_r20/external/mesa3d/src/mesa/main/dd.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 "util/glheader.h"
35 #include "formats.h"
36 #include "menums.h"
37 #include "compiler/shader_enums.h"
38 
39 #if defined(_WIN32) && defined(_WINDOWS_)
40 #error "Should not include <windows.h> here"
41 #endif
42 
43 struct gl_buffer_object;
44 struct gl_context;
45 struct gl_display_list;
46 struct gl_framebuffer;
47 struct gl_image_unit;
48 struct gl_pixelstore_attrib;
49 struct gl_program;
50 struct gl_renderbuffer;
51 struct gl_renderbuffer_attachment;
52 struct gl_shader;
53 struct gl_shader_program;
54 struct gl_texture_image;
55 struct gl_texture_object;
56 struct gl_memory_info;
57 struct gl_memory_object;
58 struct gl_query_object;
59 struct gl_sampler_object;
60 struct gl_transform_feedback_object;
61 struct gl_vertex_array_object;
62 struct ati_fragment_shader;
63 struct util_queue_monitoring;
64 struct pipe_draw_info;
65 struct pipe_draw_indirect_info;
66 struct pipe_draw_start_count_bias;
67 struct pipe_vertex_state;
68 struct pipe_draw_vertex_state_info;
69 struct pipe_vertex_buffer;
70 struct pipe_vertex_element;
71 
72 /* GL_ARB_vertex_buffer_object */
73 /* Modifies GL_MAP_UNSYNCHRONIZED_BIT to allow driver to fail (return
74  * NULL) if buffer is unavailable for immediate mapping.
75  *
76  * Does GL_MAP_INVALIDATE_RANGE_BIT do this?  It seems so, but it
77  * would require more book-keeping in the driver than seems necessary
78  * at this point.
79  *
80  * Does GL_MAP_INVALIDATE_BUFFER_BIT do this?  Not really -- we don't
81  * want to provoke the driver to throw away the old storage, we will
82  * respect the contents of already referenced data.
83  */
84 #define MESA_MAP_NOWAIT_BIT       0x4000
85 
86 /* Mapping a buffer is allowed from any thread. */
87 #define MESA_MAP_THREAD_SAFE_BIT  0x8000
88 
89 /* This buffer will only be mapped/unmapped once */
90 #define MESA_MAP_ONCE            0x10000
91 
92 /* This BufferStorage flag indicates that the buffer will be used
93  * by pipe_vertex_state, which doesn't track buffer busyness and doesn't
94  * support invalidations.
95  */
96 #define MESA_GALLIUM_VERTEX_STATE_STORAGE 0x20000
97 
98 
99 /**
100  * Device driver function table.
101  * Core Mesa uses these function pointers to call into device drivers.
102  * Most of these functions directly correspond to OpenGL state commands.
103  * Core Mesa will call these functions after error checking has been done
104  * so that the drivers don't have to worry about error testing.
105  *
106  * Vertex transformation/clipping/lighting is patched into the T&L module.
107  * Rasterization functions are patched into the swrast module.
108  *
109  * Note: when new functions are added here, the drivers/common/driverfuncs.c
110  * file should be updated too!!!
111  */
112 struct dd_function_table {
113    /**
114     * \name Vertex/fragment program functions
115     */
116    /** Allocate a new program */
117    struct gl_program * (*NewProgram)(struct gl_context *ctx,
118                                      gl_shader_stage stage,
119                                      GLuint id, bool is_arb_asm);
120    /**
121     * \name Draw functions.
122     */
123    /*@{*/
124    /**
125     * For indirect array drawing:
126     *
127     *    typedef struct {
128     *       GLuint count;
129     *       GLuint primCount;
130     *       GLuint first;
131     *       GLuint baseInstance; // in GL 4.2 and later, must be zero otherwise
132     *    } DrawArraysIndirectCommand;
133     *
134     * For indirect indexed drawing:
135     *
136     *    typedef struct {
137     *       GLuint count;
138     *       GLuint primCount;
139     *       GLuint firstIndex;
140     *       GLint  baseVertex;
141     *       GLuint baseInstance; // in GL 4.2 and later, must be zero otherwise
142     *    } DrawElementsIndirectCommand;
143     */
144 
145    /**
146     * The basic draw function used to implement glDrawArrays, glDrawElements,
147     * multidraws, and instancing.
148     *
149     * The interface is identical to pipe_context::draw_vbo.
150     */
151    void (*DrawGallium)(struct gl_context *ctx,
152                        const struct pipe_draw_info *info,
153                        unsigned drawid_offset,
154                        const struct pipe_draw_indirect_info *indirect,
155                        const struct pipe_draw_start_count_bias *draws,
156                        unsigned num_draws);
157 
158    /**
159     * Same as DrawGallium, but mode can also change between draws.
160     *
161     * "info" is not const and the following fields can be changed by
162     * the callee in addition to the fields listed by DrawGallium:
163     * - info->mode
164     *
165     * This function exists to decrease complexity of DrawGallium.
166     */
167    void (*DrawGalliumMultiMode)(struct gl_context *ctx,
168                                 struct pipe_draw_info *info,
169                                 const struct pipe_draw_start_count_bias *draws,
170                                 const unsigned char *mode,
171                                 unsigned num_draws);
172    /*@}*/
173 
174    /**
175     * \name Support for multiple T&L engines
176     */
177    /*@{*/
178 
179    /**
180     * Set by the driver-supplied T&L engine.
181     *
182     * Set to PRIM_OUTSIDE_BEGIN_END when outside glBegin()/glEnd().
183     */
184    GLuint CurrentExecPrimitive;
185 
186    /**
187     * Current glBegin state of an in-progress compilation.  May be
188     * GL_POINTS, GL_TRIANGLE_STRIP, etc. or PRIM_OUTSIDE_BEGIN_END
189     * or PRIM_UNKNOWN.
190     */
191    GLuint CurrentSavePrimitive;
192 
193 
194 #define FLUSH_STORED_VERTICES 0x1
195 #define FLUSH_UPDATE_CURRENT  0x2
196    /**
197     * Set by the driver-supplied T&L engine whenever vertices are buffered
198     * between glBegin()/glEnd() objects or __struct gl_contextRec::Current
199     * is not updated.  A bitmask of the FLUSH_x values above.
200     *
201     * The dd_function_table::FlushVertices call below may be used to resolve
202     * these conditions.
203     */
204    GLbitfield NeedFlush;
205 
206    /** Need to call vbo_save_SaveFlushVertices() upon state change? */
207    GLboolean SaveNeedFlush;
208 
209    /**@}*/
210 
211    /**
212     * Query reset status for GL_ARB_robustness
213     *
214     * Per \c glGetGraphicsResetStatusARB, this function should return a
215     * non-zero value once after a reset.  If a reset is non-atomic, the
216     * non-zero status should be returned for the duration of the reset.
217     */
218    GLenum (*GetGraphicsResetStatus)(struct gl_context *ctx);
219 
220    /**
221     * \name GL_ARB_get_program_binary
222     */
223    /*@{*/
224    /**
225     * Calls to retrieve/store a binary serialized copy of the current program.
226     */
227    void (*ProgramBinarySerializeDriverBlob)(struct gl_context *ctx,
228                                             struct gl_shader_program *shProg,
229                                             struct gl_program *prog);
230 
231    void (*ProgramBinaryDeserializeDriverBlob)(struct gl_context *ctx,
232                                               struct gl_shader_program *shProg,
233                                               struct gl_program *prog);
234    /*@}*/
235 
236    /**
237     * \name Disk shader cache functions
238     */
239    /*@{*/
240    /**
241     * Called to initialize gl_program::driver_cache_blob (and size) with a
242     * ralloc allocated buffer.
243     *
244     * This buffer will be saved and restored as part of the gl_program
245     * serialization and deserialization.
246     */
247    void (*ShaderCacheSerializeDriverBlob)(struct gl_context *ctx,
248                                           struct gl_program *prog);
249    /*@}*/
250 };
251 
252 #endif /* DD_INCLUDED */
253