radeonsi: add assertions to prevent creation of invalid surfaces
authorMarek Olšák <maraeo@gmail.com>
Tue, 19 Feb 2013 16:43:08 +0000 (17:43 +0100)
committerMichel Dänzer <michel@daenzer.net>
Wed, 20 Feb 2013 11:30:32 +0000 (12:30 +0100)
[ Cherry-picked from r600g commit ef11ed61a0414d0405c3faf7f48fa3f1d083f82e ]

NOTE: This is a candidate for the 9.1 branch.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
src/gallium/drivers/radeonsi/r600_blit.c
src/gallium/drivers/radeonsi/r600_texture.c
src/gallium/drivers/radeonsi/radeonsi_pipe.h

index 35c8f9594460f6b549e01dd1d0b45ef0c9b7ff3a..0b0eba3c79400c44a45a32ae9fa69978a5d2e81c 100644 (file)
@@ -98,21 +98,6 @@ static void r600_blitter_end(struct pipe_context *ctx)
        r600_context_queries_resume(rctx);
 }
 
-static unsigned u_max_layer(struct pipe_resource *r, unsigned level)
-{
-       switch (r->target) {
-       case PIPE_TEXTURE_CUBE:
-               return 6 - 1;
-       case PIPE_TEXTURE_3D:
-               return u_minify(r->depth0, level) - 1;
-       case PIPE_TEXTURE_1D_ARRAY:
-       case PIPE_TEXTURE_2D_ARRAY:
-               return r->array_size - 1;
-       default:
-               return 0;
-       }
-}
-
 void si_blit_uncompress_depth(struct pipe_context *ctx,
                struct r600_resource_texture *texture,
                struct r600_resource_texture *staging,
index d54655441a004618ea3cb9f08f3ef0694a5a7e2c..5790974b0138a7e55a1e5031db7722d3c371767f 100644 (file)
@@ -545,6 +545,8 @@ static struct pipe_surface *r600_create_surface(struct pipe_context *pipe,
        struct r600_surface *surface = CALLOC_STRUCT(r600_surface);
        unsigned level = surf_tmpl->u.tex.level;
 
+       assert(surf_tmpl->u.tex.first_layer <= u_max_layer(texture, surf_tmpl->u.tex.level));
+       assert(surf_tmpl->u.tex.last_layer <= u_max_layer(texture, surf_tmpl->u.tex.level));
        assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer);
        if (surface == NULL)
                return NULL;
index d0f04f405626646bba823b316b6db1d96d5973c9..8c6d9081266c2cd1575c9acb1fe47810ed64a80d 100644 (file)
@@ -277,4 +277,20 @@ static INLINE uint64_t r600_resource_va(struct pipe_screen *screen, struct pipe_
        return rscreen->ws->buffer_get_virtual_address(rresource->cs_buf);
 }
 
+static INLINE unsigned u_max_layer(struct pipe_resource *r, unsigned level)
+{
+       switch (r->target) {
+       case PIPE_TEXTURE_CUBE:
+               return 6 - 1;
+       case PIPE_TEXTURE_3D:
+               return u_minify(r->depth0, level) - 1;
+       case PIPE_TEXTURE_1D_ARRAY:
+       case PIPE_TEXTURE_2D_ARRAY:
+       case PIPE_TEXTURE_CUBE_ARRAY:
+               return r->array_size - 1;
+       default:
+               return 0;
+       }
+}
+
 #endif