Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glsl-reduce enhancement: based on perses #1179

Open
4 tasks
AaronGhost opened this issue Jan 10, 2022 · 2 comments
Open
4 tasks

glsl-reduce enhancement: based on perses #1179

AaronGhost opened this issue Jan 10, 2022 · 2 comments

Comments

@AaronGhost
Copy link
Contributor

AaronGhost commented Jan 10, 2022

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;
 }
}
@afd
Copy link
Contributor

afd commented Mar 7, 2022

@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 added a commit that referenced this issue Mar 7, 2022
Improves the reducer's ability to reduce array indexing expressions,
by being less conservative about l-values.

Part of #1179.
@AaronGhost
Copy link
Contributor Author

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.

afd added a commit that referenced this issue Mar 10, 2022
Improves the reducer's ability to reduce array indexing expressions,
by being less conservative about l-values.

Part of #1179.
afd added a commit that referenced this issue Mar 10, 2022
Adds support for simplifying, shortening and removing swizzles.

Part of #1179.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants