2007-11-07 10:04:59 -08:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
2008-09-18 15:17:05 -06:00
|
|
|
#include "main/imports.h"
|
2009-01-22 15:43:40 -07:00
|
|
|
#include "main/macros.h"
|
2011-01-09 01:25:54 -08:00
|
|
|
#include "main/mfeatures.h"
|
2008-09-18 15:17:05 -06:00
|
|
|
#include "main/mtypes.h"
|
|
|
|
#include "main/fbobject.h"
|
|
|
|
#include "main/framebuffer.h"
|
|
|
|
#include "main/renderbuffer.h"
|
|
|
|
#include "main/context.h"
|
2011-02-05 10:21:11 +00:00
|
|
|
#include "main/teximage.h"
|
2011-06-13 16:07:32 -06:00
|
|
|
#include "swrast/swrast.h"
|
2009-08-10 13:43:00 -06:00
|
|
|
#include "drivers/common/meta.h"
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
#include "intel_context.h"
|
2009-12-09 11:36:45 -08:00
|
|
|
#include "intel_batchbuffer.h"
|
2007-11-07 10:04:59 -08:00
|
|
|
#include "intel_buffers.h"
|
|
|
|
#include "intel_fbo.h"
|
|
|
|
#include "intel_mipmap_tree.h"
|
|
|
|
#include "intel_regions.h"
|
2010-12-09 17:08:31 -08:00
|
|
|
#include "intel_tex.h"
|
|
|
|
#include "intel_span.h"
|
2011-01-10 15:45:28 -08:00
|
|
|
#ifndef I915
|
|
|
|
#include "brw_context.h"
|
|
|
|
#endif
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
#define FILE_DEBUG_FLAG DEBUG_FBO
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new framebuffer object.
|
|
|
|
*/
|
|
|
|
static struct gl_framebuffer *
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_new_framebuffer(struct gl_context * ctx, GLuint name)
|
2007-11-07 10:04:59 -08:00
|
|
|
{
|
|
|
|
/* Only drawable state in intel_framebuffer at this time, just use Mesa's
|
|
|
|
* class
|
|
|
|
*/
|
|
|
|
return _mesa_new_framebuffer(ctx, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
/** Called by gl_renderbuffer::Delete() */
|
2007-11-07 10:04:59 -08:00
|
|
|
static void
|
|
|
|
intel_delete_renderbuffer(struct gl_renderbuffer *rb)
|
|
|
|
{
|
|
|
|
struct intel_renderbuffer *irb = intel_renderbuffer(rb);
|
|
|
|
|
|
|
|
ASSERT(irb);
|
|
|
|
|
2011-06-29 11:37:35 -07:00
|
|
|
intel_region_release(&irb->region);
|
|
|
|
intel_region_release(&irb->hiz_region);
|
|
|
|
|
|
|
|
_mesa_reference_renderbuffer(&irb->wrapped_depth, NULL);
|
|
|
|
_mesa_reference_renderbuffer(&irb->wrapped_stencil, NULL);
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2010-02-19 11:58:49 -05:00
|
|
|
free(irb);
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a pointer to a specific pixel in a renderbuffer.
|
|
|
|
*/
|
|
|
|
static void *
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_get_pointer(struct gl_context * ctx, struct gl_renderbuffer *rb,
|
2007-11-07 10:04:59 -08:00
|
|
|
GLint x, GLint y)
|
|
|
|
{
|
|
|
|
/* By returning NULL we force all software rendering to go through
|
|
|
|
* the span routines.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called via glRenderbufferStorageEXT() to set the format and allocate
|
|
|
|
* storage for a user-created renderbuffer.
|
|
|
|
*/
|
2011-06-22 10:26:26 -07:00
|
|
|
GLboolean
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffer *rb,
|
2007-11-07 10:04:59 -08:00
|
|
|
GLenum internalFormat,
|
|
|
|
GLuint width, GLuint height)
|
|
|
|
{
|
|
|
|
struct intel_context *intel = intel_context(ctx);
|
|
|
|
struct intel_renderbuffer *irb = intel_renderbuffer(rb);
|
2010-09-30 10:49:47 +08:00
|
|
|
int cpp, tiling;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
ASSERT(rb->Name != 0);
|
|
|
|
|
|
|
|
switch (internalFormat) {
|
2010-12-09 17:15:26 -08:00
|
|
|
default:
|
|
|
|
/* Use the same format-choice logic as for textures.
|
|
|
|
* Renderbuffers aren't any different from textures for us,
|
|
|
|
* except they're less useful because you can't texture with
|
|
|
|
* them.
|
|
|
|
*/
|
2011-01-04 13:44:34 -08:00
|
|
|
rb->Format = intel->ctx.Driver.ChooseTextureFormat(ctx, internalFormat,
|
|
|
|
GL_NONE, GL_NONE);
|
2010-08-25 06:14:42 -07:00
|
|
|
break;
|
2007-11-07 10:04:59 -08:00
|
|
|
case GL_STENCIL_INDEX:
|
|
|
|
case GL_STENCIL_INDEX1_EXT:
|
|
|
|
case GL_STENCIL_INDEX4_EXT:
|
|
|
|
case GL_STENCIL_INDEX8_EXT:
|
|
|
|
case GL_STENCIL_INDEX16_EXT:
|
2010-12-09 17:15:26 -08:00
|
|
|
/* These aren't actual texture formats, so force them here. */
|
2011-05-23 13:47:35 -07:00
|
|
|
if (intel->has_separate_stencil) {
|
|
|
|
rb->Format = MESA_FORMAT_S8;
|
|
|
|
} else {
|
|
|
|
assert(!intel->must_use_separate_stencil);
|
|
|
|
rb->Format = MESA_FORMAT_S8_Z24;
|
|
|
|
}
|
2007-11-07 10:04:59 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-06-17 12:12:35 -07:00
|
|
|
rb->Width = width;
|
|
|
|
rb->Height = height;
|
2009-10-08 20:27:27 -06:00
|
|
|
rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
|
2010-12-09 17:08:31 -08:00
|
|
|
rb->DataType = intel_mesa_format_to_rb_datatype(rb->Format);
|
2009-12-08 16:06:13 -08:00
|
|
|
cpp = _mesa_get_format_bytes(rb->Format);
|
2009-10-08 20:27:27 -06:00
|
|
|
|
2010-05-10 17:42:43 -04:00
|
|
|
intel_flush(ctx);
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
/* free old region */
|
|
|
|
if (irb->region) {
|
|
|
|
intel_region_release(&irb->region);
|
|
|
|
}
|
2011-05-23 13:48:04 -07:00
|
|
|
if (irb->hiz_region) {
|
|
|
|
intel_region_release(&irb->hiz_region);
|
|
|
|
}
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
/* allocate new memory region/renderbuffer */
|
|
|
|
|
2009-12-08 15:51:18 -08:00
|
|
|
/* alloc hardware renderbuffer */
|
2010-03-16 16:20:03 -07:00
|
|
|
DBG("Allocating %d x %d Intel RBO\n", width, height);
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2010-09-30 10:49:47 +08:00
|
|
|
tiling = I915_TILING_NONE;
|
2011-01-07 18:18:50 -08:00
|
|
|
if (intel->use_texture_tiling) {
|
|
|
|
GLenum base_format = _mesa_get_format_base_format(rb->Format);
|
|
|
|
|
|
|
|
if (intel->gen >= 4 && (base_format == GL_DEPTH_COMPONENT ||
|
2011-05-23 13:47:35 -07:00
|
|
|
base_format == GL_STENCIL_INDEX ||
|
2011-01-07 18:18:50 -08:00
|
|
|
base_format == GL_DEPTH_STENCIL))
|
|
|
|
tiling = I915_TILING_Y;
|
|
|
|
else
|
|
|
|
tiling = I915_TILING_X;
|
|
|
|
}
|
2010-09-30 10:49:47 +08:00
|
|
|
|
2011-05-23 13:47:35 -07:00
|
|
|
if (irb->Base.Format == MESA_FORMAT_S8) {
|
|
|
|
/*
|
intel: Fix stencil buffer to be W tiled
Until now, the stencil buffer was allocated as a Y tiled buffer, because
in several locations the PRM states that it is. However, it is actually
W tiled. From the PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section
4.5.2.1 W-Major Format:
W-Major Tile Format is used for separate stencil.
The GTT is incapable of W fencing, so we allocate the stencil buffer with
I915_TILING_NONE and decode the tile's layout in software.
This fix touches the following portions of code:
- In intel_allocate_renderbuffer_storage(), allocate the stencil
buffer with I915_TILING_NONE.
- In intel_verify_dri2_has_hiz(), verify that the stencil buffer is
not tiled.
- In the stencil buffer's span functions, the tile's layout must be
decoded in software.
This commit mutually depends on the xf86-video-intel commit
dri: Do not tile stencil buffer
Author: Chad Versace <chad@chad-versace.us>
Date: Mon Jul 18 00:38:00 2011 -0700
On Gen6 with separate stencil enabled, fixes the following Piglit tests:
bugs/fdo23670-drawpix_stencil
general/stencil-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-readpixels
spec/EXT_packed_depth_stencil/fbo-stencil-GL_DEPTH24_STENCIL8-copypixels
spec/EXT_packed_depth_stencil/fbo-stencil-GL_DEPTH24_STENCIL8-readpixels
spec/EXT_packed_depth_stencil/readpixels-24_8
Note: This is a candidate for the 7.11 branch.
Signed-off-by: Chad Versace <chad@chad-versace.us>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
2011-07-18 00:37:45 -07:00
|
|
|
* The stencil buffer is W tiled. However, we request from the kernel a
|
|
|
|
* non-tiled buffer because the GTT is incapable of W fencing.
|
|
|
|
*
|
2011-05-23 13:47:35 -07:00
|
|
|
* The stencil buffer has quirky pitch requirements. From Vol 2a,
|
|
|
|
* 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":
|
|
|
|
* The pitch must be set to 2x the value computed based on width, as
|
|
|
|
* the stencil buffer is stored with two rows interleaved.
|
|
|
|
* To accomplish this, we resort to the nasty hack of doubling the drm
|
|
|
|
* region's cpp and halving its height.
|
|
|
|
*
|
intel: Fix stencil buffer to be W tiled
Until now, the stencil buffer was allocated as a Y tiled buffer, because
in several locations the PRM states that it is. However, it is actually
W tiled. From the PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section
4.5.2.1 W-Major Format:
W-Major Tile Format is used for separate stencil.
The GTT is incapable of W fencing, so we allocate the stencil buffer with
I915_TILING_NONE and decode the tile's layout in software.
This fix touches the following portions of code:
- In intel_allocate_renderbuffer_storage(), allocate the stencil
buffer with I915_TILING_NONE.
- In intel_verify_dri2_has_hiz(), verify that the stencil buffer is
not tiled.
- In the stencil buffer's span functions, the tile's layout must be
decoded in software.
This commit mutually depends on the xf86-video-intel commit
dri: Do not tile stencil buffer
Author: Chad Versace <chad@chad-versace.us>
Date: Mon Jul 18 00:38:00 2011 -0700
On Gen6 with separate stencil enabled, fixes the following Piglit tests:
bugs/fdo23670-drawpix_stencil
general/stencil-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-readpixels
spec/EXT_packed_depth_stencil/fbo-stencil-GL_DEPTH24_STENCIL8-copypixels
spec/EXT_packed_depth_stencil/fbo-stencil-GL_DEPTH24_STENCIL8-readpixels
spec/EXT_packed_depth_stencil/readpixels-24_8
Note: This is a candidate for the 7.11 branch.
Signed-off-by: Chad Versace <chad@chad-versace.us>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
2011-07-18 00:37:45 -07:00
|
|
|
* If we neglect to double the pitch, then render corruption occurs.
|
2011-05-23 13:47:35 -07:00
|
|
|
*/
|
|
|
|
irb->region = intel_region_alloc(intel->intelScreen,
|
intel: Fix stencil buffer to be W tiled
Until now, the stencil buffer was allocated as a Y tiled buffer, because
in several locations the PRM states that it is. However, it is actually
W tiled. From the PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section
4.5.2.1 W-Major Format:
W-Major Tile Format is used for separate stencil.
The GTT is incapable of W fencing, so we allocate the stencil buffer with
I915_TILING_NONE and decode the tile's layout in software.
This fix touches the following portions of code:
- In intel_allocate_renderbuffer_storage(), allocate the stencil
buffer with I915_TILING_NONE.
- In intel_verify_dri2_has_hiz(), verify that the stencil buffer is
not tiled.
- In the stencil buffer's span functions, the tile's layout must be
decoded in software.
This commit mutually depends on the xf86-video-intel commit
dri: Do not tile stencil buffer
Author: Chad Versace <chad@chad-versace.us>
Date: Mon Jul 18 00:38:00 2011 -0700
On Gen6 with separate stencil enabled, fixes the following Piglit tests:
bugs/fdo23670-drawpix_stencil
general/stencil-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-readpixels
spec/EXT_packed_depth_stencil/fbo-stencil-GL_DEPTH24_STENCIL8-copypixels
spec/EXT_packed_depth_stencil/fbo-stencil-GL_DEPTH24_STENCIL8-readpixels
spec/EXT_packed_depth_stencil/readpixels-24_8
Note: This is a candidate for the 7.11 branch.
Signed-off-by: Chad Versace <chad@chad-versace.us>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
2011-07-18 00:37:45 -07:00
|
|
|
I915_TILING_NONE,
|
2011-05-23 13:47:35 -07:00
|
|
|
cpp * 2,
|
intel: Fix stencil buffer to be W tiled
Until now, the stencil buffer was allocated as a Y tiled buffer, because
in several locations the PRM states that it is. However, it is actually
W tiled. From the PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section
4.5.2.1 W-Major Format:
W-Major Tile Format is used for separate stencil.
The GTT is incapable of W fencing, so we allocate the stencil buffer with
I915_TILING_NONE and decode the tile's layout in software.
This fix touches the following portions of code:
- In intel_allocate_renderbuffer_storage(), allocate the stencil
buffer with I915_TILING_NONE.
- In intel_verify_dri2_has_hiz(), verify that the stencil buffer is
not tiled.
- In the stencil buffer's span functions, the tile's layout must be
decoded in software.
This commit mutually depends on the xf86-video-intel commit
dri: Do not tile stencil buffer
Author: Chad Versace <chad@chad-versace.us>
Date: Mon Jul 18 00:38:00 2011 -0700
On Gen6 with separate stencil enabled, fixes the following Piglit tests:
bugs/fdo23670-drawpix_stencil
general/stencil-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX16-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX1-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX4-readpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-copypixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-drawpixels
spec/EXT_framebuffer_object/fbo-stencil-GL_STENCIL_INDEX8-readpixels
spec/EXT_packed_depth_stencil/fbo-stencil-GL_DEPTH24_STENCIL8-copypixels
spec/EXT_packed_depth_stencil/fbo-stencil-GL_DEPTH24_STENCIL8-readpixels
spec/EXT_packed_depth_stencil/readpixels-24_8
Note: This is a candidate for the 7.11 branch.
Signed-off-by: Chad Versace <chad@chad-versace.us>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
2011-07-18 00:37:45 -07:00
|
|
|
ALIGN(width, 64),
|
|
|
|
ALIGN((height + 1) / 2, 64),
|
2011-05-23 13:47:35 -07:00
|
|
|
GL_TRUE);
|
2011-06-14 17:38:30 -07:00
|
|
|
if (!irb->region)
|
|
|
|
return false;
|
|
|
|
|
2011-06-17 12:12:35 -07:00
|
|
|
} else if (irb->Base.Format == MESA_FORMAT_S8_Z24
|
|
|
|
&& intel->must_use_separate_stencil) {
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
struct gl_renderbuffer *depth_rb;
|
|
|
|
struct gl_renderbuffer *stencil_rb;
|
|
|
|
|
2011-06-21 14:06:13 -07:00
|
|
|
depth_rb = intel_create_wrapped_renderbuffer(ctx, width, height,
|
2011-06-17 12:12:35 -07:00
|
|
|
MESA_FORMAT_X8_Z24);
|
2011-06-21 14:06:13 -07:00
|
|
|
stencil_rb = intel_create_wrapped_renderbuffer(ctx, width, height,
|
2011-06-17 12:12:35 -07:00
|
|
|
MESA_FORMAT_S8);
|
|
|
|
ok = depth_rb && stencil_rb;
|
|
|
|
ok = ok && intel_alloc_renderbuffer_storage(ctx, depth_rb,
|
|
|
|
depth_rb->InternalFormat,
|
|
|
|
width, height);
|
|
|
|
ok = ok && intel_alloc_renderbuffer_storage(ctx, stencil_rb,
|
|
|
|
stencil_rb->InternalFormat,
|
|
|
|
width, height);
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
if (depth_rb) {
|
|
|
|
intel_delete_renderbuffer(depth_rb);
|
|
|
|
}
|
|
|
|
if (stencil_rb) {
|
|
|
|
intel_delete_renderbuffer(stencil_rb);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 14:06:13 -07:00
|
|
|
depth_rb->Wrapped = rb;
|
|
|
|
stencil_rb->Wrapped = rb;
|
2011-06-17 12:12:35 -07:00
|
|
|
_mesa_reference_renderbuffer(&irb->wrapped_depth, depth_rb);
|
|
|
|
_mesa_reference_renderbuffer(&irb->wrapped_stencil, stencil_rb);
|
|
|
|
|
2011-05-23 13:47:35 -07:00
|
|
|
} else {
|
|
|
|
irb->region = intel_region_alloc(intel->intelScreen, tiling, cpp,
|
|
|
|
width, height, GL_TRUE);
|
2011-06-14 17:38:30 -07:00
|
|
|
if (!irb->region)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (intel->vtbl.is_hiz_depth_format(intel, rb->Format)) {
|
|
|
|
irb->hiz_region = intel_region_alloc(intel->intelScreen,
|
|
|
|
I915_TILING_Y,
|
|
|
|
irb->region->cpp,
|
|
|
|
irb->region->width,
|
|
|
|
irb->region->height,
|
|
|
|
GL_TRUE);
|
|
|
|
if (!irb->hiz_region) {
|
|
|
|
intel_region_release(&irb->region);
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-23 13:48:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-08 15:51:18 -08:00
|
|
|
return GL_TRUE;
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-11 19:04:02 -05:00
|
|
|
#if FEATURE_OES_EGL_image
|
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_image_target_renderbuffer_storage(struct gl_context *ctx,
|
2010-02-11 19:04:02 -05:00
|
|
|
struct gl_renderbuffer *rb,
|
|
|
|
void *image_handle)
|
|
|
|
{
|
|
|
|
struct intel_context *intel = intel_context(ctx);
|
|
|
|
struct intel_renderbuffer *irb;
|
|
|
|
__DRIscreen *screen;
|
|
|
|
__DRIimage *image;
|
|
|
|
|
|
|
|
screen = intel->intelScreen->driScrnPriv;
|
2010-09-22 22:01:17 -04:00
|
|
|
image = screen->dri2.image->lookupEGLImage(screen, image_handle,
|
|
|
|
screen->loaderPrivate);
|
2010-02-11 19:04:02 -05:00
|
|
|
if (image == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-08-21 21:36:40 +08:00
|
|
|
/* __DRIimage is opaque to the core so it has to be checked here */
|
|
|
|
switch (image->format) {
|
|
|
|
case MESA_FORMAT_RGBA8888_REV:
|
|
|
|
_mesa_error(&intel->ctx, GL_INVALID_OPERATION,
|
|
|
|
"glEGLImageTargetRenderbufferStorage(unsupported image format");
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-11 19:04:02 -05:00
|
|
|
irb = intel_renderbuffer(rb);
|
|
|
|
intel_region_reference(&irb->region, image->region);
|
|
|
|
|
2010-03-02 15:41:12 -05:00
|
|
|
rb->InternalFormat = image->internal_format;
|
2010-02-11 19:04:02 -05:00
|
|
|
rb->Width = image->region->width;
|
|
|
|
rb->Height = image->region->height;
|
|
|
|
rb->Format = image->format;
|
|
|
|
rb->DataType = image->data_type;
|
|
|
|
rb->_BaseFormat = _mesa_base_fbo_format(&intel->ctx,
|
|
|
|
image->internal_format);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
/**
|
|
|
|
* Called for each hardware renderbuffer when a _window_ is resized.
|
|
|
|
* Just update fields.
|
|
|
|
* Not used for user-created renderbuffers!
|
|
|
|
*/
|
|
|
|
static GLboolean
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_alloc_window_storage(struct gl_context * ctx, struct gl_renderbuffer *rb,
|
2007-11-07 10:04:59 -08:00
|
|
|
GLenum internalFormat, GLuint width, GLuint height)
|
|
|
|
{
|
|
|
|
ASSERT(rb->Name == 0);
|
|
|
|
rb->Width = width;
|
|
|
|
rb->Height = height;
|
2009-10-08 20:27:27 -06:00
|
|
|
rb->InternalFormat = internalFormat;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_resize_buffers(struct gl_context *ctx, struct gl_framebuffer *fb,
|
2007-11-07 10:04:59 -08:00
|
|
|
GLuint width, GLuint height)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_mesa_resize_framebuffer(ctx, fb, width, height);
|
|
|
|
|
|
|
|
fb->Initialized = GL_TRUE; /* XXX remove someday */
|
|
|
|
|
|
|
|
if (fb->Name != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-01 23:21:16 -05:00
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
/* Make sure all window system renderbuffers are up to date */
|
2010-01-01 23:21:16 -05:00
|
|
|
for (i = BUFFER_FRONT_LEFT; i <= BUFFER_BACK_RIGHT; i++) {
|
|
|
|
struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
/* only resize if size is changing */
|
|
|
|
if (rb && (rb->Width != width || rb->Height != height)) {
|
|
|
|
rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
|
|
|
|
/** Dummy function for gl_renderbuffer::AllocStorage() */
|
2007-11-07 10:04:59 -08:00
|
|
|
static GLboolean
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_nop_alloc_storage(struct gl_context * ctx, struct gl_renderbuffer *rb,
|
2007-11-07 10:04:59 -08:00
|
|
|
GLenum internalFormat, GLuint width, GLuint height)
|
|
|
|
{
|
|
|
|
_mesa_problem(ctx, "intel_op_alloc_storage should never be called.");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new intel_renderbuffer which corresponds to an on-screen window,
|
|
|
|
* not a user-created renderbuffer.
|
|
|
|
*/
|
|
|
|
struct intel_renderbuffer *
|
2009-10-29 19:12:50 -06:00
|
|
|
intel_create_renderbuffer(gl_format format)
|
2007-11-07 10:04:59 -08:00
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
|
|
|
|
struct intel_renderbuffer *irb;
|
|
|
|
|
|
|
|
irb = CALLOC_STRUCT(intel_renderbuffer);
|
|
|
|
if (!irb) {
|
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-08 17:03:20 -08:00
|
|
|
_mesa_init_renderbuffer(&irb->Base, 0);
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base.ClassID = INTEL_RB_CLASS;
|
2011-01-07 18:14:37 -08:00
|
|
|
irb->Base._BaseFormat = _mesa_get_format_base_format(format);
|
2009-10-29 19:12:50 -06:00
|
|
|
irb->Base.Format = format;
|
|
|
|
irb->Base.InternalFormat = irb->Base._BaseFormat;
|
2010-12-09 17:08:31 -08:00
|
|
|
irb->Base.DataType = intel_mesa_format_to_rb_datatype(format);
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
/* intel-specific methods */
|
|
|
|
irb->Base.Delete = intel_delete_renderbuffer;
|
|
|
|
irb->Base.AllocStorage = intel_alloc_window_storage;
|
|
|
|
irb->Base.GetPointer = intel_get_pointer;
|
|
|
|
|
|
|
|
return irb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-21 14:06:13 -07:00
|
|
|
struct gl_renderbuffer*
|
2011-06-17 12:12:35 -07:00
|
|
|
intel_create_wrapped_renderbuffer(struct gl_context * ctx,
|
2011-06-21 14:06:13 -07:00
|
|
|
int width, int height,
|
2011-06-17 12:12:35 -07:00
|
|
|
gl_format format)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The name here is irrelevant, as long as its nonzero, because the
|
|
|
|
* renderbuffer never gets entered into Mesa's renderbuffer hash table.
|
|
|
|
*/
|
|
|
|
GLuint name = ~0;
|
|
|
|
|
|
|
|
struct intel_renderbuffer *irb = CALLOC_STRUCT(intel_renderbuffer);
|
|
|
|
if (!irb) {
|
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gl_renderbuffer *rb = &irb->Base;
|
|
|
|
_mesa_init_renderbuffer(rb, name);
|
|
|
|
rb->ClassID = INTEL_RB_CLASS;
|
|
|
|
rb->_BaseFormat = _mesa_get_format_base_format(format);
|
|
|
|
rb->Format = format;
|
|
|
|
rb->InternalFormat = rb->_BaseFormat;
|
|
|
|
rb->DataType = intel_mesa_format_to_rb_datatype(format);
|
2011-06-21 14:06:13 -07:00
|
|
|
rb->Width = width;
|
|
|
|
rb->Height = height;
|
2011-06-17 12:12:35 -07:00
|
|
|
|
|
|
|
return rb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
/**
|
|
|
|
* Create a new renderbuffer object.
|
|
|
|
* Typically called via glBindRenderbufferEXT().
|
|
|
|
*/
|
|
|
|
static struct gl_renderbuffer *
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_new_renderbuffer(struct gl_context * ctx, GLuint name)
|
2007-11-07 10:04:59 -08:00
|
|
|
{
|
|
|
|
/*struct intel_context *intel = intel_context(ctx); */
|
|
|
|
struct intel_renderbuffer *irb;
|
|
|
|
|
|
|
|
irb = CALLOC_STRUCT(intel_renderbuffer);
|
|
|
|
if (!irb) {
|
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mesa_init_renderbuffer(&irb->Base, name);
|
|
|
|
irb->Base.ClassID = INTEL_RB_CLASS;
|
|
|
|
|
|
|
|
/* intel-specific methods */
|
|
|
|
irb->Base.Delete = intel_delete_renderbuffer;
|
|
|
|
irb->Base.AllocStorage = intel_alloc_renderbuffer_storage;
|
|
|
|
irb->Base.GetPointer = intel_get_pointer;
|
|
|
|
/* span routines set in alloc_storage function */
|
|
|
|
|
|
|
|
return &irb->Base;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called via glBindFramebufferEXT().
|
|
|
|
*/
|
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_bind_framebuffer(struct gl_context * ctx, GLenum target,
|
2007-11-07 10:04:59 -08:00
|
|
|
struct gl_framebuffer *fb, struct gl_framebuffer *fbread)
|
|
|
|
{
|
|
|
|
if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) {
|
|
|
|
intel_draw_buffer(ctx, fb);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* don't need to do anything if target == GL_READ_FRAMEBUFFER_EXT */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called via glFramebufferRenderbufferEXT().
|
|
|
|
*/
|
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_framebuffer_renderbuffer(struct gl_context * ctx,
|
2007-11-07 10:04:59 -08:00
|
|
|
struct gl_framebuffer *fb,
|
|
|
|
GLenum attachment, struct gl_renderbuffer *rb)
|
|
|
|
{
|
|
|
|
DBG("Intel FramebufferRenderbuffer %u %u\n", fb->Name, rb ? rb->Name : 0);
|
|
|
|
|
2010-05-10 17:42:43 -04:00
|
|
|
intel_flush(ctx);
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
_mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
|
|
|
|
intel_draw_buffer(ctx, fb);
|
|
|
|
}
|
|
|
|
|
2011-06-22 16:08:49 -07:00
|
|
|
static bool
|
|
|
|
intel_update_tex_wrapper_regions(struct intel_context *intel,
|
|
|
|
struct intel_renderbuffer *irb,
|
|
|
|
struct intel_texture_image *intel_image);
|
2009-01-29 14:57:31 -07:00
|
|
|
|
2008-03-14 11:39:08 +08:00
|
|
|
static GLboolean
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_update_wrapper(struct gl_context *ctx, struct intel_renderbuffer *irb,
|
2008-08-24 17:59:10 +10:00
|
|
|
struct gl_texture_image *texImage)
|
2007-11-07 10:04:59 -08:00
|
|
|
{
|
2011-05-23 13:48:14 -07:00
|
|
|
struct intel_context *intel = intel_context(ctx);
|
2011-05-23 13:48:10 -07:00
|
|
|
struct intel_texture_image *intel_image = intel_texture_image(texImage);
|
|
|
|
|
2010-12-09 17:08:31 -08:00
|
|
|
if (!intel_span_supports_format(texImage->TexFormat)) {
|
2009-12-28 14:38:43 -08:00
|
|
|
DBG("Render to texture BAD FORMAT %s\n",
|
|
|
|
_mesa_get_format_name(texImage->TexFormat));
|
2008-03-14 11:39:08 +08:00
|
|
|
return GL_FALSE;
|
2010-12-09 17:08:31 -08:00
|
|
|
} else {
|
|
|
|
DBG("Render to texture %s\n", _mesa_get_format_name(texImage->TexFormat));
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|
|
|
|
|
2009-10-08 20:27:27 -06:00
|
|
|
irb->Base.Format = texImage->TexFormat;
|
2010-12-09 17:08:31 -08:00
|
|
|
irb->Base.DataType = intel_mesa_format_to_rb_datatype(texImage->TexFormat);
|
2009-10-08 20:27:27 -06:00
|
|
|
irb->Base.InternalFormat = texImage->InternalFormat;
|
2011-04-15 20:28:51 -07:00
|
|
|
irb->Base._BaseFormat = _mesa_base_tex_format(ctx, irb->Base.InternalFormat);
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base.Width = texImage->Width;
|
|
|
|
irb->Base.Height = texImage->Height;
|
|
|
|
|
|
|
|
irb->Base.Delete = intel_delete_renderbuffer;
|
|
|
|
irb->Base.AllocStorage = intel_nop_alloc_storage;
|
|
|
|
|
2011-06-22 19:44:53 -07:00
|
|
|
if (intel_image->stencil_rb) {
|
|
|
|
/* The tex image has packed depth/stencil format, but is using separate
|
|
|
|
* stencil. */
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
struct intel_renderbuffer *depth_irb =
|
|
|
|
intel_renderbuffer(intel_image->depth_rb);
|
|
|
|
|
|
|
|
/* Update the hiz region if necessary. */
|
|
|
|
ok = intel_update_tex_wrapper_regions(intel, depth_irb, intel_image);
|
|
|
|
if (!ok) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The tex image shares its embedded depth and stencil renderbuffers with
|
|
|
|
* the renderbuffer wrapper. */
|
|
|
|
if (irb->wrapped_depth != intel_image->depth_rb) {
|
|
|
|
_mesa_reference_renderbuffer(&irb->wrapped_depth,
|
|
|
|
intel_image->depth_rb);
|
|
|
|
}
|
|
|
|
if (irb->wrapped_stencil != intel_image->stencil_rb) {
|
|
|
|
_mesa_reference_renderbuffer(&irb->wrapped_stencil,
|
|
|
|
intel_image->stencil_rb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return intel_update_tex_wrapper_regions(intel, irb, intel_image);
|
|
|
|
}
|
2011-06-22 16:08:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FIXME: The handling of the hiz region is broken for mipmapped depth textures
|
|
|
|
* FIXME: because intel_finalize_mipmap_tree is unaware of it.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
intel_update_tex_wrapper_regions(struct intel_context *intel,
|
|
|
|
struct intel_renderbuffer *irb,
|
|
|
|
struct intel_texture_image *intel_image)
|
|
|
|
{
|
2011-06-22 19:44:53 -07:00
|
|
|
struct gl_renderbuffer *rb = &irb->Base;
|
2011-06-22 16:08:49 -07:00
|
|
|
|
2011-05-23 13:48:10 -07:00
|
|
|
/* Point the renderbuffer's region to the texture's region. */
|
|
|
|
if (irb->region != intel_image->mt->region) {
|
|
|
|
intel_region_reference(&irb->region, intel_image->mt->region);
|
|
|
|
}
|
|
|
|
|
2011-05-23 13:48:14 -07:00
|
|
|
/* Allocate the texture's hiz region if necessary. */
|
2011-06-22 19:44:53 -07:00
|
|
|
if (intel->vtbl.is_hiz_depth_format(intel, rb->Format)
|
2011-05-23 13:48:14 -07:00
|
|
|
&& !intel_image->mt->hiz_region) {
|
|
|
|
intel_image->mt->hiz_region =
|
|
|
|
intel_region_alloc(intel->intelScreen,
|
|
|
|
I915_TILING_Y,
|
2011-06-22 19:44:53 -07:00
|
|
|
_mesa_get_format_bytes(rb->Format),
|
|
|
|
rb->Width,
|
|
|
|
rb->Height,
|
2011-05-23 13:48:14 -07:00
|
|
|
GL_TRUE);
|
|
|
|
if (!intel_image->mt->hiz_region)
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Point the renderbuffer's hiz region to the texture's hiz region. */
|
|
|
|
if (irb->hiz_region != intel_image->mt->hiz_region) {
|
|
|
|
intel_region_reference(&irb->hiz_region, intel_image->mt->hiz_region);
|
|
|
|
}
|
|
|
|
|
2008-03-14 11:39:08 +08:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 14:57:31 -07:00
|
|
|
|
2008-03-14 11:39:08 +08:00
|
|
|
/**
|
|
|
|
* When glFramebufferTexture[123]D is called this function sets up the
|
|
|
|
* gl_renderbuffer wrapper around the texture image.
|
|
|
|
* This will have the region info needed for hardware rendering.
|
|
|
|
*/
|
|
|
|
static struct intel_renderbuffer *
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_wrap_texture(struct gl_context * ctx, struct gl_texture_image *texImage)
|
2008-03-14 11:39:08 +08:00
|
|
|
{
|
2009-01-29 14:57:31 -07:00
|
|
|
const GLuint name = ~0; /* not significant, but distinct for debugging */
|
2008-03-14 11:39:08 +08:00
|
|
|
struct intel_renderbuffer *irb;
|
|
|
|
|
|
|
|
/* make an intel_renderbuffer to wrap the texture image */
|
|
|
|
irb = CALLOC_STRUCT(intel_renderbuffer);
|
|
|
|
if (!irb) {
|
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mesa_init_renderbuffer(&irb->Base, name);
|
|
|
|
irb->Base.ClassID = INTEL_RB_CLASS;
|
|
|
|
|
|
|
|
if (!intel_update_wrapper(ctx, irb, texImage)) {
|
2010-02-19 11:58:49 -05:00
|
|
|
free(irb);
|
2008-03-14 11:39:08 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
return irb;
|
|
|
|
}
|
|
|
|
|
2011-06-22 10:26:26 -07:00
|
|
|
void
|
2011-05-31 14:27:18 -07:00
|
|
|
intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb,
|
|
|
|
struct intel_texture_image *intel_image,
|
|
|
|
int zoffset)
|
2011-01-10 15:45:28 -08:00
|
|
|
{
|
|
|
|
unsigned int dst_x, dst_y;
|
|
|
|
|
|
|
|
/* compute offset of the particular 2D image within the texture region */
|
|
|
|
intel_miptree_get_image_offset(intel_image->mt,
|
2011-07-14 20:57:34 -06:00
|
|
|
intel_image->base.Level,
|
|
|
|
intel_image->base.Face,
|
2011-01-10 15:45:28 -08:00
|
|
|
zoffset,
|
|
|
|
&dst_x, &dst_y);
|
|
|
|
|
2011-05-31 14:27:18 -07:00
|
|
|
irb->draw_x = dst_x;
|
|
|
|
irb->draw_y = dst_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rendering to tiled buffers requires that the base address of the
|
|
|
|
* buffer be aligned to a page boundary. We generally render to
|
|
|
|
* textures by pointing the surface at the mipmap image level, which
|
|
|
|
* may not be aligned to a tile boundary.
|
|
|
|
*
|
|
|
|
* This function returns an appropriately-aligned base offset
|
|
|
|
* according to the tiling restrictions, plus any required x/y offset
|
|
|
|
* from there.
|
|
|
|
*/
|
|
|
|
uint32_t
|
|
|
|
intel_renderbuffer_tile_offsets(struct intel_renderbuffer *irb,
|
|
|
|
uint32_t *tile_x,
|
|
|
|
uint32_t *tile_y)
|
|
|
|
{
|
|
|
|
int cpp = irb->region->cpp;
|
|
|
|
uint32_t pitch = irb->region->pitch * cpp;
|
|
|
|
|
|
|
|
if (irb->region->tiling == I915_TILING_NONE) {
|
|
|
|
*tile_x = 0;
|
|
|
|
*tile_y = 0;
|
|
|
|
return irb->draw_x * cpp + irb->draw_y * pitch;
|
|
|
|
} else if (irb->region->tiling == I915_TILING_X) {
|
|
|
|
*tile_x = irb->draw_x % (512 / cpp);
|
|
|
|
*tile_y = irb->draw_y % 8;
|
|
|
|
return ((irb->draw_y / 8) * (8 * pitch) +
|
|
|
|
(irb->draw_x - *tile_x) / (512 / cpp) * 4096);
|
|
|
|
} else {
|
|
|
|
assert(irb->region->tiling == I915_TILING_Y);
|
|
|
|
*tile_x = irb->draw_x % (128 / cpp);
|
|
|
|
*tile_y = irb->draw_y % 32;
|
|
|
|
return ((irb->draw_y / 32) * (32 * pitch) +
|
|
|
|
(irb->draw_x - *tile_x) / (128 / cpp) * 4096);
|
|
|
|
}
|
2011-01-10 15:45:28 -08:00
|
|
|
}
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2011-07-25 17:06:13 -07:00
|
|
|
#ifndef I915
|
|
|
|
static bool
|
|
|
|
need_tile_offset_workaround(struct brw_context *brw,
|
|
|
|
struct intel_renderbuffer *irb)
|
|
|
|
{
|
|
|
|
uint32_t tile_x, tile_y;
|
|
|
|
|
|
|
|
if (brw->has_surface_tile_offset)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
intel_renderbuffer_tile_offsets(irb, &tile_x, &tile_y);
|
|
|
|
|
|
|
|
return tile_x != 0 || tile_y != 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
/**
|
|
|
|
* Called by glFramebufferTexture[123]DEXT() (and other places) to
|
|
|
|
* prepare for rendering into texture memory. This might be called
|
|
|
|
* many times to choose different texture levels, cube faces, etc
|
|
|
|
* before intel_finish_render_texture() is ever called.
|
|
|
|
*/
|
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_render_texture(struct gl_context * ctx,
|
2007-11-07 10:04:59 -08:00
|
|
|
struct gl_framebuffer *fb,
|
|
|
|
struct gl_renderbuffer_attachment *att)
|
|
|
|
{
|
2011-05-31 15:07:56 -07:00
|
|
|
struct gl_texture_image *image = _mesa_get_attachment_teximage(att);
|
2007-11-07 10:04:59 -08:00
|
|
|
struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer);
|
2011-05-31 15:07:56 -07:00
|
|
|
struct intel_texture_image *intel_image = intel_texture_image(image);
|
2007-11-07 10:04:59 -08:00
|
|
|
|
|
|
|
(void) fb;
|
|
|
|
|
2009-05-20 14:16:34 -07:00
|
|
|
if (!intel_image->mt) {
|
|
|
|
/* Fallback on drawing to a texture that doesn't have a miptree
|
|
|
|
* (has a border, width/height 0, etc.)
|
2008-12-06 15:47:23 -08:00
|
|
|
*/
|
2009-01-29 14:57:31 -07:00
|
|
|
_mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
|
2011-06-13 13:44:35 -06:00
|
|
|
_swrast_render_texture(ctx, fb, att);
|
2009-01-29 14:57:31 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!irb) {
|
2011-05-31 15:07:56 -07:00
|
|
|
irb = intel_wrap_texture(ctx, image);
|
2007-11-07 10:04:59 -08:00
|
|
|
if (irb) {
|
|
|
|
/* bind the wrapper to the attachment point */
|
|
|
|
_mesa_reference_renderbuffer(&att->Renderbuffer, &irb->Base);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* fallback to software rendering */
|
2011-06-13 13:44:35 -06:00
|
|
|
_swrast_render_texture(ctx, fb, att);
|
2007-11-07 10:04:59 -08:00
|
|
|
return;
|
|
|
|
}
|
2009-01-29 14:57:31 -07:00
|
|
|
}
|
|
|
|
|
2011-05-31 15:07:56 -07:00
|
|
|
if (!intel_update_wrapper(ctx, irb, image)) {
|
2008-03-14 11:39:08 +08:00
|
|
|
_mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
|
2011-06-13 13:44:35 -06:00
|
|
|
_swrast_render_texture(ctx, fb, att);
|
2008-03-14 11:39:08 +08:00
|
|
|
return;
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|
|
|
|
|
2010-02-20 01:58:27 -08:00
|
|
|
DBG("Begin render texture tid %lx tex=%u w=%d h=%d refcount=%d\n",
|
2007-11-07 10:04:59 -08:00
|
|
|
_glthread_GetID(),
|
2011-05-31 15:07:56 -07:00
|
|
|
att->Texture->Name, image->Width, image->Height,
|
2007-11-07 10:04:59 -08:00
|
|
|
irb->Base.RefCount);
|
|
|
|
|
2011-05-31 14:27:18 -07:00
|
|
|
intel_renderbuffer_set_draw_offset(irb, intel_image, att->Zoffset);
|
2009-11-04 14:54:09 -08:00
|
|
|
intel_image->used_as_render_target = GL_TRUE;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2011-01-10 15:45:28 -08:00
|
|
|
#ifndef I915
|
2011-07-25 17:06:13 -07:00
|
|
|
if (need_tile_offset_workaround(brw_context(ctx), irb)) {
|
2011-01-10 15:45:28 -08:00
|
|
|
/* Original gen4 hardware couldn't draw to a non-tile-aligned
|
|
|
|
* destination in a miptree unless you actually setup your
|
|
|
|
* renderbuffer as a miptree and used the fragile
|
|
|
|
* lod/array_index/etc. controls to select the image. So,
|
|
|
|
* instead, we just make a new single-level miptree and render
|
|
|
|
* into that.
|
|
|
|
*/
|
2011-01-12 12:29:38 -08:00
|
|
|
struct intel_context *intel = intel_context(ctx);
|
2011-01-10 15:45:28 -08:00
|
|
|
struct intel_mipmap_tree *old_mt = intel_image->mt;
|
|
|
|
struct intel_mipmap_tree *new_mt;
|
|
|
|
|
2011-05-31 15:07:56 -07:00
|
|
|
new_mt = intel_miptree_create(intel, image->TexObject->Target,
|
2011-06-09 09:16:47 -07:00
|
|
|
intel_image->base.TexFormat,
|
2011-07-14 20:57:34 -06:00
|
|
|
intel_image->base.Level,
|
|
|
|
intel_image->base.Level,
|
2011-01-10 15:45:28 -08:00
|
|
|
intel_image->base.Width,
|
|
|
|
intel_image->base.Height,
|
|
|
|
intel_image->base.Depth,
|
2011-06-09 10:23:17 -07:00
|
|
|
GL_TRUE);
|
2011-01-10 15:45:28 -08:00
|
|
|
|
|
|
|
intel_miptree_image_copy(intel,
|
|
|
|
new_mt,
|
2011-07-14 20:57:34 -06:00
|
|
|
intel_image->base.Face,
|
|
|
|
intel_image->base.Level,
|
2011-01-10 15:45:28 -08:00
|
|
|
old_mt);
|
|
|
|
|
|
|
|
intel_miptree_release(intel, &intel_image->mt);
|
|
|
|
intel_image->mt = new_mt;
|
2011-05-31 14:27:18 -07:00
|
|
|
intel_renderbuffer_set_draw_offset(irb, intel_image, att->Zoffset);
|
2011-01-10 15:45:28 -08:00
|
|
|
|
|
|
|
intel_region_reference(&irb->region, intel_image->mt->region);
|
|
|
|
}
|
|
|
|
#endif
|
2007-11-07 10:04:59 -08:00
|
|
|
/* update drawing region, etc */
|
|
|
|
intel_draw_buffer(ctx, fb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by Mesa when rendering to a texture is done.
|
|
|
|
*/
|
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_finish_render_texture(struct gl_context * ctx,
|
2007-11-07 10:04:59 -08:00
|
|
|
struct gl_renderbuffer_attachment *att)
|
|
|
|
{
|
2009-12-09 11:36:45 -08:00
|
|
|
struct intel_context *intel = intel_context(ctx);
|
2009-11-04 14:54:09 -08:00
|
|
|
struct gl_texture_object *tex_obj = att->Texture;
|
|
|
|
struct gl_texture_image *image =
|
|
|
|
tex_obj->Image[att->CubeMapFace][att->TextureLevel];
|
|
|
|
struct intel_texture_image *intel_image = intel_texture_image(image);
|
2010-09-24 11:20:16 -07:00
|
|
|
|
2010-09-24 16:22:08 -07:00
|
|
|
DBG("Finish render texture tid %lx tex=%u\n",
|
|
|
|
_glthread_GetID(), att->Texture->Name);
|
2009-11-04 14:54:09 -08:00
|
|
|
|
|
|
|
/* Flag that this image may now be validated into the object's miptree. */
|
2010-12-21 11:55:11 +00:00
|
|
|
if (intel_image)
|
|
|
|
intel_image->used_as_render_target = GL_FALSE;
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-12-09 11:36:45 -08:00
|
|
|
/* Since we've (probably) rendered to the texture and will (likely) use
|
|
|
|
* it in the texture domain later on in this batchbuffer, flush the
|
|
|
|
* batch. Once again, we wish for a domain tracker in libdrm to cover
|
|
|
|
* usage inside of a batchbuffer like GEM does in the kernel.
|
|
|
|
*/
|
2011-02-10 20:25:51 +00:00
|
|
|
intel_batchbuffer_emit_mi_flush(intel);
|
2009-12-09 11:36:45 -08:00
|
|
|
}
|
2007-11-07 10:04:59 -08:00
|
|
|
|
2009-01-20 15:30:22 -07:00
|
|
|
/**
|
|
|
|
* Do additional "completeness" testing of a framebuffer object.
|
|
|
|
*/
|
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
|
2009-01-20 15:30:22 -07:00
|
|
|
{
|
2011-01-07 15:45:33 -08:00
|
|
|
struct intel_context *intel = intel_context(ctx);
|
2009-01-22 15:32:38 -07:00
|
|
|
const struct intel_renderbuffer *depthRb =
|
|
|
|
intel_get_renderbuffer(fb, BUFFER_DEPTH);
|
|
|
|
const struct intel_renderbuffer *stencilRb =
|
|
|
|
intel_get_renderbuffer(fb, BUFFER_STENCIL);
|
2009-04-09 18:30:12 -07:00
|
|
|
int i;
|
2009-01-22 15:32:38 -07:00
|
|
|
|
2011-05-23 13:48:18 -07:00
|
|
|
/*
|
|
|
|
* The depth and stencil renderbuffers are the same renderbuffer or wrap
|
|
|
|
* the same texture.
|
|
|
|
*/
|
2011-07-12 10:01:32 -07:00
|
|
|
if (depthRb && stencilRb) {
|
|
|
|
bool depth_stencil_are_same;
|
|
|
|
if (depthRb == stencilRb)
|
|
|
|
depth_stencil_are_same = true;
|
|
|
|
else if ((fb->Attachment[BUFFER_DEPTH].Type == GL_TEXTURE) &&
|
|
|
|
(fb->Attachment[BUFFER_STENCIL].Type == GL_TEXTURE) &&
|
|
|
|
(fb->Attachment[BUFFER_DEPTH].Texture->Name ==
|
|
|
|
fb->Attachment[BUFFER_STENCIL].Texture->Name))
|
|
|
|
depth_stencil_are_same = true;
|
|
|
|
else
|
|
|
|
depth_stencil_are_same = false;
|
|
|
|
|
|
|
|
if (!intel->has_separate_stencil && !depth_stencil_are_same) {
|
|
|
|
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
|
|
|
|
}
|
2009-01-22 15:32:38 -07:00
|
|
|
}
|
2009-02-26 16:51:50 -07:00
|
|
|
|
2011-01-04 09:57:21 -08:00
|
|
|
for (i = 0; i < Elements(fb->Attachment); i++) {
|
|
|
|
struct gl_renderbuffer *rb;
|
|
|
|
struct intel_renderbuffer *irb;
|
2009-04-09 18:30:12 -07:00
|
|
|
|
2011-01-04 09:57:21 -08:00
|
|
|
if (fb->Attachment[i].Type == GL_NONE)
|
2009-04-09 18:30:12 -07:00
|
|
|
continue;
|
|
|
|
|
2011-01-04 09:57:21 -08:00
|
|
|
/* A supported attachment will have a Renderbuffer set either
|
|
|
|
* from being a Renderbuffer or being a texture that got the
|
|
|
|
* intel_wrap_texture() treatment.
|
|
|
|
*/
|
|
|
|
rb = fb->Attachment[i].Renderbuffer;
|
|
|
|
if (rb == NULL) {
|
|
|
|
DBG("attachment without renderbuffer\n");
|
|
|
|
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
irb = intel_renderbuffer(rb);
|
2009-05-20 14:05:03 -07:00
|
|
|
if (irb == NULL) {
|
2009-12-28 14:38:43 -08:00
|
|
|
DBG("software rendering renderbuffer\n");
|
2009-05-20 14:05:03 -07:00
|
|
|
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-07 15:45:33 -08:00
|
|
|
if (!intel_span_supports_format(irb->Base.Format) ||
|
|
|
|
!intel->vtbl.render_target_supported(irb->Base.Format)) {
|
2010-12-09 17:08:31 -08:00
|
|
|
DBG("Unsupported texture/renderbuffer format attached: %s\n",
|
|
|
|
_mesa_get_format_name(irb->Base.Format));
|
2009-04-09 18:30:12 -07:00
|
|
|
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
|
2009-02-26 16:51:50 -07:00
|
|
|
}
|
|
|
|
}
|
2009-01-20 15:30:22 -07:00
|
|
|
}
|
|
|
|
|
2011-02-05 10:21:11 +00:00
|
|
|
/**
|
|
|
|
* Try to do a glBlitFramebuffer using glCopyTexSubImage2D
|
|
|
|
* We can do this when the dst renderbuffer is actually a texture and
|
|
|
|
* there is no scaling, mirroring or scissoring.
|
|
|
|
*
|
|
|
|
* \return new buffer mask indicating the buffers left to blit using the
|
|
|
|
* normal path.
|
|
|
|
*/
|
|
|
|
static GLbitfield
|
|
|
|
intel_blit_framebuffer_copy_tex_sub_image(struct gl_context *ctx,
|
|
|
|
GLint srcX0, GLint srcY0,
|
|
|
|
GLint srcX1, GLint srcY1,
|
|
|
|
GLint dstX0, GLint dstY0,
|
|
|
|
GLint dstX1, GLint dstY1,
|
|
|
|
GLbitfield mask, GLenum filter)
|
|
|
|
{
|
|
|
|
if (mask & GL_COLOR_BUFFER_BIT) {
|
|
|
|
const struct gl_framebuffer *drawFb = ctx->DrawBuffer;
|
|
|
|
const struct gl_framebuffer *readFb = ctx->ReadBuffer;
|
|
|
|
const struct gl_renderbuffer_attachment *drawAtt =
|
|
|
|
&drawFb->Attachment[drawFb->_ColorDrawBufferIndexes[0]];
|
|
|
|
|
|
|
|
/* If the source and destination are the same size with no
|
|
|
|
mirroring, the rectangles are within the size of the
|
|
|
|
texture and there is no scissor then we can use
|
|
|
|
glCopyTexSubimage2D to implement the blit. This will end
|
|
|
|
up as a fast hardware blit on some drivers */
|
|
|
|
if (drawAtt && drawAtt->Texture &&
|
|
|
|
srcX0 - srcX1 == dstX0 - dstX1 &&
|
|
|
|
srcY0 - srcY1 == dstY0 - dstY1 &&
|
|
|
|
srcX1 >= srcX0 &&
|
|
|
|
srcY1 >= srcY0 &&
|
|
|
|
srcX0 >= 0 && srcX1 <= readFb->Width &&
|
|
|
|
srcY0 >= 0 && srcY1 <= readFb->Height &&
|
|
|
|
dstX0 >= 0 && dstX1 <= drawFb->Width &&
|
|
|
|
dstY0 >= 0 && dstY1 <= drawFb->Height &&
|
|
|
|
!ctx->Scissor.Enabled) {
|
|
|
|
const struct gl_texture_object *texObj = drawAtt->Texture;
|
|
|
|
const GLuint dstLevel = drawAtt->TextureLevel;
|
|
|
|
const GLenum target = texObj->Target;
|
|
|
|
|
|
|
|
struct gl_texture_image *texImage =
|
|
|
|
_mesa_select_tex_image(ctx, texObj, target, dstLevel);
|
|
|
|
GLenum internalFormat = texImage->InternalFormat;
|
|
|
|
|
|
|
|
if (intel_copy_texsubimage(intel_context(ctx), target,
|
|
|
|
intel_texture_image(texImage),
|
|
|
|
internalFormat,
|
|
|
|
dstX0, dstY0,
|
|
|
|
srcX0, srcY0,
|
|
|
|
srcX1 - srcX0, /* width */
|
|
|
|
srcY1 - srcY0))
|
|
|
|
mask &= ~GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
intel_blit_framebuffer(struct gl_context *ctx,
|
|
|
|
GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
|
|
|
|
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
|
|
|
|
GLbitfield mask, GLenum filter)
|
|
|
|
{
|
|
|
|
/* Try faster, glCopyTexSubImage2D approach first which uses the BLT. */
|
|
|
|
mask = intel_blit_framebuffer_copy_tex_sub_image(ctx,
|
|
|
|
srcX0, srcY0, srcX1, srcY1,
|
|
|
|
dstX0, dstY0, dstX1, dstY1,
|
|
|
|
mask, filter);
|
|
|
|
if (mask == 0x0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_mesa_meta_BlitFramebuffer(ctx,
|
|
|
|
srcX0, srcY0, srcX1, srcY1,
|
|
|
|
dstX0, dstY0, dstX1, dstY1,
|
|
|
|
mask, filter);
|
|
|
|
}
|
2009-01-20 15:30:22 -07:00
|
|
|
|
2007-11-07 10:04:59 -08:00
|
|
|
/**
|
|
|
|
* Do one-time context initializations related to GL_EXT_framebuffer_object.
|
|
|
|
* Hook in device driver functions.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
intel_fbo_init(struct intel_context *intel)
|
|
|
|
{
|
|
|
|
intel->ctx.Driver.NewFramebuffer = intel_new_framebuffer;
|
|
|
|
intel->ctx.Driver.NewRenderbuffer = intel_new_renderbuffer;
|
|
|
|
intel->ctx.Driver.BindFramebuffer = intel_bind_framebuffer;
|
|
|
|
intel->ctx.Driver.FramebufferRenderbuffer = intel_framebuffer_renderbuffer;
|
|
|
|
intel->ctx.Driver.RenderTexture = intel_render_texture;
|
|
|
|
intel->ctx.Driver.FinishRenderTexture = intel_finish_render_texture;
|
|
|
|
intel->ctx.Driver.ResizeBuffers = intel_resize_buffers;
|
2009-01-20 15:30:22 -07:00
|
|
|
intel->ctx.Driver.ValidateFramebuffer = intel_validate_framebuffer;
|
2011-02-05 10:21:11 +00:00
|
|
|
intel->ctx.Driver.BlitFramebuffer = intel_blit_framebuffer;
|
2010-02-11 19:04:02 -05:00
|
|
|
|
|
|
|
#if FEATURE_OES_EGL_image
|
|
|
|
intel->ctx.Driver.EGLImageTargetRenderbufferStorage =
|
|
|
|
intel_image_target_renderbuffer_storage;
|
|
|
|
#endif
|
2007-11-07 10:04:59 -08:00
|
|
|
}
|