Skip to content

Adds tests for the new Morton Code class #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Adds tests for the new Morton Code class #187

wants to merge 7 commits into from

Conversation

Fletterio
Copy link
Contributor

Checks that the arithmetic and comparisons work as expected + checks it compiles for GPU

Comment on lines 55 to 198
// -------------------------------------- SUBTRACTION -------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// ---------------------------------------- Signed -----------------------------------------------------

// No overflow
assert(static_cast<vector_t>(morton_t(vector_t(1000, 764, -365)) - morton_t(vector_t(834, -243, 100))) == vector_t(166, 1007, -465));

// Type 1 overflow: Subtraction of representable coordinates goes out of range
assert(static_cast<vector_t>(morton_t(vector_t(-900, 70, 500)) - morton_t(vector_t(578, -50, -20))) == vector_t(570, 120, -504));

// Type 2 overflow: Subtraction of irrepresentable range gives correct result
assert(static_cast<vector_t>(morton_t(vector_t(54, 900, -475)) - morton_t(vector_t(-46, 1437, -699))) == vector_t(100, -537, 224));

// ---------------------------------------- Unsigned -----------------------------------------------------

// No overflow
assert(static_cast<unsigned_vector_t>(unsigned_morton_t(unsigned_vector_t(382, 910, 543)) - unsigned_morton_t(unsigned_vector_t(322, 564, 299))) == unsigned_vector_t(60, 346, 244));

// Type 1 overflow: Subtraction of representable coordinates goes out of range
assert(static_cast<unsigned_vector_t>(unsigned_morton_t(unsigned_vector_t(382, 910, 543)) - unsigned_morton_t(unsigned_vector_t(2000, 2000, 1000))) == unsigned_vector_t(430, 958, 567));

// Type 2 overflow: Subtraction of irrepresentable range gives correct result
assert(static_cast<unsigned_vector_t>(unsigned_morton_t(unsigned_vector_t(54, 900, 475)) - unsigned_morton_t(unsigned_vector_t(-865, -100, -10))) == unsigned_vector_t(919, 1000, 485));


// ----------------------------------------------------------------------------------------------------
// -------------------------------------- UNARY NEGATION ----------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Only makes sense for signed
assert(static_cast<vector_t>(- morton_t(vector_t(-1024, 543, -475))) == vector_t(-1024, -543, 475));

// ***********************************************************************************************************************************
// ************************************************* Comparison operator tests *******************************************************
// ***********************************************************************************************************************************

// ----------------------------------------------------------------------------------------------------
// -------------------------------------- OPERATOR< ---------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Signed

// Same sign, negative
assert(morton_t(vector_t(-954, -455, -333)) < morton_t(vector_t(-433, -455, -433)) == bool_vector_t(true, false, false));
// Same sign, positive
assert(morton_t(vector_t(954, 455, 333)) < morton_t(vector_t(433, 455, 433)) == bool_vector_t(false, false, true));
// Differing signs
assert(morton_t(vector_t(954, -32, 0)) < morton_t(vector_t(-44, 0, -1)) == bool_vector_t(false, true, false));

// Unsigned
assert(unsigned_morton_t(unsigned_vector_t(239, 435, 66)) < unsigned_morton_t(unsigned_vector_t(240, 435, 50)) == bool_vector_t(true, false, false));

// ----------------------------------------------------------------------------------------------------
// -------------------------------------- OPERATOR<= --------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Signed

// Same sign, negative
assert(morton_t(vector_t(-954, -455, -333)) <= morton_t(vector_t(-433, -455, -433)) == bool_vector_t(true, true, false));
// Same sign, positive
assert(morton_t(vector_t(954, 455, 333)) <= morton_t(vector_t(433, 455, 433)) == bool_vector_t(false, true, true));
// Differing signs
assert(morton_t(vector_t(954, -32, 0)) <= morton_t(vector_t(-44, 0, -1)) == bool_vector_t(false, true, false));

// Unsigned
assert(unsigned_morton_t(unsigned_vector_t(239, 435, 66)) <= unsigned_morton_t(unsigned_vector_t(240, 435, 50)) == bool_vector_t(true, true, false));

// ----------------------------------------------------------------------------------------------------
// -------------------------------------- OPERATOR> ---------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Signed

// Same sign, negative
assert(morton_t(vector_t(-954, -455, -333)) > morton_t(vector_t(-433, -455, -433)) == bool_vector_t(false, false, true));
// Same sign, positive
assert(morton_t(vector_t(954, 455, 333)) > morton_t(vector_t(433, 455, 433)) == bool_vector_t(true, false, false));
// Differing signs
assert(morton_t(vector_t(954, -32, 0)) > morton_t(vector_t(-44, 0, -1)) == bool_vector_t(true, false, true));

// Unsigned
assert(unsigned_morton_t(unsigned_vector_t(239, 435, 66)) > unsigned_morton_t(unsigned_vector_t(240, 435, 50)) == bool_vector_t(false, false, true));

// ----------------------------------------------------------------------------------------------------
// -------------------------------------- OPERATOR>= --------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Signed

// Same sign, negative
assert(morton_t(vector_t(-954, -455, -333)) >= morton_t(vector_t(-433, -455, -433)) == bool_vector_t(false, true, true));
// Same sign, positive
assert(morton_t(vector_t(954, 455, 333)) >= morton_t(vector_t(433, 455, 433)) == bool_vector_t(true, true, false));
// Differing signs
assert(morton_t(vector_t(954, -32, 0)) >= morton_t(vector_t(-44, 0, -1)) == bool_vector_t(true, false, true));

// Unsigned
assert(unsigned_morton_t(unsigned_vector_t(239, 435, 66)) >= unsigned_morton_t(unsigned_vector_t(240, 435, 50)) == bool_vector_t(false, true, true));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmon, do single source testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single source?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see bits of example 22, there's same code you include both in some C++ function and HLSL shader, you run same code in both tests

Comment on lines 196 to 202
auto inverseGlm = glm::inverse(reinterpret_cast<typename float32_t3x3::Base const&>(testInput.inverse));
expected.inverse = reinterpret_cast<float32_t3x3&>(inverseGlm);

expected.addCarry.result = glm::uaddCarry(testInput.addCarryA, testInput.addCarryB, expected.addCarry.carry);
expected.subBorrow.result = glm::usubBorrow(testInput.subBorrowA, testInput.subBorrowB, expected.subBorrow.borrow);
expected.addCarryVec.result = glm::uaddCarry(testInput.addCarryAVec, testInput.addCarryBVec, expected.addCarryVec.carry);
expected.subBorrowVec.result = glm::usubBorrow(testInput.subBorrowAVec, testInput.subBorrowBVec, expected.subBorrowVec.borrow);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Przemog1 why is this example testing glm functions instead of our nbl::hlsl that pass through to them ?


// Proper coverage would require writing tests for ALL possible sign, dimensions and width configurations
//using morton_t2 = nbl::hlsl::morton::code<true, 8, 2>; // Fits in an int16_t
using vector_t2 = nbl::hlsl::vector<int16_t, 3>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t2 but it has dimension of 3 ?


NBL_CONSTEXPR uint32_t bufferSize = 256;

// Proper coverage would require writing tests for ALL possible sign, dimensions and width configurations

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recursion with templates, why not

accessor.set(0, foo.value);
//accessor.set(0, foo.value);
*/
uint32_t bar = _static_cast<uint32_t>(0xCAFEDEADDEADBEEF);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC its not gonna be a uint64 literal without ull suffix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants