From 1560c58b121763a21de7f883724aaa10bf37297c Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 15 Aug 2018 19:30:59 +0200 Subject: mesa/st: fix array indices off-by-one error in remapping When moving the array sizes from the old list to the new one it was not taken into account that the array indices start with one, but the array_size array started at index zero, which resulted in incorrect array sizes when arrays were merged. Correct this by copying the array_size values of the retained arrays with an offset of -1. Also fix whitespaces for the replaced lines. Fixes: d8c2119f9b0b257a23ceb398f6d0d78da916417e mesa/st/glsl_to_tgsi: Expose array live range tracking and merging Signed-off-by: Gert Wollny Reviewed-by: Dave Airlie --- src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 2 +- src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 988f3ca83ee..7b96947c607 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -5601,7 +5601,7 @@ glsl_to_tgsi_visitor::merge_registers(void) if (this->next_array > 0) { arr_live_ranges = new array_live_range[this->next_array]; for (unsigned i = 0; i < this->next_array; ++i) - arr_live_ranges[i] = array_live_range(i+1, this->array_sizes[i+1]); + arr_live_ranges[i] = array_live_range(i+1, this->array_sizes[i]); } diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp index f95b1fac7b7..1431824369e 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp @@ -587,10 +587,10 @@ int remap_arrays(int narrays, unsigned *array_sizes, /* re-calculate arrays */ #if __cplusplus < 201402L int *idx_map = new int[narrays + 1]; - unsigned *old_sizes = new unsigned[narrays + 1]; + unsigned *old_sizes = new unsigned[narrays]; #else unique_ptr idx_map = make_unique(narrays + 1); - unique_ptr old_sizes = make_unique(narrays + 1); + unique_ptr old_sizes = make_unique(narrays); #endif memcpy(&old_sizes[0], &array_sizes[0], sizeof(unsigned) * narrays); @@ -599,9 +599,9 @@ int remap_arrays(int narrays, unsigned *array_sizes, int new_narrays = 0; for (int i = 1; i <= narrays; ++i) { if (!map[i].is_valid()) { - ++new_narrays; - idx_map[i] = new_narrays; - array_sizes[new_narrays] = old_sizes[i]; + ++new_narrays; + array_sizes[new_narrays-1] = old_sizes[i-1]; + idx_map[i] = new_narrays; } } -- cgit v1.2.3