2 * (C) Copyright IBM Corporation 2002, 2004
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Utility functions for DRI drivers.
29 * \author Ian Romanick <idr@us.ibm.com>
36 #include "main/macros.h"
37 #include "main/mtypes.h"
38 #include "main/cpuinfo.h"
39 #include "main/extensions.h"
45 driParseDebugString( const char * debug
,
46 const struct dri_debug_control
* control
)
50 if ( debug
!= NULL
) {
51 while( control
->string
!= NULL
) {
52 if ( !strcmp( debug
, "all" ) ||
53 strstr( debug
, control
->string
) != NULL
) {
54 flag
|= control
->flag
;
67 * Create the \c GL_RENDERER string for DRI drivers.
69 * Almost all DRI drivers use a \c GL_RENDERER string of the form:
71 * "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
73 * Using the supplied chip name, driver data, and AGP speed, this function
76 * \param buffer Buffer to hold the \c GL_RENDERER string.
77 * \param hardware_name Name of the hardware.
78 * \param agp_mode AGP mode (speed).
81 * The length of the string stored in \c buffer. This does \b not include
82 * the terminating \c NUL character.
85 driGetRendererString( char * buffer
, const char * hardware_name
,
91 offset
= sprintf( buffer
, "Mesa DRI %s", hardware_name
);
93 /* Append any AGP-specific information.
100 offset
+= sprintf( & buffer
[ offset
], " AGP %ux", agp_mode
);
107 /* Append any CPU-specific information.
109 cpu
= _mesa_get_cpu_string();
111 offset
+= sprintf(buffer
+ offset
, " %s", cpu
);
120 * Creates a set of \c struct gl_config that a driver will expose.
122 * A set of \c struct gl_config will be created based on the supplied
123 * parameters. The number of modes processed will be 2 *
124 * \c num_depth_stencil_bits * \c num_db_modes.
126 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
127 * \c db_modes, and \c visType into each \c struct gl_config element.
128 * However, the meanings of \c fb_format and \c fb_type require further
129 * explanation. The \c fb_format specifies which color components are in
130 * each pixel and what the default order is. For example, \c GL_RGB specifies
131 * that red, green, blue are available and red is in the "most significant"
132 * position and blue is in the "least significant". The \c fb_type specifies
133 * the bit sizes of each component and the actual ordering. For example, if
134 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
135 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
138 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
139 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
140 * \c struct gl_config structure is \b identical to the \c GL_RGBA or
141 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
142 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
143 * still uses 32-bits.
145 * If in doubt, look at the tables used in the function.
147 * \param ptr_to_modes Pointer to a pointer to a linked list of
148 * \c struct gl_config. Upon completion, a pointer to
149 * the next element to be process will be stored here.
150 * If the function fails and returns \c GL_FALSE, this
151 * value will be unmodified, but some elements in the
152 * linked list may be modified.
153 * \param format Mesa mesa_format enum describing the pixel format
154 * \param depth_bits Array of depth buffer sizes to be exposed.
155 * \param stencil_bits Array of stencil buffer sizes to be exposed.
156 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
158 * \param db_modes Array of buffer swap modes. If an element has a
159 * value of \c GLX_NONE, then it represents a
160 * single-buffered mode. Other valid values are
161 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
162 * \c GLX_SWAP_UNDEFINED_OML. See the
163 * GLX_OML_swap_method extension spec for more details.
164 * \param num_db_modes Number of entries in \c db_modes.
165 * \param msaa_samples Array of msaa sample count. 0 represents a visual
166 * without a multisample buffer.
167 * \param num_msaa_modes Number of entries in \c msaa_samples.
168 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
169 * \c GLX_DIRECT_COLOR.
172 * Pointer to any array of pointers to the \c __DRIconfig structures created
173 * for the specified formats. If there is an error, \c NULL is returned.
174 * Currently the only cause of failure is a bad parameter (i.e., unsupported
178 driCreateConfigs(mesa_format format
,
179 const uint8_t * depth_bits
, const uint8_t * stencil_bits
,
180 unsigned num_depth_stencil_bits
,
181 const GLenum
* db_modes
, unsigned num_db_modes
,
182 const uint8_t * msaa_samples
, unsigned num_msaa_modes
,
183 GLboolean enable_accum
)
185 static const uint32_t masks_table
[][4] = {
186 /* MESA_FORMAT_B5G6R5_UNORM */
187 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 },
188 /* MESA_FORMAT_B8G8R8X8_UNORM */
189 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 },
190 /* MESA_FORMAT_B8G8R8A8_UNORM */
191 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 },
192 /* MESA_FORMAT_B10G10R10X2_UNORM */
193 { 0x3FF00000, 0x000FFC00, 0x000003FF, 0x00000000 },
194 /* MESA_FORMAT_B10G10R10A2_UNORM */
195 { 0x3FF00000, 0x000FFC00, 0x000003FF, 0xC0000000 },
198 const uint32_t * masks
;
199 __DRIconfig
**configs
, **c
;
200 struct gl_config
*modes
;
203 unsigned num_accum_bits
= (enable_accum
) ? 2 : 1;
211 case MESA_FORMAT_B5G6R5_UNORM
:
212 masks
= masks_table
[0];
214 case MESA_FORMAT_B8G8R8X8_UNORM
:
215 masks
= masks_table
[1];
217 case MESA_FORMAT_B8G8R8A8_UNORM
:
218 case MESA_FORMAT_B8G8R8A8_SRGB
:
219 masks
= masks_table
[2];
221 case MESA_FORMAT_B10G10R10X2_UNORM
:
222 masks
= masks_table
[3];
224 case MESA_FORMAT_B10G10R10A2_UNORM
:
225 masks
= masks_table
[4];
228 fprintf(stderr
, "[%s:%u] Unknown framebuffer type %s (%d).\n",
229 __FUNCTION__
, __LINE__
,
230 _mesa_get_format_name(format
), format
);
234 red_bits
= _mesa_get_format_bits(format
, GL_RED_BITS
);
235 green_bits
= _mesa_get_format_bits(format
, GL_GREEN_BITS
);
236 blue_bits
= _mesa_get_format_bits(format
, GL_BLUE_BITS
);
237 alpha_bits
= _mesa_get_format_bits(format
, GL_ALPHA_BITS
);
238 is_srgb
= _mesa_get_format_color_encoding(format
) == GL_SRGB
;
240 num_modes
= num_depth_stencil_bits
* num_db_modes
* num_accum_bits
* num_msaa_modes
;
241 configs
= calloc(1, (num_modes
+ 1) * sizeof *configs
);
246 for ( k
= 0 ; k
< num_depth_stencil_bits
; k
++ ) {
247 for ( i
= 0 ; i
< num_db_modes
; i
++ ) {
248 for ( h
= 0 ; h
< num_msaa_modes
; h
++ ) {
249 for ( j
= 0 ; j
< num_accum_bits
; j
++ ) {
250 *c
= malloc (sizeof **c
);
251 modes
= &(*c
)->modes
;
254 memset(modes
, 0, sizeof *modes
);
255 modes
->redBits
= red_bits
;
256 modes
->greenBits
= green_bits
;
257 modes
->blueBits
= blue_bits
;
258 modes
->alphaBits
= alpha_bits
;
259 modes
->redMask
= masks
[0];
260 modes
->greenMask
= masks
[1];
261 modes
->blueMask
= masks
[2];
262 modes
->alphaMask
= masks
[3];
263 modes
->rgbBits
= modes
->redBits
+ modes
->greenBits
264 + modes
->blueBits
+ modes
->alphaBits
;
266 modes
->accumRedBits
= 16 * j
;
267 modes
->accumGreenBits
= 16 * j
;
268 modes
->accumBlueBits
= 16 * j
;
269 modes
->accumAlphaBits
= (masks
[3] != 0) ? 16 * j
: 0;
270 modes
->visualRating
= (j
== 0) ? GLX_NONE
: GLX_SLOW_CONFIG
;
272 modes
->stencilBits
= stencil_bits
[k
];
273 modes
->depthBits
= depth_bits
[k
];
275 modes
->transparentPixel
= GLX_NONE
;
276 modes
->transparentRed
= GLX_DONT_CARE
;
277 modes
->transparentGreen
= GLX_DONT_CARE
;
278 modes
->transparentBlue
= GLX_DONT_CARE
;
279 modes
->transparentAlpha
= GLX_DONT_CARE
;
280 modes
->transparentIndex
= GLX_DONT_CARE
;
281 modes
->rgbMode
= GL_TRUE
;
283 if ( db_modes
[i
] == GLX_NONE
) {
284 modes
->doubleBufferMode
= GL_FALSE
;
287 modes
->doubleBufferMode
= GL_TRUE
;
288 modes
->swapMethod
= db_modes
[i
];
291 modes
->samples
= msaa_samples
[h
];
292 modes
->sampleBuffers
= modes
->samples
? 1 : 0;
295 modes
->haveAccumBuffer
= ((modes
->accumRedBits
+
296 modes
->accumGreenBits
+
297 modes
->accumBlueBits
+
298 modes
->accumAlphaBits
) > 0);
299 modes
->haveDepthBuffer
= (modes
->depthBits
> 0);
300 modes
->haveStencilBuffer
= (modes
->stencilBits
> 0);
302 modes
->bindToTextureRgb
= GL_TRUE
;
303 modes
->bindToTextureRgba
= GL_TRUE
;
304 modes
->bindToMipmapTexture
= GL_FALSE
;
305 modes
->bindToTextureTargets
=
306 __DRI_ATTRIB_TEXTURE_1D_BIT
|
307 __DRI_ATTRIB_TEXTURE_2D_BIT
|
308 __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT
;
310 modes
->yInverted
= GL_TRUE
;
311 modes
->sRGBCapable
= is_srgb
;
321 __DRIconfig
**driConcatConfigs(__DRIconfig
**a
,
327 if (a
== NULL
|| a
[0] == NULL
)
329 else if (b
== NULL
|| b
[0] == NULL
)
339 all
= malloc((i
+ j
+ 1) * sizeof *all
);
341 for (i
= 0; a
[i
] != NULL
; i
++)
343 for (j
= 0; b
[j
] != NULL
; j
++)
353 #define __ATTRIB(attrib, field) \
354 { attrib, offsetof(struct gl_config, field) }
356 static const struct { unsigned int attrib
, offset
; } attribMap
[] = {
357 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE
, rgbBits
),
358 __ATTRIB(__DRI_ATTRIB_LEVEL
, level
),
359 __ATTRIB(__DRI_ATTRIB_RED_SIZE
, redBits
),
360 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE
, greenBits
),
361 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE
, blueBits
),
362 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE
, alphaBits
),
363 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE
, depthBits
),
364 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE
, stencilBits
),
365 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE
, accumRedBits
),
366 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE
, accumGreenBits
),
367 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE
, accumBlueBits
),
368 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE
, accumAlphaBits
),
369 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS
, sampleBuffers
),
370 __ATTRIB(__DRI_ATTRIB_SAMPLES
, samples
),
371 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER
, doubleBufferMode
),
372 __ATTRIB(__DRI_ATTRIB_STEREO
, stereoMode
),
373 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS
, numAuxBuffers
),
374 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE
, transparentPixel
),
375 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE
, transparentPixel
),
376 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE
, transparentRed
),
377 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE
, transparentGreen
),
378 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE
, transparentBlue
),
379 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE
, transparentAlpha
),
380 __ATTRIB(__DRI_ATTRIB_RED_MASK
, redMask
),
381 __ATTRIB(__DRI_ATTRIB_GREEN_MASK
, greenMask
),
382 __ATTRIB(__DRI_ATTRIB_BLUE_MASK
, blueMask
),
383 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK
, alphaMask
),
384 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH
, maxPbufferWidth
),
385 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT
, maxPbufferHeight
),
386 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS
, maxPbufferPixels
),
387 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH
, optimalPbufferWidth
),
388 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT
, optimalPbufferHeight
),
389 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, swapMethod
),
390 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB
, bindToTextureRgb
),
391 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
, bindToTextureRgba
),
392 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE
, bindToMipmapTexture
),
393 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS
, bindToTextureTargets
),
394 __ATTRIB(__DRI_ATTRIB_YINVERTED
, yInverted
),
395 __ATTRIB(__DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE
, sRGBCapable
),
397 /* The struct field doesn't matter here, these are handled by the
398 * switch in driGetConfigAttribIndex. We need them in the array
399 * so the iterator includes them though.*/
400 __ATTRIB(__DRI_ATTRIB_RENDER_TYPE
, level
),
401 __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT
, level
),
402 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, level
)
407 * Return the value of a configuration attribute. The attribute is
408 * indicated by the index.
411 driGetConfigAttribIndex(const __DRIconfig
*config
,
412 unsigned int index
, unsigned int *value
)
414 switch (attribMap
[index
].attrib
) {
415 case __DRI_ATTRIB_RENDER_TYPE
:
416 /* no support for color index mode */
417 *value
= __DRI_ATTRIB_RGBA_BIT
;
419 case __DRI_ATTRIB_CONFIG_CAVEAT
:
420 if (config
->modes
.visualRating
== GLX_NON_CONFORMANT_CONFIG
)
421 *value
= __DRI_ATTRIB_NON_CONFORMANT_CONFIG
;
422 else if (config
->modes
.visualRating
== GLX_SLOW_CONFIG
)
423 *value
= __DRI_ATTRIB_SLOW_BIT
;
427 case __DRI_ATTRIB_SWAP_METHOD
:
428 /* XXX no return value??? */
432 /* any other int-sized field */
433 *value
= *(unsigned int *)
434 ((char *) &config
->modes
+ attribMap
[index
].offset
);
444 * Get the value of a configuration attribute.
445 * \param attrib the attribute (one of the _DRI_ATTRIB_x tokens)
446 * \param value returns the attribute's value
447 * \return 1 for success, 0 for failure
450 driGetConfigAttrib(const __DRIconfig
*config
,
451 unsigned int attrib
, unsigned int *value
)
455 for (i
= 0; i
< ARRAY_SIZE(attribMap
); i
++)
456 if (attribMap
[i
].attrib
== attrib
)
457 return driGetConfigAttribIndex(config
, i
, value
);
464 * Get a configuration attribute name and value, given an index.
465 * \param index which field of the __DRIconfig to query
466 * \param attrib returns the attribute name (one of the _DRI_ATTRIB_x tokens)
467 * \param value returns the attribute's value
468 * \return 1 for success, 0 for failure
471 driIndexConfigAttrib(const __DRIconfig
*config
, int index
,
472 unsigned int *attrib
, unsigned int *value
)
474 if (index
>= 0 && index
< ARRAY_SIZE(attribMap
)) {
475 *attrib
= attribMap
[index
].attrib
;
476 return driGetConfigAttribIndex(config
, index
, value
);
483 * Implement queries for values that are common across all Mesa drivers
485 * Currently only the following queries are supported by this function:
487 * - \c __DRI2_RENDERER_VERSION
488 * - \c __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION
489 * - \c __DRI2_RENDERER_OPENGL_COMPATIBLITY_PROFILE_VERSION
490 * - \c __DRI2_RENDERER_ES_PROFILE_VERSION
491 * - \c __DRI2_RENDERER_ES2_PROFILE_VERSION
494 * Zero if a recognized value of \c param is supplied, -1 otherwise.
497 driQueryRendererIntegerCommon(__DRIscreen
*psp
, int param
, unsigned int *value
)
500 case __DRI2_RENDERER_VERSION
: {
501 static const char *const ver
= PACKAGE_VERSION
;
505 v
[0] = strtol(ver
, &endptr
, 10);
506 assert(endptr
[0] == '.');
507 if (endptr
[0] != '.')
510 v
[1] = strtol(endptr
+ 1, &endptr
, 10);
511 assert(endptr
[0] == '.');
512 if (endptr
[0] != '.')
515 v
[2] = strtol(endptr
+ 1, &endptr
, 10);
522 case __DRI2_RENDERER_PREFERRED_PROFILE
:
523 value
[0] = (psp
->max_gl_core_version
!= 0)
524 ? (1U << __DRI_API_OPENGL_CORE
) : (1U << __DRI_API_OPENGL
);
526 case __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION
:
527 value
[0] = psp
->max_gl_core_version
/ 10;
528 value
[1] = psp
->max_gl_core_version
% 10;
530 case __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION
:
531 value
[0] = psp
->max_gl_compat_version
/ 10;
532 value
[1] = psp
->max_gl_compat_version
% 10;
534 case __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION
:
535 value
[0] = psp
->max_gl_es1_version
/ 10;
536 value
[1] = psp
->max_gl_es1_version
% 10;
538 case __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION
:
539 value
[0] = psp
->max_gl_es2_version
/ 10;
540 value
[1] = psp
->max_gl_es2_version
% 10;