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