gallium/radeon: fix a possible crash for buffer exports
authorMarek Olšák <marek.olsak@amd.com>
Tue, 27 Jun 2017 17:24:20 +0000 (19:24 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 4 Jul 2017 13:40:37 +0000 (15:40 +0200)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/drivers/radeon/r600_texture.c

index d68587b4a2791b8883a3fa982d3155b46996825c..139ab137599c5ead10be72b8ae76736530eb3836 100644 (file)
@@ -589,16 +589,22 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,
                res->external_usage = usage;
        }
 
-       if (rscreen->chip_class >= GFX9) {
-               offset = rtex->surface.u.gfx9.surf_offset;
-               stride = rtex->surface.u.gfx9.surf_pitch *
-                        rtex->surface.bpe;
-               slice_size = rtex->surface.u.gfx9.surf_slice_size;
+       if (res->b.b.target == PIPE_BUFFER) {
+               offset = 0;
+               stride = 0;
+               slice_size = 0;
        } else {
-               offset = rtex->surface.u.legacy.level[0].offset;
-               stride = rtex->surface.u.legacy.level[0].nblk_x *
-                        rtex->surface.bpe;
-               slice_size = rtex->surface.u.legacy.level[0].slice_size;
+               if (rscreen->chip_class >= GFX9) {
+                       offset = rtex->surface.u.gfx9.surf_offset;
+                       stride = rtex->surface.u.gfx9.surf_pitch *
+                                rtex->surface.bpe;
+                       slice_size = rtex->surface.u.gfx9.surf_slice_size;
+               } else {
+                       offset = rtex->surface.u.legacy.level[0].offset;
+                       stride = rtex->surface.u.legacy.level[0].nblk_x *
+                                rtex->surface.bpe;
+                       slice_size = rtex->surface.u.legacy.level[0].slice_size;
+               }
        }
        return rscreen->ws->buffer_get_handle(res->buf, stride, offset,
                                              slice_size, whandle);