Skip to content

Commit 9401bf3

Browse files
committed
use mix instead of ternary op
1 parent 237ac09 commit 9401bf3

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

include/nbl/builtin/hlsl/subgroup2/arithmetic_portability_impl.hlsl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include "nbl/builtin/hlsl/subgroup2/ballot.hlsl"
1212

1313
#include "nbl/builtin/hlsl/functional.hlsl"
14-
15-
// #include "nbl/builtin/hlsl/subgroup/arithmetic_portability_impl.hlsl"
14+
#include "nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl"
1615

1716
namespace nbl
1817
{
@@ -73,7 +72,7 @@ struct exclusive_scan
7372
type_t left = glsl::subgroupShuffleUp<type_t>(value,1);
7473

7574
type_t retval;
76-
retval[0] = bool(glsl::gl_SubgroupInvocationID()) ? left[ItemsPerInvocation-1] : binop_t::identity;
75+
retval[0] = hlsl::mix(binop_t::identity, left[ItemsPerInvocation-1], bool(glsl::gl_SubgroupInvocationID()));
7776
[unroll]
7877
for (uint32_t i = 1; i < ItemsPerInvocation; i++)
7978
retval[i] = value[i-1];
@@ -154,17 +153,15 @@ struct inclusive_scan<Params, BinOp, 1, false>
154153
const uint32_t subgroupInvocation = glsl::gl_SubgroupInvocationID();
155154

156155
type_t rhs = glsl::subgroupShuffleUp<type_t>(value, 1u); // all invocations must execute the shuffle, even if we don't apply the op() to all of them
157-
// TODO waiting on mix intrinsic fix from bxdf branch, value = op(value, hlsl::mix(rhs, binop_t::identity, subgroupInvocation < 1u));
158-
value = op(value, subgroupInvocation<1u ? binop_t::identity : rhs);
156+
value = op(value, hlsl::mix(rhs, binop_t::identity, subgroupInvocation < 1u));
159157

160158
const uint32_t SubgroupSizeLog2 = config_t::SizeLog2;
161159
[unroll]
162160
for (uint32_t i = 1; i < integral_constant<uint32_t,SubgroupSizeLog2>::value; i++)
163161
{
164162
const uint32_t step = i * 2;
165163
rhs = glsl::subgroupShuffleUp<type_t>(value, step);
166-
// TODO value = op(value, hlsl::mix(rhs, binop_t::identity, subgroupInvocation < step));
167-
value = op(value, subgroupInvocation<step ? binop_t::identity : rhs);
164+
value = op(value, hlsl::mix(rhs, binop_t::identity, subgroupInvocation < step));
168165
}
169166
return value;
170167
}
@@ -183,7 +180,7 @@ struct exclusive_scan<Params, BinOp, 1, false>
183180
// can't risk getting short-circuited, need to store to a var
184181
type_t left = glsl::subgroupShuffleUp<type_t>(value,1);
185182
// the first invocation doesn't have anything in its left so we set to the binop's identity value for exlusive scan
186-
return bool(glsl::gl_SubgroupInvocationID()) ? left:binop_t::identity;
183+
return hlsl::mix(binop_t::identity, left, bool(glsl::gl_SubgroupInvocationID()));
187184
}
188185
};
189186

0 commit comments

Comments
 (0)