Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

[glsl-new] Handle local vars scopes #126

Merged
merged 2 commits into from
Aug 13, 2020
Merged

Conversation

pjoe
Copy link
Collaborator

@pjoe pjoe commented Aug 13, 2020

I think this was the biggest remaining issue I needed to figure out - the rest should more or less be just work 😊

Probably also a good time to start figure out some proper tests.

@@ -37,6 +38,9 @@ impl fmt::Display for ErrorKind {
ErrorKind::UnknownVariable(meta, val) => {
write!(f, "Unknown variable {} at {:?}", val, meta)
}
ErrorKind::VariableAlreadyDeclared(val) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who forbids this? I think, if you encounter a variable with the same name, it can just replace the current one in the scope map

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try checking if the spec has anything to say on this ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naga IR doesn't really care about names, other than for entry points (since they connect to the API). So IR has no limitations on what the names are, might as well treat them as debug labels.
The limitation you are talking about comes from GLSL, and the front-end should assume it has valid GLSL on the input, you don't need to go into the forest of validating incoming GLSL sources :) So you don't need to worry about overlaps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would the GLSL source be validated? Is naga always supposed to be used with a validator in front of it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naga has one and only place in its pipeline where the data is guaranteed to be valid: that's the IR:

  1. front-end inputs are assumed to be valid. We don't care if they actually are, as long as the front-end doesn't crash or hangs (which is a universal requirement to the code base).
  2. front-end output IR has to be valid, and we are testing this, and any clients will be testing this, using the validator in of Validation function for the IR #59 . Any breaking of this contract is a bug in the front-end.
  3. similarly, backends can assume the IR is valid
  4. similarly, backend's produced low-level shaders have to be valid, and we are either testing, or will be testing this

So Naga doesn't care if your GLSL is valid or not. Just like a Vulkan driver doesn't care if the use of the API is valid or not. Unlike the Vulkan driver, Naga can't afford to behave strangely though.

- Check loacl vars before globals

- Rename add_scope > push_scope

- Remove unnecessary ref in lookup functions
Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed on Matrix: validating is not required, but it's not forbidden either.

@kvark kvark merged commit b4e1775 into gfx-rs:master Aug 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants