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 intel_context
*const intel
= intel_context(ctx
);
68 static char buffer
[128];
72 return (GLubyte
*) "Intel Open Source Technology Center";
76 switch (intel
->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
)
97 struct intel_context
*intel
= &brw
->intel
;
99 /* MSAA and fast color clear are not supported, so don't waste time
100 * checking whether a resolve is needed.
105 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
106 struct intel_renderbuffer
*rb
;
108 /* Usually, only the back buffer will need to be downsampled. However,
109 * the front buffer will also need it if the user has rendered into it.
111 static const gl_buffer_index buffers
[2] = {
116 for (int i
= 0; i
< 2; ++i
) {
117 rb
= intel_get_renderbuffer(fb
, buffers
[i
]);
118 if (rb
== NULL
|| rb
->mt
== NULL
)
120 if (rb
->mt
->num_samples
<= 1)
121 intel_miptree_resolve_color(brw
, rb
->mt
);
123 intel_miptree_downsample(brw
, rb
->mt
);
128 intel_flush_front(struct gl_context
*ctx
)
130 struct brw_context
*brw
= brw_context(ctx
);
131 struct intel_context
*intel
= intel_context(ctx
);
132 __DRIcontext
*driContext
= intel
->driContext
;
133 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
134 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
136 if (brw
->front_buffer_dirty
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
137 if (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
&&
139 driDrawable
->loaderPrivate
) {
141 /* Resolve before flushing FAKE_FRONT_LEFT to FRONT_LEFT.
143 * This potentially resolves both front and back buffer. It
144 * is unnecessary to resolve the back, but harms nothing except
145 * performance. And no one cares about front-buffer render
148 intel_resolve_for_dri2_flush(brw
, driDrawable
);
150 screen
->dri2
.loader
->flushFrontBuffer(driDrawable
,
151 driDrawable
->loaderPrivate
);
153 /* We set the dirty bit in intel_prepare_render() if we're
154 * front buffer rendering once we get there.
156 brw
->front_buffer_dirty
= false;
162 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
164 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
168 intel_query_dri2_buffers(struct brw_context
*brw
,
169 __DRIdrawable
*drawable
,
170 __DRIbuffer
**buffers
,
174 intel_process_dri2_buffer(struct brw_context
*brw
,
175 __DRIdrawable
*drawable
,
177 struct intel_renderbuffer
*rb
,
178 const char *buffer_name
);
181 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
183 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
184 struct intel_renderbuffer
*rb
;
185 struct brw_context
*brw
= context
->driverPrivate
;
186 struct intel_context
*intel
= &brw
->intel
;
187 __DRIbuffer
*buffers
= NULL
;
189 const char *region_name
;
191 /* Set this up front, so that in case our buffers get invalidated
192 * while we're getting new buffers, we don't clobber the stamp and
193 * thus ignore the invalidate. */
194 drawable
->lastStamp
= drawable
->dri2
.stamp
;
196 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
197 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
199 intel_query_dri2_buffers(brw
, drawable
, &buffers
, &count
);
204 for (i
= 0; i
< count
; i
++) {
205 switch (buffers
[i
].attachment
) {
206 case __DRI_BUFFER_FRONT_LEFT
:
207 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
208 region_name
= "dri2 front buffer";
211 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
212 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
213 region_name
= "dri2 fake front buffer";
216 case __DRI_BUFFER_BACK_LEFT
:
217 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
218 region_name
= "dri2 back buffer";
221 case __DRI_BUFFER_DEPTH
:
222 case __DRI_BUFFER_HIZ
:
223 case __DRI_BUFFER_DEPTH_STENCIL
:
224 case __DRI_BUFFER_STENCIL
:
225 case __DRI_BUFFER_ACCUM
:
228 "unhandled buffer attach event, attachment type %d\n",
229 buffers
[i
].attachment
);
233 intel_process_dri2_buffer(brw
, drawable
, &buffers
[i
], rb
, region_name
);
236 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
240 * intel_prepare_render should be called anywhere that curent read/drawbuffer
244 intel_prepare_render(struct brw_context
*brw
)
246 struct intel_context
*intel
= &brw
->intel
;
247 __DRIcontext
*driContext
= intel
->driContext
;
248 __DRIdrawable
*drawable
;
250 drawable
= driContext
->driDrawablePriv
;
251 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
252 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
253 intel_update_renderbuffers(driContext
, drawable
);
254 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
257 drawable
= driContext
->driReadablePriv
;
258 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
259 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
260 intel_update_renderbuffers(driContext
, drawable
);
261 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
264 /* If we're currently rendering to the front buffer, the rendering
265 * that will happen next will probably dirty the front buffer. So
266 * mark it as dirty here.
268 if (brw
->is_front_buffer_rendering
)
269 brw
->front_buffer_dirty
= true;
271 /* Wait for the swapbuffers before the one we just emitted, so we
272 * don't get too many swaps outstanding for apps that are GPU-heavy
275 * We're using intelDRI2Flush (called from the loader before
276 * swapbuffer) and glFlush (for front buffer rendering) as the
277 * indicator that a frame is done and then throttle when we get
278 * here as we prepare to render the next frame. At this point for
279 * round trips for swap/copy and getting new buffers are done and
280 * we'll spend less time waiting on the GPU.
282 * Unfortunately, we don't have a handle to the batch containing
283 * the swap, and getting our hands on that doesn't seem worth it,
284 * so we just us the first batch we emitted after the last swap.
286 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
287 if (!brw
->disable_throttling
)
288 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
289 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
290 intel
->first_post_swapbuffers_batch
= NULL
;
291 intel
->need_throttle
= false;
295 static const struct dri_debug_control debug_control
[] = {
296 { "tex", DEBUG_TEXTURE
},
297 { "state", DEBUG_STATE
},
298 { "ioctl", DEBUG_IOCTL
},
299 { "blit", DEBUG_BLIT
},
300 { "mip", DEBUG_MIPTREE
},
301 { "fall", DEBUG_PERF
},
302 { "perf", DEBUG_PERF
},
303 { "bat", DEBUG_BATCH
},
304 { "pix", DEBUG_PIXEL
},
305 { "buf", DEBUG_BUFMGR
},
306 { "reg", DEBUG_REGION
},
310 { "sync", DEBUG_SYNC
},
311 { "prim", DEBUG_PRIMS
},
312 { "vert", DEBUG_VERTS
},
313 { "dri", DEBUG_DRI
},
315 { "stats", DEBUG_STATS
},
317 { "urb", DEBUG_URB
},
319 { "clip", DEBUG_CLIP
},
320 { "aub", DEBUG_AUB
},
321 { "shader_time", DEBUG_SHADER_TIME
},
322 { "no16", DEBUG_NO16
},
323 { "blorp", DEBUG_BLORP
},
329 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
331 struct intel_context
*intel
= intel_context(ctx
);
333 if (ctx
->swrast_context
)
334 _swrast_InvalidateState(ctx
, new_state
);
335 _vbo_InvalidateState(ctx
, new_state
);
337 intel
->NewGLState
|= new_state
;
341 _intel_flush(struct gl_context
*ctx
, const char *file
, int line
)
343 struct brw_context
*brw
= brw_context(ctx
);
344 struct intel_context
*intel
= intel_context(ctx
);
346 if (intel
->batch
.used
)
347 _intel_batchbuffer_flush(brw
, file
, line
);
351 intel_glFlush(struct gl_context
*ctx
)
353 struct brw_context
*brw
= brw_context(ctx
);
354 struct intel_context
*intel
= intel_context(ctx
);
357 intel_flush_front(ctx
);
358 if (brw
->is_front_buffer_rendering
)
359 intel
->need_throttle
= true;
363 intelFinish(struct gl_context
* ctx
)
365 struct intel_context
*intel
= intel_context(ctx
);
368 intel_flush_front(ctx
);
370 if (intel
->batch
.last_bo
)
371 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
375 intelInitDriverFunctions(struct dd_function_table
*functions
)
377 _mesa_init_driver_functions(functions
);
379 functions
->Flush
= intel_glFlush
;
380 functions
->Finish
= intelFinish
;
381 functions
->GetString
= intelGetString
;
382 functions
->UpdateState
= intelInvalidateState
;
384 intelInitTextureFuncs(functions
);
385 intelInitTextureImageFuncs(functions
);
386 intelInitTextureSubImageFuncs(functions
);
387 intelInitTextureCopyImageFuncs(functions
);
388 intelInitClearFuncs(functions
);
389 intelInitBufferFuncs(functions
);
390 intelInitPixelFuncs(functions
);
391 intelInitBufferObjectFuncs(functions
);
392 intel_init_syncobj_functions(functions
);
396 validate_context_version(struct intel_screen
*screen
,
398 unsigned major_version
,
399 unsigned minor_version
,
400 unsigned *dri_ctx_error
)
402 unsigned req_version
= 10 * major_version
+ minor_version
;
403 unsigned max_version
= 0;
406 case API_OPENGL_COMPAT
:
407 max_version
= screen
->max_gl_compat_version
;
409 case API_OPENGL_CORE
:
410 max_version
= screen
->max_gl_core_version
;
413 max_version
= screen
->max_gl_es1_version
;
416 max_version
= screen
->max_gl_es2_version
;
423 if (max_version
== 0) {
424 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_API
;
426 } else if (req_version
> max_version
) {
427 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_VERSION
;
435 intelInitContext(struct brw_context
*brw
,
437 unsigned major_version
,
438 unsigned minor_version
,
439 const struct gl_config
* mesaVis
,
440 __DRIcontext
* driContextPriv
,
441 void *sharedContextPrivate
,
442 struct dd_function_table
*functions
,
443 unsigned *dri_ctx_error
)
445 struct intel_context
*intel
= &brw
->intel
;
446 struct gl_context
*ctx
= &intel
->ctx
;
447 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
448 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
449 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
451 struct gl_config visual
;
453 /* we can't do anything without a connection to the device */
454 if (intelScreen
->bufmgr
== NULL
) {
455 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
459 if (!validate_context_version(intelScreen
,
460 api
, major_version
, minor_version
,
464 if (mesaVis
== NULL
) {
465 memset(&visual
, 0, sizeof visual
);
469 intel
->intelScreen
= intelScreen
;
471 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
473 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
474 printf("%s: failed to init mesa context\n", __FUNCTION__
);
478 driContextPriv
->driverPrivate
= intel
;
479 intel
->driContext
= driContextPriv
;
480 intel
->driFd
= sPriv
->fd
;
482 intel
->gen
= intelScreen
->gen
;
484 const int devID
= intelScreen
->deviceID
;
485 if (IS_SNB_GT1(devID
) || IS_IVB_GT1(devID
) || IS_HSW_GT1(devID
))
487 else if (IS_SNB_GT2(devID
) || IS_IVB_GT2(devID
) || IS_HSW_GT2(devID
))
489 else if (IS_HSW_GT3(devID
))
494 if (IS_HASWELL(devID
)) {
495 intel
->is_haswell
= true;
496 } else if (IS_BAYTRAIL(devID
)) {
497 intel
->is_baytrail
= true;
499 } else if (IS_G4X(devID
)) {
500 intel
->is_g4x
= true;
503 intel
->has_separate_stencil
= intel
->intelScreen
->hw_has_separate_stencil
;
504 intel
->must_use_separate_stencil
= intel
->intelScreen
->hw_must_use_separate_stencil
;
505 intel
->has_hiz
= intel
->gen
>= 6;
506 intel
->has_llc
= intel
->intelScreen
->hw_has_llc
;
507 intel
->has_swizzling
= intel
->intelScreen
->hw_has_swizzling
;
509 memset(&ctx
->TextureFormatSupported
,
510 0, sizeof(ctx
->TextureFormatSupported
));
512 driParseConfigFiles(&brw
->optionCache
, &intelScreen
->optionCache
,
513 sPriv
->myNum
, "i965");
515 /* Estimate the size of the mappable aperture into the GTT. There's an
516 * ioctl to get the whole GTT size, but not one to get the mappable subset.
517 * It turns out it's basically always 256MB, though some ancient hardware
520 uint32_t gtt_size
= 256 * 1024 * 1024;
522 /* We don't want to map two objects such that a memcpy between them would
523 * just fault one mapping in and then the other over and over forever. So
524 * we would need to divide the GTT size by 2. Additionally, some GTT is
525 * taken up by things like the framebuffer and the ringbuffer and such, so
526 * be more conservative.
528 intel
->max_gtt_map_object_size
= gtt_size
/ 4;
530 brw
->bufmgr
= intelScreen
->bufmgr
;
532 bo_reuse_mode
= driQueryOptioni(&brw
->optionCache
, "bo_reuse");
533 switch (bo_reuse_mode
) {
534 case DRI_CONF_BO_REUSE_DISABLED
:
536 case DRI_CONF_BO_REUSE_ALL
:
537 intel_bufmgr_gem_enable_reuse(brw
->bufmgr
);
541 /* Initialize the software rasterizer and helper modules.
543 * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for
544 * software fallbacks (which we have to support on legacy GL to do weird
545 * glDrawPixels(), glBitmap(), and other functions).
547 if (api
!= API_OPENGL_CORE
) {
548 _swrast_CreateContext(ctx
);
551 _vbo_CreateContext(ctx
);
552 if (ctx
->swrast_context
) {
553 _tnl_CreateContext(ctx
);
554 _swsetup_CreateContext(ctx
);
556 /* Configure swrast to match hardware characteristics: */
557 _swrast_allow_pixel_fog(ctx
, false);
558 _swrast_allow_vertex_fog(ctx
, true);
561 _mesa_meta_init(ctx
);
563 intelInitExtensions(ctx
);
565 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
566 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
567 dri_bufmgr_set_debug(brw
->bufmgr
, true);
568 if ((INTEL_DEBUG
& DEBUG_SHADER_TIME
) && intel
->gen
< 7) {
570 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
571 INTEL_DEBUG
&= ~DEBUG_SHADER_TIME
;
573 if (INTEL_DEBUG
& DEBUG_PERF
)
574 intel
->perf_debug
= true;
576 if (INTEL_DEBUG
& DEBUG_AUB
)
577 drm_intel_bufmgr_gem_set_aub_dump(brw
->bufmgr
, true);
579 intel_batchbuffer_init(brw
);
583 if (!driQueryOptionb(&brw
->optionCache
, "hiz")) {
584 intel
->has_hiz
= false;
585 /* On gen6, you can only do separate stencil with HIZ. */
587 intel
->has_separate_stencil
= false;
590 if (driQueryOptionb(&brw
->optionCache
, "always_flush_batch")) {
591 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
592 brw
->always_flush_batch
= 1;
595 if (driQueryOptionb(&brw
->optionCache
, "always_flush_cache")) {
596 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
597 brw
->always_flush_cache
= 1;
600 if (driQueryOptionb(&brw
->optionCache
, "disable_throttling")) {
601 fprintf(stderr
, "disabling flush throttling\n");
602 brw
->disable_throttling
= 1;
609 intelDestroyContext(__DRIcontext
* driContextPriv
)
611 struct brw_context
*brw
=
612 (struct brw_context
*) driContextPriv
->driverPrivate
;
613 struct intel_context
*intel
= &brw
->intel
;
614 struct gl_context
*ctx
= &intel
->ctx
;
616 assert(intel
); /* should never be null */
618 /* Dump a final BMP in case the application doesn't call SwapBuffers */
619 if (INTEL_DEBUG
& DEBUG_AUB
) {
620 intel_batchbuffer_flush(brw
);
621 aub_dump_bmp(&intel
->ctx
);
624 _mesa_meta_free(&intel
->ctx
);
626 brw
->vtbl
.destroy(brw
);
628 if (ctx
->swrast_context
) {
629 _swsetup_DestroyContext(&intel
->ctx
);
630 _tnl_DestroyContext(&intel
->ctx
);
632 _vbo_DestroyContext(&intel
->ctx
);
634 if (ctx
->swrast_context
)
635 _swrast_DestroyContext(&intel
->ctx
);
637 intel_batchbuffer_free(brw
);
639 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
640 intel
->first_post_swapbuffers_batch
= NULL
;
642 driDestroyOptionCache(&brw
->optionCache
);
644 /* free the Mesa context */
645 _mesa_free_context_data(&intel
->ctx
);
648 driContextPriv
->driverPrivate
= NULL
;
653 intelUnbindContext(__DRIcontext
* driContextPriv
)
655 /* Unset current context and dispath table */
656 _mesa_make_current(NULL
, NULL
, NULL
);
662 * Fixes up the context for GLES23 with our default-to-sRGB-capable behavior
663 * on window system framebuffers.
665 * Desktop GL is fairly reasonable in its handling of sRGB: You can ask if
666 * your renderbuffer can do sRGB encode, and you can flip a switch that does
667 * sRGB encode if the renderbuffer can handle it. You can ask specifically
668 * for a visual where you're guaranteed to be capable, but it turns out that
669 * everyone just makes all their ARGB8888 visuals capable and doesn't offer
670 * incapable ones, becuase there's no difference between the two in resources
671 * used. Applications thus get built that accidentally rely on the default
672 * visual choice being sRGB, so we make ours sRGB capable. Everything sounds
675 * But for GLES2/3, they decided that it was silly to not turn on sRGB encode
676 * for sRGB renderbuffers you made with the GL_EXT_texture_sRGB equivalent.
677 * So they removed the enable knob and made it "if the renderbuffer is sRGB
678 * capable, do sRGB encode". Then, for your window system renderbuffers, you
679 * can ask for sRGB visuals and get sRGB encode, or not ask for sRGB visuals
680 * and get no sRGB encode (assuming that both kinds of visual are available).
681 * Thus our choice to support sRGB by default on our visuals for desktop would
682 * result in broken rendering of GLES apps that aren't expecting sRGB encode.
684 * Unfortunately, renderbuffer setup happens before a context is created. So
685 * in intel_screen.c we always set up sRGB, and here, if you're a GLES2/3
686 * context (without an sRGB visual, though we don't have sRGB visuals exposed
687 * yet), we go turn that back off before anyone finds out.
690 intel_gles3_srgb_workaround(struct brw_context
*brw
,
691 struct gl_framebuffer
*fb
)
693 struct intel_context
*intel
= &brw
->intel
;
694 struct gl_context
*ctx
= &intel
->ctx
;
696 if (_mesa_is_desktop_gl(ctx
) || !fb
->Visual
.sRGBCapable
)
699 /* Some day when we support the sRGB capable bit on visuals available for
700 * GLES, we'll need to respect that and not disable things here.
702 fb
->Visual
.sRGBCapable
= false;
703 for (int i
= 0; i
< BUFFER_COUNT
; i
++) {
704 if (fb
->Attachment
[i
].Renderbuffer
&&
705 fb
->Attachment
[i
].Renderbuffer
->Format
== MESA_FORMAT_SARGB8
) {
706 fb
->Attachment
[i
].Renderbuffer
->Format
= MESA_FORMAT_ARGB8888
;
712 intelMakeCurrent(__DRIcontext
* driContextPriv
,
713 __DRIdrawable
* driDrawPriv
,
714 __DRIdrawable
* driReadPriv
)
716 struct brw_context
*brw
;
717 GET_CURRENT_CONTEXT(curCtx
);
720 brw
= (struct brw_context
*) driContextPriv
->driverPrivate
;
724 /* According to the glXMakeCurrent() man page: "Pending commands to
725 * the previous context, if any, are flushed before it is released."
726 * But only flush if we're actually changing contexts.
728 if (brw_context(curCtx
) && brw_context(curCtx
) != brw
) {
732 struct intel_context
*intel
= &brw
->intel
;
734 if (driContextPriv
) {
735 struct gl_context
*ctx
= &intel
->ctx
;
736 struct gl_framebuffer
*fb
, *readFb
;
738 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
739 fb
= _mesa_get_incomplete_framebuffer();
740 readFb
= _mesa_get_incomplete_framebuffer();
742 fb
= driDrawPriv
->driverPrivate
;
743 readFb
= driReadPriv
->driverPrivate
;
744 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
745 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
748 intel_prepare_render(brw
);
749 _mesa_make_current(ctx
, fb
, readFb
);
751 intel_gles3_srgb_workaround(brw
, ctx
->WinSysDrawBuffer
);
752 intel_gles3_srgb_workaround(brw
, ctx
->WinSysReadBuffer
);
755 _mesa_make_current(NULL
, NULL
, NULL
);
762 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
764 * To determine which DRI buffers to request, examine the renderbuffers
765 * attached to the drawable's framebuffer. Then request the buffers with
766 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
768 * This is called from intel_update_renderbuffers().
770 * \param drawable Drawable whose buffers are queried.
771 * \param buffers [out] List of buffers returned by DRI2 query.
772 * \param buffer_count [out] Number of buffers returned.
774 * \see intel_update_renderbuffers()
775 * \see DRI2GetBuffers()
776 * \see DRI2GetBuffersWithFormat()
779 intel_query_dri2_buffers(struct brw_context
*brw
,
780 __DRIdrawable
*drawable
,
781 __DRIbuffer
**buffers
,
784 struct intel_context
*intel
= &brw
->intel
;
785 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
786 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
788 unsigned attachments
[8];
790 struct intel_renderbuffer
*front_rb
;
791 struct intel_renderbuffer
*back_rb
;
793 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
794 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
796 memset(attachments
, 0, sizeof(attachments
));
797 if ((brw
->is_front_buffer_rendering
||
798 brw
->is_front_buffer_reading
||
799 !back_rb
) && front_rb
) {
800 /* If a fake front buffer is in use, then querying for
801 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
802 * the real front buffer to the fake front buffer. So before doing the
803 * query, we need to make sure all the pending drawing has landed in the
806 intel_flush(&intel
->ctx
);
807 intel_flush_front(&intel
->ctx
);
809 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
810 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
811 } else if (front_rb
&& brw
->front_buffer_dirty
) {
812 /* We have pending front buffer rendering, but we aren't querying for a
813 * front buffer. If the front buffer we have is a fake front buffer,
814 * the X server is going to throw it away when it processes the query.
815 * So before doing the query, make sure all the pending drawing has
816 * landed in the real front buffer.
818 intel_flush(&intel
->ctx
);
819 intel_flush_front(&intel
->ctx
);
823 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
824 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
827 assert(i
<= ARRAY_SIZE(attachments
));
829 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
834 drawable
->loaderPrivate
);
838 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
840 * This is called from intel_update_renderbuffers().
843 * DRI buffers whose attachment point is DRI2BufferStencil or
844 * DRI2BufferDepthStencil are handled as special cases.
846 * \param buffer_name is a human readable name, such as "dri2 front buffer",
847 * that is passed to intel_region_alloc_for_handle().
849 * \see intel_update_renderbuffers()
850 * \see intel_region_alloc_for_handle()
853 intel_process_dri2_buffer(struct brw_context
*brw
,
854 __DRIdrawable
*drawable
,
856 struct intel_renderbuffer
*rb
,
857 const char *buffer_name
)
859 struct intel_context
*intel
= &brw
->intel
;
860 struct intel_region
*region
= NULL
;
865 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
867 /* We try to avoid closing and reopening the same BO name, because the first
868 * use of a mapping of the buffer involves a bunch of page faulting which is
869 * moderately expensive.
871 if (num_samples
== 0) {
874 rb
->mt
->region
->name
== buffer
->name
)
878 rb
->mt
->singlesample_mt
&&
879 rb
->mt
->singlesample_mt
->region
&&
880 rb
->mt
->singlesample_mt
->region
->name
== buffer
->name
)
884 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
886 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
887 buffer
->name
, buffer
->attachment
,
888 buffer
->cpp
, buffer
->pitch
);
891 intel_miptree_release(&rb
->mt
);
892 region
= intel_region_alloc_for_handle(intel
->intelScreen
,
902 rb
->mt
= intel_miptree_create_for_dri2_buffer(brw
,
907 intel_region_release(®ion
);