A resource is just a buffer with some metadata.
Reviewed-by: Elie Tournier <elie.tournier@collabora.com>
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);
}
{
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;
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);
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;
}
{
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);
}
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);
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);
/*
* 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 =
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;
}
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,
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;
};
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;
{
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;
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) {
{
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);
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);
}
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;
}