intel_screen.c revision 89a82d72cafc1efbcf099e5229ba9b1cb53504f0
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 <errno.h> 29#include "main/glheader.h" 30#include "main/context.h" 31#include "main/framebuffer.h" 32#include "main/renderbuffer.h" 33#include "main/hash.h" 34#include "main/fbobject.h" 35#include "main/mfeatures.h" 36 37#include "utils.h" 38#include "xmlpool.h" 39 40PUBLIC const char __driConfigOptions[] = 41 DRI_CONF_BEGIN 42 DRI_CONF_SECTION_PERFORMANCE 43 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC) 44 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED, 45 * DRI_CONF_BO_REUSE_ALL 46 */ 47 DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1") 48 DRI_CONF_DESC_BEGIN(en, "Buffer object reuse") 49 DRI_CONF_ENUM(0, "Disable buffer object reuse") 50 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects") 51 DRI_CONF_DESC_END 52 DRI_CONF_OPT_END 53 54 DRI_CONF_OPT_BEGIN(texture_tiling, bool, true) 55 DRI_CONF_DESC(en, "Enable texture tiling") 56 DRI_CONF_OPT_END 57 58 DRI_CONF_OPT_BEGIN(early_z, bool, false) 59 DRI_CONF_DESC(en, "Enable early Z in classic mode (unstable, 945-only).") 60 DRI_CONF_OPT_END 61 62 DRI_CONF_OPT_BEGIN(fragment_shader, bool, true) 63 DRI_CONF_DESC(en, "Enable limited ARB_fragment_shader support on 915/945.") 64 DRI_CONF_OPT_END 65 66 DRI_CONF_SECTION_END 67 DRI_CONF_SECTION_QUALITY 68 DRI_CONF_FORCE_S3TC_ENABLE(false) 69 DRI_CONF_ALLOW_LARGE_TEXTURES(2) 70 DRI_CONF_SECTION_END 71 DRI_CONF_SECTION_DEBUG 72 DRI_CONF_NO_RAST(false) 73 DRI_CONF_ALWAYS_FLUSH_BATCH(false) 74 DRI_CONF_ALWAYS_FLUSH_CACHE(false) 75 76 DRI_CONF_OPT_BEGIN(stub_occlusion_query, bool, false) 77 DRI_CONF_DESC(en, "Enable stub ARB_occlusion_query support on 915/945.") 78 DRI_CONF_OPT_END 79 DRI_CONF_SECTION_END 80DRI_CONF_END; 81 82const GLuint __driNConfigOptions = 11; 83 84#include "intel_batchbuffer.h" 85#include "intel_buffers.h" 86#include "intel_bufmgr.h" 87#include "intel_chipset.h" 88#include "intel_fbo.h" 89#include "intel_screen.h" 90#include "intel_tex.h" 91#include "intel_regions.h" 92 93#include "i915_drm.h" 94 95#ifdef USE_NEW_INTERFACE 96static PFNGLXCREATECONTEXTMODES create_context_modes = NULL; 97#endif /*USE_NEW_INTERFACE */ 98 99static const __DRItexBufferExtension intelTexBufferExtension = { 100 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, 101 intelSetTexBuffer, 102 intelSetTexBuffer2, 103}; 104 105static void 106intelDRI2Flush(__DRIdrawable *drawable) 107{ 108 GET_CURRENT_CONTEXT(ctx); 109 struct intel_context *intel = intel_context(ctx); 110 111 if (intel->gen < 4) 112 INTEL_FIREVERTICES(intel); 113 114 intel->need_throttle = GL_TRUE; 115 116 if (intel->batch.used) 117 intel_batchbuffer_flush(intel); 118} 119 120static const struct __DRI2flushExtensionRec intelFlushExtension = { 121 { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, 122 intelDRI2Flush, 123 dri2InvalidateDrawable, 124}; 125 126static __DRIimage * 127intel_create_image_from_name(__DRIscreen *screen, 128 int width, int height, int format, 129 int name, int pitch, void *loaderPrivate) 130{ 131 struct intel_screen *intelScreen = screen->private; 132 __DRIimage *image; 133 int cpp; 134 135 image = CALLOC(sizeof *image); 136 if (image == NULL) 137 return NULL; 138 139 switch (format) { 140 case __DRI_IMAGE_FORMAT_RGB565: 141 image->format = MESA_FORMAT_RGB565; 142 image->internal_format = GL_RGB; 143 image->data_type = GL_UNSIGNED_BYTE; 144 break; 145 case __DRI_IMAGE_FORMAT_XRGB8888: 146 image->format = MESA_FORMAT_XRGB8888; 147 image->internal_format = GL_RGB; 148 image->data_type = GL_UNSIGNED_BYTE; 149 break; 150 case __DRI_IMAGE_FORMAT_ARGB8888: 151 image->format = MESA_FORMAT_ARGB8888; 152 image->internal_format = GL_RGBA; 153 image->data_type = GL_UNSIGNED_BYTE; 154 break; 155 default: 156 free(image); 157 return NULL; 158 } 159 160 image->data = loaderPrivate; 161 cpp = _mesa_get_format_bytes(image->format); 162 163 image->region = intel_region_alloc_for_handle(intelScreen, 164 cpp, width, height, 165 pitch, name, "image"); 166 if (image->region == NULL) { 167 FREE(image); 168 return NULL; 169 } 170 171 return image; 172} 173 174static __DRIimage * 175intel_create_image_from_renderbuffer(__DRIcontext *context, 176 int renderbuffer, void *loaderPrivate) 177{ 178 __DRIimage *image; 179 struct intel_context *intel = context->driverPrivate; 180 struct gl_renderbuffer *rb; 181 struct intel_renderbuffer *irb; 182 183 rb = _mesa_lookup_renderbuffer(&intel->ctx, renderbuffer); 184 if (!rb) { 185 _mesa_error(&intel->ctx, 186 GL_INVALID_OPERATION, "glRenderbufferExternalMESA"); 187 return NULL; 188 } 189 190 irb = intel_renderbuffer(rb); 191 image = CALLOC(sizeof *image); 192 if (image == NULL) 193 return NULL; 194 195 image->internal_format = rb->InternalFormat; 196 image->format = rb->Format; 197 image->data_type = rb->DataType; 198 image->data = loaderPrivate; 199 intel_region_reference(&image->region, irb->region); 200 201 return image; 202} 203 204static void 205intel_destroy_image(__DRIimage *image) 206{ 207 intel_region_release(&image->region); 208 FREE(image); 209} 210 211static __DRIimage * 212intel_create_image(__DRIscreen *screen, 213 int width, int height, int format, 214 unsigned int use, 215 void *loaderPrivate) 216{ 217 __DRIimage *image; 218 struct intel_screen *intelScreen = screen->private; 219 uint32_t tiling; 220 int cpp; 221 222 tiling = I915_TILING_X; 223 if (use & __DRI_IMAGE_USE_CURSOR) { 224 if (width != 64 || height != 64) 225 return NULL; 226 tiling = I915_TILING_NONE; 227 } 228 229 image = CALLOC(sizeof *image); 230 if (image == NULL) 231 return NULL; 232 233 switch (format) { 234 case __DRI_IMAGE_FORMAT_RGB565: 235 image->format = MESA_FORMAT_RGB565; 236 image->internal_format = GL_RGB; 237 image->data_type = GL_UNSIGNED_BYTE; 238 break; 239 case __DRI_IMAGE_FORMAT_XRGB8888: 240 image->format = MESA_FORMAT_XRGB8888; 241 image->internal_format = GL_RGB; 242 image->data_type = GL_UNSIGNED_BYTE; 243 break; 244 case __DRI_IMAGE_FORMAT_ARGB8888: 245 image->format = MESA_FORMAT_ARGB8888; 246 image->internal_format = GL_RGBA; 247 image->data_type = GL_UNSIGNED_BYTE; 248 break; 249 default: 250 free(image); 251 return NULL; 252 } 253 254 image->data = loaderPrivate; 255 cpp = _mesa_get_format_bytes(image->format); 256 257 image->region = 258 intel_region_alloc(intelScreen, tiling, 259 cpp, width, height, GL_TRUE); 260 if (image->region == NULL) { 261 FREE(image); 262 return NULL; 263 } 264 265 return image; 266} 267 268static GLboolean 269intel_query_image(__DRIimage *image, int attrib, int *value) 270{ 271 switch (attrib) { 272 case __DRI_IMAGE_ATTRIB_STRIDE: 273 *value = image->region->pitch * image->region->cpp; 274 return GL_TRUE; 275 case __DRI_IMAGE_ATTRIB_HANDLE: 276 *value = image->region->buffer->handle; 277 return GL_TRUE; 278 case __DRI_IMAGE_ATTRIB_NAME: 279 return intel_region_flink(image->region, (uint32_t *) value); 280 default: 281 return GL_FALSE; 282 } 283} 284 285static struct __DRIimageExtensionRec intelImageExtension = { 286 { __DRI_IMAGE, __DRI_IMAGE_VERSION }, 287 intel_create_image_from_name, 288 intel_create_image_from_renderbuffer, 289 intel_destroy_image, 290 intel_create_image, 291 intel_query_image 292}; 293 294static const __DRIextension *intelScreenExtensions[] = { 295 &driReadDrawableExtension, 296 &intelTexBufferExtension.base, 297 &intelFlushExtension.base, 298 &intelImageExtension.base, 299 &dri2ConfigQueryExtension.base, 300 NULL 301}; 302 303static GLboolean 304intel_get_param(__DRIscreen *psp, int param, int *value) 305{ 306 int ret; 307 struct drm_i915_getparam gp; 308 309 gp.param = param; 310 gp.value = value; 311 312 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); 313 if (ret) { 314 if (ret != -EINVAL) 315 _mesa_warning(NULL, "drm_i915_getparam: %d", ret); 316 return GL_FALSE; 317 } 318 319 return GL_TRUE; 320} 321 322static GLboolean 323intel_get_boolean(__DRIscreen *psp, int param) 324{ 325 int value = 0; 326 return intel_get_param(psp, param, &value) && value; 327} 328 329static void 330nop_callback(GLuint key, void *data, void *userData) 331{ 332} 333 334static void 335intelDestroyScreen(__DRIscreen * sPriv) 336{ 337 struct intel_screen *intelScreen = sPriv->private; 338 339 dri_bufmgr_destroy(intelScreen->bufmgr); 340 driDestroyOptionInfo(&intelScreen->optionCache); 341 342 /* Some regions may still have references to them at this point, so 343 * flush the hash table to prevent _mesa_DeleteHashTable() from 344 * complaining about the hash not being empty; */ 345 _mesa_HashDeleteAll(intelScreen->named_regions, nop_callback, NULL); 346 _mesa_DeleteHashTable(intelScreen->named_regions); 347 348 FREE(intelScreen); 349 sPriv->private = NULL; 350} 351 352 353/** 354 * This is called when we need to set up GL rendering to a new X window. 355 */ 356static GLboolean 357intelCreateBuffer(__DRIscreen * driScrnPriv, 358 __DRIdrawable * driDrawPriv, 359 const struct gl_config * mesaVis, GLboolean isPixmap) 360{ 361 struct intel_renderbuffer *rb; 362 363 if (isPixmap) { 364 return GL_FALSE; /* not implemented */ 365 } 366 else { 367 GLboolean swStencil = (mesaVis->stencilBits > 0 && 368 mesaVis->depthBits != 24); 369 gl_format rgbFormat; 370 371 struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer); 372 373 if (!fb) 374 return GL_FALSE; 375 376 _mesa_initialize_window_framebuffer(fb, mesaVis); 377 378 if (mesaVis->redBits == 5) 379 rgbFormat = MESA_FORMAT_RGB565; 380 else if (mesaVis->alphaBits == 0) 381 rgbFormat = MESA_FORMAT_XRGB8888; 382 else 383 rgbFormat = MESA_FORMAT_ARGB8888; 384 385 /* setup the hardware-based renderbuffers */ 386 rb = intel_create_renderbuffer(rgbFormat); 387 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base); 388 389 if (mesaVis->doubleBufferMode) { 390 rb = intel_create_renderbuffer(rgbFormat); 391 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base); 392 } 393 394 if (mesaVis->depthBits == 24) { 395 assert(mesaVis->stencilBits == 8); 396 /* combined depth/stencil buffer */ 397 struct intel_renderbuffer *depthStencilRb 398 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24); 399 /* note: bind RB to two attachment points */ 400 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthStencilRb->Base); 401 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &depthStencilRb->Base); 402 } 403 else if (mesaVis->depthBits == 16) { 404 /* just 16-bit depth buffer, no hw stencil */ 405 struct intel_renderbuffer *depthRb 406 = intel_create_renderbuffer(MESA_FORMAT_Z16); 407 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base); 408 } 409 410 /* now add any/all software-based renderbuffers we may need */ 411 _mesa_add_soft_renderbuffers(fb, 412 GL_FALSE, /* never sw color */ 413 GL_FALSE, /* never sw depth */ 414 swStencil, mesaVis->accumRedBits > 0, 415 GL_FALSE, /* never sw alpha */ 416 GL_FALSE /* never sw aux */ ); 417 driDrawPriv->driverPrivate = fb; 418 419 return GL_TRUE; 420 } 421} 422 423static void 424intelDestroyBuffer(__DRIdrawable * driDrawPriv) 425{ 426 struct gl_framebuffer *fb = driDrawPriv->driverPrivate; 427 428 _mesa_reference_framebuffer(&fb, NULL); 429} 430 431/* There are probably better ways to do this, such as an 432 * init-designated function to register chipids and createcontext 433 * functions. 434 */ 435extern GLboolean i830CreateContext(const struct gl_config * mesaVis, 436 __DRIcontext * driContextPriv, 437 void *sharedContextPrivate); 438 439extern GLboolean i915CreateContext(int api, 440 const struct gl_config * mesaVis, 441 __DRIcontext * driContextPriv, 442 void *sharedContextPrivate); 443extern GLboolean brwCreateContext(int api, 444 const struct gl_config * mesaVis, 445 __DRIcontext * driContextPriv, 446 void *sharedContextPrivate); 447 448static GLboolean 449intelCreateContext(gl_api api, 450 const struct gl_config * mesaVis, 451 __DRIcontext * driContextPriv, 452 void *sharedContextPrivate) 453{ 454 __DRIscreen *sPriv = driContextPriv->driScreenPriv; 455 struct intel_screen *intelScreen = sPriv->private; 456 457#ifdef I915 458 if (IS_9XX(intelScreen->deviceID)) { 459 if (!IS_965(intelScreen->deviceID)) { 460 return i915CreateContext(api, mesaVis, driContextPriv, 461 sharedContextPrivate); 462 } 463 } else { 464 intelScreen->no_vbo = GL_TRUE; 465 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate); 466 } 467#else 468 if (IS_965(intelScreen->deviceID)) 469 return brwCreateContext(api, mesaVis, 470 driContextPriv, sharedContextPrivate); 471#endif 472 fprintf(stderr, "Unrecognized deviceID 0x%x\n", intelScreen->deviceID); 473 return GL_FALSE; 474} 475 476static GLboolean 477intel_init_bufmgr(struct intel_screen *intelScreen) 478{ 479 __DRIscreen *spriv = intelScreen->driScrnPriv; 480 int num_fences = 0; 481 482 intelScreen->no_hw = (getenv("INTEL_NO_HW") != NULL || 483 getenv("INTEL_DEVID_OVERRIDE") != NULL); 484 485 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ); 486 if (intelScreen->bufmgr == NULL) { 487 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n", 488 __func__, __LINE__); 489 return GL_FALSE; 490 } 491 492 if (!intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences) || 493 num_fences == 0) { 494 fprintf(stderr, "[%s: %u] Kernel 2.6.29 required.\n", __func__, __LINE__); 495 return GL_FALSE; 496 } 497 498 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr); 499 500 intelScreen->named_regions = _mesa_NewHashTable(); 501 502 intelScreen->relaxed_relocations = 0; 503 intelScreen->relaxed_relocations |= 504 intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA) << 0; 505 506 return GL_TRUE; 507} 508 509/** 510 * This is the driver specific part of the createNewScreen entry point. 511 * Called when using DRI2. 512 * 513 * \return the struct gl_config supported by this driver 514 */ 515static const 516__DRIconfig **intelInitScreen2(__DRIscreen *psp) 517{ 518 struct intel_screen *intelScreen; 519 GLenum fb_format[3]; 520 GLenum fb_type[3]; 521 unsigned int api_mask; 522 char *devid_override; 523 524 static const GLenum back_buffer_modes[] = { 525 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML 526 }; 527 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1]; 528 int color; 529 __DRIconfig **configs = NULL; 530 531 /* Allocate the private area */ 532 intelScreen = CALLOC(sizeof *intelScreen); 533 if (!intelScreen) { 534 fprintf(stderr, "\nERROR! Allocating private area failed\n"); 535 return GL_FALSE; 536 } 537 /* parse information in __driConfigOptions */ 538 driParseOptionInfo(&intelScreen->optionCache, 539 __driConfigOptions, __driNConfigOptions); 540 541 intelScreen->driScrnPriv = psp; 542 psp->private = (void *) intelScreen; 543 544 /* Determine chipset ID */ 545 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID, 546 &intelScreen->deviceID)) 547 return GL_FALSE; 548 549 /* Allow an override of the device ID for the purpose of making the 550 * driver produce dumps for debugging of new chipset enablement. 551 * This implies INTEL_NO_HW, to avoid programming your actual GPU 552 * incorrectly. 553 */ 554 devid_override = getenv("INTEL_DEVID_OVERRIDE"); 555 if (devid_override) { 556 intelScreen->deviceID = strtod(devid_override, NULL); 557 } 558 559 if (IS_GEN7(intelScreen->deviceID)) { 560 intelScreen->gen = 7; 561 } else if (IS_GEN6(intelScreen->deviceID)) { 562 intelScreen->gen = 6; 563 } else if (IS_GEN5(intelScreen->deviceID)) { 564 intelScreen->gen = 5; 565 } else if (IS_965(intelScreen->deviceID)) { 566 intelScreen->gen = 4; 567 } else if (IS_9XX(intelScreen->deviceID)) { 568 intelScreen->gen = 3; 569 } else { 570 intelScreen->gen = 2; 571 } 572 573 api_mask = (1 << __DRI_API_OPENGL); 574#if FEATURE_ES1 575 api_mask |= (1 << __DRI_API_GLES); 576#endif 577#if FEATURE_ES2 578 api_mask |= (1 << __DRI_API_GLES2); 579#endif 580 581 if (IS_9XX(intelScreen->deviceID) || IS_965(intelScreen->deviceID)) 582 psp->api_mask = api_mask; 583 584 if (!intel_init_bufmgr(intelScreen)) 585 return GL_FALSE; 586 587 psp->extensions = intelScreenExtensions; 588 589 msaa_samples_array[0] = 0; 590 591 fb_format[0] = GL_RGB; 592 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5; 593 594 fb_format[1] = GL_BGR; 595 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV; 596 597 fb_format[2] = GL_BGRA; 598 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV; 599 600 depth_bits[0] = 0; 601 stencil_bits[0] = 0; 602 603 /* Generate a rich set of useful configs that do not include an 604 * accumulation buffer. 605 */ 606 for (color = 0; color < ARRAY_SIZE(fb_format); color++) { 607 __DRIconfig **new_configs; 608 int depth_factor; 609 610 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil 611 * buffer that has a diffferent number of bits per pixel than the color 612 * buffer. This isn't yet supported here. 613 */ 614 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) { 615 depth_bits[1] = 16; 616 stencil_bits[1] = 0; 617 } else { 618 depth_bits[1] = 24; 619 stencil_bits[1] = 8; 620 } 621 622 depth_factor = 2; 623 624 new_configs = driCreateConfigs(fb_format[color], fb_type[color], 625 depth_bits, 626 stencil_bits, 627 depth_factor, 628 back_buffer_modes, 629 ARRAY_SIZE(back_buffer_modes), 630 msaa_samples_array, 631 ARRAY_SIZE(msaa_samples_array), 632 GL_FALSE); 633 if (configs == NULL) 634 configs = new_configs; 635 else 636 configs = driConcatConfigs(configs, new_configs); 637 } 638 639 /* Generate the minimum possible set of configs that include an 640 * accumulation buffer. 641 */ 642 for (color = 0; color < ARRAY_SIZE(fb_format); color++) { 643 __DRIconfig **new_configs; 644 645 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) { 646 depth_bits[0] = 16; 647 stencil_bits[0] = 0; 648 } else { 649 depth_bits[0] = 24; 650 stencil_bits[0] = 8; 651 } 652 653 new_configs = driCreateConfigs(fb_format[color], fb_type[color], 654 depth_bits, stencil_bits, 1, 655 back_buffer_modes + 1, 1, 656 msaa_samples_array, 1, 657 GL_TRUE); 658 if (configs == NULL) 659 configs = new_configs; 660 else 661 configs = driConcatConfigs(configs, new_configs); 662 } 663 664 if (configs == NULL) { 665 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, 666 __LINE__); 667 return NULL; 668 } 669 670 return (const __DRIconfig **)configs; 671} 672 673struct intel_buffer { 674 __DRIbuffer base; 675 struct intel_region *region; 676}; 677 678static __DRIbuffer * 679intelAllocateBuffer(__DRIscreen *screen, 680 unsigned attachment, unsigned format, 681 int width, int height) 682{ 683 struct intel_buffer *intelBuffer; 684 struct intel_screen *intelScreen = screen->private; 685 uint32_t tiling; 686 687 intelBuffer = CALLOC(sizeof *intelBuffer); 688 if (intelBuffer == NULL) 689 return NULL; 690 691 if ((attachment == __DRI_BUFFER_DEPTH || 692 attachment == __DRI_BUFFER_STENCIL || 693 attachment == __DRI_BUFFER_DEPTH_STENCIL) && 694 intelScreen->gen >= 4) 695 tiling = I915_TILING_Y; 696 else 697 tiling = I915_TILING_X; 698 699 intelBuffer->region = intel_region_alloc(intelScreen, tiling, 700 format / 8, width, height, GL_TRUE); 701 702 if (intelBuffer->region == NULL) { 703 FREE(intelBuffer); 704 return NULL; 705 } 706 707 intel_region_flink(intelBuffer->region, &intelBuffer->base.name); 708 709 intelBuffer->base.attachment = attachment; 710 intelBuffer->base.cpp = intelBuffer->region->cpp; 711 intelBuffer->base.pitch = 712 intelBuffer->region->pitch * intelBuffer->region->cpp; 713 714 return &intelBuffer->base; 715} 716 717static void 718intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer) 719{ 720 struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer; 721 722 intel_region_release(&intelBuffer->region); 723 free(intelBuffer); 724} 725 726 727const struct __DriverAPIRec driDriverAPI = { 728 .DestroyScreen = intelDestroyScreen, 729 .CreateContext = intelCreateContext, 730 .DestroyContext = intelDestroyContext, 731 .CreateBuffer = intelCreateBuffer, 732 .DestroyBuffer = intelDestroyBuffer, 733 .MakeCurrent = intelMakeCurrent, 734 .UnbindContext = intelUnbindContext, 735 .InitScreen2 = intelInitScreen2, 736 .AllocateBuffer = intelAllocateBuffer, 737 .ReleaseBuffer = intelReleaseBuffer 738}; 739 740/* This is the table of extensions that the loader will dlsym() for. */ 741PUBLIC const __DRIextension *__driDriverExtensions[] = { 742 &driCoreExtension.base, 743 &driDRI2Extension.base, 744 NULL 745}; 746