Skip to content

Commit dbc31d1

Browse files
committed
Fix: Not safe to remove vector constructor if argument doesn't fully-define the type.
E.g. Good: vec2(v.xy) Bad: vec2(v.x)
1 parent b6a71c3 commit dbc31d1

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
## What Is It For?
33
GLSL Shader Shrinker is a Windows GUI tool that attempts to reduce the size of GLSL fragment shader code, whilst keeping it _readable_ and understandable.
44

5+
It is written in C# using WPF and Visual Studio 2019, and has several hundred NUnit-powered unit tests.
6+
57
![Main UI](img/ED209.png?raw=true "Main UI")
68

79
It is designed to work primarily with code from [Shadertoy](https://www.shadertoy.com/), but has limited support for other styles of GLSL too (E.g. [Bonzomatic](https://github.com/Gargaj/Bonzomatic))

ShaderShrinker/Shrinker.Parser/Optimizations/SimplifyVectorConstructorsExtension.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public static void RemoveUnnecessaryVectorConstructors(this SyntaxNode rootNode)
8888
continue; // Can't find what type of 'vec' we have, or different types.
8989
}
9090

91+
if (lhsRhs.Length >= 2 && lhsRhs[1].Length != vectorLength)
92+
continue; // RHS does not define the entire vector.
93+
9194
// They match - Remove the surrounding vecN keyword.
9295
brackets.Remove();
9396
vectorNode.ReplaceWith(vecParam);

ShaderShrinker/Shrinker.WpfApp/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949
// You can specify all the values or you can default the Build and Revision Numbers
5050
// by using the '*' as shown below:
5151
// [assembly: AssemblyVersion("1.0.*")]
52-
[assembly: AssemblyVersion("0.1.0.0")]
53-
[assembly: AssemblyFileVersion("0.1.0.0")]
52+
[assembly: AssemblyVersion("0.2.0.0")]
53+
[assembly: AssemblyFileVersion("0.2.0.0")]

ShaderShrinker/UnitTests/ShrinkerTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ public void CheckSimplifyingVec4ConstructionFromVecComponents(
10851085
"vec2 ab; vec4 v = vec4(ab, ab.x, ab.y);",
10861086
"vec2 ab; vec4 v = vec4(ab, .1, .2);",
10871087
"vec3 ab; vec2 v = vec2(ab.x, ab.z);",
1088+
"vec3 ab; vec2 v = vec2(ab.x);",
10881089
"struct S{ float A, B, C; }; S s; vec3 v = vec3(s.A, s.B, s.C);")] string code,
10891090
[Values("vec3 ab; vec4 v = vec4(ab, 1);",
10901091
"vec3 ab; vec4 v = vec4(1, ab);",
@@ -1096,6 +1097,7 @@ public void CheckSimplifyingVec4ConstructionFromVecComponents(
10961097
"vec2 ab; vec4 v = vec4(ab, ab);",
10971098
"vec2 ab; vec4 v = vec4(ab, .1, .2);",
10981099
"vec3 ab; vec2 v = ab.xz;",
1100+
"vec3 ab; vec2 v = vec2(ab.x);",
10991101
"struct S { float A, B, C; }; S s; vec3 v = vec3(s.A, s.B, s.C);")] string expected)
11001102
{
11011103
var lexer = new Lexer();

0 commit comments

Comments
 (0)