diff options
author | Gurchetan Singh <[email protected]> | 2018-11-09 16:27:32 -0800 |
---|---|---|
committer | Bas Nieuwenhuizen <[email protected]> | 2018-12-19 13:29:16 +0100 |
commit | f749229a8e16df4e88e2a1d30895f7741b91f1fd (patch) | |
tree | 97da1df607c9f46a954edb9b8c7f1fef198f6eb3 /src/gallium/drivers | |
parent | a63da9c062bd925482250cd0939aa377f53730a2 (diff) |
virgl: move virgl_resource_layout to common code
Will be reused.
Reviewed-by: Elie Tournier <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r-- | src/gallium/drivers/virgl/virgl_resource.c | 37 | ||||
-rw-r--r-- | src/gallium/drivers/virgl/virgl_resource.h | 4 | ||||
-rw-r--r-- | 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 9174ec5cbbd..4608ad0361c 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 100e35922c8..df534652518 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 4d08da548cb..7eba476ff3a 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; |