From 1d3d311133f1f6aa3402e7b516646f71ec760b74 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Fri, 30 Nov 2018 20:45:44 -0800 Subject: [PATCH] virgl: move resource metadata into base resource A resource is just a buffer with some metadata. Reviewed-by: Elie Tournier --- src/gallium/drivers/virgl/virgl_buffer.c | 51 +++++++------ src/gallium/drivers/virgl/virgl_context.c | 5 +- src/gallium/drivers/virgl/virgl_resource.h | 21 +----- src/gallium/drivers/virgl/virgl_texture.c | 85 +++++++++++----------- 4 files changed, 71 insertions(+), 91 deletions(-) diff --git a/src/gallium/drivers/virgl/virgl_buffer.c b/src/gallium/drivers/virgl/virgl_buffer.c index bdbb3517826..c0f2afe3fb0 100644 --- a/src/gallium/drivers/virgl/virgl_buffer.c +++ b/src/gallium/drivers/virgl/virgl_buffer.c @@ -31,9 +31,9 @@ static void virgl_buffer_destroy(struct pipe_screen *screen, struct pipe_resource *buf) { struct virgl_screen *vs = virgl_screen(screen); - struct virgl_buffer *vbuf = virgl_buffer(buf); + struct virgl_resource *vbuf = virgl_resource(buf); - vs->vws->resource_unref(vs->vws, vbuf->base.hw_res); + vs->vws->resource_unref(vs->vws, vbuf->hw_res); FREE(vbuf); } @@ -46,7 +46,7 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx, { struct virgl_context *vctx = virgl_context(ctx); struct virgl_screen *vs = virgl_screen(ctx->screen); - struct virgl_buffer *vbuf = virgl_buffer(resource); + struct virgl_resource *vbuf = virgl_resource(resource); struct virgl_transfer *trans; void *ptr; bool readback; @@ -55,7 +55,7 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx, if (usage & PIPE_TRANSFER_READ) doflushwait = true; else - doflushwait = virgl_res_needs_flush_wait(vctx, &vbuf->base, usage); + doflushwait = virgl_res_needs_flush_wait(vctx, vbuf, usage); if (doflushwait) ctx->flush(ctx, NULL, 0); @@ -63,18 +63,18 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx, trans = virgl_resource_create_transfer(ctx, resource, &vbuf->metadata, level, usage, box); - readback = virgl_res_needs_readback(vctx, &vbuf->base, usage); + readback = virgl_res_needs_readback(vctx, vbuf, usage); if (readback) - vs->vws->transfer_get(vs->vws, vbuf->base.hw_res, box, trans->base.stride, + vs->vws->transfer_get(vs->vws, vbuf->hw_res, box, trans->base.stride, trans->l_stride, trans->offset, level); if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) doflushwait = true; if (doflushwait || readback) - vs->vws->resource_wait(vs->vws, vbuf->base.hw_res); + vs->vws->resource_wait(vs->vws, vbuf->hw_res); - ptr = vs->vws->resource_map(vs->vws, vbuf->base.hw_res); + ptr = vs->vws->resource_map(vs->vws, vbuf->hw_res); if (!ptr) { return NULL; } @@ -88,7 +88,7 @@ static void virgl_buffer_transfer_unmap(struct pipe_context *ctx, { struct virgl_context *vctx = virgl_context(ctx); struct virgl_transfer *trans = virgl_transfer(transfer); - struct virgl_buffer *vbuf = virgl_buffer(transfer->resource); + struct virgl_resource *vbuf = virgl_resource(transfer->resource); if (trans->base.usage & PIPE_TRANSFER_WRITE) { struct virgl_screen *vs = virgl_screen(ctx->screen); @@ -99,7 +99,7 @@ static void virgl_buffer_transfer_unmap(struct pipe_context *ctx, } vctx->num_transfers++; - vs->vws->transfer_put(vs->vws, vbuf->base.hw_res, + vs->vws->transfer_put(vs->vws, vbuf->hw_res, &transfer->box, trans->base.stride, trans->l_stride, trans->offset, transfer->level); @@ -113,7 +113,7 @@ static void virgl_buffer_transfer_flush_region(struct pipe_context *ctx, struct pipe_transfer *transfer, const struct pipe_box *box) { - struct virgl_buffer *vbuf = virgl_buffer(transfer->resource); + struct virgl_resource *vbuf = virgl_resource(transfer->resource); struct virgl_transfer *trans = virgl_transfer(transfer); /* @@ -126,7 +126,7 @@ static void virgl_buffer_transfer_flush_region(struct pipe_context *ctx, * We'll end up flushing 25 --> 70. */ util_range_add(&trans->range, box->x, box->x + box->width); - vbuf->base.clean = FALSE; + vbuf->clean = FALSE; } static const struct u_resource_vtbl virgl_buffer_vtbl = @@ -141,22 +141,21 @@ static const struct u_resource_vtbl virgl_buffer_vtbl = struct pipe_resource *virgl_buffer_create(struct virgl_screen *vs, const struct pipe_resource *template) { - struct virgl_buffer *buf; + struct virgl_resource *buf; uint32_t vbind; - buf = CALLOC_STRUCT(virgl_buffer); - buf->base.clean = TRUE; - buf->base.u.b = *template; - buf->base.u.b.screen = &vs->base; - buf->base.u.vtbl = &virgl_buffer_vtbl; - pipe_reference_init(&buf->base.u.b.reference, 1); - virgl_resource_layout(&buf->base.u.b, &buf->metadata); + buf = CALLOC_STRUCT(virgl_resource); + buf->clean = TRUE; + buf->u.b = *template; + buf->u.b.screen = &vs->base; + buf->u.vtbl = &virgl_buffer_vtbl; + pipe_reference_init(&buf->u.b.reference, 1); + virgl_resource_layout(&buf->u.b, &buf->metadata); vbind = pipe_to_virgl_bind(template->bind); - buf->base.hw_res = vs->vws->resource_create(vs->vws, template->target, - template->format, vbind, - template->width0, 1, 1, 1, 0, 0, - buf->metadata.total_size); - - return &buf->base.u.b; + buf->hw_res = vs->vws->resource_create(vs->vws, template->target, + template->format, vbind, + template->width0, 1, 1, 1, 0, 0, + buf->metadata.total_size); + return &buf->u.b; } diff --git a/src/gallium/drivers/virgl/virgl_context.c b/src/gallium/drivers/virgl/virgl_context.c index bafec289cc7..f095920489f 100644 --- a/src/gallium/drivers/virgl/virgl_context.c +++ b/src/gallium/drivers/virgl/virgl_context.c @@ -506,14 +506,13 @@ void virgl_transfer_inline_write(struct pipe_context *ctx, struct virgl_context *vctx = virgl_context(ctx); struct virgl_screen *vs = virgl_screen(ctx->screen); struct virgl_resource *grres = virgl_resource(res); - struct virgl_buffer *vbuf = virgl_buffer(res); grres->clean = FALSE; - if (virgl_res_needs_flush_wait(vctx, &vbuf->base, usage)) { + if (virgl_res_needs_flush_wait(vctx, grres, usage)) { ctx->flush(ctx, NULL, 0); - vs->vws->resource_wait(vs->vws, vbuf->base.hw_res); + vs->vws->resource_wait(vs->vws, grres->hw_res); } virgl_encoder_inline_write(vctx, grres, level, usage, diff --git a/src/gallium/drivers/virgl/virgl_resource.h b/src/gallium/drivers/virgl/virgl_resource.h index 6b76bc26d32..28b12c317f6 100644 --- a/src/gallium/drivers/virgl/virgl_resource.h +++ b/src/gallium/drivers/virgl/virgl_resource.h @@ -46,17 +46,8 @@ struct virgl_resource_metadata struct virgl_resource { struct u_resource u; - struct virgl_hw_res *hw_res; boolean clean; -}; - -struct virgl_buffer { - struct virgl_resource base; - struct virgl_resource_metadata metadata; -}; - -struct virgl_texture { - struct virgl_resource base; + struct virgl_hw_res *hw_res; struct virgl_resource_metadata metadata; }; @@ -86,16 +77,6 @@ static inline struct virgl_resource *virgl_resource(struct pipe_resource *r) return (struct virgl_resource *)r; } -static inline struct virgl_buffer *virgl_buffer(struct pipe_resource *r) -{ - return (struct virgl_buffer *)r; -} - -static inline struct virgl_texture *virgl_texture(struct pipe_resource *r) -{ - return (struct virgl_texture *)r; -} - static inline struct virgl_transfer *virgl_transfer(struct pipe_transfer *trans) { return (struct virgl_transfer *)trans; diff --git a/src/gallium/drivers/virgl/virgl_texture.c b/src/gallium/drivers/virgl/virgl_texture.c index 80094fb6ee7..d79ae4d3d09 100644 --- a/src/gallium/drivers/virgl/virgl_texture.c +++ b/src/gallium/drivers/virgl/virgl_texture.c @@ -103,19 +103,19 @@ static void *virgl_texture_transfer_map(struct pipe_context *ctx, { struct virgl_context *vctx = virgl_context(ctx); struct virgl_screen *vs = virgl_screen(ctx->screen); - struct virgl_texture *vtex = virgl_texture(resource); + struct virgl_resource *vtex = virgl_resource(resource); struct virgl_transfer *trans; void *ptr; boolean readback = TRUE; struct virgl_hw_res *hw_res; bool doflushwait; - doflushwait = virgl_res_needs_flush_wait(vctx, &vtex->base, usage); + doflushwait = virgl_res_needs_flush_wait(vctx, vtex, usage); if (doflushwait) ctx->flush(ctx, NULL, 0); - trans = virgl_resource_create_transfer(ctx, resource, &vtex->metadata, level, - usage, box); + trans = virgl_resource_create_transfer(ctx, resource, &vtex->metadata, + level, usage, box); if (resource->nr_samples > 1) { struct pipe_resource tmp_resource; @@ -128,22 +128,22 @@ static void *virgl_texture_transfer_map(struct pipe_context *ctx, ctx->flush(ctx, NULL, 0); /* we want to do a resolve blit into the temporary */ hw_res = trans->resolve_tmp->hw_res; - struct virgl_resource_metadata *data = &((struct virgl_texture*)trans->resolve_tmp)->metadata; + struct virgl_resource_metadata *data = &trans->resolve_tmp->metadata; trans->base.stride = data->stride[level]; trans->base.layer_stride = data->layer_stride[level]; trans->offset = 0; } else { - hw_res = vtex->base.hw_res; + hw_res = vtex->hw_res; trans->resolve_tmp = NULL; } - readback = virgl_res_needs_readback(vctx, &vtex->base, usage); + readback = virgl_res_needs_readback(vctx, vtex, usage); if (readback) vs->vws->transfer_get(vs->vws, hw_res, box, trans->base.stride, trans->l_stride, trans->offset, level); if (doflushwait || readback) - vs->vws->resource_wait(vs->vws, vtex->base.hw_res); + vs->vws->resource_wait(vs->vws, vtex->hw_res); ptr = vs->vws->resource_map(vs->vws, hw_res); if (!ptr) { @@ -160,14 +160,14 @@ static void virgl_texture_transfer_unmap(struct pipe_context *ctx, { struct virgl_context *vctx = virgl_context(ctx); struct virgl_transfer *trans = virgl_transfer(transfer); - struct virgl_texture *vtex = virgl_texture(transfer->resource); + struct virgl_resource *vtex = virgl_resource(transfer->resource); if (trans->base.usage & PIPE_TRANSFER_WRITE) { if (!(transfer->usage & PIPE_TRANSFER_FLUSH_EXPLICIT)) { struct virgl_screen *vs = virgl_screen(ctx->screen); - vtex->base.clean = FALSE; + vtex->clean = FALSE; vctx->num_transfers++; - vs->vws->transfer_put(vs->vws, vtex->base.hw_res, + vs->vws->transfer_put(vs->vws, vtex->hw_res, &transfer->box, trans->base.stride, trans->l_stride, trans->offset, transfer->level); @@ -186,18 +186,19 @@ static boolean virgl_texture_get_handle(struct pipe_screen *screen, struct winsys_handle *whandle) { struct virgl_screen *vs = virgl_screen(screen); - struct virgl_texture *vtex = virgl_texture(ptex); + struct virgl_resource *vtex = virgl_resource(ptex); - return vs->vws->resource_get_handle(vs->vws, vtex->base.hw_res, - vtex->metadata.stride[0], whandle); + return vs->vws->resource_get_handle(vs->vws, vtex->hw_res, + vtex->metadata.stride[0], + whandle); } static void virgl_texture_destroy(struct pipe_screen *screen, struct pipe_resource *res) { struct virgl_screen *vs = virgl_screen(screen); - struct virgl_texture *vtex = virgl_texture(res); - vs->vws->resource_unref(vs->vws, vtex->base.hw_res); + struct virgl_resource *vtex = virgl_resource(res); + vs->vws->resource_unref(vs->vws, vtex->hw_res); FREE(vtex); } @@ -215,43 +216,43 @@ virgl_texture_from_handle(struct virgl_screen *vs, const struct pipe_resource *template, struct winsys_handle *whandle) { - struct virgl_texture *tex = CALLOC_STRUCT(virgl_texture); - tex->base.u.b = *template; - tex->base.u.b.screen = &vs->base; - pipe_reference_init(&tex->base.u.b.reference, 1); - tex->base.u.vtbl = &virgl_texture_vtbl; + struct virgl_resource *tex = CALLOC_STRUCT(virgl_resource); + tex->u.b = *template; + tex->u.b.screen = &vs->base; + pipe_reference_init(&tex->u.b.reference, 1); + tex->u.vtbl = &virgl_texture_vtbl; - tex->base.hw_res = vs->vws->resource_create_from_handle(vs->vws, whandle); - return &tex->base.u.b; + tex->hw_res = vs->vws->resource_create_from_handle(vs->vws, whandle); + return &tex->u.b; } struct pipe_resource *virgl_texture_create(struct virgl_screen *vs, const struct pipe_resource *template) { - struct virgl_texture *tex; + struct virgl_resource *tex; unsigned vbind; - tex = CALLOC_STRUCT(virgl_texture); - tex->base.clean = TRUE; - tex->base.u.b = *template; - tex->base.u.b.screen = &vs->base; - pipe_reference_init(&tex->base.u.b.reference, 1); - tex->base.u.vtbl = &virgl_texture_vtbl; - virgl_resource_layout(&tex->base.u.b, &tex->metadata); + tex = CALLOC_STRUCT(virgl_resource); + tex->clean = TRUE; + tex->u.b = *template; + tex->u.b.screen = &vs->base; + pipe_reference_init(&tex->u.b.reference, 1); + tex->u.vtbl = &virgl_texture_vtbl; + virgl_resource_layout(&tex->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, - tex->metadata.total_size); - if (!tex->base.hw_res) { + tex->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->hw_res) { FREE(tex); return NULL; } - return &tex->base.u.b; + return &tex->u.b; } -- 2.30.2