From: Alexandros Frantzis Date: Tue, 4 Jun 2019 13:40:33 +0000 (+0300) Subject: virgl: Deduplicate checks for resource caching X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8eb8222c102ee6cd38a01e7df952ea87e1ca4f42;p=mesa.git 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 Reviewed-by: Chia-I Wu --- diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c index ded12933d3a..f2c41bbc903 100644 --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c @@ -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; } diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h index c0d1ae568a7..de84f308d97 100644 --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h @@ -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; }; diff --git a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c index 0273d96f0dc..ccacb81d233 100644 --- a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c +++ b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c @@ -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; } diff --git a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.h b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.h index c6b1589d7db..2a600f6a49c 100644 --- a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.h +++ b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.h @@ -71,7 +71,6 @@ struct virgl_hw_res { struct list_head head; uint32_t bind; - boolean cacheable; int64_t start, end; };