SpirvShader: Implement GLSLstd450Sin
Bug: b/126873455
Tests: dEQP-VK.glsl.builtin.precision.sin.*
Change-Id: Iec96b2a235534fbc5b76c699a6b62679b75582ca
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28668
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 890e7ba..7975872 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -3284,6 +3284,15 @@
}
break;
}
+ case GLSLstd450Sin:
+ {
+ auto radians = GenericValue(this, routine, insn.word(5));
+ for (auto i = 0u; i < type.sizeInComponents; i++)
+ {
+ dst.move(i, Sin(radians.Float(i)));
+ }
+ break;
+ }
default:
UNIMPLEMENTED("Unhandled ExtInst %d", extInstIndex);
}
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index 55ca049..abe35df 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -554,6 +554,7 @@
func_.emplace("printf", reinterpret_cast<void*>(printf));
func_.emplace("puts", reinterpret_cast<void*>(puts));
func_.emplace("fmodf", reinterpret_cast<void*>(fmodf));
+ func_.emplace("sinf", reinterpret_cast<void*>(sinf));
}
void *findSymbol(const std::string &name) const
@@ -3063,6 +3064,12 @@
}
}
+ RValue<Float4> Sin(RValue<Float4> v)
+ {
+ auto func = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::sin, { 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 bb32a46..41e15c8 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -2206,6 +2206,10 @@
RValue<Float4> Floor(RValue<Float4> x);
RValue<Float4> Ceil(RValue<Float4> x);
+ // Trigonometric functions
+ // TODO: Currentlhy unimplemented for Subzero.
+ RValue<Float4> Sin(RValue<Float4> x);
+
template<class T>
class Pointer : public LValue<Pointer<T>>
{