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/renderbuffer.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
40 #include "drivers/common/driverfuncs.h"
41 #include "drivers/common/meta.h"
43 #include "intel_chipset.h"
44 #include "intel_buffers.h"
45 #include "intel_tex.h"
46 #include "intel_batchbuffer.h"
47 #include "intel_pixel.h"
48 #include "intel_regions.h"
49 #include "intel_buffer_objects.h"
50 #include "intel_fbo.h"
51 #include "intel_bufmgr.h"
52 #include "intel_screen.h"
53 #include "intel_mipmap_tree.h"
56 #include "../glsl/ralloc.h"
59 int INTEL_DEBUG
= (0);
63 static const GLubyte
*
64 intelGetString(struct gl_context
* ctx
, GLenum name
)
66 const struct brw_context
*const brw
= brw_context(ctx
);
68 static char buffer
[128];
72 return (GLubyte
*) "Intel Open Source Technology Center";
76 switch (brw
->intelScreen
->deviceID
) {
78 #define CHIPSET(id, symbol, str) case id: chipset = str; break;
79 #include "pci_ids/i965_pci_ids.h"
81 chipset
= "Unknown Intel Chipset";
85 (void) driGetRendererString(buffer
, chipset
, 0);
86 return (GLubyte
*) buffer
;
94 intel_resolve_for_dri2_flush(struct brw_context
*brw
,
95 __DRIdrawable
*drawable
)
98 /* MSAA and fast color clear are not supported, so don't waste time
99 * checking whether a resolve is needed.
104 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
105 struct intel_renderbuffer
*rb
;
107 /* Usually, only the back buffer will need to be downsampled. However,
108 * the front buffer will also need it if the user has rendered into it.
110 static const gl_buffer_index buffers
[2] = {
115 for (int i
= 0; i
< 2; ++i
) {
116 rb
= intel_get_renderbuffer(fb
, buffers
[i
]);
117 if (rb
== NULL
|| rb
->mt
== NULL
)
119 if (rb
->mt
->num_samples
<= 1)
120 intel_miptree_resolve_color(brw
, rb
->mt
);
122 intel_miptree_downsample(brw
, rb
->mt
);
127 intel_flush_front(struct gl_context
*ctx
)
129 struct brw_context
*brw
= brw_context(ctx
);
130 __DRIcontext
*driContext
= brw
->driContext
;
131 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
132 __DRIscreen
*const screen
= brw
->intelScreen
->driScrnPriv
;
134 if (brw
->front_buffer_dirty
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
135 if (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
&&
137 driDrawable
->loaderPrivate
) {
139 /* Resolve before flushing FAKE_FRONT_LEFT to FRONT_LEFT.
141 * This potentially resolves both front and back buffer. It
142 * is unnecessary to resolve the back, but harms nothing except
143 * performance. And no one cares about front-buffer render
146 intel_resolve_for_dri2_flush(brw
, driDrawable
);
148 screen
->dri2
.loader
->flushFrontBuffer(driDrawable
,
149 driDrawable
->loaderPrivate
);
151 /* We set the dirty bit in intel_prepare_render() if we're
152 * front buffer rendering once we get there.
154 brw
->front_buffer_dirty
= false;
160 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
162 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
166 intel_query_dri2_buffers(struct brw_context
*brw
,
167 __DRIdrawable
*drawable
,
168 __DRIbuffer
**buffers
,
172 intel_process_dri2_buffer(struct brw_context
*brw
,
173 __DRIdrawable
*drawable
,
175 struct intel_renderbuffer
*rb
,
176 const char *buffer_name
);
179 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
181 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
182 struct intel_renderbuffer
*rb
;
183 struct brw_context
*brw
= context
->driverPrivate
;
184 __DRIbuffer
*buffers
= NULL
;
186 const char *region_name
;
188 /* Set this up front, so that in case our buffers get invalidated
189 * while we're getting new buffers, we don't clobber the stamp and
190 * thus ignore the invalidate. */
191 drawable
->lastStamp
= drawable
->dri2
.stamp
;
193 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
194 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
196 intel_query_dri2_buffers(brw
, drawable
, &buffers
, &count
);
201 for (i
= 0; i
< count
; i
++) {
202 switch (buffers
[i
].attachment
) {
203 case __DRI_BUFFER_FRONT_LEFT
:
204 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
205 region_name
= "dri2 front buffer";
208 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
209 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
210 region_name
= "dri2 fake front buffer";
213 case __DRI_BUFFER_BACK_LEFT
:
214 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
215 region_name
= "dri2 back buffer";
218 case __DRI_BUFFER_DEPTH
:
219 case __DRI_BUFFER_HIZ
:
220 case __DRI_BUFFER_DEPTH_STENCIL
:
221 case __DRI_BUFFER_STENCIL
:
222 case __DRI_BUFFER_ACCUM
:
225 "unhandled buffer attach event, attachment type %d\n",
226 buffers
[i
].attachment
);
230 intel_process_dri2_buffer(brw
, drawable
, &buffers
[i
], rb
, region_name
);
233 driUpdateFramebufferSize(&brw
->ctx
, drawable
);
237 * intel_prepare_render should be called anywhere that curent read/drawbuffer
241 intel_prepare_render(struct brw_context
*brw
)
243 __DRIcontext
*driContext
= brw
->driContext
;
244 __DRIdrawable
*drawable
;
246 drawable
= driContext
->driDrawablePriv
;
247 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
248 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
249 intel_update_renderbuffers(driContext
, drawable
);
250 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
253 drawable
= driContext
->driReadablePriv
;
254 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
255 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
256 intel_update_renderbuffers(driContext
, drawable
);
257 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
260 /* If we're currently rendering to the front buffer, the rendering
261 * that will happen next will probably dirty the front buffer. So
262 * mark it as dirty here.
264 if (brw
->is_front_buffer_rendering
)
265 brw
->front_buffer_dirty
= true;
267 /* Wait for the swapbuffers before the one we just emitted, so we
268 * don't get too many swaps outstanding for apps that are GPU-heavy
271 * We're using intelDRI2Flush (called from the loader before
272 * swapbuffer) and glFlush (for front buffer rendering) as the
273 * indicator that a frame is done and then throttle when we get
274 * here as we prepare to render the next frame. At this point for
275 * round trips for swap/copy and getting new buffers are done and
276 * we'll spend less time waiting on the GPU.
278 * Unfortunately, we don't have a handle to the batch containing
279 * the swap, and getting our hands on that doesn't seem worth it,
280 * so we just us the first batch we emitted after the last swap.
282 if (brw
->need_throttle
&& brw
->first_post_swapbuffers_batch
) {
283 if (!brw
->disable_throttling
)
284 drm_intel_bo_wait_rendering(brw
->first_post_swapbuffers_batch
);
285 drm_intel_bo_unreference(brw
->first_post_swapbuffers_batch
);
286 brw
->first_post_swapbuffers_batch
= NULL
;
287 brw
->need_throttle
= false;
291 static const struct dri_debug_control debug_control
[] = {
292 { "tex", DEBUG_TEXTURE
},
293 { "state", DEBUG_STATE
},
294 { "ioctl", DEBUG_IOCTL
},
295 { "blit", DEBUG_BLIT
},
296 { "mip", DEBUG_MIPTREE
},
297 { "fall", DEBUG_PERF
},
298 { "perf", DEBUG_PERF
},
299 { "bat", DEBUG_BATCH
},
300 { "pix", DEBUG_PIXEL
},
301 { "buf", DEBUG_BUFMGR
},
302 { "reg", DEBUG_REGION
},
306 { "sync", DEBUG_SYNC
},
307 { "prim", DEBUG_PRIMS
},
308 { "vert", DEBUG_VERTS
},
309 { "dri", DEBUG_DRI
},
311 { "stats", DEBUG_STATS
},
313 { "urb", DEBUG_URB
},
315 { "clip", DEBUG_CLIP
},
316 { "aub", DEBUG_AUB
},
317 { "shader_time", DEBUG_SHADER_TIME
},
318 { "no16", DEBUG_NO16
},
319 { "blorp", DEBUG_BLORP
},
325 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
327 struct brw_context
*brw
= brw_context(ctx
);
329 if (ctx
->swrast_context
)
330 _swrast_InvalidateState(ctx
, new_state
);
331 _vbo_InvalidateState(ctx
, new_state
);
333 brw
->NewGLState
|= new_state
;
337 _intel_flush(struct gl_context
*ctx
, const char *file
, int line
)
339 struct brw_context
*brw
= brw_context(ctx
);
342 _intel_batchbuffer_flush(brw
, file
, line
);
346 intel_glFlush(struct gl_context
*ctx
)
348 struct brw_context
*brw
= brw_context(ctx
);
351 intel_flush_front(ctx
);
352 if (brw
->is_front_buffer_rendering
)
353 brw
->need_throttle
= true;
357 intelFinish(struct gl_context
* ctx
)
359 struct brw_context
*brw
= brw_context(ctx
);
362 intel_flush_front(ctx
);
364 if (brw
->batch
.last_bo
)
365 drm_intel_bo_wait_rendering(brw
->batch
.last_bo
);
369 intelInitDriverFunctions(struct dd_function_table
*functions
)
371 _mesa_init_driver_functions(functions
);
373 functions
->Flush
= intel_glFlush
;
374 functions
->Finish
= intelFinish
;
375 functions
->GetString
= intelGetString
;
376 functions
->UpdateState
= intelInvalidateState
;
378 intelInitTextureFuncs(functions
);
379 intelInitTextureImageFuncs(functions
);
380 intelInitTextureSubImageFuncs(functions
);
381 intelInitTextureCopyImageFuncs(functions
);
382 intelInitClearFuncs(functions
);
383 intelInitBufferFuncs(functions
);
384 intelInitPixelFuncs(functions
);
385 intelInitBufferObjectFuncs(functions
);
386 intel_init_syncobj_functions(functions
);
390 validate_context_version(struct intel_screen
*screen
,
392 unsigned major_version
,
393 unsigned minor_version
,
394 unsigned *dri_ctx_error
)
396 unsigned req_version
= 10 * major_version
+ minor_version
;
397 unsigned max_version
= 0;
400 case API_OPENGL_COMPAT
:
401 max_version
= screen
->max_gl_compat_version
;
403 case API_OPENGL_CORE
:
404 max_version
= screen
->max_gl_core_version
;
407 max_version
= screen
->max_gl_es1_version
;
410 max_version
= screen
->max_gl_es2_version
;
417 if (max_version
== 0) {
418 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_API
;
420 } else if (req_version
> max_version
) {
421 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_VERSION
;
429 intelInitContext(struct brw_context
*brw
,
431 unsigned major_version
,
432 unsigned minor_version
,
433 const struct gl_config
* mesaVis
,
434 __DRIcontext
* driContextPriv
,
435 void *sharedContextPrivate
,
436 struct dd_function_table
*functions
,
437 unsigned *dri_ctx_error
)
439 struct gl_context
*ctx
= &brw
->ctx
;
440 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
441 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
442 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
444 struct gl_config visual
;
446 /* we can't do anything without a connection to the device */
447 if (intelScreen
->bufmgr
== NULL
) {
448 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
452 if (!validate_context_version(intelScreen
,
453 api
, major_version
, minor_version
,
457 if (mesaVis
== NULL
) {
458 memset(&visual
, 0, sizeof visual
);
462 brw
->intelScreen
= intelScreen
;
464 if (!_mesa_initialize_context(&brw
->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
= brw
;
472 brw
->driContext
= driContextPriv
;
474 brw
->gen
= intelScreen
->gen
;
476 const int devID
= intelScreen
->deviceID
;
477 if (IS_SNB_GT1(devID
) || IS_IVB_GT1(devID
) || IS_HSW_GT1(devID
))
479 else if (IS_SNB_GT2(devID
) || IS_IVB_GT2(devID
) || IS_HSW_GT2(devID
))
481 else if (IS_HSW_GT3(devID
))
486 if (IS_HASWELL(devID
)) {
487 brw
->is_haswell
= true;
488 } else if (IS_BAYTRAIL(devID
)) {
489 brw
->is_baytrail
= true;
491 } else if (IS_G4X(devID
)) {
495 brw
->has_separate_stencil
= brw
->intelScreen
->hw_has_separate_stencil
;
496 brw
->must_use_separate_stencil
= brw
->intelScreen
->hw_must_use_separate_stencil
;
497 brw
->has_hiz
= brw
->gen
>= 6;
498 brw
->has_llc
= brw
->intelScreen
->hw_has_llc
;
499 brw
->has_swizzling
= brw
->intelScreen
->hw_has_swizzling
;
501 memset(&ctx
->TextureFormatSupported
,
502 0, sizeof(ctx
->TextureFormatSupported
));
504 driParseConfigFiles(&brw
->optionCache
, &intelScreen
->optionCache
,
505 sPriv
->myNum
, "i965");
507 /* Estimate the size of the mappable aperture into the GTT. There's an
508 * ioctl to get the whole GTT size, but not one to get the mappable subset.
509 * It turns out it's basically always 256MB, though some ancient hardware
512 uint32_t gtt_size
= 256 * 1024 * 1024;
514 /* We don't want to map two objects such that a memcpy between them would
515 * just fault one mapping in and then the other over and over forever. So
516 * we would need to divide the GTT size by 2. Additionally, some GTT is
517 * taken up by things like the framebuffer and the ringbuffer and such, so
518 * be more conservative.
520 brw
->max_gtt_map_object_size
= gtt_size
/ 4;
522 brw
->bufmgr
= intelScreen
->bufmgr
;
524 bo_reuse_mode
= driQueryOptioni(&brw
->optionCache
, "bo_reuse");
525 switch (bo_reuse_mode
) {
526 case DRI_CONF_BO_REUSE_DISABLED
:
528 case DRI_CONF_BO_REUSE_ALL
:
529 intel_bufmgr_gem_enable_reuse(brw
->bufmgr
);
533 /* Initialize the software rasterizer and helper modules.
535 * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for
536 * software fallbacks (which we have to support on legacy GL to do weird
537 * glDrawPixels(), glBitmap(), and other functions).
539 if (api
!= API_OPENGL_CORE
) {
540 _swrast_CreateContext(ctx
);
543 _vbo_CreateContext(ctx
);
544 if (ctx
->swrast_context
) {
545 _tnl_CreateContext(ctx
);
546 _swsetup_CreateContext(ctx
);
548 /* Configure swrast to match hardware characteristics: */
549 _swrast_allow_pixel_fog(ctx
, false);
550 _swrast_allow_vertex_fog(ctx
, true);
553 _mesa_meta_init(ctx
);
555 intelInitExtensions(ctx
);
557 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
558 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
559 dri_bufmgr_set_debug(brw
->bufmgr
, true);
560 if ((INTEL_DEBUG
& DEBUG_SHADER_TIME
) && brw
->gen
< 7) {
562 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
563 INTEL_DEBUG
&= ~DEBUG_SHADER_TIME
;
565 if (INTEL_DEBUG
& DEBUG_PERF
)
566 brw
->perf_debug
= true;
568 if (INTEL_DEBUG
& DEBUG_AUB
)
569 drm_intel_bufmgr_gem_set_aub_dump(brw
->bufmgr
, true);
571 intel_batchbuffer_init(brw
);
575 if (!driQueryOptionb(&brw
->optionCache
, "hiz")) {
576 brw
->has_hiz
= false;
577 /* On gen6, you can only do separate stencil with HIZ. */
579 brw
->has_separate_stencil
= false;
582 if (driQueryOptionb(&brw
->optionCache
, "always_flush_batch")) {
583 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
584 brw
->always_flush_batch
= 1;
587 if (driQueryOptionb(&brw
->optionCache
, "always_flush_cache")) {
588 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
589 brw
->always_flush_cache
= 1;
592 if (driQueryOptionb(&brw
->optionCache
, "disable_throttling")) {
593 fprintf(stderr
, "disabling flush throttling\n");
594 brw
->disable_throttling
= 1;
601 intelDestroyContext(__DRIcontext
* driContextPriv
)
603 struct brw_context
*brw
=
604 (struct brw_context
*) driContextPriv
->driverPrivate
;
605 struct gl_context
*ctx
= &brw
->ctx
;
607 assert(brw
); /* should never be null */
609 /* Dump a final BMP in case the application doesn't call SwapBuffers */
610 if (INTEL_DEBUG
& DEBUG_AUB
) {
611 intel_batchbuffer_flush(brw
);
612 aub_dump_bmp(&brw
->ctx
);
615 _mesa_meta_free(&brw
->ctx
);
617 brw
->vtbl
.destroy(brw
);
619 if (ctx
->swrast_context
) {
620 _swsetup_DestroyContext(&brw
->ctx
);
621 _tnl_DestroyContext(&brw
->ctx
);
623 _vbo_DestroyContext(&brw
->ctx
);
625 if (ctx
->swrast_context
)
626 _swrast_DestroyContext(&brw
->ctx
);
628 intel_batchbuffer_free(brw
);
630 drm_intel_bo_unreference(brw
->first_post_swapbuffers_batch
);
631 brw
->first_post_swapbuffers_batch
= NULL
;
633 driDestroyOptionCache(&brw
->optionCache
);
635 /* free the Mesa context */
636 _mesa_free_context_data(&brw
->ctx
);
639 driContextPriv
->driverPrivate
= NULL
;
644 intelUnbindContext(__DRIcontext
* driContextPriv
)
646 /* Unset current context and dispath table */
647 _mesa_make_current(NULL
, NULL
, NULL
);
653 * Fixes up the context for GLES23 with our default-to-sRGB-capable behavior
654 * on window system framebuffers.
656 * Desktop GL is fairly reasonable in its handling of sRGB: You can ask if
657 * your renderbuffer can do sRGB encode, and you can flip a switch that does
658 * sRGB encode if the renderbuffer can handle it. You can ask specifically
659 * for a visual where you're guaranteed to be capable, but it turns out that
660 * everyone just makes all their ARGB8888 visuals capable and doesn't offer
661 * incapable ones, becuase there's no difference between the two in resources
662 * used. Applications thus get built that accidentally rely on the default
663 * visual choice being sRGB, so we make ours sRGB capable. Everything sounds
666 * But for GLES2/3, they decided that it was silly to not turn on sRGB encode
667 * for sRGB renderbuffers you made with the GL_EXT_texture_sRGB equivalent.
668 * So they removed the enable knob and made it "if the renderbuffer is sRGB
669 * capable, do sRGB encode". Then, for your window system renderbuffers, you
670 * can ask for sRGB visuals and get sRGB encode, or not ask for sRGB visuals
671 * and get no sRGB encode (assuming that both kinds of visual are available).
672 * Thus our choice to support sRGB by default on our visuals for desktop would
673 * result in broken rendering of GLES apps that aren't expecting sRGB encode.
675 * Unfortunately, renderbuffer setup happens before a context is created. So
676 * in intel_screen.c we always set up sRGB, and here, if you're a GLES2/3
677 * context (without an sRGB visual, though we don't have sRGB visuals exposed
678 * yet), we go turn that back off before anyone finds out.
681 intel_gles3_srgb_workaround(struct brw_context
*brw
,
682 struct gl_framebuffer
*fb
)
684 struct gl_context
*ctx
= &brw
->ctx
;
686 if (_mesa_is_desktop_gl(ctx
) || !fb
->Visual
.sRGBCapable
)
689 /* Some day when we support the sRGB capable bit on visuals available for
690 * GLES, we'll need to respect that and not disable things here.
692 fb
->Visual
.sRGBCapable
= false;
693 for (int i
= 0; i
< BUFFER_COUNT
; i
++) {
694 if (fb
->Attachment
[i
].Renderbuffer
&&
695 fb
->Attachment
[i
].Renderbuffer
->Format
== MESA_FORMAT_SARGB8
) {
696 fb
->Attachment
[i
].Renderbuffer
->Format
= MESA_FORMAT_ARGB8888
;
702 intelMakeCurrent(__DRIcontext
* driContextPriv
,
703 __DRIdrawable
* driDrawPriv
,
704 __DRIdrawable
* driReadPriv
)
706 struct brw_context
*brw
;
707 GET_CURRENT_CONTEXT(curCtx
);
710 brw
= (struct brw_context
*) driContextPriv
->driverPrivate
;
714 /* According to the glXMakeCurrent() man page: "Pending commands to
715 * the previous context, if any, are flushed before it is released."
716 * But only flush if we're actually changing contexts.
718 if (brw_context(curCtx
) && brw_context(curCtx
) != brw
) {
722 if (driContextPriv
) {
723 struct gl_context
*ctx
= &brw
->ctx
;
724 struct gl_framebuffer
*fb
, *readFb
;
726 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
727 fb
= _mesa_get_incomplete_framebuffer();
728 readFb
= _mesa_get_incomplete_framebuffer();
730 fb
= driDrawPriv
->driverPrivate
;
731 readFb
= driReadPriv
->driverPrivate
;
732 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
733 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
736 intel_prepare_render(brw
);
737 _mesa_make_current(ctx
, fb
, readFb
);
739 intel_gles3_srgb_workaround(brw
, ctx
->WinSysDrawBuffer
);
740 intel_gles3_srgb_workaround(brw
, ctx
->WinSysReadBuffer
);
743 _mesa_make_current(NULL
, NULL
, NULL
);
750 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
752 * To determine which DRI buffers to request, examine the renderbuffers
753 * attached to the drawable's framebuffer. Then request the buffers with
754 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
756 * This is called from intel_update_renderbuffers().
758 * \param drawable Drawable whose buffers are queried.
759 * \param buffers [out] List of buffers returned by DRI2 query.
760 * \param buffer_count [out] Number of buffers returned.
762 * \see intel_update_renderbuffers()
763 * \see DRI2GetBuffers()
764 * \see DRI2GetBuffersWithFormat()
767 intel_query_dri2_buffers(struct brw_context
*brw
,
768 __DRIdrawable
*drawable
,
769 __DRIbuffer
**buffers
,
772 __DRIscreen
*screen
= brw
->intelScreen
->driScrnPriv
;
773 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
775 unsigned attachments
[8];
777 struct intel_renderbuffer
*front_rb
;
778 struct intel_renderbuffer
*back_rb
;
780 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
781 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
783 memset(attachments
, 0, sizeof(attachments
));
784 if ((brw
->is_front_buffer_rendering
||
785 brw
->is_front_buffer_reading
||
786 !back_rb
) && front_rb
) {
787 /* If a fake front buffer is in use, then querying for
788 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
789 * the real front buffer to the fake front buffer. So before doing the
790 * query, we need to make sure all the pending drawing has landed in the
793 intel_flush(&brw
->ctx
);
794 intel_flush_front(&brw
->ctx
);
796 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
797 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
798 } else if (front_rb
&& brw
->front_buffer_dirty
) {
799 /* We have pending front buffer rendering, but we aren't querying for a
800 * front buffer. If the front buffer we have is a fake front buffer,
801 * the X server is going to throw it away when it processes the query.
802 * So before doing the query, make sure all the pending drawing has
803 * landed in the real front buffer.
805 intel_flush(&brw
->ctx
);
806 intel_flush_front(&brw
->ctx
);
810 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
811 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
814 assert(i
<= ARRAY_SIZE(attachments
));
816 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
821 drawable
->loaderPrivate
);
825 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
827 * This is called from intel_update_renderbuffers().
830 * DRI buffers whose attachment point is DRI2BufferStencil or
831 * DRI2BufferDepthStencil are handled as special cases.
833 * \param buffer_name is a human readable name, such as "dri2 front buffer",
834 * that is passed to intel_region_alloc_for_handle().
836 * \see intel_update_renderbuffers()
837 * \see intel_region_alloc_for_handle()
840 intel_process_dri2_buffer(struct brw_context
*brw
,
841 __DRIdrawable
*drawable
,
843 struct intel_renderbuffer
*rb
,
844 const char *buffer_name
)
846 struct intel_region
*region
= NULL
;
851 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
853 /* We try to avoid closing and reopening the same BO name, because the first
854 * use of a mapping of the buffer involves a bunch of page faulting which is
855 * moderately expensive.
857 if (num_samples
== 0) {
860 rb
->mt
->region
->name
== buffer
->name
)
864 rb
->mt
->singlesample_mt
&&
865 rb
->mt
->singlesample_mt
->region
&&
866 rb
->mt
->singlesample_mt
->region
->name
== buffer
->name
)
870 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
872 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
873 buffer
->name
, buffer
->attachment
,
874 buffer
->cpp
, buffer
->pitch
);
877 intel_miptree_release(&rb
->mt
);
878 region
= intel_region_alloc_for_handle(brw
->intelScreen
,
888 rb
->mt
= intel_miptree_create_for_dri2_buffer(brw
,
893 intel_region_release(®ion
);