r600g: add assertions to prevent creation of invalid surfaces
authorMarek Olšák <maraeo@gmail.com>
Wed, 19 Dec 2012 23:28:24 +0000 (00:28 +0100)
committerMarek Olšák <maraeo@gmail.com>
Thu, 20 Dec 2012 16:13:18 +0000 (17:13 +0100)
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_texture.c

index f702f7bd4f048a70095022d527d2a5e617810137..219d940b3c1e45a7b8040780885b943d5662a3ae 100644 (file)
@@ -98,22 +98,6 @@ static void r600_blitter_end(struct pipe_context *ctx)
         r600_resume_nontimer_queries(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:
-       case PIPE_TEXTURE_CUBE_ARRAY:
-               return r->array_size - 1;
-       default:
-               return 0;
-       }
-}
-
 static unsigned u_max_sample(struct pipe_resource *r)
 {
        return r->nr_samples ? r->nr_samples - 1 : 0;
index c348c76975b3297e7bb5fde7051913232a07fc65..8df50e9bc835afbc103f9712ee1451515563facc 100644 (file)
@@ -920,4 +920,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
index 56e9b64fc473dd16880a79557662ac2f61dabfb8..0925333236adb339417ffa1d7c1f93f067e72ee9 100644 (file)
@@ -558,6 +558,8 @@ struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
 {
        struct r600_surface *surface = CALLOC_STRUCT(r600_surface);
 
+        assert(templ->u.tex.first_layer <= u_max_layer(texture, templ->u.tex.level));
+        assert(templ->u.tex.last_layer <= u_max_layer(texture, templ->u.tex.level));
        assert(templ->u.tex.first_layer == templ->u.tex.last_layer);
        if (surface == NULL)
                return NULL;