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 case PCI_CHIP_HASWELL_GT2_PLUS
:
192 case PCI_CHIP_HASWELL_SDV_GT1
:
193 case PCI_CHIP_HASWELL_SDV_GT2
:
194 case PCI_CHIP_HASWELL_SDV_GT2_PLUS
:
195 case PCI_CHIP_HASWELL_ULT_GT1
:
196 case PCI_CHIP_HASWELL_ULT_GT2
:
197 case PCI_CHIP_HASWELL_ULT_GT2_PLUS
:
198 case PCI_CHIP_HASWELL_CRW_GT1
:
199 case PCI_CHIP_HASWELL_CRW_GT2
:
200 case PCI_CHIP_HASWELL_CRW_GT2_PLUS
:
201 chipset
= "Intel(R) Haswell Desktop";
203 case PCI_CHIP_HASWELL_M_GT1
:
204 case PCI_CHIP_HASWELL_M_GT2
:
205 case PCI_CHIP_HASWELL_M_GT2_PLUS
:
206 case PCI_CHIP_HASWELL_SDV_M_GT1
:
207 case PCI_CHIP_HASWELL_SDV_M_GT2
:
208 case PCI_CHIP_HASWELL_SDV_M_GT2_PLUS
:
209 case PCI_CHIP_HASWELL_ULT_M_GT1
:
210 case PCI_CHIP_HASWELL_ULT_M_GT2
:
211 case PCI_CHIP_HASWELL_ULT_M_GT2_PLUS
:
212 case PCI_CHIP_HASWELL_CRW_M_GT1
:
213 case PCI_CHIP_HASWELL_CRW_M_GT2
:
214 case PCI_CHIP_HASWELL_CRW_M_GT2_PLUS
:
215 chipset
= "Intel(R) Haswell Mobile";
217 case PCI_CHIP_HASWELL_S_GT1
:
218 case PCI_CHIP_HASWELL_S_GT2
:
219 case PCI_CHIP_HASWELL_S_GT2_PLUS
:
220 case PCI_CHIP_HASWELL_SDV_S_GT1
:
221 case PCI_CHIP_HASWELL_SDV_S_GT2
:
222 case PCI_CHIP_HASWELL_SDV_S_GT2_PLUS
:
223 case PCI_CHIP_HASWELL_ULT_S_GT1
:
224 case PCI_CHIP_HASWELL_ULT_S_GT2
:
225 case PCI_CHIP_HASWELL_ULT_S_GT2_PLUS
:
226 case PCI_CHIP_HASWELL_CRW_S_GT1
:
227 case PCI_CHIP_HASWELL_CRW_S_GT2
:
228 case PCI_CHIP_HASWELL_CRW_S_GT2_PLUS
:
229 chipset
= "Intel(R) Haswell Server";
232 chipset
= "Unknown Intel Chipset";
236 (void) driGetRendererString(buffer
, chipset
, 0);
237 return (GLubyte
*) buffer
;
245 intel_downsample_for_dri2_flush(struct intel_context
*intel
,
246 __DRIdrawable
*drawable
)
248 if (intel
->gen
< 6) {
249 /* MSAA is not supported, so don't waste time checking for
250 * a multisample buffer.
255 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
256 struct intel_renderbuffer
*rb
;
258 /* Usually, only the back buffer will need to be downsampled. However,
259 * the front buffer will also need it if the user has rendered into it.
261 static const gl_buffer_index buffers
[2] = {
266 for (int i
= 0; i
< 2; ++i
) {
267 rb
= intel_get_renderbuffer(fb
, buffers
[i
]);
268 if (rb
== NULL
|| rb
->mt
== NULL
)
270 intel_miptree_downsample(intel
, rb
->mt
);
275 intel_flush_front(struct gl_context
*ctx
)
277 struct intel_context
*intel
= intel_context(ctx
);
278 __DRIcontext
*driContext
= intel
->driContext
;
279 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
280 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
282 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
) && intel
->front_buffer_dirty
) {
283 if (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
&&
285 driDrawable
->loaderPrivate
) {
287 /* Downsample before flushing FAKE_FRONT_LEFT to FRONT_LEFT.
289 * This potentially downsamples both front and back buffer. It
290 * is unnecessary to downsample the back, but harms nothing except
291 * performance. And no one cares about front-buffer render
294 intel_downsample_for_dri2_flush(intel
, driDrawable
);
296 screen
->dri2
.loader
->flushFrontBuffer(driDrawable
,
297 driDrawable
->loaderPrivate
);
299 /* We set the dirty bit in intel_prepare_render() if we're
300 * front buffer rendering once we get there.
302 intel
->front_buffer_dirty
= false;
308 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
310 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
314 intel_query_dri2_buffers(struct intel_context
*intel
,
315 __DRIdrawable
*drawable
,
316 __DRIbuffer
**buffers
,
320 intel_process_dri2_buffer(struct intel_context
*intel
,
321 __DRIdrawable
*drawable
,
323 struct intel_renderbuffer
*rb
,
324 const char *buffer_name
);
327 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
329 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
330 struct intel_renderbuffer
*rb
;
331 struct intel_context
*intel
= context
->driverPrivate
;
332 __DRIbuffer
*buffers
= NULL
;
334 const char *region_name
;
336 /* If we're rendering to the fake front buffer, make sure all the
337 * pending drawing has landed on the real front buffer. Otherwise
338 * when we eventually get to DRI2GetBuffersWithFormat the stale
339 * real front buffer contents will get copied to the new fake front
342 if (intel
->is_front_buffer_rendering
) {
343 intel_flush(&intel
->ctx
);
344 intel_flush_front(&intel
->ctx
);
347 /* Set this up front, so that in case our buffers get invalidated
348 * while we're getting new buffers, we don't clobber the stamp and
349 * thus ignore the invalidate. */
350 drawable
->lastStamp
= drawable
->dri2
.stamp
;
352 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
353 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
355 intel_query_dri2_buffers(intel
, drawable
, &buffers
, &count
);
360 for (i
= 0; i
< count
; i
++) {
361 switch (buffers
[i
].attachment
) {
362 case __DRI_BUFFER_FRONT_LEFT
:
363 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
364 region_name
= "dri2 front buffer";
367 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
368 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
369 region_name
= "dri2 fake front buffer";
372 case __DRI_BUFFER_BACK_LEFT
:
373 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
374 region_name
= "dri2 back buffer";
377 case __DRI_BUFFER_DEPTH
:
378 case __DRI_BUFFER_HIZ
:
379 case __DRI_BUFFER_DEPTH_STENCIL
:
380 case __DRI_BUFFER_STENCIL
:
381 case __DRI_BUFFER_ACCUM
:
384 "unhandled buffer attach event, attachment type %d\n",
385 buffers
[i
].attachment
);
389 intel_process_dri2_buffer(intel
, drawable
, &buffers
[i
], rb
, region_name
);
392 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
396 * intel_prepare_render should be called anywhere that curent read/drawbuffer
400 intel_prepare_render(struct intel_context
*intel
)
402 __DRIcontext
*driContext
= intel
->driContext
;
403 __DRIdrawable
*drawable
;
405 drawable
= driContext
->driDrawablePriv
;
406 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
407 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
408 intel_update_renderbuffers(driContext
, drawable
);
409 intel_draw_buffer(&intel
->ctx
);
410 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
413 drawable
= driContext
->driReadablePriv
;
414 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
415 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
416 intel_update_renderbuffers(driContext
, drawable
);
417 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
420 /* If we're currently rendering to the front buffer, the rendering
421 * that will happen next will probably dirty the front buffer. So
422 * mark it as dirty here.
424 if (intel
->is_front_buffer_rendering
)
425 intel
->front_buffer_dirty
= true;
427 /* Wait for the swapbuffers before the one we just emitted, so we
428 * don't get too many swaps outstanding for apps that are GPU-heavy
431 * We're using intelDRI2Flush (called from the loader before
432 * swapbuffer) and glFlush (for front buffer rendering) as the
433 * indicator that a frame is done and then throttle when we get
434 * here as we prepare to render the next frame. At this point for
435 * round trips for swap/copy and getting new buffers are done and
436 * we'll spend less time waiting on the GPU.
438 * Unfortunately, we don't have a handle to the batch containing
439 * the swap, and getting our hands on that doesn't seem worth it,
440 * so we just us the first batch we emitted after the last swap.
442 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
443 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
444 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
445 intel
->first_post_swapbuffers_batch
= NULL
;
446 intel
->need_throttle
= false;
451 intel_viewport(struct gl_context
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
453 struct intel_context
*intel
= intel_context(ctx
);
454 __DRIcontext
*driContext
= intel
->driContext
;
456 if (intel
->saved_viewport
)
457 intel
->saved_viewport(ctx
, x
, y
, w
, h
);
459 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
460 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
461 dri2InvalidateDrawable(driContext
->driReadablePriv
);
465 static const struct dri_debug_control debug_control
[] = {
466 { "tex", DEBUG_TEXTURE
},
467 { "state", DEBUG_STATE
},
468 { "ioctl", DEBUG_IOCTL
},
469 { "blit", DEBUG_BLIT
},
470 { "mip", DEBUG_MIPTREE
},
471 { "fall", DEBUG_PERF
},
472 { "perf", DEBUG_PERF
},
473 { "verb", DEBUG_VERBOSE
},
474 { "bat", DEBUG_BATCH
},
475 { "pix", DEBUG_PIXEL
},
476 { "buf", DEBUG_BUFMGR
},
477 { "reg", DEBUG_REGION
},
481 { "sync", DEBUG_SYNC
},
482 { "prim", DEBUG_PRIMS
},
483 { "vert", DEBUG_VERTS
},
484 { "dri", DEBUG_DRI
},
486 { "san", DEBUG_SANITY
},
487 { "sleep", DEBUG_SLEEP
},
488 { "stats", DEBUG_STATS
},
489 { "tile", DEBUG_TILE
},
491 { "urb", DEBUG_URB
},
493 { "clip", DEBUG_CLIP
},
494 { "aub", DEBUG_AUB
},
495 { "shader_time", DEBUG_SHADER_TIME
},
496 { "no16", DEBUG_NO16
},
502 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
504 struct intel_context
*intel
= intel_context(ctx
);
506 if (ctx
->swrast_context
)
507 _swrast_InvalidateState(ctx
, new_state
);
508 _vbo_InvalidateState(ctx
, new_state
);
510 intel
->NewGLState
|= new_state
;
512 if (intel
->vtbl
.invalidate_state
)
513 intel
->vtbl
.invalidate_state( intel
, new_state
);
517 intel_flush_rendering_to_batch(struct gl_context
*ctx
)
519 struct intel_context
*intel
= intel_context(ctx
);
525 INTEL_FIREVERTICES(intel
);
529 _intel_flush(struct gl_context
*ctx
, const char *file
, int line
)
531 struct intel_context
*intel
= intel_context(ctx
);
533 intel_flush_rendering_to_batch(ctx
);
535 if (intel
->batch
.used
)
536 _intel_batchbuffer_flush(intel
, file
, line
);
540 intel_glFlush(struct gl_context
*ctx
)
542 struct intel_context
*intel
= intel_context(ctx
);
545 intel_flush_front(ctx
);
546 if (intel
->is_front_buffer_rendering
)
547 intel
->need_throttle
= true;
551 intelFinish(struct gl_context
* ctx
)
553 struct intel_context
*intel
= intel_context(ctx
);
556 intel_flush_front(ctx
);
558 if (intel
->batch
.last_bo
)
559 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
563 intelInitDriverFunctions(struct dd_function_table
*functions
)
565 _mesa_init_driver_functions(functions
);
567 functions
->Flush
= intel_glFlush
;
568 functions
->Finish
= intelFinish
;
569 functions
->GetString
= intelGetString
;
570 functions
->UpdateState
= intelInvalidateState
;
572 intelInitTextureFuncs(functions
);
573 intelInitTextureImageFuncs(functions
);
574 intelInitTextureSubImageFuncs(functions
);
575 intelInitTextureCopyImageFuncs(functions
);
576 intelInitClearFuncs(functions
);
577 intelInitBufferFuncs(functions
);
578 intelInitPixelFuncs(functions
);
579 intelInitBufferObjectFuncs(functions
);
580 intel_init_syncobj_functions(functions
);
584 intelInitContext(struct intel_context
*intel
,
586 const struct gl_config
* mesaVis
,
587 __DRIcontext
* driContextPriv
,
588 void *sharedContextPrivate
,
589 struct dd_function_table
*functions
)
591 struct gl_context
*ctx
= &intel
->ctx
;
592 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
593 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
594 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
596 struct gl_config visual
;
598 /* we can't do anything without a connection to the device */
599 if (intelScreen
->bufmgr
== NULL
)
602 /* Can't rely on invalidate events, fall back to glViewport hack */
603 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
) {
604 intel
->saved_viewport
= functions
->Viewport
;
605 functions
->Viewport
= intel_viewport
;
608 if (mesaVis
== NULL
) {
609 memset(&visual
, 0, sizeof visual
);
613 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
615 printf("%s: failed to init mesa context\n", __FUNCTION__
);
619 driContextPriv
->driverPrivate
= intel
;
620 intel
->intelScreen
= intelScreen
;
621 intel
->driContext
= driContextPriv
;
622 intel
->driFd
= sPriv
->fd
;
624 intel
->gen
= intelScreen
->gen
;
626 const int devID
= intelScreen
->deviceID
;
627 if (IS_SNB_GT1(devID
) || IS_IVB_GT1(devID
) || IS_HSW_GT1(devID
))
629 else if (IS_SNB_GT2(devID
) || IS_IVB_GT2(devID
) || IS_HSW_GT2(devID
))
634 if (IS_HASWELL(devID
)) {
635 intel
->is_haswell
= true;
636 } else if (IS_G4X(devID
)) {
637 intel
->is_g4x
= true;
638 } else if (IS_945(devID
)) {
639 intel
->is_945
= true;
642 if (intel
->gen
>= 5) {
643 intel
->needs_ff_sync
= true;
646 intel
->has_separate_stencil
= intel
->intelScreen
->hw_has_separate_stencil
;
647 intel
->must_use_separate_stencil
= intel
->intelScreen
->hw_must_use_separate_stencil
;
648 intel
->has_hiz
= intel
->gen
>= 6 && !intel
->is_haswell
;
649 intel
->has_llc
= intel
->intelScreen
->hw_has_llc
;
650 intel
->has_swizzling
= intel
->intelScreen
->hw_has_swizzling
;
652 memset(&ctx
->TextureFormatSupported
,
653 0, sizeof(ctx
->TextureFormatSupported
));
655 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
656 sPriv
->myNum
, (intel
->gen
>= 4) ? "i965" : "i915");
658 intel
->maxBatchSize
= 4096;
660 intel
->maxBatchSize
= sizeof(intel
->batch
.map
);
662 intel
->bufmgr
= intelScreen
->bufmgr
;
664 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
665 switch (bo_reuse_mode
) {
666 case DRI_CONF_BO_REUSE_DISABLED
:
668 case DRI_CONF_BO_REUSE_ALL
:
669 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
673 ctx
->Const
.MinLineWidth
= 1.0;
674 ctx
->Const
.MinLineWidthAA
= 1.0;
675 ctx
->Const
.MaxLineWidth
= 5.0;
676 ctx
->Const
.MaxLineWidthAA
= 5.0;
677 ctx
->Const
.LineWidthGranularity
= 0.5;
679 ctx
->Const
.MinPointSize
= 1.0;
680 ctx
->Const
.MinPointSizeAA
= 1.0;
681 ctx
->Const
.MaxPointSize
= 255.0;
682 ctx
->Const
.MaxPointSizeAA
= 3.0;
683 ctx
->Const
.PointSizeGranularity
= 1.0;
685 ctx
->Const
.MaxSamples
= 1;
688 ctx
->Const
.MaxClipPlanes
= 8;
690 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
692 /* reinitialize the context point state.
693 * It depend on constants in __struct gl_contextRec::Const
695 _mesa_init_point(ctx
);
697 if (intel
->gen
>= 4) {
698 ctx
->Const
.MaxRenderbufferSize
= 8192;
700 ctx
->Const
.MaxRenderbufferSize
= 2048;
703 /* Initialize the software rasterizer and helper modules.
705 * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for
706 * software fallbacks (which we have to support on legacy GL to do weird
707 * glDrawPixels(), glBitmap(), and other functions).
709 if (intel
->gen
<= 3 || api
!= API_OPENGL_CORE
) {
710 _swrast_CreateContext(ctx
);
713 _vbo_CreateContext(ctx
);
714 if (ctx
->swrast_context
) {
715 _tnl_CreateContext(ctx
);
716 _swsetup_CreateContext(ctx
);
718 /* Configure swrast to match hardware characteristics: */
719 _swrast_allow_pixel_fog(ctx
, false);
720 _swrast_allow_vertex_fog(ctx
, true);
723 _mesa_meta_init(ctx
);
725 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
726 intel
->hw_stipple
= 1;
728 /* XXX FBO: this doesn't seem to be used anywhere */
729 switch (mesaVis
->depthBits
) {
730 case 0: /* what to do in this case? */
732 intel
->polygon_offset_scale
= 1.0;
735 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
743 intel
->polygon_offset_scale
/= 0xffff;
745 intel
->RenderIndex
= ~0;
747 intelInitExtensions(ctx
);
749 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
750 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
751 dri_bufmgr_set_debug(intel
->bufmgr
, true);
752 if ((INTEL_DEBUG
& DEBUG_SHADER_TIME
) && intel
->gen
< 7) {
754 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
755 INTEL_DEBUG
&= ~DEBUG_SHADER_TIME
;
758 if (INTEL_DEBUG
& DEBUG_AUB
)
759 drm_intel_bufmgr_gem_set_aub_dump(intel
->bufmgr
, true);
761 intel_batchbuffer_init(intel
);
763 intel_fbo_init(intel
);
765 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
767 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
769 if (!driQueryOptionb(&intel
->optionCache
, "hiz")) {
770 intel
->has_hiz
= false;
771 /* On gen6, you can only do separate stencil with HIZ. */
773 intel
->has_separate_stencil
= false;
776 intel
->prim
.primitive
= ~0;
778 /* Force all software fallbacks */
780 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
781 fprintf(stderr
, "disabling 3D rasterization\n");
786 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
787 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
788 intel
->always_flush_batch
= 1;
791 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
792 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
793 intel
->always_flush_cache
= 1;
800 intelDestroyContext(__DRIcontext
* driContextPriv
)
802 struct intel_context
*intel
=
803 (struct intel_context
*) driContextPriv
->driverPrivate
;
804 struct gl_context
*ctx
= &intel
->ctx
;
806 assert(intel
); /* should never be null */
808 INTEL_FIREVERTICES(intel
);
810 /* Dump a final BMP in case the application doesn't call SwapBuffers */
811 if (INTEL_DEBUG
& DEBUG_AUB
) {
812 intel_batchbuffer_flush(intel
);
813 aub_dump_bmp(&intel
->ctx
);
816 _mesa_meta_free(&intel
->ctx
);
818 intel
->vtbl
.destroy(intel
);
820 if (ctx
->swrast_context
) {
821 _swsetup_DestroyContext(&intel
->ctx
);
822 _tnl_DestroyContext(&intel
->ctx
);
824 _vbo_DestroyContext(&intel
->ctx
);
826 if (ctx
->swrast_context
)
827 _swrast_DestroyContext(&intel
->ctx
);
828 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
830 intel_batchbuffer_free(intel
);
832 free(intel
->prim
.vb
);
833 intel
->prim
.vb
= NULL
;
834 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
835 intel
->prim
.vb_bo
= NULL
;
836 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
837 intel
->first_post_swapbuffers_batch
= NULL
;
839 driDestroyOptionCache(&intel
->optionCache
);
841 /* free the Mesa context */
842 _mesa_free_context_data(&intel
->ctx
);
844 _math_matrix_dtr(&intel
->ViewportMatrix
);
847 driContextPriv
->driverPrivate
= NULL
;
852 intelUnbindContext(__DRIcontext
* driContextPriv
)
854 /* Unset current context and dispath table */
855 _mesa_make_current(NULL
, NULL
, NULL
);
861 intelMakeCurrent(__DRIcontext
* driContextPriv
,
862 __DRIdrawable
* driDrawPriv
,
863 __DRIdrawable
* driReadPriv
)
865 struct intel_context
*intel
;
866 GET_CURRENT_CONTEXT(curCtx
);
869 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
873 /* According to the glXMakeCurrent() man page: "Pending commands to
874 * the previous context, if any, are flushed before it is released."
875 * But only flush if we're actually changing contexts.
877 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
881 if (driContextPriv
) {
882 struct gl_framebuffer
*fb
, *readFb
;
884 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
885 fb
= _mesa_get_incomplete_framebuffer();
886 readFb
= _mesa_get_incomplete_framebuffer();
888 fb
= driDrawPriv
->driverPrivate
;
889 readFb
= driReadPriv
->driverPrivate
;
890 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
891 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
894 intel_prepare_render(intel
);
895 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
897 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
898 * is NULL at that point. We can't call _mesa_makecurrent()
899 * first, since we need the buffer size for the initial
900 * viewport. So just call intel_draw_buffer() again here. */
901 intel_draw_buffer(&intel
->ctx
);
904 _mesa_make_current(NULL
, NULL
, NULL
);
911 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
913 * To determine which DRI buffers to request, examine the renderbuffers
914 * attached to the drawable's framebuffer. Then request the buffers with
915 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
917 * This is called from intel_update_renderbuffers().
919 * \param drawable Drawable whose buffers are queried.
920 * \param buffers [out] List of buffers returned by DRI2 query.
921 * \param buffer_count [out] Number of buffers returned.
923 * \see intel_update_renderbuffers()
924 * \see DRI2GetBuffers()
925 * \see DRI2GetBuffersWithFormat()
928 intel_query_dri2_buffers(struct intel_context
*intel
,
929 __DRIdrawable
*drawable
,
930 __DRIbuffer
**buffers
,
933 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
934 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
936 const int max_attachments
= 4;
937 unsigned *attachments
= calloc(2 * max_attachments
, sizeof(unsigned));
939 struct intel_renderbuffer
*front_rb
;
940 struct intel_renderbuffer
*back_rb
;
942 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
943 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
945 if ((intel
->is_front_buffer_rendering
||
946 intel
->is_front_buffer_reading
||
947 !back_rb
) && front_rb
) {
948 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
949 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
953 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
954 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
957 assert(i
<= 2 * max_attachments
);
959 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
964 drawable
->loaderPrivate
);
969 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
971 * This is called from intel_update_renderbuffers().
974 * DRI buffers whose attachment point is DRI2BufferStencil or
975 * DRI2BufferDepthStencil are handled as special cases.
977 * \param buffer_name is a human readable name, such as "dri2 front buffer",
978 * that is passed to intel_region_alloc_for_handle().
980 * \see intel_update_renderbuffers()
981 * \see intel_region_alloc_for_handle()
984 intel_process_dri2_buffer(struct intel_context
*intel
,
985 __DRIdrawable
*drawable
,
987 struct intel_renderbuffer
*rb
,
988 const char *buffer_name
)
990 struct intel_region
*region
= NULL
;
995 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
997 /* We try to avoid closing and reopening the same BO name, because the first
998 * use of a mapping of the buffer involves a bunch of page faulting which is
999 * moderately expensive.
1001 if (num_samples
== 0) {
1004 rb
->mt
->region
->name
== buffer
->name
)
1008 rb
->mt
->singlesample_mt
&&
1009 rb
->mt
->singlesample_mt
->region
&&
1010 rb
->mt
->singlesample_mt
->region
->name
== buffer
->name
)
1014 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
1016 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
1017 buffer
->name
, buffer
->attachment
,
1018 buffer
->cpp
, buffer
->pitch
);
1021 intel_miptree_release(&rb
->mt
);
1022 region
= intel_region_alloc_for_handle(intel
->intelScreen
,
1026 buffer
->pitch
/ buffer
->cpp
,
1032 rb
->mt
= intel_miptree_create_for_dri2_buffer(intel
,
1034 intel_rb_format(rb
),
1037 intel_region_release(®ion
);