Skip to content

Commit

Permalink
internal/shader: bug fix: a swizzling 'r' didn't work for vec2
Browse files Browse the repository at this point in the history
Closes #2652
  • Loading branch information
hajimehoshi committed Apr 23, 2023
1 parent 420e24f commit dad36c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/shader/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 28 additions & 6 deletions internal/shader/syntax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
}

Expand Down

0 comments on commit dad36c8

Please sign in to comment.