forked from laurentlb/shader-minifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix potential unsafe swizzle optimizations
The optimization in laurentlb#253 is unsafe -- `vec3(a.x)` and `vec3(x)` are not equivalent. For a single-element swizzles, they are only sure to be safe if they are the Nth argument to a vecN constructor. This change counts the number of arguments, and only allows a single-element swizzle to be optimized in that case. This does miss some edge cases -- for example, I think the swizzle in code like `vec3(foo.xy, bar.x)` is safe to remove (`vec3(foo.xy, bar)`) but that doesn't seem to actually happen in any of the examples in this repo, and it's super tricky to get right in practise (if `foo.xy` is some variable instead of a swizzle right there), etc etc. So there is potentially still something on the table, but at least for the cases available this is good enough for now. Fixes laurentlb#297
- Loading branch information
Showing
3 changed files
with
24 additions
and
6 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