Skip to content

Commit 8ec80ca

Browse files
committed
Merge branch 'master' into type_traits2
2 parents 0f0e860 + efee44e commit 8ec80ca

28 files changed

+1500
-50
lines changed

3rdparty/dxc/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ if(NBL_EMBED_BUILTIN_RESOURCES)
172172
include("${NBL_ROOT_PATH}/src/nbl/builtin/utils.cmake")
173173

174174
# SPIRV Header in builtin resources, nbl paths as aliases
175-
LIST_BUILTIN_RESOURCE(SPIRV_RESOURCES_TO_EMBED "1.2/spirv.h")
176-
LIST_BUILTIN_RESOURCE(SPIRV_RESOURCES_TO_EMBED "1.2/spirv.hpp")
175+
LIST_BUILTIN_RESOURCE(SPIRV_RESOURCES_TO_EMBED "unified1/spirv.h")
176+
LIST_BUILTIN_RESOURCE(SPIRV_RESOURCES_TO_EMBED "unified1/spirv.hpp")
177177

178178
ADD_CUSTOM_BUILTIN_RESOURCES(dxcBuiltinResourceData SPIRV_RESOURCES_TO_EMBED "${_SPIRV_BR_BUNDLE_SEARCH_DIRECTORY_}" "spirv" "spirv::builtin" "${_SPIRV_BR_OUTPUT_DIRECTORY_HEADER_}" "${_SPIRV_BR_OUTPUT_DIRECTORY_SOURCE_}" "STATIC" "INTERNAL")
179179
endif()

3rdparty/dxc/dxc

Submodule dxc updated 717 files

examples_tests

include/nbl/builtin/hlsl/binops.hlsl

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// Copyright (C) 2022 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_BINOPS_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_BINOPS_INCLUDED_
6+
7+
namespace nbl
8+
{
9+
namespace hlsl
10+
{
11+
namespace binops
12+
{
13+
template<typename T>
14+
struct bitwise_and
15+
{
16+
T operator()(const T lhs, const T rhs)
17+
{
18+
return lhs&rhs;
19+
}
20+
21+
static T identity()
22+
{
23+
return ~0;
24+
}
25+
};
26+
27+
template<typename T>
28+
struct bitwise_or
29+
{
30+
T operator()(const T lhs, const T rhs)
31+
{
32+
return lhs|rhs;
33+
}
34+
35+
static T identity()
36+
{
37+
return 0;
38+
}
39+
};
40+
41+
template<typename T>
42+
struct bitwise_xor
43+
{
44+
T operator()(const T lhs, const T rhs)
45+
{
46+
return lhs^rhs;
47+
}
48+
49+
static T identity()
50+
{
51+
return 0;
52+
}
53+
};
54+
55+
template<typename T>
56+
struct add
57+
{
58+
T operator()(const T lhs, const T rhs)
59+
{
60+
return lhs+rhs;
61+
}
62+
63+
static T identity()
64+
{
65+
return 0;
66+
}
67+
};
68+
69+
template<typename T>
70+
struct mul
71+
{
72+
T operator()(const T lhs, const T rhs)
73+
{
74+
return lhs*rhs;
75+
}
76+
77+
static T identity()
78+
{
79+
return 1;
80+
}
81+
};
82+
83+
template<typename T>
84+
struct comparator_lt_t
85+
{
86+
bool operator()(const T lhs, const T rhs)
87+
{
88+
return lhs<rhs;
89+
}
90+
};
91+
92+
template<typename T>
93+
struct comparator_gt_t
94+
{
95+
bool operator()(const T lhs, const T rhs)
96+
{
97+
return lhs>rhs;
98+
}
99+
};
100+
101+
template<typename T>
102+
struct comparator_lte_t
103+
{
104+
bool operator()(const T lhs, const T rhs)
105+
{
106+
return lhs<=rhs;
107+
}
108+
};
109+
110+
template<typename T>
111+
struct comparator_gte_t
112+
{
113+
bool operator()(const T lhs, const T rhs)
114+
{
115+
return lhs>=rhs;
116+
}
117+
};
118+
119+
template<typename T>
120+
struct min
121+
{
122+
T operator()(const T lhs, const T rhs)
123+
{
124+
comparator_lt_t<T> comp;
125+
return comp(lhs, rhs) ? lhs : rhs;
126+
}
127+
128+
static T identity()
129+
{
130+
return ~0;
131+
}
132+
};
133+
134+
template<typename T>
135+
struct max
136+
{
137+
T operator()(const T lhs, const T rhs)
138+
{
139+
comparator_gt_t<T> comp;
140+
return comp(lhs, rhs) ? lhs : rhs;
141+
}
142+
143+
static T identity()
144+
{
145+
return 0;
146+
}
147+
};
148+
149+
}
150+
}
151+
}
152+
153+
#endif

include/nbl/builtin/hlsl/bit.hlsl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#ifndef _NBL_BUILTIN_HLSL_BIT_INCLUDED_
2+
#define _NBL_BUILTIN_HLSL_BIT_INCLUDED_
3+
4+
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
5+
6+
#ifndef __HLSL_VERSION
7+
#include <bit>
8+
9+
namespace nbl::hlsl
10+
{
11+
12+
NBL_ALIAS_TEMPLATE_FUNCTION(std::rotl, rotl);
13+
NBL_ALIAS_TEMPLATE_FUNCTION(std::rotr, rotr);
14+
NBL_ALIAS_TEMPLATE_FUNCTION(std::countl_zero, countl_zero);
15+
16+
}
17+
#else
18+
namespace nbl
19+
{
20+
namespace hlsl
21+
{
22+
23+
template<typename T, typename S>
24+
T rotl(T x, S s);
25+
template<typename T, typename S>
26+
T rotr(T x, S s);
27+
28+
template<typename T, typename S>
29+
T rotl(T x, S s)
30+
{
31+
const T N = 32u;
32+
const S r = s % N;
33+
34+
if(r >= 0)
35+
{
36+
return (x << r) | (x >> (N - r));
37+
}
38+
else
39+
{
40+
return (x >> (-r)) | (x << (N - (-r)));
41+
}
42+
}
43+
44+
template<typename T, typename S>
45+
T rotr(T x, S s)
46+
{
47+
const T N = 32u;
48+
const S r = s % N;
49+
50+
if(r >= 0)
51+
{
52+
return (x >> r) | (x << (N - r));
53+
}
54+
else
55+
{
56+
return (x << (-r)) | (x >> (N - (-r)));
57+
}
58+
}
59+
60+
template<typename T>
61+
uint16_t countl_zero(T n)
62+
{
63+
uint16_t result = 0u;
64+
for(uint32_t bits_log2 = 6u; bits_log2 >= 0u; bits_log2--)
65+
{
66+
const uint16_t shift = bits_log2 ? uint16_t(1)<<(bits_log2-1) : 0;
67+
const uint64_t loMask = bits_log2 ? (1ull<<shift)-1 : 0;
68+
const bool chooseHigh = n&(loMask<<shift);
69+
n = uint16_t((chooseHigh ? (n>shift):n)&loMask);
70+
71+
result += uint16_t(chooseHigh ? 0ull : shift);
72+
}
73+
74+
return result;
75+
}
76+
77+
}
78+
}
79+
#endif
80+
81+
#endif

include/nbl/builtin/hlsl/colorspace/EOTF.hlsl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//#include <nbl/builtin/hlsl/common.hlsl>
1010
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
1111
#include <nbl/builtin/hlsl/cpp_compat/promote.hlsl>
12-
#include <nbl/builtin/hlsl/cpp_compat/type_traits.hlsl>
12+
#include <nbl/builtin/hlsl/type_traits.hlsl>
1313

1414
namespace nbl
1515
{
@@ -27,9 +27,9 @@ T identity(NBL_CONST_REF_ARG(T) nonlinear)
2727
}
2828

2929
template<typename T>
30-
T impl_shared_2_4(NBL_CONST_REF_ARG(T) nonlinear, typename scalar_type<T>::type vertex)
30+
T impl_shared_2_4(NBL_CONST_REF_ARG(T) nonlinear, typename type_traits::scalar_type<T>::type vertex)
3131
{
32-
typedef typename scalar_type<T>::type Val_t;
32+
typedef typename type_traits::scalar_type<T>::type Val_t;
3333
bool3 right = (nonlinear > promote<T, Val_t>(vertex));
3434
return lerp(nonlinear / Val_t(12.92), pow((nonlinear + promote<T, Val_t>(0.055)) / Val_t(1.055), promote<T, Val_t>(2.4)), right);
3535
}
@@ -38,7 +38,7 @@ T impl_shared_2_4(NBL_CONST_REF_ARG(T) nonlinear, typename scalar_type<T>::type
3838
template<typename T>
3939
T sRGB(NBL_CONST_REF_ARG(T) nonlinear)
4040
{
41-
typedef typename scalar_type<T>::type Val_t;
41+
typedef typename type_traits::scalar_type<T>::type Val_t;
4242
bool3 negatif = (nonlinear < promote<T, Val_t>(0.0));
4343
T absVal = impl_shared_2_4<T>(abs(nonlinear), 0.04045);
4444
return lerp(absVal, -absVal, negatif);
@@ -48,21 +48,21 @@ T sRGB(NBL_CONST_REF_ARG(T) nonlinear)
4848
template<typename T>
4949
T Display_P3(NBL_CONST_REF_ARG(T) nonlinear)
5050
{
51-
typedef typename scalar_type<T>::type Val_t;
51+
typedef typename type_traits::scalar_type<T>::type Val_t;
5252
return impl_shared_2_4<T>(nonlinear, 0.039000312);
5353
}
5454

5555
template<typename T>
5656
T DCI_P3_XYZ(NBL_CONST_REF_ARG(T) nonlinear)
5757
{
58-
typedef typename scalar_type<T>::type Val_t;
58+
typedef typename type_traits::scalar_type<T>::type Val_t;
5959
return pow(nonlinear * Val_t(52.37), promote<T, Val_t>(2.6));
6060
}
6161

6262
template<typename T>
6363
T SMPTE_170M(NBL_CONST_REF_ARG(T) nonlinear)
6464
{
65-
typedef typename scalar_type<T>::type Val_t;
65+
typedef typename type_traits::scalar_type<T>::type Val_t;
6666
// ITU specs (and the outlier BT.2020) give different constants for these, but they introduce discontinuities in the mapping
6767
// because HDR swapchains often employ the RGBA16_SFLOAT format, this would become apparent because its higher precision than 8,10,12 bits
6868
Val_t alpha = 1.099296826809443; // 1.099 for all ITU but the BT.2020 12 bit encoding, 1.0993 otherwise
@@ -73,7 +73,7 @@ T SMPTE_170M(NBL_CONST_REF_ARG(T) nonlinear)
7373
template<typename T>
7474
T SMPTE_ST2084(NBL_CONST_REF_ARG(T) nonlinear)
7575
{
76-
typedef typename scalar_type<T>::type Val_t;
76+
typedef typename type_traits::scalar_type<T>::type Val_t;
7777
const T invm2 = promote<T, Val_t>(1.0 / 78.84375);
7878
T _common = pow(invm2, invm2);
7979

@@ -89,7 +89,7 @@ T SMPTE_ST2084(NBL_CONST_REF_ARG(T) nonlinear)
8989
template<typename T>
9090
T HDR10_HLG(NBL_CONST_REF_ARG(T) nonlinear)
9191
{
92-
typedef typename scalar_type<T>::type Val_t;
92+
typedef typename type_traits::scalar_type<T>::type Val_t;
9393
// done with log2 so constants are different
9494
const Val_t a = 0.1239574303172;
9595
const T b = promote<T, Val_t>(0.02372241);
@@ -101,21 +101,21 @@ T HDR10_HLG(NBL_CONST_REF_ARG(T) nonlinear)
101101
template<typename T>
102102
T AdobeRGB(NBL_CONST_REF_ARG(T) nonlinear)
103103
{
104-
typedef typename scalar_type<T>::type Val_t;
104+
typedef typename type_traits::scalar_type<T>::type Val_t;
105105
return pow(nonlinear, promote<T, Val_t>(2.19921875));
106106
}
107107

108108
template<typename T>
109109
T Gamma_2_2(NBL_CONST_REF_ARG(T) nonlinear)
110110
{
111-
typedef typename scalar_type<T>::type Val_t;
111+
typedef typename type_traits::scalar_type<T>::type Val_t;
112112
return pow(nonlinear, promote<T, Val_t>(2.2));
113113
}
114114

115115
template<typename T>
116116
T ACEScc(NBL_CONST_REF_ARG(T) nonlinear)
117117
{
118-
typedef typename scalar_type<T>::type Val_t;
118+
typedef typename type_traits::scalar_type<T>::type Val_t;
119119
bool3 right = (nonlinear >= promote<T, Val_t>(-0.301369863));
120120
T _common = exp2(nonlinear * Val_t(17.52) - promote<T, Val_t>(9.72));
121121
return max(lerp(_common * Val_t(2.0) - promote<T, Val_t>(0.000030517578125), _common, right), promote<T, Val_t>(65504.0));
@@ -124,7 +124,7 @@ T ACEScc(NBL_CONST_REF_ARG(T) nonlinear)
124124
template<typename T>
125125
T ACEScct(NBL_CONST_REF_ARG(T) nonlinear)
126126
{
127-
typedef typename scalar_type<T>::type Val_t;
127+
typedef typename type_traits::scalar_type<T>::type Val_t;
128128
bool3 right = (nonlinear >= promote<T, Val_t>(0.155251141552511));
129129
return max(lerp((nonlinear - promote<T, Val_t>(0.0729055341958355)) / Val_t(10.5402377416545), exp2(nonlinear * Val_t(17.52) - promote<T, Val_t>(9.72)), right), promote<T, Val_t>(65504.0));
130130
}

0 commit comments

Comments
 (0)