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"
44 #include "util/u_format_s3tc.h"
46 #define MSAA_VISUAL_MAX_SAMPLES 32
50 PUBLIC
const char __driConfigOptions
[] =
52 DRI_CONF_SECTION_PERFORMANCE
53 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
54 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
57 DRI_CONF_SECTION_QUALITY
58 DRI_CONF_FORCE_S3TC_ENABLE("false")
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")
70 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
73 DRI_CONF_SECTION_MISCELLANEOUS
74 DRI_CONF_ALWAYS_HAVE_DEPTH_BUFFER("false")
80 static const uint __driNConfigOptions
= 13;
82 static const __DRIconfig
**
83 dri_fill_in_modes(struct dri_screen
*screen
)
85 static const gl_format mesa_formats
[3] = {
90 static const enum pipe_format pipe_formats
[3] = {
91 PIPE_FORMAT_BGRA8888_UNORM
,
92 PIPE_FORMAT_BGRX8888_UNORM
,
93 PIPE_FORMAT_B5G6R5_UNORM
,
96 __DRIconfig
**configs
= NULL
;
97 uint8_t depth_bits_array
[5];
98 uint8_t stencil_bits_array
[5];
99 unsigned depth_buffer_factor
;
100 unsigned msaa_samples_max
;
102 struct pipe_screen
*p_screen
= screen
->base
.screen
;
103 boolean pf_z16
, pf_x8z24
, pf_z24x8
, pf_s8z24
, pf_z24s8
, pf_z32
;
105 static const GLenum back_buffer_modes
[] = {
106 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
109 if (driQueryOptionb(&screen
->optionCache
, "always_have_depth_buffer")) {
110 /* all visuals will have a depth buffer */
111 depth_buffer_factor
= 0;
114 depth_bits_array
[0] = 0;
115 stencil_bits_array
[0] = 0;
116 depth_buffer_factor
= 1;
119 msaa_samples_max
= (screen
->st_api
->feature_mask
& ST_API_FEATURE_MS_VISUALS_MASK
)
120 ? MSAA_VISUAL_MAX_SAMPLES
: 1;
122 pf_x8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24X8_UNORM
,
124 PIPE_BIND_DEPTH_STENCIL
);
125 pf_z24x8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8Z24_UNORM
,
127 PIPE_BIND_DEPTH_STENCIL
);
128 pf_s8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24_UNORM_S8_UINT
,
130 PIPE_BIND_DEPTH_STENCIL
);
131 pf_z24s8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_S8_UINT_Z24_UNORM
,
133 PIPE_BIND_DEPTH_STENCIL
);
134 pf_z16
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z16_UNORM
,
136 PIPE_BIND_DEPTH_STENCIL
);
137 pf_z32
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z32_UNORM
,
139 PIPE_BIND_DEPTH_STENCIL
);
142 depth_bits_array
[depth_buffer_factor
] = 16;
143 stencil_bits_array
[depth_buffer_factor
++] = 0;
145 if (pf_x8z24
|| pf_z24x8
) {
146 depth_bits_array
[depth_buffer_factor
] = 24;
147 stencil_bits_array
[depth_buffer_factor
++] = 0;
148 screen
->d_depth_bits_last
= pf_x8z24
;
150 if (pf_s8z24
|| pf_z24s8
) {
151 depth_bits_array
[depth_buffer_factor
] = 24;
152 stencil_bits_array
[depth_buffer_factor
++] = 8;
153 screen
->sd_depth_bits_last
= pf_s8z24
;
156 depth_bits_array
[depth_buffer_factor
] = 32;
157 stencil_bits_array
[depth_buffer_factor
++] = 0;
160 assert(Elements(mesa_formats
) == Elements(pipe_formats
));
163 for (format
= 0; format
< Elements(mesa_formats
); format
++) {
164 __DRIconfig
**new_configs
= NULL
;
165 unsigned num_msaa_modes
= 0; /* includes a single-sample mode */
166 uint8_t msaa_modes
[MSAA_VISUAL_MAX_SAMPLES
];
168 for (i
= 1; i
<= msaa_samples_max
; i
++) {
169 int samples
= i
> 1 ? i
: 0;
171 if (p_screen
->is_format_supported(p_screen
, pipe_formats
[format
],
172 PIPE_TEXTURE_2D
, samples
,
173 PIPE_BIND_RENDER_TARGET
)) {
174 msaa_modes
[num_msaa_modes
++] = samples
;
178 if (num_msaa_modes
) {
179 /* Single-sample configs with an accumulation buffer. */
180 new_configs
= driCreateConfigs(mesa_formats
[format
],
181 depth_bits_array
, stencil_bits_array
,
182 depth_buffer_factor
, back_buffer_modes
,
183 Elements(back_buffer_modes
),
186 configs
= driConcatConfigs(configs
, new_configs
);
188 /* Multi-sample configs without an accumulation buffer. */
189 if (num_msaa_modes
> 1) {
190 new_configs
= driCreateConfigs(mesa_formats
[format
],
191 depth_bits_array
, stencil_bits_array
,
192 depth_buffer_factor
, back_buffer_modes
,
193 Elements(back_buffer_modes
),
194 msaa_modes
+1, num_msaa_modes
-1,
196 configs
= driConcatConfigs(configs
, new_configs
);
201 if (configs
== NULL
) {
202 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
206 return (const __DRIconfig
**)configs
;
209 /* The Gallium way to force MSAA. */
210 DEBUG_GET_ONCE_NUM_OPTION(msaa
, "GALLIUM_MSAA", 0);
212 /* The NVIDIA way to force MSAA. The same variable is used by the NVIDIA
214 DEBUG_GET_ONCE_NUM_OPTION(msaa_nv
, "__GL_FSAA_MODE", 0);
217 dri_force_msaa_visual(struct st_visual
*stvis
,
218 struct pipe_screen
*screen
)
221 int samples
= debug_get_option_msaa();
224 samples
= debug_get_option_msaa_nv();
227 return; /* nothing to do */
229 /* Choose a supported sample count greater than or equal to samples. */
230 for (i
= samples
; i
<= MSAA_VISUAL_MAX_SAMPLES
; i
++) {
231 if (screen
->is_format_supported(screen
, stvis
->color_format
,
233 PIPE_BIND_RENDER_TARGET
)) {
241 * Roughly the converse of dri_fill_in_modes.
244 dri_fill_st_visual(struct st_visual
*stvis
, struct dri_screen
*screen
,
245 const struct gl_config
*mode
)
247 memset(stvis
, 0, sizeof(*stvis
));
252 if (mode
->redBits
== 8) {
253 if (mode
->alphaBits
== 8)
254 stvis
->color_format
= PIPE_FORMAT_BGRA8888_UNORM
;
256 stvis
->color_format
= PIPE_FORMAT_BGRX8888_UNORM
;
258 stvis
->color_format
= PIPE_FORMAT_B5G6R5_UNORM
;
261 if (mode
->sampleBuffers
) {
262 stvis
->samples
= mode
->samples
;
265 /* This must be done after stvis->color_format is set. */
266 dri_force_msaa_visual(stvis
, screen
->base
.screen
);
269 switch (mode
->depthBits
) {
272 stvis
->depth_stencil_format
= PIPE_FORMAT_NONE
;
275 stvis
->depth_stencil_format
= PIPE_FORMAT_Z16_UNORM
;
278 if (mode
->stencilBits
== 0) {
279 stvis
->depth_stencil_format
= (screen
->d_depth_bits_last
) ?
280 PIPE_FORMAT_Z24X8_UNORM
:
281 PIPE_FORMAT_X8Z24_UNORM
;
283 stvis
->depth_stencil_format
= (screen
->sd_depth_bits_last
) ?
284 PIPE_FORMAT_Z24_UNORM_S8_UINT
:
285 PIPE_FORMAT_S8_UINT_Z24_UNORM
;
289 stvis
->depth_stencil_format
= PIPE_FORMAT_Z32_UNORM
;
293 stvis
->accum_format
= (mode
->haveAccumBuffer
) ?
294 PIPE_FORMAT_R16G16B16A16_SNORM
: PIPE_FORMAT_NONE
;
296 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_LEFT_MASK
;
297 stvis
->render_buffer
= ST_ATTACHMENT_FRONT_LEFT
;
298 if (mode
->doubleBufferMode
) {
299 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_LEFT_MASK
;
300 stvis
->render_buffer
= ST_ATTACHMENT_BACK_LEFT
;
302 if (mode
->stereoMode
) {
303 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_RIGHT_MASK
;
304 if (mode
->doubleBufferMode
)
305 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_RIGHT_MASK
;
308 if (mode
->haveDepthBuffer
|| mode
->haveStencilBuffer
)
309 stvis
->buffer_mask
|= ST_ATTACHMENT_DEPTH_STENCIL_MASK
;
310 /* let the state tracker allocate the accum buffer */
314 dri_get_egl_image(struct st_manager
*smapi
,
316 struct st_egl_image
*stimg
)
318 struct dri_screen
*screen
= (struct dri_screen
*)smapi
;
319 __DRIimage
*img
= NULL
;
321 if (screen
->lookup_egl_image
) {
322 img
= screen
->lookup_egl_image(screen
, egl_image
);
328 stimg
->texture
= NULL
;
329 pipe_resource_reference(&stimg
->texture
, img
->texture
);
330 stimg
->level
= img
->level
;
331 stimg
->layer
= img
->layer
;
337 dri_get_param(struct st_manager
*smapi
,
338 enum st_manager_param param
)
340 struct dri_screen
*screen
= (struct dri_screen
*)smapi
;
343 case ST_MANAGER_BROKEN_INVALIDATE
:
344 return screen
->broken_invalidate
;
351 dri_destroy_option_cache(struct dri_screen
* screen
)
355 if (screen
->optionCache
.info
) {
356 for (i
= 0; i
< (1 << screen
->optionCache
.tableSize
); ++i
) {
357 free(screen
->optionCache
.info
[i
].name
);
358 free(screen
->optionCache
.info
[i
].ranges
);
360 free(screen
->optionCache
.info
);
363 free(screen
->optionCache
.values
);
367 dri_destroy_screen_helper(struct dri_screen
* screen
)
369 if (screen
->st_api
&& screen
->st_api
->destroy
)
370 screen
->st_api
->destroy(screen
->st_api
);
372 if (screen
->base
.screen
)
373 screen
->base
.screen
->destroy(screen
->base
.screen
);
375 dri_destroy_option_cache(screen
);
379 dri_destroy_screen(__DRIscreen
* sPriv
)
381 struct dri_screen
*screen
= dri_screen(sPriv
);
383 dri_destroy_screen_helper(screen
);
386 sPriv
->driverPrivate
= NULL
;
387 sPriv
->extensions
= NULL
;
391 dri_init_screen_helper(struct dri_screen
*screen
,
392 struct pipe_screen
*pscreen
)
394 screen
->base
.screen
= pscreen
;
395 if (!screen
->base
.screen
) {
396 debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__
);
400 screen
->base
.get_egl_image
= dri_get_egl_image
;
401 screen
->base
.get_param
= dri_get_param
;
403 screen
->st_api
= st_gl_api_create();
407 if(pscreen
->get_param(pscreen
, PIPE_CAP_NPOT_TEXTURES
))
408 screen
->target
= PIPE_TEXTURE_2D
;
410 screen
->target
= PIPE_TEXTURE_RECT
;
412 driParseOptionInfo(&screen
->optionCacheDefaults
,
413 __driConfigOptions
, __driNConfigOptions
);
415 driParseConfigFiles(&screen
->optionCache
,
416 &screen
->optionCacheDefaults
,
417 screen
->sPriv
->myNum
,
418 driver_descriptor
.name
);
420 /* Handle force_s3tc_enable. */
421 if (!util_format_s3tc_enabled
&&
422 driQueryOptionb(&screen
->optionCache
, "force_s3tc_enable")) {
423 /* Ensure libtxc_dxtn has been loaded if available.
424 * Forcing S3TC on before calling this would prevent loading
426 * This is just a precaution, the driver should have called it
429 util_format_s3tc_init();
431 util_format_s3tc_enabled
= TRUE
;
434 return dri_fill_in_modes(screen
);
437 /* vim: set sw=3 ts=8 sts=3 expandtab: */