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/framebuffer.h"
33 #include "main/imports.h"
34 #include "main/points.h"
36 #include "swrast/swrast.h"
37 #include "swrast_setup/swrast_setup.h"
39 #include "drivers/common/driverfuncs.h"
40 #include "drivers/common/meta.h"
44 #include "intel_chipset.h"
45 #include "intel_buffers.h"
46 #include "intel_tex.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_clear.h"
49 #include "intel_extensions.h"
50 #include "intel_pixel.h"
51 #include "intel_regions.h"
52 #include "intel_buffer_objects.h"
53 #include "intel_fbo.h"
54 #include "intel_bufmgr.h"
55 #include "intel_screen.h"
57 #include "drirenderbuffer.h"
62 int INTEL_DEBUG
= (0);
66 #define DRIVER_DATE "20100330 DEVELOPMENT"
67 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
70 static const GLubyte
*
71 intelGetString(GLcontext
* ctx
, GLenum name
)
73 const struct intel_context
*const intel
= intel_context(ctx
);
75 static char buffer
[128];
79 return (GLubyte
*) "Tungsten Graphics, Inc";
83 switch (intel
->intelScreen
->deviceID
) {
85 chipset
= "Intel(R) 845G";
88 chipset
= "Intel(R) 830M";
90 case PCI_CHIP_I855_GM
:
91 chipset
= "Intel(R) 852GM/855GM";
94 chipset
= "Intel(R) 865G";
97 chipset
= "Intel(R) 915G";
99 case PCI_CHIP_E7221_G
:
100 chipset
= "Intel (R) E7221G (i915)";
102 case PCI_CHIP_I915_GM
:
103 chipset
= "Intel(R) 915GM";
105 case PCI_CHIP_I945_G
:
106 chipset
= "Intel(R) 945G";
108 case PCI_CHIP_I945_GM
:
109 chipset
= "Intel(R) 945GM";
111 case PCI_CHIP_I945_GME
:
112 chipset
= "Intel(R) 945GME";
115 chipset
= "Intel(R) G33";
118 chipset
= "Intel(R) Q35";
121 chipset
= "Intel(R) Q33";
123 case PCI_CHIP_IGD_GM
:
125 chipset
= "Intel(R) IGD";
127 case PCI_CHIP_I965_Q
:
128 chipset
= "Intel(R) 965Q";
130 case PCI_CHIP_I965_G
:
131 case PCI_CHIP_I965_G_1
:
132 chipset
= "Intel(R) 965G";
134 case PCI_CHIP_I946_GZ
:
135 chipset
= "Intel(R) 946GZ";
137 case PCI_CHIP_I965_GM
:
138 chipset
= "Intel(R) 965GM";
140 case PCI_CHIP_I965_GME
:
141 chipset
= "Intel(R) 965GME/GLE";
143 case PCI_CHIP_GM45_GM
:
144 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
146 case PCI_CHIP_IGD_E_G
:
147 chipset
= "Intel(R) Integrated Graphics Device";
150 chipset
= "Intel(R) G45/G43";
153 chipset
= "Intel(R) Q45/Q43";
156 chipset
= "Intel(R) G41";
159 chipset
= "Intel(R) B43";
162 chipset
= "Intel(R) IGDNG_D";
165 chipset
= "Intel(R) IGDNG_M";
168 chipset
= "Unknown Intel Chipset";
172 (void) driGetRendererString(buffer
, chipset
, DRIVER_DATE_GEM
, 0);
173 return (GLubyte
*) buffer
;
181 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
183 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
187 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
189 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
190 struct intel_renderbuffer
*rb
;
191 struct intel_region
*region
, *depth_region
;
192 struct intel_context
*intel
= context
->driverPrivate
;
193 struct intel_renderbuffer
*front_rb
, *back_rb
, *depth_rb
, *stencil_rb
;
194 __DRIbuffer
*buffers
= NULL
;
197 unsigned int attachments
[10];
198 const char *region_name
;
200 /* If we're rendering to the fake front buffer, make sure all the
201 * pending drawing has landed on the real front buffer. Otherwise
202 * when we eventually get to DRI2GetBuffersWithFormat the stale
203 * real front buffer contents will get copied to the new fake front
206 if (intel
->is_front_buffer_rendering
)
207 intel_flush(&intel
->ctx
, GL_FALSE
);
209 /* Set this up front, so that in case our buffers get invalidated
210 * while we're getting new buffers, we don't clobber the stamp and
211 * thus ignore the invalidate. */
212 drawable
->lastStamp
= drawable
->dri2
.stamp
;
214 if (INTEL_DEBUG
& DEBUG_DRI
)
215 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
217 screen
= intel
->intelScreen
->driScrnPriv
;
219 if (screen
->dri2
.loader
220 && (screen
->dri2
.loader
->base
.version
> 2)
221 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
223 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
224 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
225 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
226 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
229 if ((intel
->is_front_buffer_rendering
||
230 intel
->is_front_buffer_reading
||
231 !back_rb
) && front_rb
) {
232 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
233 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
237 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
238 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
241 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
242 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
243 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
244 } else if (depth_rb
!= NULL
) {
245 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
246 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
247 } else if (stencil_rb
!= NULL
) {
248 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
249 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
253 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
258 drawable
->loaderPrivate
);
259 } else if (screen
->dri2
.loader
) {
261 if (intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
))
262 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
263 if (intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
))
264 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
265 if (intel_get_renderbuffer(fb
, BUFFER_DEPTH
))
266 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
267 if (intel_get_renderbuffer(fb
, BUFFER_STENCIL
))
268 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
270 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
275 drawable
->loaderPrivate
);
285 drawable
->numClipRects
= 1;
286 drawable
->pClipRects
[0].x1
= 0;
287 drawable
->pClipRects
[0].y1
= 0;
288 drawable
->pClipRects
[0].x2
= drawable
->w
;
289 drawable
->pClipRects
[0].y2
= drawable
->h
;
290 drawable
->numBackClipRects
= 1;
291 drawable
->pBackClipRects
[0].x1
= 0;
292 drawable
->pBackClipRects
[0].y1
= 0;
293 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
294 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
297 for (i
= 0; i
< count
; i
++) {
298 switch (buffers
[i
].attachment
) {
299 case __DRI_BUFFER_FRONT_LEFT
:
300 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
301 region_name
= "dri2 front buffer";
304 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
305 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
306 region_name
= "dri2 fake front buffer";
309 case __DRI_BUFFER_BACK_LEFT
:
310 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
311 region_name
= "dri2 back buffer";
314 case __DRI_BUFFER_DEPTH
:
315 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
316 region_name
= "dri2 depth buffer";
319 case __DRI_BUFFER_DEPTH_STENCIL
:
320 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
321 region_name
= "dri2 depth / stencil buffer";
324 case __DRI_BUFFER_STENCIL
:
325 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
326 region_name
= "dri2 stencil buffer";
329 case __DRI_BUFFER_ACCUM
:
332 "unhandled buffer attach event, attacment type %d\n",
333 buffers
[i
].attachment
);
340 if (rb
->region
&& rb
->region
->name
== buffers
[i
].name
)
343 if (INTEL_DEBUG
& DEBUG_DRI
)
345 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
346 buffers
[i
].name
, buffers
[i
].attachment
,
347 buffers
[i
].cpp
, buffers
[i
].pitch
);
349 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
350 if (INTEL_DEBUG
& DEBUG_DRI
)
351 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
352 intel_region_reference(®ion
, depth_region
);
355 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
358 buffers
[i
].pitch
/ buffers
[i
].cpp
,
362 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
363 depth_region
= region
;
365 intel_renderbuffer_set_region(rb
, region
);
366 intel_region_release(®ion
);
368 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
369 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
371 struct intel_region
*stencil_region
= NULL
;
373 if (rb
->region
&& rb
->region
->name
== buffers
[i
].name
)
376 intel_region_reference(&stencil_region
, region
);
377 intel_renderbuffer_set_region(rb
, stencil_region
);
378 intel_region_release(&stencil_region
);
383 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
387 intel_prepare_render(struct intel_context
*intel
)
389 __DRIcontext
*driContext
= intel
->driContext
;
390 __DRIdrawable
*drawable
;
392 drawable
= driContext
->driDrawablePriv
;
393 if (drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
394 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
395 intel_update_renderbuffers(driContext
, drawable
);
396 intel_draw_buffer(&intel
->ctx
, intel
->ctx
.DrawBuffer
);
397 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
400 drawable
= driContext
->driReadablePriv
;
401 if (drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
402 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
403 intel_update_renderbuffers(driContext
, drawable
);
404 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
409 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
411 struct intel_context
*intel
= intel_context(ctx
);
412 __DRIcontext
*driContext
= intel
->driContext
;
414 if (!intel
->using_dri2_swapbuffers
&&
415 !intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
416 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
417 dri2InvalidateDrawable(driContext
->driReadablePriv
);
421 static const struct dri_debug_control debug_control
[] = {
422 { "tex", DEBUG_TEXTURE
},
423 { "state", DEBUG_STATE
},
424 { "ioctl", DEBUG_IOCTL
},
425 { "blit", DEBUG_BLIT
},
426 { "mip", DEBUG_MIPTREE
},
427 { "fall", DEBUG_FALLBACKS
},
428 { "verb", DEBUG_VERBOSE
},
429 { "bat", DEBUG_BATCH
},
430 { "pix", DEBUG_PIXEL
},
431 { "buf", DEBUG_BUFMGR
},
432 { "reg", DEBUG_REGION
},
434 { "lock", DEBUG_LOCK
},
435 { "sync", DEBUG_SYNC
},
436 { "prim", DEBUG_PRIMS
},
437 { "vert", DEBUG_VERTS
},
438 { "dri", DEBUG_DRI
},
439 { "dma", DEBUG_DMA
},
440 { "san", DEBUG_SANITY
},
441 { "sleep", DEBUG_SLEEP
},
442 { "stats", DEBUG_STATS
},
443 { "tile", DEBUG_TILE
},
444 { "sing", DEBUG_SINGLE_THREAD
},
445 { "thre", DEBUG_SINGLE_THREAD
},
447 { "glsl_force", DEBUG_GLSL_FORCE
},
448 { "urb", DEBUG_URB
},
455 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
457 struct intel_context
*intel
= intel_context(ctx
);
459 _swrast_InvalidateState(ctx
, new_state
);
460 _swsetup_InvalidateState(ctx
, new_state
);
461 _vbo_InvalidateState(ctx
, new_state
);
462 _tnl_InvalidateState(ctx
, new_state
);
463 _tnl_invalidate_vertex_state(ctx
, new_state
);
465 intel
->NewGLState
|= new_state
;
467 if (intel
->vtbl
.invalidate_state
)
468 intel
->vtbl
.invalidate_state( intel
, new_state
);
472 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
474 struct intel_context
*intel
= intel_context(ctx
);
475 __DRIcontext
*driContext
= intel
->driContext
;
481 INTEL_FIREVERTICES(intel
);
483 if (intel
->batch
->map
!= intel
->batch
->ptr
)
484 intel_batchbuffer_flush(intel
->batch
);
486 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
487 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
489 if (screen
->dri2
.loader
&&
490 (screen
->dri2
.loader
->base
.version
>= 2)
491 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
492 driContext
->driDrawablePriv
&&
493 driContext
->driDrawablePriv
->loaderPrivate
) {
494 (*screen
->dri2
.loader
->flushFrontBuffer
)(driContext
->driDrawablePriv
,
495 driContext
->driDrawablePriv
->loaderPrivate
);
497 /* Only clear the dirty bit if front-buffer rendering is no longer
498 * enabled. This is done so that the dirty bit can only be set in
499 * glDrawBuffer. Otherwise the dirty bit would have to be set at
500 * each of N places that do rendering. This has worse performances,
501 * but it is much easier to get correct.
503 if (!intel
->is_front_buffer_rendering
) {
504 intel
->front_buffer_dirty
= GL_FALSE
;
511 intelFlush(GLcontext
* ctx
)
513 intel_flush(ctx
, GL_FALSE
);
517 intel_glFlush(GLcontext
*ctx
)
519 struct intel_context
*intel
= intel_context(ctx
);
521 intel_flush(ctx
, GL_TRUE
);
523 /* We're using glFlush as an indicator that a frame is done, which is
524 * what DRI2 does before calling SwapBuffers (and means we should catch
525 * people doing front-buffer rendering, as well)..
527 * Wait for the swapbuffers before the one we just emitted, so we don't
528 * get too many swaps outstanding for apps that are GPU-heavy but not
531 * Unfortunately, we don't have a handle to the batch containing the swap,
532 * and getting our hands on that doesn't seem worth it, so we just us the
533 * first batch we emitted after the last swap.
535 if (!intel
->using_dri2_swapbuffers
&&
536 intel
->first_post_swapbuffers_batch
!= NULL
) {
537 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
538 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
539 intel
->first_post_swapbuffers_batch
= NULL
;
544 intelFinish(GLcontext
* ctx
)
546 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
551 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
552 struct intel_renderbuffer
*irb
;
554 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
556 if (irb
&& irb
->region
)
557 dri_bo_wait_rendering(irb
->region
->buffer
);
559 if (fb
->_DepthBuffer
) {
560 /* XXX: Wait on buffer idle */
565 intelInitDriverFunctions(struct dd_function_table
*functions
)
567 _mesa_init_driver_functions(functions
);
569 functions
->Flush
= intel_glFlush
;
570 functions
->Finish
= intelFinish
;
571 functions
->GetString
= intelGetString
;
572 functions
->UpdateState
= intelInvalidateState
;
574 intelInitTextureFuncs(functions
);
575 intelInitTextureImageFuncs(functions
);
576 intelInitTextureSubImageFuncs(functions
);
577 intelInitTextureCopyImageFuncs(functions
);
578 intelInitStateFuncs(functions
);
579 intelInitClearFuncs(functions
);
580 intelInitBufferFuncs(functions
);
581 intelInitPixelFuncs(functions
);
582 intelInitBufferObjectFuncs(functions
);
583 intel_init_syncobj_functions(functions
);
588 intelInitContext(struct intel_context
*intel
,
589 const __GLcontextModes
* mesaVis
,
590 __DRIcontext
* driContextPriv
,
591 void *sharedContextPrivate
,
592 struct dd_function_table
*functions
)
594 GLcontext
*ctx
= &intel
->ctx
;
595 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
596 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
597 struct intel_screen
*intelScreen
= sPriv
->private;
600 /* we can't do anything without a connection to the device */
601 if (intelScreen
->bufmgr
== NULL
)
604 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
605 functions
, (void *) intel
)) {
606 printf("%s: failed to init mesa context\n", __FUNCTION__
);
610 driContextPriv
->driverPrivate
= intel
;
611 intel
->intelScreen
= intelScreen
;
612 intel
->driContext
= driContextPriv
;
613 intel
->driFd
= sPriv
->fd
;
615 if (IS_GEN6(intel
->intelScreen
->deviceID
)) {
617 intel
->needs_ff_sync
= GL_TRUE
;
618 intel
->has_luminance_srgb
= GL_TRUE
;
619 } else if (IS_965(intel
->intelScreen
->deviceID
)) {
621 } else if (IS_9XX(intel
->intelScreen
->deviceID
)) {
623 if (IS_945(intel
->intelScreen
->deviceID
)) {
624 intel
->is_945
= GL_TRUE
;
630 if (IS_IGDNG(intel
->intelScreen
->deviceID
)) {
631 intel
->is_ironlake
= GL_TRUE
;
632 intel
->needs_ff_sync
= GL_TRUE
;
633 intel
->has_luminance_srgb
= GL_TRUE
;
634 } else if (IS_G4X(intel
->intelScreen
->deviceID
)) {
635 intel
->has_luminance_srgb
= GL_TRUE
;
636 intel
->is_g4x
= GL_TRUE
;
639 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
640 sPriv
->myNum
, (intel
->gen
>= 4) ? "i965" : "i915");
641 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
642 intel
->maxBatchSize
= 4096;
644 intel
->maxBatchSize
= BATCH_SZ
;
646 intel
->bufmgr
= intelScreen
->bufmgr
;
648 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
649 switch (bo_reuse_mode
) {
650 case DRI_CONF_BO_REUSE_DISABLED
:
652 case DRI_CONF_BO_REUSE_ALL
:
653 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
657 /* This doesn't yet catch all non-conformant rendering, but it's a
660 if (getenv("INTEL_STRICT_CONFORMANCE")) {
661 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
663 intel
->conformance_mode
= value
;
666 intel
->conformance_mode
= 1;
670 if (intel
->conformance_mode
> 0) {
671 ctx
->Const
.MinLineWidth
= 1.0;
672 ctx
->Const
.MinLineWidthAA
= 1.0;
673 ctx
->Const
.MaxLineWidth
= 1.0;
674 ctx
->Const
.MaxLineWidthAA
= 1.0;
675 ctx
->Const
.LineWidthGranularity
= 1.0;
678 ctx
->Const
.MinLineWidth
= 1.0;
679 ctx
->Const
.MinLineWidthAA
= 1.0;
680 ctx
->Const
.MaxLineWidth
= 5.0;
681 ctx
->Const
.MaxLineWidthAA
= 5.0;
682 ctx
->Const
.LineWidthGranularity
= 0.5;
685 ctx
->Const
.MinPointSize
= 1.0;
686 ctx
->Const
.MinPointSizeAA
= 1.0;
687 ctx
->Const
.MaxPointSize
= 255.0;
688 ctx
->Const
.MaxPointSizeAA
= 3.0;
689 ctx
->Const
.PointSizeGranularity
= 1.0;
691 /* reinitialize the context point state.
692 * It depend on constants in __GLcontextRec::Const
694 _mesa_init_point(ctx
);
696 meta_init_metaops(ctx
, &intel
->meta
);
697 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
698 if (intel
->gen
>= 4) {
699 if (MAX_WIDTH
> 8192)
700 ctx
->Const
.MaxRenderbufferSize
= 8192;
702 if (MAX_WIDTH
> 2048)
703 ctx
->Const
.MaxRenderbufferSize
= 2048;
706 /* Initialize the software rasterizer and helper modules. */
707 _swrast_CreateContext(ctx
);
708 _vbo_CreateContext(ctx
);
709 _tnl_CreateContext(ctx
);
710 _swsetup_CreateContext(ctx
);
712 /* Configure swrast to match hardware characteristics: */
713 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
714 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
716 _mesa_meta_init(ctx
);
718 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
719 intel
->hw_stipple
= 1;
721 /* XXX FBO: this doesn't seem to be used anywhere */
722 switch (mesaVis
->depthBits
) {
723 case 0: /* what to do in this case? */
725 intel
->polygon_offset_scale
= 1.0;
728 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
736 intel
->polygon_offset_scale
/= 0xffff;
738 intel
->RenderIndex
= ~0;
740 intelInitExtensions(ctx
);
742 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
743 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
744 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
746 intel
->batch
= intel_batchbuffer_alloc(intel
);
748 intel_fbo_init(intel
);
750 if (intel
->ctx
.Mesa_DXTn
) {
751 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
752 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
754 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
755 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
757 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
759 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
761 intel
->prim
.primitive
= ~0;
763 /* Force all software fallbacks */
764 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
765 fprintf(stderr
, "disabling 3D rasterization\n");
769 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
770 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
771 intel
->always_flush_batch
= 1;
774 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
775 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
776 intel
->always_flush_cache
= 1;
779 /* Disable all hardware rendering (skip emitting batches and fences/waits
782 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
788 intelDestroyContext(__DRIcontext
* driContextPriv
)
790 struct intel_context
*intel
=
791 (struct intel_context
*) driContextPriv
->driverPrivate
;
793 assert(intel
); /* should never be null */
795 GLboolean release_texture_heaps
;
797 INTEL_FIREVERTICES(intel
);
799 _mesa_meta_free(&intel
->ctx
);
801 meta_destroy_metaops(&intel
->meta
);
803 intel
->vtbl
.destroy(intel
);
805 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
806 _swsetup_DestroyContext(&intel
->ctx
);
807 _tnl_DestroyContext(&intel
->ctx
);
808 _vbo_DestroyContext(&intel
->ctx
);
810 _swrast_DestroyContext(&intel
->ctx
);
811 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
813 intel_batchbuffer_free(intel
->batch
);
816 free(intel
->prim
.vb
);
817 intel
->prim
.vb
= NULL
;
818 dri_bo_unreference(intel
->prim
.vb_bo
);
819 intel
->prim
.vb_bo
= NULL
;
820 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
821 intel
->first_post_swapbuffers_batch
= NULL
;
823 if (release_texture_heaps
) {
824 /* Nothing is currently done here to free texture heaps;
825 * but we're not using the texture heap utilities, so I
826 * rather think we shouldn't. I've taken a look, and can't
827 * find any private texture data hanging around anywhere, but
828 * I'm not yet certain there isn't any at all...
830 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
831 fprintf(stderr, "do something to free texture heaps\n");
835 driDestroyOptionCache(&intel
->optionCache
);
837 /* free the Mesa context */
838 _mesa_free_context_data(&intel
->ctx
);
841 driContextPriv
->driverPrivate
= NULL
;
846 intelUnbindContext(__DRIcontext
* driContextPriv
)
852 intelMakeCurrent(__DRIcontext
* driContextPriv
,
853 __DRIdrawable
* driDrawPriv
,
854 __DRIdrawable
* driReadPriv
)
856 struct intel_context
*intel
;
857 GET_CURRENT_CONTEXT(curCtx
);
860 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
864 /* According to the glXMakeCurrent() man page: "Pending commands to
865 * the previous context, if any, are flushed before it is released."
866 * But only flush if we're actually changing contexts.
868 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
872 if (driContextPriv
) {
873 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
874 struct gl_framebuffer
*readFb
= driReadPriv
->driverPrivate
;
876 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
877 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
878 intel_prepare_render(intel
);
879 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
882 _mesa_make_current(NULL
, NULL
, NULL
);