1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/extensions.h"
32 #include "main/fbobject.h"
33 #include "main/framebuffer.h"
34 #include "main/imports.h"
35 #include "main/points.h"
36 #include "main/renderbuffer.h"
38 #include "swrast/swrast.h"
39 #include "swrast_setup/swrast_setup.h"
41 #include "drivers/common/driverfuncs.h"
42 #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"
56 #include "intel_mipmap_tree.h"
59 #include "../glsl/ralloc.h"
62 int INTEL_DEBUG
= (0);
66 static const GLubyte
*
67 intelGetString(struct gl_context
* ctx
, GLenum name
)
69 const struct intel_context
*const intel
= intel_context(ctx
);
71 static char buffer
[128];
75 return (GLubyte
*) "Intel Open Source Technology Center";
79 switch (intel
->intelScreen
->deviceID
) {
81 chipset
= "Intel(R) 845G";
84 chipset
= "Intel(R) 830M";
86 case PCI_CHIP_I855_GM
:
87 chipset
= "Intel(R) 852GM/855GM";
90 chipset
= "Intel(R) 865G";
93 chipset
= "Intel(R) 915G";
95 case PCI_CHIP_E7221_G
:
96 chipset
= "Intel (R) E7221G (i915)";
98 case PCI_CHIP_I915_GM
:
99 chipset
= "Intel(R) 915GM";
101 case PCI_CHIP_I945_G
:
102 chipset
= "Intel(R) 945G";
104 case PCI_CHIP_I945_GM
:
105 chipset
= "Intel(R) 945GM";
107 case PCI_CHIP_I945_GME
:
108 chipset
= "Intel(R) 945GME";
111 chipset
= "Intel(R) G33";
114 chipset
= "Intel(R) Q35";
117 chipset
= "Intel(R) Q33";
119 case PCI_CHIP_IGD_GM
:
121 chipset
= "Intel(R) IGD";
123 case PCI_CHIP_I965_Q
:
124 chipset
= "Intel(R) 965Q";
126 case PCI_CHIP_I965_G
:
127 case PCI_CHIP_I965_G_1
:
128 chipset
= "Intel(R) 965G";
130 case PCI_CHIP_I946_GZ
:
131 chipset
= "Intel(R) 946GZ";
133 case PCI_CHIP_I965_GM
:
134 chipset
= "Intel(R) 965GM";
136 case PCI_CHIP_I965_GME
:
137 chipset
= "Intel(R) 965GME/GLE";
139 case PCI_CHIP_GM45_GM
:
140 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
142 case PCI_CHIP_IGD_E_G
:
143 chipset
= "Intel(R) Integrated Graphics Device";
146 chipset
= "Intel(R) G45/G43";
149 chipset
= "Intel(R) Q45/Q43";
152 chipset
= "Intel(R) G41";
155 case PCI_CHIP_B43_G1
:
156 chipset
= "Intel(R) B43";
159 chipset
= "Intel(R) Ironlake Desktop";
162 chipset
= "Intel(R) Ironlake Mobile";
164 case PCI_CHIP_SANDYBRIDGE_GT1
:
165 case PCI_CHIP_SANDYBRIDGE_GT2
:
166 case PCI_CHIP_SANDYBRIDGE_GT2_PLUS
:
167 chipset
= "Intel(R) Sandybridge Desktop";
169 case PCI_CHIP_SANDYBRIDGE_M_GT1
:
170 case PCI_CHIP_SANDYBRIDGE_M_GT2
:
171 case PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS
:
172 chipset
= "Intel(R) Sandybridge Mobile";
174 case PCI_CHIP_SANDYBRIDGE_S
:
175 chipset
= "Intel(R) Sandybridge Server";
177 case PCI_CHIP_IVYBRIDGE_GT1
:
178 case PCI_CHIP_IVYBRIDGE_GT2
:
179 chipset
= "Intel(R) Ivybridge Desktop";
181 case PCI_CHIP_IVYBRIDGE_M_GT1
:
182 case PCI_CHIP_IVYBRIDGE_M_GT2
:
183 chipset
= "Intel(R) Ivybridge Mobile";
185 case PCI_CHIP_IVYBRIDGE_S_GT1
:
186 case PCI_CHIP_IVYBRIDGE_S_GT2
:
187 chipset
= "Intel(R) Ivybridge Server";
189 case PCI_CHIP_HASWELL_GT1
:
190 case PCI_CHIP_HASWELL_GT2
:
191 chipset
= "Intel(R) Haswell Desktop";
193 case PCI_CHIP_HASWELL_M_GT1
:
194 case PCI_CHIP_HASWELL_M_GT2
:
195 case PCI_CHIP_HASWELL_M_ULT_GT2
:
196 chipset
= "Intel(R) Haswell Mobile";
199 chipset
= "Unknown Intel Chipset";
203 (void) driGetRendererString(buffer
, chipset
, 0);
204 return (GLubyte
*) buffer
;
212 intel_flush_front(struct gl_context
*ctx
)
214 struct intel_context
*intel
= intel_context(ctx
);
215 __DRIcontext
*driContext
= intel
->driContext
;
216 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
218 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
) && intel
->front_buffer_dirty
) {
219 if (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
&&
220 driContext
->driDrawablePriv
&&
221 driContext
->driDrawablePriv
->loaderPrivate
) {
222 (*screen
->dri2
.loader
->flushFrontBuffer
)(driContext
->driDrawablePriv
,
223 driContext
->driDrawablePriv
->loaderPrivate
);
225 /* We set the dirty bit in intel_prepare_render() if we're
226 * front buffer rendering once we get there.
228 intel
->front_buffer_dirty
= false;
234 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
236 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
240 intel_query_dri2_buffers(struct intel_context
*intel
,
241 __DRIdrawable
*drawable
,
242 __DRIbuffer
**buffers
,
246 intel_process_dri2_buffer(struct intel_context
*intel
,
247 __DRIdrawable
*drawable
,
249 struct intel_renderbuffer
*rb
,
250 const char *buffer_name
);
253 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
255 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
256 struct intel_renderbuffer
*rb
;
257 struct intel_context
*intel
= context
->driverPrivate
;
258 __DRIbuffer
*buffers
= NULL
;
260 const char *region_name
;
262 /* If we're rendering to the fake front buffer, make sure all the
263 * pending drawing has landed on the real front buffer. Otherwise
264 * when we eventually get to DRI2GetBuffersWithFormat the stale
265 * real front buffer contents will get copied to the new fake front
268 if (intel
->is_front_buffer_rendering
) {
269 intel_flush(&intel
->ctx
);
270 intel_flush_front(&intel
->ctx
);
273 /* Set this up front, so that in case our buffers get invalidated
274 * while we're getting new buffers, we don't clobber the stamp and
275 * thus ignore the invalidate. */
276 drawable
->lastStamp
= drawable
->dri2
.stamp
;
278 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
279 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
281 intel_query_dri2_buffers(intel
, drawable
, &buffers
, &count
);
286 for (i
= 0; i
< count
; i
++) {
287 switch (buffers
[i
].attachment
) {
288 case __DRI_BUFFER_FRONT_LEFT
:
289 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
290 region_name
= "dri2 front buffer";
293 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
294 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
295 region_name
= "dri2 fake front buffer";
298 case __DRI_BUFFER_BACK_LEFT
:
299 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
300 region_name
= "dri2 back buffer";
303 case __DRI_BUFFER_DEPTH
:
304 case __DRI_BUFFER_HIZ
:
305 case __DRI_BUFFER_DEPTH_STENCIL
:
306 case __DRI_BUFFER_STENCIL
:
307 case __DRI_BUFFER_ACCUM
:
310 "unhandled buffer attach event, attachment type %d\n",
311 buffers
[i
].attachment
);
315 intel_process_dri2_buffer(intel
, drawable
, &buffers
[i
], rb
, region_name
);
318 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
322 * intel_prepare_render should be called anywhere that curent read/drawbuffer
326 intel_prepare_render(struct intel_context
*intel
)
328 __DRIcontext
*driContext
= intel
->driContext
;
329 __DRIdrawable
*drawable
;
331 drawable
= driContext
->driDrawablePriv
;
332 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
333 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
334 intel_update_renderbuffers(driContext
, drawable
);
335 intel_draw_buffer(&intel
->ctx
);
336 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
339 drawable
= driContext
->driReadablePriv
;
340 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
341 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
342 intel_update_renderbuffers(driContext
, drawable
);
343 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
346 /* If we're currently rendering to the front buffer, the rendering
347 * that will happen next will probably dirty the front buffer. So
348 * mark it as dirty here.
350 if (intel
->is_front_buffer_rendering
)
351 intel
->front_buffer_dirty
= true;
353 /* Wait for the swapbuffers before the one we just emitted, so we
354 * don't get too many swaps outstanding for apps that are GPU-heavy
357 * We're using intelDRI2Flush (called from the loader before
358 * swapbuffer) and glFlush (for front buffer rendering) as the
359 * indicator that a frame is done and then throttle when we get
360 * here as we prepare to render the next frame. At this point for
361 * round trips for swap/copy and getting new buffers are done and
362 * we'll spend less time waiting on the GPU.
364 * Unfortunately, we don't have a handle to the batch containing
365 * the swap, and getting our hands on that doesn't seem worth it,
366 * so we just us the first batch we emitted after the last swap.
368 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
369 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
370 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
371 intel
->first_post_swapbuffers_batch
= NULL
;
372 intel
->need_throttle
= false;
377 intel_viewport(struct gl_context
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
379 struct intel_context
*intel
= intel_context(ctx
);
380 __DRIcontext
*driContext
= intel
->driContext
;
382 if (intel
->saved_viewport
)
383 intel
->saved_viewport(ctx
, x
, y
, w
, h
);
385 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
386 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
387 dri2InvalidateDrawable(driContext
->driReadablePriv
);
391 static const struct dri_debug_control debug_control
[] = {
392 { "tex", DEBUG_TEXTURE
},
393 { "state", DEBUG_STATE
},
394 { "ioctl", DEBUG_IOCTL
},
395 { "blit", DEBUG_BLIT
},
396 { "mip", DEBUG_MIPTREE
},
397 { "fall", DEBUG_FALLBACKS
},
398 { "verb", DEBUG_VERBOSE
},
399 { "bat", DEBUG_BATCH
},
400 { "pix", DEBUG_PIXEL
},
401 { "buf", DEBUG_BUFMGR
},
402 { "reg", DEBUG_REGION
},
405 { "sync", DEBUG_SYNC
},
406 { "prim", DEBUG_PRIMS
},
407 { "vert", DEBUG_VERTS
},
408 { "dri", DEBUG_DRI
},
410 { "san", DEBUG_SANITY
},
411 { "sleep", DEBUG_SLEEP
},
412 { "stats", DEBUG_STATS
},
413 { "tile", DEBUG_TILE
},
415 { "urb", DEBUG_URB
},
417 { "clip", DEBUG_CLIP
},
418 { "aub", DEBUG_AUB
},
424 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
426 struct intel_context
*intel
= intel_context(ctx
);
428 _swrast_InvalidateState(ctx
, new_state
);
429 _vbo_InvalidateState(ctx
, new_state
);
431 intel
->NewGLState
|= new_state
;
433 if (intel
->vtbl
.invalidate_state
)
434 intel
->vtbl
.invalidate_state( intel
, new_state
);
438 intel_flush_rendering_to_batch(struct gl_context
*ctx
)
440 struct intel_context
*intel
= intel_context(ctx
);
446 INTEL_FIREVERTICES(intel
);
450 _intel_flush(struct gl_context
*ctx
, const char *file
, int line
)
452 struct intel_context
*intel
= intel_context(ctx
);
454 intel_flush_rendering_to_batch(ctx
);
456 if (intel
->batch
.used
)
457 _intel_batchbuffer_flush(intel
, file
, line
);
461 intel_glFlush(struct gl_context
*ctx
)
463 struct intel_context
*intel
= intel_context(ctx
);
466 intel_flush_front(ctx
);
467 if (intel
->is_front_buffer_rendering
)
468 intel
->need_throttle
= true;
472 intelFinish(struct gl_context
* ctx
)
474 struct intel_context
*intel
= intel_context(ctx
);
477 intel_flush_front(ctx
);
479 if (intel
->batch
.last_bo
)
480 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
484 intelInitDriverFunctions(struct dd_function_table
*functions
)
486 _mesa_init_driver_functions(functions
);
488 functions
->Flush
= intel_glFlush
;
489 functions
->Finish
= intelFinish
;
490 functions
->GetString
= intelGetString
;
491 functions
->UpdateState
= intelInvalidateState
;
493 intelInitTextureFuncs(functions
);
494 intelInitTextureImageFuncs(functions
);
495 intelInitTextureSubImageFuncs(functions
);
496 intelInitTextureCopyImageFuncs(functions
);
497 intelInitStateFuncs(functions
);
498 intelInitClearFuncs(functions
);
499 intelInitBufferFuncs(functions
);
500 intelInitPixelFuncs(functions
);
501 intelInitBufferObjectFuncs(functions
);
502 intel_init_syncobj_functions(functions
);
506 intelInitContext(struct intel_context
*intel
,
508 const struct gl_config
* mesaVis
,
509 __DRIcontext
* driContextPriv
,
510 void *sharedContextPrivate
,
511 struct dd_function_table
*functions
)
513 struct gl_context
*ctx
= &intel
->ctx
;
514 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
515 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
516 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
518 struct gl_config visual
;
520 /* we can't do anything without a connection to the device */
521 if (intelScreen
->bufmgr
== NULL
)
524 /* Can't rely on invalidate events, fall back to glViewport hack */
525 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
) {
526 intel
->saved_viewport
= functions
->Viewport
;
527 functions
->Viewport
= intel_viewport
;
530 if (mesaVis
== NULL
) {
531 memset(&visual
, 0, sizeof visual
);
535 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
536 functions
, (void *) intel
)) {
537 printf("%s: failed to init mesa context\n", __FUNCTION__
);
541 driContextPriv
->driverPrivate
= intel
;
542 intel
->intelScreen
= intelScreen
;
543 intel
->driContext
= driContextPriv
;
544 intel
->driFd
= sPriv
->fd
;
546 intel
->gen
= intelScreen
->gen
;
548 const int devID
= intelScreen
->deviceID
;
549 if (IS_SNB_GT1(devID
) || IS_IVB_GT1(devID
) || IS_HSW_GT1(devID
))
551 else if (IS_SNB_GT2(devID
) || IS_IVB_GT2(devID
) || IS_HSW_GT2(devID
))
556 if (IS_HASWELL(devID
)) {
557 intel
->is_haswell
= true;
558 } else if (IS_G4X(devID
)) {
559 intel
->is_g4x
= true;
560 } else if (IS_945(devID
)) {
561 intel
->is_945
= true;
564 if (intel
->gen
>= 5) {
565 intel
->needs_ff_sync
= true;
568 intel
->has_separate_stencil
= intel
->intelScreen
->hw_has_separate_stencil
;
569 intel
->must_use_separate_stencil
= intel
->intelScreen
->hw_must_use_separate_stencil
;
570 intel
->has_hiz
= intel
->gen
>= 6 && !intel
->is_haswell
;
571 intel
->has_llc
= intel
->intelScreen
->hw_has_llc
;
572 intel
->has_swizzling
= intel
->intelScreen
->hw_has_swizzling
;
574 memset(&ctx
->TextureFormatSupported
,
575 0, sizeof(ctx
->TextureFormatSupported
));
577 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
578 sPriv
->myNum
, (intel
->gen
>= 4) ? "i965" : "i915");
580 intel
->maxBatchSize
= 4096;
582 intel
->maxBatchSize
= sizeof(intel
->batch
.map
);
584 intel
->bufmgr
= intelScreen
->bufmgr
;
586 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
587 switch (bo_reuse_mode
) {
588 case DRI_CONF_BO_REUSE_DISABLED
:
590 case DRI_CONF_BO_REUSE_ALL
:
591 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
595 ctx
->Const
.MinLineWidth
= 1.0;
596 ctx
->Const
.MinLineWidthAA
= 1.0;
597 ctx
->Const
.MaxLineWidth
= 5.0;
598 ctx
->Const
.MaxLineWidthAA
= 5.0;
599 ctx
->Const
.LineWidthGranularity
= 0.5;
601 ctx
->Const
.MinPointSize
= 1.0;
602 ctx
->Const
.MinPointSizeAA
= 1.0;
603 ctx
->Const
.MaxPointSize
= 255.0;
604 ctx
->Const
.MaxPointSizeAA
= 3.0;
605 ctx
->Const
.PointSizeGranularity
= 1.0;
607 ctx
->Const
.MaxSamples
= 1.0;
610 ctx
->Const
.MaxClipPlanes
= 8;
612 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
614 /* reinitialize the context point state.
615 * It depend on constants in __struct gl_contextRec::Const
617 _mesa_init_point(ctx
);
619 if (intel
->gen
>= 4) {
620 ctx
->Const
.MaxRenderbufferSize
= 8192;
622 ctx
->Const
.MaxRenderbufferSize
= 2048;
625 /* Initialize the software rasterizer and helper modules. */
626 _swrast_CreateContext(ctx
);
627 _vbo_CreateContext(ctx
);
628 _tnl_CreateContext(ctx
);
629 _swsetup_CreateContext(ctx
);
631 /* Configure swrast to match hardware characteristics: */
632 _swrast_allow_pixel_fog(ctx
, false);
633 _swrast_allow_vertex_fog(ctx
, true);
635 _mesa_meta_init(ctx
);
637 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
638 intel
->hw_stipple
= 1;
640 /* XXX FBO: this doesn't seem to be used anywhere */
641 switch (mesaVis
->depthBits
) {
642 case 0: /* what to do in this case? */
644 intel
->polygon_offset_scale
= 1.0;
647 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
655 intel
->polygon_offset_scale
/= 0xffff;
657 intel
->RenderIndex
= ~0;
659 intelInitExtensions(ctx
);
661 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
662 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
663 dri_bufmgr_set_debug(intel
->bufmgr
, true);
665 if (INTEL_DEBUG
& DEBUG_AUB
)
666 drm_intel_bufmgr_gem_set_aub_dump(intel
->bufmgr
, true);
668 intel_batchbuffer_init(intel
);
670 intel_fbo_init(intel
);
672 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
674 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
676 if (!driQueryOptionb(&intel
->optionCache
, "hiz")) {
677 intel
->has_hiz
= false;
678 /* On gen6, you can only do separate stencil with HIZ. */
680 intel
->has_separate_stencil
= false;
683 intel
->prim
.primitive
= ~0;
685 /* Force all software fallbacks */
686 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
687 fprintf(stderr
, "disabling 3D rasterization\n");
691 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
692 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
693 intel
->always_flush_batch
= 1;
696 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
697 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
698 intel
->always_flush_cache
= 1;
705 intelDestroyContext(__DRIcontext
* driContextPriv
)
707 struct intel_context
*intel
=
708 (struct intel_context
*) driContextPriv
->driverPrivate
;
710 assert(intel
); /* should never be null */
712 INTEL_FIREVERTICES(intel
);
714 /* Dump a final BMP in case the application doesn't call SwapBuffers */
715 if (INTEL_DEBUG
& DEBUG_AUB
) {
716 intel_batchbuffer_flush(intel
);
717 aub_dump_bmp(&intel
->ctx
);
720 _mesa_meta_free(&intel
->ctx
);
722 intel
->vtbl
.destroy(intel
);
724 _swsetup_DestroyContext(&intel
->ctx
);
725 _tnl_DestroyContext(&intel
->ctx
);
726 _vbo_DestroyContext(&intel
->ctx
);
728 _swrast_DestroyContext(&intel
->ctx
);
729 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
731 intel_batchbuffer_free(intel
);
733 free(intel
->prim
.vb
);
734 intel
->prim
.vb
= NULL
;
735 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
736 intel
->prim
.vb_bo
= NULL
;
737 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
738 intel
->first_post_swapbuffers_batch
= NULL
;
740 driDestroyOptionCache(&intel
->optionCache
);
742 /* free the Mesa context */
743 _mesa_free_context_data(&intel
->ctx
);
745 _math_matrix_dtr(&intel
->ViewportMatrix
);
748 driContextPriv
->driverPrivate
= NULL
;
753 intelUnbindContext(__DRIcontext
* driContextPriv
)
755 /* Unset current context and dispath table */
756 _mesa_make_current(NULL
, NULL
, NULL
);
762 intelMakeCurrent(__DRIcontext
* driContextPriv
,
763 __DRIdrawable
* driDrawPriv
,
764 __DRIdrawable
* driReadPriv
)
766 struct intel_context
*intel
;
767 GET_CURRENT_CONTEXT(curCtx
);
770 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
774 /* According to the glXMakeCurrent() man page: "Pending commands to
775 * the previous context, if any, are flushed before it is released."
776 * But only flush if we're actually changing contexts.
778 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
782 if (driContextPriv
) {
783 struct gl_framebuffer
*fb
, *readFb
;
785 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
786 fb
= _mesa_get_incomplete_framebuffer();
787 readFb
= _mesa_get_incomplete_framebuffer();
789 fb
= driDrawPriv
->driverPrivate
;
790 readFb
= driReadPriv
->driverPrivate
;
791 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
792 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
795 intel_prepare_render(intel
);
796 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
798 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
799 * is NULL at that point. We can't call _mesa_makecurrent()
800 * first, since we need the buffer size for the initial
801 * viewport. So just call intel_draw_buffer() again here. */
802 intel_draw_buffer(&intel
->ctx
);
805 _mesa_make_current(NULL
, NULL
, NULL
);
812 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
814 * To determine which DRI buffers to request, examine the renderbuffers
815 * attached to the drawable's framebuffer. Then request the buffers with
816 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
818 * This is called from intel_update_renderbuffers().
820 * \param drawable Drawable whose buffers are queried.
821 * \param buffers [out] List of buffers returned by DRI2 query.
822 * \param buffer_count [out] Number of buffers returned.
824 * \see intel_update_renderbuffers()
825 * \see DRI2GetBuffers()
826 * \see DRI2GetBuffersWithFormat()
829 intel_query_dri2_buffers(struct intel_context
*intel
,
830 __DRIdrawable
*drawable
,
831 __DRIbuffer
**buffers
,
834 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
835 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
837 const int max_attachments
= 4;
838 unsigned *attachments
= calloc(2 * max_attachments
, sizeof(unsigned));
840 struct intel_renderbuffer
*front_rb
;
841 struct intel_renderbuffer
*back_rb
;
843 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
844 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
846 if ((intel
->is_front_buffer_rendering
||
847 intel
->is_front_buffer_reading
||
848 !back_rb
) && front_rb
) {
849 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
850 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
854 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
855 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
858 assert(i
<= 2 * max_attachments
);
860 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
865 drawable
->loaderPrivate
);
870 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
872 * This is called from intel_update_renderbuffers().
875 * DRI buffers whose attachment point is DRI2BufferStencil or
876 * DRI2BufferDepthStencil are handled as special cases.
878 * \param buffer_name is a human readable name, such as "dri2 front buffer",
879 * that is passed to intel_region_alloc_for_handle().
881 * \see intel_update_renderbuffers()
882 * \see intel_region_alloc_for_handle()
885 intel_process_dri2_buffer(struct intel_context
*intel
,
886 __DRIdrawable
*drawable
,
888 struct intel_renderbuffer
*rb
,
889 const char *buffer_name
)
891 struct intel_region
*region
= NULL
;
896 /* We try to avoid closing and reopening the same BO name, because the first
897 * use of a mapping of the buffer involves a bunch of page faulting which is
898 * moderately expensive.
902 rb
->mt
->region
->name
== buffer
->name
)
905 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
907 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
908 buffer
->name
, buffer
->attachment
,
909 buffer
->cpp
, buffer
->pitch
);
912 intel_miptree_release(&rb
->mt
);
913 region
= intel_region_alloc_for_handle(intel
->intelScreen
,
917 buffer
->pitch
/ buffer
->cpp
,
923 rb
->mt
= intel_miptree_create_for_region(intel
,
927 intel_region_release(®ion
);