From c528af10761aa3ea902df269d71b54425c54e877 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Wed, 5 May 2021 12:53:13 +0200 Subject: [PATCH] aco/scheduler: Fix register demand computation for downwards moves MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, changes in total_demand_clause were not always propagated to total_demand. For instance, clause moves do not change the local register demand at the end of a clause, yet they may still affect the total maximum. Reviewed-by: Daniel Schürmann Fixes: 8235bc64112 ("aco: try to group together VMEM loads of the same resource") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4533 Part-of: --- src/amd/compiler/aco_scheduler.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/amd/compiler/aco_scheduler.cpp b/src/amd/compiler/aco_scheduler.cpp index f40ea7468c3..17a398a8ead 100644 --- a/src/amd/compiler/aco_scheduler.cpp +++ b/src/amd/compiler/aco_scheduler.cpp @@ -115,7 +115,6 @@ void move_element(T begin_it, size_t idx, size_t before) { void MoveState::downwards_advance_helper() { source_idx--; - total_demand.update(register_demand[source_idx]); } void MoveState::downwards_init(int current_idx, bool improved_rar_, bool may_form_clauses) @@ -126,7 +125,8 @@ void MoveState::downwards_init(int current_idx, bool improved_rar_, bool may_for insert_idx = current_idx + 1; insert_idx_clause = current_idx; - total_demand = total_demand_clause = register_demand[current_idx]; + total_demand = register_demand[current_idx]; + total_demand_clause = {}; std::fill(depends_on.begin(), depends_on.end(), false); if (improved_rar) { @@ -194,11 +194,22 @@ MoveResult MoveState::downwards_move(bool clause) for (int i = source_idx; i < dest_insert_idx - 1; i++) register_demand[i] -= candidate_diff; register_demand[dest_insert_idx - 1] = new_demand; - total_demand_clause -= candidate_diff; insert_idx_clause--; + total_demand_clause -= candidate_diff; + if (source_idx == insert_idx_clause) { + total_demand_clause = RegisterDemand{}; + } if (!clause) { total_demand -= candidate_diff; insert_idx--; + } else { + /* The local demand of clause instructions did not change. But if + * previously total_demand_clause was greater than or equal to + * total_demand, the global maximum may have changed still */ + total_demand = total_demand_clause; + for (int i = insert_idx_clause; i < insert_idx; ++i) { + total_demand.update(register_demand[i]); + } } downwards_advance_helper(); @@ -219,6 +230,7 @@ void MoveState::downwards_skip() } } total_demand_clause.update(register_demand[source_idx]); + total_demand.update(register_demand[source_idx]); downwards_advance_helper(); }