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/mfeatures.h"
33 #include "main/mtypes.h"
34 #include "main/fbobject.h"
35 #include "main/framebuffer.h"
36 #include "main/renderbuffer.h"
37 #include "main/context.h"
38 #include "main/teximage.h"
39 #include "main/image.h"
41 #include "swrast/swrast.h"
42 #include "drivers/common/meta.h"
44 #include "intel_context.h"
45 #include "intel_batchbuffer.h"
46 #include "intel_buffers.h"
47 #include "intel_blit.h"
48 #include "intel_fbo.h"
49 #include "intel_mipmap_tree.h"
50 #include "intel_regions.h"
51 #include "intel_tex.h"
52 #include "intel_span.h"
54 #include "brw_context.h"
57 #define FILE_DEBUG_FLAG DEBUG_FBO
59 static struct gl_renderbuffer
*
60 intel_new_renderbuffer(struct gl_context
* ctx
, GLuint name
);
63 intel_get_rb_region(struct gl_framebuffer
*fb
, GLuint attIndex
)
65 struct intel_renderbuffer
*irb
= intel_get_renderbuffer(fb
, attIndex
);
67 if (attIndex
== BUFFER_STENCIL
&& irb
->mt
->stencil_mt
)
68 return irb
->mt
->stencil_mt
->region
;
70 return irb
->mt
->region
;
76 * Create a new framebuffer object.
78 static struct gl_framebuffer
*
79 intel_new_framebuffer(struct gl_context
* ctx
, GLuint name
)
81 /* Only drawable state in intel_framebuffer at this time, just use Mesa's
84 return _mesa_new_framebuffer(ctx
, name
);
88 /** Called by gl_renderbuffer::Delete() */
90 intel_delete_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
92 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
96 intel_miptree_release(&irb
->mt
);
98 _mesa_delete_renderbuffer(ctx
, rb
);
102 * \see dd_function_table::MapRenderbuffer
105 intel_map_renderbuffer(struct gl_context
*ctx
,
106 struct gl_renderbuffer
*rb
,
107 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
112 struct intel_context
*intel
= intel_context(ctx
);
113 struct swrast_renderbuffer
*srb
= (struct swrast_renderbuffer
*)rb
;
114 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
119 /* this is a malloc'd renderbuffer (accum buffer), not an irb */
120 GLint bpp
= _mesa_get_format_bytes(rb
->Format
);
121 GLint rowStride
= srb
->RowStride
;
122 *out_map
= (GLubyte
*) srb
->Buffer
+ y
* rowStride
+ x
* bpp
;
123 *out_stride
= rowStride
;
127 /* We sometimes get called with this by our intel_span.c usage. */
134 /* For a window-system renderbuffer, we need to flip the mapping we receive
135 * upside-down. So we need to ask for a rectangle on flipped vertically, and
136 * we then return a pointer to the bottom of it with a negative stride.
139 y
= rb
->Height
- y
- h
;
142 intel_miptree_map(intel
, irb
->mt
, irb
->mt_level
, irb
->mt_layer
,
143 x
, y
, w
, h
, mode
, &map
, &stride
);
146 map
+= (h
- 1) * stride
;
150 DBG("%s: rb %d (%s) mt mapped: (%d, %d) (%dx%d) -> %p/%d\n",
151 __FUNCTION__
, rb
->Name
, _mesa_get_format_name(rb
->Format
),
152 x
, y
, w
, h
, map
, stride
);
155 *out_stride
= stride
;
159 * \see dd_function_table::UnmapRenderbuffer
162 intel_unmap_renderbuffer(struct gl_context
*ctx
,
163 struct gl_renderbuffer
*rb
)
165 struct intel_context
*intel
= intel_context(ctx
);
166 struct swrast_renderbuffer
*srb
= (struct swrast_renderbuffer
*)rb
;
167 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
169 DBG("%s: rb %d (%s)\n", __FUNCTION__
,
170 rb
->Name
, _mesa_get_format_name(rb
->Format
));
173 /* this is a malloc'd renderbuffer (accum buffer) */
178 intel_miptree_unmap(intel
, irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
183 * Round up the requested multisample count to the next supported sample size.
186 intel_quantize_num_samples(struct intel_screen
*intel
, unsigned num_samples
)
188 switch (intel
->gen
) {
190 /* Gen6 supports only 4x multisampling. */
196 /* Gen7 supports 4x and 8x multisampling. */
199 else if (num_samples
> 0)
205 /* MSAA unsupported. */
212 * Called via glRenderbufferStorageEXT() to set the format and allocate
213 * storage for a user-created renderbuffer.
216 intel_alloc_renderbuffer_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
217 GLenum internalFormat
,
218 GLuint width
, GLuint height
)
220 struct intel_context
*intel
= intel_context(ctx
);
221 struct intel_screen
*screen
= intel
->intelScreen
;
222 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
223 rb
->NumSamples
= intel_quantize_num_samples(screen
, rb
->NumSamples
);
225 switch (internalFormat
) {
227 /* Use the same format-choice logic as for textures.
228 * Renderbuffers aren't any different from textures for us,
229 * except they're less useful because you can't texture with
232 rb
->Format
= intel
->ctx
.Driver
.ChooseTextureFormat(ctx
, GL_TEXTURE_2D
,
236 case GL_STENCIL_INDEX
:
237 case GL_STENCIL_INDEX1_EXT
:
238 case GL_STENCIL_INDEX4_EXT
:
239 case GL_STENCIL_INDEX8_EXT
:
240 case GL_STENCIL_INDEX16_EXT
:
241 /* These aren't actual texture formats, so force them here. */
242 if (intel
->has_separate_stencil
) {
243 rb
->Format
= MESA_FORMAT_S8
;
245 assert(!intel
->must_use_separate_stencil
);
246 rb
->Format
= MESA_FORMAT_S8_Z24
;
253 rb
->_BaseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
255 intel_miptree_release(&irb
->mt
);
257 DBG("%s: %s: %s (%dx%d)\n", __FUNCTION__
,
258 _mesa_lookup_enum_by_nr(internalFormat
),
259 _mesa_get_format_name(rb
->Format
), width
, height
);
261 if (width
== 0 || height
== 0)
264 irb
->mt
= intel_miptree_create_for_renderbuffer(intel
, rb
->Format
,
275 intel_image_target_renderbuffer_storage(struct gl_context
*ctx
,
276 struct gl_renderbuffer
*rb
,
279 struct intel_context
*intel
= intel_context(ctx
);
280 struct intel_renderbuffer
*irb
;
284 screen
= intel
->intelScreen
->driScrnPriv
;
285 image
= screen
->dri2
.image
->lookupEGLImage(screen
, image_handle
,
286 screen
->loaderPrivate
);
290 /* __DRIimage is opaque to the core so it has to be checked here */
291 switch (image
->format
) {
292 case MESA_FORMAT_RGBA8888_REV
:
293 _mesa_error(&intel
->ctx
, GL_INVALID_OPERATION
,
294 "glEGLImageTargetRenderbufferStorage(unsupported image format");
301 irb
= intel_renderbuffer(rb
);
302 intel_miptree_release(&irb
->mt
);
303 irb
->mt
= intel_miptree_create_for_region(intel
,
310 rb
->InternalFormat
= image
->internal_format
;
311 rb
->Width
= image
->region
->width
;
312 rb
->Height
= image
->region
->height
;
313 rb
->Format
= image
->format
;
314 rb
->_BaseFormat
= _mesa_base_fbo_format(&intel
->ctx
,
315 image
->internal_format
);
319 * Called for each hardware renderbuffer when a _window_ is resized.
320 * Just update fields.
321 * Not used for user-created renderbuffers!
324 intel_alloc_window_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
325 GLenum internalFormat
, GLuint width
, GLuint height
)
327 ASSERT(rb
->Name
== 0);
330 rb
->InternalFormat
= internalFormat
;
337 intel_resize_buffers(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
338 GLuint width
, GLuint height
)
342 _mesa_resize_framebuffer(ctx
, fb
, width
, height
);
344 fb
->Initialized
= true; /* XXX remove someday */
346 if (_mesa_is_user_fbo(fb
)) {
351 /* Make sure all window system renderbuffers are up to date */
352 for (i
= BUFFER_FRONT_LEFT
; i
<= BUFFER_BACK_RIGHT
; i
++) {
353 struct gl_renderbuffer
*rb
= fb
->Attachment
[i
].Renderbuffer
;
355 /* only resize if size is changing */
356 if (rb
&& (rb
->Width
!= width
|| rb
->Height
!= height
)) {
357 rb
->AllocStorage(ctx
, rb
, rb
->InternalFormat
, width
, height
);
363 /** Dummy function for gl_renderbuffer::AllocStorage() */
365 intel_nop_alloc_storage(struct gl_context
* ctx
, struct gl_renderbuffer
*rb
,
366 GLenum internalFormat
, GLuint width
, GLuint height
)
368 _mesa_problem(ctx
, "intel_op_alloc_storage should never be called.");
373 * Create a new intel_renderbuffer which corresponds to an on-screen window,
374 * not a user-created renderbuffer.
376 * \param num_samples must be quantized.
378 struct intel_renderbuffer
*
379 intel_create_renderbuffer(gl_format format
, unsigned num_samples
)
381 struct intel_renderbuffer
*irb
;
382 struct gl_renderbuffer
*rb
;
384 GET_CURRENT_CONTEXT(ctx
);
386 irb
= CALLOC_STRUCT(intel_renderbuffer
);
388 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
392 rb
= &irb
->Base
.Base
;
394 _mesa_init_renderbuffer(rb
, 0);
395 rb
->ClassID
= INTEL_RB_CLASS
;
396 rb
->_BaseFormat
= _mesa_get_format_base_format(format
);
398 rb
->InternalFormat
= rb
->_BaseFormat
;
399 rb
->NumSamples
= num_samples
;
401 /* intel-specific methods */
402 rb
->Delete
= intel_delete_renderbuffer
;
403 rb
->AllocStorage
= intel_alloc_window_storage
;
409 * Private window-system buffers (as opposed to ones shared with the display
410 * server created with intel_create_renderbuffer()) are most similar in their
411 * handling to user-created renderbuffers, but they have a resize handler that
412 * may be called at intel_update_renderbuffers() time.
414 * \param num_samples must be quantized.
416 struct intel_renderbuffer
*
417 intel_create_private_renderbuffer(gl_format format
, unsigned num_samples
)
419 struct intel_renderbuffer
*irb
;
421 irb
= intel_create_renderbuffer(format
, num_samples
);
422 irb
->Base
.Base
.AllocStorage
= intel_alloc_renderbuffer_storage
;
428 * Create a new renderbuffer object.
429 * Typically called via glBindRenderbufferEXT().
431 static struct gl_renderbuffer
*
432 intel_new_renderbuffer(struct gl_context
* ctx
, GLuint name
)
434 /*struct intel_context *intel = intel_context(ctx); */
435 struct intel_renderbuffer
*irb
;
436 struct gl_renderbuffer
*rb
;
438 irb
= CALLOC_STRUCT(intel_renderbuffer
);
440 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
444 rb
= &irb
->Base
.Base
;
446 _mesa_init_renderbuffer(rb
, name
);
447 rb
->ClassID
= INTEL_RB_CLASS
;
449 /* intel-specific methods */
450 rb
->Delete
= intel_delete_renderbuffer
;
451 rb
->AllocStorage
= intel_alloc_renderbuffer_storage
;
452 /* span routines set in alloc_storage function */
459 * Called via glBindFramebufferEXT().
462 intel_bind_framebuffer(struct gl_context
* ctx
, GLenum target
,
463 struct gl_framebuffer
*fb
, struct gl_framebuffer
*fbread
)
465 if (target
== GL_FRAMEBUFFER_EXT
|| target
== GL_DRAW_FRAMEBUFFER_EXT
) {
466 intel_draw_buffer(ctx
);
469 /* don't need to do anything if target == GL_READ_FRAMEBUFFER_EXT */
475 * Called via glFramebufferRenderbufferEXT().
478 intel_framebuffer_renderbuffer(struct gl_context
* ctx
,
479 struct gl_framebuffer
*fb
,
480 GLenum attachment
, struct gl_renderbuffer
*rb
)
482 DBG("Intel FramebufferRenderbuffer %u %u\n", fb
->Name
, rb
? rb
->Name
: 0);
484 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
485 intel_draw_buffer(ctx
);
489 intel_renderbuffer_update_wrapper(struct intel_context
*intel
,
490 struct intel_renderbuffer
*irb
,
491 struct gl_texture_image
*image
,
494 struct gl_renderbuffer
*rb
= &irb
->Base
.Base
;
495 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
496 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
497 int level
= image
->Level
;
499 rb
->Format
= image
->TexFormat
;
500 rb
->InternalFormat
= image
->InternalFormat
;
501 rb
->_BaseFormat
= image
->_BaseFormat
;
502 rb
->NumSamples
= mt
->num_samples
;
504 if (mt
->msaa_layout
!= INTEL_MSAA_LAYOUT_NONE
) {
506 rb
->Width
= mt
->logical_width0
;
507 rb
->Height
= mt
->logical_height0
;
510 rb
->Width
= mt
->level
[level
].width
;
511 rb
->Height
= mt
->level
[level
].height
;
514 rb
->Delete
= intel_delete_renderbuffer
;
515 rb
->AllocStorage
= intel_nop_alloc_storage
;
517 intel_miptree_check_level_layer(mt
, level
, layer
);
518 irb
->mt_level
= level
;
520 switch (mt
->msaa_layout
) {
521 case INTEL_MSAA_LAYOUT_UMS
:
522 case INTEL_MSAA_LAYOUT_CMS
:
523 irb
->mt_layer
= layer
* mt
->num_samples
;
527 irb
->mt_layer
= layer
;
530 intel_miptree_reference(&irb
->mt
, mt
);
532 intel_renderbuffer_set_draw_offset(irb
);
534 if (mt
->hiz_mt
== NULL
&&
535 intel
->vtbl
.is_hiz_depth_format(intel
, rb
->Format
)) {
536 intel_miptree_alloc_hiz(intel
, mt
, 0 /* num_samples */);
545 * Create a fake intel_renderbuffer that wraps a gl_texture_image.
547 struct intel_renderbuffer
*
548 intel_create_fake_renderbuffer_wrapper(struct intel_context
*intel
,
549 struct gl_texture_image
*image
)
551 struct gl_context
*ctx
= &intel
->ctx
;
552 struct intel_renderbuffer
*irb
;
553 struct gl_renderbuffer
*rb
;
555 irb
= CALLOC_STRUCT(intel_renderbuffer
);
557 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "creating renderbuffer");
561 rb
= &irb
->Base
.Base
;
563 _mesa_init_renderbuffer(rb
, 0);
564 rb
->ClassID
= INTEL_RB_CLASS
;
566 if (!intel_renderbuffer_update_wrapper(intel
, irb
, image
, image
->Face
)) {
567 intel_delete_renderbuffer(ctx
, rb
);
575 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer
*irb
)
577 unsigned int dst_x
, dst_y
;
579 /* compute offset of the particular 2D image within the texture region */
580 intel_miptree_get_image_offset(irb
->mt
,
590 * Rendering to tiled buffers requires that the base address of the
591 * buffer be aligned to a page boundary. We generally render to
592 * textures by pointing the surface at the mipmap image level, which
593 * may not be aligned to a tile boundary.
595 * This function returns an appropriately-aligned base offset
596 * according to the tiling restrictions, plus any required x/y offset
600 intel_renderbuffer_tile_offsets(struct intel_renderbuffer
*irb
,
604 struct intel_region
*region
= irb
->mt
->region
;
605 uint32_t mask_x
, mask_y
;
607 intel_region_get_tile_masks(region
, &mask_x
, &mask_y
, false);
609 *tile_x
= irb
->draw_x
& mask_x
;
610 *tile_y
= irb
->draw_y
& mask_y
;
611 return intel_region_get_aligned_offset(region
, irb
->draw_x
& ~mask_x
,
612 irb
->draw_y
& ~mask_y
, false);
616 * Called by glFramebufferTexture[123]DEXT() (and other places) to
617 * prepare for rendering into texture memory. This might be called
618 * many times to choose different texture levels, cube faces, etc
619 * before intel_finish_render_texture() is ever called.
622 intel_render_texture(struct gl_context
* ctx
,
623 struct gl_framebuffer
*fb
,
624 struct gl_renderbuffer_attachment
*att
)
626 struct intel_context
*intel
= intel_context(ctx
);
627 struct gl_texture_image
*image
= _mesa_get_attachment_teximage(att
);
628 struct intel_renderbuffer
*irb
= intel_renderbuffer(att
->Renderbuffer
);
629 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
630 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
635 if (att
->CubeMapFace
> 0) {
636 assert(att
->Zoffset
== 0);
637 layer
= att
->CubeMapFace
;
639 layer
= att
->Zoffset
;
642 if (!intel_image
->mt
) {
643 /* Fallback on drawing to a texture that doesn't have a miptree
644 * (has a border, width/height 0, etc.)
646 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
);
647 _swrast_render_texture(ctx
, fb
, att
);
651 intel_miptree_check_level_layer(mt
, att
->TextureLevel
, layer
);
653 irb
= (struct intel_renderbuffer
*)intel_new_renderbuffer(ctx
, ~0);
656 /* bind the wrapper to the attachment point */
657 _mesa_reference_renderbuffer(&att
->Renderbuffer
, &irb
->Base
.Base
);
660 /* fallback to software rendering */
661 _swrast_render_texture(ctx
, fb
, att
);
666 if (!intel_renderbuffer_update_wrapper(intel
, irb
, image
, layer
)) {
667 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
);
668 _swrast_render_texture(ctx
, fb
, att
);
672 irb
->tex_image
= image
;
674 DBG("Begin render %s texture tex=%u w=%d h=%d refcount=%d\n",
675 _mesa_get_format_name(image
->TexFormat
),
676 att
->Texture
->Name
, image
->Width
, image
->Height
,
677 irb
->Base
.Base
.RefCount
);
679 /* update drawing region, etc */
680 intel_draw_buffer(ctx
);
685 * Called by Mesa when rendering to a texture is done.
688 intel_finish_render_texture(struct gl_context
* ctx
,
689 struct gl_renderbuffer_attachment
*att
)
691 struct intel_context
*intel
= intel_context(ctx
);
692 struct gl_texture_object
*tex_obj
= att
->Texture
;
693 struct gl_texture_image
*image
=
694 tex_obj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
695 struct intel_renderbuffer
*irb
= intel_renderbuffer(att
->Renderbuffer
);
697 DBG("Finish render %s texture tex=%u\n",
698 _mesa_get_format_name(image
->TexFormat
), att
->Texture
->Name
);
701 irb
->tex_image
= NULL
;
703 /* Since we've (probably) rendered to the texture and will (likely) use
704 * it in the texture domain later on in this batchbuffer, flush the
705 * batch. Once again, we wish for a domain tracker in libdrm to cover
706 * usage inside of a batchbuffer like GEM does in the kernel.
708 intel_batchbuffer_emit_mi_flush(intel
);
712 * Do additional "completeness" testing of a framebuffer object.
715 intel_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
717 struct intel_context
*intel
= intel_context(ctx
);
718 struct intel_renderbuffer
*depthRb
=
719 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
720 struct intel_renderbuffer
*stencilRb
=
721 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
722 struct intel_mipmap_tree
*depth_mt
= NULL
, *stencil_mt
= NULL
;
725 DBG("%s() on fb %p (%s)\n", __FUNCTION__
,
726 fb
, (fb
== ctx
->DrawBuffer
? "drawbuffer" :
727 (fb
== ctx
->ReadBuffer
? "readbuffer" : "other buffer")));
730 depth_mt
= depthRb
->mt
;
732 stencil_mt
= stencilRb
->mt
;
733 if (stencil_mt
->stencil_mt
)
734 stencil_mt
= stencil_mt
->stencil_mt
;
737 if (depth_mt
&& stencil_mt
) {
738 if (depth_mt
== stencil_mt
) {
739 /* For true packed depth/stencil (not faked on prefers-separate-stencil
740 * hardware) we need to be sure they're the same level/layer, since
741 * we'll be emitting a single packet describing the packed setup.
743 if (depthRb
->mt_level
!= stencilRb
->mt_level
||
744 depthRb
->mt_layer
!= stencilRb
->mt_layer
) {
745 DBG("depth image level/layer %d/%d != stencil image %d/%d\n",
749 stencilRb
->mt_layer
);
750 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
753 if (!intel
->has_separate_stencil
) {
754 DBG("separate stencil unsupported\n");
755 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
757 if (stencil_mt
->format
!= MESA_FORMAT_S8
) {
758 DBG("separate stencil is %s instead of S8\n",
759 _mesa_get_format_name(stencil_mt
->format
));
760 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
762 if (intel
->gen
< 7 && !intel_renderbuffer_has_hiz(depthRb
)) {
763 /* Before Gen7, separate depth and stencil buffers can be used
764 * only if HiZ is enabled. From the Sandybridge PRM, Volume 2,
765 * Part 1, Bit 3DSTATE_DEPTH_BUFFER.SeparateStencilBufferEnable:
766 * [DevSNB]: This field must be set to the same value (enabled
767 * or disabled) as Hierarchical Depth Buffer Enable.
769 DBG("separate stencil without HiZ\n");
770 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
775 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
776 struct gl_renderbuffer
*rb
;
777 struct intel_renderbuffer
*irb
;
779 if (fb
->Attachment
[i
].Type
== GL_NONE
)
782 /* A supported attachment will have a Renderbuffer set either
783 * from being a Renderbuffer or being a texture that got the
784 * intel_wrap_texture() treatment.
786 rb
= fb
->Attachment
[i
].Renderbuffer
;
788 DBG("attachment without renderbuffer\n");
789 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
793 if (fb
->Attachment
[i
].Type
== GL_TEXTURE
) {
794 const struct gl_texture_image
*img
=
795 _mesa_get_attachment_teximage_const(&fb
->Attachment
[i
]);
798 DBG("texture with border\n");
799 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
804 irb
= intel_renderbuffer(rb
);
806 DBG("software rendering renderbuffer\n");
807 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
811 if (!intel
->vtbl
.render_target_supported(intel
, rb
)) {
812 DBG("Unsupported HW texture/renderbuffer format attached: %s\n",
813 _mesa_get_format_name(intel_rb_format(irb
)));
814 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED_EXT
;
820 * Try to do a glBlitFramebuffer using glCopyTexSubImage2D
821 * We can do this when the dst renderbuffer is actually a texture and
822 * there is no scaling, mirroring or scissoring.
824 * \return new buffer mask indicating the buffers left to blit using the
828 intel_blit_framebuffer_copy_tex_sub_image(struct gl_context
*ctx
,
829 GLint srcX0
, GLint srcY0
,
830 GLint srcX1
, GLint srcY1
,
831 GLint dstX0
, GLint dstY0
,
832 GLint dstX1
, GLint dstY1
,
833 GLbitfield mask
, GLenum filter
)
835 if (mask
& GL_COLOR_BUFFER_BIT
) {
837 const struct gl_framebuffer
*drawFb
= ctx
->DrawBuffer
;
838 const struct gl_framebuffer
*readFb
= ctx
->ReadBuffer
;
839 const struct gl_renderbuffer_attachment
*drawAtt
;
840 struct intel_renderbuffer
*srcRb
=
841 intel_renderbuffer(readFb
->_ColorReadBuffer
);
843 /* If the source and destination are the same size with no mirroring,
844 * the rectangles are within the size of the texture and there is no
845 * scissor then we can use glCopyTexSubimage2D to implement the blit.
846 * This will end up as a fast hardware blit on some drivers.
848 const GLboolean use_intel_copy_texsubimage
=
849 srcX0
- srcX1
== dstX0
- dstX1
&&
850 srcY0
- srcY1
== dstY0
- dstY1
&&
853 srcX0
>= 0 && srcX1
<= readFb
->Width
&&
854 srcY0
>= 0 && srcY1
<= readFb
->Height
&&
855 dstX0
>= 0 && dstX1
<= drawFb
->Width
&&
856 dstY0
>= 0 && dstY1
<= drawFb
->Height
&&
857 !ctx
->Scissor
.Enabled
;
859 /* Verify that all the draw buffers can be blitted using
860 * intel_copy_texsubimage().
862 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
863 int idx
= ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[i
];
866 drawAtt
= &drawFb
->Attachment
[idx
];
868 if (srcRb
&& drawAtt
&& drawAtt
->Texture
&&
869 use_intel_copy_texsubimage
)
875 /* Blit to all active draw buffers */
876 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
877 int idx
= ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[i
];
880 drawAtt
= &drawFb
->Attachment
[idx
];
883 const struct gl_texture_object
*texObj
= drawAtt
->Texture
;
884 const GLuint dstLevel
= drawAtt
->TextureLevel
;
885 const GLenum target
= texObj
->Target
;
887 struct gl_texture_image
*texImage
=
888 _mesa_select_tex_image(ctx
, texObj
, target
, dstLevel
);
890 if (!intel_copy_texsubimage(intel_context(ctx
),
891 intel_texture_image(texImage
),
895 srcX1
- srcX0
, /* width */
901 mask
&= ~GL_COLOR_BUFFER_BIT
;
908 intel_blit_framebuffer(struct gl_context
*ctx
,
909 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
910 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
911 GLbitfield mask
, GLenum filter
)
913 /* Try faster, glCopyTexSubImage2D approach first which uses the BLT. */
914 mask
= intel_blit_framebuffer_copy_tex_sub_image(ctx
,
915 srcX0
, srcY0
, srcX1
, srcY1
,
916 dstX0
, dstY0
, dstX1
, dstY1
,
922 mask
= brw_blorp_framebuffer(intel_context(ctx
),
923 srcX0
, srcY0
, srcX1
, srcY1
,
924 dstX0
, dstY0
, dstX1
, dstY1
,
930 _mesa_meta_BlitFramebuffer(ctx
,
931 srcX0
, srcY0
, srcX1
, srcY1
,
932 dstX0
, dstY0
, dstX1
, dstY1
,
937 * This is a no-op except on multisample buffers shared with DRI2.
940 intel_renderbuffer_set_needs_downsample(struct intel_renderbuffer
*irb
)
942 if (irb
->mt
&& irb
->mt
->singlesample_mt
)
943 irb
->mt
->need_downsample
= true;
947 * Does the renderbuffer have hiz enabled?
950 intel_renderbuffer_has_hiz(struct intel_renderbuffer
*irb
)
952 return intel_miptree_slice_has_hiz(irb
->mt
, irb
->mt_level
, irb
->mt_layer
);
956 intel_renderbuffer_set_needs_hiz_resolve(struct intel_renderbuffer
*irb
)
959 intel_miptree_slice_set_needs_hiz_resolve(irb
->mt
,
966 intel_renderbuffer_set_needs_depth_resolve(struct intel_renderbuffer
*irb
)
969 intel_miptree_slice_set_needs_depth_resolve(irb
->mt
,
976 intel_renderbuffer_resolve_hiz(struct intel_context
*intel
,
977 struct intel_renderbuffer
*irb
)
980 return intel_miptree_slice_resolve_hiz(intel
,
989 intel_renderbuffer_resolve_depth(struct intel_context
*intel
,
990 struct intel_renderbuffer
*irb
)
993 return intel_miptree_slice_resolve_depth(intel
,
1002 intel_renderbuffer_move_to_temp(struct intel_context
*intel
,
1003 struct intel_renderbuffer
*irb
,
1006 struct intel_texture_image
*intel_image
=
1007 intel_texture_image(irb
->tex_image
);
1008 struct intel_mipmap_tree
*new_mt
;
1009 int width
, height
, depth
;
1011 intel_miptree_get_dimensions_for_image(irb
->tex_image
, &width
, &height
, &depth
);
1013 new_mt
= intel_miptree_create(intel
, irb
->tex_image
->TexObject
->Target
,
1014 intel_image
->base
.Base
.TexFormat
,
1015 intel_image
->base
.Base
.Level
,
1016 intel_image
->base
.Base
.Level
,
1017 width
, height
, depth
,
1019 irb
->mt
->num_samples
,
1020 false /* force_y_tiling */);
1022 if (intel
->vtbl
.is_hiz_depth_format(intel
, new_mt
->format
)) {
1023 intel_miptree_alloc_hiz(intel
, new_mt
, irb
->mt
->num_samples
);
1026 intel_miptree_copy_teximage(intel
, intel_image
, new_mt
, invalidate
);
1028 intel_miptree_reference(&irb
->mt
, intel_image
->mt
);
1029 intel_renderbuffer_set_draw_offset(irb
);
1030 intel_miptree_release(&new_mt
);
1034 * Do one-time context initializations related to GL_EXT_framebuffer_object.
1035 * Hook in device driver functions.
1038 intel_fbo_init(struct intel_context
*intel
)
1040 intel
->ctx
.Driver
.NewFramebuffer
= intel_new_framebuffer
;
1041 intel
->ctx
.Driver
.NewRenderbuffer
= intel_new_renderbuffer
;
1042 intel
->ctx
.Driver
.MapRenderbuffer
= intel_map_renderbuffer
;
1043 intel
->ctx
.Driver
.UnmapRenderbuffer
= intel_unmap_renderbuffer
;
1044 intel
->ctx
.Driver
.BindFramebuffer
= intel_bind_framebuffer
;
1045 intel
->ctx
.Driver
.FramebufferRenderbuffer
= intel_framebuffer_renderbuffer
;
1046 intel
->ctx
.Driver
.RenderTexture
= intel_render_texture
;
1047 intel
->ctx
.Driver
.FinishRenderTexture
= intel_finish_render_texture
;
1048 intel
->ctx
.Driver
.ResizeBuffers
= intel_resize_buffers
;
1049 intel
->ctx
.Driver
.ValidateFramebuffer
= intel_validate_framebuffer
;
1050 intel
->ctx
.Driver
.BlitFramebuffer
= intel_blit_framebuffer
;
1051 intel
->ctx
.Driver
.EGLImageTargetRenderbufferStorage
=
1052 intel_image_target_renderbuffer_storage
;