[Mesa-dev] [PATCH 3/4] gallium/u_inlines: improve pipe_reference_described perf for debug builds

Marek Olšák maraeo at gmail.com
Sat Sep 1 06:54:18 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

+41% performance in debug builds
(testing piglit/drawoverhead + u_threaded_context)
---
 src/gallium/auxiliary/util/u_inlines.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
index 19c6c7b75dd..815ac5c97ac 100644
--- a/src/gallium/auxiliary/util/u_inlines.h
+++ b/src/gallium/auxiliary/util/u_inlines.h
@@ -72,28 +72,29 @@ pipe_is_referenced(struct pipe_reference *src)
 static inline boolean
 pipe_reference_described(struct pipe_reference *dst,
                          struct pipe_reference *src,
                          debug_reference_descriptor get_desc)
 {
    boolean destroy = FALSE;
 
    if (dst != src) {
       /* bump the reference.count first */
       if (src) {
-         assert(pipe_is_referenced(src));
-         p_atomic_inc(&src->count);
+         MAYBE_UNUSED int count = p_atomic_inc_return(&src->count);
+         assert(count != 1); /* src had to be referenced */
          debug_reference(src, get_desc, 1);
       }
 
       if (dst) {
-         assert(pipe_is_referenced(dst));
-         if (p_atomic_dec_zero(&dst->count))
+         int count = p_atomic_dec_return(&dst->count);
+         assert(count != -1); /* dst had to be referenced */
+         if (!count)
             destroy = TRUE;
 
          debug_reference(dst, get_desc, -1);
       }
    }
 
    return destroy;
 }
 
 static inline boolean
-- 
2.17.1



More information about the mesa-dev mailing list