Skip to content
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

Maths for HLSL BxDFs (template cmath, tgmath) #803

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9cac1c9
moved math changes over
keptsecret Dec 16, 2024
8de3ce4
rsqrt not from stl
keptsecret Dec 16, 2024
aa0748e
fix example conflict
keptsecret Dec 16, 2024
b33aaed
moved math funcs to tgmath
keptsecret Dec 16, 2024
dda71b8
some needed math funcs
keptsecret Dec 16, 2024
0b46b67
some more math funcs
keptsecret Dec 16, 2024
acadc15
Merge remote-tracking branch 'origin/cpp_compat_intrinsics_refactor' …
keptsecret Dec 17, 2024
a5d48de
fixed cpp compat types
keptsecret Dec 17, 2024
0064f57
Added ieee754.hlsl and improved intrinsics.hlsl
Przemog1 Dec 18, 2024
89f37f8
Merge branch 'master' into maths_for_bxdfs_hlsl
keptsecret Dec 19, 2024
28427b5
some cpp compat fixes
keptsecret Dec 19, 2024
8e957ce
Merge branch 'master' of https://github.com/Devsh-Graphics-Programmin…
Przemog1 Dec 19, 2024
86cabe4
Improved mul function
Przemog1 Dec 19, 2024
0770eb9
isinf and isnan workaround
Przemog1 Dec 19, 2024
6690cf8
Merge branch 'master' into maths_for_bxdfs_hlsl
keptsecret Dec 20, 2024
a517d22
review changes
keptsecret Dec 20, 2024
911d8fc
use templated glm methods
keptsecret Dec 20, 2024
14e1010
reverted changes, use glm
keptsecret Dec 20, 2024
fb7b643
Updated examples
Przemog1 Dec 20, 2024
845707c
Added tgmath.hlsl
Przemog1 Dec 20, 2024
3f1db30
Moved some functions to tgmath.hlsl
Przemog1 Dec 20, 2024
f0c217f
Resolved conflicts, merged cpp_intrinsics_improvements
Przemog1 Dec 20, 2024
7e1edae
Updated examples
Przemog1 Dec 20, 2024
5fd3934
Added constraints to the `floor` function
Przemog1 Dec 20, 2024
2f38f2a
Refactor
Przemog1 Dec 20, 2024
7e73054
Refactored the `floor` function
Przemog1 Dec 21, 2024
0276f8e
`Floor` func improvement
Przemog1 Dec 21, 2024
4d0d477
Resolved conflicts, merged master
Przemog1 Dec 21, 2024
147c080
Added negate and copy sign functions
Przemog1 Dec 21, 2024
a640976
Moved flipSign function to ieee754.hlsl
Przemog1 Dec 21, 2024
70f2870
Fixed bitcount, added normalize
Przemog1 Dec 23, 2024
9dc8b43
Refactored `hlsl::cross` function
Przemog1 Dec 23, 2024
677b176
Refactor
Przemog1 Dec 23, 2024
949a972
fix
Przemog1 Dec 23, 2024
04f60ab
fix refract functions
keptsecret Dec 26, 2024
6fecfa9
Now every tgmath function utilize helpers
Przemog1 Dec 28, 2024
abf6ed7
Merge branch 'maths_for_bxdfs_hlsl' of https://github.com/Devsh-Graph…
Przemog1 Dec 28, 2024
0d5ede1
Resolved conflicts, merged master
Przemog1 Dec 28, 2024
19c30e5
Fixed NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE
Przemog1 Dec 30, 2024
2e56fc9
Added Vector and Matrix concepts
Przemog1 Dec 30, 2024
f99ad10
Added `all` and `any`
Przemog1 Dec 30, 2024
9a8842d
fix cmakelist duplicate entry, float literal
keptsecret Jan 3, 2025
274e56f
Integrated concepts into tgmath.hlsl and intrinsics.hlsl
Przemog1 Jan 3, 2025
e3bf45a
Merge branch 'maths_for_bxdfs_hlsl' of https://github.com/Devsh-Graph…
Przemog1 Jan 3, 2025
6a2bcff
Added `FloatingPointLike` concept
Przemog1 Jan 3, 2025
9a44ce8
Refactored concepts
Przemog1 Jan 7, 2025
5eb02f2
Corrections
Przemog1 Jan 7, 2025
2fb8252
Removed float64_t partial specializations
Przemog1 Jan 8, 2025
96efff4
fix frisvad mat, lp_norm loop
keptsecret Jan 9, 2025
4c0536f
Integrated concepts into intrinsics.hlsl functions and fixed some emu…
Przemog1 Jan 10, 2025
76fbce1
Merge branch 'maths_for_bxdfs_hlsl' of https://github.com/Devsh-Graph…
Przemog1 Jan 10, 2025
18c3257
removed dupe xoroshiro.hlsl
keptsecret Jan 14, 2025
c0531fb
fix length_helper
keptsecret Jan 14, 2025
bf8b628
update example conflict
keptsecret Jan 24, 2025
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
53 changes: 2 additions & 51 deletions include/nbl/builtin/hlsl/concepts.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ concept NBL_CONCEPT_NAME = requires BOOST_PP_EXPR_IF(LOCAL_PARAM_COUNT,(BOOST_PP
//
#define NBL_IMPL_CONCEPT_REQ_TYPE(...) typename __VA_ARGS__;
#define NBL_IMPL_CONCEPT_REQ_EXPR(...) __VA_ARGS__;
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) {E}; C<decltype E,__VA_ARGS__ >;
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) {E}; C<decltype E __VA_OPT__(,) __VA_ARGS__ >;
//
#define NBL_IMPL_CONCEPT (NBL_IMPL_CONCEPT_REQ_TYPE,NBL_IMPL_CONCEPT_REQ_EXPR,NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE)
//
Expand All @@ -77,56 +77,8 @@ concept NBL_CONCEPT_NAME = requires BOOST_PP_EXPR_IF(LOCAL_PARAM_COUNT,(BOOST_PP
#define NBL_CONCEPT_END(SEQ) BOOST_PP_SEQ_FOR_EACH_I(NBL_IMPL_CONCEPT_END_DEF, DUMMY, SEQ) \
}


#include <concepts>

// Alias some of the std concepts in nbl. As this is C++20 only, we don't need to use
// the macros here.
template <typename T, typename U>
concept same_as = std::same_as<T, U>;

template <typename D, typename B>
concept derived_from = std::derived_from<D, B>;

template <typename F, typename T>
concept convertible_to = std::convertible_to<F, T>;

template <typename T, typename F>
concept assignable_from = std::assignable_from<T, F>;

template <typename T, typename U>
concept common_with = std::common_with<T, U>;

template <typename T>
concept integral = std::integral<T>;

template <typename T>
concept signed_integral = std::signed_integral<T>;

template <typename T>
concept unsigned_integral = std::unsigned_integral<T>;

template <typename T>
concept floating_point = std::floating_point<T>;


// Some other useful concepts.

template<typename T, typename... Ts>
concept any_of = (same_as<T, Ts> || ...);

template <typename T>
concept scalar = floating_point<T> || integral<T>;

template <typename T>
concept vectorial = is_vector<T>::value;

template <typename T>
concept matricial = is_matrix<T>::value;

#else


// to define a concept using `concept Name = SomeContexprBoolCondition<T>;`
#define NBL_BOOL_CONCEPT NBL_CONSTEXPR bool

Expand All @@ -144,7 +96,6 @@ concept matricial = is_matrix<T>::value;
// condition, use instead of the closing `>` of a function template
#define NBL_FUNC_REQUIRES(...) ,::nbl::hlsl::enable_if_t<(__VA_ARGS__),bool> = true>


//
#define NBL_CONCEPT_BEGIN(LOCAL_PARAM_COUNT) namespace BOOST_PP_CAT(__concept__,NBL_CONCEPT_NAME) \
{
Expand All @@ -153,7 +104,7 @@ concept matricial = is_matrix<T>::value;
//
#define NBL_IMPL_CONCEPT_REQ_TYPE(...) ::nbl::hlsl::make_void_t<typename __VA_ARGS__ >
#define NBL_IMPL_CONCEPT_REQ_EXPR(...) ::nbl::hlsl::make_void_t<decltype(__VA_ARGS__)>
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) ::nbl::hlsl::enable_if_t<C<decltype E ,__VA_ARGS__ > >
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) ::nbl::hlsl::enable_if_t<C<decltype E __VA_OPT__(,) __VA_ARGS__ > >
//
#define NBL_IMPL_CONCEPT_SFINAE (NBL_IMPL_CONCEPT_REQ_TYPE,NBL_IMPL_CONCEPT_REQ_EXPR,NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE)
//
Expand Down
80 changes: 80 additions & 0 deletions include/nbl/builtin/hlsl/concepts/core.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (C) 2024-2025 - 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_CONCEPTS_CORE_HLSL_INCLUDED_
#define _NBL_BUILTIN_HLSL_CONCEPTS_CORE_HLSL_INCLUDED_


#include <nbl/builtin/hlsl/concepts.hlsl>
#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
#include <nbl/builtin/hlsl/type_traits.hlsl>

namespace nbl
{
namespace hlsl
{
namespace concepts
{

template<typename T, typename U>
NBL_BOOL_CONCEPT same_as = is_same_v<T, U>;

template<typename T>
NBL_BOOL_CONCEPT Integral = nbl::hlsl::is_integral_v<T>;

template<typename T>
NBL_BOOL_CONCEPT SignedIntegral = nbl::hlsl::is_signed_v<T> && nbl::hlsl::is_integral_v<T>;

template<typename T>
NBL_BOOL_CONCEPT UnsignedIntegral = !nbl::hlsl::is_signed_v<T> && ::nbl::hlsl::is_integral_v<T>;

template<typename T>
NBL_BOOL_CONCEPT FloatingPoint = nbl::hlsl::is_floating_point_v<T>;

template <typename T>
NBL_BOOL_CONCEPT Scalar = nbl::hlsl::is_scalar_v<T>;

template<typename T>
NBL_BOOL_CONCEPT IntegralScalar = nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;

template<typename T>
NBL_BOOL_CONCEPT SignedIntegralScalar = nbl::hlsl::is_signed_v<T> && nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;

template<typename T>
NBL_BOOL_CONCEPT UnsignedIntegralScalar = !nbl::hlsl::is_signed_v<T> && ::nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;

template<typename T>
NBL_BOOL_CONCEPT FloatingPointScalar = nbl::hlsl::is_floating_point_v<T> && nbl::hlsl::is_scalar_v<T>;

// TODO: implement when hlsl::is_base_of is done
//#define NBL_CONCEPT_NAME DerivedFrom
// ...

// TODO: implement when hlsl::is_converible is done
//#define NBL_CONCEPT_NAME ConvertibleTo
// ...

// TODO?
//#define NBL_CONCEPT_NAME AssignableFrom

// TODO?
//template <typename T, typename U>
//concept common_with = std::common_with<T, U>;

namespace impl
{
template<typename T>
struct IsEmulatingFloatingPointType
{
static const bool value = nbl::hlsl::is_floating_point_v<T>;
};
}

//! Floating point types are native floating point types or types that imitate native floating point types (for example emulated_float64_t)
template<typename T>
NBL_BOOL_CONCEPT FloatingPointLikeScalar = impl::IsEmulatingFloatingPointType<T>::value;

}
}
}
#endif
27 changes: 27 additions & 0 deletions include/nbl/builtin/hlsl/concepts/matrix.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2024-2025 - 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_CONCEPTS_MATRIX_HLSL_INCLUDED_
#define _NBL_BUILTIN_HLSL_CONCEPTS_MATRIX_HLSL_INCLUDED_


#include <nbl/builtin/hlsl/concepts.hlsl>
#include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>

namespace nbl
{
namespace hlsl
{
namespace concepts
{

template<typename T>
NBL_BOOL_CONCEPT Matrix = is_matrix<T>::value;

template<typename T>
NBL_BOOL_CONCEPT Matricial = matrix_traits<T>::IsMatrix;

}
}
}
#endif
48 changes: 48 additions & 0 deletions include/nbl/builtin/hlsl/concepts/vector.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (C) 2024-2025 - 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_CONCEPTS_VECTOR_HLSL_INCLUDED_
#define _NBL_BUILTIN_HLSL_CONCEPTS_VECTOR_HLSL_INCLUDED_


#include <nbl/builtin/hlsl/concepts.hlsl>
#include <nbl/builtin/hlsl/concepts/core.hlsl>
#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
#include <nbl/builtin/hlsl/type_traits.hlsl>

namespace nbl
{
namespace hlsl
{
namespace concepts
{

//! Concept for native vectors.
template<typename T>
NBL_BOOL_CONCEPT Vector = is_vector<T>::value;
template<typename T>
NBL_BOOL_CONCEPT FloatingPointVector = concepts::Vector<T> && concepts::FloatingPointScalar<typename vector_traits<T>::scalar_type>;
template<typename T>
NBL_BOOL_CONCEPT IntVector = concepts::Vector<T> && (is_integral_v<typename vector_traits<T>::scalar_type>);
template<typename T>
NBL_BOOL_CONCEPT SignedIntVector = concepts::Vector<T> && concepts::SignedIntegralScalar<typename vector_traits<T>::scalar_type>;

//! Concept for native vectors and vector like structs.
template<typename T>
NBL_BOOL_CONCEPT Vectorial = vector_traits<T>::IsVector;

#include <nbl/builtin/hlsl/concepts/__end.hlsl>

template<typename T>
NBL_BOOL_CONCEPT FloatingPointVectorial = concepts::Vectorial<T> && concepts::FloatingPointScalar<typename vector_traits<T>::scalar_type>;
template<typename T>
NBL_BOOL_CONCEPT FloatingPointLikeVectorial = concepts::Vectorial<T> && concepts::FloatingPointLikeScalar<typename vector_traits<T>::scalar_type>;
template<typename T>
NBL_BOOL_CONCEPT IntVectorial = concepts::Vectorial<T> && (is_integral_v<typename vector_traits<T>::scalar_type>);
template<typename T>
NBL_BOOL_CONCEPT SignedIntVectorial = concepts::Vectorial<T> && concepts::SignedIntegralScalar<typename vector_traits<T>::scalar_type>;

}
}
}
#endif
Loading