This should save some space.
Suggested-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
struct virgl_transfer *trans;
void *ptr;
bool readback;
- bool doflushwait = false;
+ bool flush = false;
trans = virgl_resource_create_transfer(&vctx->transfer_pool, resource,
&vbuf->metadata, level, usage, box);
if (usage & PIPE_TRANSFER_READ)
- doflushwait = true;
+ flush = true;
else
- doflushwait = virgl_res_needs_flush_wait(vctx, trans);
+ flush = virgl_res_needs_flush(vctx, trans);
- if (doflushwait)
+ if (flush)
ctx->flush(ctx, NULL, 0);
readback = virgl_res_needs_readback(vctx, vbuf, usage, 0);
- if (readback)
+ if (readback) {
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->hw_res);
+ }
ptr = vs->vws->resource_map(vs->vws, vbuf->hw_res);
if (!ptr) {
unsigned layer_stride)
{
struct virgl_context *vctx = virgl_context(ctx);
- struct virgl_screen *vs = virgl_screen(ctx->screen);
struct virgl_resource *grres = virgl_resource(res);
struct virgl_transfer trans = { 0 };
virgl_resource_dirty(grres, 0);
- if (virgl_res_needs_flush_wait(vctx, &trans)) {
+ if (virgl_res_needs_flush(vctx, &trans))
ctx->flush(ctx, NULL, 0);
- vs->vws->resource_wait(vs->vws, grres->hw_res);
- }
-
virgl_encoder_inline_write(vctx, grres, level, usage,
box, data, stride, layer_stride);
}
query->type = pipe_to_virgl_query(query_type);
query->index = index;
query->handle = handle;
- query->buf->clean[0] = FALSE;
+ query->buf->clean_mask &= ~1;
virgl_encoder_create_query(vctx, handle, query->type, index, query->buf, 0);
return (struct pipe_query *)query;
#include "virgl_resource.h"
#include "virgl_screen.h"
-bool virgl_res_needs_flush_wait(struct virgl_context *vctx,
- struct virgl_transfer *trans)
+bool virgl_res_needs_flush(struct virgl_context *vctx,
+ struct virgl_transfer *trans)
{
struct virgl_screen *vs = virgl_screen(vctx->base.screen);
struct virgl_resource *res = virgl_resource(trans->base.resource);
return false;
if (!vs->vws->res_is_referenced(vs->vws, vctx->cbuf, res->hw_res))
return false;
- if (res->clean[trans->base.level]) {
+ if (res->clean_mask & (1 << trans->base.level)) {
if (vctx->num_draws == 0 && vctx->num_compute == 0)
return false;
if (!virgl_transfer_queue_is_queued(&vctx->queue, trans))
unsigned usage, unsigned level)
{
bool readback = true;
- if (res->clean[level])
+ if (res->clean_mask & (1 << level))
readback = false;
else if (usage & PIPE_TRANSFER_DISCARD_RANGE)
readback = false;
return NULL;
}
- for (uint32_t i = 0; i < VR_MAX_TEXTURE_2D_LEVELS; i++)
- res->clean[i] = TRUE;
+ res->clean_mask = (1 << VR_MAX_TEXTURE_2D_LEVELS) - 1;
if (templ->target == PIPE_BUFFER)
virgl_buffer_init(res);
{
if (res) {
if (res->u.b.target == PIPE_BUFFER)
- res->clean[0] = FALSE;
+ res->clean_mask &= ~1;
else
- res->clean[level] = FALSE;
+ res->clean_mask &= ~(1 << level);
}
}
struct virgl_resource {
struct u_resource u;
- boolean clean[VR_MAX_TEXTURE_2D_LEVELS];
+ uint16_t clean_mask;
struct virgl_hw_res *hw_res;
struct virgl_resource_metadata metadata;
};
return outbind;
}
-bool virgl_res_needs_flush_wait(struct virgl_context *vctx,
- struct virgl_transfer *transfer);
+bool virgl_res_needs_flush(struct virgl_context *vctx,
+ struct virgl_transfer *transfer);
bool virgl_res_needs_readback(struct virgl_context *vctx,
struct virgl_resource *res,
unsigned usage, unsigned level);
void *ptr;
boolean readback = TRUE;
struct virgl_hw_res *hw_res;
- bool doflushwait;
+ bool flush;
trans = virgl_resource_create_transfer(&vctx->transfer_pool, resource,
&vtex->metadata, level, usage, box);
- doflushwait = virgl_res_needs_flush_wait(vctx, trans);
- if (doflushwait)
+ flush = virgl_res_needs_flush(vctx, trans);
+ if (flush)
ctx->flush(ctx, NULL, 0);
if (resource->nr_samples > 1) {
}
readback = virgl_res_needs_readback(vctx, vtex, usage, level);
- if (readback)
+ 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->hw_res);
+ }
ptr = vs->vws->resource_map(vs->vws, hw_res);
if (!ptr) {
res->size = size;
res->stride = stride;
pipe_reference_init(&res->reference, 1);
- res->num_cs_references = 0;
+ p_atomic_set(&res->num_cs_references, 0);
res->fence_fd = -1;
return res;
}
goto again;
}
-static struct virgl_cmd_buf *virgl_drm_cmd_buf_create(struct virgl_winsys *qws,
- uint32_t size)
-{
- struct virgl_drm_cmd_buf *cbuf;
-
- cbuf = CALLOC_STRUCT(virgl_drm_cmd_buf);
- if (!cbuf)
- return NULL;
-
- cbuf->ws = qws;
-
- cbuf->nres = 512;
- cbuf->res_bo = CALLOC(cbuf->nres, sizeof(struct virgl_hw_buf*));
- if (!cbuf->res_bo) {
- FREE(cbuf);
- return NULL;
- }
- cbuf->res_hlist = MALLOC(cbuf->nres * sizeof(uint32_t));
- if (!cbuf->res_hlist) {
- FREE(cbuf->res_bo);
- FREE(cbuf);
- return NULL;
- }
-
- cbuf->buf = CALLOC(size, sizeof(uint32_t));
- if (!cbuf->buf) {
- FREE(cbuf->res_hlist);
- FREE(cbuf->res_bo);
- FREE(cbuf);
- return NULL;
- }
-
- cbuf->base.buf = cbuf->buf;
- cbuf->base.in_fence_fd = -1;
- return &cbuf->base;
-}
-
-static void virgl_drm_cmd_buf_destroy(struct virgl_cmd_buf *_cbuf)
-{
- struct virgl_drm_cmd_buf *cbuf = virgl_drm_cmd_buf(_cbuf);
-
- FREE(cbuf->res_hlist);
- FREE(cbuf->res_bo);
- FREE(cbuf->buf);
- FREE(cbuf);
-
-}
-
static boolean virgl_drm_lookup_res(struct virgl_drm_cmd_buf *cbuf,
struct virgl_hw_res *res)
{
struct virgl_cmd_buf *_cbuf,
struct virgl_hw_res *res)
{
- if (!res->num_cs_references)
+ if (!p_atomic_read(&res->num_cs_references))
return FALSE;
return TRUE;
}
+static struct virgl_cmd_buf *virgl_drm_cmd_buf_create(struct virgl_winsys *qws,
+ uint32_t size)
+{
+ struct virgl_drm_cmd_buf *cbuf;
+
+ cbuf = CALLOC_STRUCT(virgl_drm_cmd_buf);
+ if (!cbuf)
+ return NULL;
+
+ cbuf->ws = qws;
+
+ cbuf->nres = 512;
+ cbuf->res_bo = CALLOC(cbuf->nres, sizeof(struct virgl_hw_buf*));
+ if (!cbuf->res_bo) {
+ FREE(cbuf);
+ return NULL;
+ }
+ cbuf->res_hlist = MALLOC(cbuf->nres * sizeof(uint32_t));
+ if (!cbuf->res_hlist) {
+ FREE(cbuf->res_bo);
+ FREE(cbuf);
+ return NULL;
+ }
+
+ cbuf->buf = CALLOC(size, sizeof(uint32_t));
+ if (!cbuf->buf) {
+ FREE(cbuf->res_hlist);
+ FREE(cbuf->res_bo);
+ FREE(cbuf);
+ return NULL;
+ }
+
+ cbuf->base.buf = cbuf->buf;
+ cbuf->base.in_fence_fd = -1;
+ return &cbuf->base;
+}
+
+static void virgl_drm_cmd_buf_destroy(struct virgl_cmd_buf *_cbuf)
+{
+ struct virgl_drm_cmd_buf *cbuf = virgl_drm_cmd_buf(_cbuf);
+
+ virgl_drm_release_all_res(virgl_drm_winsys(cbuf->ws), cbuf);
+ FREE(cbuf->res_hlist);
+ FREE(cbuf->res_bo);
+ FREE(cbuf->buf);
+ FREE(cbuf);
+
+}
+
static int virgl_drm_winsys_submit_cmd(struct virgl_winsys *qws,
struct virgl_cmd_buf *_cbuf,
int in_fence_fd, int *out_fence_fd)
res->res_handle = handle++;
pipe_reference_init(&res->reference, 1);
+ p_atomic_set(&res->num_cs_references, 0);
return res;
}
return res;
}
-static struct virgl_cmd_buf *virgl_vtest_cmd_buf_create(struct virgl_winsys *vws,
- uint32_t size)
-{
- struct virgl_vtest_cmd_buf *cbuf;
-
- cbuf = CALLOC_STRUCT(virgl_vtest_cmd_buf);
- if (!cbuf)
- return NULL;
-
- cbuf->nres = 512;
- cbuf->res_bo = CALLOC(cbuf->nres, sizeof(struct virgl_hw_buf*));
- if (!cbuf->res_bo) {
- FREE(cbuf);
- return NULL;
- }
- cbuf->ws = vws;
- cbuf->base.buf = cbuf->buf;
- cbuf->base.in_fence_fd = -1;
- return &cbuf->base;
-}
-
-static void virgl_vtest_cmd_buf_destroy(struct virgl_cmd_buf *_cbuf)
-{
- struct virgl_vtest_cmd_buf *cbuf = virgl_vtest_cmd_buf(_cbuf);
-
- FREE(cbuf->res_bo);
- FREE(cbuf);
-}
-
static boolean virgl_vtest_lookup_res(struct virgl_vtest_cmd_buf *cbuf,
struct virgl_hw_res *res)
{
cbuf->cres++;
}
+static struct virgl_cmd_buf *virgl_vtest_cmd_buf_create(struct virgl_winsys *vws,
+ uint32_t size)
+{
+ struct virgl_vtest_cmd_buf *cbuf;
+
+ cbuf = CALLOC_STRUCT(virgl_vtest_cmd_buf);
+ if (!cbuf)
+ return NULL;
+
+ cbuf->nres = 512;
+ cbuf->res_bo = CALLOC(cbuf->nres, sizeof(struct virgl_hw_buf*));
+ if (!cbuf->res_bo) {
+ FREE(cbuf);
+ return NULL;
+ }
+ cbuf->ws = vws;
+ cbuf->base.buf = cbuf->buf;
+ cbuf->base.in_fence_fd = -1;
+ return &cbuf->base;
+}
+
+static void virgl_vtest_cmd_buf_destroy(struct virgl_cmd_buf *_cbuf)
+{
+ struct virgl_vtest_cmd_buf *cbuf = virgl_vtest_cmd_buf(_cbuf);
+
+ virgl_vtest_release_all_res(virgl_vtest_winsys(cbuf->ws), cbuf);
+ FREE(cbuf->res_bo);
+ FREE(cbuf);
+}
+
static int virgl_vtest_winsys_submit_cmd(struct virgl_winsys *vws,
struct virgl_cmd_buf *_cbuf,
int in_fence_fd, int *out_fence_fd)
struct virgl_cmd_buf *_cbuf,
struct virgl_hw_res *res)
{
- if (!res->num_cs_references)
+ if (!p_atomic_read(&res->num_cs_references))
return FALSE;
return TRUE;