1 /**************************************************************************
3 * Copyright 2009, VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 VMWARE 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.
26 **************************************************************************/
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
35 #include "dri_screen.h"
37 #include "util/u_inlines.h"
38 #include "pipe/p_screen.h"
39 #include "pipe/p_format.h"
40 #include "state_tracker/st_gl_api.h" /* for st_gl_api_create */
41 #include "state_tracker/drm_driver.h"
43 #include "util/u_debug.h"
45 #define MSAA_VISUAL_MAX_SAMPLES 32
49 PUBLIC
const char __driConfigOptions
[] =
51 DRI_CONF_SECTION_PERFORMANCE
52 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
53 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
56 DRI_CONF_SECTION_QUALITY
57 /* DRI_CONF_FORCE_S3TC_ENABLE("false") */
58 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
59 DRI_CONF_PP_CELSHADE(0)
61 DRI_CONF_PP_NOGREEN(0)
63 DRI_CONF_PP_JIMENEZMLAA(0, 0, 32)
64 DRI_CONF_PP_JIMENEZMLAA_COLOR(0, 0, 32)
67 DRI_CONF_SECTION_DEBUG
68 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
69 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
72 DRI_CONF_SECTION_MISCELLANEOUS
73 DRI_CONF_ALWAYS_HAVE_DEPTH_BUFFER("false")
79 static const uint __driNConfigOptions
= 12;
81 static const __DRIconfig
**
82 dri_fill_in_modes(struct dri_screen
*screen
)
84 static const gl_format mesa_formats
[3] = {
89 static const enum pipe_format pipe_formats
[3] = {
90 PIPE_FORMAT_BGRA8888_UNORM
,
91 PIPE_FORMAT_BGRX8888_UNORM
,
92 PIPE_FORMAT_B5G6R5_UNORM
,
95 __DRIconfig
**configs
= NULL
;
96 uint8_t depth_bits_array
[5];
97 uint8_t stencil_bits_array
[5];
98 unsigned depth_buffer_factor
;
99 unsigned msaa_samples_max
;
101 struct pipe_screen
*p_screen
= screen
->base
.screen
;
102 boolean pf_z16
, pf_x8z24
, pf_z24x8
, pf_s8z24
, pf_z24s8
, pf_z32
;
104 static const GLenum back_buffer_modes
[] = {
105 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
108 if (driQueryOptionb(&screen
->optionCache
, "always_have_depth_buffer")) {
109 /* all visuals will have a depth buffer */
110 depth_buffer_factor
= 0;
113 depth_bits_array
[0] = 0;
114 stencil_bits_array
[0] = 0;
115 depth_buffer_factor
= 1;
118 msaa_samples_max
= (screen
->st_api
->feature_mask
& ST_API_FEATURE_MS_VISUALS_MASK
)
119 ? MSAA_VISUAL_MAX_SAMPLES
: 1;
121 pf_x8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24X8_UNORM
,
123 PIPE_BIND_DEPTH_STENCIL
);
124 pf_z24x8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8Z24_UNORM
,
126 PIPE_BIND_DEPTH_STENCIL
);
127 pf_s8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24_UNORM_S8_UINT
,
129 PIPE_BIND_DEPTH_STENCIL
);
130 pf_z24s8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_S8_UINT_Z24_UNORM
,
132 PIPE_BIND_DEPTH_STENCIL
);
133 pf_z16
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z16_UNORM
,
135 PIPE_BIND_DEPTH_STENCIL
);
136 pf_z32
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z32_UNORM
,
138 PIPE_BIND_DEPTH_STENCIL
);
141 depth_bits_array
[depth_buffer_factor
] = 16;
142 stencil_bits_array
[depth_buffer_factor
++] = 0;
144 if (pf_x8z24
|| pf_z24x8
) {
145 depth_bits_array
[depth_buffer_factor
] = 24;
146 stencil_bits_array
[depth_buffer_factor
++] = 0;
147 screen
->d_depth_bits_last
= pf_x8z24
;
149 if (pf_s8z24
|| pf_z24s8
) {
150 depth_bits_array
[depth_buffer_factor
] = 24;
151 stencil_bits_array
[depth_buffer_factor
++] = 8;
152 screen
->sd_depth_bits_last
= pf_s8z24
;
155 depth_bits_array
[depth_buffer_factor
] = 32;
156 stencil_bits_array
[depth_buffer_factor
++] = 0;
159 assert(Elements(mesa_formats
) == Elements(pipe_formats
));
162 for (format
= 0; format
< Elements(mesa_formats
); format
++) {
163 __DRIconfig
**new_configs
= NULL
;
164 unsigned num_msaa_modes
= 0; /* includes a single-sample mode */
165 uint8_t msaa_modes
[MSAA_VISUAL_MAX_SAMPLES
];
167 for (i
= 1; i
<= msaa_samples_max
; i
++) {
168 int samples
= i
> 1 ? i
: 0;
170 if (p_screen
->is_format_supported(p_screen
, pipe_formats
[format
],
171 PIPE_TEXTURE_2D
, samples
,
172 PIPE_BIND_RENDER_TARGET
)) {
173 msaa_modes
[num_msaa_modes
++] = samples
;
177 if (num_msaa_modes
) {
178 /* Single-sample configs with an accumulation buffer. */
179 new_configs
= driCreateConfigs(mesa_formats
[format
],
180 depth_bits_array
, stencil_bits_array
,
181 depth_buffer_factor
, back_buffer_modes
,
182 Elements(back_buffer_modes
),
185 configs
= driConcatConfigs(configs
, new_configs
);
187 /* Multi-sample configs without an accumulation buffer. */
188 if (num_msaa_modes
> 1) {
189 new_configs
= driCreateConfigs(mesa_formats
[format
],
190 depth_bits_array
, stencil_bits_array
,
191 depth_buffer_factor
, back_buffer_modes
,
192 Elements(back_buffer_modes
),
193 msaa_modes
+1, num_msaa_modes
-1,
195 configs
= driConcatConfigs(configs
, new_configs
);
200 if (configs
== NULL
) {
201 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
205 return (const __DRIconfig
**)configs
;
208 /* The Gallium way to force MSAA. */
209 DEBUG_GET_ONCE_NUM_OPTION(msaa
, "GALLIUM_MSAA", 0);
211 /* The NVIDIA way to force MSAA. The same variable is used by the NVIDIA
213 DEBUG_GET_ONCE_NUM_OPTION(msaa_nv
, "__GL_FSAA_MODE", 0);
216 dri_force_msaa_visual(struct st_visual
*stvis
,
217 struct pipe_screen
*screen
)
220 int samples
= debug_get_option_msaa();
223 samples
= debug_get_option_msaa_nv();
226 return; /* nothing to do */
228 /* Choose a supported sample count greater than or equal to samples. */
229 for (i
= samples
; i
<= MSAA_VISUAL_MAX_SAMPLES
; i
++) {
230 if (screen
->is_format_supported(screen
, stvis
->color_format
,
232 PIPE_BIND_RENDER_TARGET
)) {
240 * Roughly the converse of dri_fill_in_modes.
243 dri_fill_st_visual(struct st_visual
*stvis
, struct dri_screen
*screen
,
244 const struct gl_config
*mode
)
246 memset(stvis
, 0, sizeof(*stvis
));
251 if (mode
->redBits
== 8) {
252 if (mode
->alphaBits
== 8)
253 stvis
->color_format
= PIPE_FORMAT_BGRA8888_UNORM
;
255 stvis
->color_format
= PIPE_FORMAT_BGRX8888_UNORM
;
257 stvis
->color_format
= PIPE_FORMAT_B5G6R5_UNORM
;
260 if (mode
->sampleBuffers
) {
261 stvis
->samples
= mode
->samples
;
264 /* This must be done after stvis->color_format is set. */
265 dri_force_msaa_visual(stvis
, screen
->base
.screen
);
268 switch (mode
->depthBits
) {
271 stvis
->depth_stencil_format
= PIPE_FORMAT_NONE
;
274 stvis
->depth_stencil_format
= PIPE_FORMAT_Z16_UNORM
;
277 if (mode
->stencilBits
== 0) {
278 stvis
->depth_stencil_format
= (screen
->d_depth_bits_last
) ?
279 PIPE_FORMAT_Z24X8_UNORM
:
280 PIPE_FORMAT_X8Z24_UNORM
;
282 stvis
->depth_stencil_format
= (screen
->sd_depth_bits_last
) ?
283 PIPE_FORMAT_Z24_UNORM_S8_UINT
:
284 PIPE_FORMAT_S8_UINT_Z24_UNORM
;
288 stvis
->depth_stencil_format
= PIPE_FORMAT_Z32_UNORM
;
292 stvis
->accum_format
= (mode
->haveAccumBuffer
) ?
293 PIPE_FORMAT_R16G16B16A16_SNORM
: PIPE_FORMAT_NONE
;
295 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_LEFT_MASK
;
296 stvis
->render_buffer
= ST_ATTACHMENT_FRONT_LEFT
;
297 if (mode
->doubleBufferMode
) {
298 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_LEFT_MASK
;
299 stvis
->render_buffer
= ST_ATTACHMENT_BACK_LEFT
;
301 if (mode
->stereoMode
) {
302 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_RIGHT_MASK
;
303 if (mode
->doubleBufferMode
)
304 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_RIGHT_MASK
;
307 if (mode
->haveDepthBuffer
|| mode
->haveStencilBuffer
)
308 stvis
->buffer_mask
|= ST_ATTACHMENT_DEPTH_STENCIL_MASK
;
309 /* let the state tracker allocate the accum buffer */
313 dri_get_egl_image(struct st_manager
*smapi
,
315 struct st_egl_image
*stimg
)
317 struct dri_screen
*screen
= (struct dri_screen
*)smapi
;
318 __DRIimage
*img
= NULL
;
320 if (screen
->lookup_egl_image
) {
321 img
= screen
->lookup_egl_image(screen
, egl_image
);
327 stimg
->texture
= NULL
;
328 pipe_resource_reference(&stimg
->texture
, img
->texture
);
329 stimg
->level
= img
->level
;
330 stimg
->layer
= img
->layer
;
336 dri_get_param(struct st_manager
*smapi
,
337 enum st_manager_param param
)
339 struct dri_screen
*screen
= (struct dri_screen
*)smapi
;
342 case ST_MANAGER_BROKEN_INVALIDATE
:
343 return screen
->broken_invalidate
;
350 dri_destroy_option_cache(struct dri_screen
* screen
)
354 if (screen
->optionCache
.info
) {
355 for (i
= 0; i
< (1 << screen
->optionCache
.tableSize
); ++i
) {
356 free(screen
->optionCache
.info
[i
].name
);
357 free(screen
->optionCache
.info
[i
].ranges
);
359 free(screen
->optionCache
.info
);
362 free(screen
->optionCache
.values
);
366 dri_destroy_screen_helper(struct dri_screen
* screen
)
368 if (screen
->st_api
&& screen
->st_api
->destroy
)
369 screen
->st_api
->destroy(screen
->st_api
);
371 if (screen
->base
.screen
)
372 screen
->base
.screen
->destroy(screen
->base
.screen
);
374 dri_destroy_option_cache(screen
);
378 dri_destroy_screen(__DRIscreen
* sPriv
)
380 struct dri_screen
*screen
= dri_screen(sPriv
);
382 dri_destroy_screen_helper(screen
);
385 sPriv
->driverPrivate
= NULL
;
386 sPriv
->extensions
= NULL
;
390 dri_init_screen_helper(struct dri_screen
*screen
,
391 struct pipe_screen
*pscreen
)
393 screen
->base
.screen
= pscreen
;
394 if (!screen
->base
.screen
) {
395 debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__
);
399 screen
->base
.get_egl_image
= dri_get_egl_image
;
400 screen
->base
.get_param
= dri_get_param
;
402 screen
->st_api
= st_gl_api_create();
406 if(pscreen
->get_param(pscreen
, PIPE_CAP_NPOT_TEXTURES
))
407 screen
->target
= PIPE_TEXTURE_2D
;
409 screen
->target
= PIPE_TEXTURE_RECT
;
411 driParseOptionInfo(&screen
->optionCacheDefaults
,
412 __driConfigOptions
, __driNConfigOptions
);
414 driParseConfigFiles(&screen
->optionCache
,
415 &screen
->optionCacheDefaults
,
416 screen
->sPriv
->myNum
,
417 driver_descriptor
.name
);
419 return dri_fill_in_modes(screen
);
422 /* vim: set sw=3 ts=8 sts=3 expandtab: */