1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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"
61 int INTEL_DEBUG
= (0);
63 const char *const i915_vendor_string
= "Intel Open Source Technology Center";
66 i915_get_renderer_string(unsigned deviceID
)
69 static char buffer
[128];
73 #define CHIPSET(id, symbol, str) case id: chipset = str; break;
74 #include "pci_ids/i915_pci_ids.h"
76 chipset
= "Unknown Intel Chipset";
80 (void) driGetRendererString(buffer
, chipset
, 0);
84 static const GLubyte
*
85 intelGetString(struct gl_context
* ctx
, GLenum name
)
87 const struct intel_context
*const intel
= intel_context(ctx
);
91 return (GLubyte
*) i915_vendor_string
;
95 (GLubyte
*) i915_get_renderer_string(intel
->intelScreen
->deviceID
);
102 #define flushFront(screen) ((screen)->image.loader ? (screen)->image.loader->flushFrontBuffer : (screen)->dri2.loader->flushFrontBuffer)
105 intel_flush_front(struct gl_context
*ctx
)
107 struct intel_context
*intel
= intel_context(ctx
);
108 __DRIcontext
*driContext
= intel
->driContext
;
109 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
110 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
112 if (intel
->front_buffer_dirty
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
113 if (flushFront(screen
) &&
115 driDrawable
->loaderPrivate
) {
116 flushFront(screen
)(driDrawable
, driDrawable
->loaderPrivate
);
118 /* We set the dirty bit in intel_prepare_render() if we're
119 * front buffer rendering once we get there.
121 intel
->front_buffer_dirty
= false;
127 intel_update_image_buffers(struct intel_context
*intel
, __DRIdrawable
*drawable
);
130 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
132 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
136 intel_query_dri2_buffers(struct intel_context
*intel
,
137 __DRIdrawable
*drawable
,
138 __DRIbuffer
**buffers
,
142 intel_process_dri2_buffer(struct intel_context
*intel
,
143 __DRIdrawable
*drawable
,
145 struct intel_renderbuffer
*rb
,
146 const char *buffer_name
);
149 intel_update_dri2_buffers(struct intel_context
*intel
, __DRIdrawable
*drawable
)
151 __DRIbuffer
*buffers
= NULL
;
153 const char *region_name
;
154 struct intel_renderbuffer
*rb
;
155 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
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
);
196 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
198 struct intel_context
*intel
= context
->driverPrivate
;
199 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
201 /* Set this up front, so that in case our buffers get invalidated
202 * while we're getting new buffers, we don't clobber the stamp and
203 * thus ignore the invalidate. */
204 drawable
->lastStamp
= drawable
->dri2
.stamp
;
206 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
207 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
209 if (screen
->image
.loader
)
210 intel_update_image_buffers(intel
, drawable
);
212 intel_update_dri2_buffers(intel
, drawable
);
214 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
218 * intel_prepare_render should be called anywhere that curent read/drawbuffer
222 intel_prepare_render(struct intel_context
*intel
)
224 __DRIcontext
*driContext
= intel
->driContext
;
225 __DRIdrawable
*drawable
;
227 drawable
= driContext
->driDrawablePriv
;
228 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
229 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
230 intel_update_renderbuffers(driContext
, drawable
);
231 intel_draw_buffer(&intel
->ctx
);
232 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
235 drawable
= driContext
->driReadablePriv
;
236 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
237 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
238 intel_update_renderbuffers(driContext
, drawable
);
239 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
242 /* If we're currently rendering to the front buffer, the rendering
243 * that will happen next will probably dirty the front buffer. So
244 * mark it as dirty here.
246 if (intel
->is_front_buffer_rendering
)
247 intel
->front_buffer_dirty
= true;
249 /* Wait for the swapbuffers before the one we just emitted, so we
250 * don't get too many swaps outstanding for apps that are GPU-heavy
253 * We're using intelDRI2Flush (called from the loader before
254 * swapbuffer) and glFlush (for front buffer rendering) as the
255 * indicator that a frame is done and then throttle when we get
256 * here as we prepare to render the next frame. At this point for
257 * round trips for swap/copy and getting new buffers are done and
258 * we'll spend less time waiting on the GPU.
260 * Unfortunately, we don't have a handle to the batch containing
261 * the swap, and getting our hands on that doesn't seem worth it,
262 * so we just us the first batch we emitted after the last swap.
264 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
265 if (!intel
->disable_throttling
)
266 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
267 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
268 intel
->first_post_swapbuffers_batch
= NULL
;
269 intel
->need_throttle
= false;
274 intel_noninvalidate_viewport(struct gl_context
*ctx
)
276 struct intel_context
*intel
= intel_context(ctx
);
277 __DRIcontext
*driContext
= intel
->driContext
;
279 intelCalcViewport(ctx
);
281 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
282 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
283 dri2InvalidateDrawable(driContext
->driReadablePriv
);
288 intel_viewport(struct gl_context
*ctx
)
290 intelCalcViewport(ctx
);
293 static const struct dri_debug_control debug_control
[] = {
294 { "tex", DEBUG_TEXTURE
},
295 { "state", DEBUG_STATE
},
296 { "blit", DEBUG_BLIT
},
297 { "mip", DEBUG_MIPTREE
},
298 { "fall", DEBUG_PERF
},
299 { "perf", DEBUG_PERF
},
300 { "bat", DEBUG_BATCH
},
301 { "pix", DEBUG_PIXEL
},
302 { "buf", DEBUG_BUFMGR
},
303 { "reg", DEBUG_REGION
},
306 { "sync", DEBUG_SYNC
},
307 { "dri", DEBUG_DRI
},
308 { "stats", DEBUG_STATS
},
310 { "aub", DEBUG_AUB
},
316 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
318 struct intel_context
*intel
= intel_context(ctx
);
320 if (ctx
->swrast_context
)
321 _swrast_InvalidateState(ctx
, new_state
);
322 _vbo_InvalidateState(ctx
, new_state
);
324 intel
->NewGLState
|= new_state
;
326 if (intel
->vtbl
.invalidate_state
)
327 intel
->vtbl
.invalidate_state( intel
, new_state
);
331 intel_flush_rendering_to_batch(struct gl_context
*ctx
)
333 struct intel_context
*intel
= intel_context(ctx
);
338 INTEL_FIREVERTICES(intel
);
342 _intel_flush(struct gl_context
*ctx
, const char *file
, int line
)
344 struct intel_context
*intel
= intel_context(ctx
);
346 intel_flush_rendering_to_batch(ctx
);
348 if (intel
->batch
.used
)
349 _intel_batchbuffer_flush(intel
, file
, line
);
353 intel_glFlush(struct gl_context
*ctx
)
355 struct intel_context
*intel
= intel_context(ctx
);
358 intel_flush_front(ctx
);
359 if (intel
->is_front_buffer_rendering
)
360 intel
->need_throttle
= true;
364 intelFinish(struct gl_context
* ctx
)
366 struct intel_context
*intel
= intel_context(ctx
);
369 intel_flush_front(ctx
);
371 if (intel
->batch
.last_bo
)
372 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
376 intelInitDriverFunctions(struct dd_function_table
*functions
)
378 _mesa_init_driver_functions(functions
);
380 functions
->Flush
= intel_glFlush
;
381 functions
->Finish
= intelFinish
;
382 functions
->GetString
= intelGetString
;
383 functions
->UpdateState
= intelInvalidateState
;
385 intelInitTextureFuncs(functions
);
386 intelInitTextureImageFuncs(functions
);
387 intelInitTextureSubImageFuncs(functions
);
388 intelInitTextureCopyImageFuncs(functions
);
389 intelInitClearFuncs(functions
);
390 intelInitBufferFuncs(functions
);
391 intelInitPixelFuncs(functions
);
392 intelInitBufferObjectFuncs(functions
);
393 intel_init_syncobj_functions(functions
);
397 intelInitContext(struct intel_context
*intel
,
399 unsigned major_version
,
400 unsigned minor_version
,
402 const struct gl_config
* mesaVis
,
403 __DRIcontext
* driContextPriv
,
404 void *sharedContextPrivate
,
405 struct dd_function_table
*functions
,
406 unsigned *dri_ctx_error
)
408 struct gl_context
*ctx
= &intel
->ctx
;
409 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
410 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
411 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
414 /* Can't rely on invalidate events, fall back to glViewport hack */
415 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
)
416 functions
->Viewport
= intel_noninvalidate_viewport
;
418 functions
->Viewport
= intel_viewport
;
420 intel
->intelScreen
= intelScreen
;
422 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
424 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
425 printf("%s: failed to init mesa context\n", __FUNCTION__
);
429 driContextPriv
->driverPrivate
= intel
;
430 intel
->driContext
= driContextPriv
;
431 intel
->driFd
= sPriv
->fd
;
433 intel
->gen
= intelScreen
->gen
;
435 const int devID
= intelScreen
->deviceID
;
437 intel
->is_945
= IS_945(devID
);
439 intel
->has_swizzling
= intel
->intelScreen
->hw_has_swizzling
;
441 memset(&ctx
->TextureFormatSupported
,
442 0, sizeof(ctx
->TextureFormatSupported
));
444 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
445 sPriv
->myNum
, "i915");
446 intel
->maxBatchSize
= 4096;
448 /* Estimate the size of the mappable aperture into the GTT. There's an
449 * ioctl to get the whole GTT size, but not one to get the mappable subset.
450 * It turns out it's basically always 256MB, though some ancient hardware
453 uint32_t gtt_size
= 256 * 1024 * 1024;
455 gtt_size
= 128 * 1024 * 1024;
457 /* We don't want to map two objects such that a memcpy between them would
458 * just fault one mapping in and then the other over and over forever. So
459 * we would need to divide the GTT size by 2. Additionally, some GTT is
460 * taken up by things like the framebuffer and the ringbuffer and such, so
461 * be more conservative.
463 intel
->max_gtt_map_object_size
= gtt_size
/ 4;
465 intel
->bufmgr
= intelScreen
->bufmgr
;
467 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
468 switch (bo_reuse_mode
) {
469 case DRI_CONF_BO_REUSE_DISABLED
:
471 case DRI_CONF_BO_REUSE_ALL
:
472 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
476 ctx
->Const
.MinLineWidth
= 1.0;
477 ctx
->Const
.MinLineWidthAA
= 1.0;
478 ctx
->Const
.MaxLineWidth
= 5.0;
479 ctx
->Const
.MaxLineWidthAA
= 5.0;
480 ctx
->Const
.LineWidthGranularity
= 0.5;
482 ctx
->Const
.MinPointSize
= 1.0;
483 ctx
->Const
.MinPointSizeAA
= 1.0;
484 ctx
->Const
.MaxPointSize
= 255.0;
485 ctx
->Const
.MaxPointSizeAA
= 3.0;
486 ctx
->Const
.PointSizeGranularity
= 1.0;
488 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
490 /* reinitialize the context point state.
491 * It depend on constants in __struct gl_contextRec::Const
493 _mesa_init_point(ctx
);
495 ctx
->Const
.MaxRenderbufferSize
= 2048;
497 _swrast_CreateContext(ctx
);
498 _vbo_CreateContext(ctx
);
499 if (ctx
->swrast_context
) {
500 _tnl_CreateContext(ctx
);
501 _swsetup_CreateContext(ctx
);
503 /* Configure swrast to match hardware characteristics: */
504 _swrast_allow_pixel_fog(ctx
, false);
505 _swrast_allow_vertex_fog(ctx
, true);
508 _mesa_meta_init(ctx
);
510 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
511 intel
->hw_stipple
= 1;
513 intel
->RenderIndex
= ~0;
515 intelInitExtensions(ctx
);
517 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
518 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
519 dri_bufmgr_set_debug(intel
->bufmgr
, true);
520 if (INTEL_DEBUG
& DEBUG_PERF
)
521 intel
->perf_debug
= true;
523 if (INTEL_DEBUG
& DEBUG_AUB
)
524 drm_intel_bufmgr_gem_set_aub_dump(intel
->bufmgr
, true);
526 intel_batchbuffer_init(intel
);
528 intel_fbo_init(intel
);
530 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
532 intel
->prim
.primitive
= ~0;
534 /* Force all software fallbacks */
535 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
536 fprintf(stderr
, "disabling 3D rasterization\n");
540 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
541 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
542 intel
->always_flush_batch
= 1;
545 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
546 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
547 intel
->always_flush_cache
= 1;
550 if (driQueryOptionb(&intel
->optionCache
, "disable_throttling")) {
551 fprintf(stderr
, "disabling flush throttling\n");
552 intel
->disable_throttling
= 1;
559 intelDestroyContext(__DRIcontext
* driContextPriv
)
561 struct intel_context
*intel
=
562 (struct intel_context
*) driContextPriv
->driverPrivate
;
563 struct gl_context
*ctx
= &intel
->ctx
;
565 assert(intel
); /* should never be null */
567 INTEL_FIREVERTICES(intel
);
569 /* Dump a final BMP in case the application doesn't call SwapBuffers */
570 if (INTEL_DEBUG
& DEBUG_AUB
) {
571 intel_batchbuffer_flush(intel
);
572 aub_dump_bmp(&intel
->ctx
);
575 _mesa_meta_free(&intel
->ctx
);
577 intel
->vtbl
.destroy(intel
);
579 if (ctx
->swrast_context
) {
580 _swsetup_DestroyContext(&intel
->ctx
);
581 _tnl_DestroyContext(&intel
->ctx
);
583 _vbo_DestroyContext(&intel
->ctx
);
585 if (ctx
->swrast_context
)
586 _swrast_DestroyContext(&intel
->ctx
);
587 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
589 intel_batchbuffer_free(intel
);
591 free(intel
->prim
.vb
);
592 intel
->prim
.vb
= NULL
;
593 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
594 intel
->prim
.vb_bo
= NULL
;
595 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
596 intel
->first_post_swapbuffers_batch
= NULL
;
598 driDestroyOptionCache(&intel
->optionCache
);
600 /* free the Mesa context */
601 _mesa_free_context_data(&intel
->ctx
);
603 _math_matrix_dtr(&intel
->ViewportMatrix
);
606 driContextPriv
->driverPrivate
= NULL
;
611 intelUnbindContext(__DRIcontext
* driContextPriv
)
613 /* Unset current context and dispath table */
614 _mesa_make_current(NULL
, NULL
, NULL
);
620 intelMakeCurrent(__DRIcontext
* driContextPriv
,
621 __DRIdrawable
* driDrawPriv
,
622 __DRIdrawable
* driReadPriv
)
624 struct intel_context
*intel
;
625 GET_CURRENT_CONTEXT(curCtx
);
628 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
632 /* According to the glXMakeCurrent() man page: "Pending commands to
633 * the previous context, if any, are flushed before it is released."
634 * But only flush if we're actually changing contexts.
636 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
640 if (driContextPriv
) {
641 struct gl_context
*ctx
= &intel
->ctx
;
642 struct gl_framebuffer
*fb
, *readFb
;
644 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
645 fb
= _mesa_get_incomplete_framebuffer();
646 readFb
= _mesa_get_incomplete_framebuffer();
648 fb
= driDrawPriv
->driverPrivate
;
649 readFb
= driReadPriv
->driverPrivate
;
650 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
651 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
654 intel_prepare_render(intel
);
655 _mesa_make_current(ctx
, fb
, readFb
);
657 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
658 * is NULL at that point. We can't call _mesa_makecurrent()
659 * first, since we need the buffer size for the initial
660 * viewport. So just call intel_draw_buffer() again here. */
661 intel_draw_buffer(ctx
);
664 _mesa_make_current(NULL
, NULL
, NULL
);
671 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
673 * To determine which DRI buffers to request, examine the renderbuffers
674 * attached to the drawable's framebuffer. Then request the buffers with
675 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
677 * This is called from intel_update_renderbuffers().
679 * \param drawable Drawable whose buffers are queried.
680 * \param buffers [out] List of buffers returned by DRI2 query.
681 * \param buffer_count [out] Number of buffers returned.
683 * \see intel_update_renderbuffers()
684 * \see DRI2GetBuffers()
685 * \see DRI2GetBuffersWithFormat()
688 intel_query_dri2_buffers(struct intel_context
*intel
,
689 __DRIdrawable
*drawable
,
690 __DRIbuffer
**buffers
,
693 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
694 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
696 unsigned attachments
[8];
698 struct intel_renderbuffer
*front_rb
;
699 struct intel_renderbuffer
*back_rb
;
701 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
702 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
704 memset(attachments
, 0, sizeof(attachments
));
705 if ((intel
->is_front_buffer_rendering
||
706 intel
->is_front_buffer_reading
||
707 !back_rb
) && front_rb
) {
708 /* If a fake front buffer is in use, then querying for
709 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
710 * the real front buffer to the fake front buffer. So before doing the
711 * query, we need to make sure all the pending drawing has landed in the
714 intel_flush(&intel
->ctx
);
715 intel_flush_front(&intel
->ctx
);
717 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
718 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
719 } else if (front_rb
&& intel
->front_buffer_dirty
) {
720 /* We have pending front buffer rendering, but we aren't querying for a
721 * front buffer. If the front buffer we have is a fake front buffer,
722 * the X server is going to throw it away when it processes the query.
723 * So before doing the query, make sure all the pending drawing has
724 * landed in the real front buffer.
726 intel_flush(&intel
->ctx
);
727 intel_flush_front(&intel
->ctx
);
731 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
732 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
735 assert(i
<= ARRAY_SIZE(attachments
));
737 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
742 drawable
->loaderPrivate
);
746 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
748 * This is called from intel_update_renderbuffers().
751 * DRI buffers whose attachment point is DRI2BufferStencil or
752 * DRI2BufferDepthStencil are handled as special cases.
754 * \param buffer_name is a human readable name, such as "dri2 front buffer",
755 * that is passed to intel_region_alloc_for_handle().
757 * \see intel_update_renderbuffers()
758 * \see intel_region_alloc_for_handle()
761 intel_process_dri2_buffer(struct intel_context
*intel
,
762 __DRIdrawable
*drawable
,
764 struct intel_renderbuffer
*rb
,
765 const char *buffer_name
)
767 struct intel_region
*region
= NULL
;
772 /* We try to avoid closing and reopening the same BO name, because the first
773 * use of a mapping of the buffer involves a bunch of page faulting which is
774 * moderately expensive.
778 rb
->mt
->region
->name
== buffer
->name
)
781 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
783 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
784 buffer
->name
, buffer
->attachment
,
785 buffer
->cpp
, buffer
->pitch
);
788 intel_miptree_release(&rb
->mt
);
789 region
= intel_region_alloc_for_handle(intel
->intelScreen
,
799 rb
->mt
= intel_miptree_create_for_dri2_buffer(intel
,
803 intel_region_release(®ion
);
807 * \brief Query DRI Image loader to obtain a DRIdrawable's buffers.
809 * To determine which DRI buffers to request, examine the renderbuffers
810 * attached to the drawable's framebuffer. Then request the buffers with
813 * This is called from intel_update_renderbuffers().
815 * \param drawable Drawable whose buffers are queried.
816 * \param buffers [out] List of buffers returned by DRI2 query.
817 * \param buffer_count [out] Number of buffers returned.
819 * \see intel_update_renderbuffers()
823 intel_update_image_buffer(struct intel_context
*intel
,
824 __DRIdrawable
*drawable
,
825 struct intel_renderbuffer
*rb
,
827 enum __DRIimageBufferMask buffer_type
)
829 struct intel_region
*region
= buffer
->region
;
834 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
838 rb
->mt
->region
== region
)
841 intel_miptree_release(&rb
->mt
);
842 rb
->mt
= intel_miptree_create_for_image_buffer(intel
,
851 intel_update_image_buffers(struct intel_context
*intel
, __DRIdrawable
*drawable
)
853 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
854 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
855 struct intel_renderbuffer
*front_rb
;
856 struct intel_renderbuffer
*back_rb
;
857 struct __DRIimageList images
;
859 uint32_t buffer_mask
= 0;
861 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
862 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
865 format
= intel_rb_format(back_rb
);
867 format
= intel_rb_format(front_rb
);
871 if ((intel
->is_front_buffer_rendering
|| intel
->is_front_buffer_reading
|| !back_rb
) && front_rb
)
872 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
875 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
877 (*screen
->image
.loader
->getBuffers
) (drawable
,
878 driGLFormatToImageFormat(format
),
879 &drawable
->dri2
.stamp
,
880 drawable
->loaderPrivate
,
884 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
885 drawable
->w
= images
.front
->width
;
886 drawable
->h
= images
.front
->height
;
887 intel_update_image_buffer(intel
,
891 __DRI_IMAGE_BUFFER_FRONT
);
893 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
894 drawable
->w
= images
.back
->width
;
895 drawable
->h
= images
.back
->height
;
896 intel_update_image_buffer(intel
,
900 __DRI_IMAGE_BUFFER_BACK
);