1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "main/glheader.h"
29 #include "main/context.h"
30 #include "main/framebuffer.h"
31 #include "main/renderbuffer.h"
32 #include "main/hash.h"
33 #include "main/fbobject.h"
34 #include "main/mfeatures.h"
39 PUBLIC
const char __driConfigOptions
[] =
41 DRI_CONF_SECTION_PERFORMANCE
42 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
43 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
44 * DRI_CONF_BO_REUSE_ALL
46 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
47 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
48 DRI_CONF_ENUM(0, "Disable buffer object reuse")
49 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
53 DRI_CONF_OPT_BEGIN(texture_tiling
, bool, true)
54 DRI_CONF_DESC(en
, "Enable texture tiling")
57 DRI_CONF_OPT_BEGIN(early_z
, bool, false)
58 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
61 DRI_CONF_OPT_BEGIN(fragment_shader
, bool, true)
62 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
66 DRI_CONF_SECTION_QUALITY
67 DRI_CONF_FORCE_S3TC_ENABLE(false)
68 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
70 DRI_CONF_SECTION_DEBUG
71 DRI_CONF_NO_RAST(false)
72 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
73 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
75 DRI_CONF_OPT_BEGIN(stub_occlusion_query
, bool, false)
76 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
81 const GLuint __driNConfigOptions
= 11;
83 #include "intel_batchbuffer.h"
84 #include "intel_buffers.h"
85 #include "intel_bufmgr.h"
86 #include "intel_chipset.h"
87 #include "intel_fbo.h"
88 #include "intel_screen.h"
89 #include "intel_tex.h"
90 #include "intel_regions.h"
94 #ifdef USE_NEW_INTERFACE
95 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
96 #endif /*USE_NEW_INTERFACE */
98 static const __DRItexBufferExtension intelTexBufferExtension
= {
99 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
105 intelDRI2Flush(__DRIdrawable
*drawable
)
107 struct intel_context
*intel
= drawable
->driContextPriv
->driverPrivate
;
110 INTEL_FIREVERTICES(intel
);
112 intel
->need_throttle
= GL_TRUE
;
114 if (intel
->batch
->map
!= intel
->batch
->ptr
)
115 intel_batchbuffer_flush(intel
->batch
);
118 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
119 { __DRI2_FLUSH
, __DRI2_FLUSH_VERSION
},
121 dri2InvalidateDrawable
,
125 intel_create_image_from_name(__DRIscreen
*screen
,
126 int width
, int height
, int format
,
127 int name
, int pitch
, void *loaderPrivate
)
129 struct intel_screen
*intelScreen
= screen
->private;
133 image
= CALLOC(sizeof *image
);
138 case __DRI_IMAGE_FORMAT_RGB565
:
139 image
->format
= MESA_FORMAT_RGB565
;
140 image
->internal_format
= GL_RGB
;
141 image
->data_type
= GL_UNSIGNED_BYTE
;
143 case __DRI_IMAGE_FORMAT_XRGB8888
:
144 image
->format
= MESA_FORMAT_XRGB8888
;
145 image
->internal_format
= GL_RGB
;
146 image
->data_type
= GL_UNSIGNED_BYTE
;
148 case __DRI_IMAGE_FORMAT_ARGB8888
:
149 image
->format
= MESA_FORMAT_ARGB8888
;
150 image
->internal_format
= GL_RGBA
;
151 image
->data_type
= GL_UNSIGNED_BYTE
;
158 image
->data
= loaderPrivate
;
159 cpp
= _mesa_get_format_bytes(image
->format
);
161 image
->region
= intel_region_alloc_for_handle(intelScreen
,
163 pitch
, name
, "image");
164 if (image
->region
== NULL
) {
173 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
174 int renderbuffer
, void *loaderPrivate
)
177 struct intel_context
*intel
= context
->driverPrivate
;
178 struct gl_renderbuffer
*rb
;
179 struct intel_renderbuffer
*irb
;
181 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
183 _mesa_error(&intel
->ctx
,
184 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
188 irb
= intel_renderbuffer(rb
);
189 image
= CALLOC(sizeof *image
);
193 image
->internal_format
= rb
->InternalFormat
;
194 image
->format
= rb
->Format
;
195 image
->data_type
= rb
->DataType
;
196 image
->data
= loaderPrivate
;
197 intel_region_reference(&image
->region
, irb
->region
);
203 intel_destroy_image(__DRIimage
*image
)
205 intel_region_release(&image
->region
);
210 intel_create_image(__DRIscreen
*screen
,
211 int width
, int height
, int format
,
216 struct intel_screen
*intelScreen
= screen
->private;
219 image
= CALLOC(sizeof *image
);
224 case __DRI_IMAGE_FORMAT_RGB565
:
225 image
->format
= MESA_FORMAT_RGB565
;
226 image
->internal_format
= GL_RGB
;
227 image
->data_type
= GL_UNSIGNED_BYTE
;
229 case __DRI_IMAGE_FORMAT_XRGB8888
:
230 image
->format
= MESA_FORMAT_XRGB8888
;
231 image
->internal_format
= GL_RGB
;
232 image
->data_type
= GL_UNSIGNED_BYTE
;
234 case __DRI_IMAGE_FORMAT_ARGB8888
:
235 image
->format
= MESA_FORMAT_ARGB8888
;
236 image
->internal_format
= GL_RGBA
;
237 image
->data_type
= GL_UNSIGNED_BYTE
;
244 image
->data
= loaderPrivate
;
245 cpp
= _mesa_get_format_bytes(image
->format
);
248 intel_region_alloc(intelScreen
, I915_TILING_NONE
,
249 cpp
, width
, height
, GL_TRUE
);
250 if (image
->region
== NULL
) {
259 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
262 case __DRI_IMAGE_ATTRIB_STRIDE
:
263 *value
= image
->region
->pitch
* image
->region
->cpp
;
265 case __DRI_IMAGE_ATTRIB_HANDLE
:
266 *value
= image
->region
->buffer
->handle
;
268 case __DRI_IMAGE_ATTRIB_NAME
:
269 return intel_region_flink(image
->region
, (uint32_t *) value
);
275 static struct __DRIimageExtensionRec intelImageExtension
= {
276 { __DRI_IMAGE
, __DRI_IMAGE_VERSION
},
277 intel_create_image_from_name
,
278 intel_create_image_from_renderbuffer
,
284 static const __DRIextension
*intelScreenExtensions
[] = {
285 &driReadDrawableExtension
,
286 &intelTexBufferExtension
.base
,
287 &intelFlushExtension
.base
,
288 &intelImageExtension
.base
,
289 &dri2ConfigQueryExtension
.base
,
294 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
297 struct drm_i915_getparam gp
;
302 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
304 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
312 nop_callback(GLuint key
, void *data
, void *userData
)
317 intelDestroyScreen(__DRIscreen
* sPriv
)
319 struct intel_screen
*intelScreen
= sPriv
->private;
321 dri_bufmgr_destroy(intelScreen
->bufmgr
);
322 driDestroyOptionInfo(&intelScreen
->optionCache
);
324 /* Some regions may still have references to them at this point, so
325 * flush the hash table to prevent _mesa_DeleteHashTable() from
326 * complaining about the hash not being empty; */
327 _mesa_HashDeleteAll(intelScreen
->named_regions
, nop_callback
, NULL
);
328 _mesa_DeleteHashTable(intelScreen
->named_regions
);
331 sPriv
->private = NULL
;
336 * This is called when we need to set up GL rendering to a new X window.
339 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
340 __DRIdrawable
* driDrawPriv
,
341 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
343 struct intel_renderbuffer
*rb
;
346 return GL_FALSE
; /* not implemented */
349 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
350 mesaVis
->depthBits
!= 24);
353 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
358 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
360 if (mesaVis
->redBits
== 5)
361 rgbFormat
= MESA_FORMAT_RGB565
;
362 else if (mesaVis
->alphaBits
== 0)
363 rgbFormat
= MESA_FORMAT_XRGB8888
;
365 rgbFormat
= MESA_FORMAT_ARGB8888
;
367 /* setup the hardware-based renderbuffers */
368 rb
= intel_create_renderbuffer(rgbFormat
);
369 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
);
371 if (mesaVis
->doubleBufferMode
) {
372 rb
= intel_create_renderbuffer(rgbFormat
);
373 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
);
376 if (mesaVis
->depthBits
== 24) {
377 assert(mesaVis
->stencilBits
== 8);
378 /* combined depth/stencil buffer */
379 struct intel_renderbuffer
*depthStencilRb
380 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24
);
381 /* note: bind RB to two attachment points */
382 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthStencilRb
->Base
);
383 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &depthStencilRb
->Base
);
385 else if (mesaVis
->depthBits
== 16) {
386 /* just 16-bit depth buffer, no hw stencil */
387 struct intel_renderbuffer
*depthRb
388 = intel_create_renderbuffer(MESA_FORMAT_Z16
);
389 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
392 /* now add any/all software-based renderbuffers we may need */
393 _mesa_add_soft_renderbuffers(fb
,
394 GL_FALSE
, /* never sw color */
395 GL_FALSE
, /* never sw depth */
396 swStencil
, mesaVis
->accumRedBits
> 0,
397 GL_FALSE
, /* never sw alpha */
398 GL_FALSE
/* never sw aux */ );
399 driDrawPriv
->driverPrivate
= fb
;
406 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
408 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
410 _mesa_reference_framebuffer(&fb
, NULL
);
413 /* There are probably better ways to do this, such as an
414 * init-designated function to register chipids and createcontext
417 extern GLboolean
i830CreateContext(const struct gl_config
* mesaVis
,
418 __DRIcontext
* driContextPriv
,
419 void *sharedContextPrivate
);
421 extern GLboolean
i915CreateContext(int api
,
422 const struct gl_config
* mesaVis
,
423 __DRIcontext
* driContextPriv
,
424 void *sharedContextPrivate
);
425 extern GLboolean
brwCreateContext(int api
,
426 const struct gl_config
* mesaVis
,
427 __DRIcontext
* driContextPriv
,
428 void *sharedContextPrivate
);
431 intelCreateContext(gl_api api
,
432 const struct gl_config
* mesaVis
,
433 __DRIcontext
* driContextPriv
,
434 void *sharedContextPrivate
)
436 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
437 struct intel_screen
*intelScreen
= sPriv
->private;
440 if (IS_9XX(intelScreen
->deviceID
)) {
441 if (!IS_965(intelScreen
->deviceID
)) {
442 return i915CreateContext(api
, mesaVis
, driContextPriv
,
443 sharedContextPrivate
);
446 intelScreen
->no_vbo
= GL_TRUE
;
447 return i830CreateContext(mesaVis
, driContextPriv
, sharedContextPrivate
);
450 if (IS_965(intelScreen
->deviceID
))
451 return brwCreateContext(api
, mesaVis
,
452 driContextPriv
, sharedContextPrivate
);
454 fprintf(stderr
, "Unrecognized deviceID 0x%x\n", intelScreen
->deviceID
);
459 intel_init_bufmgr(struct intel_screen
*intelScreen
)
461 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
464 intelScreen
->no_hw
= (getenv("INTEL_NO_HW") != NULL
||
465 getenv("INTEL_DEVID_OVERRIDE") != NULL
);
467 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
468 if (intelScreen
->bufmgr
== NULL
) {
469 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
474 if (!intel_get_param(spriv
, I915_PARAM_NUM_FENCES_AVAIL
, &num_fences
) ||
476 fprintf(stderr
, "[%s: %u] Kernel 2.6.29 required.\n", __func__
, __LINE__
);
480 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
482 intelScreen
->named_regions
= _mesa_NewHashTable();
488 * This is the driver specific part of the createNewScreen entry point.
489 * Called when using DRI2.
491 * \return the struct gl_config supported by this driver
494 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
496 struct intel_screen
*intelScreen
;
499 unsigned int api_mask
;
500 char *devid_override
;
502 static const GLenum back_buffer_modes
[] = {
503 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
505 uint8_t depth_bits
[4], stencil_bits
[4], msaa_samples_array
[1];
507 __DRIconfig
**configs
= NULL
;
509 /* Allocate the private area */
510 intelScreen
= CALLOC(sizeof *intelScreen
);
512 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
515 /* parse information in __driConfigOptions */
516 driParseOptionInfo(&intelScreen
->optionCache
,
517 __driConfigOptions
, __driNConfigOptions
);
519 intelScreen
->driScrnPriv
= psp
;
520 psp
->private = (void *) intelScreen
;
522 /* Determine chipset ID */
523 if (!intel_get_param(psp
, I915_PARAM_CHIPSET_ID
,
524 &intelScreen
->deviceID
))
527 /* Allow an override of the device ID for the purpose of making the
528 * driver produce dumps for debugging of new chipset enablement.
529 * This implies INTEL_NO_HW, to avoid programming your actual GPU
532 devid_override
= getenv("INTEL_DEVID_OVERRIDE");
533 if (devid_override
) {
534 intelScreen
->deviceID
= strtod(devid_override
, NULL
);
537 api_mask
= (1 << __DRI_API_OPENGL
);
539 api_mask
|= (1 << __DRI_API_GLES
);
542 api_mask
|= (1 << __DRI_API_GLES2
);
545 if (IS_9XX(intelScreen
->deviceID
) || IS_965(intelScreen
->deviceID
))
546 psp
->api_mask
= api_mask
;
548 if (!intel_init_bufmgr(intelScreen
))
551 psp
->extensions
= intelScreenExtensions
;
553 msaa_samples_array
[0] = 0;
555 fb_format
[0] = GL_RGB
;
556 fb_type
[0] = GL_UNSIGNED_SHORT_5_6_5
;
558 fb_format
[1] = GL_BGR
;
559 fb_type
[1] = GL_UNSIGNED_INT_8_8_8_8_REV
;
561 fb_format
[2] = GL_BGRA
;
562 fb_type
[2] = GL_UNSIGNED_INT_8_8_8_8_REV
;
567 /* Generate a rich set of useful configs that do not include an
568 * accumulation buffer.
570 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
571 __DRIconfig
**new_configs
;
574 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
575 * buffer that has a diffferent number of bits per pixel than the color
576 * buffer. This isn't yet supported here.
578 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
588 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
593 ARRAY_SIZE(back_buffer_modes
),
595 ARRAY_SIZE(msaa_samples_array
),
598 configs
= new_configs
;
600 configs
= driConcatConfigs(configs
, new_configs
);
603 /* Generate the minimum possible set of configs that include an
604 * accumulation buffer.
606 for (color
= 0; color
< ARRAY_SIZE(fb_format
); color
++) {
607 __DRIconfig
**new_configs
;
609 if (fb_type
[color
] == GL_UNSIGNED_SHORT_5_6_5
) {
617 new_configs
= driCreateConfigs(fb_format
[color
], fb_type
[color
],
618 depth_bits
, stencil_bits
, 1,
619 back_buffer_modes
+ 1, 1,
620 msaa_samples_array
, 1,
623 configs
= new_configs
;
625 configs
= driConcatConfigs(configs
, new_configs
);
628 if (configs
== NULL
) {
629 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
634 return (const __DRIconfig
**)configs
;
637 const struct __DriverAPIRec driDriverAPI
= {
638 .DestroyScreen
= intelDestroyScreen
,
639 .CreateContext
= intelCreateContext
,
640 .DestroyContext
= intelDestroyContext
,
641 .CreateBuffer
= intelCreateBuffer
,
642 .DestroyBuffer
= intelDestroyBuffer
,
643 .MakeCurrent
= intelMakeCurrent
,
644 .UnbindContext
= intelUnbindContext
,
645 .InitScreen2
= intelInitScreen2
,
648 /* This is the table of extensions that the loader will dlsym() for. */
649 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
650 &driCoreExtension
.base
,
651 &driDRI2Extension
.base
,