Skip to content

Commit c194f4e

Browse files
committed
Merge branch 'master' into bxdf_fixes_non_ct
2 parents 1099d60 + a5f2718 commit c194f4e

File tree

8 files changed

+85
-36
lines changed

8 files changed

+85
-36
lines changed

include/nbl/builtin/hlsl/bxdf/common.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,10 +1126,14 @@ struct beta
11261126
{
11271127
assert(x >= T(0.999) && y >= T(0.999));
11281128

1129+
#ifdef __HLSL_VERSION
11291130
#pragma dxc diagnostic push
11301131
#pragma dxc diagnostic ignored "-Wliteral-range"
1132+
#endif
11311133
const T thresholds[4] = { 0, 5e5, 1e6, 1e15 }; // threshold values gotten from testing when the function returns nan/inf/1
1134+
#ifdef __HLSL_VERSION
11321135
#pragma dxc diagnostic pop
1136+
#endif
11331137
if (x+y > thresholds[mpl::find_lsb_v<sizeof(T)>])
11341138
return T(0.0);
11351139

include/nbl/builtin/hlsl/math/linalg/transform.hlsl

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
#ifndef _NBL_BUILTIN_HLSL_MATH_LINALG_TRANSFORM_INCLUDED_
55
#define _NBL_BUILTIN_HLSL_MATH_LINALG_TRANSFORM_INCLUDED_
66

7-
87
#include <nbl/builtin/hlsl/mpl.hlsl>
98
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
109
#include <nbl/builtin/hlsl/concepts.hlsl>
1110

12-
1311
namespace nbl
1412
{
1513
namespace hlsl
@@ -19,35 +17,81 @@ namespace math
1917
namespace linalg
2018
{
2119

22-
/// Builds a rotation 4 * 4 matrix created from an axis vector and an angle.
20+
/// Builds a rotation 3 * 3 matrix created from an axis vector and an angle.
2321
///
2422
/// @param angle Rotation angle expressed in radians.
2523
/// @param axis Rotation axis, must be normalized.
2624
///
2725
/// @tparam T A floating-point scalar type
2826
template <typename T>
29-
matrix<T, 4, 4> rotation_mat(T angle, vector<T, 3> const& axis)
27+
matrix<T, 3, 3> rotation_mat(T angle, const vector<T, 3> axis)
3028
{
31-
T const a = angle;
32-
T const c = cos(a);
33-
T const s = sin(a);
29+
const T a = angle;
30+
const T c = cos(a);
31+
const T s = sin(a);
32+
33+
vector<T, 3> temp = hlsl::promote<vector<T, 3> >((T(1.0) - c) * axis);
34+
35+
matrix<T, 3, 3> rotation;
36+
rotation[0][0] = c + temp[0] * axis[0];
37+
rotation[0][1] = temp[1] * axis[0] - s * axis[2];
38+
rotation[0][2] = temp[2] * axis[0] + s * axis[1];
3439

35-
vector<T, 3> temp((T(1) - c) * axis);
40+
rotation[1][0] = temp[0] * axis[1] + s * axis[2];
41+
rotation[1][1] = c + temp[1] * axis[1];
42+
rotation[1][2] = temp[2] * axis[1] - s * axis[0];
3643

37-
matrix<T, 4, 4> rotation;
38-
rotation[0][0] = c + temp[0] * axis[0];
39-
rotation[0][1] = temp[1] * axis[0] - s * axis[2];
40-
rotation[0][2] = temp[2] * axis[0] + s * axis[1];
44+
rotation[2][0] = temp[0] * axis[2] - s * axis[1];
45+
rotation[2][1] = temp[1] * axis[2] + s * axis[0];
46+
rotation[2][2] = c + temp[2] * axis[2];
4147

42-
rotation[1][0] = temp[0] * axis[1] + s * axis[2];
43-
rotation[1][1] = c + temp[1] * axis[1];
44-
rotation[1][2] = temp[2] * axis[1] - s * axis[0];
48+
return rotation;
49+
}
50+
51+
namespace impl
52+
{
53+
template<uint16_t MOut, uint16_t MIn, typename T>
54+
struct zero_expand_helper
55+
{
56+
static vector<T, MOut> __call(const vector<T, MIn> inVec)
57+
{
58+
return vector<T, MOut>(inVec, vector<T, MOut - MIn>(0));
59+
}
60+
};
61+
template<uint16_t M, typename T>
62+
struct zero_expand_helper<M,M,T>
63+
{
64+
static vector<T, M> __call(const vector<T, M> inVec)
65+
{
66+
return inVec;
67+
}
68+
};
69+
}
70+
71+
template<uint16_t MOut, uint16_t MIn, typename T NBL_FUNC_REQUIRES(MOut >= MIn)
72+
vector<T, MOut> zero_expand(vector<T, MIn> inVec)
73+
{
74+
return impl::zero_expand_helper<MOut, MIn, T>::__call(inVec);
75+
}
76+
77+
template <uint16_t NOut, uint16_t MOut, uint16_t NIn, uint16_t MIn, typename T NBL_FUNC_REQUIRES(NOut >= NIn && MOut >= MIn)
78+
matrix<T, NOut, MOut> promote_affine(const matrix<T, NIn, MIn> inMatrix)
79+
{
80+
matrix<T, NOut, MOut> retval;
4581

46-
rotation[2][0] = temp[0] * axis[2] - s * axis[1];
47-
rotation[2][1] = temp[1] * axis[2] + s * axis[0];
48-
rotation[2][2] = c + temp[2] * axis[2];
82+
using out_row_t = hlsl::vector<T, MOut>;
4983

50-
return rotation;
84+
NBL_UNROLL for (uint32_t row_i = 0; row_i < NIn; row_i++)
85+
{
86+
retval[row_i] = zero_expand<MOut, MIn>(inMatrix[row_i]);
87+
}
88+
NBL_UNROLL for (uint32_t row_i = NIn; row_i < NOut; row_i++)
89+
{
90+
retval[row_i] = promote<out_row_t>(0.0);
91+
if (row_i >= MIn && row_i < MOut)
92+
retval[row_i][row_i] = T(1.0);
93+
}
94+
return retval;
5195
}
5296

5397
}

include/nbl/builtin/hlsl/tgmath/impl.hlsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,14 @@ struct l2gamma_helper<T NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
539539
// implementation derived from Numerical Recipes in C, transformed for log2
540540
static T __call(T x)
541541
{
542+
#ifdef __HLSL_VERSION
542543
#pragma dxc diagnostic push
543544
#pragma dxc diagnostic ignored "-Wliteral-range"
545+
#endif
544546
const T thresholds[4] = { 0, 5e4, 1e36, 1e305 }; // threshold values gotten from testing when the function returns nan/inf
547+
#ifdef __HLSL_VERSION
545548
#pragma dxc diagnostic pop
549+
#endif
546550
if (x > thresholds[mpl::find_lsb_v<sizeof(T)>])
547551
return bit_cast<T>(numeric_limits<T>::infinity);
548552

@@ -584,10 +588,14 @@ struct beta_helper<T NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
584588
// implementation from Numerical Recipes in C, 2nd ed.
585589
static T __call(T v1, T v2)
586590
{
591+
#ifdef __HLSL_VERSION
587592
#pragma dxc diagnostic push
588593
#pragma dxc diagnostic ignored "-Wliteral-range"
594+
#endif
589595
const T thresholds[4] = { 0, 2e4, 1e6, 1e15 }; // threshold values gotten from testing when the function returns nan/inf/1
596+
#ifdef __HLSL_VERSION
590597
#pragma dxc diagnostic pop
598+
#endif
591599
if (v1+v2 > thresholds[mpl::find_lsb_v<sizeof(T)>])
592600
return T(0.0);
593601

include/nbl/core/IReferenceCounted.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class NBL_FORCE_EBO IReferenceCounted : public Interface, public AllocationOverr
133133
// Old destructor, but needed virtual for abstractness!
134134
// _NBL_INTERFACE_CHILD_DEFAULT(IReferenceCounted);
135135
//! Destructor, no need to define really, but make it pure virtual to truly prevent instantiation.
136-
NBL_API2 virtual ~IReferenceCounted() = 0;
136+
virtual ~IReferenceCounted() = 0;
137137

138138
//! Sets the debug name of the object.
139139
/** The Debugname may only be set and changed by the object
@@ -155,6 +155,13 @@ class NBL_FORCE_EBO IReferenceCounted : public Interface, public AllocationOverr
155155
static_assert(alignof(std::atomic<uint32_t>) <= _NBL_SIMD_ALIGNMENT/2u, "This compiler has a problem with its atomic int decl!");
156156
static_assert(sizeof(std::atomic<uint32_t>) <= _NBL_SIMD_ALIGNMENT/2u, "This compiler has a problem with its atomic int decl!");
157157
};
158+
159+
// yes pure virt can be inline, just needs a definition outside the class
160+
inline IReferenceCounted::~IReferenceCounted()
161+
{
162+
_NBL_DEBUG_BREAK_IF(ReferenceCounter!=0);
163+
}
164+
158165
static_assert(alignof(IReferenceCounted) == _NBL_SIMD_ALIGNMENT, "This compiler has a problem respecting alignment!");
159166

160167
template<typename T>

src/nbl/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ unset(NABLA_HEADERS_PUBLIC2 ${NBL_TMP_FULL_PATHS})
122122
# <=
123123

124124
set(NBL_CORE_SOURCES
125-
core/IReferenceCounted.cpp
126125
core/alloc/refctd_memory_resource.cpp
127126
core/hash/blake.cpp
128127
)

src/nbl/asset/utils/CGeometryCreator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ core::smart_refctd_ptr<ICPUGeometryCollection> CGeometryCreator::createArrow(
749749
});
750750
const auto coneTransform = hlsl::math::linalg::rotation_mat(hlsl::numbers::pi<hlsl::float32_t> * -0.5f, hlsl::float32_t3(1.f, 0.f, 0.f));
751751
geometries->push_back({
752-
.transform = hlsl::float32_t3x4(coneTransform),
752+
.transform = hlsl::math::linalg::promote_affine<3, 4>(coneTransform),
753753
.geometry = cone
754754
});
755755
return collection;

src/nbl/core/IReferenceCounted.cpp

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)