GLSL bug: no return undetected
Reported by
fabrice....@gmail.com,
Mar 5 2018
|
|||||
Issue descriptionUserAgent: 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 ?
,
Mar 5 2018
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.
,
Mar 5 2018
,
Mar 14 2018
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
,
Mar 14 2018
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.
,
Mar 14 2018
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.
,
Mar 14 2018
very good idea for at least if would be cross-compatible. But do you know easily how to generate the zero for any type ?
,
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?
,
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.
,
Oct 9
|
|||||
►
Sign in to add a comment |
|||||
Comment 1 by dtapu...@chromium.org
, Mar 5 2018