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"
43 #include "util/u_inlines.h"
44 #include "pipe/p_screen.h"
45 #include "pipe/p_format.h"
46 #include "state_tracker/drm_api.h"
48 #include "util/u_debug.h"
50 PUBLIC
const char __driConfigOptions
[] =
51 DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE
52 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS
)
53 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
54 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
55 /* DRI_CONF_FORCE_S3TC_ENABLE(false) */
56 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
57 DRI_CONF_SECTION_END DRI_CONF_END
;
59 const uint __driNConfigOptions
= 3;
62 dri_fill_in_modes(struct dri_screen
*screen
,
65 __DRIconfig
**configs
= NULL
;
66 __DRIconfig
**configs_r5g6b5
= NULL
;
67 __DRIconfig
**configs_a8r8g8b8
= NULL
;
68 __DRIconfig
**configs_x8r8g8b8
= NULL
;
70 uint8_t depth_bits_array
[5];
71 uint8_t stencil_bits_array
[5];
72 uint8_t msaa_samples_array
[2];
73 unsigned depth_buffer_factor
;
74 unsigned back_buffer_factor
;
75 unsigned msaa_samples_factor
;
76 struct pipe_screen
*p_screen
= screen
->pipe_screen
;
77 boolean pf_r5g6b5
, pf_a8r8g8b8
, pf_x8r8g8b8
;
78 boolean pf_z16
, pf_x8z24
, pf_z24x8
, pf_s8z24
, pf_z24s8
, pf_z32
;
80 static const GLenum back_buffer_modes
[] = {
81 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
84 depth_bits_array
[0] = 0;
85 stencil_bits_array
[0] = 0;
86 depth_buffer_factor
= 1;
88 pf_x8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24X8_UNORM
,
90 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
91 pf_z24x8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_X8Z24_UNORM
,
93 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
94 pf_s8z24
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z24S8_UNORM
,
96 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
97 pf_z24s8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_S8Z24_UNORM
,
99 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
100 pf_a8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B8G8R8A8_UNORM
,
102 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
103 pf_x8r8g8b8
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B8G8R8X8_UNORM
,
105 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
106 pf_r5g6b5
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_B5G6R5_UNORM
,
108 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0);
110 /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */
111 if (dri_with_format(screen
->sPriv
)) {
112 pf_z16
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z16_UNORM
,
114 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
115 pf_z32
= p_screen
->is_format_supported(p_screen
, PIPE_FORMAT_Z32_UNORM
,
117 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
, 0);
124 depth_bits_array
[depth_buffer_factor
] = 16;
125 stencil_bits_array
[depth_buffer_factor
++] = 0;
127 if (pf_x8z24
|| pf_z24x8
) {
128 depth_bits_array
[depth_buffer_factor
] = 24;
129 stencil_bits_array
[depth_buffer_factor
++] = 0;
130 screen
->d_depth_bits_last
= pf_x8z24
;
132 if (pf_s8z24
|| pf_z24s8
) {
133 depth_bits_array
[depth_buffer_factor
] = 24;
134 stencil_bits_array
[depth_buffer_factor
++] = 8;
135 screen
->sd_depth_bits_last
= pf_s8z24
;
138 depth_bits_array
[depth_buffer_factor
] = 32;
139 stencil_bits_array
[depth_buffer_factor
++] = 0;
142 msaa_samples_array
[0] = 0;
143 msaa_samples_array
[1] = 4;
144 back_buffer_factor
= 3;
145 msaa_samples_factor
= 2;
148 depth_buffer_factor
* back_buffer_factor
* msaa_samples_factor
* 4;
151 configs_r5g6b5
= driCreateConfigs(GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
,
152 depth_bits_array
, stencil_bits_array
,
153 depth_buffer_factor
, back_buffer_modes
,
155 msaa_samples_array
, msaa_samples_factor
,
159 configs_a8r8g8b8
= driCreateConfigs(GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
,
170 configs_x8r8g8b8
= driCreateConfigs(GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
,
180 if (pixel_bits
== 16) {
181 configs
= configs_r5g6b5
;
182 if (configs_a8r8g8b8
)
183 configs
= configs
? driConcatConfigs(configs
, configs_a8r8g8b8
) : configs_a8r8g8b8
;
184 if (configs_x8r8g8b8
)
185 configs
= configs
? driConcatConfigs(configs
, configs_x8r8g8b8
) : configs_x8r8g8b8
;
187 configs
= configs_a8r8g8b8
;
188 if (configs_x8r8g8b8
)
189 configs
= configs
? driConcatConfigs(configs
, configs_x8r8g8b8
) : configs_x8r8g8b8
;
191 configs
= configs
? driConcatConfigs(configs
, configs_r5g6b5
) : configs_r5g6b5
;
194 if (configs
== NULL
) {
195 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__
);
199 return (const __DRIconfig
**)configs
;
203 * Roughly the converse of dri_fill_in_modes.
206 dri_fill_st_visual(struct st_visual
*stvis
, struct dri_screen
*screen
,
207 const __GLcontextModes
*mode
)
209 memset(stvis
, 0, sizeof(*stvis
));
211 stvis
->samples
= mode
->samples
;
212 stvis
->render_buffer
= ST_ATTACHMENT_INVALID
;
214 if (mode
->redBits
== 8) {
215 if (mode
->alphaBits
== 8)
216 stvis
->color_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
218 stvis
->color_format
= PIPE_FORMAT_B8G8R8X8_UNORM
;
220 stvis
->color_format
= PIPE_FORMAT_B5G6R5_UNORM
;
223 switch (mode
->depthBits
) {
226 stvis
->depth_stencil_format
= PIPE_FORMAT_NONE
;
229 stvis
->depth_stencil_format
= PIPE_FORMAT_Z16_UNORM
;
232 if (mode
->stencilBits
== 0) {
233 stvis
->depth_stencil_format
= (screen
->d_depth_bits_last
) ?
234 PIPE_FORMAT_Z24X8_UNORM
:
235 PIPE_FORMAT_X8Z24_UNORM
;
237 stvis
->depth_stencil_format
= (screen
->sd_depth_bits_last
) ?
238 PIPE_FORMAT_Z24S8_UNORM
:
239 PIPE_FORMAT_S8Z24_UNORM
;
243 stvis
->depth_stencil_format
= PIPE_FORMAT_Z32_UNORM
;
247 stvis
->accum_format
= (mode
->haveAccumBuffer
) ?
248 PIPE_FORMAT_R16G16B16A16_SNORM
: PIPE_FORMAT_NONE
;
250 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_LEFT_MASK
;
251 if (mode
->doubleBufferMode
)
252 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_LEFT_MASK
;
253 if (mode
->stereoMode
) {
254 stvis
->buffer_mask
|= ST_ATTACHMENT_FRONT_RIGHT_MASK
;
255 if (mode
->doubleBufferMode
)
256 stvis
->buffer_mask
|= ST_ATTACHMENT_BACK_RIGHT_MASK
;
259 if (mode
->haveDepthBuffer
|| mode
->haveStencilBuffer
)
260 stvis
->buffer_mask
|= ST_ATTACHMENT_DEPTH_STENCIL_MASK
;
261 /* let the state tracker allocate the accum buffer */
265 * Get information about previous buffer swaps.
268 dri_get_swap_info(__DRIdrawable
* dPriv
, __DRIswapInfo
* sInfo
)
270 if (dPriv
== NULL
|| dPriv
->driverPrivate
== NULL
|| sInfo
== NULL
)
277 dri_destroy_option_cache(struct dri_screen
* screen
)
281 for (i
= 0; i
< (1 << screen
->optionCache
.tableSize
); ++i
) {
282 FREE(screen
->optionCache
.info
[i
].name
);
283 FREE(screen
->optionCache
.info
[i
].ranges
);
286 FREE(screen
->optionCache
.info
);
287 FREE(screen
->optionCache
.values
);
291 dri_destroy_screen(__DRIscreen
* sPriv
)
293 struct dri_screen
*screen
= dri_screen(sPriv
);
295 if (screen
->dri1_pipe
)
296 screen
->dri1_pipe
->destroy(screen
->dri1_pipe
);
299 dri_destroy_st_manager(screen
->smapi
);
300 if (screen
->pipe_screen
)
301 screen
->pipe_screen
->destroy(screen
->pipe_screen
);
303 dri_destroy_option_cache(screen
);
306 sPriv
->private = NULL
;
307 sPriv
->extensions
= NULL
;
310 const struct __DriverAPIRec driDriverAPI
= {
311 .DestroyScreen
= dri_destroy_screen
,
312 .CreateContext
= dri_create_context
,
313 .DestroyContext
= dri_destroy_context
,
314 .CreateBuffer
= dri_create_buffer
,
315 .DestroyBuffer
= dri_destroy_buffer
,
316 .MakeCurrent
= dri_make_current
,
317 .UnbindContext
= dri_unbind_context
,
318 .GetSwapInfo
= dri_get_swap_info
,
319 .GetDrawableMSC
= driDrawableGetMSC32
,
320 .WaitForMSC
= driWaitForMSC32
,
321 .InitScreen2
= dri_init_screen2
,
323 .InitScreen
= dri1_init_screen
,
324 .SwapBuffers
= dri1_swap_buffers
,
325 .CopySubBuffer
= dri1_copy_sub_buffer
,
328 /* This is the table of extensions that the loader will dlsym() for. */
329 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
330 &driCoreExtension
.base
,
331 &driLegacyExtension
.base
,
332 &driDRI2Extension
.base
,
336 /* vim: set sw=3 ts=8 sts=3 expandtab: */