Mesa (master): virgl: move virgl_resource_layout to common code

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 19 12:34:10 UTC 2018


Module: Mesa
Branch: master
Commit: f749229a8e16df4e88e2a1d30895f7741b91f1fd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f749229a8e16df4e88e2a1d30895f7741b91f1fd

Author: Gurchetan Singh <gurchetansingh at chromium.org>
Date:   Fri Nov  9 16:27:32 2018 -0800

virgl: move virgl_resource_layout to common code

Will be reused.

Reviewed-by: Elie Tournier <elie.tournier at collabora.com>

---

 src/gallium/drivers/virgl/virgl_resource.c | 37 +++++++++++++++++++++
 src/gallium/drivers/virgl/virgl_resource.h |  4 +++
 src/gallium/drivers/virgl/virgl_texture.c  | 52 ++++++------------------------
 3 files changed, 51 insertions(+), 42 deletions(-)

diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c
index 9174ec5cbb..4608ad0361 100644
--- a/src/gallium/drivers/virgl/virgl_resource.c
+++ b/src/gallium/drivers/virgl/virgl_resource.c
@@ -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;
+}
diff --git a/src/gallium/drivers/virgl/virgl_resource.h b/src/gallium/drivers/virgl/virgl_resource.h
index 100e35922c..df53465251 100644
--- a/src/gallium/drivers/virgl/virgl_resource.h
+++ b/src/gallium/drivers/virgl/virgl_resource.h
@@ -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
diff --git a/src/gallium/drivers/virgl/virgl_texture.c b/src/gallium/drivers/virgl/virgl_texture.c
index 4d08da548c..7eba476ff3 100644
--- a/src/gallium/drivers/virgl/virgl_texture.c
+++ b/src/gallium/drivers/virgl/virgl_texture.c
@@ -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;




More information about the mesa-commit mailing list