Skip to content

Commit cb52f01

Browse files
committed
Partial implementation of scan methods and subgroup primitives
1 parent af5f2d0 commit cb52f01

File tree

4 files changed

+570
-2
lines changed

4 files changed

+570
-2
lines changed

include/nbl/builtin/hlsl/binops.hlsl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ struct bitwise_xor
3737
}
3838
};
3939

40+
template<typename T>
41+
struct bitwise_add
42+
{
43+
T operator()(const T lhs, const T rhs)
44+
{
45+
return lhs+rhs;
46+
}
47+
};
48+
4049
template<typename T>
4150
struct bitwise_mul
4251
{
@@ -61,7 +70,7 @@ struct bitwise_min
6170
T operator()(const T lhs, const T rhs)
6271
{
6372
comparator_lt_t comp;
64-
return min(lhs, rhs, comp);
73+
return bitwise_min(lhs, rhs, comp);
6574
}
6675
};
6776

@@ -80,7 +89,7 @@ struct bitwise_max
8089
T operator()(const T lhs, const T rhs)
8190
{
8291
comparator_gt_t comp;
83-
return max(lhs, rhs, comp);
92+
return bitwise_max(lhs, rhs, comp);
8493
}
8594
};
8695

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#ifndef _NBL_BUILTIN_HLSL_SUBGROUP_ARITHMETIC_PORTABILITY_INCLUDED_
2+
#define _NBL_BUILTIN_HLSL_SUBGROUP_ARITHMETIC_PORTABILITY_INCLUDED_
3+
4+
#ifndef NBL_GL_KHR_shader_subgroup_arithmetic
5+
#include <nbl/builtin/hlsl/subgroup/basic_portability.hlsl>
6+
#endif
7+
8+
static uint4 WHOLE_WAVE = ~0;
9+
10+
namespace nbl
11+
{
12+
namespace hlsl
13+
{
14+
namespace subgroup
15+
{
16+
17+
#ifdef NBL_GL_KHR_shader_subgroup_arithmetic
18+
namespace native
19+
{
20+
21+
template<class Binop>
22+
struct reduction;
23+
template<class Binop>
24+
struct exclusive_scan;
25+
template<class Binop>
26+
struct inclusive_scan;
27+
28+
}
29+
#endif
30+
31+
template<class Binop>
32+
struct reduction
33+
{
34+
template<class ScratchAccessor, typename T>
35+
T operator()(const T x)
36+
{
37+
#ifdef NBL_GL_KHR_shader_subgroup_arithmetic
38+
return native::reduction<Binop>()(x);
39+
#else
40+
portability::reduction<Binop,ScratchAccessor> impl;
41+
return impl(x);
42+
#endif
43+
}
44+
};
45+
46+
template<class Binop>
47+
struct exclusive_scan
48+
{
49+
template<class ScratchAccessor, typename T>
50+
T operator()(const T x)
51+
{
52+
#ifdef NBL_GL_KHR_shader_subgroup_arithmetic
53+
return native::exclusive_scan<Binop>()(x);
54+
#else
55+
portability::exclusive_scan<Binop,ScratchAccessor> impl;
56+
return impl(x);
57+
#endif
58+
}
59+
};
60+
61+
template<class Binop>
62+
struct inclusive_scan
63+
{
64+
template<class ScratchAccessor, typename T>
65+
T operator()(const T x)
66+
{
67+
#ifdef NBL_GL_KHR_shader_subgroup_arithmetic
68+
return native::inclusive_scan<Binop>()(x);
69+
#else
70+
portability::inclusive_scan<Binop,ScratchAccessor> impl;
71+
return impl(x);
72+
#endif
73+
}
74+
};
75+
76+
namespace portability
77+
{
78+
79+
// PORTABILITY BINOP DECLARATIONS
80+
template<class Binop, class ScratchAccessor>
81+
struct reduction;
82+
template<class Binop, class ScratchAccessor>
83+
struct inclusive_scan;
84+
template<class Binop, class ScratchAccessor>
85+
struct exclusive_scan;
86+
87+
}
88+
89+
}
90+
}
91+
}
92+
93+
#include <nbl/builtin/hlsl/subgroup/arithmetic_portability_impl.hlsl>
94+
95+
#endif

0 commit comments

Comments
 (0)