Skip to content

Commit c365240

Browse files
author
kevyuu
committed
Fix promote.hlsl and reduce the amount of specialization for Promote
1 parent cdb6ad7 commit c365240

File tree

2 files changed

+12
-42
lines changed

2 files changed

+12
-42
lines changed

include/nbl/builtin/hlsl/cpp_compat/promote.hlsl

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,50 +21,21 @@ struct Promote
2121
}
2222
};
2323

24-
#ifdef __HLSL_VERSION
25-
26-
template<typename Scalar, typename U>
27-
struct Promote<vector <Scalar, 1>, U>
24+
// TODO(kevinyu): Should we enable truncation from uint64_t to emulated_vector<emulated_uint64_t, N>?
25+
template<typename To, typename From> NBL_PARTIAL_REQ_TOP(concepts::Vectorial<To> && is_scalar_v<From> && is_same_v<typename vector_traits<To>::scalar_type, From>)
26+
struct Promote<To, From NBL_PARTIAL_REQ_BOT(concepts::Vectorial<To> && is_scalar_v<From> && is_same_v<typename vector_traits<To>::scalar_type, From>) >
2827
{
29-
NBL_CONSTEXPR_FUNC enable_if_t<is_scalar<Scalar>::value && is_scalar<U>::value, vector <Scalar, 1> > operator()(const U v)
28+
NBL_CONSTEXPR_FUNC To operator()(const From v)
3029
{
31-
vector <Scalar, 1> promoted = {Scalar(v)};
32-
return promoted;
30+
array_set<To, From> setter;
31+
To output;
32+
[[unroll]]
33+
for (int i = 0; i < vector_traits<To>::Dimension; ++i)
34+
setter(output, i, v);
35+
return output;
3336
}
3437
};
3538

36-
template<typename Scalar, typename U>
37-
struct Promote<vector <Scalar, 2>, U>
38-
{
39-
NBL_CONSTEXPR_FUNC enable_if_t<is_scalar<Scalar>::value && is_scalar<U>::value, vector <Scalar, 2> > operator()(const U v)
40-
{
41-
vector <Scalar, 2> promoted = {Scalar(v), Scalar(v)};
42-
return promoted;
43-
}
44-
};
45-
46-
template<typename Scalar, typename U>
47-
struct Promote<vector <Scalar, 3>, U>
48-
{
49-
NBL_CONSTEXPR_FUNC enable_if_t<is_scalar<Scalar>::value && is_scalar<U>::value, vector <Scalar, 3> > operator()(const U v)
50-
{
51-
vector <Scalar, 3> promoted = {Scalar(v), Scalar(v), Scalar(v)};
52-
return promoted;
53-
}
54-
};
55-
56-
template<typename Scalar, typename U>
57-
struct Promote<vector <Scalar, 4>, U>
58-
{
59-
NBL_CONSTEXPR_FUNC enable_if_t<is_scalar<Scalar>::value && is_scalar<U>::value, vector <Scalar, 4> > operator()(const U v)
60-
{
61-
vector <Scalar, 4> promoted = {Scalar(v), Scalar(v), Scalar(v), Scalar(v)};
62-
return promoted;
63-
}
64-
};
65-
66-
#endif
67-
6839
}
6940

7041
template<typename T, typename U>

include/nbl/builtin/hlsl/morton.hlsl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ struct Transcoder
137137
return leftShift(interleaved, truncate<vector<uint16_t, Dim> >(vector<uint16_t, 4>(0, 1, 2, 3)));
138138
}
139139

140-
template<typename decode_t = conditional_t<(Bits > 16), vector<uint32_t, Dim>, vector<uint16_t, Dim> >
141-
NBL_FUNC_REQUIRES(concepts::IntVector<decode_t> && 8 * sizeof(typename vector_traits<decode_t>::scalar_type) >= Bits)
140+
template<typename decode_t = conditional_t<(Bits > 16), vector<uint32_t, Dim>, vector<uint16_t, Dim> > >
142141
/**
143142
* @brief Encodes a vector of cartesian coordinates as a Morton code
144143
*
@@ -216,7 +215,7 @@ struct Equal<Signed, Bits, D, storage_t, true>
216215
NBL_CONSTEXPR_STATIC vector<bool, D> __call(NBL_CONST_REF_ARG(storage_t) value, NBL_CONST_REF_ARG(portable_vector_t<I, D>) rhs)
217216
{
218217
const portable_vector_t<storage_t, D> InterleaveMasks = NBL_MORTON_INTERLEAVE_MASKS(storage_t, D, Bits, );
219-
const portable_vector_t<storage_t, D> zeros = _static_cast<portable_vector_t<storage_t, D> >(truncate<vector<uint64_t, D> >(vector<uint64_t, 4>(0,0,0,0)));
218+
const portable_vector_t<storage_t, D> zeros = promote<portable_vector_t<storage_t, D>>(_static_cast<storage_t>(0));
220219

221220
const portable_vector_t<storage_t, D> rhsCasted = _static_cast<portable_vector_t<storage_t, D> >(rhs);
222221
const portable_vector_t<storage_t, D> xored = rhsCasted ^ (InterleaveMasks & value);

0 commit comments

Comments
 (0)