diff options
author | George Kyriazis <[email protected]> | 2018-04-06 15:03:09 -0500 |
---|---|---|
committer | George Kyriazis <[email protected]> | 2018-04-18 10:51:38 -0500 |
commit | a81c625cb7c63ebcc79ebd8bb52ea35eb5665d43 (patch) | |
tree | 62b8337ba3e21c231536ec7e43f8db0a7cd5d99d /src | |
parent | 2966ee10288d2af6f0f30f746c3da2a21ec8f865 (diff) |
swr/rast: Type-check TemplateArgUnroller
Allows direct use of enum values in conversion to template args.
Reviewed-by: Bruce Cherniak <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/swr/rasterizer/core/utils.h | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/core/utils.h b/src/gallium/drivers/swr/rasterizer/core/utils.h index c926f6ad7f2..d6cbf2436d3 100644 --- a/src/gallium/drivers/swr/rasterizer/core/utils.h +++ b/src/gallium/drivers/swr/rasterizer/core/utils.h @@ -268,12 +268,15 @@ public: }; // Ranged integer argument for TemplateArgUnroller -template <uint32_t TMin, uint32_t TMax> -struct IntArg +template <typename T, T TMin, T TMax> +struct RangedArg { - uint32_t val; + T val; }; +template <uint32_t TMin, uint32_t TMax> +using IntArg = RangedArg<uint32_t, TMin, TMax>; + // Recursive template used to auto-nest conditionals. Converts dynamic boolean function // arguments to static template arguments. template <typename TermT, typename... ArgsB> @@ -307,49 +310,49 @@ struct TemplateArgUnroller } //----------------------------------------- - // Integer value (within specified range) + // Ranged value (within specified range) //----------------------------------------- // Last Arg Terminator - template <uint32_t TMin, uint32_t TMax> - static typename TermT::FuncType GetFunc(IntArg<TMin, TMax> iArg) + template <typename T, T TMin, T TMax> + static typename TermT::FuncType GetFunc(RangedArg<T, TMin, TMax> iArg) { if (iArg.val == TMax) { - return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, TMax>>(); + return TermT::template GetFunc<ArgsB..., std::integral_constant<T, TMax>>(); } if (TMax > TMin) { - return TemplateArgUnroller<TermT, ArgsB...>::GetFunc(IntArg<TMin, TMax-1>{iArg.val}); + return TemplateArgUnroller<TermT, ArgsB...>::GetFunc(RangedArg<T, TMin, (T)(int(TMax)-1)>{iArg.val}); } SWR_ASSUME(false); return nullptr; } - template <uint32_t TVal> - static typename TermT::FuncType GetFunc(IntArg<TVal, TVal> iArg) + template <typename T, T TVal> + static typename TermT::FuncType GetFunc(RangedArg<T, TVal, TVal> iArg) { SWR_ASSERT(iArg.val == TVal); - return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, TVal>>(); + return TermT::template GetFunc<ArgsB..., std::integral_constant<T, TVal>>(); } // Recursively parse args - template <uint32_t TMin, uint32_t TMax, typename... TArgsT> - static typename TermT::FuncType GetFunc(IntArg<TMin, TMax> iArg, TArgsT... remainingArgs) + template <typename T, T TMin, T TMax, typename... TArgsT> + static typename TermT::FuncType GetFunc(RangedArg<T, TMin, TMax> iArg, TArgsT... remainingArgs) { if (iArg.val == TMax) { - return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, TMax>>::GetFunc(remainingArgs...); + return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<T, TMax>>::GetFunc(remainingArgs...); } if (TMax > TMin) { - return TemplateArgUnroller<TermT, ArgsB...>::GetFunc(IntArg<TMin, TMax - 1>{iArg.val}, remainingArgs...); + return TemplateArgUnroller<TermT, ArgsB...>::GetFunc(RangedArg<T, TMin, (T)(int(TMax) - 1)>{iArg.val}, remainingArgs...); } SWR_ASSUME(false); return nullptr; } - template <uint32_t TVal, typename... TArgsT> - static typename TermT::FuncType GetFunc(IntArg<TVal, TVal> iArg, TArgsT... remainingArgs) + template <typename T, T TVal, typename... TArgsT> + static typename TermT::FuncType GetFunc(RangedArg<T, TVal, TVal> iArg, TArgsT... remainingArgs) { SWR_ASSERT(iArg.val == TVal); - return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, TVal>>::GetFunc(remainingArgs...); + return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<T, TVal>>::GetFunc(remainingArgs...); } }; |