From be15cf5457ed6b2fde61ecffa667928ad0c21854 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Sat, 19 Feb 2022 02:15:00 +0100 Subject: [PATCH] LibSoftGPU: Add ddx() and ddy() to calculate partial derivatives --- Userland/Libraries/LibSoftGPU/SIMD.h | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Userland/Libraries/LibSoftGPU/SIMD.h b/Userland/Libraries/LibSoftGPU/SIMD.h index 66ade79d50..4e16c92c25 100644 --- a/Userland/Libraries/LibSoftGPU/SIMD.h +++ b/Userland/Libraries/LibSoftGPU/SIMD.h @@ -67,4 +67,40 @@ ALWAYS_INLINE static constexpr Vector4 expand4(Vector4 con }; } +ALWAYS_INLINE static AK::SIMD::f32x4 ddx(AK::SIMD::f32x4 v) +{ + return AK::SIMD::f32x4 { + v[1] - v[0], + v[1] - v[0], + v[3] - v[2], + v[3] - v[2], + }; +} + +ALWAYS_INLINE static AK::SIMD::f32x4 ddy(AK::SIMD::f32x4 v) +{ + return AK::SIMD::f32x4 { + v[2] - v[0], + v[3] - v[1], + v[2] - v[0], + v[3] - v[1], + }; +} + +ALWAYS_INLINE static Vector2 ddx(Vector2 const& v) +{ + return { + ddx(v.x()), + ddx(v.y()), + }; +} + +ALWAYS_INLINE static Vector2 ddy(Vector2 const& v) +{ + return { + ddy(v.x()), + ddy(v.y()), + }; +} + }