New issue
Advanced search Search tips

Issue 818652 link

Starred by 1 user

Issue metadata

Status: Available
Owner: ----
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Compat



Sign in to add a comment

GLSL bug: no return undetected

Reported by fabrice....@gmail.com, Mar 5 2018

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36

Example URL:
https://www.shadertoy.com/view/XsdcDj

Steps to reproduce the problem:
run the shader: func return 1 only on right half window, nothing specified on left.

What is the expected behavior?
This shouldn't even compile (or return 0 or undetermined on left)

Suppressing the return in if does trigger an error. Transforming the if (e.g. 2 branches) change the result.

What went wrong?
The code does compile without error.
This configuration return 1 all the time on true OpenGL (Windows or linux) and 0 on left half on Windows/Angle.

(might fallback to classical return-in-if bugs)

Does it occur on multiple sites: N/A

Is it a problem with a plugin? No 

Did this work before? N/A 

Does this work in other browsers? No
 firefox

Chrome version: 62.0.3202.94  Channel: n/a
OS Version: 16.04
Flash Version: Shockwave Flash 28.0 r0

may somebody please add tags
Blink>WebGL
Internals>GPU
?
 
Components: Blink>WebGL
Components: Internals>GPU>ANGLE
Labels: -OS-Linux
It is indeed weird that this code compiles.

But I'm not sure we can turn it into an error. For one thing, it could break existing content.

It also really depends on whether this is supposed to be allowed by the GLSL spec. I don't know off-hand.
Status: Available (was: Unconfirmed)
Per the GLSL ES spec, section 10.29, it appears to be well-defined that a missing return path will return an undefined value, though I'm not sure if this is true also of GLSL.

https://www.khronos.org/files/opengles_shading_language.pdf
yeah, I read elsewhere that determining whether a final return was really necessary would be equivalent to the NP problem of program halting. 

In the spirit of secure languages like ADA one could force the user to always put a return at the end, but conservative constraints is not in the spirit of C-family languages which GLSL inherit.

Still, this indetermination seems to give consistently different values in OpenGL vs Angle, but there's probably not much we can do here.

Comment 6 by zmo@chromium.org, Mar 14 2018

Cc: oetu...@nvidia.com
Thanks for studying the spec and clarifying GLSL ES behavior.

This is similar to uninitialized variables. I think we could just simply append an extra "return 0" in the end of a function to get rid of undefined values.
very good idea for at least if would be cross-compatible.
But do you know easily how to generate the zero for any type ?

Comment 8 by zmo@chromium.org, Mar 14 2018

We already have the code to initialize un-initialized variables, so assume generating zero for any type is already implemented in ANGLE shader translator?

Comment 9 by oetu...@nvidia.com, Mar 15 2018

Yes, we have the code to generate zero for any type already. We can't just naively add return 0 to everything though - issues might arise if ANGLE would append return 0 in cases where the extra return is detected by the native compiler and it starts complaining about it.

We can still probably do pretty well without solving the halting problem, but it is a fair amount of effort - I don't think I'll take this on right now.
Cc: -oetu...@nvidia.com

Sign in to add a comment