From ef11ed61a0414d0405c3faf7f48fa3f1d083f82e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 20 Dec 2012 00:28:24 +0100 Subject: [PATCH] r600g: add assertions to prevent creation of invalid surfaces --- src/gallium/drivers/r600/r600_blit.c | 16 ---------------- src/gallium/drivers/r600/r600_pipe.h | 16 ++++++++++++++++ src/gallium/drivers/r600/r600_texture.c | 2 ++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c index f702f7b..219d940 100644 --- a/src/gallium/drivers/r600/r600_blit.c +++ b/src/gallium/drivers/r600/r600_blit.c @@ -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; diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h index c348c76..8df50e9 100644 --- a/src/gallium/drivers/r600/r600_pipe.h +++ b/src/gallium/drivers/r600/r600_pipe.h @@ -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 diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c index 56e9b64..0925333 100644 --- a/src/gallium/drivers/r600/r600_texture.c +++ b/src/gallium/drivers/r600/r600_texture.c @@ -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; -- 2.7.4