SpirvShader: Implement GLSLstd450Pow Bug: b/126873455 Tests: dEQP-VK.glsl.builtin.precision.pow.* Change-Id: I74797e69adc78e4c06ec4a8b2923b78166afbc18 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28439 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 df4c8b8..e92c8b1 100644 --- a/src/Pipeline/SpirvShader.cpp +++ b/src/Pipeline/SpirvShader.cpp
@@ -3404,7 +3404,12 @@ } case GLSLstd450Pow: { - UNIMPLEMENTED("GLSLstd450Pow"); + 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, Pow(x.Float(i), y.Float(i))); + } break; } case GLSLstd450Exp:
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp index 46abd51..c04b300 100644 --- a/src/Reactor/LLVMReactor.cpp +++ b/src/Reactor/LLVMReactor.cpp
@@ -566,6 +566,7 @@ func_.emplace("acoshf", reinterpret_cast<void*>(acoshf)); func_.emplace("atanhf", reinterpret_cast<void*>(atanhf)); func_.emplace("atan2f", reinterpret_cast<void*>(atan2f)); + func_.emplace("powf", reinterpret_cast<void*>(powf)); #ifdef __APPLE__ // LLVM uses this function on macOS for tan. @@ -3174,6 +3175,13 @@ return RValue<Float4>(V(out)); } + RValue<Float4> Pow(RValue<Float4> x, RValue<Float4> y) + { + auto func = llvm::Intrinsic::getDeclaration(::module, llvm::Intrinsic::pow, + { T(Float4::getType()), T(Float4::getType()) } ); + return RValue<Float4>(V(::builder->CreateCall(func, { V(x.value), V(y.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 a55f8c0..26b06fe 100644 --- a/src/Reactor/Reactor.hpp +++ b/src/Reactor/Reactor.hpp
@@ -2222,6 +2222,10 @@ RValue<Float4> Atanh(RValue<Float4> x); RValue<Float4> Atan2(RValue<Float4> x, RValue<Float4> y); + // Exponential functions + // TODO: Currentlhy unimplemented for Subzero. + RValue<Float4> Pow(RValue<Float4> x, RValue<Float4> y); + template<class T> class Pointer : public LValue<Pointer<T>> {