Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 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 | |
| 28 | #include "glheader.h" |
| 29 | #include "context.h" |
| 30 | #include "framebuffer.h" |
| 31 | #include "matrix.h" |
| 32 | #include "renderbuffer.h" |
| 33 | #include "simple_list.h" |
| 34 | #include "utils.h" |
| 35 | #include "vblank.h" |
| 36 | #include "xmlpool.h" |
| 37 | |
| 38 | |
| 39 | #include "intel_screen.h" |
| 40 | |
| 41 | #include "intel_buffers.h" |
| 42 | #include "intel_tex.h" |
| 43 | #include "intel_span.h" |
| 44 | #include "intel_tris.h" |
| 45 | #include "intel_ioctl.h" |
| 46 | #include "intel_fbo.h" |
| 47 | |
| 48 | #include "i830_dri.h" |
Eric Anholt | cfc2119 | 2007-05-17 15:28:01 -0700 | [diff] [blame] | 49 | #include "dri_bufmgr.h" |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 50 | #include "intel_regions.h" |
| 51 | #include "intel_batchbuffer.h" |
| 52 | |
Dave Airlie | c4a9a70 | 2007-10-04 15:31:47 +1000 | [diff] [blame] | 53 | #include "intel_bufmgr_ttm.h" |
| 54 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 55 | PUBLIC const char __driConfigOptions[] = |
| 56 | DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE |
| 57 | DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS) |
| 58 | DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) |
| 59 | DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY |
| 60 | DRI_CONF_FORCE_S3TC_ENABLE(false) |
| 61 | DRI_CONF_ALLOW_LARGE_TEXTURES(1) |
| 62 | DRI_CONF_SECTION_END DRI_CONF_END; |
| 63 | const GLuint __driNConfigOptions = 4; |
| 64 | |
| 65 | #ifdef USE_NEW_INTERFACE |
| 66 | static PFNGLXCREATECONTEXTMODES create_context_modes = NULL; |
| 67 | #endif /*USE_NEW_INTERFACE */ |
| 68 | |
| 69 | extern const struct dri_extension card_extensions[]; |
Michel Dänzer | 3feefee | 2007-10-16 15:48:46 +0200 | [diff] [blame^] | 70 | extern const struct dri_extension ttm_extensions[]; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Map all the memory regions described by the screen. |
| 74 | * \return GL_TRUE if success, GL_FALSE if error. |
| 75 | */ |
| 76 | GLboolean |
| 77 | intelMapScreenRegions(__DRIscreenPrivate * sPriv) |
| 78 | { |
| 79 | intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private; |
| 80 | |
| 81 | if (intelScreen->front.handle) { |
| 82 | if (drmMap(sPriv->fd, |
| 83 | intelScreen->front.handle, |
| 84 | intelScreen->front.size, |
| 85 | (drmAddress *) & intelScreen->front.map) != 0) { |
| 86 | _mesa_problem(NULL, "drmMap(frontbuffer) failed!"); |
| 87 | return GL_FALSE; |
| 88 | } |
| 89 | } |
| 90 | else { |
| 91 | _mesa_warning(NULL, "no front buffer handle in intelMapScreenRegions!"); |
| 92 | } |
| 93 | |
Brian Paul | 4db0c89 | 2006-11-01 18:48:28 +0000 | [diff] [blame] | 94 | if (0) |
| 95 | _mesa_printf("Back 0x%08x ", intelScreen->back.handle); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 96 | if (drmMap(sPriv->fd, |
| 97 | intelScreen->back.handle, |
| 98 | intelScreen->back.size, |
| 99 | (drmAddress *) & intelScreen->back.map) != 0) { |
| 100 | intelUnmapScreenRegions(intelScreen); |
| 101 | return GL_FALSE; |
| 102 | } |
| 103 | |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 104 | if (intelScreen->third.handle) { |
| 105 | if (0) |
| 106 | _mesa_printf("Third 0x%08x ", intelScreen->third.handle); |
| 107 | if (drmMap(sPriv->fd, |
| 108 | intelScreen->third.handle, |
| 109 | intelScreen->third.size, |
| 110 | (drmAddress *) & intelScreen->third.map) != 0) { |
| 111 | intelUnmapScreenRegions(intelScreen); |
| 112 | return GL_FALSE; |
| 113 | } |
| 114 | } |
| 115 | |
Brian Paul | 4db0c89 | 2006-11-01 18:48:28 +0000 | [diff] [blame] | 116 | if (0) |
| 117 | _mesa_printf("Depth 0x%08x ", intelScreen->depth.handle); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 118 | if (drmMap(sPriv->fd, |
| 119 | intelScreen->depth.handle, |
| 120 | intelScreen->depth.size, |
| 121 | (drmAddress *) & intelScreen->depth.map) != 0) { |
| 122 | intelUnmapScreenRegions(intelScreen); |
| 123 | return GL_FALSE; |
| 124 | } |
| 125 | |
Eric Anholt | cfc2119 | 2007-05-17 15:28:01 -0700 | [diff] [blame] | 126 | if (0) |
| 127 | _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle); |
| 128 | if (intelScreen->tex.size != 0) { |
Eric Anholt | cfc2119 | 2007-05-17 15:28:01 -0700 | [diff] [blame] | 129 | if (drmMap(sPriv->fd, |
| 130 | intelScreen->tex.handle, |
| 131 | intelScreen->tex.size, |
| 132 | (drmAddress *) & intelScreen->tex.map) != 0) { |
| 133 | intelUnmapScreenRegions(intelScreen); |
| 134 | return GL_FALSE; |
| 135 | } |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 136 | } |
Eric Anholt | cfc2119 | 2007-05-17 15:28:01 -0700 | [diff] [blame] | 137 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 138 | if (0) |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 139 | printf("Mappings: front: %p back: %p third: %p depth: %p tex: %p\n", |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 140 | intelScreen->front.map, |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 141 | intelScreen->back.map, intelScreen->third.map, |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 142 | intelScreen->depth.map, intelScreen->tex.map); |
| 143 | return GL_TRUE; |
| 144 | } |
| 145 | |
Eric Anholt | cfc2119 | 2007-05-17 15:28:01 -0700 | [diff] [blame] | 146 | /** Driver-specific fence emit implementation for the fake memory manager. */ |
| 147 | static unsigned int |
| 148 | intel_fence_emit(void *private) |
| 149 | { |
| 150 | intelScreenPrivate *intelScreen = (intelScreenPrivate *)private; |
| 151 | unsigned int fence; |
| 152 | |
| 153 | /* XXX: Need to emit a flush, if we haven't already (at least with the |
| 154 | * current batchbuffer implementation, we have). |
| 155 | */ |
| 156 | |
| 157 | fence = intelEmitIrqLocked(intelScreen); |
| 158 | |
| 159 | return fence; |
| 160 | } |
| 161 | |
| 162 | /** Driver-specific fence wait implementation for the fake memory manager. */ |
| 163 | static int |
| 164 | intel_fence_wait(void *private, unsigned int cookie) |
| 165 | { |
| 166 | intelScreenPrivate *intelScreen = (intelScreenPrivate *)private; |
| 167 | |
| 168 | intelWaitIrq(intelScreen, cookie); |
| 169 | |
| 170 | return 0; |
| 171 | } |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 172 | |
| 173 | static struct intel_region * |
| 174 | intel_recreate_static(intelScreenPrivate *intelScreen, |
| 175 | struct intel_region *region, |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 176 | intelRegion *region_desc, |
| 177 | GLuint mem_type) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 178 | { |
| 179 | if (region) { |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 180 | intel_region_update_static(intelScreen, region, mem_type, |
| 181 | region_desc->bo_handle, region_desc->offset, |
| 182 | region_desc->map, intelScreen->cpp, |
| 183 | region_desc->pitch / intelScreen->cpp, |
| 184 | intelScreen->height); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 185 | } else { |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 186 | region = intel_region_create_static(intelScreen, mem_type, |
| 187 | region_desc->bo_handle, |
| 188 | region_desc->offset, |
| 189 | region_desc->map, intelScreen->cpp, |
| 190 | region_desc->pitch / intelScreen->cpp, |
| 191 | intelScreen->height); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 192 | } |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 193 | |
| 194 | assert(region->buffer != NULL); |
| 195 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 196 | return region; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | /* Create intel_region structs to describe the static front,back,depth |
| 201 | * buffers created by the xserver. |
| 202 | * |
| 203 | * Although FBO's mean we now no longer use these as render targets in |
| 204 | * all circumstances, they won't go away until the back and depth |
| 205 | * buffers become private, and the front and rotated buffers will |
| 206 | * remain even then. |
| 207 | * |
| 208 | * Note that these don't allocate video memory, just describe |
| 209 | * allocations alread made by the X server. |
| 210 | */ |
| 211 | static void |
| 212 | intel_recreate_static_regions(intelScreenPrivate *intelScreen) |
| 213 | { |
| 214 | intelScreen->front_region = |
| 215 | intel_recreate_static(intelScreen, |
| 216 | intelScreen->front_region, |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 217 | &intelScreen->front, |
| 218 | DRM_BO_FLAG_MEM_TT); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 219 | |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 220 | /* The rotated region is only used for old DDXes that didn't handle rotation |
| 221 | \ * on their own. |
| 222 | */ |
Kristian Høgsberg | efd03a2 | 2007-05-14 16:37:19 -0400 | [diff] [blame] | 223 | if (intelScreen->driScrnPriv->ddx_version.minor < 8) { |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 224 | intelScreen->rotated_region = |
| 225 | intel_recreate_static(intelScreen, |
| 226 | intelScreen->rotated_region, |
| 227 | &intelScreen->rotated, |
| 228 | DRM_BO_FLAG_MEM_TT); |
| 229 | } |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 230 | |
| 231 | intelScreen->back_region = |
| 232 | intel_recreate_static(intelScreen, |
| 233 | intelScreen->back_region, |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 234 | &intelScreen->back, |
| 235 | DRM_BO_FLAG_MEM_TT); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 236 | |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 237 | if (intelScreen->third.handle) { |
| 238 | intelScreen->third_region = |
| 239 | intel_recreate_static(intelScreen, |
| 240 | intelScreen->third_region, |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 241 | &intelScreen->third, |
| 242 | DRM_BO_FLAG_MEM_TT); |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 245 | /* Still assumes front.cpp == depth.cpp. We can kill this when we move to |
| 246 | * private buffers. |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 247 | */ |
| 248 | intelScreen->depth_region = |
| 249 | intel_recreate_static(intelScreen, |
| 250 | intelScreen->depth_region, |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 251 | &intelScreen->depth, |
| 252 | DRM_BO_FLAG_MEM_TT); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Use the information in the sarea to update the screen parameters |
| 257 | * related to screen rotation. Needs to be called locked. |
| 258 | */ |
| 259 | void |
| 260 | intelUpdateScreenRotation(__DRIscreenPrivate * sPriv, drmI830Sarea * sarea) |
| 261 | { |
| 262 | intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private; |
| 263 | |
| 264 | intelUnmapScreenRegions(intelScreen); |
| 265 | intelUpdateScreenFromSAREA(intelScreen, sarea); |
| 266 | if (!intelMapScreenRegions(sPriv)) { |
| 267 | fprintf(stderr, "ERROR Remapping screen regions!!!\n"); |
| 268 | } |
| 269 | intel_recreate_static_regions(intelScreen); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | void |
| 274 | intelUnmapScreenRegions(intelScreenPrivate * intelScreen) |
| 275 | { |
| 276 | #define REALLY_UNMAP 1 |
| 277 | if (intelScreen->front.map) { |
| 278 | #if REALLY_UNMAP |
| 279 | if (drmUnmap(intelScreen->front.map, intelScreen->front.size) != 0) |
| 280 | printf("drmUnmap front failed!\n"); |
| 281 | #endif |
| 282 | intelScreen->front.map = NULL; |
| 283 | } |
| 284 | if (intelScreen->back.map) { |
| 285 | #if REALLY_UNMAP |
| 286 | if (drmUnmap(intelScreen->back.map, intelScreen->back.size) != 0) |
| 287 | printf("drmUnmap back failed!\n"); |
| 288 | #endif |
| 289 | intelScreen->back.map = NULL; |
| 290 | } |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 291 | if (intelScreen->third.map) { |
| 292 | #if REALLY_UNMAP |
| 293 | if (drmUnmap(intelScreen->third.map, intelScreen->third.size) != 0) |
| 294 | printf("drmUnmap third failed!\n"); |
| 295 | #endif |
| 296 | intelScreen->third.map = NULL; |
| 297 | } |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 298 | if (intelScreen->depth.map) { |
| 299 | #if REALLY_UNMAP |
| 300 | drmUnmap(intelScreen->depth.map, intelScreen->depth.size); |
| 301 | intelScreen->depth.map = NULL; |
| 302 | #endif |
| 303 | } |
| 304 | if (intelScreen->tex.map) { |
| 305 | #if REALLY_UNMAP |
| 306 | drmUnmap(intelScreen->tex.map, intelScreen->tex.size); |
| 307 | intelScreen->tex.map = NULL; |
| 308 | #endif |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | |
| 313 | static void |
| 314 | intelPrintDRIInfo(intelScreenPrivate * intelScreen, |
| 315 | __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv) |
| 316 | { |
| 317 | fprintf(stderr, "*** Front size: 0x%x offset: 0x%x pitch: %d\n", |
| 318 | intelScreen->front.size, intelScreen->front.offset, |
| 319 | intelScreen->front.pitch); |
| 320 | fprintf(stderr, "*** Back size: 0x%x offset: 0x%x pitch: %d\n", |
| 321 | intelScreen->back.size, intelScreen->back.offset, |
| 322 | intelScreen->back.pitch); |
| 323 | fprintf(stderr, "*** Depth size: 0x%x offset: 0x%x pitch: %d\n", |
| 324 | intelScreen->depth.size, intelScreen->depth.offset, |
| 325 | intelScreen->depth.pitch); |
| 326 | fprintf(stderr, "*** Rotated size: 0x%x offset: 0x%x pitch: %d\n", |
| 327 | intelScreen->rotated.size, intelScreen->rotated.offset, |
| 328 | intelScreen->rotated.pitch); |
| 329 | fprintf(stderr, "*** Texture size: 0x%x offset: 0x%x\n", |
| 330 | intelScreen->tex.size, intelScreen->tex.offset); |
| 331 | fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | static void |
| 336 | intelPrintSAREA(const drmI830Sarea * sarea) |
| 337 | { |
| 338 | fprintf(stderr, "SAREA: sarea width %d height %d\n", sarea->width, |
| 339 | sarea->height); |
| 340 | fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch); |
| 341 | fprintf(stderr, |
| 342 | "SAREA: front offset: 0x%08x size: 0x%x handle: 0x%x\n", |
| 343 | sarea->front_offset, sarea->front_size, |
| 344 | (unsigned) sarea->front_handle); |
| 345 | fprintf(stderr, |
| 346 | "SAREA: back offset: 0x%08x size: 0x%x handle: 0x%x\n", |
| 347 | sarea->back_offset, sarea->back_size, |
| 348 | (unsigned) sarea->back_handle); |
| 349 | fprintf(stderr, "SAREA: depth offset: 0x%08x size: 0x%x handle: 0x%x\n", |
| 350 | sarea->depth_offset, sarea->depth_size, |
| 351 | (unsigned) sarea->depth_handle); |
| 352 | fprintf(stderr, "SAREA: tex offset: 0x%08x size: 0x%x handle: 0x%x\n", |
| 353 | sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle); |
| 354 | fprintf(stderr, "SAREA: rotation: %d\n", sarea->rotation); |
| 355 | fprintf(stderr, |
| 356 | "SAREA: rotated offset: 0x%08x size: 0x%x\n", |
| 357 | sarea->rotated_offset, sarea->rotated_size); |
| 358 | fprintf(stderr, "SAREA: rotated pitch: %d\n", sarea->rotated_pitch); |
| 359 | } |
| 360 | |
| 361 | |
| 362 | /** |
| 363 | * A number of the screen parameters are obtained/computed from |
| 364 | * information in the SAREA. This function updates those parameters. |
| 365 | */ |
| 366 | void |
| 367 | intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen, |
| 368 | drmI830Sarea * sarea) |
| 369 | { |
| 370 | intelScreen->width = sarea->width; |
| 371 | intelScreen->height = sarea->height; |
| 372 | |
| 373 | intelScreen->front.offset = sarea->front_offset; |
| 374 | intelScreen->front.pitch = sarea->pitch * intelScreen->cpp; |
| 375 | intelScreen->front.handle = sarea->front_handle; |
| 376 | intelScreen->front.size = sarea->front_size; |
| 377 | |
| 378 | intelScreen->back.offset = sarea->back_offset; |
| 379 | intelScreen->back.pitch = sarea->pitch * intelScreen->cpp; |
| 380 | intelScreen->back.handle = sarea->back_handle; |
| 381 | intelScreen->back.size = sarea->back_size; |
| 382 | |
Kristian Høgsberg | efd03a2 | 2007-05-14 16:37:19 -0400 | [diff] [blame] | 383 | if (intelScreen->driScrnPriv->ddx_version.minor >= 8) { |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 384 | intelScreen->third.offset = sarea->third_offset; |
| 385 | intelScreen->third.pitch = sarea->pitch * intelScreen->cpp; |
| 386 | intelScreen->third.handle = sarea->third_handle; |
| 387 | intelScreen->third.size = sarea->third_size; |
| 388 | } |
| 389 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 390 | intelScreen->depth.offset = sarea->depth_offset; |
| 391 | intelScreen->depth.pitch = sarea->pitch * intelScreen->cpp; |
| 392 | intelScreen->depth.handle = sarea->depth_handle; |
| 393 | intelScreen->depth.size = sarea->depth_size; |
| 394 | |
Kristian Høgsberg | efd03a2 | 2007-05-14 16:37:19 -0400 | [diff] [blame] | 395 | if (intelScreen->driScrnPriv->ddx_version.minor >= 9) { |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 396 | intelScreen->front.bo_handle = sarea->front_bo_handle; |
| 397 | intelScreen->back.bo_handle = sarea->back_bo_handle; |
| 398 | intelScreen->third.bo_handle = sarea->third_bo_handle; |
| 399 | intelScreen->depth.bo_handle = sarea->depth_bo_handle; |
| 400 | } else { |
| 401 | intelScreen->front.bo_handle = -1; |
| 402 | intelScreen->back.bo_handle = -1; |
| 403 | intelScreen->third.bo_handle = -1; |
| 404 | intelScreen->depth.bo_handle = -1; |
| 405 | } |
| 406 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 407 | intelScreen->tex.offset = sarea->tex_offset; |
| 408 | intelScreen->logTextureGranularity = sarea->log_tex_granularity; |
| 409 | intelScreen->tex.handle = sarea->tex_handle; |
| 410 | intelScreen->tex.size = sarea->tex_size; |
| 411 | |
| 412 | intelScreen->rotated.offset = sarea->rotated_offset; |
| 413 | intelScreen->rotated.pitch = sarea->rotated_pitch * intelScreen->cpp; |
| 414 | intelScreen->rotated.size = sarea->rotated_size; |
| 415 | intelScreen->current_rotation = sarea->rotation; |
| 416 | matrix23Rotate(&intelScreen->rotMatrix, |
| 417 | sarea->width, sarea->height, sarea->rotation); |
| 418 | intelScreen->rotatedWidth = sarea->virtualX; |
| 419 | intelScreen->rotatedHeight = sarea->virtualY; |
| 420 | |
| 421 | if (0) |
| 422 | intelPrintSAREA(sarea); |
| 423 | } |
| 424 | |
Michel Dänzer | 9c4d104 | 2007-10-16 13:01:44 +0200 | [diff] [blame] | 425 | static const __DRItexOffsetExtension intelTexOffsetExtension = { |
| 426 | { __DRI_TEX_OFFSET }, |
| 427 | intelSetTexOffset, |
| 428 | }; |
| 429 | |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 430 | static const __DRIextension *intelExtensions[] = { |
Kristian Høgsberg | f968f67 | 2007-05-17 14:39:06 -0400 | [diff] [blame] | 431 | &driReadDrawableExtension, |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 432 | &driCopySubBufferExtension.base, |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 433 | &driSwapControlExtension.base, |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 434 | &driFrameTrackingExtension.base, |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 435 | &driMediaStreamCounterExtension.base, |
Michel Dänzer | 9c4d104 | 2007-10-16 13:01:44 +0200 | [diff] [blame] | 436 | &intelTexOffsetExtension.base, |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 437 | NULL |
| 438 | }; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 439 | |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 440 | |
| 441 | static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 442 | { |
| 443 | intelScreenPrivate *intelScreen; |
| 444 | I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv; |
| 445 | drmI830Sarea *sarea; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 446 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 447 | if (sPriv->devPrivSize != sizeof(I830DRIRec)) { |
| 448 | fprintf(stderr, |
| 449 | "\nERROR! sizeof(I830DRIRec) does not match passed size from device driver\n"); |
| 450 | return GL_FALSE; |
| 451 | } |
| 452 | |
| 453 | /* Allocate the private area */ |
| 454 | intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate)); |
| 455 | if (!intelScreen) { |
| 456 | fprintf(stderr, "\nERROR! Allocating private area failed\n"); |
| 457 | return GL_FALSE; |
| 458 | } |
| 459 | /* parse information in __driConfigOptions */ |
| 460 | driParseOptionInfo(&intelScreen->optionCache, |
| 461 | __driConfigOptions, __driNConfigOptions); |
| 462 | |
| 463 | intelScreen->driScrnPriv = sPriv; |
| 464 | sPriv->private = (void *) intelScreen; |
| 465 | intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset; |
| 466 | sarea = (drmI830Sarea *) |
| 467 | (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset); |
| 468 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 469 | intelScreen->deviceID = gDRIPriv->deviceID; |
| 470 | if (intelScreen->deviceID == PCI_CHIP_I865_G) |
| 471 | intelScreen->maxBatchSize = 4096; |
Eric Anholt | cfc2119 | 2007-05-17 15:28:01 -0700 | [diff] [blame] | 472 | else |
| 473 | intelScreen->maxBatchSize = BATCH_SZ; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 474 | |
| 475 | intelScreen->mem = gDRIPriv->mem; |
| 476 | intelScreen->cpp = gDRIPriv->cpp; |
| 477 | |
| 478 | switch (gDRIPriv->bitsPerPixel) { |
| 479 | case 16: |
| 480 | intelScreen->fbFormat = DV_PF_565; |
| 481 | break; |
| 482 | case 32: |
| 483 | intelScreen->fbFormat = DV_PF_8888; |
| 484 | break; |
| 485 | default: |
| 486 | exit(1); |
| 487 | break; |
| 488 | } |
| 489 | |
| 490 | intelUpdateScreenFromSAREA(intelScreen, sarea); |
| 491 | |
| 492 | if (!intelMapScreenRegions(sPriv)) { |
| 493 | fprintf(stderr, "\nERROR! mapping regions\n"); |
| 494 | _mesa_free(intelScreen); |
| 495 | sPriv->private = NULL; |
| 496 | return GL_FALSE; |
| 497 | } |
| 498 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 499 | intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset; |
| 500 | |
Brian Paul | 4db0c89 | 2006-11-01 18:48:28 +0000 | [diff] [blame] | 501 | if (0) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 502 | intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv); |
| 503 | |
Kristian Høgsberg | efd03a2 | 2007-05-14 16:37:19 -0400 | [diff] [blame] | 504 | intelScreen->drmMinor = sPriv->drm_version.minor; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 505 | |
| 506 | /* Determine if IRQs are active? */ |
| 507 | { |
| 508 | int ret; |
| 509 | drmI830GetParam gp; |
| 510 | |
| 511 | gp.param = I830_PARAM_IRQ_ACTIVE; |
| 512 | gp.value = &intelScreen->irq_active; |
| 513 | |
| 514 | ret = drmCommandWriteRead(sPriv->fd, DRM_I830_GETPARAM, |
| 515 | &gp, sizeof(gp)); |
| 516 | if (ret) { |
| 517 | fprintf(stderr, "drmI830GetParam: %d\n", ret); |
| 518 | return GL_FALSE; |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /* Determine if batchbuffers are allowed */ |
| 523 | { |
| 524 | int ret; |
| 525 | drmI830GetParam gp; |
| 526 | |
| 527 | gp.param = I830_PARAM_ALLOW_BATCHBUFFER; |
| 528 | gp.value = &intelScreen->allow_batchbuffer; |
| 529 | |
| 530 | ret = drmCommandWriteRead(sPriv->fd, DRM_I830_GETPARAM, |
| 531 | &gp, sizeof(gp)); |
| 532 | if (ret) { |
| 533 | fprintf(stderr, "drmI830GetParam: (%d) %d\n", gp.param, ret); |
| 534 | return GL_FALSE; |
| 535 | } |
| 536 | } |
| 537 | |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 538 | sPriv->extensions = intelExtensions; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 539 | |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 540 | /* If we've got a new enough DDX that's initializing TTM and giving us |
| 541 | * object handles for the shared buffers, use that. |
| 542 | */ |
| 543 | intelScreen->ttm = GL_FALSE; |
| 544 | if (getenv("INTEL_NO_TTM") == NULL && |
Kristian Høgsberg | efd03a2 | 2007-05-14 16:37:19 -0400 | [diff] [blame] | 545 | intelScreen->driScrnPriv->ddx_version.minor >= 9 && |
Dave Airlie | 9e06cf0 | 2007-10-12 11:01:17 +1000 | [diff] [blame] | 546 | intelScreen->drmMinor >= 11 && |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 547 | intelScreen->front.bo_handle != -1) { |
Dave Airlie | fa031c8 | 2007-10-03 16:54:59 +1000 | [diff] [blame] | 548 | intelScreen->bufmgr = intel_bufmgr_ttm_init(sPriv->fd, |
Dave Airlie | 8909f11 | 2007-10-09 14:36:04 +1000 | [diff] [blame] | 549 | DRM_FENCE_TYPE_EXE, |
| 550 | DRM_FENCE_TYPE_EXE | |
| 551 | DRM_I915_FENCE_TYPE_RW, |
| 552 | BATCH_SZ); |
Eric Anholt | 3e168a0 | 2007-08-16 14:32:53 -0700 | [diff] [blame] | 553 | if (intelScreen->bufmgr != NULL) |
| 554 | intelScreen->ttm = GL_TRUE; |
| 555 | } |
| 556 | /* Otherwise, use the classic buffer manager. */ |
Eric Anholt | 1ddbfd7 | 2007-06-18 12:19:42 -0700 | [diff] [blame] | 557 | if (intelScreen->bufmgr == NULL) { |
| 558 | if (intelScreen->tex.size == 0) { |
| 559 | fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n", |
| 560 | __func__, __LINE__); |
| 561 | return GL_FALSE; |
| 562 | } |
Eric Anholt | 9a4cc2e | 2007-07-25 10:12:23 -0700 | [diff] [blame] | 563 | fprintf(stderr, "[%s:%u] Failed to init TTM buffer manager, falling back" |
| 564 | " to classic.\n", __func__, __LINE__); |
Eric Anholt | cfc2119 | 2007-05-17 15:28:01 -0700 | [diff] [blame] | 565 | intelScreen->bufmgr = dri_bufmgr_fake_init(intelScreen->tex.offset, |
| 566 | intelScreen->tex.map, |
| 567 | intelScreen->tex.size, |
| 568 | intel_fence_emit, |
| 569 | intel_fence_wait, |
| 570 | intelScreen); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | intel_recreate_static_regions(intelScreen); |
| 574 | |
| 575 | return GL_TRUE; |
| 576 | } |
| 577 | |
| 578 | |
| 579 | static void |
| 580 | intelDestroyScreen(__DRIscreenPrivate * sPriv) |
| 581 | { |
| 582 | intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private; |
| 583 | |
| 584 | intelUnmapScreenRegions(intelScreen); |
| 585 | |
Eric Anholt | 2ac17c6 | 2007-05-31 09:45:45 -0700 | [diff] [blame] | 586 | dri_bufmgr_destroy(intelScreen->bufmgr); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 587 | FREE(intelScreen); |
| 588 | sPriv->private = NULL; |
| 589 | } |
| 590 | |
| 591 | |
| 592 | /** |
| 593 | * This is called when we need to set up GL rendering to a new X window. |
| 594 | */ |
| 595 | static GLboolean |
| 596 | intelCreateBuffer(__DRIscreenPrivate * driScrnPriv, |
| 597 | __DRIdrawablePrivate * driDrawPriv, |
| 598 | const __GLcontextModes * mesaVis, GLboolean isPixmap) |
| 599 | { |
| 600 | intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private; |
| 601 | |
| 602 | if (isPixmap) { |
| 603 | return GL_FALSE; /* not implemented */ |
| 604 | } |
| 605 | else { |
| 606 | GLboolean swStencil = (mesaVis->stencilBits > 0 && |
| 607 | mesaVis->depthBits != 24); |
| 608 | GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8); |
| 609 | |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 610 | struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer); |
| 611 | |
| 612 | if (!intel_fb) |
| 613 | return GL_FALSE; |
| 614 | |
| 615 | _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 616 | |
| 617 | /* setup the hardware-based renderbuffers */ |
| 618 | { |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 619 | intel_fb->color_rb[0] |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 620 | = intel_create_renderbuffer(rgbFormat, |
| 621 | screen->width, screen->height, |
| 622 | screen->front.offset, |
| 623 | screen->front.pitch, |
| 624 | screen->cpp, |
| 625 | screen->front.map); |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 626 | intel_set_span_functions(&intel_fb->color_rb[0]->Base); |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 627 | _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT, |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 628 | &intel_fb->color_rb[0]->Base); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | if (mesaVis->doubleBufferMode) { |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 632 | intel_fb->color_rb[1] |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 633 | = intel_create_renderbuffer(rgbFormat, |
| 634 | screen->width, screen->height, |
| 635 | screen->back.offset, |
| 636 | screen->back.pitch, |
| 637 | screen->cpp, |
| 638 | screen->back.map); |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 639 | intel_set_span_functions(&intel_fb->color_rb[1]->Base); |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 640 | _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT, |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 641 | &intel_fb->color_rb[1]->Base); |
| 642 | |
| 643 | if (screen->third.handle) { |
Michel Dänzer | 76f3b66 | 2007-03-26 17:38:58 +0200 | [diff] [blame] | 644 | struct gl_renderbuffer *tmp_rb = NULL; |
| 645 | |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 646 | intel_fb->color_rb[2] |
| 647 | = intel_create_renderbuffer(rgbFormat, |
| 648 | screen->width, screen->height, |
| 649 | screen->third.offset, |
| 650 | screen->third.pitch, |
| 651 | screen->cpp, |
| 652 | screen->third.map); |
| 653 | intel_set_span_functions(&intel_fb->color_rb[2]->Base); |
Michel Dänzer | 76f3b66 | 2007-03-26 17:38:58 +0200 | [diff] [blame] | 654 | _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base); |
Michel Dänzer | e33a9d6 | 2007-02-20 19:14:23 +0100 | [diff] [blame] | 655 | } |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) { |
| 659 | /* combined depth/stencil buffer */ |
| 660 | struct intel_renderbuffer *depthStencilRb |
| 661 | = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT, |
| 662 | screen->width, screen->height, |
| 663 | screen->depth.offset, |
| 664 | screen->depth.pitch, |
| 665 | screen->cpp, /* 4! */ |
| 666 | screen->depth.map); |
| 667 | intel_set_span_functions(&depthStencilRb->Base); |
| 668 | /* note: bind RB to two attachment points */ |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 669 | _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, |
| 670 | &depthStencilRb->Base); |
| 671 | _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL, |
| 672 | &depthStencilRb->Base); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 673 | } |
| 674 | else if (mesaVis->depthBits == 16) { |
| 675 | /* just 16-bit depth buffer, no hw stencil */ |
| 676 | struct intel_renderbuffer *depthRb |
| 677 | = intel_create_renderbuffer(GL_DEPTH_COMPONENT16, |
| 678 | screen->width, screen->height, |
| 679 | screen->depth.offset, |
| 680 | screen->depth.pitch, |
| 681 | screen->cpp, /* 2! */ |
| 682 | screen->depth.map); |
| 683 | intel_set_span_functions(&depthRb->Base); |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 684 | _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /* now add any/all software-based renderbuffers we may need */ |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 688 | _mesa_add_soft_renderbuffers(&intel_fb->Base, |
| 689 | GL_FALSE, /* never sw color */ |
| 690 | GL_FALSE, /* never sw depth */ |
| 691 | swStencil, mesaVis->accumRedBits > 0, |
| 692 | GL_FALSE, /* never sw alpha */ |
| 693 | GL_FALSE /* never sw aux */ ); |
| 694 | driDrawPriv->driverPrivate = (void *) intel_fb; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 695 | |
Michel Dänzer | 6b99caf | 2007-02-15 16:30:40 +0100 | [diff] [blame] | 696 | return GL_TRUE; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | |
| 700 | static void |
| 701 | intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv) |
| 702 | { |
Brian | a510bc3 | 2007-03-06 10:07:59 -0700 | [diff] [blame] | 703 | _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate))); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | |
| 707 | /** |
| 708 | * Get information about previous buffer swaps. |
| 709 | */ |
| 710 | static int |
| 711 | intelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo) |
| 712 | { |
Michel Dänzer | 641c966 | 2007-02-22 17:24:09 +0100 | [diff] [blame] | 713 | struct intel_framebuffer *intel_fb; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 714 | |
Michel Dänzer | 641c966 | 2007-02-22 17:24:09 +0100 | [diff] [blame] | 715 | if ((dPriv == NULL) || (dPriv->driverPrivate == NULL) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 716 | || (sInfo == NULL)) { |
| 717 | return -1; |
| 718 | } |
| 719 | |
Michel Dänzer | 641c966 | 2007-02-22 17:24:09 +0100 | [diff] [blame] | 720 | intel_fb = dPriv->driverPrivate; |
| 721 | sInfo->swap_count = intel_fb->swap_count; |
| 722 | sInfo->swap_ust = intel_fb->swap_ust; |
| 723 | sInfo->swap_missed_count = intel_fb->swap_missed_count; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 724 | |
| 725 | sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0) |
Michel Dänzer | 641c966 | 2007-02-22 17:24:09 +0100 | [diff] [blame] | 726 | ? driCalculateSwapUsage(dPriv, 0, intel_fb->swap_missed_ust) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 727 | : 0.0; |
| 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | |
| 733 | /* There are probably better ways to do this, such as an |
| 734 | * init-designated function to register chipids and createcontext |
| 735 | * functions. |
| 736 | */ |
| 737 | extern GLboolean i830CreateContext(const __GLcontextModes * mesaVis, |
| 738 | __DRIcontextPrivate * driContextPriv, |
| 739 | void *sharedContextPrivate); |
| 740 | |
| 741 | extern GLboolean i915CreateContext(const __GLcontextModes * mesaVis, |
| 742 | __DRIcontextPrivate * driContextPriv, |
| 743 | void *sharedContextPrivate); |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | static GLboolean |
| 749 | intelCreateContext(const __GLcontextModes * mesaVis, |
| 750 | __DRIcontextPrivate * driContextPriv, |
| 751 | void *sharedContextPrivate) |
| 752 | { |
| 753 | __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; |
| 754 | intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private; |
| 755 | |
| 756 | switch (intelScreen->deviceID) { |
| 757 | /* Don't deal with i830 until texture work complete: |
| 758 | */ |
| 759 | case PCI_CHIP_845_G: |
| 760 | case PCI_CHIP_I830_M: |
| 761 | case PCI_CHIP_I855_GM: |
| 762 | case PCI_CHIP_I865_G: |
| 763 | return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate); |
| 764 | |
| 765 | case PCI_CHIP_I915_G: |
| 766 | case PCI_CHIP_I915_GM: |
| 767 | case PCI_CHIP_I945_G: |
| 768 | case PCI_CHIP_I945_GM: |
Wang Zhenyu | ad6351a | 2007-05-30 16:18:26 +0800 | [diff] [blame] | 769 | case PCI_CHIP_I945_GME: |
Wang Zhenyu | 8331d9d | 2007-06-05 11:42:43 -0700 | [diff] [blame] | 770 | case PCI_CHIP_G33_G: |
| 771 | case PCI_CHIP_Q35_G: |
| 772 | case PCI_CHIP_Q33_G: |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 773 | return i915CreateContext(mesaVis, driContextPriv, sharedContextPrivate); |
| 774 | |
| 775 | default: |
| 776 | fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID); |
| 777 | return GL_FALSE; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | |
| 782 | static const struct __DriverAPIRec intelAPI = { |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 783 | .DestroyScreen = intelDestroyScreen, |
| 784 | .CreateContext = intelCreateContext, |
| 785 | .DestroyContext = intelDestroyContext, |
| 786 | .CreateBuffer = intelCreateBuffer, |
| 787 | .DestroyBuffer = intelDestroyBuffer, |
| 788 | .SwapBuffers = intelSwapBuffers, |
| 789 | .MakeCurrent = intelMakeCurrent, |
| 790 | .UnbindContext = intelUnbindContext, |
| 791 | .GetSwapInfo = intelGetSwapInfo, |
| 792 | .GetMSC = driGetMSC32, |
| 793 | .WaitForMSC = driWaitForMSC32, |
| 794 | .WaitForSBC = NULL, |
| 795 | .SwapBuffersMSC = NULL, |
Michel Dänzer | e0885b8 | 2007-05-22 14:08:11 +0200 | [diff] [blame] | 796 | .CopySubBuffer = intelCopySubBuffer, |
| 797 | .setTexOffset = intelSetTexOffset, |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 798 | }; |
| 799 | |
| 800 | |
| 801 | static __GLcontextModes * |
| 802 | intelFillInModes(unsigned pixel_bits, unsigned depth_bits, |
| 803 | unsigned stencil_bits, GLboolean have_back_buffer) |
| 804 | { |
| 805 | __GLcontextModes *modes; |
| 806 | __GLcontextModes *m; |
| 807 | unsigned num_modes; |
| 808 | unsigned depth_buffer_factor; |
| 809 | unsigned back_buffer_factor; |
| 810 | GLenum fb_format; |
| 811 | GLenum fb_type; |
| 812 | |
| 813 | /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't |
| 814 | * support pageflipping at all. |
| 815 | */ |
| 816 | static const GLenum back_buffer_modes[] = { |
| 817 | GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML |
| 818 | }; |
| 819 | |
| 820 | u_int8_t depth_bits_array[3]; |
| 821 | u_int8_t stencil_bits_array[3]; |
| 822 | |
| 823 | |
| 824 | depth_bits_array[0] = 0; |
| 825 | depth_bits_array[1] = depth_bits; |
| 826 | depth_bits_array[2] = depth_bits; |
| 827 | |
| 828 | /* Just like with the accumulation buffer, always provide some modes |
| 829 | * with a stencil buffer. It will be a sw fallback, but some apps won't |
| 830 | * care about that. |
| 831 | */ |
| 832 | stencil_bits_array[0] = 0; |
| 833 | stencil_bits_array[1] = 0; |
Dave Airlie | b6becfa | 2006-12-31 10:01:17 +1100 | [diff] [blame] | 834 | if (depth_bits == 24) |
| 835 | stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits; |
| 836 | |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 837 | stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits; |
| 838 | |
| 839 | depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1; |
| 840 | back_buffer_factor = (have_back_buffer) ? 3 : 1; |
| 841 | |
| 842 | num_modes = depth_buffer_factor * back_buffer_factor * 4; |
| 843 | |
| 844 | if (pixel_bits == 16) { |
| 845 | fb_format = GL_RGB; |
| 846 | fb_type = GL_UNSIGNED_SHORT_5_6_5; |
| 847 | } |
| 848 | else { |
| 849 | fb_format = GL_BGRA; |
| 850 | fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; |
| 851 | } |
| 852 | |
| 853 | modes = |
| 854 | (*dri_interface->createContextModes) (num_modes, |
| 855 | sizeof(__GLcontextModes)); |
| 856 | m = modes; |
| 857 | if (!driFillInModes(&m, fb_format, fb_type, |
| 858 | depth_bits_array, stencil_bits_array, |
| 859 | depth_buffer_factor, back_buffer_modes, |
| 860 | back_buffer_factor, GLX_TRUE_COLOR)) { |
| 861 | fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, |
| 862 | __LINE__); |
| 863 | return NULL; |
| 864 | } |
| 865 | if (!driFillInModes(&m, fb_format, fb_type, |
| 866 | depth_bits_array, stencil_bits_array, |
| 867 | depth_buffer_factor, back_buffer_modes, |
| 868 | back_buffer_factor, GLX_DIRECT_COLOR)) { |
| 869 | fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, |
| 870 | __LINE__); |
| 871 | return NULL; |
| 872 | } |
| 873 | |
| 874 | /* Mark the visual as slow if there are "fake" stencil bits. |
| 875 | */ |
| 876 | for (m = modes; m != NULL; m = m->next) { |
| 877 | if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { |
| 878 | m->visualRating = GLX_SLOW_CONFIG; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | return modes; |
| 883 | } |
| 884 | |
| 885 | |
| 886 | /** |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 887 | * This is the driver specific part of the createNewScreen entry point. |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 888 | * |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 889 | * \todo maybe fold this into intelInitDriver |
| 890 | * |
| 891 | * \return the __GLcontextModes supported by this driver |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 892 | */ |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 893 | PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 894 | { |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 895 | static const __DRIversion ddx_expected = { 1, 5, 0 }; |
| 896 | static const __DRIversion dri_expected = { 4, 0, 0 }; |
Eric Anholt | 4cf2cc0 | 2007-05-18 11:29:55 -0700 | [diff] [blame] | 897 | static const __DRIversion drm_expected = { 1, 5, 0 }; |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 898 | I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 899 | |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 900 | psp->DriverAPI = intelAPI; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 901 | |
| 902 | if (!driCheckDriDdxDrmVersions2("i915", |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 903 | &psp->dri_version, &dri_expected, |
| 904 | &psp->ddx_version, &ddx_expected, |
| 905 | &psp->drm_version, &drm_expected)) { |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 906 | return NULL; |
| 907 | } |
| 908 | |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 909 | /* Calling driInitExtensions here, with a NULL context pointer, |
| 910 | * does not actually enable the extensions. It just makes sure |
| 911 | * that all the dispatch offsets for all the extensions that |
| 912 | * *might* be enables are known. This is needed because the |
| 913 | * dispatch offsets need to be known when _mesa_context_create is |
| 914 | * called, but we can't enable the extensions until we have a |
| 915 | * context pointer. |
| 916 | * |
| 917 | * Hello chicken. Hello egg. How are you two today? |
| 918 | */ |
| 919 | driInitExtensions(NULL, card_extensions, GL_FALSE); |
Michel Dänzer | 3feefee | 2007-10-16 15:48:46 +0200 | [diff] [blame^] | 920 | driInitExtensions(NULL, ttm_extensions, GL_FALSE); |
Thomas Hellstrom | da56df9 | 2007-04-16 16:04:12 +0200 | [diff] [blame] | 921 | |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 922 | if (!intelInitDriver(psp)) |
| 923 | return NULL; |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 924 | |
Kristian Høgsberg | 64106d0 | 2007-05-14 16:58:37 -0400 | [diff] [blame] | 925 | return intelFillInModes(dri_priv->cpp * 8, |
| 926 | (dri_priv->cpp == 2) ? 16 : 24, |
| 927 | (dri_priv->cpp == 2) ? 0 : 8, 1); |
Keith Whitwell | 6b9e31f | 2006-11-01 12:03:11 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen) |
| 931 | { |
| 932 | /* |
| 933 | * This should probably change to have the screen allocate a dummy |
| 934 | * context at screen creation. For now just use the current context. |
| 935 | */ |
| 936 | |
| 937 | GET_CURRENT_CONTEXT(ctx); |
| 938 | if (ctx == NULL) { |
| 939 | _mesa_problem(NULL, "No current context in intelScreenContext\n"); |
| 940 | return NULL; |
| 941 | } |
| 942 | return intel_context(ctx); |
| 943 | } |
| 944 | |