Mesa (master): gallium: add pipe_screen::num_contexts for skipping mutex locking in util_range

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Mar 11 07:16:49 UTC 2021


Module: Mesa
Branch: master
Commit: 981e55d5300f2bfb7e062d3c8807b9d7c37fd49d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=981e55d5300f2bfb7e062d3c8807b9d7c37fd49d

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Thu Feb 11 14:59:08 2021 -0500

gallium: add pipe_screen::num_contexts for skipping mutex locking in util_range

Reviewed-by: Zoltán Böszörményi <zboszor at gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9356>

---

 src/gallium/auxiliary/util/u_range.h | 5 ++++-
 src/gallium/include/pipe/p_screen.h  | 6 ++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/util/u_range.h b/src/gallium/auxiliary/util/u_range.h
index 9a158a4fcf9..90dc80bbc69 100644
--- a/src/gallium/auxiliary/util/u_range.h
+++ b/src/gallium/auxiliary/util/u_range.h
@@ -36,6 +36,8 @@
 
 #include "os/os_thread.h"
 #include "pipe/p_state.h"
+#include "pipe/p_screen.h"
+#include "util/u_atomic.h"
 #include "util/u_math.h"
 #include "util/simple_mtx.h"
 
@@ -61,7 +63,8 @@ util_range_add(struct pipe_resource *resource, struct util_range *range,
                unsigned start, unsigned end)
 {
    if (start < range->start || end > range->end) {
-      if (resource->flags & PIPE_RESOURCE_FLAG_SINGLE_THREAD_USE) {
+      if (resource->flags & PIPE_RESOURCE_FLAG_SINGLE_THREAD_USE ||
+          p_atomic_read(&resource->screen->num_contexts) == 1) {
          range->start = MIN2(start, range->start);
          range->end = MAX2(end, range->end);
       } else {
diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h
index 78dae7865b2..ae0e08318b3 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -68,6 +68,12 @@ struct u_transfer_helper;
  * context.
  */
 struct pipe_screen {
+   /**
+    * Atomically incremented by drivers to track the number of contexts.
+    * If it's 0, it can be assumed that contexts are not tracked.
+    * Used by some places to skip locking if num_contexts == 1.
+    */
+   unsigned num_contexts;
 
    /**
     * For drivers using u_transfer_helper:



More information about the mesa-commit mailing list