virgl: move vrend_get_tex_image_offset to common code
authorGurchetan Singh <gurchetansingh@chromium.org>
Sat, 10 Nov 2018 00:40:03 +0000 (16:40 -0800)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Wed, 19 Dec 2018 12:29:16 +0000 (13:29 +0100)
Will be reused.

Reviewed-by: Elie Tournier <elie.tournier@collabora.com>
src/gallium/drivers/virgl/virgl_resource.c
src/gallium/drivers/virgl/virgl_resource.h
src/gallium/drivers/virgl/virgl_texture.c

index 4608ad0361c609000fcc2f61fd65ef395659fdf8..b252be1ba33c6b4f04dc971a63fad975d0e3c5f8 100644 (file)
@@ -147,3 +147,27 @@ void virgl_resource_layout(struct pipe_resource *pt,
    else /* don't create guest backing store for MSAA */
       metadata->total_size = 0;
 }
+
+unsigned virgl_resource_offset(struct pipe_resource *pres,
+                               struct virgl_resource_metadata *metadata,
+                               unsigned level, unsigned layer)
+{
+   const unsigned hgt = u_minify(pres->height0, level);
+   const unsigned nblocksy = util_format_get_nblocksy(pres->format, hgt);
+   unsigned offset = metadata->level_offset[level];
+
+   if (pres->target == PIPE_TEXTURE_CUBE ||
+       pres->target == PIPE_TEXTURE_CUBE_ARRAY ||
+       pres->target == PIPE_TEXTURE_3D ||
+       pres->target == PIPE_TEXTURE_2D_ARRAY) {
+      offset += layer * nblocksy * metadata->stride[level];
+   }
+   else if (pres->target == PIPE_TEXTURE_1D_ARRAY) {
+      offset += layer * metadata->stride[level];
+   }
+   else {
+      assert(layer == 0);
+   }
+
+   return offset;
+}
index df534652518a1df8b0abdd9e63acc75d85bc1326..1a43e5ddc5d8824dbb49f604fc25b280c3a692c1 100644 (file)
@@ -154,4 +154,7 @@ bool virgl_res_needs_readback(struct virgl_context *vctx,
 void virgl_resource_layout(struct pipe_resource *pt,
                            struct virgl_resource_metadata *metadata);
 
+unsigned virgl_resource_offset(struct pipe_resource *pres,
+                               struct virgl_resource_metadata *metadata,
+                               unsigned level, unsigned layer);
 #endif
index 7eba476ff3a3b086f6751bb204b97f21f334e698..c9d8e541f7ddc58c1fdb1a3b7e0817ddb173e224 100644 (file)
@@ -94,31 +94,6 @@ static void virgl_init_temp_resource_from_box(struct pipe_resource *res,
    }
 }
 
-static unsigned
-vrend_get_tex_image_offset(const struct virgl_texture *res,
-                           unsigned level, unsigned layer)
-{
-   const struct pipe_resource *pres = &res->base.u.b;
-   const unsigned hgt = u_minify(pres->height0, level);
-   const unsigned nblocksy = util_format_get_nblocksy(pres->format, hgt);
-   unsigned offset = res->metadata.level_offset[level];
-
-   if (pres->target == PIPE_TEXTURE_CUBE ||
-       pres->target == PIPE_TEXTURE_CUBE_ARRAY ||
-       pres->target == PIPE_TEXTURE_3D ||
-       pres->target == PIPE_TEXTURE_2D_ARRAY) {
-      offset += layer * nblocksy * res->metadata.stride[level];
-   }
-   else if (pres->target == PIPE_TEXTURE_1D_ARRAY) {
-      offset += layer * res->metadata.stride[level];
-   }
-   else {
-      assert(layer == 0);
-   }
-
-   return offset;
-}
-
 static void *virgl_texture_transfer_map(struct pipe_context *ctx,
                                         struct pipe_resource *resource,
                                         unsigned level,
@@ -179,7 +154,7 @@ static void *virgl_texture_transfer_map(struct pipe_context *ctx,
       trans->base.stride = ((struct virgl_texture*)trans->resolve_tmp)->metadata.stride[level];
       trans->base.layer_stride = trans->base.stride * nblocksy;
    } else {
-      offset = vrend_get_tex_image_offset(vtex, level, box->z);
+      offset = virgl_resource_offset(&vtex->base.u.b, &vtex->metadata, level, box->z);
 
       offset += box->y / util_format_get_blockheight(format) * trans->base.stride +
       box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);