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 **************************************************************************/
32 #include "simple_list.h"
33 #include "extensions.h"
34 #include "framebuffer.h"
38 #include "swrast/swrast.h"
39 #include "swrast_setup/swrast_setup.h"
42 #include "tnl/t_pipeline.h"
43 #include "tnl/t_vertex.h"
45 #include "drivers/common/driverfuncs.h"
47 #include "intel_screen.h"
51 #include "intel_chipset.h"
52 #include "intel_buffers.h"
53 #include "intel_tex.h"
54 #include "intel_ioctl.h"
55 #include "intel_batchbuffer.h"
56 #include "intel_blit.h"
57 #include "intel_pixel.h"
58 #include "intel_regions.h"
59 #include "intel_buffer_objects.h"
60 #include "intel_fbo.h"
61 #include "intel_decode.h"
62 #include "intel_bufmgr_ttm.h"
64 #include "drirenderbuffer.h"
67 #include "xmlpool.h" /* for symbolic values of enum-type options */
69 int INTEL_DEBUG
= (0);
72 #define need_GL_NV_point_sprite
73 #define need_GL_ARB_multisample
74 #define need_GL_ARB_point_parameters
75 #define need_GL_ARB_texture_compression
76 #define need_GL_ARB_vertex_buffer_object
77 #define need_GL_ARB_vertex_program
78 #define need_GL_ARB_window_pos
79 #define need_GL_ARB_occlusion_query
80 #define need_GL_EXT_blend_color
81 #define need_GL_EXT_blend_equation_separate
82 #define need_GL_EXT_blend_func_separate
83 #define need_GL_EXT_blend_minmax
84 #define need_GL_EXT_cull_vertex
85 #define need_GL_EXT_fog_coord
86 #define need_GL_EXT_framebuffer_object
87 #define need_GL_EXT_multi_draw_arrays
88 #define need_GL_EXT_secondary_color
89 #define need_GL_NV_vertex_program
90 #define need_GL_ATI_separate_stencil
91 #define need_GL_EXT_point_parameters
92 #define need_GL_VERSION_2_0
93 #define need_GL_VERSION_2_1
94 #define need_GL_ARB_shader_objects
95 #define need_GL_ARB_vertex_shader
97 #include "extension_helper.h"
99 #define DRIVER_DATE "20061102"
101 static const GLubyte
*
102 intelGetString(GLcontext
* ctx
, GLenum name
)
105 static char buffer
[128];
109 return (GLubyte
*) "Tungsten Graphics, Inc";
113 switch (intel_context(ctx
)->intelScreen
->deviceID
) {
115 chipset
= "Intel(R) 845G";
117 case PCI_CHIP_I830_M
:
118 chipset
= "Intel(R) 830M";
120 case PCI_CHIP_I855_GM
:
121 chipset
= "Intel(R) 852GM/855GM";
123 case PCI_CHIP_I865_G
:
124 chipset
= "Intel(R) 865G";
126 case PCI_CHIP_I915_G
:
127 chipset
= "Intel(R) 915G";
129 case PCI_CHIP_E7221_G
:
130 chipset
= "Intel (R) E7221G (i915)";
132 case PCI_CHIP_I915_GM
:
133 chipset
= "Intel(R) 915GM";
135 case PCI_CHIP_I945_G
:
136 chipset
= "Intel(R) 945G";
138 case PCI_CHIP_I945_GM
:
139 chipset
= "Intel(R) 945GM";
141 case PCI_CHIP_I945_GME
:
142 chipset
= "Intel(R) 945GME";
145 chipset
= "Intel(R) G33";
148 chipset
= "Intel(R) Q35";
151 chipset
= "Intel(R) Q33";
153 case PCI_CHIP_I965_Q
:
154 chipset
= "Intel(R) 965Q";
156 case PCI_CHIP_I965_G
:
157 case PCI_CHIP_I965_G_1
:
158 chipset
= "Intel(R) 965G";
160 case PCI_CHIP_I946_GZ
:
161 chipset
= "Intel(R) 946GZ";
163 case PCI_CHIP_I965_GM
:
164 chipset
= "Intel(R) 965GM";
166 case PCI_CHIP_I965_GME
:
167 chipset
= "Intel(R) 965GME/GLE";
169 case PCI_CHIP_IGD_GM
:
170 chipset
= "Intel(R) Integrated Graphics Device";
173 chipset
= "Unknown Intel Chipset";
177 (void) driGetRendererString(buffer
, chipset
, DRIVER_DATE
, 0);
178 return (GLubyte
*) buffer
;
186 * Extension strings exported by the intel driver.
189 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
190 * old i830-specific driver.
192 const struct dri_extension card_extensions
[] = {
193 {"GL_ARB_multisample", GL_ARB_multisample_functions
},
194 {"GL_ARB_multitexture", NULL
},
195 {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
196 {"GL_NV_point_sprite", GL_NV_point_sprite_functions
},
197 {"GL_ARB_texture_border_clamp", NULL
},
198 {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
199 {"GL_ARB_texture_cube_map", NULL
},
200 {"GL_ARB_texture_env_add", NULL
},
201 {"GL_ARB_texture_env_combine", NULL
},
202 {"GL_ARB_texture_env_dot3", NULL
},
203 {"GL_ARB_texture_mirrored_repeat", NULL
},
204 {"GL_ARB_texture_non_power_of_two", NULL
},
205 {"GL_ARB_texture_rectangle", NULL
},
206 {"GL_NV_texture_rectangle", NULL
},
207 {"GL_EXT_texture_rectangle", NULL
},
208 {"GL_ARB_point_sprite", NULL
},
209 {"GL_ARB_point_parameters", NULL
},
210 {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
211 {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
212 {"GL_ARB_window_pos", GL_ARB_window_pos_functions
},
213 {"GL_EXT_blend_color", GL_EXT_blend_color_functions
},
214 {"GL_EXT_blend_equation_separate",
215 GL_EXT_blend_equation_separate_functions
},
216 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
217 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
218 {"GL_EXT_blend_logic_op", NULL
},
219 {"GL_EXT_blend_subtract", NULL
},
220 {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions
},
221 {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
222 {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
223 {"GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions
},
224 #if 1 /* XXX FBO temporary? */
225 {"GL_EXT_packed_depth_stencil", NULL
},
227 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
228 {"GL_EXT_stencil_wrap", NULL
},
229 {"GL_EXT_texture_edge_clamp", NULL
},
230 {"GL_EXT_texture_env_combine", NULL
},
231 {"GL_EXT_texture_env_dot3", NULL
},
232 {"GL_EXT_texture_filter_anisotropic", NULL
},
233 {"GL_EXT_texture_lod_bias", NULL
},
234 {"GL_EXT_texture_sRGB", NULL
},
235 {"GL_3DFX_texture_compression_FXT1", NULL
},
236 {"GL_APPLE_client_storage", NULL
},
237 {"GL_MESA_pack_invert", NULL
},
238 {"GL_MESA_ycbcr_texture", NULL
},
239 {"GL_NV_blend_square", NULL
},
240 {"GL_NV_vertex_program", GL_NV_vertex_program_functions
},
241 {"GL_NV_vertex_program1_1", NULL
},
242 { "GL_SGIS_generate_mipmap", NULL
},
246 const struct dri_extension brw_extensions
[] = {
247 { "GL_ARB_shading_language_100", GL_VERSION_2_0_functions
},
248 { "GL_ARB_shading_language_120", GL_VERSION_2_1_functions
},
249 { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions
},
250 { "GL_ARB_vertex_shader", GL_ARB_vertex_shader_functions
},
251 { "GL_ARB_fragment_shader", NULL
},
252 { "GL_ARB_draw_buffers", NULL
},
256 const struct dri_extension arb_oc_extensions
[] = {
257 {"GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
},
261 const struct dri_extension ttm_extensions
[] = {
262 {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions
},
263 {"GL_ARB_pixel_buffer_object", NULL
},
268 * Initializes potential list of extensions if ctx == NULL, or actually enables
269 * extensions for a context.
271 static void intelInitExtensions(GLcontext
*ctx
, GLboolean enable_imaging
)
273 struct intel_context
*intel
= ctx
?intel_context(ctx
):NULL
;
275 /* Disable imaging extension until convolution is working in teximage paths.
277 enable_imaging
= GL_FALSE
;
279 driInitExtensions(ctx
, card_extensions
, enable_imaging
);
281 if (intel
== NULL
|| intel
->ttm
)
282 driInitExtensions(ctx
, ttm_extensions
, GL_FALSE
);
285 (IS_965(intel
->intelScreen
->deviceID
) &&
286 intel
->intelScreen
->drmMinor
>= 8))
287 driInitExtensions(ctx
, arb_oc_extensions
, GL_FALSE
);
289 if (intel
== NULL
|| IS_965(intel
->intelScreen
->deviceID
))
290 driInitExtensions(ctx
, brw_extensions
, GL_FALSE
);
293 static const struct dri_debug_control debug_control
[] = {
294 { "tex", DEBUG_TEXTURE
},
295 { "state", DEBUG_STATE
},
296 { "ioctl", DEBUG_IOCTL
},
297 { "blit", DEBUG_BLIT
},
298 { "mip", DEBUG_MIPTREE
},
299 { "fall", DEBUG_FALLBACKS
},
300 { "verb", DEBUG_VERBOSE
},
301 { "bat", DEBUG_BATCH
},
302 { "pix", DEBUG_PIXEL
},
303 { "buf", DEBUG_BUFMGR
},
304 { "reg", DEBUG_REGION
},
306 { "lock", DEBUG_LOCK
},
307 { "sync", DEBUG_SYNC
},
308 { "prim", DEBUG_PRIMS
},
309 { "vert", DEBUG_VERTS
},
310 { "dri", DEBUG_DRI
},
311 { "dma", DEBUG_DMA
},
312 { "san", DEBUG_SANITY
},
313 { "sleep", DEBUG_SLEEP
},
314 { "stats", DEBUG_STATS
},
315 { "tile", DEBUG_TILE
},
316 { "sing", DEBUG_SINGLE_THREAD
},
317 { "thre", DEBUG_SINGLE_THREAD
},
319 { "urb", DEBUG_URB
},
326 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
328 struct intel_context
*intel
= intel_context(ctx
);
330 _swrast_InvalidateState(ctx
, new_state
);
331 _swsetup_InvalidateState(ctx
, new_state
);
332 _vbo_InvalidateState(ctx
, new_state
);
333 _tnl_InvalidateState(ctx
, new_state
);
334 _tnl_invalidate_vertex_state(ctx
, new_state
);
336 intel
->NewGLState
|= new_state
;
338 if (intel
->vtbl
.invalidate_state
)
339 intel
->vtbl
.invalidate_state( intel
, new_state
);
344 intelFlush(GLcontext
* ctx
)
346 struct intel_context
*intel
= intel_context(ctx
);
351 if (!IS_965(intel
->intelScreen
->deviceID
))
352 INTEL_FIREVERTICES(intel
);
354 if (intel
->batch
->map
!= intel
->batch
->ptr
)
355 intel_batchbuffer_flush(intel
->batch
);
357 /* XXX: Need to do an MI_FLUSH here.
362 intelFinish(GLcontext
* ctx
)
364 struct intel_context
*intel
= intel_context(ctx
);
366 if (intel
->batch
->last_fence
) {
367 dri_fence_wait(intel
->batch
->last_fence
);
368 dri_fence_unreference(intel
->batch
->last_fence
);
369 intel
->batch
->last_fence
= NULL
;
374 intelBeginQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
376 struct intel_context
*intel
= intel_context( ctx
);
377 struct drm_i915_mmio io
= {
378 .read_write
= I915_MMIO_READ
,
379 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
383 intelFinish(&intel
->ctx
);
384 drmCommandWrite(intel
->driFd
, DRM_I915_MMIO
, &io
, sizeof(io
));
388 intelEndQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
390 struct intel_context
*intel
= intel_context( ctx
);
392 struct drm_i915_mmio io
= {
393 .read_write
= I915_MMIO_READ
,
394 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
397 intelFinish(&intel
->ctx
);
398 drmCommandWrite(intel
->driFd
, DRM_I915_MMIO
, &io
, sizeof(io
));
399 q
->Result
= tmp
- q
->Result
;
404 /** Driver-specific fence emit implementation for the fake memory manager. */
406 intel_fence_emit(void *private)
408 struct intel_context
*intel
= (struct intel_context
*)private;
411 /* XXX: Need to emit a flush, if we haven't already (at least with the
412 * current batchbuffer implementation, we have).
415 fence
= intelEmitIrqLocked(intel
);
420 /** Driver-specific fence wait implementation for the fake memory manager. */
422 intel_fence_wait(void *private, unsigned int cookie
)
424 struct intel_context
*intel
= (struct intel_context
*)private;
426 intelWaitIrq(intel
, cookie
);
432 intel_init_bufmgr(struct intel_context
*intel
)
434 intelScreenPrivate
*intelScreen
= intel
->intelScreen
;
435 GLboolean ttm_disable
= getenv("INTEL_NO_TTM") != NULL
;
437 /* If we've got a new enough DDX that's initializing TTM and giving us
438 * object handles for the shared buffers, use that.
440 intel
->ttm
= GL_FALSE
;
442 intel
->intelScreen
->driScrnPriv
->ddx_version
.minor
>= 9 &&
443 intel
->intelScreen
->drmMinor
>= 11 &&
444 intel
->intelScreen
->front
.bo_handle
!= -1)
446 intel
->bufmgr
= intel_bufmgr_ttm_init(intel
->driFd
,
449 DRM_I915_FENCE_TYPE_RW
,
451 if (intel
->bufmgr
!= NULL
)
452 intel
->ttm
= GL_TRUE
;
454 /* Otherwise, use the classic buffer manager. */
455 if (intel
->bufmgr
== NULL
) {
457 fprintf(stderr
, "TTM buffer manager disabled. Using classic.\n");
459 fprintf(stderr
, "Failed to initialize TTM buffer manager. "
460 "Falling back to classic.\n");
463 if (intelScreen
->tex
.size
== 0) {
464 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
469 intel
->bufmgr
= dri_bufmgr_fake_init(intelScreen
->tex
.offset
,
470 intelScreen
->tex
.map
,
471 intelScreen
->tex
.size
,
481 intelInitDriverFunctions(struct dd_function_table
*functions
)
483 _mesa_init_driver_functions(functions
);
485 functions
->Flush
= intelFlush
;
486 functions
->Finish
= intelFinish
;
487 functions
->GetString
= intelGetString
;
488 functions
->UpdateState
= intelInvalidateState
;
490 functions
->CopyColorTable
= _swrast_CopyColorTable
;
491 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
492 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
493 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
495 functions
->BeginQuery
= intelBeginQuery
;
496 functions
->EndQuery
= intelEndQuery
;
498 intelInitTextureFuncs(functions
);
499 intelInitStateFuncs(functions
);
500 intelInitBufferFuncs(functions
);
505 intelInitContext(struct intel_context
*intel
,
506 const __GLcontextModes
* mesaVis
,
507 __DRIcontextPrivate
* driContextPriv
,
508 void *sharedContextPrivate
,
509 struct dd_function_table
*functions
)
511 GLcontext
*ctx
= &intel
->ctx
;
512 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
513 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
514 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
515 volatile struct drm_i915_sarea
*saPriv
= (struct drm_i915_sarea
*)
516 (((GLubyte
*) sPriv
->pSAREA
) + intelScreen
->sarea_priv_offset
);
519 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
520 functions
, (void *) intel
)) {
521 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
525 driContextPriv
->driverPrivate
= intel
;
526 intel
->intelScreen
= intelScreen
;
527 intel
->driScreen
= sPriv
;
528 intel
->sarea
= saPriv
;
531 intel
->hHWContext
= driContextPriv
->hHWContext
;
532 intel
->driFd
= sPriv
->fd
;
533 intel
->driHwLock
= sPriv
->lock
;
535 intel
->width
= intelScreen
->width
;
536 intel
->height
= intelScreen
->height
;
538 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
539 intel
->maxBatchSize
= 4096;
541 intel
->maxBatchSize
= BATCH_SZ
;
543 if (!intel_init_bufmgr(intel
))
546 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
547 intel
->driScreen
->myNum
,
548 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
550 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
552 /* This doesn't yet catch all non-conformant rendering, but it's a
555 if (getenv("INTEL_STRICT_CONFORMANCE")) {
556 intel
->strict_conformance
= 1;
559 if (intel
->strict_conformance
) {
560 ctx
->Const
.MinLineWidth
= 1.0;
561 ctx
->Const
.MinLineWidthAA
= 1.0;
562 ctx
->Const
.MaxLineWidth
= 1.0;
563 ctx
->Const
.MaxLineWidthAA
= 1.0;
564 ctx
->Const
.LineWidthGranularity
= 1.0;
567 ctx
->Const
.MinLineWidth
= 1.0;
568 ctx
->Const
.MinLineWidthAA
= 1.0;
569 ctx
->Const
.MaxLineWidth
= 5.0;
570 ctx
->Const
.MaxLineWidthAA
= 5.0;
571 ctx
->Const
.LineWidthGranularity
= 0.5;
574 ctx
->Const
.MinPointSize
= 1.0;
575 ctx
->Const
.MinPointSizeAA
= 1.0;
576 ctx
->Const
.MaxPointSize
= 255.0;
577 ctx
->Const
.MaxPointSizeAA
= 3.0;
578 ctx
->Const
.PointSizeGranularity
= 1.0;
580 /* reinitialize the context point state.
581 * It depend on constants in __GLcontextRec::Const
583 _mesa_init_point(ctx
);
585 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
587 /* Initialize the software rasterizer and helper modules. */
588 _swrast_CreateContext(ctx
);
589 _vbo_CreateContext(ctx
);
590 _tnl_CreateContext(ctx
);
591 _swsetup_CreateContext(ctx
);
593 /* Configure swrast to match hardware characteristics: */
594 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
595 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
597 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
598 intel
->hw_stipple
= 1;
600 /* XXX FBO: this doesn't seem to be used anywhere */
601 switch (mesaVis
->depthBits
) {
602 case 0: /* what to do in this case? */
604 intel
->polygon_offset_scale
= 1.0;
607 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
614 if (IS_965(intelScreen
->deviceID
))
615 intel
->polygon_offset_scale
/= 0xffff;
617 intel
->RenderIndex
= ~0;
619 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
620 intel
->irqsEmitted
= 0;
622 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
623 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
625 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
627 _math_matrix_ctr(&intel
->ViewportMatrix
);
629 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
630 _mesa_printf("IRQs not active. Exiting\n");
634 intelInitExtensions(ctx
, GL_FALSE
);
636 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
637 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
638 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
640 if (!sPriv
->dri2
.enabled
)
641 intel_recreate_static_regions(intel
);
643 intel
->batch
= intel_batchbuffer_alloc(intel
);
644 intel
->last_swap_fence
= NULL
;
645 intel
->first_swap_fence
= NULL
;
647 intel_bufferobj_init(intel
);
648 intel_fbo_init(intel
);
650 if (intel
->ctx
.Mesa_DXTn
) {
651 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
652 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
654 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
655 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
658 intel
->prim
.primitive
= ~0;
660 /* Force all software fallbacks */
661 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
662 fprintf(stderr
, "disabling 3D rasterization\n");
663 FALLBACK(intel
, INTEL_FALLBACK_USER
, 1);
667 /* Disable all hardware rendering (skip emitting batches and fences/waits
670 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
676 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
678 struct intel_context
*intel
=
679 (struct intel_context
*) driContextPriv
->driverPrivate
;
681 assert(intel
); /* should never be null */
683 GLboolean release_texture_heaps
;
685 INTEL_FIREVERTICES(intel
);
687 intel
->vtbl
.destroy(intel
);
689 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
690 _swsetup_DestroyContext(&intel
->ctx
);
691 _tnl_DestroyContext(&intel
->ctx
);
692 _vbo_DestroyContext(&intel
->ctx
);
694 _swrast_DestroyContext(&intel
->ctx
);
695 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
697 intel_batchbuffer_free(intel
->batch
);
699 if (intel
->last_swap_fence
) {
700 dri_fence_wait(intel
->last_swap_fence
);
701 dri_fence_unreference(intel
->last_swap_fence
);
702 intel
->last_swap_fence
= NULL
;
704 if (intel
->first_swap_fence
) {
705 dri_fence_wait(intel
->first_swap_fence
);
706 dri_fence_unreference(intel
->first_swap_fence
);
707 intel
->first_swap_fence
= NULL
;
710 if (release_texture_heaps
) {
711 /* This share group is about to go away, free our private
712 * texture object data.
714 if (INTEL_DEBUG
& DEBUG_TEXTURE
)
715 fprintf(stderr
, "do something to free texture heaps\n");
718 /* free the Mesa context */
719 _mesa_free_context_data(&intel
->ctx
);
721 dri_bufmgr_destroy(intel
->bufmgr
);
726 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
732 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
733 __DRIdrawablePrivate
* driDrawPriv
,
734 __DRIdrawablePrivate
* driReadPriv
)
737 if (driContextPriv
) {
738 struct intel_context
*intel
=
739 (struct intel_context
*) driContextPriv
->driverPrivate
;
740 struct intel_framebuffer
*intel_fb
=
741 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
742 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
745 /* XXX FBO temporary fix-ups! */
746 /* if the renderbuffers don't have regions, init them from the context */
747 if (!driContextPriv
->driScreenPriv
->dri2
.enabled
) {
748 struct intel_renderbuffer
*irbDepth
749 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
750 struct intel_renderbuffer
*irbStencil
751 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
753 if (intel_fb
->color_rb
[0]) {
754 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
755 intel
->front_region
);
757 if (intel_fb
->color_rb
[1]) {
758 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
762 if (intel_fb
->color_rb
[2]) {
763 intel_renderbuffer_set_region(intel_fb
->color_rb
[2],
764 intel
->third_region
);
768 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
771 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
775 /* set GLframebuffer size to match window, if needed */
776 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
778 if (driReadPriv
!= driDrawPriv
) {
779 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
782 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
784 /* The drawbuffer won't always be updated by _mesa_make_current:
786 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
788 if (intel
->driReadDrawable
!= driReadPriv
)
789 intel
->driReadDrawable
= driReadPriv
;
791 if (intel
->driDrawable
!= driDrawPriv
) {
792 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
795 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
796 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
797 : VBLANK_FLAG_NO_IRQ
;
799 (*dri_interface
->getUST
) (&intel_fb
->swap_ust
);
800 driDrawableInitVBlank(driDrawPriv
);
801 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
803 for (i
= 0; i
< (intel
->intelScreen
->third
.handle
? 3 : 2); i
++) {
804 if (intel_fb
->color_rb
[i
])
805 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
808 intel
->driDrawable
= driDrawPriv
;
809 intelWindowMoved(intel
);
812 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
816 _mesa_make_current(NULL
, NULL
, NULL
);
823 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
825 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
826 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
827 volatile struct drm_i915_sarea
*sarea
= intel
->sarea
;
828 int drawable_changed
= 0;
829 int me
= intel
->hHWContext
;
831 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
833 if (INTEL_DEBUG
& DEBUG_LOCK
)
834 _mesa_printf("%s - got contended lock\n", __progname
);
836 /* If the window moved, may need to set a new cliprect now.
838 * NOTE: This releases and regains the hw lock, so all state
839 * checking must be done *after* this call:
842 if (sPriv
->dri2
.enabled
)
843 drawable_changed
= __driParseEvents(sPriv
, dPriv
);
845 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
848 if (sarea
&& sarea
->ctxOwner
!= me
) {
849 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
850 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
851 sarea
->ctxOwner
, me
);
853 sarea
->ctxOwner
= me
;
856 /* If the last consumer of the texture memory wasn't us, notify the fake
857 * bufmgr and record the new owner. We should have the memory shared
858 * between contexts of a single fake bufmgr, but this will at least make
859 * things correct for now.
861 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
862 sarea
->texAge
= intel
->hHWContext
;
863 dri_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
864 if (INTEL_DEBUG
& DEBUG_BATCH
)
865 intel_decode_context_reset();
866 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
867 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
868 sarea
->ctxOwner
, intel
->hHWContext
);
871 if (!sPriv
->dri2
.enabled
) {
872 if (sarea
->width
!= intel
->width
|| sarea
->height
!= intel
->height
) {
873 int numClipRects
= intel
->numClipRects
;
876 * FIXME: Really only need to do this when drawing to a
877 * common back- or front buffer.
881 * This will essentially drop the outstanding batchbuffer on
884 intel
->numClipRects
= 0;
887 _swrast_flush(&intel
->ctx
);
889 if (!IS_965(intel
->intelScreen
->deviceID
))
890 INTEL_FIREVERTICES(intel
);
892 if (intel
->batch
->map
!= intel
->batch
->ptr
)
893 intel_batchbuffer_flush(intel
->batch
);
895 intel
->numClipRects
= numClipRects
;
897 /* force window update */
898 intel
->lastStamp
= 0;
900 intel
->width
= sarea
->width
;
901 intel
->height
= sarea
->height
;
906 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
907 intelWindowMoved(intel
);
908 intel
->lastStamp
= dPriv
->lastStamp
;
910 } else if (drawable_changed
) {
911 intelWindowMoved(intel
);
912 intel_draw_buffer(&intel
->ctx
, intel
->ctx
.DrawBuffer
);
917 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
919 /* Lock the hardware and validate our state.
921 void LOCK_HARDWARE( struct intel_context
*intel
)
923 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
925 struct intel_framebuffer
*intel_fb
= NULL
;
926 struct intel_renderbuffer
*intel_rb
= NULL
;
928 _glthread_LOCK_MUTEX(lockMutex
);
929 assert(!intel
->locked
);
931 if (intel
->driDrawable
) {
932 intel_fb
= intel
->driDrawable
->driverPrivate
;
936 intel_get_renderbuffer(&intel_fb
->Base
,
937 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
940 if (intel_rb
&& dPriv
->vblFlags
&&
941 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
942 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
945 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
947 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
948 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
951 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
952 drmWaitVBlank(intel
->driFd
, &vbl
);
953 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
956 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
957 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
960 intelContendedLock( intel
, 0 );
963 if (INTEL_DEBUG
& DEBUG_LOCK
)
964 _mesa_printf("%s - locked\n", __progname
);
968 /* Unlock the hardware using the global current context
970 void UNLOCK_HARDWARE( struct intel_context
*intel
)
974 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
976 _glthread_UNLOCK_MUTEX(lockMutex
);
978 if (INTEL_DEBUG
& DEBUG_LOCK
)
979 _mesa_printf("%s - unlocked\n", __progname
);
982 * Nothing should be left in batch outside of LOCK/UNLOCK which references
985 assert(intel
->batch
->cliprect_mode
!= REFERENCES_CLIPRECTS
);