Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
cdf867d
add operator= for glm:: matrices corresponding to our at home matrice…
AnastaZIuk Oct 25, 2024
6ef4f89
I'm stupid, I have explicit at home matrix constructor taking glm:: m…
AnastaZIuk Oct 25, 2024
22f505c
steal include/nbl/builtin/hlsl/matrix_utils/transformation_matrix_uti…
AnastaZIuk Oct 25, 2024
51f4ced
fix getMatrix3x4As4x4 (return type issues) & buildCameraLookAtMatrixR…
AnastaZIuk Oct 25, 2024
7f2c085
update examples_tests submodule
AnastaZIuk Oct 25, 2024
f1daa25
actually *this* addresses https://github.com/Devsh-Graphics-Programmi…
AnastaZIuk Oct 25, 2024
2192e99
update examples_tests submodule
AnastaZIuk Oct 25, 2024
520b1f5
update examples_tests submodule
AnastaZIuk Oct 28, 2024
a0890f0
forgot to commit projection build methods, update examples_tests subm…
AnastaZIuk Nov 2, 2024
0109b22
add is_smart_refctd_ptr_v, update examples_tests submodule
AnastaZIuk Nov 2, 2024
2a29a2f
update examples_tests submodule
AnastaZIuk Nov 3, 2024
7673769
update examples_tests submodule
AnastaZIuk Nov 3, 2024
fc7bc33
pull master & resolve conflicts
AnastaZIuk Nov 4, 2024
8fc4f89
pull mastrer & resolve conflicts
AnastaZIuk Nov 6, 2024
9a139df
update examples_tests submodule
AnastaZIuk Nov 6, 2024
24a80c9
create ui::E_MOUSE_CODE & constexpr ui::mouseCodeToString - we really…
AnastaZIuk Nov 8, 2024
03fa2ca
pull master & resolve conflicts
AnastaZIuk Nov 11, 2024
21b89b4
@alichraghi small homework - read https://en.cppreference.com/w/cpp/l…
AnastaZIuk Nov 11, 2024
68bc7be
update examples_tests submodule
AnastaZIuk Nov 12, 2024
866e844
update examples_tests submodule
AnastaZIuk Nov 15, 2024
8bd6436
update examples_tests submodule
AnastaZIuk Nov 15, 2024
de69afe
update examples_tests submodule
AnastaZIuk Nov 18, 2024
a55bd39
update imguizmo with its upstream
AnastaZIuk Nov 18, 2024
6f3c5fc
update examples_tests submodule
AnastaZIuk Nov 18, 2024
0d126df
update examples_tests submodule
AnastaZIuk Dec 2, 2024
31e85e7
update examples_tests submodule
AnastaZIuk Dec 2, 2024
08f11f6
update examples_tests submodule
AnastaZIuk Dec 3, 2024
5bcd6ef
add getCastedMatrix & getCastedVector, update examples_tests submodule
AnastaZIuk Dec 12, 2024
5a07fe7
update examples_tests submodule
AnastaZIuk Dec 13, 2024
f55b268
update examples_tests submodule
AnastaZIuk Dec 13, 2024
01f909a
add examples_tests submodule
AnastaZIuk Dec 13, 2024
ab90d33
update examples_tests submodule
AnastaZIuk Dec 13, 2024
c9f0960
update examples_tests submodule
AnastaZIuk Dec 14, 2024
3727ae3
update examples_tests submodule
AnastaZIuk Dec 14, 2024
e9f78a2
update examples_tests submodule
AnastaZIuk Dec 14, 2024
33f8d01
add constexpr stringToKeyCode & stringToMouseCode
AnastaZIuk Dec 16, 2024
b3d7710
update examples_tests submodule
AnastaZIuk Dec 17, 2024
53f72ec
update examples_tests submodule
AnastaZIuk Dec 18, 2024
e3d282b
update examples_tests submodule
AnastaZIuk Dec 19, 2024
5124136
update examples_tests submodule
AnastaZIuk Dec 19, 2024
fb2ce01
update examples_tests submodule
AnastaZIuk Dec 20, 2024
7ce37ba
update examples_tests submodule
AnastaZIuk Dec 20, 2024
406fef8
update examples_tests submodule
AnastaZIuk Dec 21, 2024
661dae9
update examples_tests submodule
AnastaZIuk Dec 21, 2024
183a8fd
update examples_tests submodule
AnastaZIuk Dec 22, 2024
a30c409
update examples_tests submodule
AnastaZIuk Dec 22, 2024
5f033af
update examples_tests submodule
AnastaZIuk Dec 23, 2024
0529f8a
update examples_tests submodule
AnastaZIuk Dec 23, 2024
74b8c11
update examples_tests submodule
AnastaZIuk Dec 23, 2024
2fdf296
update examples_tests submodule
AnastaZIuk Dec 23, 2024
3b68444
update examples_tests submodule
AnastaZIuk Dec 30, 2024
b21de61
pull master & resolve conflicts
AnastaZIuk Jan 24, 2025
2693caf
update examples_tests submodule
AnastaZIuk Jan 24, 2025
ae315a0
a comment for glslFunctions, update examples_tests submodule
AnastaZIuk Jan 24, 2025
07eeef7
small temporary updates to transformation_matrix_utils.hlsl, update e…
AnastaZIuk Jan 31, 2025
15aa72f
introduce reference frame concept to imguizmo - commit submodule update
AnastaZIuk Feb 2, 2025
661f999
update examples_tests submodule
AnastaZIuk Feb 2, 2025
db1102c
update examples_tests submodule
AnastaZIuk Feb 6, 2025
329d98f
pull master & resolve conflicts
AnastaZIuk Feb 17, 2025
52901f2
pull master, resolve conflicts
AnastaZIuk Jan 13, 2026
ba3d7a0
adjust to code, precompile remaining runtime shaders
AnastaZIuk Feb 3, 2026
7d81d9c
imgui log polish
AnastaZIuk Feb 5, 2026
04ce784
Update camera module and async dispatcher exit
AnastaZIuk Feb 7, 2026
b25a81f
Merge remote-tracking branch 'origin/master' into cameraz
AnastaZIuk Feb 7, 2026
40c1fdb
Restore transformation matrix utils compatibility
AnastaZIuk Feb 7, 2026
749175c
Update examples_tests submodule pointer
AnastaZIuk Feb 14, 2026
037fc08
Update examples_tests submodule pointer
AnastaZIuk Feb 18, 2026
4b7cbe8
Update examples_tests pointer for world axis fix
AnastaZIuk Feb 18, 2026
8e76424
Update examples tests camera smoke integration
AnastaZIuk Feb 18, 2026
69d49fd
Add frustum extension and camera smoke updates
AnastaZIuk Feb 18, 2026
1108584
Update examples tests continuity frustum script
AnastaZIuk Feb 18, 2026
ef5429f
Merge remote-tracking branch 'origin/master' into cameraz
AnastaZIuk Feb 19, 2026
848aabe
Update camera test submodule revision
AnastaZIuk Feb 19, 2026
7d97b8b
Update examples_tests submodule revision
AnastaZIuk Feb 19, 2026
cadefbb
Update examples_tests for cameraz smoke fixes
AnastaZIuk Apr 3, 2026
d97f18d
Update examples_tests after master merge
AnastaZIuk Apr 3, 2026
a38d167
Merge master
AnastaZIuk Apr 3, 2026
3c6fd0e
Update examples_tests after json alias fix
AnastaZIuk Apr 3, 2026
530883e
Update examples_tests checkpoint
AnastaZIuk Apr 3, 2026
abbcfe7
Update examples_tests after goal solver rename
AnastaZIuk Apr 3, 2026
38d92c2
Update examples_tests after camera goal cleanup
AnastaZIuk Apr 3, 2026
e7b8b4f
Update examples_tests after camera goal solver changes
AnastaZIuk Apr 4, 2026
5cae47e
Update examples_tests after preset compatibility changes
AnastaZIuk Apr 4, 2026
23fa6b6
Update examples_tests after preset policy changes
AnastaZIuk Apr 4, 2026
0fb9e90
Update examples_tests after Chase and Dolly preset flow checks
AnastaZIuk Apr 4, 2026
dac6e97
Update examples_tests after planar binding cleanup
AnastaZIuk Apr 4, 2026
53f960a
Update examples_tests after camera contract cleanup
AnastaZIuk Apr 4, 2026
944f5cb
Update examples_tests after input binding helper cleanup
AnastaZIuk Apr 4, 2026
630b7bd
Update examples_tests after transform editor cleanup
AnastaZIuk Apr 4, 2026
760acaa
Update examples_tests after binding layout rename
AnastaZIuk Apr 4, 2026
7eb2a91
Update examples_tests after binding storage split
AnastaZIuk Apr 4, 2026
0b50aea
Update examples_tests after binding layout header split
AnastaZIuk Apr 4, 2026
5de70ac
Update examples_tests after JSON binding rename
AnastaZIuk Apr 4, 2026
1817146
Update examples_tests after input processor rename
AnastaZIuk Apr 4, 2026
405b434
Update examples_tests after camera rig setup cleanup
AnastaZIuk Apr 4, 2026
37b7075
Update examples_tests after rig config routing
AnastaZIuk Apr 4, 2026
0314dbf
Update examples_tests after rig preset helper cleanup
AnastaZIuk Apr 4, 2026
4a244ca
Update examples_tests after camera binding layout decoupling
AnastaZIuk Apr 4, 2026
f12b5b6
Update examples_tests after binding naming cleanup
AnastaZIuk Apr 4, 2026
3393bbd
Update examples_tests after camera binding cleanup
AnastaZIuk Apr 4, 2026
fa953f1
Update examples_tests after motion config split
AnastaZIuk Apr 4, 2026
90b7c19
Update examples_tests after scoped motion overrides
AnastaZIuk Apr 4, 2026
1b7a8d8
Update examples_tests after unit motion wrapper
AnastaZIuk Apr 4, 2026
9cd1fc8
Update examples_tests after goal alias cleanup
AnastaZIuk Apr 4, 2026
d8776fd
Update examples_tests after preset UI cleanup
AnastaZIuk Apr 4, 2026
5add016
Update examples_tests after playback summary changes
AnastaZIuk Apr 4, 2026
70e2ce9
Update examples_tests after preset banner cleanup
AnastaZIuk Apr 4, 2026
e80ef0c
Update examples_tests after playback scrub preview
AnastaZIuk Apr 4, 2026
ee188ff
Update examples_tests after capture gating
AnastaZIuk Apr 4, 2026
da75579
Update examples_tests after shared goal API cleanup
AnastaZIuk Apr 4, 2026
0b3ec40
Update examples_tests after shared preset API cleanup
AnastaZIuk Apr 4, 2026
1234059
Update examples_tests after playback keyframe authoring cleanup
AnastaZIuk Apr 4, 2026
f821947
Update examples_tests after keyframe storage changes
AnastaZIuk Apr 4, 2026
0bab320
Update examples_tests after shared analysis cleanup
AnastaZIuk Apr 4, 2026
7f78cc2
Update examples_tests after shared keyframe track cleanup
AnastaZIuk Apr 4, 2026
9a32427
Update examples_tests after camera docs
AnastaZIuk Apr 4, 2026
1ac6209
Update examples_tests after header docs
AnastaZIuk Apr 4, 2026
bfae93a
Update examples_tests after playback timeline cleanup
AnastaZIuk Apr 4, 2026
c6fa314
Update examples_tests after camera persistence cleanup
AnastaZIuk Apr 4, 2026
fd191f1
Update examples_tests after preset flow cleanup
AnastaZIuk Apr 4, 2026
19ebf8b
Update examples_tests after preset apply summary cleanup
AnastaZIuk Apr 4, 2026
11d9347
Update examples_tests after camera helper smoke hardening
AnastaZIuk Apr 4, 2026
9cfdb18
Update examples_tests after camera helper polish
AnastaZIuk Apr 4, 2026
ca1d35b
Update examples_tests after camera manipulation cleanup
AnastaZIuk Apr 4, 2026
eada28c
Update examples_tests after camera text cleanup
AnastaZIuk Apr 4, 2026
2bf4590
Update examples_tests after camera projection cleanup
AnastaZIuk Apr 4, 2026
6289e65
Update examples_tests after analysis text cleanup
AnastaZIuk Apr 4, 2026
6c0d131
Update examples_tests after helper smoke hardening
AnastaZIuk Apr 4, 2026
777117d
Update examples_tests after presentation cleanup
AnastaZIuk Apr 4, 2026
b88598a
Update examples_tests after presentation badge cleanup
AnastaZIuk Apr 4, 2026
ea56b53
Update examples_tests after preset comparison cleanup
AnastaZIuk Apr 4, 2026
e21be7e
Update examples_tests after presentation label cleanup
AnastaZIuk Apr 4, 2026
b52527e
Update examples_tests after preset collection cleanup
AnastaZIuk Apr 4, 2026
36f2668
Update examples_tests after continuity scripting cleanup
AnastaZIuk Apr 6, 2026
2cb9950
Update examples_tests after follow integration
AnastaZIuk Apr 6, 2026
c257396
Update examples_tests after follow integration
AnastaZIuk Apr 6, 2026
7a7172f
Update examples_tests after sequence policy cleanup
AnastaZIuk Apr 6, 2026
d2fe6b1
Update examples_tests after scripted runtime cleanup
AnastaZIuk Apr 7, 2026
016c2bf
Update examples_tests after camera docs rewrite
AnastaZIuk Apr 7, 2026
f783968
Update examples_tests after camera API cleanup
AnastaZIuk Apr 7, 2026
c937315
Update examples_tests after camera cleanup
AnastaZIuk Apr 7, 2026
24fc3fb
Update examples_tests after camera contract cleanup
AnastaZIuk Apr 7, 2026
3cac470
Update examples_tests after ui presentation cleanup
AnastaZIuk Apr 7, 2026
885e330
Update examples_tests after follow label cleanup
AnastaZIuk Apr 7, 2026
d74490f
Update examples_tests after system follow cleanup
AnastaZIuk Apr 7, 2026
f56a8fb
Update examples_tests after hlsl cleanup
AnastaZIuk Apr 7, 2026
0068d09
Update examples_tests after docs cleanup
AnastaZIuk Apr 7, 2026
5254830
Update examples_tests after header docs
AnastaZIuk Apr 7, 2026
8c2b795
Polish hlsl transform utility cleanup
AnastaZIuk Apr 7, 2026
4182b2d
Update examples_tests after camera cleanup
AnastaZIuk Apr 8, 2026
cc9521f
Update examples_tests after camera cleanup
AnastaZIuk Apr 8, 2026
3a88506
Move cameras module into ext
AnastaZIuk Apr 10, 2026
6afa742
Clean up cameras ext module
AnastaZIuk Apr 10, 2026
5b0e78c
Polish cameras README
AnastaZIuk Apr 10, 2026
5009f8b
Trim non-camera drift from cameras ext
AnastaZIuk Apr 10, 2026
28cc1d3
Use shared quaternion cast in cameras
AnastaZIuk Apr 10, 2026
d5335f2
Restore dxc submodule pointer
AnastaZIuk Apr 10, 2026
b582488
Split cameras utilities into source files
AnastaZIuk Apr 10, 2026
e9ac109
Move gimbal input processing into source files
AnastaZIuk Apr 10, 2026
f5629c7
Revert shared quaternion cast change
AnastaZIuk Apr 10, 2026
f83004a
Restore shared quaternion cast
AnastaZIuk Apr 10, 2026
d825ef2
Use bitmask helpers for goal solver issues
AnastaZIuk Apr 10, 2026
b9be28a
Update examples_tests submodule
AnastaZIuk Apr 10, 2026
5f901e7
Merge latest master into cameraz
AnastaZIuk Apr 10, 2026
a80bb82
Refresh examples cameraz submodule
AnastaZIuk Apr 10, 2026
96e0ccd
Refresh examples cameraz submodule
AnastaZIuk Apr 10, 2026
7130af4
Fix GitHub math in cameras README
AnastaZIuk Apr 10, 2026
06b1a4b
Fix Path Rig math rendering
AnastaZIuk Apr 10, 2026
33a7793
Refresh examples cameraz submodule
AnastaZIuk Apr 10, 2026
f89e4f3
Refresh examples cameraz submodule
AnastaZIuk Apr 10, 2026
8f4cc2f
Refresh examples cameraz submodule
AnastaZIuk Apr 11, 2026
c92b9b2
Fix camera scaling and view accessors
AnastaZIuk Apr 11, 2026
89cfa0b
Merge master into cameraz
AnastaZIuk Apr 11, 2026
3d956aa
bug fixes and minor typo fixes to input system
Erfan-Ahmadi Sep 11, 2026
339788d
update examples after merge with master
Erfan-Ahmadi Sep 15, 2026
922e486
Merge branch 'master' into cameraz
Erfan-Ahmadi Sep 15, 2026
16b790e
new hlsl::approx helpers and ieee754 fixes and improvements + update …
Erfan-Ahmadi Sep 16, 2026
4275035
camera namespace changes + minor fixes + remove useless classes
Erfan-Ahmadi Sep 17, 2026
f1a8b83
cleanup math utilities, use hlsl:: as much as possible and remove red…
Erfan-Ahmadi Sep 17, 2026
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
2 changes: 1 addition & 1 deletion examples_tests
Submodule examples_tests updated 128 files
2 changes: 2 additions & 0 deletions include/nbl/asset/IAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#define _NBL_ASSET_I_ASSET_H_INCLUDED_

#include "nbl/core/decl/smart_refctd_ptr.h"
// this header specializes `system::impl::to_string_helper` for `IAsset::E_TYPE` below
#include "nbl/system/to_string.h"

#include <string>

Expand Down
6 changes: 3 additions & 3 deletions include/nbl/builtin/hlsl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ library header. Those hold only what the standard header provides.
| `type_traits.hlsl` | `<type_traits>` | Type trait structs and aliases. |
| `utility.hlsl` | `<utility>` | Standard utilities (currently `declval`). |
| `tgmath.hlsl` | `<tgmath>`/`<cmath>` | Type-generic math functions. |
| `ieee754.hlsl` | | IEEE-754 float layout traits and bit helpers. |
| `ieee754.hlsl` | | IEEE-754 float layout traits and bit helpers (including ULP distance). |
| `mpl.hlsl` | | Template metaprogramming helpers (compile-time, boost::mpl style). |
| `enums.hlsl` | | Engine enums shared host and device (e.g. `ShaderStage`). |
| `format.hlsl` | | Texel block format enum and format pack/unpack (includes `format/`). |
Expand All @@ -99,6 +99,7 @@ library header. Those hold only what the standard header provides.

| Folder | Contents and what belongs here |
| --- | --- |
| `approx/` | Approximate float comparison (ULP, absolute+relative), vector checks (perpendicular, orientation, squared length) and max-error tracking. |
| `barycentric/` | Barycentric coordinate utilities. |
| `bda/` | Buffer Device Address: typed pointers, references, and accessors. |
| `blit/` | Image blit and normalization compute shaders and their parameters. |
Expand All @@ -111,7 +112,6 @@ library header. Those hold only what the standard header provides.
| `fft/` | FFT building blocks. See [`fft/README.md`](fft/README.md). |
| `format/` | Pixel/texel format pack and unpack (octahedral, shared exponent). |
| `glsl_compat/` | GLSL builtin equivalents (core, subgroup ops). |
| `ieee754/` | IEEE-754 implementation details. |
| `ies/` | IES light profile sampling and textures. |
| `math/` | Math routines: geometry, linalg, quaternions, equations, quadrature, and more. |
| `matrix_utils/` | Matrix traits, compile-time and runtime. |
Expand All @@ -127,9 +127,9 @@ library header. Those hold only what the standard header provides.
| `spirv_intrinsics/` | Raw SPIR-V intrinsic declarations. |
| `subgroup/` | Subgroup-level collectives (ballot, arithmetic, basic, fft). |
| `subgroup2/` | Newer subgroup collective API. |
| `testing/` | Comparison helpers for tests (approx compare, max error). |
| `text_rendering/` | Text rendering (MSDF). |
| `tgmath/` | `tgmath` implementation details (isnan, output structs). |
| `utils/` | Small generic helpers (bitfield, elementwise All/Any/None testers for scalars, vectors and matrices). |
| `vector_utils/` | Vector traits. |
| `visualization/` | Visualization helpers (turbo colormap). |
| `workgroup/` | Workgroup-level collectives (arithmetic, ballot, scan, shuffle, fft). |
Expand Down
65 changes: 65 additions & 0 deletions include/nbl/builtin/hlsl/approx/abs_rel.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (C) 2018-2026 - 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
#ifndef _NBL_BUILTIN_HLSL_APPROX_ABS_REL_INCLUDED_
#define _NBL_BUILTIN_HLSL_APPROX_ABS_REL_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include <nbl/builtin/hlsl/concepts/core.hlsl>
#include <nbl/builtin/hlsl/tgmath.hlsl>
#include <nbl/builtin/hlsl/utils/elementwise.hlsl>

namespace nbl
{
namespace hlsl
{
namespace approx
{

// Scalar predicate: `lhs` and `rhs` are equal if they differ by at most `maxAbsoluteDifference`
// OR by at most `maxRelativeDifference` times the larger magnitude.
// The absolute bound is what makes comparisons against 0 work, a purely relative bound degrades to exact equality there.
// IEEE semantics: NaN never compares equal, infinities only equal themselves.
template<typename FloatingPoint NBL_PRIMARY_REQUIRES(concepts::FloatingPointScalar<FloatingPoint>)
struct AbsRelEqualPred
{
using this_t = AbsRelEqualPred<FloatingPoint>;

static this_t create(const FloatingPoint _maxAbsoluteDifference, const FloatingPoint _maxRelativeDifference)
{
this_t retval;
retval.maxAbsoluteDifference = _maxAbsoluteDifference;
retval.maxRelativeDifference = _maxRelativeDifference;
return retval;
}

bool operator()(const FloatingPoint lhs, const FloatingPoint rhs) NBL_CONST_MEMBER_FUNC
{
// exact matches, `+0 == -0` and same-signed infinities
if (lhs == rhs)
return true;
// no special case for NaN, `diff` will be NaN and every comparison below false
const FloatingPoint diff = hlsl::abs<FloatingPoint>(lhs - rhs);
const FloatingPoint largest = hlsl::max<FloatingPoint>(hlsl::abs<FloatingPoint>(lhs), hlsl::abs<FloatingPoint>(rhs));
// multiplying instead of dividing by `largest` is cheaper, but `inf <= maxRelativeDifference*inf` would hold,
// hence the infinity guard which uses a bit pattern test so it survives `/fp:fast` and `-ffast-math`
return diff <= maxAbsoluteDifference || (diff <= maxRelativeDifference * largest && !hlsl::isinf<FloatingPoint>(largest));
}

FloatingPoint maxAbsoluteDifference;
FloatingPoint maxRelativeDifference;
};

// Works on floating point scalars, vectors and matrices, every element has to pass.
template<typename T>
bool absRelEqual(NBL_CONST_REF_ARG(T) lhs, NBL_CONST_REF_ARG(T) rhs, const scalar_type_t<T> maxAbsoluteDifference, const scalar_type_t<T> maxRelativeDifference)
{
using pred_t = AbsRelEqualPred<scalar_type_t<T> >;
return utils::elementwiseAll<T, pred_t>(lhs, rhs, pred_t::create(maxAbsoluteDifference, maxRelativeDifference));
}

}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _NBL_BUILTIN_HLSL_TESTING_MAX_ERROR_INCLUDED_
#define _NBL_BUILTIN_HLSL_TESTING_MAX_ERROR_INCLUDED_
#ifndef _NBL_BUILTIN_HLSL_APPROX_MAX_ERROR_INCLUDED_
#define _NBL_BUILTIN_HLSL_APPROX_MAX_ERROR_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat/basic.h>
#include <nbl/builtin/hlsl/concepts/core.hlsl>
Expand All @@ -11,7 +11,7 @@ namespace nbl
{
namespace hlsl
{
namespace testing
namespace approx
{

struct SMaxError
Expand Down
47 changes: 47 additions & 0 deletions include/nbl/builtin/hlsl/approx/orientation.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef _NBL_BUILTIN_HLSL_APPROX_ORIENTATION_INCLUDED_
#define _NBL_BUILTIN_HLSL_APPROX_ORIENTATION_INCLUDED_

#include <nbl/builtin/hlsl/approx/abs_rel.hlsl>
#include <nbl/builtin/hlsl/limits.hlsl>

namespace nbl
{
namespace hlsl
{
namespace approx
{
namespace impl
{

template<typename FloatingPointVector NBL_PRIMARY_REQUIRES(concepts::FloatingPointVectorial<FloatingPointVector>)
struct OrientationEqualHelper
{
static bool __call(NBL_CONST_REF_ARG(FloatingPointVector) lhs, NBL_CONST_REF_ARG(FloatingPointVector) rhs, const typename vector_traits<FloatingPointVector>::scalar_type maxRelativeDifference)
{
using scalar_t = typename vector_traits<FloatingPointVector>::scalar_type;

const scalar_t dotLR = hlsl::abs(hlsl::dot(lhs, rhs));
const scalar_t dotLL = hlsl::dot(lhs,lhs);
const scalar_t dotRR = hlsl::dot(rhs,rhs);
if (dotLL < numeric_limits<scalar_t>::min || dotRR < numeric_limits<scalar_t>::min)
return false;

const scalar_t scale = hlsl::sqrt(dotLL * dotRR);
return absRelEqual<scalar_t>(dotLR, scale, scalar_t(0), maxRelativeDifference);
}
};

}

// true if `lhs` and `rhs` point along the same line (either direction), ignoring their lengths
template<typename T>
bool orientationEqual(NBL_CONST_REF_ARG(T) lhs, NBL_CONST_REF_ARG(T) rhs, const typename vector_traits<T>::scalar_type maxRelativeDifference)
{
return impl::OrientationEqualHelper<T>::__call(lhs, rhs, maxRelativeDifference);
}

}
}
}

#endif
60 changes: 60 additions & 0 deletions include/nbl/builtin/hlsl/approx/ulp.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (C) 2018-2026 - 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
#ifndef _NBL_BUILTIN_HLSL_APPROX_ULP_INCLUDED_
#define _NBL_BUILTIN_HLSL_APPROX_ULP_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include <nbl/builtin/hlsl/concepts/core.hlsl>
#include <nbl/builtin/hlsl/ieee754.hlsl>
#include <nbl/builtin/hlsl/tgmath.hlsl>
#include <nbl/builtin/hlsl/utils/elementwise.hlsl>

namespace nbl
{
namespace hlsl
{
namespace approx
{

// Scalar predicate: `lhs` and `rhs` are equal if they are at most `maxULPs` representable values apart, see `ieee754::ulpDistance`.
template<typename FloatingPoint NBL_PRIMARY_REQUIRES(concepts::FloatingPointScalar<FloatingPoint>)
struct ULPEqualPred
{
using this_t = ULPEqualPred<FloatingPoint>;
using uint_type = typename unsigned_integer_of_size<sizeof(FloatingPoint)>::type;

static this_t create(const uint_type _maxULPs)
{
this_t retval;
retval.maxULPs = _maxULPs;
return retval;
}

bool operator()(const FloatingPoint lhs, const FloatingPoint rhs) NBL_CONST_MEMBER_FUNC
{
// NaN payloads can be a single ULP apart when looked at as integers, so NaN has to be rejected explicitly
if (hlsl::isnan<FloatingPoint>(lhs) || hlsl::isnan<FloatingPoint>(rhs))
return false;
// the largest finite value is a single ULP away from infinity, so infinities have to match exactly
if (hlsl::isinf<FloatingPoint>(lhs) || hlsl::isinf<FloatingPoint>(rhs))
return ieee754::impl::bitCastToUintType(lhs) == ieee754::impl::bitCastToUintType(rhs);
return ieee754::ulpDistance<FloatingPoint>(lhs, rhs) <= maxULPs;
}

uint_type maxULPs;
};

// Works on floating point scalars, vectors and matrices, every element has to pass.
template<typename T>
bool ulpEqual(NBL_CONST_REF_ARG(T) lhs, NBL_CONST_REF_ARG(T) rhs, const typename ULPEqualPred<scalar_type_t<T> >::uint_type maxULPs)
{
using pred_t = ULPEqualPred<scalar_type_t<T> >;
return utils::elementwiseAll<T, pred_t>(lhs, rhs, pred_t::create(maxULPs));
}

}
}
}

#endif
71 changes: 71 additions & 0 deletions include/nbl/builtin/hlsl/approx/vector.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef _NBL_BUILTIN_HLSL_APPROX_VECTOR_INCLUDED_
#define _NBL_BUILTIN_HLSL_APPROX_VECTOR_INCLUDED_

#include <nbl/builtin/hlsl/approx/abs_rel.hlsl>

// TODO: move `impl::OrientationEqualHelper`/`orientationEqual` from `approx/orientation.hlsl` here and rename to `isParallel`

namespace nbl
{
namespace hlsl
{
namespace approx
{
namespace impl
{

template<typename FloatingPointVector NBL_PRIMARY_REQUIRES(concepts::FloatingPointVectorial<FloatingPointVector>)
struct IsPerpendicularHelper
{
using scalar_t = typename vector_traits<FloatingPointVector>::scalar_type;

// Vectors `a` and `b` are perpendicular when the angle `theta` between them is 90deg. From the dot product formula:
// dot(a,b) = |a| * |b| * cos(theta)
// cos(theta) = dot(a,b) / (|a| * |b|)
// so perpendicular means cos(theta) == 0.
//
// We accept |cos(theta)| <= epsilon. For a small deviation `delta` from 90deg, cos(90deg - delta) = sin(delta) ~= delta (in radians),
// so this allows a deviation of asin(epsilon) ~= epsilon radians, e.g. epsilon = 1e-5 is ~5.73e-4 degrees (~2 arcseconds).
//
// Only the absolute error is used: we compare against 0.0 and an error relative to 0 is meaningless
// (a relative bound scaled by a magnitude of 0 degenerates into requiring an exact match).
//
// To avoid the division, `|a| * |b|` moves to the other side of the inequality:
// |dot(a,b)| / (|a| * |b|) <= epsilon
// |dot(a,b)| <= epsilon * |a| * |b| = epsilon * sqrt(dot(a,a) * dot(b,b))
// `maxAbsoluteDifference` is that right hand side (a single `sqrt`, since dot(v,v) = |v|^2), and `absRelEqual` checks `dot(a,b)` against it.
// The bound grows with the lengths, so uniformly scaled vectors give the same answer.
//
// A zero length vector counts as perpendicular to everything (the dot product and the bound are both 0).
static bool __call(NBL_CONST_REF_ARG(FloatingPointVector) lhs, NBL_CONST_REF_ARG(FloatingPointVector) rhs, const scalar_t cosThetaEpsilon)
{
// NOTE: we considered getting rid of the `sqrt` by squaring both sides, `dot(a,b)^2 <= epsilon^2 * dot(a,a) * dot(b,b)`,
// and decided against it: squaring the already squared lengths makes floating point overflow much more likely for larger values.
const scalar_t maxAbsoluteDifference = cosThetaEpsilon * hlsl::sqrt(hlsl::dot(lhs, lhs) * hlsl::dot(rhs, rhs));
return absRelEqual<scalar_t>(hlsl::dot(lhs, rhs), scalar_t(0.0), maxAbsoluteDifference, scalar_t(0.0));
}
};

}

// compares the squared lengths of `lhs` and `rhs` with `absRelEqual`
template<typename T NBL_FUNC_REQUIRES(concepts::FloatingPointVectorial<T>)
bool squaredLengthEqual(NBL_CONST_REF_ARG(T) lhs, NBL_CONST_REF_ARG(T) rhs, const typename vector_traits<T>::scalar_type maxAbsoluteDifference, const typename vector_traits<T>::scalar_type maxRelativeDifference)
{
using scalar_t = typename vector_traits<T>::scalar_type;
return absRelEqual<scalar_t>(hlsl::dot(lhs,lhs), hlsl::dot(rhs,rhs), maxAbsoluteDifference, maxRelativeDifference);
}

// true if |cos(theta)| <= `cosThetaEpsilon` for the angle `theta` between `lhs` and `rhs`, regardless of their lengths
// (about `cosThetaEpsilon` radians of deviation from 90deg), see `impl::IsPerpendicularHelper` for the math
template<typename T>
bool isPerpendicular(NBL_CONST_REF_ARG(T) lhs, NBL_CONST_REF_ARG(T) rhs, const typename vector_traits<T>::scalar_type cosThetaEpsilon)
{
return impl::IsPerpendicularHelper<T>::__call(lhs, rhs, cosThetaEpsilon);
}

}
}
}

#endif
Loading
Loading