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 "util/debug.h"
60 #include "util/ralloc.h"
62 int INTEL_DEBUG
= (0);
64 const char *const i915_vendor_string
= "Intel Open Source Technology Center";
67 i915_get_renderer_string(unsigned deviceID
)
70 static char buffer
[128];
74 #define CHIPSET(id, symbol, str) case id: chipset = str; break;
75 #include "pci_ids/i915_pci_ids.h"
77 chipset
= "Unknown Intel Chipset";
81 (void) driGetRendererString(buffer
, chipset
, 0);
85 static const GLubyte
*
86 intelGetString(struct gl_context
* ctx
, GLenum name
)
88 const struct intel_context
*const intel
= intel_context(ctx
);
92 return (GLubyte
*) i915_vendor_string
;
96 (GLubyte
*) i915_get_renderer_string(intel
->intelScreen
->deviceID
);
103 #define flushFront(screen) ((screen)->image.loader ? (screen)->image.loader->flushFrontBuffer : (screen)->dri2.loader->flushFrontBuffer)
106 intel_flush_front(struct gl_context
*ctx
)
108 struct intel_context
*intel
= intel_context(ctx
);
109 __DRIcontext
*driContext
= intel
->driContext
;
110 __DRIdrawable
*driDrawable
= driContext
->driDrawablePriv
;
111 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
113 if (intel
->front_buffer_dirty
&& _mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
114 if (flushFront(screen
) &&
116 driDrawable
->loaderPrivate
) {
117 flushFront(screen
)(driDrawable
, driDrawable
->loaderPrivate
);
119 /* We set the dirty bit in intel_prepare_render() if we're
120 * front buffer rendering once we get there.
122 intel
->front_buffer_dirty
= false;
128 intel_update_image_buffers(struct intel_context
*intel
, __DRIdrawable
*drawable
);
131 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
133 return _mesa_get_format_bytes(intel_rb_format(rb
)) * 8;
137 intel_query_dri2_buffers(struct intel_context
*intel
,
138 __DRIdrawable
*drawable
,
139 __DRIbuffer
**buffers
,
143 intel_process_dri2_buffer(struct intel_context
*intel
,
144 __DRIdrawable
*drawable
,
146 struct intel_renderbuffer
*rb
,
147 const char *buffer_name
);
150 intel_update_dri2_buffers(struct intel_context
*intel
, __DRIdrawable
*drawable
)
152 __DRIbuffer
*buffers
= NULL
;
154 const char *region_name
;
155 struct intel_renderbuffer
*rb
;
156 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
158 intel_query_dri2_buffers(intel
, drawable
, &buffers
, &count
);
163 for (i
= 0; i
< count
; i
++) {
164 switch (buffers
[i
].attachment
) {
165 case __DRI_BUFFER_FRONT_LEFT
:
166 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
167 region_name
= "dri2 front buffer";
170 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
171 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
172 region_name
= "dri2 fake front buffer";
175 case __DRI_BUFFER_BACK_LEFT
:
176 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
177 region_name
= "dri2 back buffer";
180 case __DRI_BUFFER_DEPTH
:
181 case __DRI_BUFFER_HIZ
:
182 case __DRI_BUFFER_DEPTH_STENCIL
:
183 case __DRI_BUFFER_STENCIL
:
184 case __DRI_BUFFER_ACCUM
:
187 "unhandled buffer attach event, attachment type %d\n",
188 buffers
[i
].attachment
);
192 intel_process_dri2_buffer(intel
, drawable
, &buffers
[i
], rb
, region_name
);
197 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
199 struct intel_context
*intel
= context
->driverPrivate
;
200 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
202 /* Set this up front, so that in case our buffers get invalidated
203 * while we're getting new buffers, we don't clobber the stamp and
204 * thus ignore the invalidate. */
205 drawable
->lastStamp
= drawable
->dri2
.stamp
;
207 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
))
208 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
210 if (screen
->image
.loader
)
211 intel_update_image_buffers(intel
, drawable
);
213 intel_update_dri2_buffers(intel
, drawable
);
215 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
219 * intel_prepare_render should be called anywhere that curent read/drawbuffer
223 intel_prepare_render(struct intel_context
*intel
)
225 __DRIcontext
*driContext
= intel
->driContext
;
226 __DRIdrawable
*drawable
;
228 drawable
= driContext
->driDrawablePriv
;
229 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.draw_stamp
) {
230 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
231 intel_update_renderbuffers(driContext
, drawable
);
232 intel_draw_buffer(&intel
->ctx
);
233 driContext
->dri2
.draw_stamp
= drawable
->dri2
.stamp
;
236 drawable
= driContext
->driReadablePriv
;
237 if (drawable
&& drawable
->dri2
.stamp
!= driContext
->dri2
.read_stamp
) {
238 if (drawable
->lastStamp
!= drawable
->dri2
.stamp
)
239 intel_update_renderbuffers(driContext
, drawable
);
240 driContext
->dri2
.read_stamp
= drawable
->dri2
.stamp
;
243 /* If we're currently rendering to the front buffer, the rendering
244 * that will happen next will probably dirty the front buffer. So
245 * mark it as dirty here.
247 if (_mesa_is_front_buffer_drawing(intel
->ctx
.DrawBuffer
))
248 intel
->front_buffer_dirty
= true;
250 /* Wait for the swapbuffers before the one we just emitted, so we
251 * don't get too many swaps outstanding for apps that are GPU-heavy
254 * We're using intelDRI2Flush (called from the loader before
255 * swapbuffer) and glFlush (for front buffer rendering) as the
256 * indicator that a frame is done and then throttle when we get
257 * here as we prepare to render the next frame. At this point for
258 * round trips for swap/copy and getting new buffers are done and
259 * we'll spend less time waiting on the GPU.
261 * Unfortunately, we don't have a handle to the batch containing
262 * the swap, and getting our hands on that doesn't seem worth it,
263 * so we just us the first batch we emitted after the last swap.
265 if (intel
->need_throttle
&& intel
->first_post_swapbuffers_batch
) {
266 if (!intel
->disable_throttling
)
267 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
268 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
269 intel
->first_post_swapbuffers_batch
= NULL
;
270 intel
->need_throttle
= false;
275 intel_noninvalidate_viewport(struct gl_context
*ctx
)
277 struct intel_context
*intel
= intel_context(ctx
);
278 __DRIcontext
*driContext
= intel
->driContext
;
280 intelCalcViewport(ctx
);
282 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
283 dri2InvalidateDrawable(driContext
->driDrawablePriv
);
284 dri2InvalidateDrawable(driContext
->driReadablePriv
);
289 intel_viewport(struct gl_context
*ctx
)
291 intelCalcViewport(ctx
);
294 static const struct debug_control debug_control
[] = {
295 { "tex", DEBUG_TEXTURE
},
296 { "state", DEBUG_STATE
},
297 { "blit", DEBUG_BLIT
},
298 { "mip", DEBUG_MIPTREE
},
299 { "fall", DEBUG_PERF
},
300 { "perf", DEBUG_PERF
},
301 { "bat", DEBUG_BATCH
},
302 { "pix", DEBUG_PIXEL
},
303 { "buf", DEBUG_BUFMGR
},
304 { "reg", DEBUG_REGION
},
307 { "sync", DEBUG_SYNC
},
308 { "dri", DEBUG_DRI
},
309 { "stats", DEBUG_STATS
},
311 { "aub", DEBUG_AUB
},
317 intelInvalidateState(struct gl_context
* ctx
)
319 GLuint new_state
= ctx
->NewState
;
320 struct intel_context
*intel
= intel_context(ctx
);
322 if (ctx
->swrast_context
)
323 _swrast_InvalidateState(ctx
, new_state
);
325 intel
->NewGLState
|= new_state
;
327 if (new_state
& (_NEW_SCISSOR
| _NEW_BUFFERS
| _NEW_VIEWPORT
))
328 _mesa_update_draw_buffer_bounds(ctx
, ctx
->DrawBuffer
);
330 if (intel
->vtbl
.invalidate_state
)
331 intel
->vtbl
.invalidate_state( intel
, new_state
);
335 intel_flush_rendering_to_batch(struct gl_context
*ctx
)
337 struct intel_context
*intel
= intel_context(ctx
);
342 INTEL_FIREVERTICES(intel
);
346 _intel_flush(struct gl_context
*ctx
, const char *file
, int line
)
348 struct intel_context
*intel
= intel_context(ctx
);
350 intel_flush_rendering_to_batch(ctx
);
352 if (intel
->batch
.used
)
353 _intel_batchbuffer_flush(intel
, file
, line
);
357 intel_glFlush(struct gl_context
*ctx
)
359 struct intel_context
*intel
= intel_context(ctx
);
362 intel_flush_front(ctx
);
363 if (_mesa_is_front_buffer_drawing(ctx
->DrawBuffer
))
364 intel
->need_throttle
= true;
368 intelFinish(struct gl_context
* ctx
)
370 struct intel_context
*intel
= intel_context(ctx
);
373 intel_flush_front(ctx
);
375 if (intel
->batch
.last_bo
)
376 drm_intel_bo_wait_rendering(intel
->batch
.last_bo
);
380 intelInitDriverFunctions(struct dd_function_table
*functions
)
382 _mesa_init_driver_functions(functions
);
383 _tnl_init_driver_draw_function(functions
);
385 functions
->Flush
= intel_glFlush
;
386 functions
->Finish
= intelFinish
;
387 functions
->GetString
= intelGetString
;
388 functions
->UpdateState
= intelInvalidateState
;
390 intelInitTextureFuncs(functions
);
391 intelInitTextureImageFuncs(functions
);
392 intelInitTextureSubImageFuncs(functions
);
393 intelInitTextureCopyImageFuncs(functions
);
394 intelInitClearFuncs(functions
);
395 intelInitBufferFuncs(functions
);
396 intelInitPixelFuncs(functions
);
397 intelInitBufferObjectFuncs(functions
);
398 intel_init_syncobj_functions(functions
);
402 intelInitContext(struct intel_context
*intel
,
404 unsigned major_version
,
405 unsigned minor_version
,
407 const struct gl_config
* mesaVis
,
408 __DRIcontext
* driContextPriv
,
409 void *sharedContextPrivate
,
410 struct dd_function_table
*functions
,
411 unsigned *dri_ctx_error
)
413 struct gl_context
*ctx
= &intel
->ctx
;
414 struct gl_context
*shareCtx
= (struct gl_context
*) sharedContextPrivate
;
415 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
416 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
419 /* Can't rely on invalidate events, fall back to glViewport hack */
420 if (!driContextPriv
->driScreenPriv
->dri2
.useInvalidate
)
421 functions
->Viewport
= intel_noninvalidate_viewport
;
423 functions
->Viewport
= intel_viewport
;
425 intel
->intelScreen
= intelScreen
;
427 if (!_mesa_initialize_context(&intel
->ctx
, api
, mesaVis
, shareCtx
,
429 *dri_ctx_error
= __DRI_CTX_ERROR_NO_MEMORY
;
430 printf("%s: failed to init mesa context\n", __func__
);
434 driContextSetFlags(&intel
->ctx
, flags
);
436 driContextPriv
->driverPrivate
= intel
;
437 intel
->driContext
= driContextPriv
;
439 intel
->gen
= intelScreen
->gen
;
441 const int devID
= intelScreen
->deviceID
;
443 intel
->is_945
= IS_945(devID
);
445 intel
->has_swizzling
= intel
->intelScreen
->hw_has_swizzling
;
447 memset(&ctx
->TextureFormatSupported
,
448 0, sizeof(ctx
->TextureFormatSupported
));
450 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
451 sPriv
->myNum
, "i915");
452 intel
->maxBatchSize
= 4096;
454 /* Estimate the size of the mappable aperture into the GTT. There's an
455 * ioctl to get the whole GTT size, but not one to get the mappable subset.
456 * It turns out it's basically always 256MB, though some ancient hardware
459 uint32_t gtt_size
= 256 * 1024 * 1024;
461 gtt_size
= 128 * 1024 * 1024;
463 /* We don't want to map two objects such that a memcpy between them would
464 * just fault one mapping in and then the other over and over forever. So
465 * we would need to divide the GTT size by 2. Additionally, some GTT is
466 * taken up by things like the framebuffer and the ringbuffer and such, so
467 * be more conservative.
469 intel
->max_gtt_map_object_size
= gtt_size
/ 4;
471 intel
->bufmgr
= intelScreen
->bufmgr
;
473 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
474 switch (bo_reuse_mode
) {
475 case DRI_CONF_BO_REUSE_DISABLED
:
477 case DRI_CONF_BO_REUSE_ALL
:
478 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
482 ctx
->Const
.MinLineWidth
= 1.0;
483 ctx
->Const
.MinLineWidthAA
= 1.0;
484 ctx
->Const
.MaxLineWidth
= 7.0;
485 ctx
->Const
.MaxLineWidthAA
= 7.0;
486 ctx
->Const
.LineWidthGranularity
= 0.5;
488 ctx
->Const
.MinPointSize
= 1.0;
489 ctx
->Const
.MinPointSizeAA
= 1.0;
490 ctx
->Const
.MaxPointSize
= 255.0;
491 ctx
->Const
.MaxPointSizeAA
= 3.0;
492 ctx
->Const
.PointSizeGranularity
= 1.0;
494 ctx
->Const
.StripTextureBorder
= GL_TRUE
;
496 /* reinitialize the context point state.
497 * It depend on constants in __struct gl_contextRec::Const
499 _mesa_init_point(ctx
);
501 ctx
->Const
.MaxRenderbufferSize
= 2048;
503 _swrast_CreateContext(ctx
);
504 _vbo_CreateContext(ctx
);
505 if (ctx
->swrast_context
) {
506 _tnl_CreateContext(ctx
);
507 _swsetup_CreateContext(ctx
);
509 /* Configure swrast to match hardware characteristics: */
510 _swrast_allow_pixel_fog(ctx
, false);
511 _swrast_allow_vertex_fog(ctx
, true);
514 _mesa_meta_init(ctx
);
516 intel
->hw_stipple
= 1;
518 intel
->RenderIndex
= ~0;
520 intelInitExtensions(ctx
);
522 INTEL_DEBUG
= parse_debug_string(getenv("INTEL_DEBUG"), debug_control
);
523 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
524 dri_bufmgr_set_debug(intel
->bufmgr
, true);
525 if (INTEL_DEBUG
& DEBUG_PERF
)
526 intel
->perf_debug
= true;
528 if (INTEL_DEBUG
& DEBUG_AUB
)
529 drm_intel_bufmgr_gem_set_aub_dump(intel
->bufmgr
, true);
531 intel_batchbuffer_init(intel
);
533 intel_fbo_init(intel
);
535 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
537 intel
->prim
.primitive
= ~0;
539 /* Force all software fallbacks */
540 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
541 fprintf(stderr
, "disabling 3D rasterization\n");
545 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
546 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
547 intel
->always_flush_batch
= 1;
550 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
551 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
552 intel
->always_flush_cache
= 1;
555 if (driQueryOptionb(&intel
->optionCache
, "disable_throttling")) {
556 fprintf(stderr
, "disabling flush throttling\n");
557 intel
->disable_throttling
= 1;
564 intelDestroyContext(__DRIcontext
* driContextPriv
)
566 struct intel_context
*intel
=
567 (struct intel_context
*) driContextPriv
->driverPrivate
;
568 struct gl_context
*ctx
= &intel
->ctx
;
570 assert(intel
); /* should never be null */
572 INTEL_FIREVERTICES(intel
);
574 /* Dump a final BMP in case the application doesn't call SwapBuffers */
575 if (INTEL_DEBUG
& DEBUG_AUB
) {
576 intel_batchbuffer_flush(intel
);
577 aub_dump_bmp(&intel
->ctx
);
580 _mesa_meta_free(&intel
->ctx
);
582 intel
->vtbl
.destroy(intel
);
584 if (ctx
->swrast_context
) {
585 _swsetup_DestroyContext(&intel
->ctx
);
586 _tnl_DestroyContext(&intel
->ctx
);
588 _vbo_DestroyContext(&intel
->ctx
);
590 if (ctx
->swrast_context
)
591 _swrast_DestroyContext(&intel
->ctx
);
592 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
594 intel_batchbuffer_free(intel
);
596 free(intel
->prim
.vb
);
597 intel
->prim
.vb
= NULL
;
598 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
599 intel
->prim
.vb_bo
= NULL
;
600 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
601 intel
->first_post_swapbuffers_batch
= NULL
;
603 driDestroyOptionCache(&intel
->optionCache
);
605 /* free the Mesa context */
606 _mesa_free_context_data(&intel
->ctx
);
608 _math_matrix_dtr(&intel
->ViewportMatrix
);
611 driContextPriv
->driverPrivate
= NULL
;
616 intelUnbindContext(__DRIcontext
* driContextPriv
)
618 /* Unset current context and dispath table */
619 _mesa_make_current(NULL
, NULL
, NULL
);
625 intelMakeCurrent(__DRIcontext
* driContextPriv
,
626 __DRIdrawable
* driDrawPriv
,
627 __DRIdrawable
* driReadPriv
)
629 struct intel_context
*intel
;
632 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
636 if (driContextPriv
) {
637 struct gl_context
*ctx
= &intel
->ctx
;
638 struct gl_framebuffer
*fb
, *readFb
;
640 if (driDrawPriv
== NULL
&& driReadPriv
== NULL
) {
641 fb
= _mesa_get_incomplete_framebuffer();
642 readFb
= _mesa_get_incomplete_framebuffer();
644 fb
= driDrawPriv
->driverPrivate
;
645 readFb
= driReadPriv
->driverPrivate
;
646 driContextPriv
->dri2
.draw_stamp
= driDrawPriv
->dri2
.stamp
- 1;
647 driContextPriv
->dri2
.read_stamp
= driReadPriv
->dri2
.stamp
- 1;
650 intel_prepare_render(intel
);
651 _mesa_make_current(ctx
, fb
, readFb
);
653 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
654 * is NULL at that point. We can't call _mesa_makecurrent()
655 * first, since we need the buffer size for the initial
656 * viewport. So just call intel_draw_buffer() again here. */
657 intel_draw_buffer(ctx
);
660 _mesa_make_current(NULL
, NULL
, NULL
);
667 * \brief Query DRI2 to obtain a DRIdrawable's buffers.
669 * To determine which DRI buffers to request, examine the renderbuffers
670 * attached to the drawable's framebuffer. Then request the buffers with
671 * DRI2GetBuffers() or DRI2GetBuffersWithFormat().
673 * This is called from intel_update_renderbuffers().
675 * \param drawable Drawable whose buffers are queried.
676 * \param buffers [out] List of buffers returned by DRI2 query.
677 * \param buffer_count [out] Number of buffers returned.
679 * \see intel_update_renderbuffers()
680 * \see DRI2GetBuffers()
681 * \see DRI2GetBuffersWithFormat()
684 intel_query_dri2_buffers(struct intel_context
*intel
,
685 __DRIdrawable
*drawable
,
686 __DRIbuffer
**buffers
,
689 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
690 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
692 unsigned attachments
[8];
694 struct intel_renderbuffer
*front_rb
;
695 struct intel_renderbuffer
*back_rb
;
697 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
698 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
700 memset(attachments
, 0, sizeof(attachments
));
701 if ((_mesa_is_front_buffer_drawing(fb
) ||
702 _mesa_is_front_buffer_reading(fb
) ||
703 !back_rb
) && front_rb
) {
704 /* If a fake front buffer is in use, then querying for
705 * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
706 * the real front buffer to the fake front buffer. So before doing the
707 * query, we need to make sure all the pending drawing has landed in the
710 intel_flush(&intel
->ctx
);
711 intel_flush_front(&intel
->ctx
);
713 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
714 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
715 } else if (front_rb
&& intel
->front_buffer_dirty
) {
716 /* We have pending front buffer rendering, but we aren't querying for a
717 * front buffer. If the front buffer we have is a fake front buffer,
718 * the X server is going to throw it away when it processes the query.
719 * So before doing the query, make sure all the pending drawing has
720 * landed in the real front buffer.
722 intel_flush(&intel
->ctx
);
723 intel_flush_front(&intel
->ctx
);
727 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
728 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
731 assert(i
<= ARRAY_SIZE(attachments
));
733 *buffers
= screen
->dri2
.loader
->getBuffersWithFormat(drawable
,
738 drawable
->loaderPrivate
);
742 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
744 * This is called from intel_update_renderbuffers().
747 * DRI buffers whose attachment point is DRI2BufferStencil or
748 * DRI2BufferDepthStencil are handled as special cases.
750 * \param buffer_name is a human readable name, such as "dri2 front buffer",
751 * that is passed to intel_region_alloc_for_handle().
753 * \see intel_update_renderbuffers()
754 * \see intel_region_alloc_for_handle()
757 intel_process_dri2_buffer(struct intel_context
*intel
,
758 __DRIdrawable
*drawable
,
760 struct intel_renderbuffer
*rb
,
761 const char *buffer_name
)
763 struct intel_region
*region
= NULL
;
768 /* We try to avoid closing and reopening the same BO name, because the first
769 * use of a mapping of the buffer involves a bunch of page faulting which is
770 * moderately expensive.
774 rb
->mt
->region
->name
== buffer
->name
)
777 if (unlikely(INTEL_DEBUG
& DEBUG_DRI
)) {
779 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
780 buffer
->name
, buffer
->attachment
,
781 buffer
->cpp
, buffer
->pitch
);
784 intel_miptree_release(&rb
->mt
);
785 region
= intel_region_alloc_for_handle(intel
->intelScreen
,
795 rb
->mt
= intel_miptree_create_for_dri2_buffer(intel
,
799 intel_region_release(®ion
);
803 * \brief Query DRI Image loader to obtain a DRIdrawable's buffers.
805 * To determine which DRI buffers to request, examine the renderbuffers
806 * attached to the drawable's framebuffer. Then request the buffers with
809 * This is called from intel_update_renderbuffers().
811 * \param drawable Drawable whose buffers are queried.
812 * \param buffers [out] List of buffers returned by DRI2 query.
813 * \param buffer_count [out] Number of buffers returned.
815 * \see intel_update_renderbuffers()
819 intel_update_image_buffer(struct intel_context
*intel
,
820 __DRIdrawable
*drawable
,
821 struct intel_renderbuffer
*rb
,
823 enum __DRIimageBufferMask buffer_type
)
825 struct intel_region
*region
= buffer
->region
;
830 unsigned num_samples
= rb
->Base
.Base
.NumSamples
;
834 rb
->mt
->region
== region
)
837 intel_miptree_release(&rb
->mt
);
838 rb
->mt
= intel_miptree_create_for_image_buffer(intel
,
847 intel_update_image_buffers(struct intel_context
*intel
, __DRIdrawable
*drawable
)
849 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
850 __DRIscreen
*screen
= intel
->intelScreen
->driScrnPriv
;
851 struct intel_renderbuffer
*front_rb
;
852 struct intel_renderbuffer
*back_rb
;
853 struct __DRIimageList images
;
855 uint32_t buffer_mask
= 0;
858 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
859 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
862 format
= intel_rb_format(back_rb
);
864 format
= intel_rb_format(front_rb
);
868 if (front_rb
&& (_mesa_is_front_buffer_drawing(fb
) ||
869 _mesa_is_front_buffer_reading(fb
) || !back_rb
)) {
870 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
874 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
876 ret
= screen
->image
.loader
->getBuffers(drawable
,
877 driGLFormatToImageFormat(format
),
878 &drawable
->dri2
.stamp
,
879 drawable
->loaderPrivate
,
885 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
886 drawable
->w
= images
.front
->width
;
887 drawable
->h
= images
.front
->height
;
888 intel_update_image_buffer(intel
,
892 __DRI_IMAGE_BUFFER_FRONT
);
894 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
895 drawable
->w
= images
.back
->width
;
896 drawable
->h
= images
.back
->height
;
897 intel_update_image_buffer(intel
,
901 __DRI_IMAGE_BUFFER_BACK
);