[Mesa-stable] [PATCH 16/19] gallium/pipebuffer: Add a cache buffer manager bypass mask

Brian Paul brianp at vmware.com
Fri Feb 14 02:21:08 CET 2014


From: Thomas Hellstrom <thellstrom at vmware.com>

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 at vmware.com>
Reviewed-by: José Fonseca <jfonseca at vmware.com>
Reviewed-by: Brian Paul <brianp at vmware.com>
Cc: "10.1" <mesa-stable at lists.freedesktop.org>
---
 src/gallium/auxiliary/pipebuffer/pb_bufmgr.h       |    3 ++-
 src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c |   23 +++++++++++++++++---
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.c  |    2 +-
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h b/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h
index fe4c8c2..3044ec8 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h
@@ -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;
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
index 6de5de0..0469146 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
@@ -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);
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index b7137d2..6f0e2a5 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -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;
 
-- 
1.7.10.4



More information about the mesa-stable mailing list