internal/shader: Add more tests for const

Updates #1847
This commit is contained in:
Hajime Hoshi 2021-11-14 16:24:26 +09:00
parent 36ce3b836e
commit 9be4ce928b
3 changed files with 54 additions and 7 deletions

View File

@ -200,13 +200,6 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
cs.addError(e.Pos(), fmt.Sprintf("single-value context and multiple-value context cannot be mixed: %s", e.Fun))
return nil, nil, nil, false
}
// If the argument is a non-typed constant value, treat is as a float value (#1874).
for i, e := range es {
if e.Type == shaderir.NumberExpr && e.ConstType == shaderir.ConstTypeNone {
e.ConstType = shaderir.ConstTypeFloat
ts[i] = shaderir.Type{Main: shaderir.Float}
}
}
args = append(args, es...)
argts = append(argts, ts...)
stmts = append(stmts, ss...)
@ -276,6 +269,11 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
case shaderir.Texture2DF:
t = shaderir.Type{Main: shaderir.Vec4}
default:
// If the argument is a non-typed constant value, treat is as a float value (#1874).
if args[0].Type == shaderir.NumberExpr && args[0].ConstType == shaderir.ConstTypeNone {
args[0].ConstType = shaderir.ConstTypeFloat
argts[0] = shaderir.Type{Main: shaderir.Float}
}
t = argts[0]
}
return []shaderir.Expr{

View File

@ -0,0 +1,28 @@
void F0(in int l0, out int l1);
void F1(in float l0, out float l1);
void F2(out int l0);
void F3(out float l0);
void F0(in int l0, out int l1) {
l1 = (1) + (l0);
return;
}
void F1(in float l0, out float l1) {
l1 = (1.0) + (l0);
return;
}
void F2(out int l0) {
int l1 = 0;
F0(1, l1);
l0 = l1;
return;
}
void F3(out float l0) {
float l1 = float(0);
F1(1.0, l1);
l0 = l1;
return;
}

21
internal/shader/testdata/const4.go vendored Normal file
View File

@ -0,0 +1,21 @@
package main
func Foo(x int) int {
const a = 1
return a + x
}
func Bar(x float) float {
const a = 1
return a + x
}
func Baz() int {
const a = 1
return Foo(a)
}
func Qux() float {
const a = 1
return Bar(a)
}