virgl: Deduplicate checks for resource caching

Also fixes a missed check for VIRGL_BIND_CUSTOM in one of the duplicate
code snippets.

Note that legacy fences also use VIRGL_BIND_CUSTOM, but we ensured they
don't go through the cache in the previous commit.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
This commit is contained in:
Alexandros Frantzis 2019-06-04 16:40:33 +03:00 committed by Chia-I Wu
parent e0ffcdf16a
commit 8eb8222c10
4 changed files with 14 additions and 20 deletions

View file

@ -50,9 +50,12 @@
#define VIRGL_DRM_VERSION_FENCE_FD VIRGL_DRM_VERSION(0, 1)
static inline boolean can_cache_resource(struct virgl_hw_res *res)
static inline boolean can_cache_resource_with_bind(uint32_t bind)
{
return res->cacheable == TRUE;
return bind == VIRGL_BIND_CONSTANT_BUFFER ||
bind == VIRGL_BIND_INDEX_BUFFER ||
bind == VIRGL_BIND_VERTEX_BUFFER ||
bind == VIRGL_BIND_CUSTOM;
}
static void virgl_hw_res_destroy(struct virgl_drm_winsys *qdws,
@ -156,7 +159,7 @@ static void virgl_drm_resource_reference(struct virgl_drm_winsys *qdws,
struct virgl_hw_res *old = *dres;
if (pipe_reference(&(*dres)->reference, &sres->reference)) {
if (!can_cache_resource(old)) {
if (!can_cache_resource_with_bind(old->bind)) {
virgl_hw_res_destroy(qdws, old);
} else {
mtx_lock(&qdws->mutex);
@ -316,9 +319,7 @@ virgl_drm_winsys_resource_cache_create(struct virgl_winsys *qws,
int64_t now;
int ret = 0;
/* only store binds for vertex/index/const buffers */
if (bind != VIRGL_BIND_CONSTANT_BUFFER && bind != VIRGL_BIND_INDEX_BUFFER &&
bind != VIRGL_BIND_VERTEX_BUFFER && bind != VIRGL_BIND_CUSTOM)
if (!can_cache_resource_with_bind(bind))
goto alloc;
mtx_lock(&qdws->mutex);
@ -375,9 +376,6 @@ alloc:
res = virgl_drm_winsys_resource_create(qws, target, format, bind,
width, height, depth, array_size,
last_level, nr_samples, size);
if (bind == VIRGL_BIND_CONSTANT_BUFFER || bind == VIRGL_BIND_INDEX_BUFFER ||
bind == VIRGL_BIND_VERTEX_BUFFER)
res->cacheable = TRUE;
return res;
}

View file

@ -45,7 +45,6 @@ struct virgl_hw_res {
struct list_head head;
uint32_t format;
uint32_t bind;
boolean cacheable;
int64_t start, end;
uint32_t flink_name;
};

View file

@ -37,9 +37,12 @@ static void *virgl_vtest_resource_map(struct virgl_winsys *vws,
static void virgl_vtest_resource_unmap(struct virgl_winsys *vws,
struct virgl_hw_res *res);
static inline boolean can_cache_resource(struct virgl_hw_res *res)
static inline boolean can_cache_resource_with_bind(uint32_t bind)
{
return res->cacheable == TRUE;
return bind == VIRGL_BIND_CONSTANT_BUFFER ||
bind == VIRGL_BIND_INDEX_BUFFER ||
bind == VIRGL_BIND_VERTEX_BUFFER ||
bind == VIRGL_BIND_CUSTOM;
}
static uint32_t vtest_get_transfer_size(struct virgl_hw_res *res,
@ -242,7 +245,7 @@ static void virgl_vtest_resource_reference(struct virgl_vtest_winsys *vtws,
{
struct virgl_hw_res *old = *dres;
if (pipe_reference(&(*dres)->reference, &sres->reference)) {
if (!can_cache_resource(old)) {
if (!can_cache_resource_with_bind(old->bind)) {
virgl_hw_res_destroy(vtws, old);
} else {
mtx_lock(&vtws->mutex);
@ -419,9 +422,7 @@ virgl_vtest_winsys_resource_cache_create(struct virgl_winsys *vws,
int64_t now;
int ret = -1;
/* only store binds for vertex/index/const buffers */
if (bind != VIRGL_BIND_CONSTANT_BUFFER && bind != VIRGL_BIND_INDEX_BUFFER &&
bind != VIRGL_BIND_VERTEX_BUFFER && bind != VIRGL_BIND_CUSTOM)
if (!can_cache_resource_with_bind(bind))
goto alloc;
mtx_lock(&vtws->mutex);
@ -478,9 +479,6 @@ alloc:
res = virgl_vtest_winsys_resource_create(vws, target, format, bind,
width, height, depth, array_size,
last_level, nr_samples, size);
if (bind == VIRGL_BIND_CONSTANT_BUFFER || bind == VIRGL_BIND_INDEX_BUFFER ||
bind == VIRGL_BIND_VERTEX_BUFFER)
res->cacheable = TRUE;
return res;
}

View file

@ -71,7 +71,6 @@ struct virgl_hw_res {
struct list_head head;
uint32_t bind;
boolean cacheable;
int64_t start, end;
};