summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGert Wollny <gert.wollny@collabora.com>2019-05-13 14:02:24 +0200
committerJuan A. Suarez Romero <jasuarez@igalia.com>2019-05-14 08:41:50 +0000
commit9b51dcf1e28fcda5062ea7beb326f6f09a4e8586 (patch)
tree3c0492914844147786d64a8afad3440bedd34e29
parent914ac06e32136ddf504b0e0ce8b4347ebabc2802 (diff)
softpipe/buffer: load only as many components as the the buffer resource type provides
Otherwise we risk to read past the end of the buffer. In addition, change the loop counters to unsigned to be consistent with the types. Fixes: afa8707ba93a7d226a76319acda2a8dd89524db7 softpipe: add SSBO/shader atomics support. Signed-off-by: Gert Wollny <gert.wollny@collabora.com> Reviewed-by: Dave Airlie <airlied@redhat.com> (cherry picked from commit 865b9ddae4874186182e529b5fd154ab04a61f79)
-rw-r--r--src/gallium/drivers/softpipe/sp_buffer.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/gallium/drivers/softpipe/sp_buffer.c b/src/gallium/drivers/softpipe/sp_buffer.c
index 3ec738527af..4b0617e0bea 100644
--- a/src/gallium/drivers/softpipe/sp_buffer.c
+++ b/src/gallium/drivers/softpipe/sp_buffer.c
@@ -55,7 +55,8 @@ sp_tgsi_load(const struct tgsi_buffer *buffer,
struct pipe_shader_buffer *bview;
struct softpipe_resource *spr;
unsigned width;
- int c, j;
+ unsigned ncomp;
+ unsigned c, j;
unsigned char *data_ptr;
const struct util_format_description *format_desc = util_format_description(PIPE_FORMAT_R32_UINT);
@@ -63,6 +64,8 @@ sp_tgsi_load(const struct tgsi_buffer *buffer,
goto fail_write_all_zero;
bview = &sp_buf->sp_bview[params->unit];
+ ncomp = util_format_get_nr_components(bview->buffer->format);
+
spr = softpipe_resource(bview->buffer);
if (!spr)
goto fail_write_all_zero;
@@ -88,7 +91,7 @@ sp_tgsi_load(const struct tgsi_buffer *buffer,
continue;
}
data_ptr = (unsigned char *)spr->data + bview->buffer_offset + s_coord;
- for (c = 0; c < 4; c++) {
+ for (c = 0; c < ncomp; c++) {
format_desc->fetch_rgba_uint(sdata, data_ptr, 0, 0);
((uint32_t *)rgba[c])[j] = sdata[0];
data_ptr += 4;