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>
36 #include "dri_screen.h"
37 #include "dri_context.h"
38 #include "dri_drawable.h"
39 #include "dri_st_api.h"
40 #include "dri1_helper.h"
44 #include "util/u_inlines.h"
45 #include "pipe/p_screen.h"
46 #include "pipe/p_format.h"
47 #include "state_tracker/drm_api.h"
49 #include "util/u_debug.h"
51 PUBLIC
const char __driConfigOptions
[] =
52 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
53 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
54 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
55 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
56 /* DRI_CONF_FORCE_S3TC_ENABLE(false) */
57 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
58 DRI_CONF_SECTION_END DRI_CONF_END
;
60 const uint __driNConfigOptions
= 3;
63 dri_fill_in_modes(struct dri_screen
*screen
,
66 __DRIconfig
**configs
= NULL
;
67 __DRIconfig
**configs_r5g6b5
= NULL
;
68 __DRIconfig
**configs_a8r8g8b8
= NULL
;
69 __DRIconfig
**configs_x8r8g8b8
= NULL
;
71 uint8_t depth_bits_array
[5];
72 uint8_t stencil_bits_array
[5];
73 uint8_t msaa_samples_array
[2];
74 unsigned depth_buffer_factor
;
75 unsigned back_buffer_factor
;
76 unsigned msaa_samples_factor
;
77 struct pipe_screen
*p_screen
= screen
->pipe_screen
;
78 boolean pf_r5g6b5
, pf_a8r8g8b8
, pf_x8r8g8b8
;
79 boolean pf_z16
, pf_x8z24
, pf_z24x8
, pf_s8z24
, pf_z24s8
, pf_z32
;
81 static const GLenum back_buffer_modes
[] = {
82 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
85 depth_bits_array
[0] = 0;
86 stencil_bits_array
[0] = 0;
87 depth_buffer_factor
= 1;
89 pf_x8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24X8_UNORM
,
91 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
92 pf_z24x8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8Z24_UNORM
,
94 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
95 pf_s8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24S8_UNORM
,
97 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
98 pf_z24s8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_S8Z24_UNORM
,
100 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
101 pf_a8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B8G8R8A8_UNORM
,
103 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
104 pf_x8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B8G8R8X8_UNORM
,
106 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
107 pf_r5g6b5
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B5G6R5_UNORM
,
109 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
111 /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */
112 if (dri_with_format(screen
->sPriv
)) {
113 pf_z16
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z16_UNORM
,
115 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
116 pf_z32
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z32_UNORM
,
118 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
125 depth_bits_array
[depth_buffer_factor
] = 16;
126 stencil_bits_array
[depth_buffer_factor
++] = 0;
128 if (pf_x8z24
|| pf_z24x8
) {
129 depth_bits_array
[depth_buffer_factor
] = 24;
130 stencil_bits_array
[depth_buffer_factor
++] = 0;
131 screen
->d_depth_bits_last
= pf_x8z24
;
133 if (pf_s8z24
|| pf_z24s8
) {
134 depth_bits_array
[depth_buffer_factor
] = 24;
135 stencil_bits_array
[depth_buffer_factor
++] = 8;
136 screen
->sd_depth_bits_last
= pf_s8z24
;
139 depth_bits_array
[depth_buffer_factor
] = 32;
140 stencil_bits_array
[depth_buffer_factor
++] = 0;
143 msaa_samples_array
[0] = 0;
144 msaa_samples_array
[1] = 4;
145 back_buffer_factor
= 3;
146 msaa_samples_factor
= 2;
149 depth_buffer_factor
* back_buffer_factor
* msaa_samples_factor
* 4;
152 configs_r5g6b5
= driCreateConfigs(GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
,
153 depth_bits_array
, stencil_bits_array
,
154 depth_buffer_factor
, back_buffer_modes
,
156 msaa_samples_array
, msaa_samples_factor
,
160 configs_a8r8g8b8
= driCreateConfigs(GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
,
171 configs_x8r8g8b8
= driCreateConfigs(GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
,
181 if (pixel_bits
== 16) {
182 configs
= configs_r5g6b5
;
183 if (configs_a8r8g8b8
)
184 configs
= configs
? driConcatConfigs(configs
, configs_a8r8g8b8
) : configs_a8r8g8b8
;
185 if (configs_x8r8g8b8
)
186 configs
= configs
? driConcatConfigs(configs
, configs_x8r8g8b8
) : configs_x8r8g8b8
;
188 configs
= configs_a8r8g8b8
;
189 if (configs_x8r8g8b8
)
190 configs
= configs
? driConcatConfigs(configs
, configs_x8r8g8b8
) : configs_x8r8g8b8
;
192 configs
= configs
? driConcatConfigs(configs
, configs_r5g6b5
) : configs_r5g6b5
;
195 if (configs
== NULL
) {
196 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
200 return (const __DRIconfig
**)configs
;
204 * Roughly the converse of dri_fill_in_modes.
207 dri_fill_st_visual(struct st_visual
*stvis
, struct dri_screen
*screen
,
208 const __GLcontextModes
*mode
)
210 memset(stvis
, 0, sizeof(*stvis
));
212 stvis
->samples
= mode
->samples
;
213 stvis
->render_buffer
= ST_ATTACHMENT_INVALID
;
215 if (mode
->redBits
== 8) {
216 if (mode
->alphaBits
== 8)
217 stvis
->color_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
219 stvis
->color_format
= PIPE_FORMAT_B8G8R8X8_UNORM
;
221 stvis
->color_format
= PIPE_FORMAT_B5G6R5_UNORM
;
224 switch (mode
->depthBits
) {
227 stvis
->depth_stencil_format
= PIPE_FORMAT_NONE
;
230 stvis
->depth_stencil_format
= PIPE_FORMAT_Z16_UNORM
;
233 if (mode
->stencilBits
== 0) {
234 stvis
->depth_stencil_format
= (screen
->d_depth_bits_last
) ?
235 PIPE_FORMAT_Z24X8_UNORM
:
236 PIPE_FORMAT_X8Z24_UNORM
;
238 stvis
->depth_stencil_format
= (screen
->sd_depth_bits_last
) ?
239 PIPE_FORMAT_Z24S8_UNORM
:
240 PIPE_FORMAT_S8Z24_UNORM
;
244 stvis
->depth_stencil_format
= PIPE_FORMAT_Z32_UNORM
;
248 stvis
->accum_format
= (mode
->haveAccumBuffer
) ?
249 PIPE_FORMAT_R16G16B16A16_SNORM
: PIPE_FORMAT_NONE
;
251 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_LEFT_MASK
;
252 if (mode
->doubleBufferMode
)
253 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_LEFT_MASK
;
254 if (mode
->stereoMode
) {
255 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_RIGHT_MASK
;
256 if (mode
->doubleBufferMode
)
257 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_RIGHT_MASK
;
260 if (mode
->haveDepthBuffer
|| mode
->haveStencilBuffer
)
261 stvis
->buffer_mask
|= ST_ATTACHMENT_DEPTH_STENCIL_MASK
;
262 /* let the state tracker allocate the accum buffer */
266 * Get information about previous buffer swaps.
269 dri_get_swap_info(__DRIdrawable
* dPriv
, __DRIswapInfo
* sInfo
)
271 if (dPriv
== NULL
|| dPriv
->driverPrivate
== NULL
|| sInfo
== NULL
)
278 dri_destroy_option_cache(struct dri_screen
* screen
)
282 for (i
= 0; i
< (1 << screen
->optionCache
.tableSize
); ++i
) {
283 FREE(screen
->optionCache
.info
[i
].name
);
284 FREE(screen
->optionCache
.info
[i
].ranges
);
287 FREE(screen
->optionCache
.info
);
288 FREE(screen
->optionCache
.values
);
292 dri_destroy_screen(__DRIscreen
* sPriv
)
294 struct dri_screen
*screen
= dri_screen(sPriv
);
296 dri1_destroy_pipe_context(screen
);
299 dri_destroy_st_manager(screen
->smapi
);
301 if (screen
->pipe_screen
)
302 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
304 dri_destroy_option_cache(screen
);
307 sPriv
->private = NULL
;
308 sPriv
->extensions
= NULL
;
311 const struct __DriverAPIRec driDriverAPI
= {
312 .DestroyScreen
= dri_destroy_screen
,
313 .CreateContext
= dri_create_context
,
314 .DestroyContext
= dri_destroy_context
,
315 .CreateBuffer
= dri_create_buffer
,
316 .DestroyBuffer
= dri_destroy_buffer
,
317 .MakeCurrent
= dri_make_current
,
318 .UnbindContext
= dri_unbind_context
,
319 .GetSwapInfo
= dri_get_swap_info
,
320 .GetDrawableMSC
= driDrawableGetMSC32
,
321 .WaitForMSC
= driWaitForMSC32
,
322 .InitScreen2
= dri_init_screen2
,
324 .InitScreen
= dri1_init_screen
,
325 .SwapBuffers
= dri1_swap_buffers
,
326 .CopySubBuffer
= dri1_copy_sub_buffer
,
329 /* This is the table of extensions that the loader will dlsym() for. */
330 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
331 &driCoreExtension
.base
,
332 &driLegacyExtension
.base
,
333 &driDRI2Extension
.base
,
337 /* vim: set sw=3 ts=8 sts=3 expandtab: */