-
Notifications
You must be signed in to change notification settings - Fork 67
Fixed emulated vector template resolution ambiguity #972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
devshgraphicsprogramming
merged 1 commit into
master
from
fix_emulated_vector_templates
Dec 24, 2025
+85
−113
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,14 +134,6 @@ NBL_CONSTEXPR_FUNC this_t operator OP() NBL_CONST_MEMBER_FUNC \ | |
| } | ||
|
|
||
| #define NBL_EMULATED_VECTOR_ARITHMETIC_OPERATOR(OP)\ | ||
| NBL_CONSTEXPR_FUNC this_t operator OP (component_t val) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
| [[unroll]]\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, this_t::getComponent(i) OP val);\ | ||
| return output;\ | ||
| }\ | ||
| NBL_CONSTEXPR_FUNC this_t operator OP (this_t other) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
|
|
@@ -183,6 +175,14 @@ NBL_CONSTEXPR_FUNC vector<bool, CRTP::Dimension> operator OP (vector<component_t | |
| #define NBL_EMULATED_VECTOR_CREATION_AND_COMPONENT_SUM \ | ||
| using this_t = emulated_vector<ComponentType, CRTP>;\ | ||
| using component_t = ComponentType;\ | ||
| template<typename T>\ | ||
| NBL_CONSTEXPR_STATIC this_t create(vector<T, CRTP::Dimension> other)\ | ||
|
Comment on lines
+178
to
+179
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs |
||
| {\ | ||
| this_t output;\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, component_t::create(other[i]));\ | ||
| return output;\ | ||
| }\ | ||
| NBL_CONSTEXPR_STATIC this_t create(this_t other)\ | ||
| {\ | ||
| CRTP output;\ | ||
|
|
@@ -209,6 +209,43 @@ NBL_CONSTEXPR_STATIC this_t create(vector<component_t, CRTP::Dimension> other)\ | |
| return output;\ | ||
| } | ||
|
|
||
| #define DEFINE_OPERATORS_FOR_TYPE(...)\ | ||
| NBL_CONSTEXPR_FUNC this_t operator+(__VA_ARGS__ val) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, CRTP::getComponent(i) + _static_cast<component_t>(val));\ | ||
| \ | ||
| return output;\ | ||
| }\ | ||
| \ | ||
| NBL_CONSTEXPR_FUNC this_t operator-(__VA_ARGS__ val) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, CRTP::getComponent(i) - _static_cast<component_t>(val));\ | ||
| \ | ||
| return output;\ | ||
| }\ | ||
| \ | ||
| NBL_CONSTEXPR_FUNC this_t operator*(__VA_ARGS__ val) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, CRTP::getComponent(i) * _static_cast<component_t>(val));\ | ||
| \ | ||
| return output;\ | ||
| }\ | ||
| \ | ||
| NBL_CONSTEXPR_FUNC this_t operator/(__VA_ARGS__ val) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, CRTP::getComponent(i) / _static_cast<component_t>(val));\ | ||
| \ | ||
| return output;\ | ||
| }\ | ||
|
|
||
| // Fundamental, integral | ||
| template <typename ComponentType, typename CRTP> NBL_PARTIAL_REQ_TOP(is_fundamental_v<ComponentType> && concepts::IntegralLikeScalar<ComponentType>) | ||
| struct emulated_vector<ComponentType, CRTP NBL_PARTIAL_REQ_BOT(is_fundamental_v<ComponentType>&& concepts::IntegralLikeScalar<ComponentType>) > : CRTP | ||
|
|
@@ -232,6 +269,15 @@ struct emulated_vector<ComponentType, CRTP NBL_PARTIAL_REQ_BOT(is_fundamental_v< | |
| NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_COMPARISON_OPERATOR(<=) | ||
| NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_COMPARISON_OPERATOR(>) | ||
| NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_COMPARISON_OPERATOR(>=) | ||
|
|
||
| DEFINE_OPERATORS_FOR_TYPE(emulated_uint64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(emulated_int64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int64_t) | ||
| }; | ||
|
|
||
| // Fundamental, not integral | ||
|
|
@@ -253,6 +299,15 @@ struct emulated_vector<ComponentType, CRTP NBL_PARTIAL_REQ_BOT(is_fundamental_v< | |
| NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_COMPARISON_OPERATOR(<=) | ||
| NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_COMPARISON_OPERATOR(>) | ||
| NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_COMPARISON_OPERATOR(>=) | ||
|
|
||
| DEFINE_OPERATORS_FOR_TYPE(emulated_uint64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(emulated_int64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int64_t) | ||
| }; | ||
|
|
||
| // Not fundamental, integral | ||
|
|
@@ -278,6 +333,20 @@ struct emulated_vector<ComponentType, CRTP NBL_PARTIAL_REQ_BOT(!is_fundamental_v | |
| NBL_EMULATED_VECTOR_COMPARISON_OPERATOR(<=) | ||
| NBL_EMULATED_VECTOR_COMPARISON_OPERATOR(>) | ||
| NBL_EMULATED_VECTOR_COMPARISON_OPERATOR(>=) | ||
|
|
||
| DEFINE_OPERATORS_FOR_TYPE(emulated_float64_t<true, true>) | ||
| DEFINE_OPERATORS_FOR_TYPE(emulated_float64_t<true, false>) | ||
| DEFINE_OPERATORS_FOR_TYPE(emulated_float64_t<false, true>) | ||
| DEFINE_OPERATORS_FOR_TYPE(emulated_float64_t<false, false>) | ||
| DEFINE_OPERATORS_FOR_TYPE(float16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(float32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(float64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int64_t) | ||
| }; | ||
|
|
||
| // Not fundamental, not integral | ||
|
|
@@ -299,107 +368,12 @@ struct emulated_vector<ComponentType, CRTP NBL_PARTIAL_REQ_BOT(!is_fundamental_v | |
| NBL_EMULATED_VECTOR_COMPARISON_OPERATOR(<=) | ||
| NBL_EMULATED_VECTOR_COMPARISON_OPERATOR(>) | ||
| NBL_EMULATED_VECTOR_COMPARISON_OPERATOR(>=) | ||
| }; | ||
devshgraphicsprogramming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #undef NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_CREATION_AND_COMPONENT_SUM | ||
| #undef NBL_EMULATED_VECTOR_CREATION_AND_COMPONENT_SUM | ||
| #undef NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_COMPARISON_OPERATOR | ||
| #undef NBL_EMULATED_VECTOR_COMPARISON_OPERATOR | ||
| #undef NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_ARITHMETIC_OPERATOR | ||
| #undef NBL_EMULATED_VECTOR_ARITHMETIC_OPERATOR | ||
| #undef NBL_EMULATED_VECTOR_UNARY_OPERATOR | ||
|
|
||
| // ----------------------------------------------------- EMULATED FLOAT SPECIALIZATION -------------------------------------------------------------------- | ||
|
|
||
| #define DEFINE_OPERATORS_FOR_TYPE(...)\ | ||
| NBL_CONSTEXPR_FUNC this_t operator+(__VA_ARGS__ val) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, CRTP::getComponent(i) + component_t::create(val));\ | ||
| \ | ||
| return output;\ | ||
| }\ | ||
| \ | ||
| NBL_CONSTEXPR_FUNC this_t operator-(__VA_ARGS__ val) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, CRTP::getComponent(i) - component_t::create(val));\ | ||
| \ | ||
| return output;\ | ||
| }\ | ||
| \ | ||
| NBL_CONSTEXPR_FUNC this_t operator*(__VA_ARGS__ val) NBL_CONST_MEMBER_FUNC \ | ||
| {\ | ||
| this_t output;\ | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i)\ | ||
| output.setComponent(i, CRTP::getComponent(i) * component_t::create(val));\ | ||
| \ | ||
| return output;\ | ||
| }\ | ||
| \ | ||
|
|
||
|
|
||
| template <bool FastMath, bool FlushDenormToZero, typename CRTP> | ||
| struct emulated_vector<emulated_float64_t<FastMath, FlushDenormToZero>, CRTP> : CRTP | ||
| { | ||
| using component_t = emulated_float64_t<FastMath, FlushDenormToZero>; | ||
| using this_t = emulated_vector<component_t, CRTP>; | ||
|
|
||
| NBL_CONSTEXPR_STATIC this_t create(this_t other) | ||
| { | ||
| this_t output; | ||
|
|
||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i) | ||
| output.setComponent(i, other.getComponent(i)); | ||
|
|
||
| return output; | ||
| } | ||
|
|
||
| template<typename T> | ||
| NBL_CONSTEXPR_STATIC this_t create(vector<T, CRTP::Dimension> other) | ||
| { | ||
| this_t output; | ||
|
|
||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i) | ||
| output.setComponent(i, component_t::create(other[i])); | ||
|
|
||
| return output; | ||
| } | ||
|
|
||
| NBL_CONSTEXPR_FUNC this_t operator+(this_t other) NBL_CONST_MEMBER_FUNC | ||
| { | ||
| this_t output; | ||
|
|
||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i) | ||
| output.setComponent(i, CRTP::getComponent(i) + other.getComponent(i)); | ||
|
|
||
| return output; | ||
| } | ||
| NBL_CONSTEXPR_FUNC this_t operator-(this_t other) NBL_CONST_MEMBER_FUNC | ||
| { | ||
| this_t output; | ||
|
|
||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i) | ||
| output.setComponent(i, CRTP::getComponent(i) - other.getComponent(i)); | ||
|
|
||
| return output; | ||
| } | ||
| NBL_CONSTEXPR_FUNC this_t operator*(this_t other) NBL_CONST_MEMBER_FUNC | ||
| { | ||
| this_t output; | ||
|
|
||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i) | ||
| output.setComponent(i, CRTP::getComponent(i) * other.getComponent(i)); | ||
|
|
||
| return output; | ||
| } | ||
|
|
||
| DEFINE_OPERATORS_FOR_TYPE(emulated_float64_t<true, true>) | ||
| DEFINE_OPERATORS_FOR_TYPE(emulated_float64_t<true, false>) | ||
| DEFINE_OPERATORS_FOR_TYPE(emulated_float64_t<false, true>) | ||
| DEFINE_OPERATORS_FOR_TYPE(emulated_float64_t<false, false>) | ||
| DEFINE_OPERATORS_FOR_TYPE(float16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(float32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(float64_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(uint16_t) | ||
|
|
@@ -408,17 +382,15 @@ struct emulated_vector<emulated_float64_t<FastMath, FlushDenormToZero>, CRTP> : | |
| DEFINE_OPERATORS_FOR_TYPE(int16_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int32_t) | ||
| DEFINE_OPERATORS_FOR_TYPE(int64_t) | ||
|
|
||
| NBL_CONSTEXPR_FUNC component_t calcComponentSum() NBL_CONST_MEMBER_FUNC | ||
| { | ||
| component_t sum = component_t::create(0); | ||
| for (uint32_t i = 0u; i < CRTP::Dimension; ++i) | ||
| sum = sum + CRTP::getComponent(i); | ||
|
|
||
| return sum; | ||
| } | ||
| }; | ||
|
|
||
| #undef NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_CREATION_AND_COMPONENT_SUM | ||
| #undef NBL_EMULATED_VECTOR_CREATION_AND_COMPONENT_SUM | ||
| #undef NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_COMPARISON_OPERATOR | ||
| #undef NBL_EMULATED_VECTOR_COMPARISON_OPERATOR | ||
| #undef NBL_EMULATED_FUNDAMENTAL_TYPE_VECTOR_ARITHMETIC_OPERATOR | ||
| #undef NBL_EMULATED_VECTOR_ARITHMETIC_OPERATOR | ||
| #undef NBL_EMULATED_VECTOR_UNARY_OPERATOR | ||
| #undef DEFINE_OPERATORS_FOR_TYPE | ||
|
|
||
| template<typename T, uint32_t N> | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.