[Mesa-dev] [PATCH] svga: dynamically allocate svga_texture::rendered_to array

Brian Paul brianp at vmware.com
Sat Nov 16 07:49:43 PST 2013


Needs to be larger than 6 to accomodate 3D textures and array textures.
Fixes a few piglit tests (fbo-3d, copyteximage 3D).
---
 src/gallium/drivers/svga/svga_resource_texture.c |    9 +++++
 src/gallium/drivers/svga/svga_resource_texture.h |   41 ++++++++++++----------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c
index 17c87ef..88ab451 100644
--- a/src/gallium/drivers/svga/svga_resource_texture.c
+++ b/src/gallium/drivers/svga/svga_resource_texture.c
@@ -238,6 +238,7 @@ svga_texture_destroy(struct pipe_screen *screen,
 
    ss->total_resource_bytes -= tex->size;
 
+   FREE(tex->rendered_to);
    FREE(tex);
 }
 
@@ -735,9 +736,15 @@ svga_texture_create(struct pipe_screen *screen,
    tex->size = util_resource_size(template);
    svgascreen->total_resource_bytes += tex->size;
 
+   tex->rendered_to = calloc(template->depth0 * template->array_size,
+                             sizeof(tex->rendered_to[0]));
+   if (!tex->rendered_to)
+      goto error2;
+
    return &tex->b.b;
 
 error2:
+   FREE(tex->rendered_to);
    FREE(tex);
 error1:
    return NULL;
@@ -796,5 +803,7 @@ svga_texture_from_handle(struct pipe_screen *screen,
    tex->key.cachable = 0;
    tex->handle = srf;
 
+   tex->rendered_to = malloc(sizeof(tex->rendered_to[0]));
+
    return &tex->b.b;
 }
diff --git a/src/gallium/drivers/svga/svga_resource_texture.h b/src/gallium/drivers/svga/svga_resource_texture.h
index 6c7a754..1ff42fa 100644
--- a/src/gallium/drivers/svga/svga_resource_texture.h
+++ b/src/gallium/drivers/svga/svga_resource_texture.h
@@ -79,7 +79,8 @@ struct svga_texture
 
    unsigned size;  /**< Approximate size in bytes */
 
-   unsigned rendered_to[6];  /** six cube faces, one bit per mipmap level */
+   /** array indexed by cube face or 3D/array slice, one bit per mipmap level */
+   ushort *rendered_to;
 };
 
 
@@ -157,16 +158,30 @@ svga_is_texture_level_defined(const struct svga_texture *tex,
 }
 
 
-static INLINE void
-svga_set_texture_rendered_to(struct svga_texture *tex,
-                             unsigned face, unsigned level)
+/** For debugging, check that face and level are legal */
+static inline void
+check_face_level(const struct svga_texture *tex,
+                 unsigned face, unsigned level)
 {
    if (tex->b.b.target == PIPE_TEXTURE_CUBE) {
-      assert(face < Elements(tex->rendered_to));
+      assert(face < 6);
+   }
+   else if (tex->b.b.target == PIPE_TEXTURE_3D) {
+      assert(face < tex->b.b.depth0);
    }
    else {
-      assert(face == 0);
+      assert(face < tex->b.b.array_size);
    }
+
+   assert(level < 8 * sizeof(tex->rendered_to[0]));
+}
+
+
+static INLINE void
+svga_set_texture_rendered_to(struct svga_texture *tex,
+                             unsigned face, unsigned level)
+{
+   check_face_level(tex, face, level);
    tex->rendered_to[face] |= 1 << level;
 }
 
@@ -175,12 +190,7 @@ static INLINE void
 svga_clear_texture_rendered_to(struct svga_texture *tex,
                                unsigned face, unsigned level)
 {
-   if (tex->b.b.target == PIPE_TEXTURE_CUBE) {
-      assert(face < Elements(tex->rendered_to));
-   }
-   else {
-      assert(face == 0);
-   }
+   check_face_level(tex, face, level);
    tex->rendered_to[face] &= ~(1 << level);
 }
 
@@ -189,12 +199,7 @@ static INLINE boolean
 svga_was_texture_rendered_to(const struct svga_texture *tex,
                              unsigned face, unsigned level)
 {
-   if (tex->b.b.target == PIPE_TEXTURE_CUBE) {
-      assert(face < Elements(tex->rendered_to));
-   }
-   else {
-      assert(face == 0);
-   }
+   check_face_level(tex, face, level);
    return !!(tex->rendered_to[face] & (1 << level));
 }
 
-- 
1.7.10.4



More information about the mesa-dev mailing list