Mesa (main): iris: save some iris_syncobj_reference() calls at update_bo_syncobjs()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Feb 1 00:55:29 UTC 2022


Module: Mesa
Branch: main
Commit: 06b279ccb2523ac8f5b5300d6bb651e3d0fc3556
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=06b279ccb2523ac8f5b5300d6bb651e3d0fc3556

Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Wed Jan 26 16:56:48 2022 -0800

iris: save some iris_syncobj_reference() calls at update_bo_syncobjs()

Save some iris_syncobj_reference() calls at at update_bo_syncobjs() by
refactoring the function, moving the unnecessary calls out of the for
loop. Also improve the documentation and drive-by fix a white space
issue.

Commit a90a1f15a7c8 incremented IRIS_BATCH_COUNT and adjusted the code
involving it. But the way it was done at update_bo_syncobjs() means
we'll now call iris_syncobj_reference() more than the amount of times
we need. This isn't a problem since in the second call we're moving
the reference from something to the same thing, but still we can get
away with just not doing it, so why not?

There is also the question of whether we should really iterate over
IRIS_BATCH_COUNT or something else (to save time on platforms that
don't have as many batches as IRIS_BATCH_COUNT), but this is a matter
for a separate patch (see MR !14747). In this patch we reorder the
operations a little bit so when the time comes there will be just one
loop to adjust.

I also changed the order so first we look at's in bo_deps and only
later we write to bo_deps. This is more future-proof and will make the
next patch easier to land and understand.

Reference: a90a1f15a7c8 ("iris: Create an IRIS_BATCH_BLITTER for using the BLT command streamer")
Reference: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14747
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14505>

---

 src/gallium/drivers/iris/iris_batch.c | 49 +++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/src/gallium/drivers/iris/iris_batch.c b/src/gallium/drivers/iris/iris_batch.c
index e1f7e53884c..45c1cad579a 100644
--- a/src/gallium/drivers/iris/iris_batch.c
+++ b/src/gallium/drivers/iris/iris_batch.c
@@ -814,7 +814,7 @@ update_bo_syncobjs(struct iris_batch *batch, struct iris_bo *bo, bool write)
    /* Make sure bo->deps is big enough */
    if (screen->id >= bo->deps_size) {
       int new_size = screen->id + 1;
-      bo->deps= realloc(bo->deps, new_size * sizeof(bo->deps[0]));
+      bo->deps = realloc(bo->deps, new_size * sizeof(bo->deps[0]));
       memset(&bo->deps[bo->deps_size], 0,
              sizeof(bo->deps[0]) * (new_size - bo->deps_size));
 
@@ -828,7 +828,7 @@ update_bo_syncobjs(struct iris_batch *batch, struct iris_bo *bo, bool write)
     * our code may need to care about all the operations done by every batch
     * on every screen.
     */
-   struct iris_bo_screen_deps *deps = &bo->deps[screen->id];
+   struct iris_bo_screen_deps *bo_deps = &bo->deps[screen->id];
    int batch_idx = batch->name;
 
    /* Someday if IRIS_BATCH_COUNT increases to 4, we could do:
@@ -845,33 +845,38 @@ update_bo_syncobjs(struct iris_batch *batch, struct iris_bo *bo, bool write)
       (batch_idx ^ 2) & 2,
    };
 
+   /* Make our batch depend on additional syncobjs depending on what other
+    * batches have been doing to this bo.
+    */
    for (unsigned i = 0; i < ARRAY_SIZE(other_batch_idxs); i++) {
       unsigned other_batch_idx = other_batch_idxs[i];
 
-      /* If it is being written to by others, wait on it. */
-      if (deps->write_syncobjs[other_batch_idx])
-         move_syncobj_to_batch(batch, &deps->write_syncobjs[other_batch_idx],
+      /* If the bo is being written to by others, wait for them. */
+      if (bo_deps->write_syncobjs[other_batch_idx])
+         move_syncobj_to_batch(batch,
+                               &bo_deps->write_syncobjs[other_batch_idx],
                                I915_EXEC_FENCE_WAIT);
 
-      struct iris_syncobj *batch_syncobj =
-         iris_batch_get_signal_syncobj(batch);
-
-      if (write) {
-         /* If we're writing to it, set our batch's syncobj as write_syncobj
-          * so others can wait on us. Also wait every reader we care about
-          * before writing.
-          */
-         iris_syncobj_reference(bufmgr, &deps->write_syncobjs[batch_idx],
-                                 batch_syncobj);
+      /* If we're writing to the bo, wait on the reads from other batches. */
+      if (write)
+         move_syncobj_to_batch(batch,
+                               &bo_deps->read_syncobjs[other_batch_idx],
+                               I915_EXEC_FENCE_WAIT);
+   }
 
-         move_syncobj_to_batch(batch, &deps->read_syncobjs[other_batch_idx],
-                              I915_EXEC_FENCE_WAIT);
+   struct iris_syncobj *batch_syncobj =
+      iris_batch_get_signal_syncobj(batch);
 
-      } else {
-         /* If we're reading, replace the other read from our batch index. */
-         iris_syncobj_reference(bufmgr, &deps->read_syncobjs[batch_idx],
-                                batch_syncobj);
-      }
+   /* Update bo_deps depending on what we're doing with the bo in this batch
+    * by putting the batch's syncobj in the bo_deps lists accordingly. Only
+    * keep track of the last time we wrote to or read the BO.
+    */
+   if (write) {
+      iris_syncobj_reference(bufmgr, &bo_deps->write_syncobjs[batch_idx],
+                             batch_syncobj);
+   } else {
+      iris_syncobj_reference(bufmgr, &bo_deps->read_syncobjs[batch_idx],
+                             batch_syncobj);
    }
 }
 



More information about the mesa-commit mailing list