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 #define CHIPSET(id, symbol, str) case id: chipset = str; break;
82 #include "pci_ids/i915_pci_ids.h"
83 #include "pci_ids/i965_pci_ids.h"
85 chipset
= "Unknown Intel Chipset";
89 (void) driGetRendererString(buffer
, chipset
, 0);
90 return (GLubyte
*) buffer
;
98 intel_flush_front(struct gl_context
*ctx
)
100 struct intel_context
*intel
= intel_context(ctx
);
101 __DRIcontext
*driContext
= intel
->driContext
;
102 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
103 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
105 if (intel
->front_buffer_dirty
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
106 if (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
&&
108 driDrawable
->loaderPrivate
) {
109 screen
->dri2
.loader
->flushFrontBuffer(driDrawable
,
110 driDrawable
->loaderPrivate
);
112 /* We set the dirty bit in intel_prepare_render() if we're
113 * front buffer rendering once we get there.
115 intel
->front_buffer_dirty
= false;
121 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
123 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
127 intel_query_dri2_buffers(struct intel_context
*intel
,
128 __DRIdrawable
*drawable
,
129 __DRIbuffer
**buffers
,
133 intel_process_dri2_buffer(struct intel_context
*intel
,
134 __DRIdrawable
*drawable
,
136 struct intel_renderbuffer
*rb
,
137 const char *buffer_name
);
140 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
142 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
143 struct intel_renderbuffer
*rb
;
144 struct intel_context
*intel
= context
->driverPrivate
;
145 __DRIbuffer
*buffers
= NULL
;
147 const char *region_name
;
149 /* Set this up front, so that in case our buffers get invalidated
150 * while we're getting new buffers, we don't clobber the stamp and
151 * thus ignore the invalidate. */
152 drawable
->lastStamp
= drawable
->dri2
.stamp
;
154 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
155 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
157 intel_query_dri2_buffers(intel
, drawable
, &buffers
, &count
);
162 for (i
= 0; i
< count
; i
++) {
163 switch (buffers
[i
].attachment
) {
164 case __DRI_BUFFER_FRONT_LEFT
:
165 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
166 region_name
= "dri2 front buffer";
169 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
170 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
171 region_name
= "dri2 fake front buffer";
174 case __DRI_BUFFER_BACK_LEFT
:
175 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
176 region_name
= "dri2 back buffer";
179 case __DRI_BUFFER_DEPTH
:
180 case __DRI_BUFFER_HIZ
:
181 case __DRI_BUFFER_DEPTH_STENCIL
:
182 case __DRI_BUFFER_STENCIL
:
183 case __DRI_BUFFER_ACCUM
:
186 "unhandled buffer attach event, attachment type %d\n",
187 buffers
[i
].attachment
);
191 intel_process_dri2_buffer(intel
, drawable
, &buffers
[i
], rb
, region_name
);
194 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
198 * intel_prepare_render should be called anywhere that curent read/drawbuffer
202 intel_prepare_render(struct intel_context
*intel
)
204 __DRIcontext
*driContext
= intel
->driContext
;
205 __DRIdrawable
*drawable
;
207 drawable
= driContext
->driDrawablePriv
;
208 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
209 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
210 intel_update_renderbuffers(driContext
, drawable
);
211 intel_draw_buffer(&intel
->ctx
);
212 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
215 drawable
= driContext
->driReadablePriv
;
216 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
217 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
218 intel_update_renderbuffers(driContext
, drawable
);
219 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
222 /* If we're currently rendering to the front buffer, the rendering
223 * that will happen next will probably dirty the front buffer. So
224 * mark it as dirty here.
226 if (intel
->is_front_buffer_rendering
)
227 intel
->front_buffer_dirty
= true;
229 /* Wait for the swapbuffers before the one we just emitted, so we
230 * don't get too many swaps outstanding for apps that are GPU-heavy
233 * We're using intelDRI2Flush (called from the loader before
234 * swapbuffer) and glFlush (for front buffer rendering) as the
235 * indicator that a frame is done and then throttle when we get
236 * here as we prepare to render the next frame. At this point for
237 * round trips for swap/copy and getting new buffers are done and
238 * we'll spend less time waiting on the GPU.
240 * Unfortunately, we don't have a handle to the batch containing
241 * the swap, and getting our hands on that doesn't seem worth it,
242 * so we just us the first batch we emitted after the last swap.
244 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
245 if (!intel
->disable_throttling
)
246 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
247 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
248 intel
->first_post_swapbuffers_batch
= NULL
;
249 intel
->need_throttle
= false;
254 intel_viewport(struct gl_context
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
256 struct intel_context
*intel
= intel_context(ctx
);
257 __DRIcontext
*driContext
= intel
->driContext
;
259 if (intel
->saved_viewport
)
260 intel
->saved_viewport(ctx
, x
, y
, w
, h
);
262 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
263 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
264 dri2InvalidateDrawable(driContext
->driReadablePriv
);
268 static const struct dri_debug_control debug_control
[] = {
269 { "tex", DEBUG_TEXTURE
},
270 { "state", DEBUG_STATE
},
271 { "ioctl", DEBUG_IOCTL
},
272 { "blit", DEBUG_BLIT
},
273 { "mip", DEBUG_MIPTREE
},
274 { "fall", DEBUG_PERF
},
275 { "perf", DEBUG_PERF
},
276 { "bat", DEBUG_BATCH
},
277 { "pix", DEBUG_PIXEL
},
278 { "buf", DEBUG_BUFMGR
},
279 { "reg", DEBUG_REGION
},
283 { "sync", DEBUG_SYNC
},
284 { "prim", DEBUG_PRIMS
},
285 { "vert", DEBUG_VERTS
},
286 { "dri", DEBUG_DRI
},
288 { "stats", DEBUG_STATS
},
290 { "urb", DEBUG_URB
},
292 { "clip", DEBUG_CLIP
},
293 { "aub", DEBUG_AUB
},
294 { "shader_time", DEBUG_SHADER_TIME
},
295 { "no16", DEBUG_NO16
},
296 { "blorp", DEBUG_BLORP
},
302 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
304 struct intel_context
*intel
= intel_context(ctx
);
306 if (ctx
->swrast_context
)
307 _swrast_InvalidateState(ctx
, new_state
);
308 _vbo_InvalidateState(ctx
, new_state
);
310 intel
->NewGLState
|= new_state
;
312 if (intel
->vtbl
.invalidate_state
)
313 intel
->vtbl
.invalidate_state( intel
, new_state
);
317 intel_flush_rendering_to_batch(struct gl_context
*ctx
)
319 struct intel_context
*intel
= intel_context(ctx
);
325 INTEL_FIREVERTICES(intel
);
329 _intel_flush(struct gl_context
*ctx
, const char *file
, int line
)
331 struct intel_context
*intel
= intel_context(ctx
);
333 intel_flush_rendering_to_batch(ctx
);
335 if (intel
->batch
.used
)
336 _intel_batchbuffer_flush(intel
, file
, line
);
340 intel_glFlush(struct gl_context
*ctx
)
342 struct intel_context
*intel
= intel_context(ctx
);
345 intel_flush_front(ctx
);
346 if (intel
->is_front_buffer_rendering
)
347 intel
->need_throttle
= true;
351 intelFinish(struct gl_context
* ctx
)
353 struct intel_context
*intel
= intel_context(ctx
);
356 intel_flush_front(ctx
);
358 if (intel
->batch
.last_bo
)
359 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
363 intelInitDriverFunctions(struct dd_function_table
*functions
)
365 _mesa_init_driver_functions(functions
);
367 functions
->Flush
= intel_glFlush
;
368 functions
->Finish
= intelFinish
;
369 functions
->GetString
= intelGetString
;
370 functions
->UpdateState
= intelInvalidateState
;
372 intelInitTextureFuncs(functions
);
373 intelInitTextureImageFuncs(functions
);
374 intelInitTextureSubImageFuncs(functions
);
375 intelInitTextureCopyImageFuncs(functions
);
376 intelInitClearFuncs(functions
);
377 intelInitBufferFuncs(functions
);
378 intelInitPixelFuncs(functions
);
379 intelInitBufferObjectFuncs(functions
);
380 intel_init_syncobj_functions(functions
);
384 validate_context_version(struct intel_screen
*screen
,
386 unsigned major_version
,
387 unsigned minor_version
,
388 unsigned *dri_ctx_error
)
390 unsigned req_version
= 10 * major_version
+ minor_version
;
391 unsigned max_version
= 0;
394 case API_OPENGL_COMPAT
:
395 max_version
= screen
->max_gl_compat_version
;
397 case API_OPENGL_CORE
:
398 max_version
= screen
->max_gl_core_version
;
401 max_version
= screen
->max_gl_es1_version
;
404 max_version
= screen
->max_gl_es2_version
;
411 if (max_version
== 0) {
412 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_API
;
414 } else if (req_version
> max_version
) {
415 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_VERSION
;
423 intelInitContext(struct intel_context
*intel
,
425 unsigned major_version
,
426 unsigned minor_version
,
427 const struct gl_config
* mesaVis
,
428 __DRIcontext
* driContextPriv
,
429 void *sharedContextPrivate
,
430 struct dd_function_table
*functions
,
431 unsigned *dri_ctx_error
)
433 struct gl_context
*ctx
= &intel
->ctx
;
434 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
435 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
436 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
438 struct gl_config visual
;
440 /* we can't do anything without a connection to the device */
441 if (intelScreen
->bufmgr
== NULL
) {
442 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
446 if (!validate_context_version(intelScreen
,
447 api
, major_version
, minor_version
,
451 /* Can't rely on invalidate events, fall back to glViewport hack */
452 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
) {
453 intel
->saved_viewport
= functions
->Viewport
;
454 functions
->Viewport
= intel_viewport
;
457 if (mesaVis
== NULL
) {
458 memset(&visual
, 0, sizeof visual
);
462 intel
->intelScreen
= intelScreen
;
464 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
466 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
467 printf("%s: failed to init mesa context\n", __FUNCTION__
);
471 driContextPriv
->driverPrivate
= intel
;
472 intel
->driContext
= driContextPriv
;
473 intel
->driFd
= sPriv
->fd
;
475 intel
->gen
= intelScreen
->gen
;
477 const int devID
= intelScreen
->deviceID
;
478 if (IS_SNB_GT1(devID
) || IS_IVB_GT1(devID
) || IS_HSW_GT1(devID
))
480 else if (IS_SNB_GT2(devID
) || IS_IVB_GT2(devID
) || IS_HSW_GT2(devID
))
482 else if (IS_HSW_GT3(devID
))
487 if (IS_HASWELL(devID
)) {
488 intel
->is_haswell
= true;
489 } else if (IS_BAYTRAIL(devID
)) {
490 intel
->is_baytrail
= true;
492 } else if (IS_G4X(devID
)) {
493 intel
->is_g4x
= true;
494 } else if (IS_945(devID
)) {
495 intel
->is_945
= true;
498 if (intel
->gen
>= 5) {
499 intel
->needs_ff_sync
= true;
502 intel
->has_separate_stencil
= intel
->intelScreen
->hw_has_separate_stencil
;
503 intel
->must_use_separate_stencil
= intel
->intelScreen
->hw_must_use_separate_stencil
;
504 intel
->has_llc
= intel
->intelScreen
->hw_has_llc
;
505 intel
->has_swizzling
= intel
->intelScreen
->hw_has_swizzling
;
507 memset(&ctx
->TextureFormatSupported
,
508 0, sizeof(ctx
->TextureFormatSupported
));
510 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
511 sPriv
->myNum
, (intel
->gen
>= 4) ? "i965" : "i915");
513 intel
->maxBatchSize
= 4096;
515 intel
->maxBatchSize
= BATCH_SZ
;
517 /* Estimate the size of the mappable aperture into the GTT. There's an
518 * ioctl to get the whole GTT size, but not one to get the mappable subset.
519 * It turns out it's basically always 256MB, though some ancient hardware
522 uint32_t gtt_size
= 256 * 1024 * 1024;
524 gtt_size
= 128 * 1024 * 1024;
526 /* We don't want to map two objects such that a memcpy between them would
527 * just fault one mapping in and then the other over and over forever. So
528 * we would need to divide the GTT size by 2. Additionally, some GTT is
529 * taken up by things like the framebuffer and the ringbuffer and such, so
530 * be more conservative.
532 intel
->max_gtt_map_object_size
= gtt_size
/ 4;
534 intel
->bufmgr
= intelScreen
->bufmgr
;
536 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
537 switch (bo_reuse_mode
) {
538 case DRI_CONF_BO_REUSE_DISABLED
:
540 case DRI_CONF_BO_REUSE_ALL
:
541 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
545 ctx
->Const
.MinLineWidth
= 1.0;
546 ctx
->Const
.MinLineWidthAA
= 1.0;
547 ctx
->Const
.MaxLineWidth
= 5.0;
548 ctx
->Const
.MaxLineWidthAA
= 5.0;
549 ctx
->Const
.LineWidthGranularity
= 0.5;
551 ctx
->Const
.MinPointSize
= 1.0;
552 ctx
->Const
.MinPointSizeAA
= 1.0;
553 ctx
->Const
.MaxPointSize
= 255.0;
554 ctx
->Const
.MaxPointSizeAA
= 3.0;
555 ctx
->Const
.PointSizeGranularity
= 1.0;
558 ctx
->Const
.MaxClipPlanes
= 8;
560 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
562 /* reinitialize the context point state.
563 * It depend on constants in __struct gl_contextRec::Const
565 _mesa_init_point(ctx
);
567 if (intel
->gen
>= 4) {
568 ctx
->Const
.MaxRenderbufferSize
= 8192;
570 ctx
->Const
.MaxRenderbufferSize
= 2048;
573 /* Initialize the software rasterizer and helper modules.
575 * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for
576 * software fallbacks (which we have to support on legacy GL to do weird
577 * glDrawPixels(), glBitmap(), and other functions).
579 if (intel
->gen
<= 3 || api
!= API_OPENGL_CORE
) {
580 _swrast_CreateContext(ctx
);
583 _vbo_CreateContext(ctx
);
584 if (ctx
->swrast_context
) {
585 _tnl_CreateContext(ctx
);
586 _swsetup_CreateContext(ctx
);
588 /* Configure swrast to match hardware characteristics: */
589 _swrast_allow_pixel_fog(ctx
, false);
590 _swrast_allow_vertex_fog(ctx
, true);
593 _mesa_meta_init(ctx
);
595 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
596 intel
->hw_stipple
= 1;
598 intel
->RenderIndex
= ~0;
600 intelInitExtensions(ctx
);
602 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
603 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
604 dri_bufmgr_set_debug(intel
->bufmgr
, true);
605 if ((INTEL_DEBUG
& DEBUG_SHADER_TIME
) && intel
->gen
< 7) {
607 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
608 INTEL_DEBUG
&= ~DEBUG_SHADER_TIME
;
610 if (INTEL_DEBUG
& DEBUG_PERF
)
611 intel
->perf_debug
= true;
613 if (INTEL_DEBUG
& DEBUG_AUB
)
614 drm_intel_bufmgr_gem_set_aub_dump(intel
->bufmgr
, true);
616 intel_batchbuffer_init(intel
);
618 intel_fbo_init(intel
);
620 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
622 intel
->prim
.primitive
= ~0;
624 /* Force all software fallbacks */
625 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
626 fprintf(stderr
, "disabling 3D rasterization\n");
630 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
631 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
632 intel
->always_flush_batch
= 1;
635 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
636 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
637 intel
->always_flush_cache
= 1;
640 if (driQueryOptionb(&intel
->optionCache
, "disable_throttling")) {
641 fprintf(stderr
, "disabling flush throttling\n");
642 intel
->disable_throttling
= 1;
649 intelDestroyContext(__DRIcontext
* driContextPriv
)
651 struct intel_context
*intel
=
652 (struct intel_context
*) driContextPriv
->driverPrivate
;
653 struct gl_context
*ctx
= &intel
->ctx
;
655 assert(intel
); /* should never be null */
657 INTEL_FIREVERTICES(intel
);
659 /* Dump a final BMP in case the application doesn't call SwapBuffers */
660 if (INTEL_DEBUG
& DEBUG_AUB
) {
661 intel_batchbuffer_flush(intel
);
662 aub_dump_bmp(&intel
->ctx
);
665 _mesa_meta_free(&intel
->ctx
);
667 intel
->vtbl
.destroy(intel
);
669 if (ctx
->swrast_context
) {
670 _swsetup_DestroyContext(&intel
->ctx
);
671 _tnl_DestroyContext(&intel
->ctx
);
673 _vbo_DestroyContext(&intel
->ctx
);
675 if (ctx
->swrast_context
)
676 _swrast_DestroyContext(&intel
->ctx
);
677 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
679 intel_batchbuffer_free(intel
);
681 free(intel
->prim
.vb
);
682 intel
->prim
.vb
= NULL
;
683 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
684 intel
->prim
.vb_bo
= NULL
;
685 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
686 intel
->first_post_swapbuffers_batch
= NULL
;
688 driDestroyOptionCache(&intel
->optionCache
);
690 /* free the Mesa context */
691 _mesa_free_context_data(&intel
->ctx
);
693 _math_matrix_dtr(&intel
->ViewportMatrix
);
696 driContextPriv
->driverPrivate
= NULL
;
701 intelUnbindContext(__DRIcontext
* driContextPriv
)
703 /* Unset current context and dispath table */
704 _mesa_make_current(NULL
, NULL
, NULL
);
710 * Fixes up the context for GLES23 with our default-to-sRGB-capable behavior
711 * on window system framebuffers.
713 * Desktop GL is fairly reasonable in its handling of sRGB: You can ask if
714 * your renderbuffer can do sRGB encode, and you can flip a switch that does
715 * sRGB encode if the renderbuffer can handle it. You can ask specifically
716 * for a visual where you're guaranteed to be capable, but it turns out that
717 * everyone just makes all their ARGB8888 visuals capable and doesn't offer
718 * incapable ones, becuase there's no difference between the two in resources
719 * used. Applications thus get built that accidentally rely on the default
720 * visual choice being sRGB, so we make ours sRGB capable. Everything sounds
723 * But for GLES2/3, they decided that it was silly to not turn on sRGB encode
724 * for sRGB renderbuffers you made with the GL_EXT_texture_sRGB equivalent.
725 * So they removed the enable knob and made it "if the renderbuffer is sRGB
726 * capable, do sRGB encode". Then, for your window system renderbuffers, you
727 * can ask for sRGB visuals and get sRGB encode, or not ask for sRGB visuals
728 * and get no sRGB encode (assuming that both kinds of visual are available).
729 * Thus our choice to support sRGB by default on our visuals for desktop would
730 * result in broken rendering of GLES apps that aren't expecting sRGB encode.
732 * Unfortunately, renderbuffer setup happens before a context is created. So
733 * in intel_screen.c we always set up sRGB, and here, if you're a GLES2/3
734 * context (without an sRGB visual, though we don't have sRGB visuals exposed
735 * yet), we go turn that back off before anyone finds out.
738 intel_gles3_srgb_workaround(struct intel_context
*intel
,
739 struct gl_framebuffer
*fb
)
741 struct gl_context
*ctx
= &intel
->ctx
;
743 if (_mesa_is_desktop_gl(ctx
) || !fb
->Visual
.sRGBCapable
)
746 /* Some day when we support the sRGB capable bit on visuals available for
747 * GLES, we'll need to respect that and not disable things here.
749 fb
->Visual
.sRGBCapable
= false;
750 for (int i
= 0; i
< BUFFER_COUNT
; i
++) {
751 if (fb
->Attachment
[i
].Renderbuffer
&&
752 fb
->Attachment
[i
].Renderbuffer
->Format
== MESA_FORMAT_SARGB8
) {
753 fb
->Attachment
[i
].Renderbuffer
->Format
= MESA_FORMAT_ARGB8888
;
759 intelMakeCurrent(__DRIcontext
* driContextPriv
,
760 __DRIdrawable
* driDrawPriv
,
761 __DRIdrawable
* driReadPriv
)
763 struct intel_context
*intel
;
764 GET_CURRENT_CONTEXT(curCtx
);
767 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
771 /* According to the glXMakeCurrent() man page: "Pending commands to
772 * the previous context, if any, are flushed before it is released."
773 * But only flush if we're actually changing contexts.
775 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
779 if (driContextPriv
) {
780 struct gl_context
*ctx
= &intel
->ctx
;
781 struct gl_framebuffer
*fb
, *readFb
;
783 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
784 fb
= _mesa_get_incomplete_framebuffer();
785 readFb
= _mesa_get_incomplete_framebuffer();
787 fb
= driDrawPriv
->driverPrivate
;
788 readFb
= driReadPriv
->driverPrivate
;
789 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
790 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
793 intel_prepare_render(intel
);
794 _mesa_make_current(ctx
, fb
, readFb
);
796 intel_gles3_srgb_workaround(intel
, ctx
->WinSysDrawBuffer
);
797 intel_gles3_srgb_workaround(intel
, ctx
->WinSysReadBuffer
);
799 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
800 * is NULL at that point. We can't call _mesa_makecurrent()
801 * first, since we need the buffer size for the initial
802 * viewport. So just call intel_draw_buffer() again here. */
803 intel_draw_buffer(ctx
);
806 _mesa_make_current(NULL
, NULL
, NULL
);
813 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
815 * To determine which DRI buffers to request, examine the renderbuffers
816 * attached to the drawable's framebuffer. Then request the buffers with
817 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
819 * This is called from intel_update_renderbuffers().
821 * \param drawable Drawable whose buffers are queried.
822 * \param buffers [out] List of buffers returned by DRI2 query.
823 * \param buffer_count [out] Number of buffers returned.
825 * \see intel_update_renderbuffers()
826 * \see DRI2GetBuffers()
827 * \see DRI2GetBuffersWithFormat()
830 intel_query_dri2_buffers(struct intel_context
*intel
,
831 __DRIdrawable
*drawable
,
832 __DRIbuffer
**buffers
,
835 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
836 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
838 unsigned attachments
[8];
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 memset(attachments
, 0, sizeof(attachments
));
847 if ((intel
->is_front_buffer_rendering
||
848 intel
->is_front_buffer_reading
||
849 !back_rb
) && front_rb
) {
850 /* If a fake front buffer is in use, then querying for
851 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
852 * the real front buffer to the fake front buffer. So before doing the
853 * query, we need to make sure all the pending drawing has landed in the
856 intel_flush(&intel
->ctx
);
857 intel_flush_front(&intel
->ctx
);
859 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
860 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
861 } else if (front_rb
&& intel
->front_buffer_dirty
) {
862 /* We have pending front buffer rendering, but we aren't querying for a
863 * front buffer. If the front buffer we have is a fake front buffer,
864 * the X server is going to throw it away when it processes the query.
865 * So before doing the query, make sure all the pending drawing has
866 * landed in the real front buffer.
868 intel_flush(&intel
->ctx
);
869 intel_flush_front(&intel
->ctx
);
873 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
874 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
877 assert(i
<= ARRAY_SIZE(attachments
));
879 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
884 drawable
->loaderPrivate
);
888 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
890 * This is called from intel_update_renderbuffers().
893 * DRI buffers whose attachment point is DRI2BufferStencil or
894 * DRI2BufferDepthStencil are handled as special cases.
896 * \param buffer_name is a human readable name, such as "dri2 front buffer",
897 * that is passed to intel_region_alloc_for_handle().
899 * \see intel_update_renderbuffers()
900 * \see intel_region_alloc_for_handle()
903 intel_process_dri2_buffer(struct intel_context
*intel
,
904 __DRIdrawable
*drawable
,
906 struct intel_renderbuffer
*rb
,
907 const char *buffer_name
)
909 struct intel_region
*region
= NULL
;
914 /* We try to avoid closing and reopening the same BO name, because the first
915 * use of a mapping of the buffer involves a bunch of page faulting which is
916 * moderately expensive.
920 rb
->mt
->region
->name
== buffer
->name
)
923 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
925 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
926 buffer
->name
, buffer
->attachment
,
927 buffer
->cpp
, buffer
->pitch
);
930 intel_miptree_release(&rb
->mt
);
931 region
= intel_region_alloc_for_handle(intel
->intelScreen
,
941 rb
->mt
= intel_miptree_create_for_dri2_buffer(intel
,
945 intel_region_release(®ion
);