intel_screen.c revision 5dfba09d49ccec2655e4d22ef6f46b9c67862bc9
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 int cpp; 220 221 image = CALLOC(sizeof *image); 222 if (image == NULL) 223 return NULL; 224 225 switch (format) { 226 case __DRI_IMAGE_FORMAT_RGB565: 227 image->format = MESA_FORMAT_RGB565; 228 image->internal_format = GL_RGB; 229 image->data_type = GL_UNSIGNED_BYTE; 230 break; 231 case __DRI_IMAGE_FORMAT_XRGB8888: 232 image->format = MESA_FORMAT_XRGB8888; 233 image->internal_format = GL_RGB; 234 image->data_type = GL_UNSIGNED_BYTE; 235 break; 236 case __DRI_IMAGE_FORMAT_ARGB8888: 237 image->format = MESA_FORMAT_ARGB8888; 238 image->internal_format = GL_RGBA; 239 image->data_type = GL_UNSIGNED_BYTE; 240 break; 241 default: 242 free(image); 243 return NULL; 244 } 245 246 image->data = loaderPrivate; 247 cpp = _mesa_get_format_bytes(image->format); 248 249 image->region = 250 intel_region_alloc(intelScreen, I915_TILING_X, 251 cpp, width, height, GL_TRUE); 252 if (image->region == NULL) { 253 FREE(image); 254 return NULL; 255 } 256 257 return image; 258} 259 260static GLboolean 261intel_query_image(__DRIimage *image, int attrib, int *value) 262{ 263 switch (attrib) { 264 case __DRI_IMAGE_ATTRIB_STRIDE: 265 *value = image->region->pitch * image->region->cpp; 266 return GL_TRUE; 267 case __DRI_IMAGE_ATTRIB_HANDLE: 268 *value = image->region->buffer->handle; 269 return GL_TRUE; 270 case __DRI_IMAGE_ATTRIB_NAME: 271 return intel_region_flink(image->region, (uint32_t *) value); 272 default: 273 return GL_FALSE; 274 } 275} 276 277static struct __DRIimageExtensionRec intelImageExtension = { 278 { __DRI_IMAGE, __DRI_IMAGE_VERSION }, 279 intel_create_image_from_name, 280 intel_create_image_from_renderbuffer, 281 intel_destroy_image, 282 intel_create_image, 283 intel_query_image 284}; 285 286static const __DRIextension *intelScreenExtensions[] = { 287 &driReadDrawableExtension, 288 &intelTexBufferExtension.base, 289 &intelFlushExtension.base, 290 &intelImageExtension.base, 291 &dri2ConfigQueryExtension.base, 292 NULL 293}; 294 295static GLboolean 296intel_get_param(__DRIscreen *psp, int param, int *value) 297{ 298 int ret; 299 struct drm_i915_getparam gp; 300 301 gp.param = param; 302 gp.value = value; 303 304 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); 305 if (ret) { 306 if (ret != -EINVAL) 307 _mesa_warning(NULL, "drm_i915_getparam: %d", ret); 308 return GL_FALSE; 309 } 310 311 return GL_TRUE; 312} 313 314static GLboolean 315intel_get_boolean(__DRIscreen *psp, int param) 316{ 317 int value = 0; 318 return intel_get_param(psp, param, &value) && value; 319} 320 321static void 322nop_callback(GLuint key, void *data, void *userData) 323{ 324} 325 326static void 327intelDestroyScreen(__DRIscreen * sPriv) 328{ 329 struct intel_screen *intelScreen = sPriv->private; 330 331 dri_bufmgr_destroy(intelScreen->bufmgr); 332 driDestroyOptionInfo(&intelScreen->optionCache); 333 334 /* Some regions may still have references to them at this point, so 335 * flush the hash table to prevent _mesa_DeleteHashTable() from 336 * complaining about the hash not being empty; */ 337 _mesa_HashDeleteAll(intelScreen->named_regions, nop_callback, NULL); 338 _mesa_DeleteHashTable(intelScreen->named_regions); 339 340 FREE(intelScreen); 341 sPriv->private = NULL; 342} 343 344 345/** 346 * This is called when we need to set up GL rendering to a new X window. 347 */ 348static GLboolean 349intelCreateBuffer(__DRIscreen * driScrnPriv, 350 __DRIdrawable * driDrawPriv, 351 const struct gl_config * mesaVis, GLboolean isPixmap) 352{ 353 struct intel_renderbuffer *rb; 354 355 if (isPixmap) { 356 return GL_FALSE; /* not implemented */ 357 } 358 else { 359 GLboolean swStencil = (mesaVis->stencilBits > 0 && 360 mesaVis->depthBits != 24); 361 gl_format rgbFormat; 362 363 struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer); 364 365 if (!fb) 366 return GL_FALSE; 367 368 _mesa_initialize_window_framebuffer(fb, mesaVis); 369 370 if (mesaVis->redBits == 5) 371 rgbFormat = MESA_FORMAT_RGB565; 372 else if (mesaVis->alphaBits == 0) 373 rgbFormat = MESA_FORMAT_XRGB8888; 374 else 375 rgbFormat = MESA_FORMAT_ARGB8888; 376 377 /* setup the hardware-based renderbuffers */ 378 rb = intel_create_renderbuffer(rgbFormat); 379 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base); 380 381 if (mesaVis->doubleBufferMode) { 382 rb = intel_create_renderbuffer(rgbFormat); 383 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base); 384 } 385 386 if (mesaVis->depthBits == 24) { 387 assert(mesaVis->stencilBits == 8); 388 /* combined depth/stencil buffer */ 389 struct intel_renderbuffer *depthStencilRb 390 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24); 391 /* note: bind RB to two attachment points */ 392 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthStencilRb->Base); 393 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &depthStencilRb->Base); 394 } 395 else if (mesaVis->depthBits == 16) { 396 /* just 16-bit depth buffer, no hw stencil */ 397 struct intel_renderbuffer *depthRb 398 = intel_create_renderbuffer(MESA_FORMAT_Z16); 399 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base); 400 } 401 402 /* now add any/all software-based renderbuffers we may need */ 403 _mesa_add_soft_renderbuffers(fb, 404 GL_FALSE, /* never sw color */ 405 GL_FALSE, /* never sw depth */ 406 swStencil, mesaVis->accumRedBits > 0, 407 GL_FALSE, /* never sw alpha */ 408 GL_FALSE /* never sw aux */ ); 409 driDrawPriv->driverPrivate = fb; 410 411 return GL_TRUE; 412 } 413} 414 415static void 416intelDestroyBuffer(__DRIdrawable * driDrawPriv) 417{ 418 struct gl_framebuffer *fb = driDrawPriv->driverPrivate; 419 420 _mesa_reference_framebuffer(&fb, NULL); 421} 422 423/* There are probably better ways to do this, such as an 424 * init-designated function to register chipids and createcontext 425 * functions. 426 */ 427extern GLboolean i830CreateContext(const struct gl_config * mesaVis, 428 __DRIcontext * driContextPriv, 429 void *sharedContextPrivate); 430 431extern GLboolean i915CreateContext(int api, 432 const struct gl_config * mesaVis, 433 __DRIcontext * driContextPriv, 434 void *sharedContextPrivate); 435extern GLboolean brwCreateContext(int api, 436 const struct gl_config * mesaVis, 437 __DRIcontext * driContextPriv, 438 void *sharedContextPrivate); 439 440static GLboolean 441intelCreateContext(gl_api api, 442 const struct gl_config * mesaVis, 443 __DRIcontext * driContextPriv, 444 void *sharedContextPrivate) 445{ 446 __DRIscreen *sPriv = driContextPriv->driScreenPriv; 447 struct intel_screen *intelScreen = sPriv->private; 448 449#ifdef I915 450 if (IS_9XX(intelScreen->deviceID)) { 451 if (!IS_965(intelScreen->deviceID)) { 452 return i915CreateContext(api, mesaVis, driContextPriv, 453 sharedContextPrivate); 454 } 455 } else { 456 intelScreen->no_vbo = GL_TRUE; 457 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate); 458 } 459#else 460 if (IS_965(intelScreen->deviceID)) 461 return brwCreateContext(api, mesaVis, 462 driContextPriv, sharedContextPrivate); 463#endif 464 fprintf(stderr, "Unrecognized deviceID 0x%x\n", intelScreen->deviceID); 465 return GL_FALSE; 466} 467 468static GLboolean 469intel_init_bufmgr(struct intel_screen *intelScreen) 470{ 471 __DRIscreen *spriv = intelScreen->driScrnPriv; 472 int num_fences = 0; 473 474 intelScreen->no_hw = (getenv("INTEL_NO_HW") != NULL || 475 getenv("INTEL_DEVID_OVERRIDE") != NULL); 476 477 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ); 478 if (intelScreen->bufmgr == NULL) { 479 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n", 480 __func__, __LINE__); 481 return GL_FALSE; 482 } 483 484 if (!intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences) || 485 num_fences == 0) { 486 fprintf(stderr, "[%s: %u] Kernel 2.6.29 required.\n", __func__, __LINE__); 487 return GL_FALSE; 488 } 489 490 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr); 491 492 intelScreen->named_regions = _mesa_NewHashTable(); 493 494 intelScreen->relaxed_relocations = 0; 495 intelScreen->relaxed_relocations |= 496 intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA) << 0; 497 498 return GL_TRUE; 499} 500 501/** 502 * This is the driver specific part of the createNewScreen entry point. 503 * Called when using DRI2. 504 * 505 * \return the struct gl_config supported by this driver 506 */ 507static const 508__DRIconfig **intelInitScreen2(__DRIscreen *psp) 509{ 510 struct intel_screen *intelScreen; 511 GLenum fb_format[3]; 512 GLenum fb_type[3]; 513 unsigned int api_mask; 514 char *devid_override; 515 516 static const GLenum back_buffer_modes[] = { 517 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML 518 }; 519 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1]; 520 int color; 521 __DRIconfig **configs = NULL; 522 523 /* Allocate the private area */ 524 intelScreen = CALLOC(sizeof *intelScreen); 525 if (!intelScreen) { 526 fprintf(stderr, "\nERROR! Allocating private area failed\n"); 527 return GL_FALSE; 528 } 529 /* parse information in __driConfigOptions */ 530 driParseOptionInfo(&intelScreen->optionCache, 531 __driConfigOptions, __driNConfigOptions); 532 533 intelScreen->driScrnPriv = psp; 534 psp->private = (void *) intelScreen; 535 536 /* Determine chipset ID */ 537 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID, 538 &intelScreen->deviceID)) 539 return GL_FALSE; 540 541 /* Allow an override of the device ID for the purpose of making the 542 * driver produce dumps for debugging of new chipset enablement. 543 * This implies INTEL_NO_HW, to avoid programming your actual GPU 544 * incorrectly. 545 */ 546 devid_override = getenv("INTEL_DEVID_OVERRIDE"); 547 if (devid_override) { 548 intelScreen->deviceID = strtod(devid_override, NULL); 549 } 550 551 if (IS_GEN6(intelScreen->deviceID)) { 552 intelScreen->gen = 6; 553 } else if (IS_GEN5(intelScreen->deviceID)) { 554 intelScreen->gen = 5; 555 } else if (IS_965(intelScreen->deviceID)) { 556 intelScreen->gen = 4; 557 } else if (IS_9XX(intelScreen->deviceID)) { 558 intelScreen->gen = 3; 559 } else { 560 intelScreen->gen = 2; 561 } 562 563 api_mask = (1 << __DRI_API_OPENGL); 564#if FEATURE_ES1 565 api_mask |= (1 << __DRI_API_GLES); 566#endif 567#if FEATURE_ES2 568 api_mask |= (1 << __DRI_API_GLES2); 569#endif 570 571 if (IS_9XX(intelScreen->deviceID) || IS_965(intelScreen->deviceID)) 572 psp->api_mask = api_mask; 573 574 if (!intel_init_bufmgr(intelScreen)) 575 return GL_FALSE; 576 577 psp->extensions = intelScreenExtensions; 578 579 msaa_samples_array[0] = 0; 580 581 fb_format[0] = GL_RGB; 582 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5; 583 584 fb_format[1] = GL_BGR; 585 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV; 586 587 fb_format[2] = GL_BGRA; 588 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV; 589 590 depth_bits[0] = 0; 591 stencil_bits[0] = 0; 592 593 /* Generate a rich set of useful configs that do not include an 594 * accumulation buffer. 595 */ 596 for (color = 0; color < ARRAY_SIZE(fb_format); color++) { 597 __DRIconfig **new_configs; 598 int depth_factor; 599 600 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil 601 * buffer that has a diffferent number of bits per pixel than the color 602 * buffer. This isn't yet supported here. 603 */ 604 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) { 605 depth_bits[1] = 16; 606 stencil_bits[1] = 0; 607 } else { 608 depth_bits[1] = 24; 609 stencil_bits[1] = 8; 610 } 611 612 depth_factor = 2; 613 614 new_configs = driCreateConfigs(fb_format[color], fb_type[color], 615 depth_bits, 616 stencil_bits, 617 depth_factor, 618 back_buffer_modes, 619 ARRAY_SIZE(back_buffer_modes), 620 msaa_samples_array, 621 ARRAY_SIZE(msaa_samples_array), 622 GL_FALSE); 623 if (configs == NULL) 624 configs = new_configs; 625 else 626 configs = driConcatConfigs(configs, new_configs); 627 } 628 629 /* Generate the minimum possible set of configs that include an 630 * accumulation buffer. 631 */ 632 for (color = 0; color < ARRAY_SIZE(fb_format); color++) { 633 __DRIconfig **new_configs; 634 635 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) { 636 depth_bits[0] = 16; 637 stencil_bits[0] = 0; 638 } else { 639 depth_bits[0] = 24; 640 stencil_bits[0] = 8; 641 } 642 643 new_configs = driCreateConfigs(fb_format[color], fb_type[color], 644 depth_bits, stencil_bits, 1, 645 back_buffer_modes + 1, 1, 646 msaa_samples_array, 1, 647 GL_TRUE); 648 if (configs == NULL) 649 configs = new_configs; 650 else 651 configs = driConcatConfigs(configs, new_configs); 652 } 653 654 if (configs == NULL) { 655 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, 656 __LINE__); 657 return NULL; 658 } 659 660 return (const __DRIconfig **)configs; 661} 662 663struct intel_buffer { 664 __DRIbuffer base; 665 struct intel_region *region; 666}; 667 668static __DRIbuffer * 669intelAllocateBuffer(__DRIscreen *screen, 670 unsigned attachment, unsigned format, 671 int width, int height) 672{ 673 struct intel_buffer *intelBuffer; 674 struct intel_screen *intelScreen = screen->private; 675 uint32_t tiling; 676 677 intelBuffer = CALLOC(sizeof *intelBuffer); 678 if (intelBuffer == NULL) 679 return NULL; 680 681 if ((attachment == __DRI_BUFFER_DEPTH || 682 attachment == __DRI_BUFFER_STENCIL || 683 attachment == __DRI_BUFFER_DEPTH_STENCIL) && 684 intelScreen->gen >= 4) 685 tiling = I915_TILING_Y; 686 else 687 tiling = I915_TILING_X; 688 689 intelBuffer->region = intel_region_alloc(intelScreen, tiling, 690 format / 8, width, height, GL_TRUE); 691 692 if (intelBuffer->region == NULL) { 693 FREE(intelBuffer); 694 return NULL; 695 } 696 697 intel_region_flink(intelBuffer->region, &intelBuffer->base.name); 698 699 intelBuffer->base.attachment = attachment; 700 intelBuffer->base.cpp = intelBuffer->region->cpp; 701 intelBuffer->base.pitch = 702 intelBuffer->region->pitch * intelBuffer->region->cpp; 703 704 return &intelBuffer->base; 705} 706 707static void 708intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer) 709{ 710 struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer; 711 712 intel_region_release(&intelBuffer->region); 713 free(intelBuffer); 714} 715 716 717const struct __DriverAPIRec driDriverAPI = { 718 .DestroyScreen = intelDestroyScreen, 719 .CreateContext = intelCreateContext, 720 .DestroyContext = intelDestroyContext, 721 .CreateBuffer = intelCreateBuffer, 722 .DestroyBuffer = intelDestroyBuffer, 723 .MakeCurrent = intelMakeCurrent, 724 .UnbindContext = intelUnbindContext, 725 .InitScreen2 = intelInitScreen2, 726 .AllocateBuffer = intelAllocateBuffer, 727 .ReleaseBuffer = intelReleaseBuffer 728}; 729 730/* This is the table of extensions that the loader will dlsym() for. */ 731PUBLIC const __DRIextension *__driDriverExtensions[] = { 732 &driCoreExtension.base, 733 &driDRI2Extension.base, 734 NULL 735}; 736