-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: master
Are you sure you want to change the base?
Conversation
XX_Mortons/main.cpp
Outdated
// -------------------------------------- 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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single source?
There was a problem hiding this comment.
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
22_CppCompat/CIntrinsicsTester.h
Outdated
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); |
There was a problem hiding this comment.
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 ?
12_Mortons/app_resources/common.hlsl
Outdated
|
||
// 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>; |
There was a problem hiding this comment.
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 ?
12_Mortons/app_resources/common.hlsl
Outdated
|
||
NBL_CONSTEXPR uint32_t bufferSize = 256; | ||
|
||
// Proper coverage would require writing tests for ALL possible sign, dimensions and width configurations |
There was a problem hiding this comment.
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
12_Mortons/app_resources/shader.hlsl
Outdated
accessor.set(0, foo.value); | ||
//accessor.set(0, foo.value); | ||
*/ | ||
uint32_t bar = _static_cast<uint32_t>(0xCAFEDEADDEADBEEF); |
There was a problem hiding this comment.
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
Checks that the arithmetic and comparisons work as expected + checks it compiles for GPU