Skip to content

gen_variable_index_write_tests: stop arrays from being optimised away

Previously these tests would generate something that looked like this:

   mat3x3[3] dst_matrix = mat3x3[3](mat3x3(0.0), mat3x3(0.0), mat3x3(0.0));

   dst_matrix[index] = src_matrix;
   dst_matrix[index][1] = value;

   gl_FrontColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
     ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);

Because we are writing to and reading from the array with the same uniform index Mesas NIR optimisations were smart enough to eliminate the array altogether. With an upcoming Mesa improvement to eliminate dead uniforms this was also causing the tests to fail because the uniform index gets eliminated and the test can no longer set it.

With this change we add index2 which will be set to the same value as index but only used when reading from the array. With this NIR can no longer eliminate the array.

An example of the new code:

   mat3x3[3] dst_matrix = mat3x3[3](mat3x3(0.0), mat3x3(0.0), mat3x3(0.0));

   dst_matrix[index] = src_matrix;
   dst_matrix[index][1] = value;

   gl_FrontColor = (distanceSqr(dst_matrix[index2] * v, expect) < 4e-9)
     ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
Edited by Timothy Arceri

Merge request reports

Loading