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_screen.h"
50 #include "intel_tex.h"
51 #include "brw_context.h"
53 #define FILE_DEBUG_FLAG DEBUG_FBO
56 * Create a new framebuffer object.
58 static struct gl_framebuffer
*
59 intel_new_framebuffer(struct gl_context
* ctx
, GLuint name
)
61 /* Only drawable state in intel_framebuffer at this time, just use Mesa's
64 return _mesa_new_framebuffer(ctx
, name
);
68 /** Called by gl_renderbuffer::Delete() */
70 intel_delete_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
72 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
76 intel_miptree_release(&irb
->mt
);
78 _mesa_delete_renderbuffer(ctx
, rb
);
82 * \see dd_function_table::MapRenderbuffer
85 intel_map_renderbuffer(struct gl_context
*ctx
,
86 struct gl_renderbuffer
*rb
,
87 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
92 struct brw_context
*brw
= brw_context(ctx
);
93 struct swrast_renderbuffer
*srb
= (struct swrast_renderbuffer
*)rb
;
94 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
99 /* this is a malloc'd renderbuffer (accum buffer), not an irb */
100 GLint bpp
= _mesa_get_format_bytes(rb
->Format
);
101 GLint rowStride
= srb
->RowStride
;
102 *out_map
= (GLubyte
*) srb
->Buffer
+ y
* rowStride
+ x
* bpp
;
103 *out_stride
= rowStride
;
107 intel_prepare_render(brw
);
109 /* For a window-system renderbuffer, we need to flip the mapping we receive
110 * upside-down. So we need to ask for a rectangle on flipped vertically, and
111 * we then return a pointer to the bottom of it with a negative stride.
114 y
= rb
->Height
- y
- h
;
117 intel_miptree_map(brw
, irb
->mt
, irb
->mt_level
, irb
->mt_layer
,
118 x
, y
, w
, h
, mode
, &map
, &stride
);
121 map
+= (h
- 1) * stride
;
125 DBG("%s: rb %d (%s) mt mapped: (%d, %d) (%dx%d) -> %p/%d\n",
126 __FUNCTION__
, rb
->Name
, _mesa_get_format_name(rb
->Format
),
127 x
, y
, w
, h
, map
, stride
);
130 *out_stride
= stride
;
134 * \see dd_function_table::UnmapRenderbuffer
137 intel_unmap_renderbuffer(struct gl_context
*ctx
,
138 struct gl_renderbuffer
*rb
)
140 struct brw_context
*brw
= brw_context(ctx
);
141 struct swrast_renderbuffer
*srb
= (struct swrast_renderbuffer
*)rb
;
142 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
144 DBG("%s: rb %d (%s)\n", __FUNCTION__
,
145 rb
->Name
, _mesa_get_format_name(rb
->Format
));
148 /* this is a malloc'd renderbuffer (accum buffer) */
153 intel_miptree_unmap(brw
, irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
158 * Round up the requested multisample count to the next supported sample size.
161 intel_quantize_num_samples(struct intel_screen
*intel
, unsigned num_samples
)
163 const int *msaa_modes
= intel_supported_msaa_modes(intel
);
164 int quantized_samples
= 0;
166 for (int i
= 0; msaa_modes
[i
] != -1; ++i
) {
167 if (msaa_modes
[i
] >= num_samples
)
168 quantized_samples
= msaa_modes
[i
];
173 return quantized_samples
;
178 * Called via glRenderbufferStorageEXT() to set the format and allocate
179 * storage for a user-created renderbuffer.
182 intel_alloc_renderbuffer_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
183 GLenum internalFormat
,
184 GLuint width
, GLuint height
)
186 struct brw_context
*brw
= brw_context(ctx
);
187 struct intel_screen
*screen
= brw
->intelScreen
;
188 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
189 rb
->NumSamples
= intel_quantize_num_samples(screen
, rb
->NumSamples
);
191 switch (internalFormat
) {
193 /* Use the same format-choice logic as for textures.
194 * Renderbuffers aren't any different from textures for us,
195 * except they're less useful because you can't texture with
198 rb
->Format
= ctx
->Driver
.ChooseTextureFormat(ctx
, GL_TEXTURE_2D
,
202 case GL_STENCIL_INDEX
:
203 case GL_STENCIL_INDEX1_EXT
:
204 case GL_STENCIL_INDEX4_EXT
:
205 case GL_STENCIL_INDEX8_EXT
:
206 case GL_STENCIL_INDEX16_EXT
:
207 /* These aren't actual texture formats, so force them here. */
208 if (brw
->has_separate_stencil
) {
209 rb
->Format
= MESA_FORMAT_S8
;
211 assert(!brw
->must_use_separate_stencil
);
212 rb
->Format
= MESA_FORMAT_S8_Z24
;
219 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
221 intel_miptree_release(&irb
->mt
);
223 DBG("%s: %s: %s (%dx%d)\n", __FUNCTION__
,
224 _mesa_lookup_enum_by_nr(internalFormat
),
225 _mesa_get_format_name(rb
->Format
), width
, height
);
227 if (width
== 0 || height
== 0)
230 irb
->mt
= intel_miptree_create_for_renderbuffer(brw
, rb
->Format
,
241 intel_image_target_renderbuffer_storage(struct gl_context
*ctx
,
242 struct gl_renderbuffer
*rb
,
245 struct brw_context
*brw
= brw_context(ctx
);
246 struct intel_renderbuffer
*irb
;
250 screen
= brw
->intelScreen
->driScrnPriv
;
251 image
= screen
->dri2
.image
->lookupEGLImage(screen
, image_handle
,
252 screen
->loaderPrivate
);
256 if (image
->planar_format
&& image
->planar_format
->nplanes
> 1) {
257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
258 "glEGLImageTargetRenderbufferStorage(planar buffers are not "
259 "supported as render targets.");
263 /* Buffers originating from outside are for read-only. */
264 if (image
->dma_buf_imported
) {
265 _mesa_error(ctx
, GL_INVALID_OPERATION
,
266 "glEGLImageTargetRenderbufferStorage(dma buffers are read-only)");
270 /* __DRIimage is opaque to the core so it has to be checked here */
271 switch (image
->format
) {
272 case MESA_FORMAT_RGBA8888_REV
:
273 _mesa_error(ctx
, GL_INVALID_OPERATION
,
274 "glEGLImageTargetRenderbufferStorage(unsupported image format");
281 irb
= intel_renderbuffer(rb
);
282 intel_miptree_release(&irb
->mt
);
283 irb
->mt
= intel_miptree_create_for_bo(brw
,
287 image
->region
->width
,
288 image
->region
->height
,
289 image
->region
->pitch
,
290 image
->region
->tiling
);
294 rb
->InternalFormat
= image
->internal_format
;
295 rb
->Width
= image
->region
->width
;
296 rb
->Height
= image
->region
->height
;
297 rb
->Format
= image
->format
;
298 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, image
->internal_format
);
299 rb
->NeedsFinishRenderTexture
= true;
303 * Called by _mesa_resize_framebuffer() for each hardware renderbuffer when a
304 * window system framebuffer is resized.
306 * Any actual buffer reallocations for hardware renderbuffers (which would
307 * have triggered _mesa_resize_framebuffer()) were done by
308 * intel_process_dri2_buffer().
311 intel_alloc_window_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
312 GLenum internalFormat
, GLuint width
, GLuint height
)
314 ASSERT(rb
->Name
== 0);
317 rb
->InternalFormat
= internalFormat
;
322 /** Dummy function for gl_renderbuffer::AllocStorage() */
324 intel_nop_alloc_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
325 GLenum internalFormat
, GLuint width
, GLuint height
)
327 _mesa_problem(ctx
, "intel_op_alloc_storage should never be called.");
332 * Create a new intel_renderbuffer which corresponds to an on-screen window,
333 * not a user-created renderbuffer.
335 * \param num_samples must be quantized.
337 struct intel_renderbuffer
*
338 intel_create_renderbuffer(gl_format format
, unsigned num_samples
)
340 struct intel_renderbuffer
*irb
;
341 struct gl_renderbuffer
*rb
;
343 GET_CURRENT_CONTEXT(ctx
);
345 irb
= CALLOC_STRUCT(intel_renderbuffer
);
347 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
351 rb
= &irb
->Base
.Base
;
353 _mesa_init_renderbuffer(rb
, 0);
354 rb
->ClassID
= INTEL_RB_CLASS
;
355 rb
->_BaseFormat
= _mesa_get_format_base_format(format
);
357 rb
->InternalFormat
= rb
->_BaseFormat
;
358 rb
->NumSamples
= num_samples
;
360 /* intel-specific methods */
361 rb
->Delete
= intel_delete_renderbuffer
;
362 rb
->AllocStorage
= intel_alloc_window_storage
;
368 * Private window-system buffers (as opposed to ones shared with the display
369 * server created with intel_create_renderbuffer()) are most similar in their
370 * handling to user-created renderbuffers, but they have a resize handler that
371 * may be called at intel_update_renderbuffers() time.
373 * \param num_samples must be quantized.
375 struct intel_renderbuffer
*
376 intel_create_private_renderbuffer(gl_format format
, unsigned num_samples
)
378 struct intel_renderbuffer
*irb
;
380 irb
= intel_create_renderbuffer(format
, num_samples
);
381 irb
->Base
.Base
.AllocStorage
= intel_alloc_renderbuffer_storage
;
387 * Create a new renderbuffer object.
388 * Typically called via glBindRenderbufferEXT().
390 static struct gl_renderbuffer
*
391 intel_new_renderbuffer(struct gl_context
* ctx
, GLuint name
)
393 struct intel_renderbuffer
*irb
;
394 struct gl_renderbuffer
*rb
;
396 irb
= CALLOC_STRUCT(intel_renderbuffer
);
398 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
402 rb
= &irb
->Base
.Base
;
404 _mesa_init_renderbuffer(rb
, name
);
405 rb
->ClassID
= INTEL_RB_CLASS
;
407 /* intel-specific methods */
408 rb
->Delete
= intel_delete_renderbuffer
;
409 rb
->AllocStorage
= intel_alloc_renderbuffer_storage
;
410 /* span routines set in alloc_storage function */
416 intel_renderbuffer_update_wrapper(struct brw_context
*brw
,
417 struct intel_renderbuffer
*irb
,
418 struct gl_texture_image
*image
,
421 struct gl_renderbuffer
*rb
= &irb
->Base
.Base
;
422 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
423 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
424 int level
= image
->Level
;
426 rb
->AllocStorage
= intel_nop_alloc_storage
;
428 intel_miptree_check_level_layer(mt
, level
, layer
);
429 irb
->mt_level
= level
;
431 switch (mt
->msaa_layout
) {
432 case INTEL_MSAA_LAYOUT_UMS
:
433 case INTEL_MSAA_LAYOUT_CMS
:
434 irb
->mt_layer
= layer
* mt
->num_samples
;
438 irb
->mt_layer
= layer
;
441 intel_miptree_reference(&irb
->mt
, mt
);
443 intel_renderbuffer_set_draw_offset(irb
);
445 if (mt
->hiz_mt
== NULL
&& brw_is_hiz_depth_format(brw
, rb
->Format
)) {
446 intel_miptree_alloc_hiz(brw
, mt
);
455 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer
*irb
)
457 unsigned int dst_x
, dst_y
;
459 /* compute offset of the particular 2D image within the texture region */
460 intel_miptree_get_image_offset(irb
->mt
,
470 * Called by glFramebufferTexture[123]DEXT() (and other places) to
471 * prepare for rendering into texture memory. This might be called
472 * many times to choose different texture levels, cube faces, etc
473 * before intel_finish_render_texture() is ever called.
476 intel_render_texture(struct gl_context
* ctx
,
477 struct gl_framebuffer
*fb
,
478 struct gl_renderbuffer_attachment
*att
)
480 struct brw_context
*brw
= brw_context(ctx
);
481 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
482 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
483 struct gl_texture_image
*image
= rb
->TexImage
;
484 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
485 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
490 if (att
->CubeMapFace
> 0) {
491 assert(att
->Zoffset
== 0);
492 layer
= att
->CubeMapFace
;
494 layer
= att
->Zoffset
;
497 if (!intel_image
->mt
) {
498 /* Fallback on drawing to a texture that doesn't have a miptree
499 * (has a border, width/height 0, etc.)
501 _swrast_render_texture(ctx
, fb
, att
);
505 intel_miptree_check_level_layer(mt
, att
->TextureLevel
, layer
);
507 if (!intel_renderbuffer_update_wrapper(brw
, irb
, image
, layer
)) {
508 _swrast_render_texture(ctx
, fb
, att
);
512 DBG("Begin render %s texture tex=%u w=%d h=%d d=%d refcount=%d\n",
513 _mesa_get_format_name(image
->TexFormat
),
514 att
->Texture
->Name
, image
->Width
, image
->Height
, image
->Depth
,
520 * Called by Mesa when rendering to a texture is done.
523 intel_finish_render_texture(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
)
525 struct brw_context
*brw
= brw_context(ctx
);
527 DBG("Finish render %s texture\n", _mesa_get_format_name(rb
->Format
));
529 /* Since we've (probably) rendered to the texture and will (likely) use
530 * it in the texture domain later on in this batchbuffer, flush the
531 * batch. Once again, we wish for a domain tracker in libdrm to cover
532 * usage inside of a batchbuffer like GEM does in the kernel.
534 intel_batchbuffer_emit_mi_flush(brw
);
537 #define fbo_incomplete(fb, ...) do { \
538 static GLuint msg_id = 0; \
539 if (unlikely(ctx->Const.ContextFlags & GL_CONTEXT_FLAG_DEBUG_BIT)) { \
540 _mesa_gl_debug(ctx, &msg_id, \
541 MESA_DEBUG_TYPE_OTHER, \
542 MESA_DEBUG_SEVERITY_MEDIUM, \
546 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; \
550 * Do additional "completeness" testing of a framebuffer object.
553 intel_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
555 struct brw_context
*brw
= brw_context(ctx
);
556 struct intel_renderbuffer
*depthRb
=
557 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
558 struct intel_renderbuffer
*stencilRb
=
559 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
560 struct intel_mipmap_tree
*depth_mt
= NULL
, *stencil_mt
= NULL
;
563 DBG("%s() on fb %p (%s)\n", __FUNCTION__
,
564 fb
, (fb
== ctx
->DrawBuffer
? "drawbuffer" :
565 (fb
== ctx
->ReadBuffer
? "readbuffer" : "other buffer")));
568 depth_mt
= depthRb
->mt
;
570 stencil_mt
= stencilRb
->mt
;
571 if (stencil_mt
->stencil_mt
)
572 stencil_mt
= stencil_mt
->stencil_mt
;
575 if (depth_mt
&& stencil_mt
) {
577 /* For gen >= 7, we are using the lod/minimum-array-element fields
578 * and supportting layered rendering. This means that we must restrict
579 * the depth & stencil attachments to match in various more retrictive
580 * ways. (width, height, depth, LOD and layer)
582 if (depth_mt
->physical_width0
!= stencil_mt
->physical_width0
||
583 depth_mt
->physical_height0
!= stencil_mt
->physical_height0
||
584 depth_mt
->physical_depth0
!= stencil_mt
->physical_depth0
||
585 depthRb
->mt_level
!= stencilRb
->mt_level
||
586 depthRb
->mt_layer
!= stencilRb
->mt_layer
) {
588 "FBO incomplete: depth and stencil must match in"
589 "width, height, depth, LOD and layer\n");
592 if (depth_mt
== stencil_mt
) {
593 /* For true packed depth/stencil (not faked on prefers-separate-stencil
594 * hardware) we need to be sure they're the same level/layer, since
595 * we'll be emitting a single packet describing the packed setup.
597 if (depthRb
->mt_level
!= stencilRb
->mt_level
||
598 depthRb
->mt_layer
!= stencilRb
->mt_layer
) {
600 "FBO incomplete: depth image level/layer %d/%d != "
601 "stencil image %d/%d\n",
605 stencilRb
->mt_layer
);
608 if (!brw
->has_separate_stencil
) {
609 fbo_incomplete(fb
, "FBO incomplete: separate stencil "
612 if (stencil_mt
->format
!= MESA_FORMAT_S8
) {
613 fbo_incomplete(fb
, "FBO incomplete: separate stencil is %s "
615 _mesa_get_format_name(stencil_mt
->format
));
617 if (brw
->gen
< 7 && !intel_renderbuffer_has_hiz(depthRb
)) {
618 /* Before Gen7, separate depth and stencil buffers can be used
619 * only if HiZ is enabled. From the Sandybridge PRM, Volume 2,
620 * Part 1, Bit 3DSTATE_DEPTH_BUFFER.SeparateStencilBufferEnable:
621 * [DevSNB]: This field must be set to the same value (enabled
622 * or disabled) as Hierarchical Depth Buffer Enable.
624 fbo_incomplete(fb
, "FBO incomplete: separate stencil "
630 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
631 struct gl_renderbuffer
*rb
;
632 struct intel_renderbuffer
*irb
;
634 if (fb
->Attachment
[i
].Type
== GL_NONE
)
637 /* A supported attachment will have a Renderbuffer set either
638 * from being a Renderbuffer or being a texture that got the
639 * intel_wrap_texture() treatment.
641 rb
= fb
->Attachment
[i
].Renderbuffer
;
643 fbo_incomplete(fb
, "FBO incomplete: attachment without "
648 if (fb
->Attachment
[i
].Type
== GL_TEXTURE
) {
649 if (rb
->TexImage
->Border
) {
650 fbo_incomplete(fb
, "FBO incomplete: texture with border\n");
655 irb
= intel_renderbuffer(rb
);
657 fbo_incomplete(fb
, "FBO incomplete: software rendering "
662 if (!brw_render_target_supported(brw
, rb
)) {
663 fbo_incomplete(fb
, "FBO incomplete: Unsupported HW "
664 "texture/renderbuffer format attached: %s\n",
665 _mesa_get_format_name(intel_rb_format(irb
)));
671 * Try to do a glBlitFramebuffer using glCopyTexSubImage2D
672 * We can do this when the dst renderbuffer is actually a texture and
673 * there is no scaling, mirroring or scissoring.
675 * \return new buffer mask indicating the buffers left to blit using the
679 intel_blit_framebuffer_with_blitter(struct gl_context
*ctx
,
680 GLint srcX0
, GLint srcY0
,
681 GLint srcX1
, GLint srcY1
,
682 GLint dstX0
, GLint dstY0
,
683 GLint dstX1
, GLint dstY1
,
684 GLbitfield mask
, GLenum filter
)
686 struct brw_context
*brw
= brw_context(ctx
);
688 /* Sync up the state of window system buffers. We need to do this before
689 * we go looking for the buffers.
691 intel_prepare_render(brw
);
693 if (mask
& GL_COLOR_BUFFER_BIT
) {
695 const struct gl_framebuffer
*drawFb
= ctx
->DrawBuffer
;
696 const struct gl_framebuffer
*readFb
= ctx
->ReadBuffer
;
697 struct gl_renderbuffer
*src_rb
= readFb
->_ColorReadBuffer
;
698 struct intel_renderbuffer
*src_irb
= intel_renderbuffer(src_rb
);
701 perf_debug("glBlitFramebuffer(): missing src renderbuffer. "
702 "Falling back to software rendering.\n");
706 /* If the source and destination are the same size with no mirroring,
707 * the rectangles are within the size of the texture and there is no
708 * scissor, then we can probably use the blit engine.
710 if (!(srcX0
- srcX1
== dstX0
- dstX1
&&
711 srcY0
- srcY1
== dstY0
- dstY1
&&
714 srcX0
>= 0 && srcX1
<= readFb
->Width
&&
715 srcY0
>= 0 && srcY1
<= readFb
->Height
&&
716 dstX0
>= 0 && dstX1
<= drawFb
->Width
&&
717 dstY0
>= 0 && dstY1
<= drawFb
->Height
&&
718 !ctx
->Scissor
.Enabled
)) {
719 perf_debug("glBlitFramebuffer(): non-1:1 blit. "
720 "Falling back to software rendering.\n");
724 /* Blit to all active draw buffers. We don't do any pre-checking,
725 * because we assume that copying to MRTs is rare, and failure midway
726 * through copying is even more rare. Even if it was to occur, it's
727 * safe to let meta start the copy over from scratch, because
728 * glBlitFramebuffer completely overwrites the destination pixels, and
729 * results are undefined if any destination pixels have a dependency on
732 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
733 struct gl_renderbuffer
*dst_rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
734 struct intel_renderbuffer
*dst_irb
= intel_renderbuffer(dst_rb
);
737 perf_debug("glBlitFramebuffer(): missing dst renderbuffer. "
738 "Falling back to software rendering.\n");
742 gl_format src_format
= _mesa_get_srgb_format_linear(src_rb
->Format
);
743 gl_format dst_format
= _mesa_get_srgb_format_linear(dst_rb
->Format
);
744 if (src_format
!= dst_format
) {
745 perf_debug("glBlitFramebuffer(): unsupported blit from %s to %s. "
746 "Falling back to software rendering.\n",
747 _mesa_get_format_name(src_format
),
748 _mesa_get_format_name(dst_format
));
752 if (!intel_miptree_blit(brw
,
754 src_irb
->mt_level
, src_irb
->mt_layer
,
755 srcX0
, srcY0
, src_rb
->Name
== 0,
757 dst_irb
->mt_level
, dst_irb
->mt_layer
,
758 dstX0
, dstY0
, dst_rb
->Name
== 0,
759 dstX1
- dstX0
, dstY1
- dstY0
, GL_COPY
)) {
760 perf_debug("glBlitFramebuffer(): unknown blit failure. "
761 "Falling back to software rendering.\n");
766 mask
&= ~GL_COLOR_BUFFER_BIT
;
773 intel_blit_framebuffer(struct gl_context
*ctx
,
774 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
775 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
776 GLbitfield mask
, GLenum filter
)
778 mask
= brw_blorp_framebuffer(brw_context(ctx
),
779 srcX0
, srcY0
, srcX1
, srcY1
,
780 dstX0
, dstY0
, dstX1
, dstY1
,
785 /* Try using the BLT engine. */
786 mask
= intel_blit_framebuffer_with_blitter(ctx
,
787 srcX0
, srcY0
, srcX1
, srcY1
,
788 dstX0
, dstY0
, dstX1
, dstY1
,
794 _mesa_meta_BlitFramebuffer(ctx
,
795 srcX0
, srcY0
, srcX1
, srcY1
,
796 dstX0
, dstY0
, dstX1
, dstY1
,
801 * This is a no-op except on multisample buffers shared with DRI2.
804 intel_renderbuffer_set_needs_downsample(struct intel_renderbuffer
*irb
)
806 if (irb
->mt
&& irb
->mt
->singlesample_mt
)
807 irb
->mt
->need_downsample
= true;
811 * Does the renderbuffer have hiz enabled?
814 intel_renderbuffer_has_hiz(struct intel_renderbuffer
*irb
)
816 return intel_miptree_slice_has_hiz(irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
820 intel_renderbuffer_resolve_hiz(struct brw_context
*brw
,
821 struct intel_renderbuffer
*irb
)
824 return intel_miptree_slice_resolve_hiz(brw
,
833 intel_renderbuffer_att_set_needs_depth_resolve(struct gl_renderbuffer_attachment
*att
)
835 struct intel_renderbuffer
*irb
= intel_renderbuffer(att
->Renderbuffer
);
838 intel_miptree_set_all_slices_need_depth_resolve(irb
->mt
, irb
->mt_level
);
840 intel_miptree_slice_set_needs_depth_resolve(irb
->mt
,
848 intel_renderbuffer_resolve_depth(struct brw_context
*brw
,
849 struct intel_renderbuffer
*irb
)
852 return intel_miptree_slice_resolve_depth(brw
,
861 intel_renderbuffer_move_to_temp(struct brw_context
*brw
,
862 struct intel_renderbuffer
*irb
,
865 struct gl_renderbuffer
*rb
=&irb
->Base
.Base
;
866 struct intel_texture_image
*intel_image
= intel_texture_image(rb
->TexImage
);
867 struct intel_mipmap_tree
*new_mt
;
868 int width
, height
, depth
;
870 intel_miptree_get_dimensions_for_image(rb
->TexImage
, &width
, &height
, &depth
);
872 new_mt
= intel_miptree_create(brw
, rb
->TexImage
->TexObject
->Target
,
873 intel_image
->base
.Base
.TexFormat
,
874 intel_image
->base
.Base
.Level
,
875 intel_image
->base
.Base
.Level
,
876 width
, height
, depth
,
878 irb
->mt
->num_samples
,
879 INTEL_MIPTREE_TILING_ANY
);
881 if (brw_is_hiz_depth_format(brw
, new_mt
->format
)) {
882 intel_miptree_alloc_hiz(brw
, new_mt
);
885 intel_miptree_copy_teximage(brw
, intel_image
, new_mt
, invalidate
);
887 intel_miptree_reference(&irb
->mt
, intel_image
->mt
);
888 intel_renderbuffer_set_draw_offset(irb
);
889 intel_miptree_release(&new_mt
);
893 * Do one-time context initializations related to GL_EXT_framebuffer_object.
894 * Hook in device driver functions.
897 intel_fbo_init(struct brw_context
*brw
)
899 struct dd_function_table
*dd
= &brw
->ctx
.Driver
;
900 dd
->NewFramebuffer
= intel_new_framebuffer
;
901 dd
->NewRenderbuffer
= intel_new_renderbuffer
;
902 dd
->MapRenderbuffer
= intel_map_renderbuffer
;
903 dd
->UnmapRenderbuffer
= intel_unmap_renderbuffer
;
904 dd
->RenderTexture
= intel_render_texture
;
905 dd
->FinishRenderTexture
= intel_finish_render_texture
;
906 dd
->ValidateFramebuffer
= intel_validate_framebuffer
;
907 dd
->BlitFramebuffer
= intel_blit_framebuffer
;
908 dd
->EGLImageTargetRenderbufferStorage
=
909 intel_image_target_renderbuffer_storage
;