Mesa (master): mesa/st: fix array indices off-by-one error in remapping
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Aug 16 07:09:17 UTC 2018
Module: Mesa
Branch: master
Commit: 1560c58b121763a21de7f883724aaa10bf37297c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=1560c58b121763a21de7f883724aaa10bf37297c
Author: Gert Wollny <gw.fossdev at gmail.com>
Date: Wed Aug 15 19:30:59 2018 +0200
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 <gw.fossdev at gmail.com>
Reviewed-by: Dave Airlie <airlied at redhat.com>
---
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 988f3ca83e..7b96947c60 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 f95b1fac7b..1431824369 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<int[]> idx_map = make_unique<int[]>(narrays + 1);
- unique_ptr<unsigned[]> old_sizes = make_unique<unsigned[]>(narrays + 1);
+ unique_ptr<unsigned[]> old_sizes = make_unique<unsigned[]>(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;
}
}
More information about the mesa-commit
mailing list