summaryrefslogtreecommitdiff
path: root/indra/llmath
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmath')
-rw-r--r--indra/llmath/CMakeLists.txt10
-rw-r--r--indra/llmath/llcalcparser.h6
-rw-r--r--indra/llmath/llmath.h4
-rw-r--r--indra/llmath/llmatrix3a.cpp2
-rw-r--r--indra/llmath/llmatrix4a.cpp2
-rw-r--r--indra/llmath/llrigginginfo.cpp2
-rw-r--r--indra/llmath/llsimdmath.h6
-rw-r--r--indra/llmath/llvector4a.cpp2
-rw-r--r--indra/llmath/llvector4a.h13
-rw-r--r--indra/llmath/llvolume.cpp45
-rw-r--r--indra/llmath/llvolumeoctree.cpp2
-rw-r--r--indra/llmath/v3colorutil.h1
-rw-r--r--indra/llmath/v3math.h51
-rw-r--r--indra/llmath/v4math.h51
14 files changed, 186 insertions, 11 deletions
diff --git a/indra/llmath/CMakeLists.txt b/indra/llmath/CMakeLists.txt
index eb29df245a..c0a62ad225 100644
--- a/indra/llmath/CMakeLists.txt
+++ b/indra/llmath/CMakeLists.txt
@@ -59,6 +59,7 @@ set(llmath_HEADER_FILES
llmath.h
llmatrix3a.h
llmatrix3a.inl
+ llmatrix4a.h
llmodularmath.h
lloctree.h
llperlin.h
@@ -97,11 +98,20 @@ set(llmath_HEADER_FILES
list(APPEND llmath_SOURCE_FILES ${llmath_HEADER_FILES})
+include_directories(${LIBS_PREBUILT_DIR}/include)
+
add_library (llmath ${llmath_SOURCE_FILES})
target_link_libraries(llmath llcommon llmeshoptimizer)
target_include_directories( llmath INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
+if (USESYSTEMLIBS AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ set_source_files_properties(llcalc.cpp PROPERTIES
+ COMPILE_FLAGS -Wno-dangling-pointer)
+endif ()
+
+include(LibraryInstall)
+
# Add tests
if (LL_TESTS)
include(LLAddBuildTest)
diff --git a/indra/llmath/llcalcparser.h b/indra/llmath/llcalcparser.h
index ea71752ebc..ec7f6a2cb6 100644
--- a/indra/llmath/llcalcparser.h
+++ b/indra/llmath/llcalcparser.h
@@ -131,14 +131,14 @@ struct LLCalcParser : grammar<LLCalcParser>
power =
unary_expr[power.value = arg1] >>
- *('^' >> assert_syntax(unary_expr[power.value = phoenix::bind(&powf)(power.value, arg1)]))
+ *('^' >> assert_syntax(unary_expr[power.value = phoenix::bind(&LLCalcParser::_pow)(self, power.value, arg1)]))
;
term =
power[term.value = arg1] >>
*(('*' >> assert_syntax(power[term.value *= arg1])) |
('/' >> assert_syntax(power[term.value /= arg1])) |
- ('%' >> assert_syntax(power[term.value = phoenix::bind(&fmodf)(term.value, arg1)]))
+ ('%' >> assert_syntax(power[term.value = phoenix::bind(&LLCalcParser::_fmod)(self, term.value, arg1)]))
)
;
@@ -177,6 +177,8 @@ private:
F32 _floor(const F32& a) const { return (F32)llfloor(a); }
F32 _ceil(const F32& a) const { return (F32)llceil(a); }
F32 _atan2(const F32& a,const F32& b) const { return atan2(a,b); }
+ F32 _pow(const F32& a, const F32& b) const { return powf(a, b); }
+ F32 _fmod(const F32&a, const F32& b) const { return fmodf(a, b); }
LLCalc::calc_map_t* mConstants;
LLCalc::calc_map_t* mVariables;
diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h
index fa315291a3..a72993a21a 100644
--- a/indra/llmath/llmath.h
+++ b/indra/llmath/llmath.h
@@ -358,10 +358,14 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs)
return new_foo;
}
+#ifdef __GNUC__
+using std::lerp;
+#else
inline F32 lerp(F32 a, F32 b, F32 u)
{
return a + ((b - a) * u);
}
+#endif
inline F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
{
diff --git a/indra/llmath/llmatrix3a.cpp b/indra/llmath/llmatrix3a.cpp
index 48a72e71e1..c0b00201cf 100644
--- a/indra/llmath/llmatrix3a.cpp
+++ b/indra/llmath/llmatrix3a.cpp
@@ -24,6 +24,8 @@
* $/LicenseInfo$
*/
+#include "linden_common.h"
+
#include "llmath.h"
static LL_ALIGN_16(const F32 M_IDENT_3A[12]) =
diff --git a/indra/llmath/llmatrix4a.cpp b/indra/llmath/llmatrix4a.cpp
index 00e30a248b..bfb4c2b07a 100644
--- a/indra/llmath/llmatrix4a.cpp
+++ b/indra/llmath/llmatrix4a.cpp
@@ -24,6 +24,8 @@
* $/LicenseInfo$
*/
+#include "linden_common.h"
+
#include "llmath.h"
#include "llmatrix4a.h"
diff --git a/indra/llmath/llrigginginfo.cpp b/indra/llmath/llrigginginfo.cpp
index 23dbddd78e..2f59f685d5 100644
--- a/indra/llmath/llrigginginfo.cpp
+++ b/indra/llmath/llrigginginfo.cpp
@@ -24,6 +24,8 @@
* $/LicenseInfo$
*/
+#include "linden_common.h"
+
#include "llmath.h"
#include "llrigginginfo.h"
diff --git a/indra/llmath/llsimdmath.h b/indra/llmath/llsimdmath.h
index 40953dc2e8..590d8de92f 100644
--- a/indra/llmath/llsimdmath.h
+++ b/indra/llmath/llsimdmath.h
@@ -31,7 +31,7 @@
#error "Please include llmath.h before this file."
#endif
-#if ( ( LL_DARWIN || LL_LINUX ) && !(__SSE2__) ) || ( LL_WINDOWS && ( _M_IX86_FP < 2 && ADDRESS_SIZE == 32 ) )
+#if ( ( LL_DARWIN || LL_LINUX ) && !(__SSE2__ || __ARM_NEON) ) || ( LL_WINDOWS && ( _M_IX86_FP < 2 && ADDRESS_SIZE == 32 ) )
#error SSE2 not enabled. LLVector4a and related class will not compile.
#endif
@@ -39,8 +39,12 @@
#include <stdint.h>
#endif
+#if defined(__i386__) || defined(__x86_64__)
#include <xmmintrin.h>
#include <emmintrin.h>
+#else
+#include <sse2neon.h>
+#endif
#include "llmemory.h"
#include "llsimdtypes.h"
diff --git a/indra/llmath/llvector4a.cpp b/indra/llmath/llvector4a.cpp
index 0ac91366b6..b81d50f0f9 100644
--- a/indra/llmath/llvector4a.cpp
+++ b/indra/llmath/llvector4a.cpp
@@ -24,6 +24,8 @@
* $/LicenseInfo$
*/
+#include "linden_common.h"
+
#include "llmemory.h"
#include "llmath.h"
#include "llquantize.h"
diff --git a/indra/llmath/llvector4a.h b/indra/llmath/llvector4a.h
index 8ef560dadf..4004852e06 100644
--- a/indra/llmath/llvector4a.h
+++ b/indra/llmath/llvector4a.h
@@ -33,6 +33,9 @@ class LLRotation;
#include <assert.h>
#include "llpreprocessor.h"
#include "llmemory.h"
+#include "glm/vec3.hpp"
+#include "glm/vec4.hpp"
+#include "glm/gtc/type_ptr.hpp"
///////////////////////////////////
// FIRST TIME USERS PLEASE READ
@@ -364,6 +367,16 @@ public:
inline operator LLQuad() const;
+ explicit inline operator glm::vec3() const
+ {
+ return glm::make_vec3(getF32ptr());
+ };
+
+ explicit inline operator glm::vec4() const
+ {
+ return glm::make_vec4(getF32ptr());
+ };
+
private:
LLQuad mQ{};
};
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index 44b6e7923b..6335da5b62 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -55,7 +55,11 @@
#include "mikktspace/mikktspace.hh"
+#if LL_USESYSTEMLIBS
+#include <meshoptimizer.h>
+#else
#include "meshoptimizer/meshoptimizer.h"
+#endif
#define DEBUG_SILHOUETTE_BINORMALS 0
#define DEBUG_SILHOUETTE_NORMALS 0 // TomY: Use this to display normals using the silhouette
@@ -5586,14 +5590,22 @@ struct MikktData
{
U32 count = face->mNumIndices;
- p.resize(count);
- n.resize(count);
- tc.resize(count);
- t.resize(count);
+ try
+ {
+ p.resize(count);
+ n.resize(count);
+ tc.resize(count);
+ t.resize(count);
- if (face->mWeights)
+ if (face->mWeights)
+ {
+ w.resize(count);
+ }
+ }
+ catch (std::bad_alloc&)
{
- w.resize(count);
+ LLError::LLUserWarningMsg::showOutOfMemory();
+ LL_ERRS("LLCoros") << "Bad memory allocation in MikktData, elements count: " << count << LL_ENDL;
}
@@ -5665,7 +5677,16 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents)
// and is executed on a background thread
MikktData data(this);
mikk::Mikktspace ctx(data);
- ctx.genTangSpace();
+ try
+ {
+ ctx.genTangSpace();
+ }
+ catch (std::bad_alloc&)
+ {
+ LLError::LLUserWarningMsg::showOutOfMemory();
+ LL_ERRS("LLCoros") << "Bad memory allocation in MikktData::genTangSpace" << LL_ENDL;
+ }
+
//re-weld
meshopt_Stream mos[] =
@@ -5678,7 +5699,15 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents)
};
std::vector<U32> remap;
- remap.resize(data.p.size());
+ try
+ {
+ remap.resize(data.p.size());
+ }
+ catch (std::bad_alloc&)
+ {
+ LLError::LLUserWarningMsg::showOutOfMemory();
+ LL_ERRS("LLCoros") << "Failed to allocate memory for remap: " << (S32)data.p.size() << LL_ENDL;
+ }
U32 stream_count = data.w.empty() ? 4 : 5;
diff --git a/indra/llmath/llvolumeoctree.cpp b/indra/llmath/llvolumeoctree.cpp
index 71288daa89..141317ee8d 100644
--- a/indra/llmath/llvolumeoctree.cpp
+++ b/indra/llmath/llvolumeoctree.cpp
@@ -24,6 +24,8 @@
* $/LicenseInfo$
*/
+#include "linden_common.h"
+
#include "llvolumeoctree.h"
#include "llvector4a.h"
diff --git a/indra/llmath/v3colorutil.h b/indra/llmath/v3colorutil.h
index 62005f76a0..af8799e42a 100644
--- a/indra/llmath/v3colorutil.h
+++ b/indra/llmath/v3colorutil.h
@@ -28,6 +28,7 @@
#define LL_V3COLORUTIL_H
#include "v3color.h"
+#include "v4color.h"
inline LLColor3 componentDiv(LLColor3 const &left, LLColor3 const & right)
{
diff --git a/indra/llmath/v3math.h b/indra/llmath/v3math.h
index d063b15c74..a3bfa68060 100644
--- a/indra/llmath/v3math.h
+++ b/indra/llmath/v3math.h
@@ -31,6 +31,11 @@
#include "llmath.h"
#include "llsd.h"
+
+#include "glm/vec3.hpp"
+#include "glm/vec4.hpp"
+#include "glm/gtc/type_ptr.hpp"
+
class LLVector2;
class LLVector4;
class LLVector4a;
@@ -66,6 +71,11 @@ class LLVector3
explicit LLVector3(const LLVector4a& vec); // Initializes LLVector4 to (vec[0]. vec[1], vec[2])
explicit LLVector3(const LLSD& sd);
+ // GLM interop
+ explicit LLVector3(const glm::vec3& vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2])
+ explicit LLVector3(const glm::vec4& vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2])
+ explicit inline operator glm::vec3() const; // Initializes glm::vec3 to (vec[0]. vec[1], vec[2])
+ explicit inline operator glm::vec4() const; // Initializes glm::vec4 to (vec[0]. vec[1], vec[2], 1)
LLSD getValue() const;
@@ -92,6 +102,8 @@ class LLVector3
inline void set(const F32 *vec); // Sets LLVector3 to vec
const LLVector3& set(const LLVector4 &vec);
const LLVector3& set(const LLVector3d &vec);// Sets LLVector3 to vec
+ inline void set(const glm::vec4& vec); // Sets LLVector3 to vec
+ inline void set(const glm::vec3& vec); // Sets LLVector3 to vec
inline void setVec(F32 x, F32 y, F32 z); // deprecated
inline void setVec(const LLVector3 &vec); // deprecated
@@ -190,6 +202,20 @@ inline LLVector3::LLVector3(const F32 *vec)
mV[VZ] = vec[VZ];
}
+inline LLVector3::LLVector3(const glm::vec3& vec)
+{
+ mV[VX] = vec.x;
+ mV[VY] = vec.y;
+ mV[VZ] = vec.z;
+}
+
+inline LLVector3::LLVector3(const glm::vec4& vec)
+{
+ mV[VX] = vec.x;
+ mV[VY] = vec.y;
+ mV[VZ] = vec.z;
+}
+
/*
inline LLVector3::LLVector3(const LLVector3 &copy)
{
@@ -259,6 +285,20 @@ inline void LLVector3::set(const F32 *vec)
mV[2] = vec[2];
}
+inline void LLVector3::set(const glm::vec4& vec)
+{
+ mV[VX] = vec.x;
+ mV[VY] = vec.y;
+ mV[VZ] = vec.z;
+}
+
+inline void LLVector3::set(const glm::vec3& vec)
+{
+ mV[VX] = vec.x;
+ mV[VY] = vec.y;
+ mV[VZ] = vec.z;
+}
+
// deprecated
inline void LLVector3::setVec(F32 x, F32 y, F32 z)
{
@@ -471,6 +511,17 @@ inline LLVector3 operator-(const LLVector3 &a)
return LLVector3( -a.mV[0], -a.mV[1], -a.mV[2] );
}
+inline LLVector3::operator glm::vec3() const
+{
+ // Do not use glm::make_vec3 it can result in a buffer overrun on some platforms due to glm::vec3 being a simd vector internally
+ return glm::vec3(mV[VX], mV[VY], mV[VZ]);
+}
+
+inline LLVector3::operator glm::vec4() const
+{
+ return glm::vec4(mV[VX], mV[VY], mV[VZ], 1.f);
+}
+
inline F32 dist_vec(const LLVector3 &a, const LLVector3 &b)
{
F32 x = a.mV[0] - b.mV[0];
diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h
index a5b6f506d7..a4c9668fdd 100644
--- a/indra/llmath/v4math.h
+++ b/indra/llmath/v4math.h
@@ -32,6 +32,10 @@
#include "v3math.h"
#include "v2math.h"
+#include "glm/vec3.hpp"
+#include "glm/vec4.hpp"
+#include "glm/gtc/type_ptr.hpp"
+
class LLMatrix3;
class LLMatrix4;
class LLQuaternion;
@@ -73,6 +77,11 @@ class LLVector4
mV[3] = (F32)sd[3].asReal();
}
+ // GLM interop
+ explicit LLVector4(const glm::vec3& vec); // Initializes LLVector4 to (vec, 1)
+ explicit LLVector4(const glm::vec4& vec); // Initializes LLVector4 to vec
+ explicit operator glm::vec3() const; // Initializes glm::vec3 to (vec[0]. vec[1], vec[2])
+ explicit operator glm::vec4() const; // Initializes glm::vec4 to (vec[0]. vec[1], vec[2], vec[3])
inline bool isFinite() const; // checks to see if all values of LLVector3 are finite
@@ -85,6 +94,8 @@ class LLVector4
inline void set(const LLVector4 &vec); // Sets LLVector4 to vec
inline void set(const LLVector3 &vec, F32 w = 1.f); // Sets LLVector4 to LLVector3 vec
inline void set(const F32 *vec); // Sets LLVector4 to vec
+ inline void set(const glm::vec4& vec); // Sets LLVector4 to vec
+ inline void set(const glm::vec3& vec, F32 w = 1.f); // Sets LLVector4 to LLVector3 vec with w defaulted to 1
inline void setVec(F32 x, F32 y, F32 z); // deprecated
inline void setVec(F32 x, F32 y, F32 z, F32 w); // deprecated
@@ -223,6 +234,21 @@ inline LLVector4::LLVector4(const LLSD &sd)
setValue(sd);
}
+inline LLVector4::LLVector4(const glm::vec3& vec)
+{
+ mV[VX] = vec.x;
+ mV[VY] = vec.y;
+ mV[VZ] = vec.z;
+ mV[VW] = 1.f;
+}
+
+inline LLVector4::LLVector4(const glm::vec4& vec)
+{
+ mV[VX] = vec.x;
+ mV[VY] = vec.y;
+ mV[VZ] = vec.z;
+ mV[VW] = vec.w;
+}
inline bool LLVector4::isFinite() const
{
@@ -297,6 +323,21 @@ inline void LLVector4::set(const F32 *vec)
mV[VW] = vec[VW];
}
+inline void LLVector4::set(const glm::vec4& vec)
+{
+ mV[VX] = vec.x;
+ mV[VY] = vec.y;
+ mV[VZ] = vec.z;
+ mV[VW] = vec.w;
+}
+
+inline void LLVector4::set(const glm::vec3& vec, F32 w)
+{
+ mV[VX] = vec.x;
+ mV[VY] = vec.y;
+ mV[VZ] = vec.z;
+ mV[VW] = w;
+}
// deprecated
inline void LLVector4::setVec(F32 x, F32 y, F32 z)
@@ -466,6 +507,16 @@ inline LLVector4 operator-(const LLVector4 &a)
return LLVector4( -a.mV[VX], -a.mV[VY], -a.mV[VZ] );
}
+inline LLVector4::operator glm::vec3() const
+{
+ return glm::vec3(mV[VX], mV[VY], mV[VZ]);
+}
+
+inline LLVector4::operator glm::vec4() const
+{
+ return glm::make_vec4(mV);
+}
+
inline F32 dist_vec(const LLVector4 &a, const LLVector4 &b)
{
LLVector4 vec = a - b;