Commit 1560c58b authored by Gert Wollny's avatar Gert Wollny
Browse files

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: d8c2119f


  mesa/st/glsl_to_tgsi: Expose array live range tracking and merging
Signed-off-by: Gert Wollny's avatarGert Wollny <gw.fossdev@gmail.com>
Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
parent 9a96bf0e
......@@ -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]);
}
......
......@@ -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;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment