Skip to content

Commit

Permalink
shaderir: Bug fix: Implement atan2 for Metal correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Sep 21, 2020
1 parent a3634e1 commit 26768aa
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/shader/testdata/atan.expected.metal
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 10 additions & 0 deletions internal/shader/testdata/atan.expected.vs
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions internal/shader/testdata/atan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

func Foo(x, y float) bool {
a := atan(y / x)
b := atan2(y, x)
return a == b
}
2 changes: 2 additions & 0 deletions internal/shaderir/glsl/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions internal/shaderir/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -271,6 +272,7 @@ func ParseBuiltinFunc(str string) (BuiltinFunc, bool) {
Asin,
Acos,
Atan,
Atan2,
Pow,
Exp,
Log,
Expand Down

0 comments on commit 26768aa

Please sign in to comment.