virgl: move virgl_resource_layout to common code
authorGurchetan Singh <gurchetansingh@chromium.org>
Sat, 10 Nov 2018 00:27:32 +0000 (16:27 -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 9174ec5cbbd0f45d73e83a3ed093af3d62e2fab3..4608ad0361c609000fcc2f61fd65ef395659fdf8 100644 (file)
@@ -20,6 +20,7 @@
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
+#include "util/u_format.h"
 #include "util/u_inlines.h"
 #include "virgl_context.h"
 #include "virgl_resource.h"
@@ -110,3 +111,39 @@ void virgl_init_context_resource_functions(struct pipe_context *ctx)
     ctx->buffer_subdata = virgl_buffer_subdata;
     ctx->texture_subdata = u_default_texture_subdata;
 }
+
+void virgl_resource_layout(struct pipe_resource *pt,
+                           struct virgl_resource_metadata *metadata)
+{
+   unsigned level;
+   unsigned width = pt->width0;
+   unsigned height = pt->height0;
+   unsigned depth = pt->depth0;
+   unsigned buffer_size = 0;
+
+   for (level = 0; level <= pt->last_level; level++) {
+      unsigned slices;
+
+      if (pt->target == PIPE_TEXTURE_CUBE)
+         slices = 6;
+      else if (pt->target == PIPE_TEXTURE_3D)
+         slices = depth;
+      else
+         slices = pt->array_size;
+
+      metadata->stride[level] = util_format_get_stride(pt->format, width);
+      metadata->level_offset[level] = buffer_size;
+
+      buffer_size += (util_format_get_nblocksy(pt->format, height) *
+                      slices * metadata->stride[level]);
+
+      width = u_minify(width, 1);
+      height = u_minify(height, 1);
+      depth = u_minify(depth, 1);
+   }
+
+   if (pt->nr_samples <= 1)
+      metadata->total_size = buffer_size;
+   else /* don't create guest backing store for MSAA */
+      metadata->total_size = 0;
+}
index 100e35922c896f06db1f1f88b3c5363a25f84db0..df534652518a1df8b0abdd9e63acc75d85bc1326 100644 (file)
@@ -150,4 +150,8 @@ bool virgl_res_needs_flush_wait(struct virgl_context *vctx,
 bool virgl_res_needs_readback(struct virgl_context *vctx,
                               struct virgl_resource *res,
                               unsigned usage);
+
+void virgl_resource_layout(struct pipe_resource *pt,
+                           struct virgl_resource_metadata *metadata);
+
 #endif
index 4d08da548cb34cdd686c080939a4753335fa7748..7eba476ff3a3b086f6751bb204b97f21f334e698 100644 (file)
@@ -240,45 +240,6 @@ static void virgl_texture_transfer_unmap(struct pipe_context *ctx,
    slab_free(&vctx->transfer_pool, trans);
 }
 
-
-static void
-vrend_resource_layout(struct virgl_texture *res,
-                      uint32_t *total_size)
-{
-   struct pipe_resource *pt = &res->base.u.b;
-   unsigned level;
-   unsigned width = pt->width0;
-   unsigned height = pt->height0;
-   unsigned depth = pt->depth0;
-   unsigned buffer_size = 0;
-
-   for (level = 0; level <= pt->last_level; level++) {
-      unsigned slices;
-
-      if (pt->target == PIPE_TEXTURE_CUBE)
-         slices = 6;
-      else if (pt->target == PIPE_TEXTURE_3D)
-         slices = depth;
-      else
-         slices = pt->array_size;
-
-      res->metadata.stride[level] = util_format_get_stride(pt->format, width);
-      res->metadata.level_offset[level] = buffer_size;
-
-      buffer_size += (util_format_get_nblocksy(pt->format, height) *
-                      slices * res->metadata.stride[level]);
-
-      width = u_minify(width, 1);
-      height = u_minify(height, 1);
-      depth = u_minify(depth, 1);
-   }
-
-   if (pt->nr_samples <= 1)
-      *total_size = buffer_size;
-   else /* don't create guest backing store for MSAA */
-      *total_size = 0;
-}
-
 static boolean virgl_texture_get_handle(struct pipe_screen *screen,
                                          struct pipe_resource *ptex,
                                          struct winsys_handle *whandle)
@@ -327,7 +288,6 @@ struct pipe_resource *virgl_texture_create(struct virgl_screen *vs,
                                            const struct pipe_resource *template)
 {
    struct virgl_texture *tex;
-   uint32_t size;
    unsigned vbind;
 
    tex = CALLOC_STRUCT(virgl_texture);
@@ -336,10 +296,18 @@ struct pipe_resource *virgl_texture_create(struct virgl_screen *vs,
    tex->base.u.b.screen = &vs->base;
    pipe_reference_init(&tex->base.u.b.reference, 1);
    tex->base.u.vtbl = &virgl_texture_vtbl;
-   vrend_resource_layout(tex, &size);
+   virgl_resource_layout(&tex->base.u.b, &tex->metadata);
 
    vbind = pipe_to_virgl_bind(template->bind);
-   tex->base.hw_res = vs->vws->resource_create(vs->vws, template->target, template->format, vbind, template->width0, template->height0, template->depth0, template->array_size, template->last_level, template->nr_samples, size);
+   tex->base.hw_res = vs->vws->resource_create(vs->vws, template->target,
+                                               template->format, vbind,
+                                               template->width0,
+                                               template->height0,
+                                               template->depth0,
+                                               template->array_size,
+                                               template->last_level,
+                                               template->nr_samples,
+                                               tex->metadata.total_size);
    if (!tex->base.hw_res) {
       FREE(tex);
       return NULL;