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"
84 chipset
= "Unknown Intel Chipset";
88 (void) driGetRendererString(buffer
, chipset
, 0);
89 return (GLubyte
*) buffer
;
97 intel_flush_front(struct gl_context
*ctx
)
99 struct intel_context
*intel
= intel_context(ctx
);
100 __DRIcontext
*driContext
= intel
->driContext
;
101 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
102 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
104 if (intel
->front_buffer_dirty
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
105 if (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
&&
107 driDrawable
->loaderPrivate
) {
108 screen
->dri2
.loader
->flushFrontBuffer(driDrawable
,
109 driDrawable
->loaderPrivate
);
111 /* We set the dirty bit in intel_prepare_render() if we're
112 * front buffer rendering once we get there.
114 intel
->front_buffer_dirty
= false;
120 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
122 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
126 intel_query_dri2_buffers(struct intel_context
*intel
,
127 __DRIdrawable
*drawable
,
128 __DRIbuffer
**buffers
,
132 intel_process_dri2_buffer(struct intel_context
*intel
,
133 __DRIdrawable
*drawable
,
135 struct intel_renderbuffer
*rb
,
136 const char *buffer_name
);
139 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
141 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
142 struct intel_renderbuffer
*rb
;
143 struct intel_context
*intel
= context
->driverPrivate
;
144 __DRIbuffer
*buffers
= NULL
;
146 const char *region_name
;
148 /* Set this up front, so that in case our buffers get invalidated
149 * while we're getting new buffers, we don't clobber the stamp and
150 * thus ignore the invalidate. */
151 drawable
->lastStamp
= drawable
->dri2
.stamp
;
153 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
154 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
156 intel_query_dri2_buffers(intel
, drawable
, &buffers
, &count
);
161 for (i
= 0; i
< count
; i
++) {
162 switch (buffers
[i
].attachment
) {
163 case __DRI_BUFFER_FRONT_LEFT
:
164 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
165 region_name
= "dri2 front buffer";
168 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
169 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
170 region_name
= "dri2 fake front buffer";
173 case __DRI_BUFFER_BACK_LEFT
:
174 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
175 region_name
= "dri2 back buffer";
178 case __DRI_BUFFER_DEPTH
:
179 case __DRI_BUFFER_HIZ
:
180 case __DRI_BUFFER_DEPTH_STENCIL
:
181 case __DRI_BUFFER_STENCIL
:
182 case __DRI_BUFFER_ACCUM
:
185 "unhandled buffer attach event, attachment type %d\n",
186 buffers
[i
].attachment
);
190 intel_process_dri2_buffer(intel
, drawable
, &buffers
[i
], rb
, region_name
);
193 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
197 * intel_prepare_render should be called anywhere that curent read/drawbuffer
201 intel_prepare_render(struct intel_context
*intel
)
203 __DRIcontext
*driContext
= intel
->driContext
;
204 __DRIdrawable
*drawable
;
206 drawable
= driContext
->driDrawablePriv
;
207 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
208 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
209 intel_update_renderbuffers(driContext
, drawable
);
210 intel_draw_buffer(&intel
->ctx
);
211 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
214 drawable
= driContext
->driReadablePriv
;
215 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
216 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
217 intel_update_renderbuffers(driContext
, drawable
);
218 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
221 /* If we're currently rendering to the front buffer, the rendering
222 * that will happen next will probably dirty the front buffer. So
223 * mark it as dirty here.
225 if (intel
->is_front_buffer_rendering
)
226 intel
->front_buffer_dirty
= true;
228 /* Wait for the swapbuffers before the one we just emitted, so we
229 * don't get too many swaps outstanding for apps that are GPU-heavy
232 * We're using intelDRI2Flush (called from the loader before
233 * swapbuffer) and glFlush (for front buffer rendering) as the
234 * indicator that a frame is done and then throttle when we get
235 * here as we prepare to render the next frame. At this point for
236 * round trips for swap/copy and getting new buffers are done and
237 * we'll spend less time waiting on the GPU.
239 * Unfortunately, we don't have a handle to the batch containing
240 * the swap, and getting our hands on that doesn't seem worth it,
241 * so we just us the first batch we emitted after the last swap.
243 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
244 if (!intel
->disable_throttling
)
245 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
246 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
247 intel
->first_post_swapbuffers_batch
= NULL
;
248 intel
->need_throttle
= false;
253 intel_viewport(struct gl_context
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
255 struct intel_context
*intel
= intel_context(ctx
);
256 __DRIcontext
*driContext
= intel
->driContext
;
258 if (intel
->saved_viewport
)
259 intel
->saved_viewport(ctx
, x
, y
, w
, h
);
261 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
262 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
263 dri2InvalidateDrawable(driContext
->driReadablePriv
);
267 static const struct dri_debug_control debug_control
[] = {
268 { "tex", DEBUG_TEXTURE
},
269 { "state", DEBUG_STATE
},
270 { "blit", DEBUG_BLIT
},
271 { "mip", DEBUG_MIPTREE
},
272 { "fall", DEBUG_PERF
},
273 { "perf", DEBUG_PERF
},
274 { "bat", DEBUG_BATCH
},
275 { "pix", DEBUG_PIXEL
},
276 { "buf", DEBUG_BUFMGR
},
277 { "reg", DEBUG_REGION
},
280 { "sync", DEBUG_SYNC
},
281 { "dri", DEBUG_DRI
},
282 { "stats", DEBUG_STATS
},
284 { "aub", DEBUG_AUB
},
290 intelInvalidateState(struct gl_context
* ctx
, GLuint new_state
)
292 struct intel_context
*intel
= intel_context(ctx
);
294 if (ctx
->swrast_context
)
295 _swrast_InvalidateState(ctx
, new_state
);
296 _vbo_InvalidateState(ctx
, new_state
);
298 intel
->NewGLState
|= new_state
;
300 if (intel
->vtbl
.invalidate_state
)
301 intel
->vtbl
.invalidate_state( intel
, new_state
);
305 intel_flush_rendering_to_batch(struct gl_context
*ctx
)
307 struct intel_context
*intel
= intel_context(ctx
);
312 INTEL_FIREVERTICES(intel
);
316 _intel_flush(struct gl_context
*ctx
, const char *file
, int line
)
318 struct intel_context
*intel
= intel_context(ctx
);
320 intel_flush_rendering_to_batch(ctx
);
322 if (intel
->batch
.used
)
323 _intel_batchbuffer_flush(intel
, file
, line
);
327 intel_glFlush(struct gl_context
*ctx
)
329 struct intel_context
*intel
= intel_context(ctx
);
332 intel_flush_front(ctx
);
333 if (intel
->is_front_buffer_rendering
)
334 intel
->need_throttle
= true;
338 intelFinish(struct gl_context
* ctx
)
340 struct intel_context
*intel
= intel_context(ctx
);
343 intel_flush_front(ctx
);
345 if (intel
->batch
.last_bo
)
346 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
350 intelInitDriverFunctions(struct dd_function_table
*functions
)
352 _mesa_init_driver_functions(functions
);
354 functions
->Flush
= intel_glFlush
;
355 functions
->Finish
= intelFinish
;
356 functions
->GetString
= intelGetString
;
357 functions
->UpdateState
= intelInvalidateState
;
359 intelInitTextureFuncs(functions
);
360 intelInitTextureImageFuncs(functions
);
361 intelInitTextureSubImageFuncs(functions
);
362 intelInitTextureCopyImageFuncs(functions
);
363 intelInitClearFuncs(functions
);
364 intelInitBufferFuncs(functions
);
365 intelInitPixelFuncs(functions
);
366 intelInitBufferObjectFuncs(functions
);
367 intel_init_syncobj_functions(functions
);
371 validate_context_version(struct intel_screen
*screen
,
373 unsigned major_version
,
374 unsigned minor_version
,
375 unsigned *dri_ctx_error
)
377 unsigned req_version
= 10 * major_version
+ minor_version
;
378 unsigned max_version
= 0;
381 case API_OPENGL_COMPAT
:
382 max_version
= screen
->max_gl_compat_version
;
384 case API_OPENGL_CORE
:
385 max_version
= screen
->max_gl_core_version
;
388 max_version
= screen
->max_gl_es1_version
;
391 max_version
= screen
->max_gl_es2_version
;
398 if (max_version
== 0) {
399 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_API
;
401 } else if (req_version
> max_version
) {
402 *dri_ctx_error
= __DRI_CTX_ERROR_BAD_VERSION
;
410 intelInitContext(struct intel_context
*intel
,
412 unsigned major_version
,
413 unsigned minor_version
,
414 const struct gl_config
* mesaVis
,
415 __DRIcontext
* driContextPriv
,
416 void *sharedContextPrivate
,
417 struct dd_function_table
*functions
,
418 unsigned *dri_ctx_error
)
420 struct gl_context
*ctx
= &intel
->ctx
;
421 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
422 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
423 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
425 struct gl_config visual
;
427 /* we can't do anything without a connection to the device */
428 if (intelScreen
->bufmgr
== NULL
) {
429 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
433 if (!validate_context_version(intelScreen
,
434 api
, major_version
, minor_version
,
438 /* Can't rely on invalidate events, fall back to glViewport hack */
439 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
) {
440 intel
->saved_viewport
= functions
->Viewport
;
441 functions
->Viewport
= intel_viewport
;
444 if (mesaVis
== NULL
) {
445 memset(&visual
, 0, sizeof visual
);
449 intel
->intelScreen
= intelScreen
;
451 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
453 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
454 printf("%s: failed to init mesa context\n", __FUNCTION__
);
458 driContextPriv
->driverPrivate
= intel
;
459 intel
->driContext
= driContextPriv
;
460 intel
->driFd
= sPriv
->fd
;
462 intel
->gen
= intelScreen
->gen
;
464 const int devID
= intelScreen
->deviceID
;
466 intel
->is_945
= IS_945(devID
);
468 intel
->has_swizzling
= intel
->intelScreen
->hw_has_swizzling
;
470 memset(&ctx
->TextureFormatSupported
,
471 0, sizeof(ctx
->TextureFormatSupported
));
473 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
474 sPriv
->myNum
, "i915");
475 intel
->maxBatchSize
= 4096;
477 /* Estimate the size of the mappable aperture into the GTT. There's an
478 * ioctl to get the whole GTT size, but not one to get the mappable subset.
479 * It turns out it's basically always 256MB, though some ancient hardware
482 uint32_t gtt_size
= 256 * 1024 * 1024;
484 gtt_size
= 128 * 1024 * 1024;
486 /* We don't want to map two objects such that a memcpy between them would
487 * just fault one mapping in and then the other over and over forever. So
488 * we would need to divide the GTT size by 2. Additionally, some GTT is
489 * taken up by things like the framebuffer and the ringbuffer and such, so
490 * be more conservative.
492 intel
->max_gtt_map_object_size
= gtt_size
/ 4;
494 intel
->bufmgr
= intelScreen
->bufmgr
;
496 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
497 switch (bo_reuse_mode
) {
498 case DRI_CONF_BO_REUSE_DISABLED
:
500 case DRI_CONF_BO_REUSE_ALL
:
501 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
505 ctx
->Const
.MinLineWidth
= 1.0;
506 ctx
->Const
.MinLineWidthAA
= 1.0;
507 ctx
->Const
.MaxLineWidth
= 5.0;
508 ctx
->Const
.MaxLineWidthAA
= 5.0;
509 ctx
->Const
.LineWidthGranularity
= 0.5;
511 ctx
->Const
.MinPointSize
= 1.0;
512 ctx
->Const
.MinPointSizeAA
= 1.0;
513 ctx
->Const
.MaxPointSize
= 255.0;
514 ctx
->Const
.MaxPointSizeAA
= 3.0;
515 ctx
->Const
.PointSizeGranularity
= 1.0;
517 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
519 /* reinitialize the context point state.
520 * It depend on constants in __struct gl_contextRec::Const
522 _mesa_init_point(ctx
);
524 ctx
->Const
.MaxRenderbufferSize
= 2048;
526 _swrast_CreateContext(ctx
);
527 _vbo_CreateContext(ctx
);
528 if (ctx
->swrast_context
) {
529 _tnl_CreateContext(ctx
);
530 _swsetup_CreateContext(ctx
);
532 /* Configure swrast to match hardware characteristics: */
533 _swrast_allow_pixel_fog(ctx
, false);
534 _swrast_allow_vertex_fog(ctx
, true);
537 _mesa_meta_init(ctx
);
539 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
540 intel
->hw_stipple
= 1;
542 intel
->RenderIndex
= ~0;
544 intelInitExtensions(ctx
);
546 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
547 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
548 dri_bufmgr_set_debug(intel
->bufmgr
, true);
549 if (INTEL_DEBUG
& DEBUG_PERF
)
550 intel
->perf_debug
= true;
552 if (INTEL_DEBUG
& DEBUG_AUB
)
553 drm_intel_bufmgr_gem_set_aub_dump(intel
->bufmgr
, true);
555 intel_batchbuffer_init(intel
);
557 intel_fbo_init(intel
);
559 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
561 intel
->prim
.primitive
= ~0;
563 /* Force all software fallbacks */
564 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
565 fprintf(stderr
, "disabling 3D rasterization\n");
569 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
570 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
571 intel
->always_flush_batch
= 1;
574 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
575 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
576 intel
->always_flush_cache
= 1;
579 if (driQueryOptionb(&intel
->optionCache
, "disable_throttling")) {
580 fprintf(stderr
, "disabling flush throttling\n");
581 intel
->disable_throttling
= 1;
588 intelDestroyContext(__DRIcontext
* driContextPriv
)
590 struct intel_context
*intel
=
591 (struct intel_context
*) driContextPriv
->driverPrivate
;
592 struct gl_context
*ctx
= &intel
->ctx
;
594 assert(intel
); /* should never be null */
596 INTEL_FIREVERTICES(intel
);
598 /* Dump a final BMP in case the application doesn't call SwapBuffers */
599 if (INTEL_DEBUG
& DEBUG_AUB
) {
600 intel_batchbuffer_flush(intel
);
601 aub_dump_bmp(&intel
->ctx
);
604 _mesa_meta_free(&intel
->ctx
);
606 intel
->vtbl
.destroy(intel
);
608 if (ctx
->swrast_context
) {
609 _swsetup_DestroyContext(&intel
->ctx
);
610 _tnl_DestroyContext(&intel
->ctx
);
612 _vbo_DestroyContext(&intel
->ctx
);
614 if (ctx
->swrast_context
)
615 _swrast_DestroyContext(&intel
->ctx
);
616 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
618 intel_batchbuffer_free(intel
);
620 free(intel
->prim
.vb
);
621 intel
->prim
.vb
= NULL
;
622 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
623 intel
->prim
.vb_bo
= NULL
;
624 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
625 intel
->first_post_swapbuffers_batch
= NULL
;
627 driDestroyOptionCache(&intel
->optionCache
);
629 /* free the Mesa context */
630 _mesa_free_context_data(&intel
->ctx
);
632 _math_matrix_dtr(&intel
->ViewportMatrix
);
635 driContextPriv
->driverPrivate
= NULL
;
640 intelUnbindContext(__DRIcontext
* driContextPriv
)
642 /* Unset current context and dispath table */
643 _mesa_make_current(NULL
, NULL
, NULL
);
649 intelMakeCurrent(__DRIcontext
* driContextPriv
,
650 __DRIdrawable
* driDrawPriv
,
651 __DRIdrawable
* driReadPriv
)
653 struct intel_context
*intel
;
654 GET_CURRENT_CONTEXT(curCtx
);
657 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
661 /* According to the glXMakeCurrent() man page: "Pending commands to
662 * the previous context, if any, are flushed before it is released."
663 * But only flush if we're actually changing contexts.
665 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
669 if (driContextPriv
) {
670 struct gl_context
*ctx
= &intel
->ctx
;
671 struct gl_framebuffer
*fb
, *readFb
;
673 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
674 fb
= _mesa_get_incomplete_framebuffer();
675 readFb
= _mesa_get_incomplete_framebuffer();
677 fb
= driDrawPriv
->driverPrivate
;
678 readFb
= driReadPriv
->driverPrivate
;
679 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
680 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
683 intel_prepare_render(intel
);
684 _mesa_make_current(ctx
, fb
, readFb
);
686 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
687 * is NULL at that point. We can't call _mesa_makecurrent()
688 * first, since we need the buffer size for the initial
689 * viewport. So just call intel_draw_buffer() again here. */
690 intel_draw_buffer(ctx
);
693 _mesa_make_current(NULL
, NULL
, NULL
);
700 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
702 * To determine which DRI buffers to request, examine the renderbuffers
703 * attached to the drawable's framebuffer. Then request the buffers with
704 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
706 * This is called from intel_update_renderbuffers().
708 * \param drawable Drawable whose buffers are queried.
709 * \param buffers [out] List of buffers returned by DRI2 query.
710 * \param buffer_count [out] Number of buffers returned.
712 * \see intel_update_renderbuffers()
713 * \see DRI2GetBuffers()
714 * \see DRI2GetBuffersWithFormat()
717 intel_query_dri2_buffers(struct intel_context
*intel
,
718 __DRIdrawable
*drawable
,
719 __DRIbuffer
**buffers
,
722 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
723 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
725 unsigned attachments
[8];
727 struct intel_renderbuffer
*front_rb
;
728 struct intel_renderbuffer
*back_rb
;
730 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
731 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
733 memset(attachments
, 0, sizeof(attachments
));
734 if ((intel
->is_front_buffer_rendering
||
735 intel
->is_front_buffer_reading
||
736 !back_rb
) && front_rb
) {
737 /* If a fake front buffer is in use, then querying for
738 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
739 * the real front buffer to the fake front buffer. So before doing the
740 * query, we need to make sure all the pending drawing has landed in the
743 intel_flush(&intel
->ctx
);
744 intel_flush_front(&intel
->ctx
);
746 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
747 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
748 } else if (front_rb
&& intel
->front_buffer_dirty
) {
749 /* We have pending front buffer rendering, but we aren't querying for a
750 * front buffer. If the front buffer we have is a fake front buffer,
751 * the X server is going to throw it away when it processes the query.
752 * So before doing the query, make sure all the pending drawing has
753 * landed in the real front buffer.
755 intel_flush(&intel
->ctx
);
756 intel_flush_front(&intel
->ctx
);
760 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
761 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
764 assert(i
<= ARRAY_SIZE(attachments
));
766 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
771 drawable
->loaderPrivate
);
775 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
777 * This is called from intel_update_renderbuffers().
780 * DRI buffers whose attachment point is DRI2BufferStencil or
781 * DRI2BufferDepthStencil are handled as special cases.
783 * \param buffer_name is a human readable name, such as "dri2 front buffer",
784 * that is passed to intel_region_alloc_for_handle().
786 * \see intel_update_renderbuffers()
787 * \see intel_region_alloc_for_handle()
790 intel_process_dri2_buffer(struct intel_context
*intel
,
791 __DRIdrawable
*drawable
,
793 struct intel_renderbuffer
*rb
,
794 const char *buffer_name
)
796 struct intel_region
*region
= NULL
;
801 /* We try to avoid closing and reopening the same BO name, because the first
802 * use of a mapping of the buffer involves a bunch of page faulting which is
803 * moderately expensive.
807 rb
->mt
->region
->name
== buffer
->name
)
810 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
812 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
813 buffer
->name
, buffer
->attachment
,
814 buffer
->cpp
, buffer
->pitch
);
817 intel_miptree_release(&rb
->mt
);
818 region
= intel_region_alloc_for_handle(intel
->intelScreen
,
828 rb
->mt
= intel_miptree_create_for_dri2_buffer(intel
,
832 intel_region_release(®ion
);