From 2b16a44b4d28d205767bad4ae09c604c48cc6b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Mon, 31 Dec 2018 17:17:43 -0800 Subject: [PATCH 1/4] Added more strideAlign test. --- tests/uint32_test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/uint32_test.cpp b/tests/uint32_test.cpp index bb7e0dc..ce8a8a7 100644 --- a/tests/uint32_test.cpp +++ b/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") From 3df370aedc35b55c23e8863f0ccce88d290f5e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 3 Jan 2019 12:27:45 -0800 Subject: [PATCH 2/4] Cleanup. --- tests/nlalloc_test.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/nlalloc_test.cpp b/tests/nlalloc_test.cpp index 91b0354..34ac8ab 100644 --- a/tests/nlalloc_test.cpp +++ b/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() ); } From 1f3e70ebd284825788f591666ec73e4b7f5fb986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 3 Jan 2019 14:30:46 -0800 Subject: [PATCH 3/4] Added Vec3 round. --- include/bx/inline/math.inl | 10 ++++++++++ include/bx/math.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/include/bx/inline/math.inl b/include/bx/inline/math.inl index 4be1e21..f7ec88e 100644 --- a/include/bx/inline/math.inl +++ b/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 diff --git a/include/bx/math.h b/include/bx/math.h index 29d2aed..d910710 100644 --- a/include/bx/math.h +++ b/include/bx/math.h @@ -275,6 +275,9 @@ namespace bx template void store(void* _ptr, const Ty& _a); + /// + BX_CONSTEXPR_FUNC Vec3 round(const Vec3 _a); + /// BX_CONSTEXPR_FUNC Vec3 abs(const Vec3 _a); From cd0fc36c3c14b453852669acfae29c86bef02797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 3 Jan 2019 15:24:17 -0800 Subject: [PATCH 4/4] Removing old math. --- include/bx/inline/math.inl | 19 ------------------- include/bx/math.h | 6 ------ 2 files changed, 25 deletions(-) diff --git a/include/bx/inline/math.inl b/include/bx/inline/math.inl index f7ec88e..2bc4016 100644 --- a/include/bx/inline/math.inl +++ b/include/bx/inline/math.inl @@ -939,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]; diff --git a/include/bx/math.h b/include/bx/math.h index d910710..d04d841 100644 --- a/include/bx/math.h +++ b/include/bx/math.h @@ -527,12 +527,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);