summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/r300/r300_texture.c
diff options
context:
space:
mode:
authorMarek Olšák <maraeo@gmail.com>2010-07-24 03:34:18 +0200
committerMarek Olšák <maraeo@gmail.com>2010-07-25 10:25:21 +0200
commit065e3f7ff2a9b6170e51b0104036088e8d163ea0 (patch)
tree04060c79de38bb73937803dd48673c617836f366 /src/gallium/drivers/r300/r300_texture.c
parent4ce26210842176c4b280b7db85639ced40d4083d (diff)
r300g: reject resources from handles which are not large enough
The driver gets a buffer and its size in resource_from_handle. It computes the required minimum buffer size from given texture properties, and compares the two sizes. This is to early detect DDX bugs.
Diffstat (limited to 'src/gallium/drivers/r300/r300_texture.c')
-rw-r--r--src/gallium/drivers/r300/r300_texture.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c
index 176fa76920..711042722c 100644
--- a/src/gallium/drivers/r300/r300_texture.c
+++ b/src/gallium/drivers/r300/r300_texture.c
@@ -1022,6 +1022,7 @@ struct pipe_resource* r300_texture_create(struct pipe_screen* screen,
tex->buffer = rws->buffer_create(rws, tex->size, 2048, base->bind,
base->usage, tex->domain);
+ tex->buffer_size = tex->size;
if (!tex->buffer) {
FREE(tex);
@@ -1120,7 +1121,7 @@ r300_texture_from_handle(struct pipe_screen* screen,
struct r300_screen* rscreen = r300_screen(screen);
struct r300_winsys_buffer *buffer;
struct r300_texture* tex;
- unsigned stride;
+ unsigned stride, size;
boolean override_zb_flags;
/* Support only 2D textures without mipmaps */
@@ -1130,7 +1131,7 @@ r300_texture_from_handle(struct pipe_screen* screen,
return NULL;
}
- buffer = rws->buffer_from_handle(rws, whandle, &stride);
+ buffer = rws->buffer_from_handle(rws, whandle, &stride, &size);
if (!buffer) {
return NULL;
}
@@ -1150,6 +1151,7 @@ r300_texture_from_handle(struct pipe_screen* screen,
/* one ref already taken */
tex->buffer = buffer;
+ tex->buffer_size = size;
rws->buffer_get_tiling(rws, buffer, &tex->microtile, &tex->macrotile);
r300_setup_flags(tex);
@@ -1186,8 +1188,18 @@ r300_texture_from_handle(struct pipe_screen* screen,
tex->pitch[0] * util_format_get_blocksize(tex->b.b.format));
}
- if (SCREEN_DBG_ON(rscreen, DBG_TEX))
+ /* Make sure the buffer we got is large enough. */
+ if (tex->size > tex->buffer_size) {
+ fprintf(stderr, "r300: texture_from_handle: The buffer is not "
+ "large enough. Got: %i, Need: %i, Info:\n",
+ tex->buffer_size, tex->size);
r300_tex_print_info(rscreen, tex, "texture_from_handle");
+ pipe_resource_reference((struct pipe_resource**)&tex, NULL);
+ return NULL;
+ } else {
+ if (SCREEN_DBG_ON(rscreen, DBG_TEX))
+ r300_tex_print_info(rscreen, tex, "texture_from_handle");
+ }
return (struct pipe_resource*)tex;
}