SpirvShader: Implement GLSLstd450Cos
Bug: b/126873455
Tests: dEQP-VK.glsl.builtin.precision.cos.*
Change-Id: I4b5fe36487f0832ad21f3e78df9ba133284cffbd
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28669
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 7975872..ad3d08f 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -3293,6 +3293,15 @@
}
break;
}
+ case GLSLstd450Cos:
+ {
+ auto radians = GenericValue(this, routine, insn.word(5));
+ for (auto i = 0u; i < type.sizeInComponents; i++)
+ {
+ dst.move(i, Cos(radians.Float(i)));
+ }
+ break;
+ }
default:
UNIMPLEMENTED("Unhandled ExtInst %d", extInstIndex);
}
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index abe35df..578dfa1 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -555,6 +555,7 @@
func_.emplace("puts", reinterpret_cast<void*>(puts));
func_.emplace("fmodf", reinterpret_cast<void*>(fmodf));
func_.emplace("sinf", reinterpret_cast<void*>(sinf));
+ func_.emplace("cosf", reinterpret_cast<void*>(cosf));
}
void *findSymbol(const std::string &name) const
@@ -3070,6 +3071,12 @@
return RValue<Float4>(V(::builder->CreateCall(func, V(v.value))));
}
+ RValue<Float4> Cos(RValue<Float4> v)
+ {
+ auto func = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::cos, { V(v.value)->getType() } );
+ return RValue<Float4>(V(::builder->CreateCall(func, V(v.value))));
+ }
+
Type *Float4::getType()
{
return T(llvm::VectorType::get(T(Float::getType()), 4));
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index 41e15c8..2419dbe 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -2209,6 +2209,7 @@
// Trigonometric functions
// TODO: Currentlhy unimplemented for Subzero.
RValue<Float4> Sin(RValue<Float4> x);
+ RValue<Float4> Cos(RValue<Float4> x);
template<class T>
class Pointer : public LValue<Pointer<T>>