r600: implement resource_get_info
authorJulien Isorce <jisorce@oblong.com>
Thu, 2 May 2019 22:57:04 +0000 (15:57 -0700)
committerJulien Isorce <julien.isorce@gmail.com>
Fri, 3 May 2019 05:54:28 +0000 (05:54 +0000)
Factoring code with resource_get_handle.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=110443
Signed-off-by: Julien Isorce <jisorce@oblong.com>
Reviewed-by: Dave Airlie airlied@redhat.com
src/gallium/drivers/r600/r600_texture.c

index 71606df38d93a4656ba2377e08b1a007c65b7c0e..27565e0aa0c6d7c6a571c99b5cd62a7cd8f497ef 100644 (file)
@@ -442,6 +442,32 @@ static void r600_reallocate_texture_inplace(struct r600_common_context *rctx,
        p_atomic_inc(&rctx->screen->dirty_tex_counter);
 }
 
+static void r600_texture_get_info(struct pipe_screen* screen,
+                                 struct pipe_resource *resource,
+                                 unsigned *pstride,
+                                 unsigned *poffset)
+{
+       struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;
+       struct r600_texture *rtex = (struct r600_texture*)resource;
+       unsigned stride = 0;
+       unsigned offset = 0;
+
+       if (!rscreen || !rtex)
+               return;
+
+       if (resource->target != PIPE_BUFFER) {
+               offset = rtex->surface.u.legacy.level[0].offset;
+               stride = rtex->surface.u.legacy.level[0].nblk_x *
+                        rtex->surface.bpe;
+       }
+
+       if (pstride)
+               *pstride = stride;
+
+       if (poffset)
+               *poffset = offset;
+}
+
 static boolean r600_texture_get_handle(struct pipe_screen* screen,
                                       struct pipe_context *ctx,
                                       struct pipe_resource *resource,
@@ -500,9 +526,6 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,
                        rscreen->ws->buffer_set_metadata(res->buf, &metadata);
                }
 
-               offset = rtex->surface.u.legacy.level[0].offset;
-               stride = rtex->surface.u.legacy.level[0].nblk_x *
-                       rtex->surface.bpe;
                slice_size = (uint64_t)rtex->surface.u.legacy.level[0].slice_size_dw * 4;
        } else {
                /* Move a suballocated buffer into a non-suballocated allocation. */
@@ -532,11 +555,11 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,
                }
 
                /* Buffers */
-               offset = 0;
-               stride = 0;
                slice_size = 0;
        }
 
+       r600_texture_get_info(screen, resource, &stride, &offset);
+
        if (res->b.is_shared) {
                /* USAGE_EXPLICIT_FLUSH must be cleared if at least one user
                 * doesn't set it.
@@ -1957,6 +1980,7 @@ void r600_init_screen_texture_functions(struct r600_common_screen *rscreen)
 {
        rscreen->b.resource_from_handle = r600_texture_from_handle;
        rscreen->b.resource_get_handle = r600_texture_get_handle;
+       rscreen->b.resource_get_info = r600_texture_get_info;
        rscreen->b.resource_from_memobj = r600_texture_from_memobj;
        rscreen->b.memobj_create_from_handle = r600_memobj_from_handle;
        rscreen->b.memobj_destroy = r600_memobj_destroy;