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) Ironlake Desktop";
165 chipset
= "Intel(R) Ironlake Mobile";
168 chipset
= "Unknown Intel Chipset";
172 (void) driGetRendererString(buffer
, chipset
, DRIVER_DATE_GEM
, 0);
173 return (GLubyte
*) buffer
;
181 intel_flush_front(GLcontext
*ctx
)
183 struct intel_context
*intel
= intel_context(ctx
);
184 __DRIcontext
*driContext
= intel
->driContext
;
185 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
187 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
188 if (screen
->dri2
.loader
&&
189 (screen
->dri2
.loader
->base
.version
>= 2)
190 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
191 driContext
->driDrawablePriv
&&
192 driContext
->driDrawablePriv
->loaderPrivate
) {
193 (*screen
->dri2
.loader
->flushFrontBuffer
)(driContext
->driDrawablePriv
,
194 driContext
->driDrawablePriv
->loaderPrivate
);
196 /* We set the dirty bit in intel_prepare_render() if we're
197 * front buffer rendering once we get there.
199 intel
->front_buffer_dirty
= GL_FALSE
;
205 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
207 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
211 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
213 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
214 struct intel_renderbuffer
*rb
;
215 struct intel_region
*region
, *depth_region
;
216 struct intel_context
*intel
= context
->driverPrivate
;
217 struct intel_renderbuffer
*front_rb
, *back_rb
, *depth_rb
, *stencil_rb
;
218 __DRIbuffer
*buffers
= NULL
;
221 unsigned int attachments
[10];
222 const char *region_name
;
224 /* If we're rendering to the fake front buffer, make sure all the
225 * pending drawing has landed on the real front buffer. Otherwise
226 * when we eventually get to DRI2GetBuffersWithFormat the stale
227 * real front buffer contents will get copied to the new fake front
230 if (intel
->is_front_buffer_rendering
) {
231 intel_flush(&intel
->ctx
);
232 intel_flush_front(&intel
->ctx
);
235 /* Set this up front, so that in case our buffers get invalidated
236 * while we're getting new buffers, we don't clobber the stamp and
237 * thus ignore the invalidate. */
238 drawable
->lastStamp
= drawable
->dri2
.stamp
;
240 if (INTEL_DEBUG
& DEBUG_DRI
)
241 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
243 screen
= intel
->intelScreen
->driScrnPriv
;
245 if (screen
->dri2
.loader
246 && (screen
->dri2
.loader
->base
.version
> 2)
247 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
249 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
250 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
251 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
252 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
255 if ((intel
->is_front_buffer_rendering
||
256 intel
->is_front_buffer_reading
||
257 !back_rb
) && front_rb
) {
258 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
259 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
263 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
264 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
267 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
268 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
269 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
270 } else if (depth_rb
!= NULL
) {
271 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
272 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
273 } else if (stencil_rb
!= NULL
) {
274 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
275 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
279 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
284 drawable
->loaderPrivate
);
285 } else if (screen
->dri2
.loader
) {
287 if (intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
))
288 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
289 if (intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
))
290 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
291 if (intel_get_renderbuffer(fb
, BUFFER_DEPTH
))
292 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
293 if (intel_get_renderbuffer(fb
, BUFFER_STENCIL
))
294 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
296 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
301 drawable
->loaderPrivate
);
311 drawable
->numClipRects
= 1;
312 drawable
->pClipRects
[0].x1
= 0;
313 drawable
->pClipRects
[0].y1
= 0;
314 drawable
->pClipRects
[0].x2
= drawable
->w
;
315 drawable
->pClipRects
[0].y2
= drawable
->h
;
316 drawable
->numBackClipRects
= 1;
317 drawable
->pBackClipRects
[0].x1
= 0;
318 drawable
->pBackClipRects
[0].y1
= 0;
319 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
320 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
323 for (i
= 0; i
< count
; i
++) {
324 switch (buffers
[i
].attachment
) {
325 case __DRI_BUFFER_FRONT_LEFT
:
326 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
327 region_name
= "dri2 front buffer";
330 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
331 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
332 region_name
= "dri2 fake front buffer";
335 case __DRI_BUFFER_BACK_LEFT
:
336 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
337 region_name
= "dri2 back buffer";
340 case __DRI_BUFFER_DEPTH
:
341 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
342 region_name
= "dri2 depth buffer";
345 case __DRI_BUFFER_DEPTH_STENCIL
:
346 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
347 region_name
= "dri2 depth / stencil buffer";
350 case __DRI_BUFFER_STENCIL
:
351 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
352 region_name
= "dri2 stencil buffer";
355 case __DRI_BUFFER_ACCUM
:
358 "unhandled buffer attach event, attacment type %d\n",
359 buffers
[i
].attachment
);
366 if (rb
->region
&& rb
->region
->name
== buffers
[i
].name
)
369 if (INTEL_DEBUG
& DEBUG_DRI
)
371 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
372 buffers
[i
].name
, buffers
[i
].attachment
,
373 buffers
[i
].cpp
, buffers
[i
].pitch
);
375 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
376 if (INTEL_DEBUG
& DEBUG_DRI
)
377 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
378 intel_region_reference(®ion
, depth_region
);
381 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
384 buffers
[i
].pitch
/ buffers
[i
].cpp
,
388 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
389 depth_region
= region
;
391 intel_renderbuffer_set_region(intel
, rb
, region
);
392 intel_region_release(®ion
);
394 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
395 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
397 struct intel_region
*stencil_region
= NULL
;
399 if (rb
->region
&& rb
->region
->name
== buffers
[i
].name
)
402 intel_region_reference(&stencil_region
, region
);
403 intel_renderbuffer_set_region(intel
, rb
, stencil_region
);
404 intel_region_release(&stencil_region
);
409 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
413 intel_prepare_render(struct intel_context
*intel
)
415 __DRIcontext
*driContext
= intel
->driContext
;
416 __DRIdrawable
*drawable
;
418 drawable
= driContext
->driDrawablePriv
;
419 if (drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
420 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
421 intel_update_renderbuffers(driContext
, drawable
);
422 intel_draw_buffer(&intel
->ctx
, intel
->ctx
.DrawBuffer
);
423 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
426 drawable
= driContext
->driReadablePriv
;
427 if (drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
428 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
429 intel_update_renderbuffers(driContext
, drawable
);
430 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
433 /* If we're currently rendering to the front buffer, the rendering
434 * that will happen next will probably dirty the front buffer. So
435 * mark it as dirty here.
437 if (intel
->is_front_buffer_rendering
)
438 intel
->front_buffer_dirty
= GL_TRUE
;
442 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
444 struct intel_context
*intel
= intel_context(ctx
);
445 __DRIcontext
*driContext
= intel
->driContext
;
447 if (!intel
->using_dri2_swapbuffers
&&
448 !intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
449 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
450 dri2InvalidateDrawable(driContext
->driReadablePriv
);
454 static const struct dri_debug_control debug_control
[] = {
455 { "tex", DEBUG_TEXTURE
},
456 { "state", DEBUG_STATE
},
457 { "ioctl", DEBUG_IOCTL
},
458 { "blit", DEBUG_BLIT
},
459 { "mip", DEBUG_MIPTREE
},
460 { "fall", DEBUG_FALLBACKS
},
461 { "verb", DEBUG_VERBOSE
},
462 { "bat", DEBUG_BATCH
},
463 { "pix", DEBUG_PIXEL
},
464 { "buf", DEBUG_BUFMGR
},
465 { "reg", DEBUG_REGION
},
467 { "lock", DEBUG_LOCK
},
468 { "sync", DEBUG_SYNC
},
469 { "prim", DEBUG_PRIMS
},
470 { "vert", DEBUG_VERTS
},
471 { "dri", DEBUG_DRI
},
472 { "dma", DEBUG_DMA
},
473 { "san", DEBUG_SANITY
},
474 { "sleep", DEBUG_SLEEP
},
475 { "stats", DEBUG_STATS
},
476 { "tile", DEBUG_TILE
},
477 { "sing", DEBUG_SINGLE_THREAD
},
478 { "thre", DEBUG_SINGLE_THREAD
},
480 { "glsl_force", DEBUG_GLSL_FORCE
},
481 { "urb", DEBUG_URB
},
488 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
490 struct intel_context
*intel
= intel_context(ctx
);
492 _swrast_InvalidateState(ctx
, new_state
);
493 _swsetup_InvalidateState(ctx
, new_state
);
494 _vbo_InvalidateState(ctx
, new_state
);
495 _tnl_InvalidateState(ctx
, new_state
);
496 _tnl_invalidate_vertex_state(ctx
, new_state
);
498 intel
->NewGLState
|= new_state
;
500 if (intel
->vtbl
.invalidate_state
)
501 intel
->vtbl
.invalidate_state( intel
, new_state
);
505 intel_flush(GLcontext
*ctx
)
507 struct intel_context
*intel
= intel_context(ctx
);
513 INTEL_FIREVERTICES(intel
);
515 if (intel
->batch
->map
!= intel
->batch
->ptr
)
516 intel_batchbuffer_flush(intel
->batch
);
520 intel_glFlush(GLcontext
*ctx
)
522 struct intel_context
*intel
= intel_context(ctx
);
526 intel_flush_front(ctx
);
528 /* We're using glFlush as an indicator that a frame is done, which is
529 * what DRI2 does before calling SwapBuffers (and means we should catch
530 * people doing front-buffer rendering, as well)..
532 * Wait for the swapbuffers before the one we just emitted, so we don't
533 * get too many swaps outstanding for apps that are GPU-heavy but not
536 * Unfortunately, we don't have a handle to the batch containing the swap,
537 * and getting our hands on that doesn't seem worth it, so we just us the
538 * first batch we emitted after the last swap.
540 if (!intel
->using_dri2_swapbuffers
&&
541 intel
->first_post_swapbuffers_batch
!= NULL
) {
542 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
543 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
544 intel
->first_post_swapbuffers_batch
= NULL
;
549 intelFinish(GLcontext
* ctx
)
551 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
556 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
557 struct intel_renderbuffer
*irb
;
559 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
561 if (irb
&& irb
->region
)
562 dri_bo_wait_rendering(irb
->region
->buffer
);
564 if (fb
->_DepthBuffer
) {
565 /* XXX: Wait on buffer idle */
570 intelInitDriverFunctions(struct dd_function_table
*functions
)
572 _mesa_init_driver_functions(functions
);
574 functions
->Flush
= intel_glFlush
;
575 functions
->Finish
= intelFinish
;
576 functions
->GetString
= intelGetString
;
577 functions
->UpdateState
= intelInvalidateState
;
579 intelInitTextureFuncs(functions
);
580 intelInitTextureImageFuncs(functions
);
581 intelInitTextureSubImageFuncs(functions
);
582 intelInitTextureCopyImageFuncs(functions
);
583 intelInitStateFuncs(functions
);
584 intelInitClearFuncs(functions
);
585 intelInitBufferFuncs(functions
);
586 intelInitPixelFuncs(functions
);
587 intelInitBufferObjectFuncs(functions
);
588 intel_init_syncobj_functions(functions
);
593 intelInitContext(struct intel_context
*intel
,
595 const __GLcontextModes
* mesaVis
,
596 __DRIcontext
* driContextPriv
,
597 void *sharedContextPrivate
,
598 struct dd_function_table
*functions
)
600 GLcontext
*ctx
= &intel
->ctx
;
601 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
602 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
603 struct intel_screen
*intelScreen
= sPriv
->private;
606 /* we can't do anything without a connection to the device */
607 if (intelScreen
->bufmgr
== NULL
)
610 if (!_mesa_initialize_context_for_api(&intel
->ctx
, api
, mesaVis
, shareCtx
,
611 functions
, (void *) intel
)) {
612 printf("%s: failed to init mesa context\n", __FUNCTION__
);
616 driContextPriv
->driverPrivate
= intel
;
617 intel
->intelScreen
= intelScreen
;
618 intel
->driContext
= driContextPriv
;
619 intel
->driFd
= sPriv
->fd
;
621 if (IS_GEN6(intel
->intelScreen
->deviceID
)) {
623 intel
->needs_ff_sync
= GL_TRUE
;
624 intel
->has_luminance_srgb
= GL_TRUE
;
625 } else if (IS_GEN5(intel
->intelScreen
->deviceID
)) {
627 intel
->needs_ff_sync
= GL_TRUE
;
628 intel
->has_luminance_srgb
= GL_TRUE
;
629 } else if (IS_965(intel
->intelScreen
->deviceID
)) {
631 if (IS_G4X(intel
->intelScreen
->deviceID
)) {
632 intel
->has_luminance_srgb
= GL_TRUE
;
633 intel
->is_g4x
= GL_TRUE
;
635 } else if (IS_9XX(intel
->intelScreen
->deviceID
)) {
637 if (IS_945(intel
->intelScreen
->deviceID
)) {
638 intel
->is_945
= GL_TRUE
;
644 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
645 sPriv
->myNum
, (intel
->gen
>= 4) ? "i965" : "i915");
646 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
647 intel
->maxBatchSize
= 4096;
649 intel
->maxBatchSize
= BATCH_SZ
;
651 intel
->bufmgr
= intelScreen
->bufmgr
;
653 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
654 switch (bo_reuse_mode
) {
655 case DRI_CONF_BO_REUSE_DISABLED
:
657 case DRI_CONF_BO_REUSE_ALL
:
658 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
662 /* This doesn't yet catch all non-conformant rendering, but it's a
665 if (getenv("INTEL_STRICT_CONFORMANCE")) {
666 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
668 intel
->conformance_mode
= value
;
671 intel
->conformance_mode
= 1;
675 if (intel
->conformance_mode
> 0) {
676 ctx
->Const
.MinLineWidth
= 1.0;
677 ctx
->Const
.MinLineWidthAA
= 1.0;
678 ctx
->Const
.MaxLineWidth
= 1.0;
679 ctx
->Const
.MaxLineWidthAA
= 1.0;
680 ctx
->Const
.LineWidthGranularity
= 1.0;
683 ctx
->Const
.MinLineWidth
= 1.0;
684 ctx
->Const
.MinLineWidthAA
= 1.0;
685 ctx
->Const
.MaxLineWidth
= 5.0;
686 ctx
->Const
.MaxLineWidthAA
= 5.0;
687 ctx
->Const
.LineWidthGranularity
= 0.5;
690 ctx
->Const
.MinPointSize
= 1.0;
691 ctx
->Const
.MinPointSizeAA
= 1.0;
692 ctx
->Const
.MaxPointSize
= 255.0;
693 ctx
->Const
.MaxPointSizeAA
= 3.0;
694 ctx
->Const
.PointSizeGranularity
= 1.0;
696 /* reinitialize the context point state.
697 * It depend on constants in __GLcontextRec::Const
699 _mesa_init_point(ctx
);
701 meta_init_metaops(ctx
, &intel
->meta
);
702 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
703 if (intel
->gen
>= 4) {
704 if (MAX_WIDTH
> 8192)
705 ctx
->Const
.MaxRenderbufferSize
= 8192;
707 if (MAX_WIDTH
> 2048)
708 ctx
->Const
.MaxRenderbufferSize
= 2048;
711 /* Initialize the software rasterizer and helper modules. */
712 _swrast_CreateContext(ctx
);
713 _vbo_CreateContext(ctx
);
714 _tnl_CreateContext(ctx
);
715 _swsetup_CreateContext(ctx
);
717 /* Configure swrast to match hardware characteristics: */
718 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
719 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
721 _mesa_meta_init(ctx
);
723 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
724 intel
->hw_stipple
= 1;
726 /* XXX FBO: this doesn't seem to be used anywhere */
727 switch (mesaVis
->depthBits
) {
728 case 0: /* what to do in this case? */
730 intel
->polygon_offset_scale
= 1.0;
733 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
741 intel
->polygon_offset_scale
/= 0xffff;
743 intel
->RenderIndex
= ~0;
747 intelInitExtensions(ctx
);
752 intelInitExtensionsES2(ctx
);
756 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
757 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
758 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
760 intel
->batch
= intel_batchbuffer_alloc(intel
);
762 intel_fbo_init(intel
);
764 if (intel
->ctx
.Mesa_DXTn
) {
765 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
766 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
768 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
769 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
771 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
773 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
775 intel
->prim
.primitive
= ~0;
777 /* Force all software fallbacks */
778 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
779 fprintf(stderr
, "disabling 3D rasterization\n");
783 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
784 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
785 intel
->always_flush_batch
= 1;
788 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
789 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
790 intel
->always_flush_cache
= 1;
793 /* Disable all hardware rendering (skip emitting batches and fences/waits
796 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
802 intelDestroyContext(__DRIcontext
* driContextPriv
)
804 struct intel_context
*intel
=
805 (struct intel_context
*) driContextPriv
->driverPrivate
;
807 assert(intel
); /* should never be null */
809 GLboolean release_texture_heaps
;
811 INTEL_FIREVERTICES(intel
);
813 _mesa_meta_free(&intel
->ctx
);
815 meta_destroy_metaops(&intel
->meta
);
817 intel
->vtbl
.destroy(intel
);
819 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
820 _swsetup_DestroyContext(&intel
->ctx
);
821 _tnl_DestroyContext(&intel
->ctx
);
822 _vbo_DestroyContext(&intel
->ctx
);
824 _swrast_DestroyContext(&intel
->ctx
);
825 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
827 intel_batchbuffer_free(intel
->batch
);
830 free(intel
->prim
.vb
);
831 intel
->prim
.vb
= NULL
;
832 dri_bo_unreference(intel
->prim
.vb_bo
);
833 intel
->prim
.vb_bo
= NULL
;
834 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
835 intel
->first_post_swapbuffers_batch
= NULL
;
837 if (release_texture_heaps
) {
838 /* Nothing is currently done here to free texture heaps;
839 * but we're not using the texture heap utilities, so I
840 * rather think we shouldn't. I've taken a look, and can't
841 * find any private texture data hanging around anywhere, but
842 * I'm not yet certain there isn't any at all...
844 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
845 fprintf(stderr, "do something to free texture heaps\n");
849 driDestroyOptionCache(&intel
->optionCache
);
851 /* free the Mesa context */
852 _mesa_free_context_data(&intel
->ctx
);
855 driContextPriv
->driverPrivate
= NULL
;
860 intelUnbindContext(__DRIcontext
* driContextPriv
)
866 intelMakeCurrent(__DRIcontext
* driContextPriv
,
867 __DRIdrawable
* driDrawPriv
,
868 __DRIdrawable
* driReadPriv
)
870 struct intel_context
*intel
;
871 GET_CURRENT_CONTEXT(curCtx
);
874 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
878 /* According to the glXMakeCurrent() man page: "Pending commands to
879 * the previous context, if any, are flushed before it is released."
880 * But only flush if we're actually changing contexts.
882 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
886 if (driContextPriv
) {
887 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
888 struct gl_framebuffer
*readFb
= driReadPriv
->driverPrivate
;
890 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
891 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
892 intel_prepare_render(intel
);
893 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
896 _mesa_make_current(NULL
, NULL
, NULL
);