-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[naga wgsl-in] Ensure constant evaluation correctly handles Composes …
…of vector ZeroValues Constant evaluation often relies on the expressions being evaluated being either a Literal, or a vector Compose for which it can iterate over each component. Currently this is achieved by calling two functions: * eval_zero_value_and_splat() which transforms a scalar ZeroValue into a Literal, or a Splat or vector ZeroValue into a Compose of Literals. * proc::flatten_compose() takes potentially nested nested Compose and Splat expressions and produces an flat iterator that yields each component. eg `vec3(vec2(0), 0)` would yield `Literal(0), Literal(0), Literal(0)`. For component-wise vector operations, we can then iterate through each component of the flattened compose and apply the operation. When there are multiple operands it is crucial they have both been flattened correctly so that we use the corresponding component from each operand together. Where this falls short is if a *vector* ZeroValue is nested within a Compose. eg `vec3(vec2(), 0)`. flatten_compose() is unable to flatten this, and the resulting iterator will yield `ZeroValue, Literal(0)` This causes various issues. Take binary_op(), for example. If we attempt to add `vec3(1, 2, 3)` to our unflattenable `vec3(vec2(), 0)` this should be evaluated component-wise as 0 + 1, 0 + 2, and 0 + 3. As this has not been correctly flattened, however, we will evaluate vec2() + 1, and 0 + 2, which is simply incorrect. To solve this, we make eval_zero_value_and_splat() recursively call itself for each component if the expression is a Compose. This ensures no ZeroValues will be present during flatten_compose(), meaning it will successfully fully flatten the expression.
- Loading branch information
1 parent
bae0e70
commit adeadb6
Showing
7 changed files
with
174 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters