-
Notifications
You must be signed in to change notification settings - Fork 195
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-in: Fix missing stores for local declarations #2029
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some problems with how the problem is handled but the overall approach is good, you should also change add_local_var
to make the init
field always None
# src/front/glsl/variables.rs:646
- init: decl.init,
+ init: None,
Ok(res) => Some(res), | ||
// Note that even if we solve the constant, we only use the solution for global constants. | ||
// Locals have to be re-assigned every time they are encountered. | ||
Ok(res) if ctx.external => Some(res), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be moved before the constant is solved, no point in wasting time processing it if it isn't going to be used
8088149
to
4122648
Compare
Previously, if a local variable was declared with a constant value, we would elide the store and instead give the variable an initial value (as if it was a global variable). This caused variables to not be re-initialized each time through a loop.
4122648
to
c9bca44
Compare
// If the variable is global and const qualified, solve the initializer for a constant | ||
// and use that as the variable's initial value. | ||
let is_const = ctx.qualifiers.storage.0 == StorageQualifier::Const; | ||
let maybe_constant = match (init, ctx.external, is_const) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will prevent non constant globals from being evaluated, try this instead:
let maybe_constant = if ctx.external {
match parser.solve_constant(ctx.ctx, root, meta) {
Ok(res) => Some(res),
// If the declaration is external (global scope) and is constant qualified
// then the initializer must be a constant expression
Err(err) is_const => return Err(err),
_ => None,
}
} else {
None
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks! There's a lot of cases here and I still didn't have it clear in my head.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, if we have a non-constant qualified global with an initializer that can't be solved, should that also be an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No glsl allows globals to refer to other globals which can't be constified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fascinating, ok! I will go with this. Thanks again!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution
Previously, if a local variable was declared with a constant value, we
would elide the store and instead give the variable an initial value (as
if it was a global variable). This caused variables to not be
re-initialized each time through a loop.
Fixes #1935, but the issue seems broad and might fix others.