From dad36c8de8529d195b4ce5cd44fcaa45029a04ea Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 23 Apr 2023 21:29:15 +0900 Subject: [PATCH] internal/shader: bug fix: a swizzling 'r' didn't work for vec2 Closes #2652 --- internal/shader/expr.go | 2 +- internal/shader/syntax_test.go | 34 ++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/internal/shader/expr.go b/internal/shader/expr.go index e2ddeaf96bb2..96fd8ce2df4f 100644 --- a/internal/shader/expr.go +++ b/internal/shader/expr.go @@ -1178,7 +1178,7 @@ func isValidSwizzling(swizzling string, t shaderir.Type) bool { switch t.Main { case shaderir.Vec2, shaderir.IVec2: - return !strings.ContainsAny(swizzling, "zwbarq") + return !strings.ContainsAny(swizzling, "zwbapq") case shaderir.Vec3, shaderir.IVec3: return !strings.ContainsAny(swizzling, "waq") case shaderir.Vec4, shaderir.IVec4: diff --git a/internal/shader/syntax_test.go b/internal/shader/syntax_test.go index 2f2b4cf56947..d1be23c40847 100644 --- a/internal/shader/syntax_test.go +++ b/internal/shader/syntax_test.go @@ -2765,9 +2765,31 @@ func TestSyntaxSwizzling(t *testing.T) { {stmt: "var a vec2; var b vec3 = a.xyz; _ = b", err: true}, {stmt: "var a vec2; var b vec3 = a.xyw; _ = b", err: true}, {stmt: "var a vec2; var b vec3 = a.xyy; _ = b", err: false}, - {stmt: "var a vec2; var b vec3 = a.xyz; _ = b", err: true}, + {stmt: "var a vec2; var b vec3 = a.zzz; _ = b", err: true}, {stmt: "var a vec2; var b vec4 = a.xyzw; _ = b", err: true}, + {stmt: "var a vec2; var b float = a.r; _ = b", err: false}, + {stmt: "var a vec2; var b float = a.g; _ = b", err: false}, + {stmt: "var a vec2; var b float = a.b; _ = b", err: true}, + {stmt: "var a vec2; var b float = a.a; _ = b", err: true}, + {stmt: "var a vec2; var b vec2 = a.rg; _ = b", err: false}, + {stmt: "var a vec2; var b vec3 = a.rgb; _ = b", err: true}, + {stmt: "var a vec2; var b vec3 = a.rga; _ = b", err: true}, + {stmt: "var a vec2; var b vec3 = a.rgg; _ = b", err: false}, + {stmt: "var a vec2; var b vec3 = a.bbb; _ = b", err: true}, + {stmt: "var a vec2; var b vec4 = a.rgba; _ = b", err: true}, + + {stmt: "var a vec2; var b float = a.s; _ = b", err: false}, + {stmt: "var a vec2; var b float = a.t; _ = b", err: false}, + {stmt: "var a vec2; var b float = a.p; _ = b", err: true}, + {stmt: "var a vec2; var b float = a.q; _ = b", err: true}, + {stmt: "var a vec2; var b vec2 = a.st; _ = b", err: false}, + {stmt: "var a vec2; var b vec3 = a.stp; _ = b", err: true}, + {stmt: "var a vec2; var b vec3 = a.stq; _ = b", err: true}, + {stmt: "var a vec2; var b vec3 = a.stt; _ = b", err: false}, + {stmt: "var a vec2; var b vec3 = a.ppp; _ = b", err: true}, + {stmt: "var a vec2; var b vec4 = a.stpq; _ = b", err: true}, + {stmt: "var a vec3; var b float = a.x; _ = b", err: false}, {stmt: "var a vec3; var b float = a.y; _ = b", err: false}, {stmt: "var a vec3; var b float = a.z; _ = b", err: false}, @@ -2776,7 +2798,7 @@ func TestSyntaxSwizzling(t *testing.T) { {stmt: "var a vec3; var b vec3 = a.xyz; _ = b", err: false}, {stmt: "var a vec3; var b vec3 = a.xyw; _ = b", err: true}, {stmt: "var a vec3; var b vec3 = a.xyy; _ = b", err: false}, - {stmt: "var a vec3; var b vec3 = a.xyz; _ = b", err: false}, + {stmt: "var a vec3; var b vec3 = a.zzz; _ = b", err: false}, {stmt: "var a vec3; var b vec4 = a.xyzw; _ = b", err: true}, {stmt: "var a vec4; var b float = a.x; _ = b", err: false}, @@ -2787,7 +2809,7 @@ func TestSyntaxSwizzling(t *testing.T) { {stmt: "var a vec4; var b vec3 = a.xyz; _ = b", err: false}, {stmt: "var a vec4; var b vec3 = a.xyw; _ = b", err: false}, {stmt: "var a vec4; var b vec3 = a.xyy; _ = b", err: false}, - {stmt: "var a vec4; var b vec3 = a.xyz; _ = b", err: false}, + {stmt: "var a vec4; var b vec3 = a.zzz; _ = b", err: false}, {stmt: "var a vec4; var b vec4 = a.xyzw; _ = b", err: false}, {stmt: "var a ivec2; var b int = a.x; _ = b", err: false}, @@ -2798,7 +2820,7 @@ func TestSyntaxSwizzling(t *testing.T) { {stmt: "var a ivec2; var b ivec3 = a.xyz; _ = b", err: true}, {stmt: "var a ivec2; var b ivec3 = a.xyw; _ = b", err: true}, {stmt: "var a ivec2; var b ivec3 = a.xyy; _ = b", err: false}, - {stmt: "var a ivec2; var b ivec3 = a.xyz; _ = b", err: true}, + {stmt: "var a ivec2; var b ivec3 = a.zzz; _ = b", err: true}, {stmt: "var a ivec2; var b ivec4 = a.xyzw; _ = b", err: true}, {stmt: "var a ivec3; var b int = a.x; _ = b", err: false}, @@ -2809,7 +2831,7 @@ func TestSyntaxSwizzling(t *testing.T) { {stmt: "var a ivec3; var b ivec3 = a.xyz; _ = b", err: false}, {stmt: "var a ivec3; var b ivec3 = a.xyw; _ = b", err: true}, {stmt: "var a ivec3; var b ivec3 = a.xyy; _ = b", err: false}, - {stmt: "var a ivec3; var b ivec3 = a.xyz; _ = b", err: false}, + {stmt: "var a ivec3; var b ivec3 = a.zzz; _ = b", err: false}, {stmt: "var a ivec3; var b ivec4 = a.xyzw; _ = b", err: true}, {stmt: "var a ivec4; var b int = a.x; _ = b", err: false}, @@ -2820,7 +2842,7 @@ func TestSyntaxSwizzling(t *testing.T) { {stmt: "var a ivec4; var b ivec3 = a.xyz; _ = b", err: false}, {stmt: "var a ivec4; var b ivec3 = a.xyw; _ = b", err: false}, {stmt: "var a ivec4; var b ivec3 = a.xyy; _ = b", err: false}, - {stmt: "var a ivec4; var b ivec3 = a.xyz; _ = b", err: false}, + {stmt: "var a ivec4; var b ivec3 = a.zzz; _ = b", err: false}, {stmt: "var a ivec4; var b ivec4 = a.xyzw; _ = b", err: false}, }