gallium/pipebuffer: Add a cache buffer manager bypass mask
authorThomas Hellstrom <thellstrom@vmware.com>
Sat, 8 Feb 2014 17:51:15 +0000 (09:51 -0800)
committerBrian Paul <brianp@vmware.com>
Fri, 14 Feb 2014 15:21:44 +0000 (08:21 -0700)
In some situations, it may be desirable to bypass the cache at buffer
creation but to insert the buffer in the cache at buffer destruction.
One such situation is where we already have a kernel representation of a
buffer that we want to use, but we also want to insert it in the cache when
it's freed up.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Cc: "10.1" <mesa-stable@lists.freedesktop.org>
src/gallium/auxiliary/pipebuffer/pb_bufmgr.h
src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c

index fe4c8c20071d7f0abe1ec7242e735dcd3bb83ce2..3044ec881fd976b509bc2183aee4220cc48f68cf 100644 (file)
@@ -162,7 +162,8 @@ pb_slab_range_manager_create(struct pb_manager *provider,
 struct pb_manager *
 pb_cache_manager_create(struct pb_manager *provider, 
                        unsigned usecs,
-                       unsigned size_factor); 
+                       unsigned size_factor,
+                        unsigned bypass_usage);
 
 
 struct pb_fence_ops;
index 6de5de04fe95f84946be3afee5cef5b8b4497b71..0469146d15bc2753a2d4c397963934ec53b11978 100644 (file)
@@ -83,6 +83,7 @@ struct pb_cache_manager
    struct list_head delayed;
    pb_size numDelayed;
    unsigned size_factor;
+   unsigned bypass_usage;
 };
 
 
@@ -228,6 +229,9 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf,
                           pb_size size,
                           const struct pb_desc *desc)
 {
+   if (desc->usage & buf->mgr->bypass_usage)
+      return 0;
+
    if(buf->base.size < size)
       return 0;
 
@@ -339,7 +343,7 @@ pb_cache_manager_create_buffer(struct pb_manager *_mgr,
    
    assert(pipe_is_referenced(&buf->buffer->reference));
    assert(pb_check_alignment(desc->alignment, buf->buffer->alignment));
-   assert(pb_check_usage(desc->usage, buf->buffer->usage));
+   assert(pb_check_usage(desc->usage & ~mgr->bypass_usage, buf->buffer->usage));
    assert(buf->buffer->size >= size);
    
    pipe_reference_init(&buf->base.reference, 1);
@@ -385,11 +389,23 @@ pb_cache_manager_destroy(struct pb_manager *mgr)
    FREE(mgr);
 }
 
-
+/**
+ * Create a caching buffer manager
+ *
+ * @param provider The buffer manager to which cache miss buffer requests
+ * should be redirected.
+ * @param usecs Unused buffers may be released from the cache after this
+ * time
+ * @param size_factor Declare buffers that are size_factor times bigger than
+ * the requested size as cache hits.
+ * @param bypass_usage Bitmask. If (requested usage & bypass_usage) != 0,
+ * buffer allocation requests are redirected to the provider.
+ */
 struct pb_manager *
 pb_cache_manager_create(struct pb_manager *provider, 
                        unsigned usecs,
-                       unsigned size_factor) 
+                       unsigned size_factor,
+                        unsigned bypass_usage)
 {
    struct pb_cache_manager *mgr;
 
@@ -406,6 +422,7 @@ pb_cache_manager_create(struct pb_manager *provider,
    mgr->provider = provider;
    mgr->usecs = usecs;
    mgr->size_factor = size_factor;
+   mgr->bypass_usage = bypass_usage;
    LIST_INITHEAD(&mgr->delayed);
    mgr->numDelayed = 0;
    pipe_mutex_init(mgr->mutex);
index b7137d221ca058eea60961e4928715b61dc6dc2d..6f0e2a57669d2b7946b695dcbda3b7e4b3811f3e 100644 (file)
@@ -645,7 +645,7 @@ PUBLIC struct radeon_winsys *radeon_drm_winsys_create(int fd)
     ws->kman = radeon_bomgr_create(ws);
     if (!ws->kman)
         goto fail;
-    ws->cman = pb_cache_manager_create(ws->kman, 1000000, 2);
+    ws->cman = pb_cache_manager_create(ws->kman, 1000000, 2, 0);
     if (!ws->cman)
         goto fail;