diff options
author | Gurchetan Singh <[email protected]> | 2019-09-25 10:33:16 -0700 |
---|---|---|
committer | Gurchetan Singh <[email protected]> | 2019-10-02 17:57:53 -0700 |
commit | 9bde8f3a8fcb6c3e0bf1fe4b87155161b85cf9b6 (patch) | |
tree | cdebd17367500265c026090d3bc42854100ab039 /src/gallium | |
parent | aad4127c41b70981f5c8a5aad6e3d7922a812ccb (diff) |
virgl: modify internal structures to track winsys-supplied data
The winsys might supply dimensions that are different than
those we calculate. In additional, it may supply virtualized
modifiers.
In practice, a stride != bpp * width and virtualized modifiers don't
happen yet, but the plan is to move in that direction.
Also make virgl_resource_layout static.
Reviewed by: Robert Tarasov <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/drivers/virgl/virgl_resource.c | 89 | ||||
-rw-r--r-- | src/gallium/drivers/virgl/virgl_resource.h | 6 |
2 files changed, 52 insertions, 43 deletions
diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c index 530f8e57fe7..fa0eb708438 100644 --- a/src/gallium/drivers/virgl/virgl_resource.c +++ b/src/gallium/drivers/virgl/virgl_resource.c @@ -453,6 +453,51 @@ virgl_resource_transfer_map(struct pipe_context *ctx, return map_addr; } +static void virgl_resource_layout(struct pipe_resource *pt, + struct virgl_resource_metadata *metadata, + uint32_t plane, + uint32_t winsys_stride, + uint32_t plane_offset, + uint32_t modifier) +{ + unsigned level, nblocksy; + 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; + + nblocksy = util_format_get_nblocksy(pt->format, height); + metadata->stride[level] = winsys_stride ? winsys_stride : + util_format_get_stride(pt->format, width); + metadata->layer_stride[level] = nblocksy * metadata->stride[level]; + metadata->level_offset[level] = buffer_size; + + buffer_size += slices * metadata->layer_stride[level]; + + width = u_minify(width, 1); + height = u_minify(height, 1); + depth = u_minify(depth, 1); + } + + metadata->plane = plane; + metadata->plane_offset = plane_offset; + metadata->modifier = modifier; + if (pt->nr_samples <= 1) + metadata->total_size = buffer_size; + else /* don't create guest backing store for MSAA */ + metadata->total_size = 0; +} + static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen, const struct pipe_resource *templ) { @@ -464,7 +509,7 @@ static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen, res->u.b.screen = &vs->base; pipe_reference_init(&res->u.b.reference, 1); vbind = pipe_to_virgl_bind(vs, templ->bind, templ->flags); - virgl_resource_layout(&res->u.b, &res->metadata); + virgl_resource_layout(&res->u.b, &res->metadata, 0, 0, 0, 0); if ((vs->caps.caps.v2.capability_bits & VIRGL_CAP_APP_TWEAK_SUPPORT) && vs->tweak_gles_emulate_bgra && @@ -517,7 +562,6 @@ static struct pipe_resource *virgl_resource_from_handle(struct pipe_screen *scre res->u.b = *templ; res->u.b.screen = &vs->base; pipe_reference_init(&res->u.b.reference, 1); - virgl_resource_layout(&res->u.b, &res->metadata); plane = winsys_stride = plane_offset = modifier = 0; res->hw_res = vs->vws->resource_create_from_handle(vs->vws, whandle, @@ -525,6 +569,9 @@ static struct pipe_resource *virgl_resource_from_handle(struct pipe_screen *scre &winsys_stride, &plane_offset, &modifier); + + virgl_resource_layout(&res->u.b, &res->metadata, plane, winsys_stride, + plane_offset, modifier); if (!res->hw_res) { FREE(res); return NULL; @@ -577,42 +624,6 @@ void virgl_init_context_resource_functions(struct pipe_context *ctx) ctx->texture_subdata = u_default_texture_subdata; } -void virgl_resource_layout(struct pipe_resource *pt, - struct virgl_resource_metadata *metadata) -{ - unsigned level, nblocksy; - 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; - - nblocksy = util_format_get_nblocksy(pt->format, height); - metadata->stride[level] = util_format_get_stride(pt->format, width); - metadata->layer_stride[level] = nblocksy * metadata->stride[level]; - metadata->level_offset[level] = buffer_size; - - buffer_size += slices * metadata->layer_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; -} struct virgl_transfer * virgl_resource_create_transfer(struct virgl_context *vctx, @@ -627,7 +638,7 @@ virgl_resource_create_transfer(struct virgl_context *vctx, const unsigned blocksy = box->y / util_format_get_blockheight(format); const unsigned blocksx = box->x / util_format_get_blockwidth(format); - unsigned offset = metadata->level_offset[level]; + unsigned offset = metadata->plane_offset + metadata->level_offset[level]; if (pres->target == PIPE_TEXTURE_CUBE || pres->target == PIPE_TEXTURE_CUBE_ARRAY || pres->target == PIPE_TEXTURE_3D || diff --git a/src/gallium/drivers/virgl/virgl_resource.h b/src/gallium/drivers/virgl/virgl_resource.h index 2151f36cf1c..f17dac72a0e 100644 --- a/src/gallium/drivers/virgl/virgl_resource.h +++ b/src/gallium/drivers/virgl/virgl_resource.h @@ -42,7 +42,8 @@ struct virgl_resource_metadata unsigned long level_offset[VR_MAX_TEXTURE_2D_LEVELS]; unsigned stride[VR_MAX_TEXTURE_2D_LEVELS]; unsigned layer_stride[VR_MAX_TEXTURE_2D_LEVELS]; - uint32_t total_size; + uint32_t plane, plane_offset, total_size; + uint64_t modifier; }; struct virgl_resource { @@ -155,9 +156,6 @@ virgl_resource_transfer_map(struct pipe_context *ctx, const struct pipe_box *box, struct pipe_transfer **transfer); -void virgl_resource_layout(struct pipe_resource *pt, - struct virgl_resource_metadata *metadata); - struct virgl_transfer * virgl_resource_create_transfer(struct virgl_context *vctx, struct pipe_resource *pres, |