Просмотр исходного кода

Merge branch 'master' of github.com:bkaradzic/bx

Бранимир Караџић 7 лет назад
Родитель
Сommit
99de60e99d
4 измененных файлов с 41 добавлено и 29 удалено
  1. 10 19
      include/bx/inline/math.inl
  2. 3 6
      include/bx/math.h
  3. 21 4
      tests/nlalloc_test.cpp
  4. 7 0
      tests/uint32_test.cpp

+ 10 - 19
include/bx/inline/math.inl

@@ -361,6 +361,16 @@ namespace bx
 		memCopy(_ptr, &_a, sizeof(Ty) );
 	}
 
+	inline BX_CONSTEXPR_FUNC Vec3 round(const Vec3 _a)
+	{
+		return
+		{
+			round(_a.x),
+			round(_a.y),
+			round(_a.z),
+		};
+	}
+
 	inline BX_CONSTEXPR_FUNC Vec3 abs(const Vec3 _a)
 	{
 		return
@@ -929,25 +939,6 @@ namespace bx
 		return result;
 	}
 
-	inline void vec3MulMtx(float* _result, const float* _vec, const float* _mat)
-	{
-		_result[0] = _vec[0] * _mat[ 0] + _vec[1] * _mat[4] + _vec[2] * _mat[ 8] + _mat[12];
-		_result[1] = _vec[0] * _mat[ 1] + _vec[1] * _mat[5] + _vec[2] * _mat[ 9] + _mat[13];
-		_result[2] = _vec[0] * _mat[ 2] + _vec[1] * _mat[6] + _vec[2] * _mat[10] + _mat[14];
-	}
-
-	inline void vec3MulMtxH(float* _result, const float* _vec, const float* _mat)
-	{
-		float xx = _vec[0] * _mat[ 0] + _vec[1] * _mat[4] + _vec[2] * _mat[ 8] + _mat[12];
-		float yy = _vec[0] * _mat[ 1] + _vec[1] * _mat[5] + _vec[2] * _mat[ 9] + _mat[13];
-		float zz = _vec[0] * _mat[ 2] + _vec[1] * _mat[6] + _vec[2] * _mat[10] + _mat[14];
-		float ww = _vec[0] * _mat[ 3] + _vec[1] * _mat[7] + _vec[2] * _mat[11] + _mat[15];
-		float invW = sign(ww)/ww;
-		_result[0] = xx*invW;
-		_result[1] = yy*invW;
-		_result[2] = zz*invW;
-	}
-
 	inline void vec4MulMtx(float* _result, const float* _vec, const float* _mat)
 	{
 		_result[0] = _vec[0] * _mat[ 0] + _vec[1] * _mat[4] + _vec[2] * _mat[ 8] + _vec[3] * _mat[12];

+ 3 - 6
include/bx/math.h

@@ -281,6 +281,9 @@ namespace bx
 	template<typename Ty>
 	void store(void* _ptr, const Ty& _a);
 
+	///
+	BX_CONSTEXPR_FUNC Vec3 round(const Vec3 _a);
+
 	///
 	BX_CONSTEXPR_FUNC Vec3 abs(const Vec3 _a);
 
@@ -530,12 +533,6 @@ namespace bx
 	///
 	Vec3 mulH(const Vec3& _vec, const float* _mat);
 
-	///
-	void vec3MulMtx(float* _result, const float* _vec, const float* _mat);
-
-	///
-	void vec3MulMtxH(float* _result, const float* _vec, const float* _mat);
-
 	///
 	void vec4MulMtx(float* _result, const float* _vec, const float* _mat);
 

+ 21 - 4
tests/nlalloc_test.cpp

@@ -34,7 +34,7 @@ namespace bx
 {
 	struct Blk
 	{
-		static const uint64_t kInvalid = UINT64_MAX;
+		static constexpr uint64_t kInvalid = UINT64_MAX;
 
 		Blk()
 			: ptr(kInvalid)
@@ -66,6 +66,8 @@ namespace bx
 	class NonLocalAllocator
 	{
 	public:
+		static constexpr uint32_t kMinBlockSize = 16u;
+
 		NonLocalAllocator()
 		{
 			reset();
@@ -102,13 +104,13 @@ namespace bx
 
 		Blk alloc(uint32_t _size)
 		{
-			_size = max(_size, 16u);
+			_size = max(_size, kMinBlockSize);
 
 			for (FreeList::iterator it = m_free.begin(), itEnd = m_free.end(); it != itEnd; ++it)
 			{
 				if (it->size >= _size)
 				{
-					uint64_t ptr = it->ptr;
+					const uint64_t ptr = it->ptr;
 
 					if (it->size != _size)
 					{
@@ -121,6 +123,7 @@ namespace bx
 					}
 
 					m_used += _size;
+
 					return Blk{ ptr, _size };
 				}
 			}
@@ -142,7 +145,8 @@ namespace bx
 				  m_free.begin()
 				, uint32_t(m_free.end() - m_free.begin() )
 				, sizeof(Blk)
-				, [](const void* _a, const void* _b) -> int32_t {
+				, [](const void* _a, const void* _b) -> int32_t
+				{
 					const Blk& lhs = *(const Blk*)(_a);
 					const Blk& rhs = *(const Blk*)(_b);
 					return lhs < rhs ? -1 : 1;
@@ -175,6 +179,9 @@ namespace bx
 		FreeList m_free;
 		uint32_t m_used;
 	};
+
+	constexpr uint32_t NonLocalAllocator::kMinBlockSize;
+
 } // namespace bx
 
 TEST_CASE("nlalloc")
@@ -190,6 +197,16 @@ TEST_CASE("nlalloc")
 	blk = nla.alloc(100);
 	REQUIRE(isValid(blk) );
 
+	bx::Blk blk2 = nla.alloc(1);
+	REQUIRE(!isValid(blk2) );
+
 	nla.free(blk);
 	REQUIRE(0 == nla.getUsed() );
+
+	blk2 = nla.alloc(1);
+	REQUIRE(isValid(blk2) );
+	REQUIRE(bx::NonLocalAllocator::kMinBlockSize == nla.getUsed() );
+
+	nla.free(blk2);
+	REQUIRE(0 == nla.getUsed() );
 }

+ 7 - 0
tests/uint32_test.cpp

@@ -19,6 +19,13 @@ TEST_CASE("StrideAlign")
 	{
 		REQUIRE(48 == bx::strideAlign16(ii+1, 12) );
 	}
+
+	uint32_t offset = 11;
+	offset = bx::strideAlign(offset, 32);
+	REQUIRE(offset == 32);
+
+	offset = bx::strideAlign(offset, 24);
+	REQUIRE(offset == 48);
 }
 
 TEST_CASE("uint32_cnt")