Skip to content

Commit 90eac3d

Browse files
committed
Change min/max to use comparators
1 parent 01a8151 commit 90eac3d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

include/nbl/builtin/hlsl/binops.hlsl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,31 @@ struct mul
4646
}
4747
};
4848

49+
template<typename T, class Comparator>
50+
struct min
51+
{
52+
T operator()(const T lhs, const T rhs, in Comparator comp)
53+
{
54+
return comp(lhs, rhs) ? lhs : rhs;
55+
}
56+
};
57+
4958
template<typename T>
5059
struct min
5160
{
5261
T operator()(const T lhs, const T rhs)
5362
{
54-
return lhs>rhs ? rhs : lhs;
63+
comparator_lt_t comp;
64+
return min(lhs, rhs, comp);
65+
}
66+
};
67+
68+
template<typename T, class Comparator>
69+
struct max
70+
{
71+
T operator()(const T lhs, const T rhs, in Comparator comp)
72+
{
73+
return comp(lhs, rhs) ? lhs : rhs;
5574
}
5675
};
5776

@@ -60,7 +79,8 @@ struct max
6079
{
6180
T operator()(const T lhs, const T rhs)
6281
{
63-
return lhs>rhs ? lhs : rhs;
82+
comparator_gt_t comp;
83+
return max(lhs, rhs, comp);
6484
}
6585
};
6686

0 commit comments

Comments
 (0)