summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@gmail.com>2015-03-16 13:36:41 +1000
committerDave Airlie <airlied@redhat.com>2015-06-16 12:34:26 +1000
commitdbb714b87f48a67cc93d28677eab5d15a866b0e9 (patch)
tree8228c8f31a22572e64c6b991d7b7355647978339
parentc8041416b74ed9ee9ae11baacb4bddec1d725322 (diff)
vtest: add more resource caching bits
-rw-r--r--src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c
index b2c0972a886..98f381f6720 100644
--- a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c
+++ b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c
@@ -121,6 +121,27 @@ virgl_cache_flush(struct virgl_vtest_winsys *vtws)
pipe_mutex_unlock(vtws->mutex);
}
+static void
+virgl_cache_list_check_free(struct virgl_vtest_winsys *vtws)
+{
+ struct list_head *curr, *next;
+ struct virgl_hw_res *res;
+ int64_t now;
+
+ now = os_time_get();
+ curr = vtws->delayed.next;
+ next = curr->next;
+ while (curr != &vtws->delayed) {
+ res = LIST_ENTRY(struct virgl_hw_res, curr, head);
+ if (!os_time_timeout(res->start, res->end, now))
+ break;
+
+ LIST_DEL(&res->head);
+ virgl_hw_res_destroy(vtws, res);
+ curr = next;
+ next = curr->next;
+ }
+}
static void virgl_vtest_resource_reference(struct virgl_vtest_winsys *vtws,
struct virgl_hw_res **dres,
@@ -128,7 +149,18 @@ static void virgl_vtest_resource_reference(struct virgl_vtest_winsys *vtws,
{
struct virgl_hw_res *old = *dres;
if (pipe_reference(&(*dres)->reference, &sres->reference)) {
- virgl_hw_res_destroy(vtws, old);
+ if (!can_cache_resource(old)) {
+ virgl_hw_res_destroy(vtws, old);
+ } else {
+ pipe_mutex_lock(vtws->mutex);
+ virgl_cache_list_check_free(vtws);
+
+ old->start = os_time_get();
+ old->end = old->start + vtws->usecs;
+ LIST_ADDTAIL(&old->head, &vtws->delayed);
+ vtws->num_delayed++;
+ pipe_mutex_unlock(vtws->mutex);
+ }
}
*dres = sres;
}