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 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/extensions.h"
32 #include "main/fbobject.h"
33 #include "main/framebuffer.h"
34 #include "main/imports.h"
35 #include "main/points.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
40 #include "drivers/common/driverfuncs.h"
41 #include "drivers/common/meta.h"
43 #include "intel_chipset.h"
44 #include "intel_buffers.h"
45 #include "intel_tex.h"
46 #include "intel_batchbuffer.h"
47 #include "intel_clear.h"
48 #include "intel_extensions.h"
49 #include "intel_pixel.h"
50 #include "intel_regions.h"
51 #include "intel_buffer_objects.h"
52 #include "intel_fbo.h"
53 #include "intel_bufmgr.h"
54 #include "intel_screen.h"
56 #include "drirenderbuffer.h"
61 int INTEL_DEBUG
= (0);
65 static const GLubyte
*
66 intelGetString(struct gl_context
* ctx
, GLenum name
)
68 const struct intel_context
*const intel
= intel_context(ctx
);
70 static char buffer
[128];
74 return (GLubyte
*) "Tungsten Graphics, Inc";
78 switch (intel
->intelScreen
->deviceID
) {
80 chipset
= "Intel(R) 845G";
83 chipset
= "Intel(R) 830M";
85 case PCI_CHIP_I855_GM
:
86 chipset
= "Intel(R) 852GM/855GM";
89 chipset
= "Intel(R) 865G";
92 chipset
= "Intel(R) 915G";
94 case PCI_CHIP_E7221_G
:
95 chipset
= "Intel (R) E7221G (i915)";
97 case PCI_CHIP_I915_GM
:
98 chipset
= "Intel(R) 915GM";
100 case PCI_CHIP_I945_G
:
101 chipset
= "Intel(R) 945G";
103 case PCI_CHIP_I945_GM
:
104 chipset
= "Intel(R) 945GM";
106 case PCI_CHIP_I945_GME
:
107 chipset
= "Intel(R) 945GME";
110 chipset
= "Intel(R) G33";
113 chipset
= "Intel(R) Q35";
116 chipset
= "Intel(R) Q33";
118 case PCI_CHIP_IGD_GM
:
120 chipset
= "Intel(R) IGD";
122 case PCI_CHIP_I965_Q
:
123 chipset
= "Intel(R) 965Q";
125 case PCI_CHIP_I965_G
:
126 case PCI_CHIP_I965_G_1
:
127 chipset
= "Intel(R) 965G";
129 case PCI_CHIP_I946_GZ
:
130 chipset
= "Intel(R) 946GZ";
132 case PCI_CHIP_I965_GM
:
133 chipset
= "Intel(R) 965GM";
135 case PCI_CHIP_I965_GME
:
136 chipset
= "Intel(R) 965GME/GLE";
138 case PCI_CHIP_GM45_GM
:
139 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
141 case PCI_CHIP_IGD_E_G
:
142 chipset
= "Intel(R) Integrated Graphics Device";
145 chipset
= "Intel(R) G45/G43";
148 chipset
= "Intel(R) Q45/Q43";
151 chipset
= "Intel(R) G41";
154 case PCI_CHIP_B43_G1
:
155 chipset
= "Intel(R) B43";
158 chipset
= "Intel(R) Ironlake Desktop";
161 chipset
= "Intel(R) Ironlake Mobile";
163 case PCI_CHIP_SANDYBRIDGE_GT1
:
164 case PCI_CHIP_SANDYBRIDGE_GT2
:
165 case PCI_CHIP_SANDYBRIDGE_GT2_PLUS
:
166 chipset
= "Intel(R) Sandybridge Desktop";
168 case PCI_CHIP_SANDYBRIDGE_M_GT1
:
169 case PCI_CHIP_SANDYBRIDGE_M_GT2
:
170 case PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS
:
171 chipset
= "Intel(R) Sandybridge Mobile";
173 case PCI_CHIP_SANDYBRIDGE_S
:
174 chipset
= "Intel(R) Sandybridge Server";
176 case PCI_CHIP_IVYBRIDGE_GT1
:
177 case PCI_CHIP_IVYBRIDGE_GT2
:
178 chipset
= "Intel(R) Ivybridge Desktop";
180 case PCI_CHIP_IVYBRIDGE_M_GT1
:
181 case PCI_CHIP_IVYBRIDGE_M_GT2
:
182 chipset
= "Intel(R) Ivybridge Mobile";
184 case PCI_CHIP_IVYBRIDGE_S_GT1
:
185 chipset
= "Intel(R) Ivybridge Server";
188 chipset
= "Unknown Intel Chipset";
192 (void) driGetRendererString(buffer
, chipset
, 0);
193 return (GLubyte
*) buffer
;
201 intel_flush_front(struct gl_context
*ctx
)
203 struct intel_context
*intel
= intel_context(ctx
);
204 __DRIcontext
*driContext
= intel
->driContext
;
205 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
207 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
208 if (screen
->dri2
.loader
&&
209 (screen
->dri2
.loader
->base
.version
>= 2)
210 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
211 driContext
->driDrawablePriv
&&
212 driContext
->driDrawablePriv
->loaderPrivate
) {
213 (*screen
->dri2
.loader
->flushFrontBuffer
)(driContext
->driDrawablePriv
,
214 driContext
->driDrawablePriv
->loaderPrivate
);
216 /* We set the dirty bit in intel_prepare_render() if we're
217 * front buffer rendering once we get there.
219 intel
->front_buffer_dirty
= GL_FALSE
;
225 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
227 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
231 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
233 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
234 struct intel_renderbuffer
*rb
;
235 struct intel_region
*region
, *depth_region
;
236 struct intel_context
*intel
= context
->driverPrivate
;
237 struct intel_renderbuffer
*front_rb
, *back_rb
, *depth_rb
, *stencil_rb
;
238 __DRIbuffer
*buffers
= NULL
;
241 unsigned int attachments
[10];
242 const char *region_name
;
244 /* If we're rendering to the fake front buffer, make sure all the
245 * pending drawing has landed on the real front buffer. Otherwise
246 * when we eventually get to DRI2GetBuffersWithFormat the stale
247 * real front buffer contents will get copied to the new fake front
250 if (intel
->is_front_buffer_rendering
) {
251 intel_flush(&intel
->ctx
);
252 intel_flush_front(&intel
->ctx
);
255 /* Set this up front, so that in case our buffers get invalidated
256 * while we're getting new buffers, we don't clobber the stamp and
257 * thus ignore the invalidate. */
258 drawable
->lastStamp
= drawable
->dri2
.stamp
;
260 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
261 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
263 screen
= intel
->intelScreen
->driScrnPriv
;
265 if (screen
->dri2
.loader
266 && (screen
->dri2
.loader
->base
.version
> 2)
267 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
269 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
270 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
271 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
272 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
275 if ((intel
->is_front_buffer_rendering
||
276 intel
->is_front_buffer_reading
||
277 !back_rb
) && front_rb
) {
278 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
279 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
283 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
284 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
287 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
288 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
289 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
290 } else if (depth_rb
!= NULL
) {
291 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
292 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
293 } else if (stencil_rb
!= NULL
) {
294 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
295 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
299 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
304 drawable
->loaderPrivate
);
305 } else if (screen
->dri2
.loader
) {
307 if (intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
))
308 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
309 if (intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
))
310 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
311 if (intel_get_renderbuffer(fb
, BUFFER_DEPTH
))
312 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
313 if (intel_get_renderbuffer(fb
, BUFFER_STENCIL
))
314 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
316 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
321 drawable
->loaderPrivate
);
331 drawable
->numClipRects
= 1;
332 drawable
->pClipRects
[0].x1
= 0;
333 drawable
->pClipRects
[0].y1
= 0;
334 drawable
->pClipRects
[0].x2
= drawable
->w
;
335 drawable
->pClipRects
[0].y2
= drawable
->h
;
336 drawable
->numBackClipRects
= 1;
337 drawable
->pBackClipRects
[0].x1
= 0;
338 drawable
->pBackClipRects
[0].y1
= 0;
339 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
340 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
343 for (i
= 0; i
< count
; i
++) {
344 switch (buffers
[i
].attachment
) {
345 case __DRI_BUFFER_FRONT_LEFT
:
346 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
347 region_name
= "dri2 front buffer";
350 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
351 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
352 region_name
= "dri2 fake front buffer";
355 case __DRI_BUFFER_BACK_LEFT
:
356 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
357 region_name
= "dri2 back buffer";
360 case __DRI_BUFFER_DEPTH
:
361 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
362 region_name
= "dri2 depth buffer";
365 case __DRI_BUFFER_DEPTH_STENCIL
:
366 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
367 region_name
= "dri2 depth / stencil buffer";
370 case __DRI_BUFFER_STENCIL
:
371 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
372 region_name
= "dri2 stencil buffer";
375 case __DRI_BUFFER_ACCUM
:
378 "unhandled buffer attach event, attachment type %d\n",
379 buffers
[i
].attachment
);
386 if (rb
->region
&& rb
->region
->name
== buffers
[i
].name
)
389 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
391 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
392 buffers
[i
].name
, buffers
[i
].attachment
,
393 buffers
[i
].cpp
, buffers
[i
].pitch
);
395 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
396 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
397 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
398 intel_region_reference(®ion
, depth_region
);
401 region
= intel_region_alloc_for_handle(intel
->intelScreen
,
405 buffers
[i
].pitch
/ buffers
[i
].cpp
,
409 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
410 depth_region
= region
;
412 intel_renderbuffer_set_region(intel
, rb
, region
);
413 intel_region_release(®ion
);
415 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
416 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
418 struct intel_region
*stencil_region
= NULL
;
420 if (rb
->region
&& rb
->region
->name
== buffers
[i
].name
)
423 intel_region_reference(&stencil_region
, region
);
424 intel_renderbuffer_set_region(intel
, rb
, stencil_region
);
425 intel_region_release(&stencil_region
);
430 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
434 * intel_prepare_render should be called anywhere that curent read/drawbuffer
438 intel_prepare_render(struct intel_context
*intel
)
440 __DRIcontext
*driContext
= intel
->driContext
;
441 __DRIdrawable
*drawable
;
443 drawable
= driContext
->driDrawablePriv
;
444 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
445 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
446 intel_update_renderbuffers(driContext
, drawable
);
447 intel_draw_buffer(&intel
->ctx
, intel
->ctx
.DrawBuffer
);
448 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
451 drawable
= driContext
->driReadablePriv
;
452 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
453 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
454 intel_update_renderbuffers(driContext
, drawable
);
455 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
458 /* If we're currently rendering to the front buffer, the rendering
459 * that will happen next will probably dirty the front buffer. So
460 * mark it as dirty here.
462 if (intel
->is_front_buffer_rendering
)
463 intel
->front_buffer_dirty
= GL_TRUE
;
465 /* Wait for the swapbuffers before the one we just emitted, so we
466 * don't get too many swaps outstanding for apps that are GPU-heavy
469 * We're using intelDRI2Flush (called from the loader before
470 * swapbuffer) and glFlush (for front buffer rendering) as the
471 * indicator that a frame is done and then throttle when we get
472 * here as we prepare to render the next frame. At this point for
473 * round trips for swap/copy and getting new buffers are done and
474 * we'll spend less time waiting on the GPU.
476 * Unfortunately, we don't have a handle to the batch containing
477 * the swap, and getting our hands on that doesn't seem worth it,
478 * so we just us the first batch we emitted after the last swap.
480 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
481 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
482 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
483 intel
->first_post_swapbuffers_batch
= NULL
;
484 intel
->need_throttle
= GL_FALSE
;
489 intel_viewport(struct gl_context
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
491 struct intel_context
*intel
= intel_context(ctx
);
492 __DRIcontext
*driContext
= intel
->driContext
;
494 if (intel
->saved_viewport
)
495 intel
->saved_viewport(ctx
, x
, y
, w
, h
);
497 if (ctx
->DrawBuffer
->Name
== 0) {
498 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
499 dri2InvalidateDrawable(driContext
->driReadablePriv
);
503 static const struct dri_debug_control debug_control
[] = {
504 { "tex", DEBUG_TEXTURE
},
505 { "state", DEBUG_STATE
},
506 { "ioctl", DEBUG_IOCTL
},
507 { "blit", DEBUG_BLIT
},
508 { "mip", DEBUG_MIPTREE
},
509 { "fall", DEBUG_FALLBACKS
},
510 { "verb", DEBUG_VERBOSE
},
511 { "bat", DEBUG_BATCH
},
512 { "pix", DEBUG_PIXEL
},
513 { "buf", DEBUG_BUFMGR
},
514 { "reg", DEBUG_REGION
},
517 { "sync", DEBUG_SYNC
},
518 { "prim", DEBUG_PRIMS
},
519 { "vert", DEBUG_VERTS
},
520 { "dri", DEBUG_DRI
},
522 { "san", DEBUG_SANITY
},
523 { "sleep", DEBUG_SLEEP
},
524 { "stats", DEBUG_STATS
},
525 { "tile", DEBUG_TILE
},
526 { "sing", DEBUG_SINGLE_THREAD
},
527 { "thre", DEBUG_SINGLE_THREAD
},
529 { "urb", DEBUG_URB
},
531 { "clip", DEBUG_CLIP
},
537 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
539 struct intel_context
*intel
= intel_context(ctx
);
541 _swrast_InvalidateState(ctx
, new_state
);
542 _swsetup_InvalidateState(ctx
, new_state
);
543 _vbo_InvalidateState(ctx
, new_state
);
544 _tnl_InvalidateState(ctx
, new_state
);
545 _tnl_invalidate_vertex_state(ctx
, new_state
);
547 intel
->NewGLState
|= new_state
;
549 if (intel
->vtbl
.invalidate_state
)
550 intel
->vtbl
.invalidate_state( intel
, new_state
);
554 intel_flush(struct gl_context
*ctx
)
556 struct intel_context
*intel
= intel_context(ctx
);
562 INTEL_FIREVERTICES(intel
);
564 if (intel
->batch
.used
)
565 intel_batchbuffer_flush(intel
);
569 intel_glFlush(struct gl_context
*ctx
)
571 struct intel_context
*intel
= intel_context(ctx
);
574 intel_flush_front(ctx
);
575 if (intel
->is_front_buffer_rendering
)
576 intel
->need_throttle
= GL_TRUE
;
580 intelFinish(struct gl_context
* ctx
)
582 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
586 intel_flush_front(ctx
);
588 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
589 struct intel_renderbuffer
*irb
;
591 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
593 if (irb
&& irb
->region
&& irb
->region
->buffer
)
594 drm_intel_bo_wait_rendering(irb
->region
->buffer
);
596 if (fb
->_DepthBuffer
) {
597 /* XXX: Wait on buffer idle */
602 intelInitDriverFunctions(struct dd_function_table
*functions
)
604 _mesa_init_driver_functions(functions
);
606 functions
->Flush
= intel_glFlush
;
607 functions
->Finish
= intelFinish
;
608 functions
->GetString
= intelGetString
;
609 functions
->UpdateState
= intelInvalidateState
;
611 intelInitTextureFuncs(functions
);
612 intelInitTextureImageFuncs(functions
);
613 intelInitTextureSubImageFuncs(functions
);
614 intelInitTextureCopyImageFuncs(functions
);
615 intelInitStateFuncs(functions
);
616 intelInitClearFuncs(functions
);
617 intelInitBufferFuncs(functions
);
618 intelInitPixelFuncs(functions
);
619 intelInitBufferObjectFuncs(functions
);
620 intel_init_syncobj_functions(functions
);
625 intelInitContext(struct intel_context
*intel
,
627 const struct gl_config
* mesaVis
,
628 __DRIcontext
* driContextPriv
,
629 void *sharedContextPrivate
,
630 struct dd_function_table
*functions
)
632 struct gl_context
*ctx
= &intel
->ctx
;
633 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
634 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
635 struct intel_screen
*intelScreen
= sPriv
->private;
637 struct gl_config visual
;
639 /* we can't do anything without a connection to the device */
640 if (intelScreen
->bufmgr
== NULL
)
643 /* Can't rely on invalidate events, fall back to glViewport hack */
644 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
) {
645 intel
->saved_viewport
= functions
->Viewport
;
646 functions
->Viewport
= intel_viewport
;
649 if (mesaVis
== NULL
) {
650 memset(&visual
, 0, sizeof visual
);
654 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
655 functions
, (void *) intel
)) {
656 printf("%s: failed to init mesa context\n", __FUNCTION__
);
660 driContextPriv
->driverPrivate
= intel
;
661 intel
->intelScreen
= intelScreen
;
662 intel
->driContext
= driContextPriv
;
663 intel
->driFd
= sPriv
->fd
;
665 intel
->has_xrgb_textures
= GL_TRUE
;
666 intel
->gen
= intelScreen
->gen
;
667 if (IS_GEN7(intel
->intelScreen
->deviceID
)) {
668 intel
->needs_ff_sync
= GL_TRUE
;
669 intel
->has_luminance_srgb
= GL_TRUE
;
670 } else if (IS_GEN6(intel
->intelScreen
->deviceID
)) {
671 intel
->needs_ff_sync
= GL_TRUE
;
672 intel
->has_luminance_srgb
= GL_TRUE
;
673 } else if (IS_GEN5(intel
->intelScreen
->deviceID
)) {
674 intel
->needs_ff_sync
= GL_TRUE
;
675 intel
->has_luminance_srgb
= GL_TRUE
;
676 } else if (IS_965(intel
->intelScreen
->deviceID
)) {
677 if (IS_G4X(intel
->intelScreen
->deviceID
)) {
678 intel
->has_luminance_srgb
= GL_TRUE
;
679 intel
->is_g4x
= GL_TRUE
;
681 } else if (IS_9XX(intel
->intelScreen
->deviceID
)) {
682 if (IS_945(intel
->intelScreen
->deviceID
)) {
683 intel
->is_945
= GL_TRUE
;
686 if (intel
->intelScreen
->deviceID
== PCI_CHIP_I830_M
||
687 intel
->intelScreen
->deviceID
== PCI_CHIP_845_G
) {
688 intel
->has_xrgb_textures
= GL_FALSE
;
692 memset(&ctx
->TextureFormatSupported
, 0,
693 sizeof(ctx
->TextureFormatSupported
));
694 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB8888
] = GL_TRUE
;
695 if (intel
->has_xrgb_textures
)
696 ctx
->TextureFormatSupported
[MESA_FORMAT_XRGB8888
] = GL_TRUE
;
697 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB4444
] = GL_TRUE
;
698 ctx
->TextureFormatSupported
[MESA_FORMAT_ARGB1555
] = GL_TRUE
;
699 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB565
] = GL_TRUE
;
700 ctx
->TextureFormatSupported
[MESA_FORMAT_L8
] = GL_TRUE
;
701 ctx
->TextureFormatSupported
[MESA_FORMAT_A8
] = GL_TRUE
;
702 ctx
->TextureFormatSupported
[MESA_FORMAT_I8
] = GL_TRUE
;
703 ctx
->TextureFormatSupported
[MESA_FORMAT_AL88
] = GL_TRUE
;
705 ctx
->TextureFormatSupported
[MESA_FORMAT_AL1616
] = GL_TRUE
;
706 ctx
->TextureFormatSupported
[MESA_FORMAT_S8_Z24
] = GL_TRUE
;
708 * This was disabled in initial FBO enabling to avoid combinations
709 * of depth+stencil that wouldn't work together. We since decided
710 * that it was OK, since it's up to the app to come up with the
711 * combo that actually works, so this can probably be re-enabled.
714 ctx->TextureFormatSupported[MESA_FORMAT_Z16] = GL_TRUE;
715 ctx->TextureFormatSupported[MESA_FORMAT_Z24] = GL_TRUE;
718 /* ctx->Extensions.MESA_ycbcr_texture */
719 ctx
->TextureFormatSupported
[MESA_FORMAT_YCBCR
] = GL_TRUE
;
720 ctx
->TextureFormatSupported
[MESA_FORMAT_YCBCR_REV
] = GL_TRUE
;
722 /* GL_3DFX_texture_compression_FXT1 */
723 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_FXT1
] = GL_TRUE
;
724 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_FXT1
] = GL_TRUE
;
726 /* GL_EXT_texture_compression_s3tc */
727 ctx
->TextureFormatSupported
[MESA_FORMAT_RGB_DXT1
] = GL_TRUE
;
728 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT1
] = GL_TRUE
;
729 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT3
] = GL_TRUE
;
730 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_DXT5
] = GL_TRUE
;
733 /* GL_ARB_texture_compression_rgtc */
734 ctx
->TextureFormatSupported
[MESA_FORMAT_RED_RGTC1
] = GL_TRUE
;
735 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RED_RGTC1
] = GL_TRUE
;
736 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_RGTC2
] = GL_TRUE
;
737 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RG_RGTC2
] = GL_TRUE
;
739 /* GL_ARB_texture_rg */
740 ctx
->TextureFormatSupported
[MESA_FORMAT_R8
] = GL_TRUE
;
741 ctx
->TextureFormatSupported
[MESA_FORMAT_R16
] = GL_TRUE
;
742 ctx
->TextureFormatSupported
[MESA_FORMAT_RG88
] = GL_TRUE
;
743 ctx
->TextureFormatSupported
[MESA_FORMAT_RG1616
] = GL_TRUE
;
745 /* GL_MESA_texture_signed_rgba / GL_EXT_texture_snorm */
746 ctx
->TextureFormatSupported
[MESA_FORMAT_DUDV8
] = GL_TRUE
;
747 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = GL_TRUE
;
748 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_R8
] = GL_TRUE
;
749 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_RG88_REV
] = GL_TRUE
;
750 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_R16
] = GL_TRUE
;
751 ctx
->TextureFormatSupported
[MESA_FORMAT_SIGNED_GR1616
] = GL_TRUE
;
753 /* GL_EXT_texture_sRGB */
754 ctx
->TextureFormatSupported
[MESA_FORMAT_SARGB8
] = GL_TRUE
;
755 if (intel
->gen
>= 5 || intel
->is_g4x
)
756 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGB_DXT1
] = GL_TRUE
;
757 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT1
] = GL_TRUE
;
758 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT3
] = GL_TRUE
;
759 ctx
->TextureFormatSupported
[MESA_FORMAT_SRGBA_DXT5
] = GL_TRUE
;
760 if (intel
->has_luminance_srgb
) {
761 ctx
->TextureFormatSupported
[MESA_FORMAT_SL8
] = GL_TRUE
;
762 ctx
->TextureFormatSupported
[MESA_FORMAT_SLA8
] = GL_TRUE
;
765 #ifdef TEXTURE_FLOAT_ENABLED
766 ctx
->TextureFormatSupported
[MESA_FORMAT_RGBA_FLOAT32
] = GL_TRUE
;
767 ctx
->TextureFormatSupported
[MESA_FORMAT_RG_FLOAT32
] = GL_TRUE
;
768 ctx
->TextureFormatSupported
[MESA_FORMAT_R_FLOAT32
] = GL_TRUE
;
769 ctx
->TextureFormatSupported
[MESA_FORMAT_INTENSITY_FLOAT32
] = GL_TRUE
;
770 ctx
->TextureFormatSupported
[MESA_FORMAT_LUMINANCE_FLOAT32
] = GL_TRUE
;
771 ctx
->TextureFormatSupported
[MESA_FORMAT_ALPHA_FLOAT32
] = GL_TRUE
;
772 ctx
->TextureFormatSupported
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = GL_TRUE
;
777 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
778 sPriv
->myNum
, (intel
->gen
>= 4) ? "i965" : "i915");
780 intel
->maxBatchSize
= 4096;
782 intel
->maxBatchSize
= sizeof(intel
->batch
.map
);
784 intel
->bufmgr
= intelScreen
->bufmgr
;
786 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
787 switch (bo_reuse_mode
) {
788 case DRI_CONF_BO_REUSE_DISABLED
:
790 case DRI_CONF_BO_REUSE_ALL
:
791 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
795 /* This doesn't yet catch all non-conformant rendering, but it's a
798 if (getenv("INTEL_STRICT_CONFORMANCE")) {
799 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
801 intel
->conformance_mode
= value
;
804 intel
->conformance_mode
= 1;
808 if (intel
->conformance_mode
> 0) {
809 ctx
->Const
.MinLineWidth
= 1.0;
810 ctx
->Const
.MinLineWidthAA
= 1.0;
811 ctx
->Const
.MaxLineWidth
= 1.0;
812 ctx
->Const
.MaxLineWidthAA
= 1.0;
813 ctx
->Const
.LineWidthGranularity
= 1.0;
816 ctx
->Const
.MinLineWidth
= 1.0;
817 ctx
->Const
.MinLineWidthAA
= 1.0;
818 ctx
->Const
.MaxLineWidth
= 5.0;
819 ctx
->Const
.MaxLineWidthAA
= 5.0;
820 ctx
->Const
.LineWidthGranularity
= 0.5;
823 ctx
->Const
.MinPointSize
= 1.0;
824 ctx
->Const
.MinPointSizeAA
= 1.0;
825 ctx
->Const
.MaxPointSize
= 255.0;
826 ctx
->Const
.MaxPointSizeAA
= 3.0;
827 ctx
->Const
.PointSizeGranularity
= 1.0;
829 ctx
->Const
.MaxSamples
= 1.0;
831 /* reinitialize the context point state.
832 * It depend on constants in __struct gl_contextRec::Const
834 _mesa_init_point(ctx
);
836 if (intel
->gen
>= 4) {
837 ctx
->Const
.sRGBCapable
= GL_TRUE
;
838 if (MAX_WIDTH
> 8192)
839 ctx
->Const
.MaxRenderbufferSize
= 8192;
841 if (MAX_WIDTH
> 2048)
842 ctx
->Const
.MaxRenderbufferSize
= 2048;
845 /* Initialize the software rasterizer and helper modules. */
846 _swrast_CreateContext(ctx
);
847 _vbo_CreateContext(ctx
);
848 _tnl_CreateContext(ctx
);
849 _swsetup_CreateContext(ctx
);
851 /* Configure swrast to match hardware characteristics: */
852 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
853 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
855 _mesa_meta_init(ctx
);
857 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
858 intel
->hw_stipple
= 1;
860 /* XXX FBO: this doesn't seem to be used anywhere */
861 switch (mesaVis
->depthBits
) {
862 case 0: /* what to do in this case? */
864 intel
->polygon_offset_scale
= 1.0;
867 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
875 intel
->polygon_offset_scale
/= 0xffff;
877 intel
->RenderIndex
= ~0;
881 intelInitExtensions(ctx
);
886 intelInitExtensionsES2(ctx
);
890 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
891 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
892 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
894 intel_batchbuffer_reset(intel
);
896 intel_fbo_init(intel
);
898 if (intel
->ctx
.Mesa_DXTn
) {
899 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
900 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
902 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
903 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
905 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
907 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
909 intel
->prim
.primitive
= ~0;
911 /* Force all software fallbacks */
912 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
913 fprintf(stderr
, "disabling 3D rasterization\n");
917 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
918 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
919 intel
->always_flush_batch
= 1;
922 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
923 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
924 intel
->always_flush_cache
= 1;
931 intelDestroyContext(__DRIcontext
* driContextPriv
)
933 struct intel_context
*intel
=
934 (struct intel_context
*) driContextPriv
->driverPrivate
;
936 assert(intel
); /* should never be null */
938 INTEL_FIREVERTICES(intel
);
940 _mesa_meta_free(&intel
->ctx
);
942 intel
->vtbl
.destroy(intel
);
944 _swsetup_DestroyContext(&intel
->ctx
);
945 _tnl_DestroyContext(&intel
->ctx
);
946 _vbo_DestroyContext(&intel
->ctx
);
948 _swrast_DestroyContext(&intel
->ctx
);
949 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
951 intel_batchbuffer_free(intel
);
953 free(intel
->prim
.vb
);
954 intel
->prim
.vb
= NULL
;
955 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
956 intel
->prim
.vb_bo
= NULL
;
957 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
958 intel
->first_post_swapbuffers_batch
= NULL
;
960 driDestroyOptionCache(&intel
->optionCache
);
962 /* free the Mesa context */
963 _mesa_free_context_data(&intel
->ctx
);
966 driContextPriv
->driverPrivate
= NULL
;
971 intelUnbindContext(__DRIcontext
* driContextPriv
)
973 /* Unset current context and dispath table */
974 _mesa_make_current(NULL
, NULL
, NULL
);
980 intelMakeCurrent(__DRIcontext
* driContextPriv
,
981 __DRIdrawable
* driDrawPriv
,
982 __DRIdrawable
* driReadPriv
)
984 struct intel_context
*intel
;
985 GET_CURRENT_CONTEXT(curCtx
);
988 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
992 /* According to the glXMakeCurrent() man page: "Pending commands to
993 * the previous context, if any, are flushed before it is released."
994 * But only flush if we're actually changing contexts.
996 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
1000 if (driContextPriv
) {
1001 struct gl_framebuffer
*fb
, *readFb
;
1003 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
1004 fb
= _mesa_get_incomplete_framebuffer();
1005 readFb
= _mesa_get_incomplete_framebuffer();
1007 fb
= driDrawPriv
->driverPrivate
;
1008 readFb
= driReadPriv
->driverPrivate
;
1009 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
1010 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
1013 intel_prepare_render(intel
);
1014 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
1016 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
1017 * is NULL at that point. We can't call _mesa_makecurrent()
1018 * first, since we need the buffer size for the initial
1019 * viewport. So just call intel_draw_buffer() again here. */
1020 intel_draw_buffer(&intel
->ctx
, intel
->ctx
.DrawBuffer
);
1023 _mesa_make_current(NULL
, NULL
, NULL
);