shader: Bug fix: correct type deduction from 'mat2*vec2'

Fixes #1236
This commit is contained in:
Hajime Hoshi 2020-07-04 20:07:54 +09:00
parent 6c33ed107f
commit f362455387
3 changed files with 25 additions and 3 deletions

View File

@ -912,9 +912,10 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
}
var t shaderir.Type
if lhst.Equal(&rhst) {
switch {
case lhst.Equal(&rhst):
t = lhst
} else if lhst.Main == shaderir.Float || lhst.Main == shaderir.Int {
case lhst.Main == shaderir.Float || lhst.Main == shaderir.Int:
switch rhst.Main {
case shaderir.Int:
t = lhst
@ -924,7 +925,7 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", lhst.String(), e.Op, rhst.String()))
return nil, nil, nil, false
}
} else if rhst.Main == shaderir.Float || rhst.Main == shaderir.Int {
case rhst.Main == shaderir.Float || rhst.Main == shaderir.Int:
switch lhst.Main {
case shaderir.Int:
t = rhst
@ -934,6 +935,15 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
cs.addError(e.Pos(), fmt.Sprintf("types don't match: %s %s %s", lhst.String(), e.Op, rhst.String()))
return nil, nil, nil, false
}
case lhst.Main == shaderir.Vec2 && rhst.Main == shaderir.Mat2 ||
lhst.Main == shaderir.Mat2 && rhst.Main == shaderir.Vec2:
t = shaderir.Type{Main: shaderir.Vec2}
case lhst.Main == shaderir.Vec3 && rhst.Main == shaderir.Mat3 ||
lhst.Main == shaderir.Mat3 && rhst.Main == shaderir.Vec3:
t = shaderir.Type{Main: shaderir.Vec3}
case lhst.Main == shaderir.Vec4 && rhst.Main == shaderir.Mat4 ||
lhst.Main == shaderir.Mat4 && rhst.Main == shaderir.Vec4:
t = shaderir.Type{Main: shaderir.Vec4}
}
op, ok := shaderir.OpFromToken(e.Op)

View File

@ -0,0 +1,6 @@
void F0(in vec4 l0, out vec4 l1) {
vec4 l2 = vec4(0);
l2 = (mat4(1.0)) * (l0);
l1 = l2;
return;
}

6
internal/shader/testdata/issue1236.go vendored Normal file
View File

@ -0,0 +1,6 @@
package main
func Foo(v vec4) vec4 {
v2 := mat4(1) * v
return v2
}