graphicsfuzz icon indicating copy to clipboard operation
graphicsfuzz copied to clipboard

glsl-reduce enhancement: based on perses

Open AaronGhost opened this issue 2 years ago • 2 comments

I have been experimenting with both glsl-reduce and perses as reducers. It seems that Perses performs more reduction opportunities than glsl-reduce, especially in reducing more aggressively array indexes. Please find below some examples of structures reduced first with glsl-reduce and then with perses.

  • [ ] Reducing ternary operators in array indexes

glsl-reduce

void main()
{
 ext_2[(all(bvec2(true)) ? (+ abs(ext_1[1])) : (ext_0 & -- ext_2[2]))] |= 1;
}

perses

void main()
{
 ext_2[abs(ext_1[1])] |= 1;
}
  • [ ] Removing the outer array in an array index expression

glsl-reduce

void main()
{
 ext_3[(+ + (ext_1 /= (ext_5[2086006349])))] = 1u;
 ++ ext_4[int(var_0[ext_4[(ext_4[ext_4[(ext_4[ext_4[ext_4[1893896488]]])]])]].ttt)];
}

perses

void main()
{
 ext_1/=  ext_5[2086006349];
 ++ ext_4[int(var_0[ext_4[1893896488]])];
}
  • [ ] Reducing complicated swizzles (some can be removed altogether)

glsl-reduce

void main()
{
  ivec4 var_1 = ivec4(- 2147483634);
 (ext_3[ext_7]) = bitfieldExtract(114u, 1, (~ ext_1) / var_1.ttp.yx.x);
}

perses

void main()
{
  ivec4 var_1 = ivec4(- 2147483634);
  ext_3[ext_7]  = bitfieldExtract(114u, 1,  ~ ext_1  / var_1.x);
}
  • [ ] Reducing the number of parameters in type constructors

glsl-reduce

void main()
{
 while(1u + ext_3 <= uint(uvec4(bvec2(false), 1u, true)))
  {
   ext_10 = 1u;
  }
}

perses

 void main()
{
 while(1u + ext_3 <= uint(false))
 {
   ext_10 = 1u;
 }
}

AaronGhost avatar Jan 10 '22 09:01 AaronGhost

@AaronGhost For the second one, "Removing the outer array in an array index expression", are you able to paste the necessary buffer block declarations?

afd avatar Mar 07 '22 16:03 afd

I am not quite sure to understand the question. I picked two different lines from two shaders so the main did not make much sense. I edited with a distinct ext value.

The buffer block could be something like this:

layout(std430, binding = 0) buffer buffer_0
{
int ext_1;
uint ext_3[10];
int ext_4[2];
int ext_5[3];
};

A value of ext_4[0] = 0 for example leads to a "loop" behaviour.

AaronGhost avatar Mar 07 '22 16:03 AaronGhost