Skip to content

Commit c1021c8

Browse files
committed
Moved *struct functions to tgmath.hlsl
1 parent c946db5 commit c1021c8

File tree

8 files changed

+112
-111
lines changed

8 files changed

+112
-111
lines changed

include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <boost/preprocessor/comparison/not_equal.hpp>
1616
#include <boost/preprocessor/punctuation/comma_if.hpp>
1717
#include <boost/preprocessor/seq/for_each_i.hpp>
18-
#include <nbl/builtin/hlsl/cpp_compat/output_structs.hlsl>
1918

2019
namespace nbl
2120
{
@@ -82,10 +81,6 @@ template<typename T NBL_STRUCT_CONSTRAINABLE>
8281
struct reflect_helper;
8382
template<typename T, typename U NBL_STRUCT_CONSTRAINABLE>
8483
struct refract_helper;
85-
template<typename T NBL_STRUCT_CONSTRAINABLE>
86-
struct modfStruct_helper;
87-
template<typename T NBL_STRUCT_CONSTRAINABLE>
88-
struct frexpStruct_helper;
8984

9085
#ifdef __HLSL_VERSION // HLSL only specializations
9186

@@ -141,8 +136,6 @@ template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(clamp_helper, sClamp, (
141136
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(smoothStep_helper, smoothStep, (T), (T)(T)(T), T)
142137
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(faceForward_helper, faceForward, (T), (T)(T)(T), T)
143138
template<typename T, typename U> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(refract_helper, refract, (T)(U), (T)(T)(U), T)
144-
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(modfStruct_helper, modfStruct, (T), (T), ModfOutput<T>)
145-
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(frexpStruct_helper, frexpStruct, (T), (T), FrexpOutput<T>)
146139

147140
#define BITCOUNT_HELPER_RETRUN_TYPE conditional_t<is_vector_v<T>, vector<int32_t, vector_traits<T>::Dimension>, int32_t>
148141
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(bitCount_helper, bitCount, (T), (T), BITCOUNT_HELPER_RETRUN_TYPE)
@@ -517,34 +510,6 @@ struct refract_helper<T, U>
517510
}
518511
};
519512

520-
template<typename T>
521-
requires concepts::FloatingPointScalar<T>
522-
struct modfStruct_helper<T>
523-
{
524-
using return_t = ModfOutput<T>;
525-
static inline return_t __call(const T val)
526-
{
527-
return_t output;
528-
output.fractionalPart = std::modf(val, &output.wholeNumberPart);
529-
530-
return output;
531-
}
532-
};
533-
534-
template<typename T>
535-
requires concepts::FloatingPointScalar<T>
536-
struct frexpStruct_helper<T>
537-
{
538-
using return_t = FrexpOutput<T>;
539-
static inline return_t __call(const T val)
540-
{
541-
return_t output;
542-
output.significand = std::frexp(val, &output.exponent);
543-
544-
return output;
545-
}
546-
};
547-
548513
#endif // C++ only specializations
549514

550515
// C++ and HLSL specializations
@@ -800,67 +765,6 @@ struct smoothStep_helper<T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT) >
800765
}
801766
};
802767

803-
template<typename T>
804-
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT)
805-
struct modfStruct_helper<T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT) >
806-
{
807-
using return_t = ModfOutput<T>;
808-
static return_t __call(NBL_CONST_REF_ARG(T) x)
809-
{
810-
using traits = hlsl::vector_traits<T>;
811-
array_get<T, typename traits::scalar_type> getter;
812-
array_set<T, typename traits::scalar_type> setter;
813-
814-
T fracPartOut;
815-
T intPartOut;
816-
for (uint32_t i = 0; i < traits::Dimension; ++i)
817-
{
818-
using component_return_t = ModfOutput<typename vector_traits<T>::scalar_type>;
819-
component_return_t result = modfStruct_helper<typename traits::scalar_type>::__call(getter(x, i));
820-
821-
setter(fracPartOut, i, result.fractionalPart);
822-
setter(intPartOut, i, result.wholeNumberPart);
823-
}
824-
825-
return_t output;
826-
output.fractionalPart = fracPartOut;
827-
output.wholeNumberPart = intPartOut;
828-
829-
return output;
830-
}
831-
};
832-
833-
template<typename T>
834-
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT)
835-
struct frexpStruct_helper<T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT) >
836-
{
837-
using return_t = FrexpOutput<T>;
838-
static return_t __call(NBL_CONST_REF_ARG(T) x)
839-
{
840-
using traits = hlsl::vector_traits<T>;
841-
array_get<T, typename traits::scalar_type> getter;
842-
array_set<T, typename traits::scalar_type> significandSetter;
843-
array_set<T, typename traits::scalar_type> exponentSetter;
844-
845-
T significandOut;
846-
T exponentOut;
847-
for (uint32_t i = 0; i < traits::Dimension; ++i)
848-
{
849-
using component_return_t = FrexpOutput<typename vector_traits<T>::scalar_type>;
850-
component_return_t result = frexpStruct_helper<typename traits::scalar_type>::__call(getter(x, i));
851-
852-
significandSetter(significandOut, i, result.significand);
853-
exponentSetter(exponentOut, i, result.exponent);
854-
}
855-
856-
return_t output;
857-
output.significand = significandOut;
858-
output.exponent = exponentOut;
859-
860-
return output;
861-
}
862-
};
863-
864768
}
865769
}
866770
}

include/nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,6 @@ inline T refract(NBL_CONST_REF_ARG(T) I, NBL_CONST_REF_ARG(T) N, NBL_CONST_REF_A
231231
return cpp_compat_intrinsics_impl::refract_helper<T, U>::__call(I, N, eta);
232232
}
233233

234-
template<typename T>
235-
inline ModfOutput<T> modfStruct(NBL_CONST_REF_ARG(T) val)
236-
{
237-
return cpp_compat_intrinsics_impl::modfStruct_helper<T>::__call(val);
238-
}
239-
240-
template<typename T>
241-
inline FrexpOutput<T> frexpStruct(NBL_CONST_REF_ARG(T) val)
242-
{
243-
return cpp_compat_intrinsics_impl::frexpStruct_helper<T>::__call(val);
244-
}
245-
246234
#ifdef __HLSL_VERSION
247235
#define NAMESPACE spirv
248236
#else

include/nbl/builtin/hlsl/impl/tgmath_impl.hlsl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <nbl/builtin/hlsl/spirv_intrinsics/core.hlsl>
88
#include <nbl/builtin/hlsl/spirv_intrinsics/glsl.std.450.hlsl>
99
#include <nbl/builtin/hlsl/ieee754.hlsl>
10+
#include <nbl/builtin/hlsl/tgmath/output_structs.hlsl>
1011

1112
// C++ includes
1213
#ifndef __HLSL_VERSION
@@ -79,6 +80,10 @@ template<typename T NBL_STRUCT_CONSTRAINABLE>
7980
struct fma_helper;
8081
template<typename T, typename U NBL_STRUCT_CONSTRAINABLE>
8182
struct ldexp_helper;
83+
template<typename T NBL_STRUCT_CONSTRAINABLE>
84+
struct modfStruct_helper;
85+
template<typename T NBL_STRUCT_CONSTRAINABLE>
86+
struct frexpStruct_helper;
8287

8388
#ifdef __HLSL_VERSION
8489

@@ -118,6 +123,8 @@ template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(ceil_helper, ceil, (T),
118123
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(pow_helper, pow, (T), (T)(T), T)
119124
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(fma_helper, fma, (T), (T)(T)(T), T)
120125
template<typename T, typename U> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(ldexp_helper, ldexp, (T)(U), (T)(U), T)
126+
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(modfStruct_helper, modfStruct, (T), (T), ModfOutput<T>)
127+
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(frexpStruct_helper, frexpStruct, (T), (T), FrexpOutput<T>)
121128

122129
#define ISINF_AND_ISNAN_RETURN_TYPE conditional_t<is_vector_v<T>, vector<bool, vector_traits<T>::Dimension>, bool>
123130
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(isinf_helper, isInf, (T), (T), ISINF_AND_ISNAN_RETURN_TYPE)
@@ -327,6 +334,34 @@ struct ldexp_helper<T, U NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T> &&
327334
}
328335
};
329336

337+
template<typename T>
338+
requires concepts::FloatingPointScalar<T>
339+
struct modfStruct_helper<T>
340+
{
341+
using return_t = ModfOutput<T>;
342+
static inline return_t __call(const T val)
343+
{
344+
return_t output;
345+
output.fractionalPart = std::modf(val, &output.wholeNumberPart);
346+
347+
return output;
348+
}
349+
};
350+
351+
template<typename T>
352+
requires concepts::FloatingPointScalar<T>
353+
struct frexpStruct_helper<T>
354+
{
355+
using return_t = FrexpOutput<T>;
356+
static inline return_t __call(const T val)
357+
{
358+
return_t output;
359+
output.significand = std::frexp(val, &output.exponent);
360+
361+
return output;
362+
}
363+
};
364+
330365
#endif // C++ only specializations
331366

332367
// C++ and HLSL specializations
@@ -480,6 +515,67 @@ struct ldexp_helper<T, U NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT && (v
480515
}
481516
};
482517

518+
template<typename T>
519+
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT)
520+
struct modfStruct_helper<T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT) >
521+
{
522+
using return_t = ModfOutput<T>;
523+
static return_t __call(NBL_CONST_REF_ARG(T) x)
524+
{
525+
using traits = hlsl::vector_traits<T>;
526+
array_get<T, typename traits::scalar_type> getter;
527+
array_set<T, typename traits::scalar_type> setter;
528+
529+
T fracPartOut;
530+
T intPartOut;
531+
for (uint32_t i = 0; i < traits::Dimension; ++i)
532+
{
533+
using component_return_t = ModfOutput<typename vector_traits<T>::scalar_type>;
534+
component_return_t result = modfStruct_helper<typename traits::scalar_type>::__call(getter(x, i));
535+
536+
setter(fracPartOut, i, result.fractionalPart);
537+
setter(intPartOut, i, result.wholeNumberPart);
538+
}
539+
540+
return_t output;
541+
output.fractionalPart = fracPartOut;
542+
output.wholeNumberPart = intPartOut;
543+
544+
return output;
545+
}
546+
};
547+
548+
template<typename T>
549+
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT)
550+
struct frexpStruct_helper<T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT) >
551+
{
552+
using return_t = FrexpOutput<T>;
553+
static return_t __call(NBL_CONST_REF_ARG(T) x)
554+
{
555+
using traits = hlsl::vector_traits<T>;
556+
array_get<T, typename traits::scalar_type> getter;
557+
array_set<T, typename traits::scalar_type> significandSetter;
558+
array_set<T, typename traits::scalar_type> exponentSetter;
559+
560+
T significandOut;
561+
T exponentOut;
562+
for (uint32_t i = 0; i < traits::Dimension; ++i)
563+
{
564+
using component_return_t = FrexpOutput<typename vector_traits<T>::scalar_type>;
565+
component_return_t result = frexpStruct_helper<typename traits::scalar_type>::__call(getter(x, i));
566+
567+
significandSetter(significandOut, i, result.significand);
568+
exponentSetter(exponentOut, i, result.exponent);
569+
}
570+
571+
return_t output;
572+
output.significand = significandOut;
573+
output.exponent = exponentOut;
574+
575+
return output;
576+
}
577+
};
578+
483579
#undef VECTOR_SPECIALIZATION_CONCEPT
484580

485581
}

include/nbl/builtin/hlsl/spirv_intrinsics/glsl.std.450.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
77
#include <nbl/builtin/hlsl/cpp_compat/basic.h>
88
#include <nbl/builtin/hlsl/concepts.hlsl>
9-
#include <nbl/builtin/hlsl/cpp_compat/output_structs.hlsl>
9+
#include <nbl/builtin/hlsl/tgmath/output_structs.hlsl>
1010
#include "spirv/unified1/GLSL.std.450.h"
1111

1212
namespace nbl

include/nbl/builtin/hlsl/tgmath.hlsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ inline T ldexp(NBL_CONST_REF_ARG(T) arg, NBL_CONST_REF_ARG(U) exp)
162162
return tgmath_impl::ldexp_helper<T, U>::__call(arg, exp);
163163
}
164164

165+
template<typename T>
166+
inline ModfOutput<T> modfStruct(NBL_CONST_REF_ARG(T) val)
167+
{
168+
return tgmath_impl::modfStruct_helper<T>::__call(val);
169+
}
170+
171+
template<typename T>
172+
inline FrexpOutput<T> frexpStruct(NBL_CONST_REF_ARG(T) val)
173+
{
174+
return tgmath_impl::frexpStruct_helper<T>::__call(val);
175+
}
176+
165177
}
166178
}
167179

src/nbl/builtin/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/glsl.std.450
243243
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat.hlsl")
244244
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat/basic.h")
245245
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat/intrinsics.hlsl")
246-
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat/output_structs.hlsl")
247246
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat/matrix.hlsl")
248247
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat/promote.hlsl")
249248
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat/vector.hlsl")
@@ -358,5 +357,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/concepts/accessors/loadable_i
358357
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/concepts/accessors/mip_mapped.hlsl")
359358
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/concepts/accessors/storable_image.hlsl")
360359
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/concepts/accessors/fft.hlsl")
360+
#tgmath
361+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/tgmath/output_structs.hlsl")
361362

362363
ADD_CUSTOM_BUILTIN_RESOURCES(nblBuiltinResourceData NBL_RESOURCES_TO_EMBED "${NBL_ROOT_PATH}/include" "nbl/builtin" "nbl::builtin" "${NBL_ROOT_PATH_BINARY}/include" "${NBL_ROOT_PATH_BINARY}/src" "STATIC" "INTERNAL")

0 commit comments

Comments
 (0)