1 /**************************************************************************
3 * Copyright 2006 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/enums.h"
30 #include "main/imports.h"
31 #include "main/macros.h"
32 #include "main/mtypes.h"
33 #include "main/fbobject.h"
34 #include "main/framebuffer.h"
35 #include "main/renderbuffer.h"
36 #include "main/context.h"
37 #include "main/teximage.h"
38 #include "main/image.h"
40 #include "swrast/swrast.h"
41 #include "drivers/common/meta.h"
43 #include "intel_batchbuffer.h"
44 #include "intel_buffers.h"
45 #include "intel_blit.h"
46 #include "intel_fbo.h"
47 #include "intel_mipmap_tree.h"
48 #include "intel_regions.h"
49 #include "intel_tex.h"
50 #include "brw_context.h"
52 #define FILE_DEBUG_FLAG DEBUG_FBO
55 * Create a new framebuffer object.
57 static struct gl_framebuffer
*
58 intel_new_framebuffer(struct gl_context
* ctx
, GLuint name
)
60 /* Only drawable state in intel_framebuffer at this time, just use Mesa's
63 return _mesa_new_framebuffer(ctx
, name
);
67 /** Called by gl_renderbuffer::Delete() */
69 intel_delete_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
71 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
75 intel_miptree_release(&irb
->mt
);
77 _mesa_delete_renderbuffer(ctx
, rb
);
81 * \see dd_function_table::MapRenderbuffer
84 intel_map_renderbuffer(struct gl_context
*ctx
,
85 struct gl_renderbuffer
*rb
,
86 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
91 struct brw_context
*brw
= brw_context(ctx
);
92 struct swrast_renderbuffer
*srb
= (struct swrast_renderbuffer
*)rb
;
93 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
98 /* this is a malloc'd renderbuffer (accum buffer), not an irb */
99 GLint bpp
= _mesa_get_format_bytes(rb
->Format
);
100 GLint rowStride
= srb
->RowStride
;
101 *out_map
= (GLubyte
*) srb
->Buffer
+ y
* rowStride
+ x
* bpp
;
102 *out_stride
= rowStride
;
106 intel_prepare_render(brw
);
108 /* For a window-system renderbuffer, we need to flip the mapping we receive
109 * upside-down. So we need to ask for a rectangle on flipped vertically, and
110 * we then return a pointer to the bottom of it with a negative stride.
113 y
= rb
->Height
- y
- h
;
116 intel_miptree_map(brw
, irb
->mt
, irb
->mt_level
, irb
->mt_layer
,
117 x
, y
, w
, h
, mode
, &map
, &stride
);
120 map
+= (h
- 1) * stride
;
124 DBG("%s: rb %d (%s) mt mapped: (%d, %d) (%dx%d) -> %p/%d\n",
125 __FUNCTION__
, rb
->Name
, _mesa_get_format_name(rb
->Format
),
126 x
, y
, w
, h
, map
, stride
);
129 *out_stride
= stride
;
133 * \see dd_function_table::UnmapRenderbuffer
136 intel_unmap_renderbuffer(struct gl_context
*ctx
,
137 struct gl_renderbuffer
*rb
)
139 struct brw_context
*brw
= brw_context(ctx
);
140 struct swrast_renderbuffer
*srb
= (struct swrast_renderbuffer
*)rb
;
141 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
143 DBG("%s: rb %d (%s)\n", __FUNCTION__
,
144 rb
->Name
, _mesa_get_format_name(rb
->Format
));
147 /* this is a malloc'd renderbuffer (accum buffer) */
152 intel_miptree_unmap(brw
, irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
157 * Round up the requested multisample count to the next supported sample size.
160 intel_quantize_num_samples(struct intel_screen
*intel
, unsigned num_samples
)
162 switch (intel
->gen
) {
164 /* Gen6 supports only 4x multisampling. */
170 /* Gen7 supports 4x and 8x multisampling. */
173 else if (num_samples
> 0)
179 /* MSAA unsupported. */
186 * Called via glRenderbufferStorageEXT() to set the format and allocate
187 * storage for a user-created renderbuffer.
190 intel_alloc_renderbuffer_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
191 GLenum internalFormat
,
192 GLuint width
, GLuint height
)
194 struct brw_context
*brw
= brw_context(ctx
);
195 struct intel_screen
*screen
= brw
->intelScreen
;
196 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
197 rb
->NumSamples
= intel_quantize_num_samples(screen
, rb
->NumSamples
);
199 switch (internalFormat
) {
201 /* Use the same format-choice logic as for textures.
202 * Renderbuffers aren't any different from textures for us,
203 * except they're less useful because you can't texture with
206 rb
->Format
= ctx
->Driver
.ChooseTextureFormat(ctx
, GL_TEXTURE_2D
,
210 case GL_STENCIL_INDEX
:
211 case GL_STENCIL_INDEX1_EXT
:
212 case GL_STENCIL_INDEX4_EXT
:
213 case GL_STENCIL_INDEX8_EXT
:
214 case GL_STENCIL_INDEX16_EXT
:
215 /* These aren't actual texture formats, so force them here. */
216 if (brw
->has_separate_stencil
) {
217 rb
->Format
= MESA_FORMAT_S8
;
219 assert(!brw
->must_use_separate_stencil
);
220 rb
->Format
= MESA_FORMAT_S8_Z24
;
227 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
229 intel_miptree_release(&irb
->mt
);
231 DBG("%s: %s: %s (%dx%d)\n", __FUNCTION__
,
232 _mesa_lookup_enum_by_nr(internalFormat
),
233 _mesa_get_format_name(rb
->Format
), width
, height
);
235 if (width
== 0 || height
== 0)
238 irb
->mt
= intel_miptree_create_for_renderbuffer(brw
, rb
->Format
,
249 intel_image_target_renderbuffer_storage(struct gl_context
*ctx
,
250 struct gl_renderbuffer
*rb
,
253 struct brw_context
*brw
= brw_context(ctx
);
254 struct intel_renderbuffer
*irb
;
258 screen
= brw
->intelScreen
->driScrnPriv
;
259 image
= screen
->dri2
.image
->lookupEGLImage(screen
, image_handle
,
260 screen
->loaderPrivate
);
264 if (image
->planar_format
&& image
->planar_format
->nplanes
> 1) {
265 _mesa_error(ctx
, GL_INVALID_OPERATION
,
266 "glEGLImageTargetRenderbufferStorage(planar buffers are not "
267 "supported as render targets.");
271 /* Buffers originating from outside are for read-only. */
272 if (image
->dma_buf_imported
) {
273 _mesa_error(ctx
, GL_INVALID_OPERATION
,
274 "glEGLImageTargetRenderbufferStorage(dma buffers are read-only)");
278 /* __DRIimage is opaque to the core so it has to be checked here */
279 switch (image
->format
) {
280 case MESA_FORMAT_RGBA8888_REV
:
281 _mesa_error(ctx
, GL_INVALID_OPERATION
,
282 "glEGLImageTargetRenderbufferStorage(unsupported image format");
289 irb
= intel_renderbuffer(rb
);
290 intel_miptree_release(&irb
->mt
);
291 irb
->mt
= intel_miptree_create_for_bo(brw
,
295 image
->region
->width
,
296 image
->region
->height
,
297 image
->region
->pitch
,
298 image
->region
->tiling
);
302 rb
->InternalFormat
= image
->internal_format
;
303 rb
->Width
= image
->region
->width
;
304 rb
->Height
= image
->region
->height
;
305 rb
->Format
= image
->format
;
306 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, image
->internal_format
);
307 rb
->NeedsFinishRenderTexture
= true;
311 * Called by _mesa_resize_framebuffer() for each hardware renderbuffer when a
312 * window system framebuffer is resized.
314 * Any actual buffer reallocations for hardware renderbuffers (which would
315 * have triggered _mesa_resize_framebuffer()) were done by
316 * intel_process_dri2_buffer().
319 intel_alloc_window_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
320 GLenum internalFormat
, GLuint width
, GLuint height
)
322 ASSERT(rb
->Name
== 0);
325 rb
->InternalFormat
= internalFormat
;
330 /** Dummy function for gl_renderbuffer::AllocStorage() */
332 intel_nop_alloc_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
333 GLenum internalFormat
, GLuint width
, GLuint height
)
335 _mesa_problem(ctx
, "intel_op_alloc_storage should never be called.");
340 * Create a new intel_renderbuffer which corresponds to an on-screen window,
341 * not a user-created renderbuffer.
343 * \param num_samples must be quantized.
345 struct intel_renderbuffer
*
346 intel_create_renderbuffer(gl_format format
, unsigned num_samples
)
348 struct intel_renderbuffer
*irb
;
349 struct gl_renderbuffer
*rb
;
351 GET_CURRENT_CONTEXT(ctx
);
353 irb
= CALLOC_STRUCT(intel_renderbuffer
);
355 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
359 rb
= &irb
->Base
.Base
;
361 _mesa_init_renderbuffer(rb
, 0);
362 rb
->ClassID
= INTEL_RB_CLASS
;
363 rb
->_BaseFormat
= _mesa_get_format_base_format(format
);
365 rb
->InternalFormat
= rb
->_BaseFormat
;
366 rb
->NumSamples
= num_samples
;
368 /* intel-specific methods */
369 rb
->Delete
= intel_delete_renderbuffer
;
370 rb
->AllocStorage
= intel_alloc_window_storage
;
376 * Private window-system buffers (as opposed to ones shared with the display
377 * server created with intel_create_renderbuffer()) are most similar in their
378 * handling to user-created renderbuffers, but they have a resize handler that
379 * may be called at intel_update_renderbuffers() time.
381 * \param num_samples must be quantized.
383 struct intel_renderbuffer
*
384 intel_create_private_renderbuffer(gl_format format
, unsigned num_samples
)
386 struct intel_renderbuffer
*irb
;
388 irb
= intel_create_renderbuffer(format
, num_samples
);
389 irb
->Base
.Base
.AllocStorage
= intel_alloc_renderbuffer_storage
;
395 * Create a new renderbuffer object.
396 * Typically called via glBindRenderbufferEXT().
398 static struct gl_renderbuffer
*
399 intel_new_renderbuffer(struct gl_context
* ctx
, GLuint name
)
401 struct intel_renderbuffer
*irb
;
402 struct gl_renderbuffer
*rb
;
404 irb
= CALLOC_STRUCT(intel_renderbuffer
);
406 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
410 rb
= &irb
->Base
.Base
;
412 _mesa_init_renderbuffer(rb
, name
);
413 rb
->ClassID
= INTEL_RB_CLASS
;
415 /* intel-specific methods */
416 rb
->Delete
= intel_delete_renderbuffer
;
417 rb
->AllocStorage
= intel_alloc_renderbuffer_storage
;
418 /* span routines set in alloc_storage function */
424 intel_renderbuffer_update_wrapper(struct brw_context
*brw
,
425 struct intel_renderbuffer
*irb
,
426 struct gl_texture_image
*image
,
429 struct gl_renderbuffer
*rb
= &irb
->Base
.Base
;
430 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
431 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
432 int level
= image
->Level
;
434 rb
->Depth
= image
->Depth
;
436 rb
->AllocStorage
= intel_nop_alloc_storage
;
438 intel_miptree_check_level_layer(mt
, level
, layer
);
439 irb
->mt_level
= level
;
441 switch (mt
->msaa_layout
) {
442 case INTEL_MSAA_LAYOUT_UMS
:
443 case INTEL_MSAA_LAYOUT_CMS
:
444 irb
->mt_layer
= layer
* mt
->num_samples
;
448 irb
->mt_layer
= layer
;
451 intel_miptree_reference(&irb
->mt
, mt
);
453 intel_renderbuffer_set_draw_offset(irb
);
455 if (mt
->hiz_mt
== NULL
&& brw_is_hiz_depth_format(brw
, rb
->Format
)) {
456 intel_miptree_alloc_hiz(brw
, mt
);
465 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer
*irb
)
467 unsigned int dst_x
, dst_y
;
469 /* compute offset of the particular 2D image within the texture region */
470 intel_miptree_get_image_offset(irb
->mt
,
480 * Called by glFramebufferTexture[123]DEXT() (and other places) to
481 * prepare for rendering into texture memory. This might be called
482 * many times to choose different texture levels, cube faces, etc
483 * before intel_finish_render_texture() is ever called.
486 intel_render_texture(struct gl_context
* ctx
,
487 struct gl_framebuffer
*fb
,
488 struct gl_renderbuffer_attachment
*att
)
490 struct brw_context
*brw
= brw_context(ctx
);
491 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
492 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
493 struct gl_texture_image
*image
= rb
->TexImage
;
494 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
495 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
500 if (att
->CubeMapFace
> 0) {
501 assert(att
->Zoffset
== 0);
502 layer
= att
->CubeMapFace
;
504 layer
= att
->Zoffset
;
507 if (!intel_image
->mt
) {
508 /* Fallback on drawing to a texture that doesn't have a miptree
509 * (has a border, width/height 0, etc.)
511 _swrast_render_texture(ctx
, fb
, att
);
515 intel_miptree_check_level_layer(mt
, att
->TextureLevel
, layer
);
517 if (!intel_renderbuffer_update_wrapper(brw
, irb
, image
, layer
)) {
518 _swrast_render_texture(ctx
, fb
, att
);
522 DBG("Begin render %s texture tex=%u w=%d h=%d d=%d refcount=%d\n",
523 _mesa_get_format_name(image
->TexFormat
),
524 att
->Texture
->Name
, image
->Width
, image
->Height
, image
->Depth
,
530 * Called by Mesa when rendering to a texture is done.
533 intel_finish_render_texture(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
)
535 struct brw_context
*brw
= brw_context(ctx
);
537 DBG("Finish render %s texture\n", _mesa_get_format_name(rb
->Format
));
539 /* Since we've (probably) rendered to the texture and will (likely) use
540 * it in the texture domain later on in this batchbuffer, flush the
541 * batch. Once again, we wish for a domain tracker in libdrm to cover
542 * usage inside of a batchbuffer like GEM does in the kernel.
544 intel_batchbuffer_emit_mi_flush(brw
);
547 #define fbo_incomplete(fb, ...) do { \
548 static GLuint msg_id = 0; \
549 if (unlikely(ctx->Const.ContextFlags & GL_CONTEXT_FLAG_DEBUG_BIT)) { \
550 _mesa_gl_debug(ctx, &msg_id, \
551 MESA_DEBUG_TYPE_OTHER, \
552 MESA_DEBUG_SEVERITY_MEDIUM, \
556 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; \
560 * Do additional "completeness" testing of a framebuffer object.
563 intel_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
565 struct brw_context
*brw
= brw_context(ctx
);
566 struct intel_renderbuffer
*depthRb
=
567 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
568 struct intel_renderbuffer
*stencilRb
=
569 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
570 struct intel_mipmap_tree
*depth_mt
= NULL
, *stencil_mt
= NULL
;
573 DBG("%s() on fb %p (%s)\n", __FUNCTION__
,
574 fb
, (fb
== ctx
->DrawBuffer
? "drawbuffer" :
575 (fb
== ctx
->ReadBuffer
? "readbuffer" : "other buffer")));
578 depth_mt
= depthRb
->mt
;
580 stencil_mt
= stencilRb
->mt
;
581 if (stencil_mt
->stencil_mt
)
582 stencil_mt
= stencil_mt
->stencil_mt
;
585 if (depth_mt
&& stencil_mt
) {
587 /* For gen >= 7, we are using the lod/minimum-array-element fields
588 * and supportting layered rendering. This means that we must restrict
589 * the depth & stencil attachments to match in various more retrictive
590 * ways. (width, height, depth, LOD and layer)
592 if (depth_mt
->physical_width0
!= stencil_mt
->physical_width0
||
593 depth_mt
->physical_height0
!= stencil_mt
->physical_height0
||
594 depth_mt
->physical_depth0
!= stencil_mt
->physical_depth0
||
595 depthRb
->mt_level
!= stencilRb
->mt_level
||
596 depthRb
->mt_layer
!= stencilRb
->mt_layer
) {
598 "FBO incomplete: depth and stencil must match in"
599 "width, height, depth, LOD and layer\n");
602 if (depth_mt
== stencil_mt
) {
603 /* For true packed depth/stencil (not faked on prefers-separate-stencil
604 * hardware) we need to be sure they're the same level/layer, since
605 * we'll be emitting a single packet describing the packed setup.
607 if (depthRb
->mt_level
!= stencilRb
->mt_level
||
608 depthRb
->mt_layer
!= stencilRb
->mt_layer
) {
610 "FBO incomplete: depth image level/layer %d/%d != "
611 "stencil image %d/%d\n",
615 stencilRb
->mt_layer
);
618 if (!brw
->has_separate_stencil
) {
619 fbo_incomplete(fb
, "FBO incomplete: separate stencil "
622 if (stencil_mt
->format
!= MESA_FORMAT_S8
) {
623 fbo_incomplete(fb
, "FBO incomplete: separate stencil is %s "
625 _mesa_get_format_name(stencil_mt
->format
));
627 if (brw
->gen
< 7 && !intel_renderbuffer_has_hiz(depthRb
)) {
628 /* Before Gen7, separate depth and stencil buffers can be used
629 * only if HiZ is enabled. From the Sandybridge PRM, Volume 2,
630 * Part 1, Bit 3DSTATE_DEPTH_BUFFER.SeparateStencilBufferEnable:
631 * [DevSNB]: This field must be set to the same value (enabled
632 * or disabled) as Hierarchical Depth Buffer Enable.
634 fbo_incomplete(fb
, "FBO incomplete: separate stencil "
640 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
641 struct gl_renderbuffer
*rb
;
642 struct intel_renderbuffer
*irb
;
644 if (fb
->Attachment
[i
].Type
== GL_NONE
)
647 /* A supported attachment will have a Renderbuffer set either
648 * from being a Renderbuffer or being a texture that got the
649 * intel_wrap_texture() treatment.
651 rb
= fb
->Attachment
[i
].Renderbuffer
;
653 fbo_incomplete(fb
, "FBO incomplete: attachment without "
658 if (fb
->Attachment
[i
].Type
== GL_TEXTURE
) {
659 if (rb
->TexImage
->Border
) {
660 fbo_incomplete(fb
, "FBO incomplete: texture with border\n");
665 irb
= intel_renderbuffer(rb
);
667 fbo_incomplete(fb
, "FBO incomplete: software rendering "
672 if (!brw_render_target_supported(brw
, rb
)) {
673 fbo_incomplete(fb
, "FBO incomplete: Unsupported HW "
674 "texture/renderbuffer format attached: %s\n",
675 _mesa_get_format_name(intel_rb_format(irb
)));
681 * Try to do a glBlitFramebuffer using glCopyTexSubImage2D
682 * We can do this when the dst renderbuffer is actually a texture and
683 * there is no scaling, mirroring or scissoring.
685 * \return new buffer mask indicating the buffers left to blit using the
689 intel_blit_framebuffer_with_blitter(struct gl_context
*ctx
,
690 GLint srcX0
, GLint srcY0
,
691 GLint srcX1
, GLint srcY1
,
692 GLint dstX0
, GLint dstY0
,
693 GLint dstX1
, GLint dstY1
,
694 GLbitfield mask
, GLenum filter
)
696 struct brw_context
*brw
= brw_context(ctx
);
698 /* Sync up the state of window system buffers. We need to do this before
699 * we go looking for the buffers.
701 intel_prepare_render(brw
);
703 if (mask
& GL_COLOR_BUFFER_BIT
) {
705 const struct gl_framebuffer
*drawFb
= ctx
->DrawBuffer
;
706 const struct gl_framebuffer
*readFb
= ctx
->ReadBuffer
;
707 struct gl_renderbuffer
*src_rb
= readFb
->_ColorReadBuffer
;
708 struct intel_renderbuffer
*src_irb
= intel_renderbuffer(src_rb
);
711 perf_debug("glBlitFramebuffer(): missing src renderbuffer. "
712 "Falling back to software rendering.\n");
716 /* If the source and destination are the same size with no mirroring,
717 * the rectangles are within the size of the texture and there is no
718 * scissor, then we can probably use the blit engine.
720 if (!(srcX0
- srcX1
== dstX0
- dstX1
&&
721 srcY0
- srcY1
== dstY0
- dstY1
&&
724 srcX0
>= 0 && srcX1
<= readFb
->Width
&&
725 srcY0
>= 0 && srcY1
<= readFb
->Height
&&
726 dstX0
>= 0 && dstX1
<= drawFb
->Width
&&
727 dstY0
>= 0 && dstY1
<= drawFb
->Height
&&
728 !ctx
->Scissor
.Enabled
)) {
729 perf_debug("glBlitFramebuffer(): non-1:1 blit. "
730 "Falling back to software rendering.\n");
734 /* Blit to all active draw buffers. We don't do any pre-checking,
735 * because we assume that copying to MRTs is rare, and failure midway
736 * through copying is even more rare. Even if it was to occur, it's
737 * safe to let meta start the copy over from scratch, because
738 * glBlitFramebuffer completely overwrites the destination pixels, and
739 * results are undefined if any destination pixels have a dependency on
742 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
743 struct gl_renderbuffer
*dst_rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
744 struct intel_renderbuffer
*dst_irb
= intel_renderbuffer(dst_rb
);
747 perf_debug("glBlitFramebuffer(): missing dst renderbuffer. "
748 "Falling back to software rendering.\n");
752 gl_format src_format
= _mesa_get_srgb_format_linear(src_rb
->Format
);
753 gl_format dst_format
= _mesa_get_srgb_format_linear(dst_rb
->Format
);
754 if (src_format
!= dst_format
) {
755 perf_debug("glBlitFramebuffer(): unsupported blit from %s to %s. "
756 "Falling back to software rendering.\n",
757 _mesa_get_format_name(src_format
),
758 _mesa_get_format_name(dst_format
));
762 if (!intel_miptree_blit(brw
,
764 src_irb
->mt_level
, src_irb
->mt_layer
,
765 srcX0
, srcY0
, src_rb
->Name
== 0,
767 dst_irb
->mt_level
, dst_irb
->mt_layer
,
768 dstX0
, dstY0
, dst_rb
->Name
== 0,
769 dstX1
- dstX0
, dstY1
- dstY0
, GL_COPY
)) {
770 perf_debug("glBlitFramebuffer(): unknown blit failure. "
771 "Falling back to software rendering.\n");
776 mask
&= ~GL_COLOR_BUFFER_BIT
;
783 intel_blit_framebuffer(struct gl_context
*ctx
,
784 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
785 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
786 GLbitfield mask
, GLenum filter
)
788 mask
= brw_blorp_framebuffer(brw_context(ctx
),
789 srcX0
, srcY0
, srcX1
, srcY1
,
790 dstX0
, dstY0
, dstX1
, dstY1
,
795 /* Try using the BLT engine. */
796 mask
= intel_blit_framebuffer_with_blitter(ctx
,
797 srcX0
, srcY0
, srcX1
, srcY1
,
798 dstX0
, dstY0
, dstX1
, dstY1
,
804 _mesa_meta_BlitFramebuffer(ctx
,
805 srcX0
, srcY0
, srcX1
, srcY1
,
806 dstX0
, dstY0
, dstX1
, dstY1
,
811 * This is a no-op except on multisample buffers shared with DRI2.
814 intel_renderbuffer_set_needs_downsample(struct intel_renderbuffer
*irb
)
816 if (irb
->mt
&& irb
->mt
->singlesample_mt
)
817 irb
->mt
->need_downsample
= true;
821 * Does the renderbuffer have hiz enabled?
824 intel_renderbuffer_has_hiz(struct intel_renderbuffer
*irb
)
826 return intel_miptree_slice_has_hiz(irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
830 intel_renderbuffer_resolve_hiz(struct brw_context
*brw
,
831 struct intel_renderbuffer
*irb
)
834 return intel_miptree_slice_resolve_hiz(brw
,
843 intel_renderbuffer_att_set_needs_depth_resolve(struct gl_renderbuffer_attachment
*att
)
845 struct intel_renderbuffer
*irb
= intel_renderbuffer(att
->Renderbuffer
);
848 intel_miptree_set_all_slices_need_depth_resolve(irb
->mt
, irb
->mt_level
);
850 intel_miptree_slice_set_needs_depth_resolve(irb
->mt
,
858 intel_renderbuffer_resolve_depth(struct brw_context
*brw
,
859 struct intel_renderbuffer
*irb
)
862 return intel_miptree_slice_resolve_depth(brw
,
871 intel_renderbuffer_move_to_temp(struct brw_context
*brw
,
872 struct intel_renderbuffer
*irb
,
875 struct gl_renderbuffer
*rb
=&irb
->Base
.Base
;
876 struct intel_texture_image
*intel_image
= intel_texture_image(rb
->TexImage
);
877 struct intel_mipmap_tree
*new_mt
;
878 int width
, height
, depth
;
880 intel_miptree_get_dimensions_for_image(rb
->TexImage
, &width
, &height
, &depth
);
882 new_mt
= intel_miptree_create(brw
, rb
->TexImage
->TexObject
->Target
,
883 intel_image
->base
.Base
.TexFormat
,
884 intel_image
->base
.Base
.Level
,
885 intel_image
->base
.Base
.Level
,
886 width
, height
, depth
,
888 irb
->mt
->num_samples
,
889 INTEL_MIPTREE_TILING_ANY
);
891 if (brw_is_hiz_depth_format(brw
, new_mt
->format
)) {
892 intel_miptree_alloc_hiz(brw
, new_mt
);
895 intel_miptree_copy_teximage(brw
, intel_image
, new_mt
, invalidate
);
897 intel_miptree_reference(&irb
->mt
, intel_image
->mt
);
898 intel_renderbuffer_set_draw_offset(irb
);
899 intel_miptree_release(&new_mt
);
903 * Do one-time context initializations related to GL_EXT_framebuffer_object.
904 * Hook in device driver functions.
907 intel_fbo_init(struct brw_context
*brw
)
909 struct dd_function_table
*dd
= &brw
->ctx
.Driver
;
910 dd
->NewFramebuffer
= intel_new_framebuffer
;
911 dd
->NewRenderbuffer
= intel_new_renderbuffer
;
912 dd
->MapRenderbuffer
= intel_map_renderbuffer
;
913 dd
->UnmapRenderbuffer
= intel_unmap_renderbuffer
;
914 dd
->RenderTexture
= intel_render_texture
;
915 dd
->FinishRenderTexture
= intel_finish_render_texture
;
916 dd
->ValidateFramebuffer
= intel_validate_framebuffer
;
917 dd
->BlitFramebuffer
= intel_blit_framebuffer
;
918 dd
->EGLImageTargetRenderbufferStorage
=
919 intel_image_target_renderbuffer_storage
;