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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions 12_Mortons/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include(common RESULT_VARIABLE RES)
if(NOT RES)
message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory")
endif()

nbl_create_executable_project("" "" "" "" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}")

if(NBL_EMBED_BUILTIN_RESOURCES)
set(_BR_TARGET_ ${EXECUTABLE_NAME}_builtinResourceData)
set(RESOURCE_DIR "app_resources")

get_filename_component(_SEARCH_DIRECTORIES_ "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)

file(GLOB_RECURSE BUILTIN_RESOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}" CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}/*")
foreach(RES_FILE ${BUILTIN_RESOURCE_FILES})
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "${RES_FILE}")
endforeach()

ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${RESOURCE_DIR}" "nbl::this_example::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")

LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_})
endif()
416 changes: 416 additions & 0 deletions 12_Mortons/Tester.h

Large diffs are not rendered by default.

484 changes: 484 additions & 0 deletions 12_Mortons/app_resources/common.hlsl

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions 12_Mortons/app_resources/mortonTest.comp.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// Copyright (C) 2023-2024 - DevSH Graphics Programming Sp. z O.O.
//// This file is part of the "Nabla Engine".
//// For conditions of distribution and use, see copyright notice in nabla.h
#pragma shader_stage(compute)

#include "common.hlsl"

[[vk::binding(0, 0)]] RWStructuredBuffer<InputTestValues> inputTestValues;
[[vk::binding(1, 0)]] RWStructuredBuffer<TestValues> outputTestValues;

[numthreads(256, 1, 1)]
void main(uint3 invocationID : SV_DispatchThreadID)
{
if (invocationID.x == 0)
outputTestValues[0].fillTestValues(inputTestValues[0]);
}
28 changes: 28 additions & 0 deletions 12_Mortons/config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"enableParallelBuild": true,
"threadsPerBuildProcess" : 2,
"isExecuted": false,
"scriptPath": "",
"cmake": {
"configurations": [ "Release", "Debug", "RelWithDebInfo" ],
"buildModes": [],
"requiredOptions": []
},
"profiles": [
{
"backend": "vulkan", // should be none
"platform": "windows",
"buildModes": [],
"runConfiguration": "Release", // we also need to run in Debug nad RWDI because foundational example
"gpuArchitectures": []
}
],
"dependencies": [],
"data": [
{
"dependencies": [],
"command": [""],
"outputs": []
}
]
}
80 changes: 80 additions & 0 deletions 12_Mortons/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (C) 2018-2024 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#include <nabla.h>
#include <iostream>
#include <cstdio>
#include <assert.h>

#include "nbl/application_templates/MonoDeviceApplication.hpp"
#include "nbl/application_templates/MonoAssetManagerAndBuiltinResourceApplication.hpp"

#include "app_resources/common.hlsl"
#include "Tester.h"

using namespace nbl::core;
using namespace nbl::hlsl;
using namespace nbl::system;
using namespace nbl::asset;
using namespace nbl::video;
using namespace nbl::application_templates;

class MortonTest final : public MonoDeviceApplication, public MonoAssetManagerAndBuiltinResourceApplication
{
using device_base_t = MonoDeviceApplication;
using asset_base_t = MonoAssetManagerAndBuiltinResourceApplication;
public:
MortonTest(const path& _localInputCWD, const path& _localOutputCWD, const path& _sharedInputCWD, const path& _sharedOutputCWD) :
IApplicationFramework(_localInputCWD, _localOutputCWD, _sharedInputCWD, _sharedOutputCWD) {
}

bool onAppInitialized(smart_refctd_ptr<ISystem>&& system) override
{
// Remember to call the base class initialization!
if (!device_base_t::onAppInitialized(smart_refctd_ptr(system)))
return false;
if (!asset_base_t::onAppInitialized(std::move(system)))
return false;
{

}

Tester::PipelineSetupData pplnSetupData;
pplnSetupData.device = m_device;
pplnSetupData.api = m_api;
pplnSetupData.assetMgr = m_assetMgr;
pplnSetupData.logger = m_logger;
pplnSetupData.physicalDevice = m_physicalDevice;
pplnSetupData.computeFamilyIndex = getComputeQueue()->getFamilyIndex();
{
Tester mortonTester;
pplnSetupData.testShaderPath = "app_resources/mortonTest.comp.hlsl";
mortonTester.setupPipeline<InputTestValues, TestValues>(pplnSetupData);
mortonTester.performTests();
}


return true;
}

void onAppTerminated_impl() override
{
m_device->waitIdle();
}

void workLoopBody() override
{
m_keepRunning = false;
}

bool keepRunning() override
{
return m_keepRunning;
}


private:
bool m_keepRunning = true;
};

NBL_MAIN_FUNC(MortonTest)
50 changes: 50 additions & 0 deletions 12_Mortons/pipeline.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import org.DevshGraphicsProgramming.Agent
import org.DevshGraphicsProgramming.BuilderInfo
import org.DevshGraphicsProgramming.IBuilder

class CStreamingAndBufferDeviceAddressBuilder extends IBuilder
{
public CStreamingAndBufferDeviceAddressBuilder(Agent _agent, _info)
{
super(_agent, _info)
}

@Override
public boolean prepare(Map axisMapping)
{
return true
}

@Override
public boolean build(Map axisMapping)
{
IBuilder.CONFIGURATION config = axisMapping.get("CONFIGURATION")
IBuilder.BUILD_TYPE buildType = axisMapping.get("BUILD_TYPE")

def nameOfBuildDirectory = getNameOfBuildDirectory(buildType)
def nameOfConfig = getNameOfConfig(config)

agent.execute("cmake --build ${info.rootProjectPath}/${nameOfBuildDirectory}/${info.targetProjectPathRelativeToRoot} --target ${info.targetBaseName} --config ${nameOfConfig} -j12 -v")

return true
}

@Override
public boolean test(Map axisMapping)
{
return true
}

@Override
public boolean install(Map axisMapping)
{
return true
}
}

def create(Agent _agent, _info)
{
return new CStreamingAndBufferDeviceAddressBuilder(_agent, _info)
}

return this
25 changes: 25 additions & 0 deletions 22_CppCompat/CIntrinsicsTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class CIntrinsicsTester final : public ITester
testInput.smoothStepEdge0 = realDistributionNeg(mt);
testInput.smoothStepEdge1 = realDistributionPos(mt);
testInput.smoothStepX = realDistribution(mt);
testInput.addCarryA = std::numeric_limits<uint32_t>::max() - uintDistribution(mt);
testInput.addCarryB = uintDistribution(mt);
testInput.subBorrowA = uintDistribution(mt);
testInput.subBorrowB = uintDistribution(mt);

testInput.bitCountVec = int32_t3(intDistribution(mt), intDistribution(mt), intDistribution(mt));
testInput.clampValVec = float32_t3(realDistribution(mt), realDistribution(mt), realDistribution(mt));
Expand Down Expand Up @@ -119,6 +123,10 @@ class CIntrinsicsTester final : public ITester
testInput.refractI = float32_t3(realDistribution(mt), realDistribution(mt), realDistribution(mt));
testInput.refractN = glm::normalize(float32_t3(realDistribution(mt), realDistribution(mt), realDistribution(mt)));
testInput.refractEta = realDistribution(mt);
testInput.addCarryAVec = uint32_t3(std::numeric_limits<uint32_t>::max() - uintDistribution(mt), std::numeric_limits<uint32_t>::max() - uintDistribution(mt), std::numeric_limits<uint32_t>::max() - uintDistribution(mt));
testInput.addCarryBVec = uint32_t3(uintDistribution(mt), uintDistribution(mt), uintDistribution(mt));
testInput.subBorrowAVec = uint32_t3(uintDistribution(mt), uintDistribution(mt), uintDistribution(mt));
testInput.subBorrowBVec = uint32_t3(uintDistribution(mt), uintDistribution(mt), uintDistribution(mt));

// use std library or glm functions to determine expected test values, the output of functions from intrinsics.hlsl will be verified against these values
IntrinsicsTestValues expected;
Expand All @@ -139,6 +147,9 @@ class CIntrinsicsTester final : public ITester
expected.step = glm::step(testInput.stepEdge, testInput.stepX);
expected.smoothStep = glm::smoothstep(testInput.smoothStepEdge0, testInput.smoothStepEdge1, testInput.smoothStepX);

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.frac = testInput.frac - std::floor(testInput.frac);
expected.bitReverse = glm::bitfieldReverse(testInput.bitReverse);

Expand Down Expand Up @@ -181,6 +192,9 @@ class CIntrinsicsTester final : public ITester
expected.reflect = glm::reflect(testInput.reflectI, testInput.reflectN);
expected.refract = glm::refract(testInput.refractI, testInput.refractN, testInput.refractEta);

expected.addCarryVec.result = glm::uaddCarry(testInput.addCarryAVec, testInput.addCarryBVec, expected.addCarryVec.carry);
expected.subBorrowVec.result = glm::usubBorrow(testInput.subBorrowAVec, testInput.subBorrowBVec, expected.subBorrowVec.borrow);

auto mulGlm = nbl::hlsl::mul(testInput.mulLhs, testInput.mulRhs);
expected.mul = reinterpret_cast<float32_t3x3&>(mulGlm);
auto transposeGlm = glm::transpose(reinterpret_cast<typename float32_t3x3::Base const&>(testInput.transpose));
Expand All @@ -200,6 +214,7 @@ class CIntrinsicsTester final : public ITester
void performCpuTests(const IntrinsicsIntputTestValues& commonTestInputValues, const IntrinsicsTestValues& expectedTestValues)
{
IntrinsicsTestValues cpuTestValues;

cpuTestValues.fillTestValues(commonTestInputValues);
verifyTestValues(expectedTestValues, cpuTestValues, ITester::TestType::CPU);

Expand Down Expand Up @@ -232,6 +247,11 @@ class CIntrinsicsTester final : public ITester
verifyTestValue("degrees", expectedTestValues.degrees, testValues.degrees, testType);
verifyTestValue("step", expectedTestValues.step, testValues.step, testType);
verifyTestValue("smoothStep", expectedTestValues.smoothStep, testValues.smoothStep, testType);
verifyTestValue("addCarryResult", expectedTestValues.addCarry.result, testValues.addCarry.result, testType);
verifyTestValue("addCarryCarry", expectedTestValues.addCarry.carry, testValues.addCarry.carry, testType);
// Disabled: current glm implementation is wrong
//verifyTestValue("subBorrowResult", expectedTestValues.subBorrow.result, testValues.subBorrow.result, testType);
//verifyTestValue("subBorrowBorrow", expectedTestValues.subBorrow.borrow, testValues.subBorrow.borrow, testType);

verifyTestVector3dValue("normalize", expectedTestValues.normalize, testValues.normalize, testType);
verifyTestVector3dValue("cross", expectedTestValues.cross, testValues.cross, testType);
Expand All @@ -254,6 +274,11 @@ class CIntrinsicsTester final : public ITester
verifyTestVector3dValue("faceForward", expectedTestValues.faceForward, testValues.faceForward, testType);
verifyTestVector3dValue("reflect", expectedTestValues.reflect, testValues.reflect, testType);
verifyTestVector3dValue("refract", expectedTestValues.refract, testValues.refract, testType);
verifyTestVector3dValue("addCarryVecResult", expectedTestValues.addCarryVec.result, testValues.addCarryVec.result, testType);
verifyTestVector3dValue("addCarryVecCarry", expectedTestValues.addCarryVec.carry, testValues.addCarryVec.carry, testType);
// Disabled: current glm implementation is wrong
//verifyTestVector3dValue("subBorrowVecResult", expectedTestValues.subBorrowVec.result, testValues.subBorrowVec.result, testType);
//verifyTestVector3dValue("subBorrowVecBorrow", expectedTestValues.subBorrowVec.borrow, testValues.subBorrowVec.borrow, testType);

verifyTestMatrix3x3Value("mul", expectedTestValues.mul, testValues.mul, testType);
verifyTestMatrix3x3Value("transpose", expectedTestValues.transpose, testValues.transpose, testType);
Expand Down
1 change: 1 addition & 0 deletions 22_CppCompat/ITester.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class ITester
{
case TestType::CPU:
ss << "CPU TEST ERROR:\n";
break;
case TestType::GPU:
ss << "GPU TEST ERROR:\n";
}
Expand Down
Loading