mesa: Track the TexImage being rendered to in the gl_renderbuffer.
authorEric Anholt <eric@anholt.net>
Fri, 10 May 2013 18:51:01 +0000 (11:51 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 17 May 2013 20:04:05 +0000 (13:04 -0700)
We keep having to pass the attachments around with our gl_renderbuffers
because that's the only way to find what the gl_renderbuffer actually
refers to.  This is a step toward removing that (though drivers still need
the Zoffset as well).

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
12 files changed:
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/intel/intel_fbo.c
src/mesa/drivers/dri/intel/intel_fbo.h
src/mesa/drivers/dri/nouveau/nouveau_fbo.c
src/mesa/drivers/dri/radeon/radeon_fbo.c
src/mesa/main/fbobject.c
src/mesa/main/fbobject.h
src/mesa/main/framebuffer.c
src/mesa/main/mtypes.h
src/mesa/main/teximage.c
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/swrast/s_texrender.c

index 784e90718b4781df67065f97a6570141fdc2e2db..bbe8579c5534521d0717f8c4e378f01ef6ba2b6e 100644 (file)
@@ -1328,7 +1328,7 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
    /* _NEW_BUFFERS */
    gl_format rb_format = _mesa_get_render_format(ctx, intel_rb_format(irb));
 
-   if (irb->tex_image && !brw->has_surface_tile_offset) {
+   if (rb->TexImage && !brw->has_surface_tile_offset) {
       intel_renderbuffer_tile_offsets(irb, &tile_x, &tile_y);
 
       if (tile_x != 0 || tile_y != 0) {
index 6b30262892a8dfb1cdee96161f78629f22a4da50..bf8e48d779bf84fa12981a4ae83b91220582d137 100644 (file)
@@ -572,8 +572,9 @@ intel_render_texture(struct gl_context * ctx,
                      struct gl_renderbuffer_attachment *att)
 {
    struct intel_context *intel = intel_context(ctx);
-   struct gl_texture_image *image = _mesa_get_attachment_teximage(att);
-   struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer);
+   struct gl_renderbuffer *rb = att->Renderbuffer;
+   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
+   struct gl_texture_image *image = rb->TexImage;
    struct intel_texture_image *intel_image = intel_texture_image(image);
    struct intel_mipmap_tree *mt = intel_image->mt;
    int layer;
@@ -602,12 +603,10 @@ intel_render_texture(struct gl_context * ctx,
        return;
    }
 
-   irb->tex_image = image;
-
    DBG("Begin render %s texture tex=%u w=%d h=%d refcount=%d\n",
        _mesa_get_format_name(image->TexFormat),
        att->Texture->Name, image->Width, image->Height,
-       irb->Base.Base.RefCount);
+       rb->RefCount);
 
    /* update drawing region, etc */
    intel_draw_buffer(ctx);
@@ -623,13 +622,9 @@ intel_finish_render_texture(struct gl_context * ctx,
 {
    struct intel_context *intel = intel_context(ctx);
    struct gl_renderbuffer *rb = att->Renderbuffer;
-   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
 
    DBG("Finish render %s texture\n", _mesa_get_format_name(rb->Format));
 
-   if (irb)
-      irb->tex_image = NULL;
-
    /* 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
@@ -734,10 +729,7 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
       }
 
       if (fb->Attachment[i].Type == GL_TEXTURE) {
-        const struct gl_texture_image *img =
-           _mesa_get_attachment_teximage_const(&fb->Attachment[i]);
-
-        if (img->Border) {
+        if (rb->TexImage->Border) {
            fbo_incomplete(fb, "FBO incomplete: texture with border\n");
            continue;
         }
@@ -945,14 +937,14 @@ intel_renderbuffer_move_to_temp(struct intel_context *intel,
                                 struct intel_renderbuffer *irb,
                                 bool invalidate)
 {
-   struct intel_texture_image *intel_image =
-      intel_texture_image(irb->tex_image);
+   struct gl_renderbuffer *rb =&irb->Base.Base;
+   struct intel_texture_image *intel_image = intel_texture_image(rb->TexImage);
    struct intel_mipmap_tree *new_mt;
    int width, height, depth;
 
-   intel_miptree_get_dimensions_for_image(irb->tex_image, &width, &height, &depth);
+   intel_miptree_get_dimensions_for_image(rb->TexImage, &width, &height, &depth);
 
-   new_mt = intel_miptree_create(intel, irb->tex_image->TexObject->Target,
+   new_mt = intel_miptree_create(intel, rb->TexImage->TexObject->Target,
                                  intel_image->base.Base.TexFormat,
                                  intel_image->base.Base.Level,
                                  intel_image->base.Base.Level,
index 0e0806b63bb889e6092a52f803834c70d5907c44..aa52b979f88d17f4ba2eaedb7720ff0c783ad0d4 100644 (file)
@@ -52,9 +52,6 @@ struct intel_renderbuffer
    struct intel_mipmap_tree *mt; /**< The renderbuffer storage. */
    drm_intel_bo *map_bo;
 
-   /* Current texture image this renderbuffer is attached to. */
-   struct gl_texture_image *tex_image;
-
    /**
     * \name Miptree view
     * \{
index a692051c082950839b0a2c9019d33c4f4594afef..f997ac888f9f076c7e197868fdd0a5da73eda94d 100644 (file)
@@ -252,8 +252,7 @@ nouveau_render_texture(struct gl_context *ctx, struct gl_framebuffer *fb,
                       struct gl_renderbuffer_attachment *att)
 {
        struct gl_renderbuffer *rb = att->Renderbuffer;
-       struct gl_texture_image *ti =
-               att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+       struct gl_texture_image *ti = rb->TexImage;
 
        /* Update the renderbuffer fields from the texture. */
        nouveau_surface_ref(&to_nouveau_teximage(ti)->surface,
index c43f527d2221b75bca8f84c03074a1ca1507e224..1fdcf05656215a273c63276415cab2585c89203b 100644 (file)
@@ -787,9 +787,9 @@ radeon_render_texture(struct gl_context * ctx,
                      struct gl_framebuffer *fb,
                      struct gl_renderbuffer_attachment *att)
 {
-   struct gl_texture_image *newImage
-      = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
-   struct radeon_renderbuffer *rrb = radeon_renderbuffer(att->Renderbuffer);
+   struct gl_renderbuffer *rb = att->Renderbuffer;
+   struct gl_texture_image *newImage = rb->TexImage;
+   struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
    radeon_texture_image *radeon_image;
    GLuint imageOffset;
 
@@ -818,7 +818,7 @@ radeon_render_texture(struct gl_context * ctx,
    DBG("Begin render texture tid %lx tex=%u w=%d h=%d refcount=%d\n",
        _glthread_GetID(),
        att->Texture->Name, newImage->Width, newImage->Height,
-       rrb->base.Base.RefCount);
+       rb->RefCount);
 
    /* point the renderbufer's region to the texture image region */
    if (rrb->bo != radeon_image->mt->bo) {
@@ -853,11 +853,8 @@ static void
 radeon_finish_render_texture(struct gl_context * ctx,
                             struct gl_renderbuffer_attachment *att)
 {
-    struct gl_texture_object *tex_obj = att->Texture;
-    radeon_texture_image *radeon_image = NULL;
-
-    if (tex_obj)
-        radeon_image = (radeon_texture_image *)_mesa_get_attachment_teximage(att);
+    struct gl_texture_image *image = att->Renderbuffer->TexImage;
+    radeon_texture_image *radeon_image = (radeon_texture_image *)image;
 
     if (radeon_image)
        radeon_image->used_as_render_target = GL_FALSE;
@@ -883,7 +880,7 @@ radeon_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
                }
 
                if (att->Type == GL_TEXTURE) {
-                       mesa_format = att->Texture->Image[att->CubeMapFace][att->TextureLevel]->TexFormat;
+                       mesa_format = att->Renderbuffer->TexImage->TexFormat;
                } else {
                        /* All renderbuffer formats are renderable, but not sampable */
                        continue;
index f00d11ab9f181e8bc6a3b3187e0677e9f2e63139..070fb8c535628aa92346d1d699478830a1fca652 100644 (file)
@@ -363,7 +363,7 @@ _mesa_update_texture_renderbuffer(struct gl_context *ctx,
    struct gl_texture_image *texImage;
    struct gl_renderbuffer *rb;
 
-   texImage = _mesa_get_attachment_teximage(att);
+   texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
    if (!texImage)
       return;
 
@@ -390,6 +390,7 @@ _mesa_update_texture_renderbuffer(struct gl_context *ctx,
    rb->Width = texImage->Width2;
    rb->Height = texImage->Height2;
    rb->NumSamples = texImage->NumSamples;
+   rb->TexImage = texImage;
 
    ctx->Driver.RenderTexture(ctx, fb, att);
 }
@@ -889,8 +890,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
       /* get width, height, format of the renderbuffer/texture
        */
       if (att->Type == GL_TEXTURE) {
-         const struct gl_texture_image *texImg =
-            _mesa_get_attachment_teximage(att);
+         const struct gl_texture_image *texImg = att->Renderbuffer->TexImage;
          minWidth = MIN2(minWidth, texImg->Width);
          maxWidth = MAX2(maxWidth, texImg->Width);
          minHeight = MIN2(minHeight, texImg->Height);
@@ -1862,7 +1862,7 @@ check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
 
    for (i = 0; i < BUFFER_COUNT; i++) {
       struct gl_renderbuffer_attachment *att = fb->Attachment + i;
-      if (att->Texture && _mesa_get_attachment_teximage(att)) {
+      if (att->Texture && att->Renderbuffer->TexImage) {
          ctx->Driver.RenderTexture(ctx, fb, att);
       }
    }
index bfab6e17da7d4dce169187b40df9d6cdba1aa148..dfd795a3a52806008d9947fccc6c94e46400f609 100644 (file)
@@ -71,25 +71,6 @@ extern struct gl_renderbuffer_attachment *
 _mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
                      GLenum attachment);
 
-
-/** Return the texture image for a renderbuffer attachment */
-static inline struct gl_texture_image *
-_mesa_get_attachment_teximage(struct gl_renderbuffer_attachment *att)
-{
-   assert(att->Type == GL_TEXTURE);
-   return att->Texture->Image[att->CubeMapFace][att->TextureLevel];
-}
-
-
-/** Return the (const) texture image for a renderbuffer attachment */
-static inline const struct gl_texture_image *
-_mesa_get_attachment_teximage_const(const struct gl_renderbuffer_attachment *att)
-{
-   assert(att->Type == GL_TEXTURE);
-   return att->Texture->Image[att->CubeMapFace][att->TextureLevel];
-}
-
-
 extern void
 _mesa_remove_attachment(struct gl_context *ctx,
                         struct gl_renderbuffer_attachment *att);
index 911bb927a6098b2add6323f2c6ee1061f9b845df..af3c595258309a5392aaee6ff724e2fa9714794d 100644 (file)
@@ -962,8 +962,7 @@ _mesa_print_framebuffer(const struct gl_framebuffer *fb)
    for (i = 0; i < BUFFER_COUNT; i++) {
       const struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
       if (att->Type == GL_TEXTURE) {
-         const struct gl_texture_image *texImage =
-            _mesa_get_attachment_teximage_const(att);
+         const struct gl_texture_image *texImage = att->Renderbuffer->TexImage;
          fprintf(stderr,
                  "  %2d: Texture %u, level %u, face %u, slice %u, complete %d\n",
                  i, att->Texture->Name, att->TextureLevel, att->CubeMapFace,
index 5dfe911d060c77b3a35df9a7f3e5a2dfb8cca431..244bee2e670f3f48b4b5a6621428c826c3abbe76 100644 (file)
@@ -2586,6 +2586,14 @@ struct gl_renderbuffer
    GLenum _BaseFormat;    /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
                                GL_STENCIL_INDEX. */
    gl_format Format;      /**< The actual renderbuffer memory format */
+   /**
+    * Pointer to the texture image if this renderbuffer wraps a texture,
+    * otherwise NULL.
+    *
+    * Note that the reference on the gl_texture_object containing this
+    * TexImage is held by the gl_renderbuffer_attachment.
+    */
+   struct gl_texture_image *TexImage;
 
    /** Delete this renderbuffer */
    void (*Delete)(struct gl_context *ctx, struct gl_renderbuffer *rb);
index 26fa4c381907250389ae091d96f605f71b83b7b1..d07f6e9dc9ec790d2cd8c1fb8ab507b2052bc0b3 100644 (file)
@@ -2759,8 +2759,8 @@ check_rtt_cb(GLuint key, void *data, void *userData)
              att->Texture == texObj &&
              att->TextureLevel == level &&
              att->CubeMapFace == face) {
-            ASSERT(_mesa_get_attachment_teximage(att));
             _mesa_update_texture_renderbuffer(ctx, ctx->DrawBuffer, att);
+            ASSERT(att->Renderbuffer->TexImage);
             /* Mark fb status as indeterminate to force re-validation */
             fb->_Status = 0;
          }
index aa245d3fc0e76c25d3718c3aad32291f3ba5eec6..db4728b3237af21a7ee14b743c894ad99e2d30dd 100644 (file)
@@ -394,7 +394,6 @@ st_render_texture(struct gl_context *ctx,
    struct st_renderbuffer *strb = st_renderbuffer(rb);
    struct pipe_resource *pt;
    struct st_texture_object *stObj;
-   const struct gl_texture_image *texImage;
    struct pipe_surface surf_tmpl;
 
    if (!st_finalize_texture(ctx, pipe, att->Texture))
@@ -403,9 +402,6 @@ st_render_texture(struct gl_context *ctx,
    pt = st_get_texobj_resource(att->Texture);
    assert(pt);
 
-   /* get pointer to texture image we're rendeing to */
-   texImage = _mesa_get_attachment_teximage(att);
-
    /* get the texture for the texture object */
    stObj = st_texture_object(att->Texture);
 
@@ -503,7 +499,7 @@ st_validate_attachment(struct gl_context *ctx,
       return GL_FALSE;
 
    format = stObj->pt->format;
-   texFormat = _mesa_get_attachment_teximage_const(att)->TexFormat;
+   texFormat = att->Renderbuffer->TexImage->TexFormat;
 
    /* If the encoding is sRGB and sRGB rendering cannot be enabled,
     * check for linear format support instead.
index 00b3ca55ac0c6a4a05e2b5a741da6279bf9dd56e..643f2bc2c24e3b8d636a8d98c7bebe5e64344be5 100644 (file)
@@ -38,7 +38,7 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
 
    (void) ctx;
 
-   swImage = swrast_texture_image(_mesa_get_attachment_teximage(att));
+   swImage = swrast_texture_image(rb->TexImage);
    assert(swImage);
 
    format = swImage->Base.TexFormat;