shaderir: Bug fix: Implement atan2 for Metal correctly

Fixes #1360
This commit is contained in:
Hajime Hoshi 2020-09-22 04:29:31 +09:00
parent a3634e163a
commit 26768aa831
5 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,10 @@
void F0(float l0, float l1, thread bool& l2);
void F0(float l0, float l1, thread bool& l2) {
float l3 = float(0);
float l4 = float(0);
l3 = atan((l1) / (l0));
l4 = atan2(l1, l0);
l2 = (l3) == (l4);
return;
}

View File

@ -0,0 +1,10 @@
void F0(in float l0, in float l1, out bool l2);
void F0(in float l0, in float l1, out bool l2) {
float l3 = float(0);
float l4 = float(0);
l3 = atan((l1) / (l0));
l4 = atan(l1, l0);
l2 = (l3) == (l4);
return;
}

7
internal/shader/testdata/atan.go vendored Normal file
View File

@ -0,0 +1,7 @@
package main
func Foo(x, y float) bool {
a := atan(y / x)
b := atan2(y, x)
return a == b
}

View File

@ -65,6 +65,8 @@ func basicTypeString(t shaderir.BasicType) string {
func builtinFuncString(f shaderir.BuiltinFunc) string {
switch f {
case shaderir.Atan2:
return "atan"
case shaderir.Dfdx:
return "dFdx"
case shaderir.Dfdy:

View File

@ -220,6 +220,7 @@ const (
Asin BuiltinFunc = "asin"
Acos BuiltinFunc = "acos"
Atan BuiltinFunc = "atan"
Atan2 BuiltinFunc = "atan2"
Pow BuiltinFunc = "pow"
Exp BuiltinFunc = "exp"
Log BuiltinFunc = "log"
@ -271,6 +272,7 @@ func ParseBuiltinFunc(str string) (BuiltinFunc, bool) {
Asin,
Acos,
Atan,
Atan2,
Pow,
Exp,
Log,