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 a90a1f15a7 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: a90a1f15a7 ("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@whitecape.org>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14505>
This commit is contained in:
Paulo Zanoni 2022-01-26 16:56:48 -08:00 committed by Marge Bot
parent db475c81b7
commit 06b279ccb2
1 changed files with 27 additions and 22 deletions

View File

@ -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 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);
}
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);
struct iris_syncobj *batch_syncobj =
iris_batch_get_signal_syncobj(batch);
move_syncobj_to_batch(batch, &deps->read_syncobjs[other_batch_idx],
I915_EXEC_FENCE_WAIT);
} 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);
}
}