Mesa (master): fbo: Only reuse depth/ stencil attachments if the parameters match.

Brian Paul brianp at vmware.com
Mon May 7 18:00:21 UTC 2012


On 05/07/2012 11:53 AM, Paul Berry wrote:
> Module: Mesa
> Branch: master
> Commit: b9819a027d08b38abb380526bed9f2908ffeb507
> URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b9819a027d08b38abb380526bed9f2908ffeb507
>
> Author: Paul Berry<stereotype441 at gmail.com>
> Date:   Fri Apr 13 21:50:08 2012 -0700
>
> fbo: Only reuse depth/stencil attachments if the parameters match.
>
> When the user attaches a texture to one of the depth/stencil
> attachment points (GL_STENCIL_ATTACHMENT or GL_DEPTH_ATTACHMENT), we
> check to see if the same texture is also attached to the other
> attachment point, and if so, we re-use the existing texture
> attachment.  This is necessary to ensure that if the user later
> queries what is attached to GL_DEPTH_STENCIL_ATTACHMENT, they will not
> receive an error.
>
> If, however, the user attaches buffers to the two different attachment
> points using different parameters (e.g. a different miplevel), then we
> can't re-use the existing texture attachment, because it is pointing
> to the wrong part of the texture.  This might occur as a transitory
> condition if, for example, if the user attached miplevel zero of a
> texture to GL_STENCIL_ATTACHMENT and GL_DEPTH_ATTACHMENT, rendered to
> it, and then later attempted to attach miplevel one of the same
> texture to GL_STENCIL_ATTACHMENT and GL_DEPTH_ATTACHMENT.
>
> This patch causes Mesa to check that GL_STENCIL_ATTACHMENT and
> GL_DEPTH_ATTACHMENT use the same attachment parameters before
> attempting to share the texture attachment.
>
> On i965 Gen6, fixes piglit tests
> "texturing/depthstencil-render-miplevels 1024 depth_stencil_shared"
> and "texturing/depthstencil-render-miplevels 1024
> stencil_depth_shared".
>
> Reviewed-by: Chad Versace<chad.versace at linux.intel.com>
>
> ---
>
>   src/mesa/main/fbobject.c |   14 +++++++++++---
>   1 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
> index 26ae108..f563694 100644
> --- a/src/mesa/main/fbobject.c
> +++ b/src/mesa/main/fbobject.c
> @@ -2023,7 +2023,11 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
>      _glthread_LOCK_MUTEX(fb->Mutex);
>      if (texObj) {
>         if (attachment == GL_DEPTH_ATTACHMENT&&
> -	   texObj == fb->Attachment[BUFFER_STENCIL].Texture) {
> +          texObj == fb->Attachment[BUFFER_STENCIL].Texture&&
> +          level == fb->Attachment[BUFFER_STENCIL].TextureLevel&&
> +          _mesa_tex_target_to_face(textarget) ==
> +          fb->Attachment[BUFFER_STENCIL].CubeMapFace&&
> +          zoffset == fb->Attachment[BUFFER_STENCIL].Zoffset) {
>   	 /* The texture object is already attached to the stencil attachment
>   	  * point. Don't create a new renderbuffer; just reuse the stencil
>   	  * attachment's. This is required to prevent a GL error in
> @@ -2032,8 +2036,12 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
>   	 reuse_framebuffer_texture_attachment(fb, BUFFER_DEPTH,
>   	                                      BUFFER_STENCIL);
>         } else if (attachment == GL_STENCIL_ATTACHMENT&&
> -	         texObj == fb->Attachment[BUFFER_DEPTH].Texture) {
> -	 /* As above, but with depth and stencil juxtaposed. */
> +	         texObj == fb->Attachment[BUFFER_DEPTH].Texture&&
> +                 level == fb->Attachment[BUFFER_DEPTH].TextureLevel&&
> +                 _mesa_tex_target_to_face(textarget) ==
> +                 fb->Attachment[BUFFER_DEPTH].CubeMapFace&&
> +                 zoffset == fb->Attachment[BUFFER_DEPTH].Zoffset) {
> +	 /* As above, but with depth and stencil transposed. */
>   	 reuse_framebuffer_texture_attachment(fb, BUFFER_STENCIL,
>   	                                      BUFFER_DEPTH);
>         } else {

It looks like there's some common code there that could be put into a 
utility function and shared.  Something like:

/**
  * Check if the frambuffer attachment point matches the given texture
  * image info.
  */
GLboolean
attachment_matches_texture(const struct gl_renderbuffer_attachment *att,
                            const gl_texture_object *texObj,
                            GLuint texTarget, GLuint level, GLuint 
zoffset)

-Brian



More information about the mesa-commit mailing list