blob: 8da96ede644753520d95ece1d5147a95c6beb34a [file] [log] [blame]
Keith Whitwell6b9e31f2006-11-01 12:03:11 +00001/**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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 TUNGSTEN GRAPHICS 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.
25 *
26 **************************************************************************/
27
Brian Paulecadb512008-09-18 15:17:05 -060028#include "main/glheader.h"
29#include "main/context.h"
30#include "main/framebuffer.h"
Brian Paulecadb512008-09-18 15:17:05 -060031#include "main/renderbuffer.h"
Brian Paul6c244b02009-01-26 12:38:46 -070032
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000033#include "utils.h"
34#include "vblank.h"
35#include "xmlpool.h"
36
Brian Paul6c244b02009-01-26 12:38:46 -070037#include "intel_batchbuffer.h"
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000038#include "intel_buffers.h"
Brian Paul6c244b02009-01-26 12:38:46 -070039#include "intel_bufmgr.h"
Eric Anholtbea6b5f2007-12-20 11:29:39 -080040#include "intel_chipset.h"
Brian Paul6c244b02009-01-26 12:38:46 -070041#include "intel_extensions.h"
42#include "intel_fbo.h"
43#include "intel_regions.h"
Brian Paul6fcebbe2009-01-26 11:53:06 -070044#include "intel_swapbuffers.h"
Brian Paul6c244b02009-01-26 12:38:46 -070045#include "intel_screen.h"
46#include "intel_span.h"
47#include "intel_tex.h"
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000048
Eric Anholtbea6b5f2007-12-20 11:29:39 -080049#include "i915_drm.h"
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000050#include "i830_dri.h"
Brian Paul6c244b02009-01-26 12:38:46 -070051
Eric Anholt1ba96652009-06-03 16:40:20 +000052#define DRI_CONF_TEXTURE_TILING(def) \
53 DRI_CONF_OPT_BEGIN(texture_tiling, bool, def) \
54 DRI_CONF_DESC(en, "Enable texture tiling") \
55 DRI_CONF_OPT_END \
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000056
57PUBLIC const char __driConfigOptions[] =
Eric Anholta0e453a2008-01-17 14:23:04 -080058 DRI_CONF_BEGIN
59 DRI_CONF_SECTION_PERFORMANCE
60 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
Jesse Barnese9bf3e42008-07-31 11:50:37 -070061 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
Eric Anholtfe91c052008-03-05 14:14:54 -080062 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
63 * DRI_CONF_BO_REUSE_ALL
64 */
Dave Airlief75843a2008-08-24 17:59:10 +100065 DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
Eric Anholtfe91c052008-03-05 14:14:54 -080066 DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
67 DRI_CONF_ENUM(0, "Disable buffer object reuse")
68 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
69 DRI_CONF_DESC_END
70 DRI_CONF_OPT_END
Eric Anholt1ba96652009-06-03 16:40:20 +000071
72#ifdef I915
73 DRI_CONF_TEXTURE_TILING(false)
74#else
75 DRI_CONF_TEXTURE_TILING(true)
76#endif
77
Eric Anholtb30dc2c2009-06-09 16:12:43 -070078 DRI_CONF_OPT_BEGIN(early_z, bool, false)
79 DRI_CONF_DESC(en, "Enable early Z in classic mode (unstable, 945-only).")
80 DRI_CONF_OPT_END
81
Eric Anholta0e453a2008-01-17 14:23:04 -080082 DRI_CONF_SECTION_END
83 DRI_CONF_SECTION_QUALITY
84 DRI_CONF_FORCE_S3TC_ENABLE(false)
Michel Dänzeracba9c12008-04-29 18:43:28 +020085 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
Eric Anholta0e453a2008-01-17 14:23:04 -080086 DRI_CONF_SECTION_END
87 DRI_CONF_SECTION_DEBUG
88 DRI_CONF_NO_RAST(false)
Eric Anholt40bc2742009-03-05 17:18:49 -080089 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
Eric Anholtf3687282009-03-05 17:08:36 -080090 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
Eric Anholta0e453a2008-01-17 14:23:04 -080091 DRI_CONF_SECTION_END
92DRI_CONF_END;
93
Eric Anholtb30dc2c2009-06-09 16:12:43 -070094const GLuint __driNConfigOptions = 10;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000095
96#ifdef USE_NEW_INTERFACE
Eric Anholt85063f12008-02-13 16:08:19 -080097static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +000098#endif /*USE_NEW_INTERFACE */
99
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000100/**
101 * Map all the memory regions described by the screen.
102 * \return GL_TRUE if success, GL_FALSE if error.
103 */
104GLboolean
105intelMapScreenRegions(__DRIscreenPrivate * sPriv)
106{
107 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
108
Eric Anholtcfc21192007-05-17 15:28:01 -0700109 if (0)
110 _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
111 if (intelScreen->tex.size != 0) {
Eric Anholtcfc21192007-05-17 15:28:01 -0700112 if (drmMap(sPriv->fd,
113 intelScreen->tex.handle,
114 intelScreen->tex.size,
115 (drmAddress *) & intelScreen->tex.map) != 0) {
116 intelUnmapScreenRegions(intelScreen);
117 return GL_FALSE;
118 }
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000119 }
Eric Anholtcfc21192007-05-17 15:28:01 -0700120
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000121 return GL_TRUE;
122}
123
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000124void
125intelUnmapScreenRegions(intelScreenPrivate * intelScreen)
126{
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000127 if (intelScreen->tex.map) {
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000128 drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
129 intelScreen->tex.map = NULL;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000130 }
131}
132
133
134static void
135intelPrintDRIInfo(intelScreenPrivate * intelScreen,
136 __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
137{
138 fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n",
139 intelScreen->front.size, intelScreen->front.offset,
Kristian Høgsberg46eb02b2008-01-22 12:13:16 -0500140 intelScreen->pitch);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000141 fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n",
142 intelScreen->back.size, intelScreen->back.offset,
Kristian Høgsberg46eb02b2008-01-22 12:13:16 -0500143 intelScreen->pitch);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000144 fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n",
145 intelScreen->depth.size, intelScreen->depth.offset,
Kristian Høgsberg46eb02b2008-01-22 12:13:16 -0500146 intelScreen->pitch);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000147 fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n",
148 intelScreen->tex.size, intelScreen->tex.offset);
149 fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
150}
151
152
153static void
Timo Aaltonen39e6d0d2009-01-20 11:45:35 -0500154intelPrintSAREA(const drm_i915_sarea_t * sarea)
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000155{
156 fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width,
157 sarea->height);
158 fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
159 fprintf(stderr,
Dave Airlief75843a2008-08-24 17:59:10 +1000160 "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000161 sarea->front_offset, sarea->front_size,
Dave Airlief75843a2008-08-24 17:59:10 +1000162 (unsigned) sarea->front_handle, sarea->front_tiled);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000163 fprintf(stderr,
Dave Airlief75843a2008-08-24 17:59:10 +1000164 "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000165 sarea->back_offset, sarea->back_size,
Dave Airlief75843a2008-08-24 17:59:10 +1000166 (unsigned) sarea->back_handle, sarea->back_tiled);
167 fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x tiled: %d\n",
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000168 sarea->depth_offset, sarea->depth_size,
Dave Airlief75843a2008-08-24 17:59:10 +1000169 (unsigned) sarea->depth_handle, sarea->depth_tiled);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000170 fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n",
171 sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000172}
173
174
175/**
176 * A number of the screen parameters are obtained/computed from
177 * information in the SAREA. This function updates those parameters.
178 */
Brian Paulaae27292009-01-26 12:36:17 -0700179static void
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000180intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
Timo Aaltonen39e6d0d2009-01-20 11:45:35 -0500181 drm_i915_sarea_t * sarea)
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000182{
183 intelScreen->width = sarea->width;
184 intelScreen->height = sarea->height;
Kristian Høgsberg46eb02b2008-01-22 12:13:16 -0500185 intelScreen->pitch = sarea->pitch;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000186
187 intelScreen->front.offset = sarea->front_offset;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000188 intelScreen->front.handle = sarea->front_handle;
189 intelScreen->front.size = sarea->front_size;
Eric Anholtf00a6492007-11-16 16:43:45 -0800190 intelScreen->front.tiled = sarea->front_tiled;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000191
192 intelScreen->back.offset = sarea->back_offset;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000193 intelScreen->back.handle = sarea->back_handle;
194 intelScreen->back.size = sarea->back_size;
Eric Anholtf00a6492007-11-16 16:43:45 -0800195 intelScreen->back.tiled = sarea->back_tiled;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000196
197 intelScreen->depth.offset = sarea->depth_offset;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000198 intelScreen->depth.handle = sarea->depth_handle;
199 intelScreen->depth.size = sarea->depth_size;
Eric Anholtf00a6492007-11-16 16:43:45 -0800200 intelScreen->depth.tiled = sarea->depth_tiled;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000201
Kristian Høgsbergefd03a22007-05-14 16:37:19 -0400202 if (intelScreen->driScrnPriv->ddx_version.minor >= 9) {
Eric Anholt3e168a02007-08-16 14:32:53 -0700203 intelScreen->front.bo_handle = sarea->front_bo_handle;
204 intelScreen->back.bo_handle = sarea->back_bo_handle;
Eric Anholt3e168a02007-08-16 14:32:53 -0700205 intelScreen->depth.bo_handle = sarea->depth_bo_handle;
206 } else {
207 intelScreen->front.bo_handle = -1;
208 intelScreen->back.bo_handle = -1;
Eric Anholt3e168a02007-08-16 14:32:53 -0700209 intelScreen->depth.bo_handle = -1;
210 }
211
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000212 intelScreen->tex.offset = sarea->tex_offset;
213 intelScreen->logTextureGranularity = sarea->log_tex_granularity;
214 intelScreen->tex.handle = sarea->tex_handle;
215 intelScreen->tex.size = sarea->tex_size;
216
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000217 if (0)
218 intelPrintSAREA(sarea);
219}
220
Michel Dänzer9c4d1042007-10-16 13:01:44 +0200221static const __DRItexOffsetExtension intelTexOffsetExtension = {
222 { __DRI_TEX_OFFSET },
223 intelSetTexOffset,
224};
225
Kristian Høgsberg6d487792008-02-14 22:12:51 -0500226static const __DRItexBufferExtension intelTexBufferExtension = {
227 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
228 intelSetTexBuffer,
Eric Anholt66175aa2009-03-18 12:07:09 -0700229 intelSetTexBuffer2,
Kristian Høgsberg6d487792008-02-14 22:12:51 -0500230};
231
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400232static const __DRIextension *intelScreenExtensions[] = {
Kristian Høgsbergf968f672007-05-17 14:39:06 -0400233 &driReadDrawableExtension,
Kristian Høgsbergac3e8382007-05-15 15:17:30 -0400234 &driCopySubBufferExtension.base,
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -0400235 &driSwapControlExtension.base,
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -0400236 &driFrameTrackingExtension.base,
Kristian Høgsberg106a6f22007-05-16 18:13:41 -0400237 &driMediaStreamCounterExtension.base,
Michel Dänzer9c4d1042007-10-16 13:01:44 +0200238 &intelTexOffsetExtension.base,
Kristian Høgsberg6d487792008-02-14 22:12:51 -0500239 &intelTexBufferExtension.base,
Kristian Høgsbergac3e8382007-05-15 15:17:30 -0400240 NULL
241};
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000242
Kristian Høgsberg24e7e452008-01-09 18:04:19 -0500243static GLboolean
244intel_get_param(__DRIscreenPrivate *psp, int param, int *value)
245{
246 int ret;
Alan Hourihane1c718c02008-02-22 00:18:54 +0000247 struct drm_i915_getparam gp;
Kristian Høgsberg24e7e452008-01-09 18:04:19 -0500248
249 gp.param = param;
250 gp.value = value;
251
Alan Hourihane1c718c02008-02-22 00:18:54 +0000252 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
Kristian Høgsberg24e7e452008-01-09 18:04:19 -0500253 if (ret) {
Brian Paul42e9bde2009-06-08 14:41:54 -0600254 _mesa_warning(NULL, "drm_i915_getparam: %d", ret);
Kristian Høgsberg24e7e452008-01-09 18:04:19 -0500255 return GL_FALSE;
256 }
257
258 return GL_TRUE;
259}
Kristian Høgsbergac3e8382007-05-15 15:17:30 -0400260
261static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000262{
263 intelScreenPrivate *intelScreen;
264 I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
Timo Aaltonen39e6d0d2009-01-20 11:45:35 -0500265 drm_i915_sarea_t *sarea;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000266
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000267 if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
268 fprintf(stderr,
269 "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n");
270 return GL_FALSE;
271 }
272
273 /* Allocate the private area */
274 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
275 if (!intelScreen) {
276 fprintf(stderr, "\nERROR! Allocating private area failed\n");
277 return GL_FALSE;
278 }
279 /* parse information in __driConfigOptions */
280 driParseOptionInfo(&intelScreen->optionCache,
281 __driConfigOptions, __driNConfigOptions);
282
283 intelScreen->driScrnPriv = sPriv;
284 sPriv->private = (void *) intelScreen;
Timo Aaltonen39e6d0d2009-01-20 11:45:35 -0500285 sarea = (drm_i915_sarea_t *)
Eric Anholt36281852008-09-06 03:09:43 +0100286 (((GLubyte *) sPriv->pSAREA) + gDRIPriv->sarea_priv_offset);
287 intelScreen->sarea = sarea;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000288
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000289 intelScreen->deviceID = gDRIPriv->deviceID;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000290
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000291 intelUpdateScreenFromSAREA(intelScreen, sarea);
292
293 if (!intelMapScreenRegions(sPriv)) {
294 fprintf(stderr, "\nERROR! mapping regions\n");
295 _mesa_free(intelScreen);
296 sPriv->private = NULL;
297 return GL_FALSE;
298 }
299
Brian Paul4db0c892006-11-01 18:48:28 +0000300 if (0)
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000301 intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
302
Kristian Høgsbergefd03a22007-05-14 16:37:19 -0400303 intelScreen->drmMinor = sPriv->drm_version.minor;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000304
305 /* Determine if IRQs are active? */
Alan Hourihane1c718c02008-02-22 00:18:54 +0000306 if (!intel_get_param(sPriv, I915_PARAM_IRQ_ACTIVE,
Kristian Høgsberg24e7e452008-01-09 18:04:19 -0500307 &intelScreen->irq_active))
308 return GL_FALSE;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000309
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400310 sPriv->extensions = intelScreenExtensions;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000311
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000312 return GL_TRUE;
313}
314
315
316static void
317intelDestroyScreen(__DRIscreenPrivate * sPriv)
318{
319 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
320
Eric Anholt904f31a2008-09-16 17:01:06 -0700321 dri_bufmgr_destroy(intelScreen->bufmgr);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000322 intelUnmapScreenRegions(intelScreen);
Eric Anholt60953052009-02-11 01:15:36 -0800323 driDestroyOptionCache(&intelScreen->optionCache);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000324
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000325 FREE(intelScreen);
326 sPriv->private = NULL;
327}
328
329
330/**
331 * This is called when we need to set up GL rendering to a new X window.
332 */
333static GLboolean
334intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
335 __DRIdrawablePrivate * driDrawPriv,
336 const __GLcontextModes * mesaVis, GLboolean isPixmap)
337{
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000338 if (isPixmap) {
339 return GL_FALSE; /* not implemented */
340 }
341 else {
342 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
343 mesaVis->depthBits != 24);
Eric Anholt119f34e2009-02-25 22:54:51 -0800344 GLenum rgbFormat;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000345
Michel Dänzer6b99caf2007-02-15 16:30:40 +0100346 struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer);
347
348 if (!intel_fb)
349 return GL_FALSE;
350
351 _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000352
Eric Anholt119f34e2009-02-25 22:54:51 -0800353 if (mesaVis->redBits == 5)
354 rgbFormat = GL_RGB5;
355 else if (mesaVis->alphaBits == 0)
356 rgbFormat = GL_RGB8;
357 else
358 rgbFormat = GL_RGBA8;
359
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000360 /* setup the hardware-based renderbuffers */
Dave Airlief75843a2008-08-24 17:59:10 +1000361 intel_fb->color_rb[0] = intel_create_renderbuffer(rgbFormat);
362 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
363 &intel_fb->color_rb[0]->Base);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000364
365 if (mesaVis->doubleBufferMode) {
Dave Airlief75843a2008-08-24 17:59:10 +1000366 intel_fb->color_rb[1] = intel_create_renderbuffer(rgbFormat);
367
Michel Dänzer6b99caf2007-02-15 16:30:40 +0100368 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
Michel Dänzere33a9d62007-02-20 19:14:23 +0100369 &intel_fb->color_rb[1]->Base);
370
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000371 }
372
Eric Anholt38c61622007-11-08 14:49:37 -0800373 if (mesaVis->depthBits == 24) {
374 if (mesaVis->stencilBits == 8) {
375 /* combined depth/stencil buffer */
376 struct intel_renderbuffer *depthStencilRb
Kristian Høgsberge131c462008-01-09 16:55:32 -0500377 = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT);
Eric Anholt38c61622007-11-08 14:49:37 -0800378 /* note: bind RB to two attachment points */
379 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
380 &depthStencilRb->Base);
381 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL,
382 &depthStencilRb->Base);
383 } else {
384 struct intel_renderbuffer *depthRb
Kristian Høgsberge131c462008-01-09 16:55:32 -0500385 = intel_create_renderbuffer(GL_DEPTH_COMPONENT24);
Eric Anholt38c61622007-11-08 14:49:37 -0800386 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
387 &depthRb->Base);
388 }
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000389 }
390 else if (mesaVis->depthBits == 16) {
391 /* just 16-bit depth buffer, no hw stencil */
392 struct intel_renderbuffer *depthRb
Dave Airlief75843a2008-08-24 17:59:10 +1000393 = intel_create_renderbuffer(GL_DEPTH_COMPONENT16);
Michel Dänzer6b99caf2007-02-15 16:30:40 +0100394 _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000395 }
396
397 /* now add any/all software-based renderbuffers we may need */
Michel Dänzer6b99caf2007-02-15 16:30:40 +0100398 _mesa_add_soft_renderbuffers(&intel_fb->Base,
399 GL_FALSE, /* never sw color */
400 GL_FALSE, /* never sw depth */
401 swStencil, mesaVis->accumRedBits > 0,
402 GL_FALSE, /* never sw alpha */
403 GL_FALSE /* never sw aux */ );
404 driDrawPriv->driverPrivate = (void *) intel_fb;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000405
Michel Dänzer6b99caf2007-02-15 16:30:40 +0100406 return GL_TRUE;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000407 }
408}
409
410static void
411intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
412{
Brian Paul0f04a1d2009-03-07 11:32:18 -0700413 _mesa_reference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000414}
415
416
417/**
418 * Get information about previous buffer swaps.
419 */
420static int
421intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
422{
Michel Dänzer641c9662007-02-22 17:24:09 +0100423 struct intel_framebuffer *intel_fb;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000424
Michel Dänzer641c9662007-02-22 17:24:09 +0100425 if ((dPriv == NULL) || (dPriv->driverPrivate == NULL)
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000426 || (sInfo == NULL)) {
427 return -1;
428 }
429
Michel Dänzer641c9662007-02-22 17:24:09 +0100430 intel_fb = dPriv->driverPrivate;
431 sInfo->swap_count = intel_fb->swap_count;
432 sInfo->swap_ust = intel_fb->swap_ust;
433 sInfo->swap_missed_count = intel_fb->swap_missed_count;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000434
435 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
Michel Dänzer641c9662007-02-22 17:24:09 +0100436 ? driCalculateSwapUsage(dPriv, 0, intel_fb->swap_missed_ust)
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000437 : 0.0;
438
439 return 0;
440}
441
442
443/* There are probably better ways to do this, such as an
444 * init-designated function to register chipids and createcontext
445 * functions.
446 */
447extern GLboolean i830CreateContext(const __GLcontextModes * mesaVis,
448 __DRIcontextPrivate * driContextPriv,
449 void *sharedContextPrivate);
450
451extern GLboolean i915CreateContext(const __GLcontextModes * mesaVis,
452 __DRIcontextPrivate * driContextPriv,
453 void *sharedContextPrivate);
Eric Anholtbea6b5f2007-12-20 11:29:39 -0800454extern GLboolean brwCreateContext(const __GLcontextModes * mesaVis,
455 __DRIcontextPrivate * driContextPriv,
456 void *sharedContextPrivate);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000457
458static GLboolean
459intelCreateContext(const __GLcontextModes * mesaVis,
460 __DRIcontextPrivate * driContextPriv,
461 void *sharedContextPrivate)
462{
463 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
464 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
465
Eric Anholtbea6b5f2007-12-20 11:29:39 -0800466#ifdef I915
Eric Anholt19420e62008-02-15 13:16:01 -0800467 if (IS_9XX(intelScreen->deviceID)) {
468 if (!IS_965(intelScreen->deviceID)) {
469 return i915CreateContext(mesaVis, driContextPriv,
Eric Anholtbea6b5f2007-12-20 11:29:39 -0800470 sharedContextPrivate);
Eric Anholt19420e62008-02-15 13:16:01 -0800471 }
Eric Anholtbea6b5f2007-12-20 11:29:39 -0800472 } else {
Dave Airliecd031742008-11-28 19:38:47 +1000473 intelScreen->no_vbo = GL_TRUE;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000474 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000475 }
Eric Anholtbea6b5f2007-12-20 11:29:39 -0800476#else
477 if (IS_965(intelScreen->deviceID))
478 return brwCreateContext(mesaVis, driContextPriv, sharedContextPrivate);
479#endif
480 fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
481 return GL_FALSE;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000482}
483
484
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400485static __DRIconfig **
Kristian Høgsberg6cb3f5c2008-02-28 10:32:28 -0500486intelFillInModes(__DRIscreenPrivate *psp,
487 unsigned pixel_bits, unsigned depth_bits,
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000488 unsigned stencil_bits, GLboolean have_back_buffer)
489{
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400490 __DRIconfig **configs;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000491 __GLcontextModes *m;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000492 unsigned depth_buffer_factor;
493 unsigned back_buffer_factor;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400494 int i;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000495
496 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
497 * support pageflipping at all.
498 */
499 static const GLenum back_buffer_modes[] = {
500 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
501 };
502
Keith Whitwell5a46e172008-09-20 07:32:30 -0700503 uint8_t depth_bits_array[3];
504 uint8_t stencil_bits_array[3];
Brian Paule1359362009-02-09 11:16:20 -0700505 uint8_t msaa_samples_array[1];
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000506
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000507 depth_bits_array[0] = 0;
508 depth_bits_array[1] = depth_bits;
509 depth_bits_array[2] = depth_bits;
510
511 /* Just like with the accumulation buffer, always provide some modes
512 * with a stencil buffer. It will be a sw fallback, but some apps won't
513 * care about that.
514 */
515 stencil_bits_array[0] = 0;
516 stencil_bits_array[1] = 0;
Dave Airlieb6becfa2006-12-31 10:01:17 +1100517 if (depth_bits == 24)
518 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
519
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000520 stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
521
Michel Dänzereaf15db2009-02-10 13:47:49 +0100522 msaa_samples_array[0] = 0;
523
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000524 depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
525 back_buffer_factor = (have_back_buffer) ? 3 : 1;
526
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000527 if (pixel_bits == 16) {
Eric Anholt5d5ae372009-02-10 14:30:38 -0800528 configs = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
529 depth_bits_array, stencil_bits_array,
530 depth_buffer_factor, back_buffer_modes,
531 back_buffer_factor,
532 msaa_samples_array, 1);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000533 }
534 else {
Eric Anholt5d5ae372009-02-10 14:30:38 -0800535 __DRIconfig **configs_a8r8g8b8;
536 __DRIconfig **configs_x8r8g8b8;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000537
Eric Anholt5d5ae372009-02-10 14:30:38 -0800538 configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
539 depth_bits_array,
540 stencil_bits_array,
541 depth_buffer_factor,
542 back_buffer_modes,
543 back_buffer_factor,
544 msaa_samples_array, 1);
545 configs_x8r8g8b8 = driCreateConfigs(GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV,
546 depth_bits_array,
547 stencil_bits_array,
548 depth_buffer_factor,
549 back_buffer_modes,
550 back_buffer_factor,
551 msaa_samples_array, 1);
552 configs = driConcatConfigs(configs_a8r8g8b8, configs_x8r8g8b8);
553 }
Brian Paule1359362009-02-09 11:16:20 -0700554
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400555 if (configs == NULL) {
556 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000557 __LINE__);
558 return NULL;
559 }
560
561 /* Mark the visual as slow if there are "fake" stencil bits.
562 */
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400563 for (i = 0; configs[i]; i++) {
564 m = &configs[i]->modes;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000565 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
566 m->visualRating = GLX_SLOW_CONFIG;
567 }
568 }
569
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400570 return configs;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000571}
572
Eric Anholt7e0bbdc2008-09-04 22:16:31 +0100573static GLboolean
574intel_init_bufmgr(intelScreenPrivate *intelScreen)
575{
576 GLboolean gem_disable = getenv("INTEL_NO_GEM") != NULL;
577 int gem_kernel = 0;
578 GLboolean gem_supported;
579 struct drm_i915_getparam gp;
580 __DRIscreenPrivate *spriv = intelScreen->driScrnPriv;
Eric Anholte7aef002009-04-06 09:38:16 -0700581 int num_fences;
Eric Anholt7e0bbdc2008-09-04 22:16:31 +0100582
583 intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL;
584
585 gp.param = I915_PARAM_HAS_GEM;
586 gp.value = &gem_kernel;
587
588 (void) drmCommandWriteRead(spriv->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
589
590 /* If we've got a new enough DDX that's initializing GEM and giving us
591 * object handles for the shared buffers, use that.
592 */
593 intelScreen->ttm = GL_FALSE;
594 if (intelScreen->driScrnPriv->dri2.enabled)
595 gem_supported = GL_TRUE;
596 else if (intelScreen->driScrnPriv->ddx_version.minor >= 9 &&
597 gem_kernel &&
598 intelScreen->front.bo_handle != -1)
599 gem_supported = GL_TRUE;
600 else
601 gem_supported = GL_FALSE;
602
603 if (!gem_disable && gem_supported) {
604 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
605 if (intelScreen->bufmgr != NULL)
606 intelScreen->ttm = GL_TRUE;
607 }
608 /* Otherwise, use the classic buffer manager. */
609 if (intelScreen->bufmgr == NULL) {
610 if (gem_disable) {
611 fprintf(stderr, "GEM disabled. Using classic.\n");
612 } else {
613 fprintf(stderr, "Failed to initialize GEM. "
614 "Falling back to classic.\n");
615 }
616
617 if (intelScreen->tex.size == 0) {
618 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
619 __func__, __LINE__);
620 return GL_FALSE;
621 }
622
Eric Anholt36281852008-09-06 03:09:43 +0100623 intelScreen->bufmgr =
624 intel_bufmgr_fake_init(spriv->fd,
625 intelScreen->tex.offset,
626 intelScreen->tex.map,
627 intelScreen->tex.size,
628 (unsigned int * volatile)
629 &intelScreen->sarea->last_dispatch);
Eric Anholt7e0bbdc2008-09-04 22:16:31 +0100630 }
631
Eric Anholte7aef002009-04-06 09:38:16 -0700632 if (intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences))
633 intelScreen->kernel_exec_fencing = !!num_fences;
634 else
635 intelScreen->kernel_exec_fencing = GL_FALSE;
636
Eric Anholt7e0bbdc2008-09-04 22:16:31 +0100637 return GL_TRUE;
638}
639
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000640/**
Kristian Høgsberg64106d02007-05-14 16:58:37 -0400641 * This is the driver specific part of the createNewScreen entry point.
Brian Paul8d976ae2008-06-11 19:33:14 -0600642 * Called when using legacy DRI.
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000643 *
Kristian Høgsberg64106d02007-05-14 16:58:37 -0400644 * \todo maybe fold this into intelInitDriver
645 *
646 * \return the __GLcontextModes supported by this driver
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000647 */
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400648static const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp)
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000649{
Eric Anholt7e0bbdc2008-09-04 22:16:31 +0100650 intelScreenPrivate *intelScreen;
Eric Anholtbea6b5f2007-12-20 11:29:39 -0800651#ifdef I915
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000652 static const __DRIversion ddx_expected = { 1, 5, 0 };
Eric Anholtbea6b5f2007-12-20 11:29:39 -0800653#else
654 static const __DRIversion ddx_expected = { 1, 6, 0 };
655#endif
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000656 static const __DRIversion dri_expected = { 4, 0, 0 };
Eric Anholt4cf2cc02007-05-18 11:29:55 -0700657 static const __DRIversion drm_expected = { 1, 5, 0 };
Kristian Høgsberg64106d02007-05-14 16:58:37 -0400658 I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000659
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000660 if (!driCheckDriDdxDrmVersions2("i915",
Kristian Høgsberg64106d02007-05-14 16:58:37 -0400661 &psp->dri_version, &dri_expected,
662 &psp->ddx_version, &ddx_expected,
663 &psp->drm_version, &drm_expected)) {
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000664 return NULL;
665 }
666
Kristian Høgsberg64106d02007-05-14 16:58:37 -0400667 /* Calling driInitExtensions here, with a NULL context pointer,
668 * does not actually enable the extensions. It just makes sure
669 * that all the dispatch offsets for all the extensions that
670 * *might* be enables are known. This is needed because the
671 * dispatch offsets need to be known when _mesa_context_create is
672 * called, but we can't enable the extensions until we have a
673 * context pointer.
674 *
675 * Hello chicken. Hello egg. How are you two today?
676 */
Kristian Høgsberg60c0f092008-02-27 11:19:29 -0500677 intelInitExtensions(NULL, GL_TRUE);
678
Kristian Høgsberg64106d02007-05-14 16:58:37 -0400679 if (!intelInitDriver(psp))
680 return NULL;
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000681
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400682 psp->extensions = intelScreenExtensions;
683
Eric Anholt7e0bbdc2008-09-04 22:16:31 +0100684 intelScreen = psp->private;
685 if (!intel_init_bufmgr(intelScreen))
686 return GL_FALSE;
687
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400688 return (const __DRIconfig **)
689 intelFillInModes(psp, dri_priv->cpp * 8,
690 (dri_priv->cpp == 2) ? 16 : 24,
691 (dri_priv->cpp == 2) ? 0 : 8, 1);
Keith Whitwell6b9e31f2006-11-01 12:03:11 +0000692}
693
694struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
695{
696 /*
697 * This should probably change to have the screen allocate a dummy
698 * context at screen creation. For now just use the current context.
699 */
700
701 GET_CURRENT_CONTEXT(ctx);
702 if (ctx == NULL) {
703 _mesa_problem(NULL, "No current context in intelScreenContext\n");
704 return NULL;
705 }
706 return intel_context(ctx);
707}
708
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500709/**
710 * This is the driver specific part of the createNewScreen entry point.
Brian Paul8d976ae2008-06-11 19:33:14 -0600711 * Called when using DRI2.
712 *
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500713 * \return the __GLcontextModes supported by this driver
714 */
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400715static const
716__DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp)
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500717{
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500718 intelScreenPrivate *intelScreen;
Eric Anholt3ee21f32009-01-29 14:57:49 -0800719 GLenum fb_format[3];
720 GLenum fb_type[3];
721 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
722 * support pageflipping at all.
723 */
724 static const GLenum back_buffer_modes[] = {
725 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
726 };
Brian Paule1359362009-02-09 11:16:20 -0700727 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
Eric Anholt3ee21f32009-01-29 14:57:49 -0800728 int color;
Eric Anholt5d5ae372009-02-10 14:30:38 -0800729 __DRIconfig **configs = NULL;
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500730
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500731 /* Calling driInitExtensions here, with a NULL context pointer,
732 * does not actually enable the extensions. It just makes sure
733 * that all the dispatch offsets for all the extensions that
734 * *might* be enables are known. This is needed because the
735 * dispatch offsets need to be known when _mesa_context_create is
736 * called, but we can't enable the extensions until we have a
737 * context pointer.
738 *
739 * Hello chicken. Hello egg. How are you two today?
740 */
Kristian Høgsberg60c0f092008-02-27 11:19:29 -0500741 intelInitExtensions(NULL, GL_TRUE);
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500742
743 /* Allocate the private area */
744 intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
745 if (!intelScreen) {
746 fprintf(stderr, "\nERROR! Allocating private area failed\n");
747 return GL_FALSE;
748 }
749 /* parse information in __driConfigOptions */
750 driParseOptionInfo(&intelScreen->optionCache,
751 __driConfigOptions, __driNConfigOptions);
752
753 intelScreen->driScrnPriv = psp;
754 psp->private = (void *) intelScreen;
755
756 intelScreen->drmMinor = psp->drm_version.minor;
757
Kristian Høgsbergf56b5692008-08-13 11:46:25 -0400758 /* Determine chipset ID */
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500759 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
760 &intelScreen->deviceID))
761 return GL_FALSE;
762
Eric Anholt7e0bbdc2008-09-04 22:16:31 +0100763 if (!intel_init_bufmgr(intelScreen))
764 return GL_FALSE;
765
Kristian Høgsbergf56b5692008-08-13 11:46:25 -0400766 intelScreen->irq_active = 1;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400767 psp->extensions = intelScreenExtensions;
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500768
Eric Anholt3ee21f32009-01-29 14:57:49 -0800769 depth_bits[0] = 0;
770 stencil_bits[0] = 0;
771 depth_bits[1] = 16;
772 stencil_bits[1] = 0;
773 depth_bits[2] = 24;
774 stencil_bits[2] = 0;
775 depth_bits[3] = 24;
776 stencil_bits[3] = 8;
777
Michel Dänzereaf15db2009-02-10 13:47:49 +0100778 msaa_samples_array[0] = 0;
779
Eric Anholt3ee21f32009-01-29 14:57:49 -0800780 fb_format[0] = GL_RGB;
781 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5;
782
Eric Anholt24ff1692009-01-31 10:32:34 -0800783 fb_format[1] = GL_BGR;
Eric Anholt3ee21f32009-01-29 14:57:49 -0800784 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV;
785
Eric Anholt24ff1692009-01-31 10:32:34 -0800786 fb_format[2] = GL_BGRA;
Eric Anholt3ee21f32009-01-29 14:57:49 -0800787 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV;
788
Eric Anholt160c3612009-02-26 00:18:46 -0800789 depth_bits[0] = 0;
790 stencil_bits[0] = 0;
791
Eric Anholt3ee21f32009-01-29 14:57:49 -0800792 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
Eric Anholt5d5ae372009-02-10 14:30:38 -0800793 __DRIconfig **new_configs;
Eric Anholt160c3612009-02-26 00:18:46 -0800794 int depth_factor;
Eric Anholt3ee21f32009-01-29 14:57:49 -0800795
Eric Anholt160c3612009-02-26 00:18:46 -0800796 /* With DRI2 right now, GetBuffers always returns a depth/stencil buffer
797 * with the same cpp as the drawable. So we can't support depth cpp !=
798 * color cpp currently.
799 */
800 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
801 depth_bits[1] = 16;
802 stencil_bits[1] = 0;
803
804 depth_factor = 2;
805 } else {
806 depth_bits[1] = 24;
807 stencil_bits[1] = 0;
808 depth_bits[2] = 24;
809 stencil_bits[2] = 8;
810
811 depth_factor = 3;
812 }
Eric Anholt5d5ae372009-02-10 14:30:38 -0800813 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
814 depth_bits,
815 stencil_bits,
Eric Anholt160c3612009-02-26 00:18:46 -0800816 depth_factor,
Eric Anholt5d5ae372009-02-10 14:30:38 -0800817 back_buffer_modes,
818 ARRAY_SIZE(back_buffer_modes),
819 msaa_samples_array,
820 ARRAY_SIZE(msaa_samples_array));
Eric Anholt3ee21f32009-01-29 14:57:49 -0800821 if (configs == NULL)
822 configs = new_configs;
823 else
824 configs = driConcatConfigs(configs, new_configs);
825 }
826
827 if (configs == NULL) {
828 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
829 __LINE__);
830 return NULL;
831 }
832
Eric Anholt5d5ae372009-02-10 14:30:38 -0800833 return (const __DRIconfig **)configs;
Kristian Høgsbergc5c73c12008-01-21 17:07:33 -0500834}
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400835
836const struct __DriverAPIRec driDriverAPI = {
837 .InitScreen = intelInitScreen,
838 .DestroyScreen = intelDestroyScreen,
839 .CreateContext = intelCreateContext,
840 .DestroyContext = intelDestroyContext,
841 .CreateBuffer = intelCreateBuffer,
842 .DestroyBuffer = intelDestroyBuffer,
843 .SwapBuffers = intelSwapBuffers,
844 .MakeCurrent = intelMakeCurrent,
845 .UnbindContext = intelUnbindContext,
846 .GetSwapInfo = intelGetSwapInfo,
847 .GetDrawableMSC = driDrawableGetMSC32,
848 .WaitForMSC = driWaitForMSC32,
849 .CopySubBuffer = intelCopySubBuffer,
850
851 .InitScreen2 = intelInitScreen2,
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400852};