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

"integer constant overflow" errors can be triggered by minifier precomputing some float values #329

Open
TheNuSan opened this issue Mar 22, 2024 · 2 comments

Comments

@TheNuSan
Copy link

The following code:
float distance=100000; if (other_value < distance * distance) {....}
will be minified to something like:
if(a < 10000000000) {...}
which trigger an "integer constant overflow" opengl error at shader compile time

if I add a point to my float declaration to "force" it to be a float:
float distance=100000.; if (other_value < distance * distance) {....}
it will be minified to something like:
if(a < 1e10) {...}
and no longer be an issue

To be honest, this variable was gonna be animated later, so the issue would have probably disappeared once no longer a constant, but it took me a while to understand why it happened

@laurentlb
Copy link
Owner

Thanks! An issue is that we lose type information when we inline (the value is an int, but the variable is a float), similar to #323 (comment)

@TheNuSan
Copy link
Author

I can see how it's hard to check for all those cases, and maybe it's not so bad to have something smaller 99% of the time than disabling an optimisation for the sake of a few fringes cases. It took me a while to find only because my debugging tools were bad and broken, but now I made it so I can easily use the minified shader in my editor, with proper error reporting, so it should be easier to work out those kind of mistakes in the future.
On this topic, I wonder if it would be possible for shaderminifier to generate some kind of log, maybe try to compile the shader by itself so it can report if there is an error somewhere... but I'm pretty sure nobody would look at the log anyway haha so it's probably a bad idea

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