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

WebGLProgram: make unroll loop regexp accept other coding style #20012

Merged
merged 1 commit into from
Aug 17, 2020

Conversation

DavidPeicho
Copy link
Contributor

@DavidPeicho DavidPeicho commented Aug 4, 2020

It often happens that my loop don't get unrolled because my coding style isn't as aired as the one from Three.js. Nothing fancy but this should allow to unroll loops like:

// 1. Works with Allman curly brackets

#pragma unroll_loop_start
for ( int i = 0; i < 5; i ++ )
{
}
#pragma unroll_loop_end

// 2. Space or not in condition braces

#pragma unroll_loop_start
for (int i = 0; i < 5; i ++) {
}
#pragma unroll_loop_end

// 3. Space or not between `i` and `++`

#pragma unroll_loop_start
for (int i = 0; i < 5; i++) { }
#pragma unroll_loop_end

We can obviously go much more crazy and authorize ++i or whatever, but I believe at least the brackets position is important, otherwise colleagues start to fix shaders coding style and no unrolling occurs 😄

Other potential fix would be to do the unrolling directly in my codebase.

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 4, 2020

Is this a duplicate of #19726?

@DavidPeicho
Copy link
Contributor Author

DavidPeicho commented Aug 5, 2020

It looks like the changes required by #19726 includes my this PR yes. Only thing is that I didn't make it 100% whitespace insensitive but it can be done.

EDIT: Took a quick look at the code of the other PR, yes it's basically the same. I would say it's a good idea to make the regexp slightly more complex (it's really adding few \s*). Basically right now I often break in the material update and I print the shader to be 100% sure it's unrolled...

@mrdoob
Copy link
Owner

mrdoob commented Aug 17, 2020

Let's start with this one. We can add more if needed.

@mrdoob mrdoob added this to the r120 milestone Aug 17, 2020
@mrdoob mrdoob merged commit 8ff94fe into mrdoob:dev Aug 17, 2020
@mrdoob
Copy link
Owner

mrdoob commented Aug 17, 2020

Thanks!

yushijinhun added a commit to yushijinhun/three.js that referenced this pull request Aug 23, 2020
This is just another mrdoob#19726.
Since mrdoob#20012 is accepted, I think it's okay to make loop unrolling
completely whitespace-insensitive.
yushijinhun added a commit to yushijinhun/three.js that referenced this pull request Aug 25, 2020
This is just another mrdoob#19726.
Since mrdoob#20012 is accepted, I think it's okay to make loop unrolling
completely whitespace-insensitive.
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

Successfully merging this pull request may close these issues.

3 participants