i965/fs_nir: Do retyping for ALU srouces in get_nir_alu_src
[mesa.git] / src / mesa / drivers / dri / common / dri_util.h
1 /*
2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file dri_util.h
28 * DRI utility functions definitions.
29 *
30 * This module acts as glue between GLX and the actual hardware driver. A DRI
31 * driver doesn't really \e have to use any of this - it's optional. But, some
32 * useful stuff is done here that otherwise would have to be duplicated in most
33 * drivers.
34 *
35 * Basically, these utility functions take care of some of the dirty details of
36 * screen initialization, context creation, context binding, DRM setup, etc.
37 *
38 * These functions are compiled into each DRI driver so libGL.so knows nothing
39 * about them.
40 *
41 * \sa dri_util.c.
42 *
43 * \author Kevin E. Martin <kevin@precisioninsight.com>
44 * \author Brian Paul <brian@precisioninsight.com>
45 */
46
47 /**
48 * The following structs are shared between DRISW and DRI2, the DRISW structs
49 * are essentially base classes of the DRI2 structs. DRISW needs to compile on
50 * platforms without DRM, so keep the structs opaque to DRM.
51 */
52
53 #ifndef _DRI_UTIL_H_
54 #define _DRI_UTIL_H_
55
56 #include <GL/gl.h>
57 #include <GL/internal/dri_interface.h>
58 #include "main/mtypes.h"
59 #include "xmlconfig.h"
60 #include <stdbool.h>
61
62 /**
63 * Extensions.
64 */
65 extern const __DRIcoreExtension driCoreExtension;
66 extern const __DRIswrastExtension driSWRastExtension;
67 extern const __DRIdri2Extension driDRI2Extension;
68 extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
69 extern const __DRIcopySubBufferExtension driCopySubBufferExtension;
70 /**
71 * Driver callback functions.
72 *
73 * Each DRI driver must have one of these structures with all the pointers set
74 * to appropriate functions within the driver.
75 *
76 * When glXCreateContext() is called, for example, it'll call a helper function
77 * dri_util.c which in turn will jump through the \a CreateContext pointer in
78 * this structure.
79 */
80 struct __DriverAPIRec {
81 const __DRIconfig **(*InitScreen) (__DRIscreen * priv);
82
83 void (*DestroyScreen)(__DRIscreen *driScrnPriv);
84
85 GLboolean (*CreateContext)(gl_api api,
86 const struct gl_config *glVis,
87 __DRIcontext *driContextPriv,
88 unsigned major_version,
89 unsigned minor_version,
90 uint32_t flags,
91 bool notify_reset,
92 unsigned *error,
93 void *sharedContextPrivate);
94
95 void (*DestroyContext)(__DRIcontext *driContextPriv);
96
97 GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
98 __DRIdrawable *driDrawPriv,
99 const struct gl_config *glVis,
100 GLboolean pixmapBuffer);
101
102 void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
103
104 void (*SwapBuffers)(__DRIdrawable *driDrawPriv);
105
106 GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv,
107 __DRIdrawable *driDrawPriv,
108 __DRIdrawable *driReadPriv);
109
110 GLboolean (*UnbindContext)(__DRIcontext *driContextPriv);
111
112 __DRIbuffer *(*AllocateBuffer) (__DRIscreen *screenPrivate,
113 unsigned int attachment,
114 unsigned int format,
115 int width, int height);
116
117 void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
118
119 void (*CopySubBuffer)(__DRIdrawable *driDrawPriv, int x, int y,
120 int w, int h);
121 };
122
123 extern const struct __DriverAPIRec driDriverAPI;
124 extern const struct __DriverAPIRec *globalDriverAPI;
125
126 /**
127 * Per-screen private driver information.
128 */
129 struct __DRIscreenRec {
130 /**
131 * Driver-specific entrypoints provided by the driver's
132 * __DRIDriverVtableExtensionRec.
133 */
134 const struct __DriverAPIRec *driver;
135
136 /**
137 * Current screen's number
138 */
139 int myNum;
140
141 /**
142 * File descriptor returned when the kernel device driver is opened.
143 *
144 * Used to:
145 * - authenticate client to kernel
146 * - map the frame buffer, SAREA, etc.
147 * - close the kernel device driver
148 */
149 int fd;
150
151 /**
152 * DRM (kernel module) version information.
153 */
154 __DRIversion drm_version;
155
156 /**
157 * Device-dependent private information (not stored in the SAREA).
158 *
159 * This pointer is never touched by the DRI layer.
160 */
161 void *driverPrivate;
162
163 void *loaderPrivate;
164
165 int max_gl_core_version;
166 int max_gl_compat_version;
167 int max_gl_es1_version;
168 int max_gl_es2_version;
169
170 const __DRIextension **extensions;
171
172 const __DRIswrastLoaderExtension *swrast_loader;
173
174 struct {
175 /* Flag to indicate that this is a DRI2 screen. Many of the above
176 * fields will not be valid or initializaed in that case. */
177 const __DRIdri2LoaderExtension *loader;
178 const __DRIimageLookupExtension *image;
179 const __DRIuseInvalidateExtension *useInvalidate;
180 } dri2;
181
182 struct {
183 const __DRIimageLoaderExtension *loader;
184 } image;
185
186 driOptionCache optionInfo;
187 driOptionCache optionCache;
188
189 unsigned int api_mask;
190 };
191
192 /**
193 * Per-context private driver information.
194 */
195 struct __DRIcontextRec {
196 /**
197 * Device driver's private context data. This structure is opaque.
198 */
199 void *driverPrivate;
200
201 /**
202 * The loaders's private context data. This structure is opaque.
203 */
204 void *loaderPrivate;
205
206 /**
207 * Pointer to drawable currently bound to this context for drawing.
208 */
209 __DRIdrawable *driDrawablePriv;
210
211 /**
212 * Pointer to drawable currently bound to this context for reading.
213 */
214 __DRIdrawable *driReadablePriv;
215
216 /**
217 * Pointer to screen on which this context was created.
218 */
219 __DRIscreen *driScreenPriv;
220
221 struct {
222 int draw_stamp;
223 int read_stamp;
224 } dri2;
225 };
226
227 /**
228 * Per-drawable private DRI driver information.
229 */
230 struct __DRIdrawableRec {
231 /**
232 * Driver's private drawable information.
233 *
234 * This structure is opaque.
235 */
236 void *driverPrivate;
237
238 /**
239 * Private data from the loader. We just hold on to it and pass
240 * it back when calling into loader provided functions.
241 */
242 void *loaderPrivate;
243
244 /**
245 * Pointer to context to which this drawable is currently bound.
246 */
247 __DRIcontext *driContextPriv;
248
249 /**
250 * Pointer to screen on which this drawable was created.
251 */
252 __DRIscreen *driScreenPriv;
253
254 /**
255 * Reference count for number of context's currently bound to this
256 * drawable.
257 *
258 * Once it reaches zero, the drawable can be destroyed.
259 *
260 * \note This behavior will change with GLX 1.3.
261 */
262 int refcount;
263
264 /**
265 * Last value of the stamp.
266 *
267 * If this differs from the value stored at __DRIdrawable::dri2.stamp,
268 * then the drawable information has been modified by the X server, and the
269 * drawable information (below) should be retrieved from the X server.
270 */
271 unsigned int lastStamp;
272
273 int w, h;
274
275 /**
276 * Drawable timestamp. Increased when the loader calls invalidate.
277 */
278 struct {
279 unsigned int stamp;
280 } dri2;
281 };
282
283 extern uint32_t
284 driGLFormatToImageFormat(mesa_format format);
285
286 extern mesa_format
287 driImageFormatToGLFormat(uint32_t image_format);
288
289 extern void
290 dri2InvalidateDrawable(__DRIdrawable *drawable);
291
292 extern void
293 driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv);
294
295 extern void
296 driContextSetFlags(struct gl_context *ctx, uint32_t flags);
297
298 extern const __DRIimageDriverExtension driImageDriverExtension;
299
300 #endif /* _DRI_UTIL_H_ */