iris: Don't search the exec list if BOs have never been added to one
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 22 Dec 2023 12:02:47 +0000 (04:02 -0800)
committerEric Engestrom <eric@engestrom.ch>
Wed, 27 Dec 2023 13:39:29 +0000 (13:39 +0000)
Whenever we use a BO in a batch, we need to find its corresponding exec
list entry, either to a) record that it's been used, b) update whether
it's being written, c) check for cross-batch implicit dependencies.

bo->index exists to accelerate these lookups.  If a BO is used multiple
times by a batch, bo->index is its location in the list.  Because the
field is global, and a BO can in theory be used concurrently by multiple
contexts, we need to double-check whether it's still there.  If not, we
fall back to a linear search of all BOs in the list, looking to see if
our index was simply wrong (but presumably right for another context).

However, there's one glaringly obvious case that we missed here.  If
bo->index is -1, then it's wrong for /all/ contexts, and in fact implies
that said BO has never been added to any exec list, ever.  This is quite
common in fact: a new BO, never been used before, say from the BO cache,
or streaming uploaders, gets used for the first time.

In this case we can simply conclude that it's not in the list and skip
the linear walk through all buffers referenced by the batch.

Improves performance on an i7-12700 and A770:

- SPECviewperf2020 catiav5test1: 72.9214% +/- 0.312735% (n=45)

Cc: mesa-stable
Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26806>
(cherry picked from commit d55b5d4af5d55a25837d8507840f4ab9b1075ea3)

.pick_status.json
src/gallium/drivers/iris/iris_batch.c

index c5fedf3..f495786 100644 (file)
@@ -14,7 +14,7 @@
         "description": "iris: Don't search the exec list if BOs have never been added to one",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null,
         "notes": null
index d1f75a5..293a3b8 100644 (file)
@@ -278,6 +278,9 @@ find_exec_index(struct iris_batch *batch, struct iris_bo *bo)
 {
    unsigned index = READ_ONCE(bo->index);
 
+   if (index == -1)
+      return -1;
+
    if (index < batch->exec_count && batch->exec_bos[index] == bo)
       return index;