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/matrix.h"
32 #include "main/simple_list.h"
33 #include "main/extensions.h"
34 #include "main/framebuffer.h"
35 #include "main/imports.h"
36 #include "main/points.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_batchbuffer.h"
55 #include "intel_blit.h"
56 #include "intel_pixel.h"
57 #include "intel_regions.h"
58 #include "intel_buffer_objects.h"
59 #include "intel_fbo.h"
60 #include "intel_decode.h"
61 #include "intel_bufmgr.h"
63 #include "drirenderbuffer.h"
66 #include "xmlpool.h" /* for symbolic values of enum-type options */
68 int INTEL_DEBUG
= (0);
71 #define need_GL_NV_point_sprite
72 #define need_GL_ARB_multisample
73 #define need_GL_ARB_point_parameters
74 #define need_GL_ARB_texture_compression
75 #define need_GL_ARB_vertex_buffer_object
76 #define need_GL_ARB_vertex_program
77 #define need_GL_ARB_window_pos
78 #define need_GL_ARB_occlusion_query
79 #define need_GL_EXT_blend_color
80 #define need_GL_EXT_blend_equation_separate
81 #define need_GL_EXT_blend_func_separate
82 #define need_GL_EXT_blend_minmax
83 #define need_GL_EXT_cull_vertex
84 #define need_GL_EXT_fog_coord
85 #define need_GL_EXT_framebuffer_object
86 #define need_GL_EXT_multi_draw_arrays
87 #define need_GL_EXT_secondary_color
88 #define need_GL_NV_vertex_program
89 #define need_GL_ATI_separate_stencil
90 #define need_GL_EXT_point_parameters
91 #define need_GL_VERSION_2_0
92 #define need_GL_VERSION_2_1
93 #define need_GL_ARB_shader_objects
94 #define need_GL_ARB_vertex_shader
96 #include "extension_helper.h"
98 #define DRIVER_DATE "20080716"
99 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
101 static const GLubyte
*
102 intelGetString(GLcontext
* ctx
, GLenum name
)
104 const struct intel_context
*const intel
= intel_context(ctx
);
106 static char buffer
[128];
110 return (GLubyte
*) "Tungsten Graphics, Inc";
114 switch (intel
->intelScreen
->deviceID
) {
116 chipset
= "Intel(R) 845G";
118 case PCI_CHIP_I830_M
:
119 chipset
= "Intel(R) 830M";
121 case PCI_CHIP_I855_GM
:
122 chipset
= "Intel(R) 852GM/855GM";
124 case PCI_CHIP_I865_G
:
125 chipset
= "Intel(R) 865G";
127 case PCI_CHIP_I915_G
:
128 chipset
= "Intel(R) 915G";
130 case PCI_CHIP_E7221_G
:
131 chipset
= "Intel (R) E7221G (i915)";
133 case PCI_CHIP_I915_GM
:
134 chipset
= "Intel(R) 915GM";
136 case PCI_CHIP_I945_G
:
137 chipset
= "Intel(R) 945G";
139 case PCI_CHIP_I945_GM
:
140 chipset
= "Intel(R) 945GM";
142 case PCI_CHIP_I945_GME
:
143 chipset
= "Intel(R) 945GME";
146 chipset
= "Intel(R) G33";
149 chipset
= "Intel(R) Q35";
152 chipset
= "Intel(R) Q33";
154 case PCI_CHIP_I965_Q
:
155 chipset
= "Intel(R) 965Q";
157 case PCI_CHIP_I965_G
:
158 case PCI_CHIP_I965_G_1
:
159 chipset
= "Intel(R) 965G";
161 case PCI_CHIP_I946_GZ
:
162 chipset
= "Intel(R) 946GZ";
164 case PCI_CHIP_I965_GM
:
165 chipset
= "Intel(R) 965GM";
167 case PCI_CHIP_I965_GME
:
168 chipset
= "Intel(R) 965GME/GLE";
170 case PCI_CHIP_GM45_GM
:
171 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
173 case PCI_CHIP_IGD_E_G
:
174 chipset
= "Intel(R) Integrated Graphics Device";
177 chipset
= "Intel(R) G45/G43";
180 chipset
= "Intel(R) Q45/Q43";
183 chipset
= "Intel(R) G41";
186 chipset
= "Unknown Intel Chipset";
190 (void) driGetRendererString(buffer
, chipset
,
191 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
193 return (GLubyte
*) buffer
;
201 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
203 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
204 struct intel_renderbuffer
*rb
;
205 struct intel_region
*region
, *depth_region
;
206 struct intel_context
*intel
= context
->driverPrivate
;
207 __DRIbuffer
*buffers
;
210 unsigned int attachments
[10];
212 const char *region_name
;
214 if (INTEL_DEBUG
& DEBUG_DRI
)
215 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
217 screen
= intel
->intelScreen
->driScrnPriv
;
220 if (intel_fb
->color_rb
[0])
221 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
222 if (intel_fb
->color_rb
[1])
223 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
224 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
225 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
226 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
227 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
229 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
234 drawable
->loaderPrivate
);
243 drawable
->numClipRects
= 1;
244 drawable
->pClipRects
[0].x1
= 0;
245 drawable
->pClipRects
[0].y1
= 0;
246 drawable
->pClipRects
[0].x2
= drawable
->w
;
247 drawable
->pClipRects
[0].y2
= drawable
->h
;
248 drawable
->numBackClipRects
= 1;
249 drawable
->pBackClipRects
[0].x1
= 0;
250 drawable
->pBackClipRects
[0].y1
= 0;
251 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
252 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
255 for (i
= 0; i
< count
; i
++) {
256 switch (buffers
[i
].attachment
) {
257 case __DRI_BUFFER_FRONT_LEFT
:
258 rb
= intel_fb
->color_rb
[0];
259 region_name
= "dri2 front buffer";
262 case __DRI_BUFFER_BACK_LEFT
:
263 rb
= intel_fb
->color_rb
[1];
264 region_name
= "dri2 back buffer";
267 case __DRI_BUFFER_DEPTH
:
268 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
269 region_name
= "dri2 depth buffer";
272 case __DRI_BUFFER_STENCIL
:
273 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
274 region_name
= "dri2 stencil buffer";
277 case __DRI_BUFFER_ACCUM
:
280 "unhandled buffer attach event, attacment type %d\n",
281 buffers
[i
].attachment
);
286 dri_bo_flink(rb
->region
->buffer
, &name
);
287 if (name
== buffers
[i
].name
)
291 if (INTEL_DEBUG
& DEBUG_DRI
)
293 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
294 buffers
[i
].name
, buffers
[i
].attachment
,
295 buffers
[i
].cpp
, buffers
[i
].pitch
);
297 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
298 if (INTEL_DEBUG
& DEBUG_DRI
)
299 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
300 intel_region_reference(®ion
, depth_region
);
303 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
306 buffers
[i
].pitch
/ buffers
[i
].cpp
,
310 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
311 depth_region
= region
;
313 intel_renderbuffer_set_region(rb
, region
);
314 intel_region_release(®ion
);
317 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
321 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
323 struct intel_context
*intel
= intel_context(ctx
);
324 __DRIcontext
*driContext
= intel
->driContext
;
326 if (!driContext
->driScreenPriv
->dri2
.enabled
)
329 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
330 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
331 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
333 ctx
->Driver
.Viewport
= NULL
;
334 intel
->driDrawable
= driContext
->driDrawablePriv
;
335 intelWindowMoved(intel
);
336 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
337 ctx
->Driver
.Viewport
= intel_viewport
;
341 * Extension strings exported by the intel driver.
343 * Extensions supported by all chips supported by i830_dri, i915_dri, or
346 static const struct dri_extension card_extensions
[] = {
347 {"GL_ARB_multisample", GL_ARB_multisample_functions
},
348 {"GL_ARB_multitexture", NULL
},
349 {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
350 {"GL_NV_point_sprite", GL_NV_point_sprite_functions
},
351 {"GL_ARB_texture_border_clamp", NULL
},
352 {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
353 {"GL_ARB_texture_cube_map", NULL
},
354 {"GL_ARB_texture_env_add", NULL
},
355 {"GL_ARB_texture_env_combine", NULL
},
356 {"GL_ARB_texture_env_crossbar", NULL
},
357 {"GL_ARB_texture_env_dot3", NULL
},
358 {"GL_ARB_texture_mirrored_repeat", NULL
},
359 {"GL_ARB_texture_non_power_of_two", NULL
},
360 {"GL_ARB_texture_rectangle", NULL
},
361 {"GL_NV_texture_rectangle", NULL
},
362 {"GL_EXT_texture_rectangle", NULL
},
363 {"GL_ARB_point_parameters", NULL
},
364 {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
365 {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
366 {"GL_ARB_window_pos", GL_ARB_window_pos_functions
},
367 {"GL_EXT_blend_color", GL_EXT_blend_color_functions
},
368 {"GL_EXT_blend_equation_separate",
369 GL_EXT_blend_equation_separate_functions
},
370 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
371 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
372 {"GL_EXT_blend_logic_op", NULL
},
373 {"GL_EXT_blend_subtract", NULL
},
374 {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions
},
375 {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
376 {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
377 {"GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions
},
378 #if 1 /* XXX FBO temporary? */
379 {"GL_EXT_packed_depth_stencil", NULL
},
381 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
382 {"GL_EXT_stencil_wrap", NULL
},
383 {"GL_EXT_texture_edge_clamp", NULL
},
384 {"GL_EXT_texture_env_combine", NULL
},
385 {"GL_EXT_texture_env_dot3", NULL
},
386 {"GL_EXT_texture_filter_anisotropic", NULL
},
387 {"GL_EXT_texture_lod_bias", NULL
},
388 {"GL_3DFX_texture_compression_FXT1", NULL
},
389 {"GL_APPLE_client_storage", NULL
},
390 {"GL_MESA_pack_invert", NULL
},
391 {"GL_MESA_ycbcr_texture", NULL
},
392 {"GL_NV_blend_square", NULL
},
393 {"GL_NV_vertex_program", GL_NV_vertex_program_functions
},
394 {"GL_NV_vertex_program1_1", NULL
},
395 { "GL_SGIS_generate_mipmap", NULL
},
399 static const struct dri_extension brw_extensions
[] = {
400 { "GL_ARB_shading_language_100", GL_VERSION_2_0_functions
},
401 { "GL_ARB_shading_language_120", GL_VERSION_2_1_functions
},
402 { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions
},
403 { "GL_ARB_vertex_shader", GL_ARB_vertex_shader_functions
},
404 { "GL_ARB_point_sprite", NULL
},
405 { "GL_ARB_fragment_shader", NULL
},
406 { "GL_ARB_draw_buffers", NULL
},
407 { "GL_ARB_depth_texture", NULL
},
408 { "GL_ARB_fragment_program", NULL
},
409 { "GL_ARB_shadow", NULL
},
410 { "GL_EXT_shadow_funcs", NULL
},
411 { "GL_ARB_fragment_program_shadow", NULL
},
412 /* ARB extn won't work if not enabled */
413 { "GL_SGIX_depth_texture", NULL
},
414 { "GL_EXT_texture_sRGB", NULL
},
418 #ifdef I915_MMIO_READ
419 static const struct dri_extension arb_oc_extensions
[] = {
420 {"GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
},
425 static const struct dri_extension ttm_extensions
[] = {
426 {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions
},
427 {"GL_ARB_pixel_buffer_object", NULL
},
432 * Initializes potential list of extensions if ctx == NULL, or actually enables
433 * extensions for a context.
435 void intelInitExtensions(GLcontext
*ctx
, GLboolean enable_imaging
)
437 struct intel_context
*intel
= ctx
?intel_context(ctx
):NULL
;
439 /* Disable imaging extension until convolution is working in teximage paths.
441 enable_imaging
= GL_FALSE
;
443 driInitExtensions(ctx
, card_extensions
, enable_imaging
);
445 if (intel
== NULL
|| intel
->ttm
)
446 driInitExtensions(ctx
, ttm_extensions
, GL_FALSE
);
448 #ifdef I915_MMIO_READ
450 (IS_965(intel
->intelScreen
->deviceID
) &&
451 intel
->intelScreen
->drmMinor
>= 8))
452 driInitExtensions(ctx
, arb_oc_extensions
, GL_FALSE
);
455 if (intel
== NULL
|| IS_965(intel
->intelScreen
->deviceID
))
456 driInitExtensions(ctx
, brw_extensions
, GL_FALSE
);
459 static const struct dri_debug_control debug_control
[] = {
460 { "tex", DEBUG_TEXTURE
},
461 { "state", DEBUG_STATE
},
462 { "ioctl", DEBUG_IOCTL
},
463 { "blit", DEBUG_BLIT
},
464 { "mip", DEBUG_MIPTREE
},
465 { "fall", DEBUG_FALLBACKS
},
466 { "verb", DEBUG_VERBOSE
},
467 { "bat", DEBUG_BATCH
},
468 { "pix", DEBUG_PIXEL
},
469 { "buf", DEBUG_BUFMGR
},
470 { "reg", DEBUG_REGION
},
472 { "lock", DEBUG_LOCK
},
473 { "sync", DEBUG_SYNC
},
474 { "prim", DEBUG_PRIMS
},
475 { "vert", DEBUG_VERTS
},
476 { "dri", DEBUG_DRI
},
477 { "dma", DEBUG_DMA
},
478 { "san", DEBUG_SANITY
},
479 { "sleep", DEBUG_SLEEP
},
480 { "stats", DEBUG_STATS
},
481 { "tile", DEBUG_TILE
},
482 { "sing", DEBUG_SINGLE_THREAD
},
483 { "thre", DEBUG_SINGLE_THREAD
},
485 { "urb", DEBUG_URB
},
492 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
494 struct intel_context
*intel
= intel_context(ctx
);
496 _swrast_InvalidateState(ctx
, new_state
);
497 _swsetup_InvalidateState(ctx
, new_state
);
498 _vbo_InvalidateState(ctx
, new_state
);
499 _tnl_InvalidateState(ctx
, new_state
);
500 _tnl_invalidate_vertex_state(ctx
, new_state
);
502 intel
->NewGLState
|= new_state
;
504 if (intel
->vtbl
.invalidate_state
)
505 intel
->vtbl
.invalidate_state( intel
, new_state
);
510 intelFlush(GLcontext
* ctx
)
512 struct intel_context
*intel
= intel_context(ctx
);
517 if (!IS_965(intel
->intelScreen
->deviceID
))
518 INTEL_FIREVERTICES(intel
);
520 /* Emit a flush so that any frontbuffer rendering that might have occurred
521 * lands onscreen in a timely manner, even if the X Server doesn't trigger
524 intel_batchbuffer_emit_mi_flush(intel
->batch
);
526 if (intel
->batch
->map
!= intel
->batch
->ptr
)
527 intel_batchbuffer_flush(intel
->batch
);
531 intelFinish(GLcontext
* ctx
)
533 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
538 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
539 struct intel_renderbuffer
*irb
;
541 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
544 dri_bo_wait_rendering(irb
->region
->buffer
);
546 if (fb
->_DepthBuffer
) {
547 /* XXX: Wait on buffer idle */
551 #ifdef I915_MMIO_READ
553 intelBeginQuery(GLcontext
*ctx
, struct gl_query_object
*q
)
555 struct intel_context
*intel
= intel_context( ctx
);
556 struct drm_i915_mmio io
= {
557 .read_write
= I915_MMIO_READ
,
558 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
562 intelFinish(&intel
->ctx
);
563 drmCommandWrite(intel
->driFd
, DRM_I915_MMIO
, &io
, sizeof(io
));
567 intelEndQuery(GLcontext
*ctx
, struct gl_query_object
*q
)
569 struct intel_context
*intel
= intel_context( ctx
);
571 struct drm_i915_mmio io
= {
572 .read_write
= I915_MMIO_READ
,
573 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
576 intelFinish(&intel
->ctx
);
577 drmCommandWrite(intel
->driFd
, DRM_I915_MMIO
, &io
, sizeof(io
));
578 q
->Result
= tmp
- q
->Result
;
585 intelInitDriverFunctions(struct dd_function_table
*functions
)
587 _mesa_init_driver_functions(functions
);
589 functions
->Flush
= intelFlush
;
590 functions
->Finish
= intelFinish
;
591 functions
->GetString
= intelGetString
;
592 functions
->UpdateState
= intelInvalidateState
;
593 functions
->Viewport
= intel_viewport
;
595 functions
->CopyColorTable
= _swrast_CopyColorTable
;
596 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
597 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
598 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
600 #ifdef I915_MMIO_READ
601 functions
->BeginQuery
= intelBeginQuery
;
602 functions
->EndQuery
= intelEndQuery
;
605 intelInitTextureFuncs(functions
);
606 intelInitStateFuncs(functions
);
607 intelInitBufferFuncs(functions
);
608 intelInitPixelFuncs(functions
);
613 intelInitContext(struct intel_context
*intel
,
614 const __GLcontextModes
* mesaVis
,
615 __DRIcontextPrivate
* driContextPriv
,
616 void *sharedContextPrivate
,
617 struct dd_function_table
*functions
)
619 GLcontext
*ctx
= &intel
->ctx
;
620 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
621 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
622 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
625 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
626 functions
, (void *) intel
)) {
627 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
631 driContextPriv
->driverPrivate
= intel
;
632 intel
->intelScreen
= intelScreen
;
633 intel
->driScreen
= sPriv
;
634 intel
->sarea
= intelScreen
->sarea
;
635 intel
->driContext
= driContextPriv
;
638 intel
->hHWContext
= driContextPriv
->hHWContext
;
639 intel
->driFd
= sPriv
->fd
;
640 intel
->driHwLock
= sPriv
->lock
;
642 intel
->width
= intelScreen
->width
;
643 intel
->height
= intelScreen
->height
;
645 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
646 intel
->driScreen
->myNum
,
647 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
648 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
649 intel
->maxBatchSize
= 4096;
651 intel
->maxBatchSize
= BATCH_SZ
;
653 intel
->bufmgr
= intelScreen
->bufmgr
;
654 intel
->ttm
= intelScreen
->ttm
;
658 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
659 switch (bo_reuse_mode
) {
660 case DRI_CONF_BO_REUSE_DISABLED
:
662 case DRI_CONF_BO_REUSE_ALL
:
663 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
668 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
670 /* This doesn't yet catch all non-conformant rendering, but it's a
673 if (getenv("INTEL_STRICT_CONFORMANCE")) {
674 intel
->strict_conformance
= 1;
677 if (intel
->strict_conformance
) {
678 ctx
->Const
.MinLineWidth
= 1.0;
679 ctx
->Const
.MinLineWidthAA
= 1.0;
680 ctx
->Const
.MaxLineWidth
= 1.0;
681 ctx
->Const
.MaxLineWidthAA
= 1.0;
682 ctx
->Const
.LineWidthGranularity
= 1.0;
685 ctx
->Const
.MinLineWidth
= 1.0;
686 ctx
->Const
.MinLineWidthAA
= 1.0;
687 ctx
->Const
.MaxLineWidth
= 5.0;
688 ctx
->Const
.MaxLineWidthAA
= 5.0;
689 ctx
->Const
.LineWidthGranularity
= 0.5;
692 ctx
->Const
.MinPointSize
= 1.0;
693 ctx
->Const
.MinPointSizeAA
= 1.0;
694 ctx
->Const
.MaxPointSize
= 255.0;
695 ctx
->Const
.MaxPointSizeAA
= 3.0;
696 ctx
->Const
.PointSizeGranularity
= 1.0;
698 /* reinitialize the context point state.
699 * It depend on constants in __GLcontextRec::Const
701 _mesa_init_point(ctx
);
703 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
705 /* Initialize the software rasterizer and helper modules. */
706 _swrast_CreateContext(ctx
);
707 _vbo_CreateContext(ctx
);
708 _tnl_CreateContext(ctx
);
709 _swsetup_CreateContext(ctx
);
711 /* Configure swrast to match hardware characteristics: */
712 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
713 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
715 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
716 intel
->hw_stipple
= 1;
718 /* XXX FBO: this doesn't seem to be used anywhere */
719 switch (mesaVis
->depthBits
) {
720 case 0: /* what to do in this case? */
722 intel
->polygon_offset_scale
= 1.0;
725 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
732 if (IS_965(intelScreen
->deviceID
))
733 intel
->polygon_offset_scale
/= 0xffff;
735 intel
->RenderIndex
= ~0;
737 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
738 intel
->irqsEmitted
= 0;
740 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
741 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
743 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
745 _math_matrix_ctr(&intel
->ViewportMatrix
);
747 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
748 _mesa_printf("IRQs not active. Exiting\n");
752 intelInitExtensions(ctx
, GL_FALSE
);
754 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
755 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
756 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
758 if (!sPriv
->dri2
.enabled
)
759 intel_recreate_static_regions(intel
);
761 intel
->batch
= intel_batchbuffer_alloc(intel
);
763 intel_bufferobj_init(intel
);
764 intel_fbo_init(intel
);
766 if (intel
->ctx
.Mesa_DXTn
) {
767 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
768 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
770 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
771 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
774 intel
->prim
.primitive
= ~0;
776 /* Force all software fallbacks */
777 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
778 fprintf(stderr
, "disabling 3D rasterization\n");
782 /* Disable all hardware rendering (skip emitting batches and fences/waits
785 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
791 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
793 struct intel_context
*intel
=
794 (struct intel_context
*) driContextPriv
->driverPrivate
;
796 assert(intel
); /* should never be null */
798 GLboolean release_texture_heaps
;
800 INTEL_FIREVERTICES(intel
);
802 intel
->vtbl
.destroy(intel
);
804 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
805 _swsetup_DestroyContext(&intel
->ctx
);
806 _tnl_DestroyContext(&intel
->ctx
);
807 _vbo_DestroyContext(&intel
->ctx
);
809 _swrast_DestroyContext(&intel
->ctx
);
810 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
812 intel_batchbuffer_free(intel
->batch
);
813 free(intel
->prim
.vb
);
815 if (release_texture_heaps
) {
816 /* This share group is about to go away, free our private
817 * texture object data.
819 if (INTEL_DEBUG
& DEBUG_TEXTURE
)
820 fprintf(stderr
, "do something to free texture heaps\n");
823 /* free the Mesa context */
824 _mesa_free_context_data(&intel
->ctx
);
829 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
835 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
836 __DRIdrawablePrivate
* driDrawPriv
,
837 __DRIdrawablePrivate
* driReadPriv
)
839 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
841 if (driContextPriv
) {
842 struct intel_context
*intel
=
843 (struct intel_context
*) driContextPriv
->driverPrivate
;
844 struct intel_framebuffer
*intel_fb
=
845 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
846 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
848 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
849 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
850 if (driDrawPriv
!= driReadPriv
)
851 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
853 /* XXX FBO temporary fix-ups! */
854 /* if the renderbuffers don't have regions, init them from the context */
855 struct intel_renderbuffer
*irbDepth
856 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
857 struct intel_renderbuffer
*irbStencil
858 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
860 if (intel_fb
->color_rb
[0]) {
861 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
862 intel
->front_region
);
864 if (intel_fb
->color_rb
[1]) {
865 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
869 if (intel_fb
->color_rb
[2]) {
870 intel_renderbuffer_set_region(intel_fb
->color_rb
[2],
871 intel
->third_region
);
875 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
878 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
882 /* set GLframebuffer size to match window, if needed */
883 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
885 if (driReadPriv
!= driDrawPriv
) {
886 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
889 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
891 /* The drawbuffer won't always be updated by _mesa_make_current:
893 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
895 if (intel
->driReadDrawable
!= driReadPriv
)
896 intel
->driReadDrawable
= driReadPriv
;
898 if (intel
->driDrawable
!= driDrawPriv
) {
899 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
902 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
903 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
904 : VBLANK_FLAG_NO_IRQ
;
906 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
907 driDrawableInitVBlank(driDrawPriv
);
908 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
910 for (i
= 0; i
< (intel
->intelScreen
->third
.handle
? 3 : 2); i
++) {
911 if (intel_fb
->color_rb
[i
])
912 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
915 intel
->driDrawable
= driDrawPriv
;
916 intelWindowMoved(intel
);
919 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
923 _mesa_make_current(NULL
, NULL
, NULL
);
930 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
932 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
933 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
934 volatile struct drm_i915_sarea
*sarea
= intel
->sarea
;
935 int me
= intel
->hHWContext
;
937 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
940 if (INTEL_DEBUG
& DEBUG_LOCK
)
941 _mesa_printf("%s - got contended lock\n", __progname
);
943 /* If the window moved, may need to set a new cliprect now.
945 * NOTE: This releases and regains the hw lock, so all state
946 * checking must be done *after* this call:
949 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
951 if (sarea
&& sarea
->ctxOwner
!= me
) {
952 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
953 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
954 sarea
->ctxOwner
, me
);
956 sarea
->ctxOwner
= me
;
959 /* If the last consumer of the texture memory wasn't us, notify the fake
960 * bufmgr and record the new owner. We should have the memory shared
961 * between contexts of a single fake bufmgr, but this will at least make
962 * things correct for now.
964 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
965 sarea
->texAge
= intel
->hHWContext
;
966 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
967 if (INTEL_DEBUG
& DEBUG_BATCH
)
968 intel_decode_context_reset();
969 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
970 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
971 sarea
->ctxOwner
, intel
->hHWContext
);
974 if (sarea
->width
!= intel
->width
|| sarea
->height
!= intel
->height
) {
975 int numClipRects
= intel
->numClipRects
;
978 * FIXME: Really only need to do this when drawing to a
979 * common back- or front buffer.
983 * This will essentially drop the outstanding batchbuffer on
986 intel
->numClipRects
= 0;
989 _swrast_flush(&intel
->ctx
);
991 if (!IS_965(intel
->intelScreen
->deviceID
))
992 INTEL_FIREVERTICES(intel
);
994 if (intel
->batch
->map
!= intel
->batch
->ptr
)
995 intel_batchbuffer_flush(intel
->batch
);
997 intel
->numClipRects
= numClipRects
;
999 /* force window update */
1000 intel
->lastStamp
= 0;
1002 intel
->width
= sarea
->width
;
1003 intel
->height
= sarea
->height
;
1006 /* Drawable changed?
1008 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1009 intelWindowMoved(intel
);
1010 intel
->lastStamp
= dPriv
->lastStamp
;
1015 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1017 /* Lock the hardware and validate our state.
1019 void LOCK_HARDWARE( struct intel_context
*intel
)
1021 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1022 __DRIscreen
*sPriv
= intel
->driScreen
;
1024 struct intel_framebuffer
*intel_fb
= NULL
;
1025 struct intel_renderbuffer
*intel_rb
= NULL
;
1027 _glthread_LOCK_MUTEX(lockMutex
);
1028 assert(!intel
->locked
);
1031 if (intel
->driDrawable
) {
1032 intel_fb
= intel
->driDrawable
->driverPrivate
;
1036 intel_get_renderbuffer(&intel_fb
->Base
,
1037 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1040 if (intel_rb
&& dPriv
->vblFlags
&&
1041 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1042 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1045 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1047 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1048 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1051 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1052 drmWaitVBlank(intel
->driFd
, &vbl
);
1053 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1056 if (!sPriv
->dri2
.enabled
) {
1057 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1058 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1061 intelContendedLock( intel
, 0 );
1065 if (INTEL_DEBUG
& DEBUG_LOCK
)
1066 _mesa_printf("%s - locked\n", __progname
);
1070 /* Unlock the hardware using the global current context
1072 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1074 __DRIscreen
*sPriv
= intel
->driScreen
;
1076 intel
->vtbl
.note_unlock( intel
);
1079 if (!sPriv
->dri2
.enabled
)
1080 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1082 _glthread_UNLOCK_MUTEX(lockMutex
);
1084 if (INTEL_DEBUG
& DEBUG_LOCK
)
1085 _mesa_printf("%s - unlocked\n", __progname
);
1088 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1091 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1092 intel_batchbuffer_flush(intel
->batch
);