Commit a520c3e2 by Ben Clayton

SpirvShader: Implement GLSLstd450Atan2

Bug: b/126873455 Tests: dEQP-VK.glsl.builtin.precision.atan2.* Change-Id: I85596109069d3cee8ebd5f65770cb06ca7b93e53 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28438Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent fa6a539a
...@@ -3394,7 +3394,12 @@ namespace sw ...@@ -3394,7 +3394,12 @@ namespace sw
} }
case GLSLstd450Atan2: case GLSLstd450Atan2:
{ {
UNIMPLEMENTED("GLSLstd450Atan2"); auto x = GenericValue(this, routine, insn.word(5));
auto y = GenericValue(this, routine, insn.word(6));
for (auto i = 0u; i < type.sizeInComponents; i++)
{
dst.move(i, Atan2(x.Float(i), y.Float(i)));
}
break; break;
} }
case GLSLstd450Pow: case GLSLstd450Pow:
......
...@@ -565,6 +565,7 @@ namespace rr ...@@ -565,6 +565,7 @@ namespace rr
func_.emplace("asinhf", reinterpret_cast<void*>(asinhf)); func_.emplace("asinhf", reinterpret_cast<void*>(asinhf));
func_.emplace("acoshf", reinterpret_cast<void*>(acoshf)); func_.emplace("acoshf", reinterpret_cast<void*>(acoshf));
func_.emplace("atanhf", reinterpret_cast<void*>(atanhf)); func_.emplace("atanhf", reinterpret_cast<void*>(atanhf));
func_.emplace("atan2f", reinterpret_cast<void*>(atan2f));
#ifdef __APPLE__ #ifdef __APPLE__
// LLVM uses this function on macOS for tan. // LLVM uses this function on macOS for tan.
...@@ -3156,6 +3157,23 @@ namespace rr ...@@ -3156,6 +3157,23 @@ namespace rr
return TransformFloat4PerElement(v, "atanhf"); return TransformFloat4PerElement(v, "atanhf");
} }
RValue<Float4> Atan2(RValue<Float4> x, RValue<Float4> y)
{
auto funcTy = ::llvm::FunctionType::get(T(Float::getType()),
{T(Float::getType()), T(Float::getType())}, false);
auto func = ::module->getOrInsertFunction("atan2f", funcTy);
llvm::Value *out = ::llvm::UndefValue::get(T(Float4::getType()));
for (uint64_t i = 0; i < 4; i++)
{
auto el = ::builder->CreateCall(func, {
::builder->CreateExtractElement(V(x.value), i),
::builder->CreateExtractElement(V(y.value), i),
});
out = ::builder->CreateInsertElement(out, el, i);
}
return RValue<Float4>(V(out));
}
Type *Float4::getType() Type *Float4::getType()
{ {
return T(llvm::VectorType::get(T(Float::getType()), 4)); return T(llvm::VectorType::get(T(Float::getType()), 4));
......
...@@ -2220,6 +2220,7 @@ namespace rr ...@@ -2220,6 +2220,7 @@ namespace rr
RValue<Float4> Asinh(RValue<Float4> x); RValue<Float4> Asinh(RValue<Float4> x);
RValue<Float4> Acosh(RValue<Float4> x); RValue<Float4> Acosh(RValue<Float4> x);
RValue<Float4> Atanh(RValue<Float4> x); RValue<Float4> Atanh(RValue<Float4> x);
RValue<Float4> Atan2(RValue<Float4> x, RValue<Float4> y);
template<class T> template<class T>
class Pointer : public LValue<Pointer<T>> class Pointer : public LValue<Pointer<T>>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment