From: Tim Rowley Date: Wed, 13 Jul 2016 21:06:13 +0000 (-0600) Subject: swr: [rasterizer core] support range of values in TemplateArgUnroller X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e0529a4668c7f50fb51b2c4ae8bc5954934db55f;p=mesa.git swr: [rasterizer core] support range of values in TemplateArgUnroller Fixes Linux warnings. Signed-off-by: Tim Rowley --- diff --git a/src/gallium/drivers/swr/rasterizer/core/frontend.cpp b/src/gallium/drivers/swr/rasterizer/core/frontend.cpp index 8537c59033c..cb13b50df14 100644 --- a/src/gallium/drivers/swr/rasterizer/core/frontend.cpp +++ b/src/gallium/drivers/swr/rasterizer/core/frontend.cpp @@ -1481,7 +1481,6 @@ INLINE void ProcessAttributes( } __m128 attrib[3]; // triangle attribs (always 4 wide) - static const uint32_t numVerts = NumVertsT::value < 3 ? NumVertsT::value : 3; float* pAttribStart = pBuffer; if (HasConstantInterpT::value) @@ -1519,7 +1518,7 @@ INLINE void ProcessAttributes( pa.AssembleSingle(inputSlot, adjustedTriIndex, attrib); - for (uint32_t i = 0; i < numVerts; ++i) + for (uint32_t i = 0; i < NumVertsT::value; ++i) { _mm_store_ps(pBuffer, attrib[vid]); pBuffer += 4; @@ -1529,7 +1528,7 @@ INLINE void ProcessAttributes( { pa.AssembleSingle(inputSlot, triIndex, attrib); - for (uint32_t i = 0; i < numVerts; ++i) + for (uint32_t i = 0; i < NumVertsT::value; ++i) { _mm_store_ps(pBuffer, attrib[i]); pBuffer += 4; @@ -1540,7 +1539,7 @@ INLINE void ProcessAttributes( { pa.AssembleSingle(inputSlot, triIndex, attrib); - for (uint32_t i = 0; i < numVerts; ++i) + for (uint32_t i = 0; i < NumVertsT::value; ++i) { _mm_store_ps(pBuffer, attrib[i]); pBuffer += 4; @@ -1551,9 +1550,9 @@ INLINE void ProcessAttributes( // interpolation code in the pixel shader works correctly for the // 3 topologies - point, line, tri. This effectively zeros out the // effect of the missing vertices in the triangle interpolation. - for (uint32_t v = numVerts; v < 3; ++v) + for (uint32_t v = NumVertsT::value; v < 3; ++v) { - _mm_store_ps(pBuffer, attrib[numVerts - 1]); + _mm_store_ps(pBuffer, attrib[NumVertsT::value - 1]); pBuffer += 4; } @@ -1608,7 +1607,7 @@ struct ProcessAttributesChooser PFN_PROCESS_ATTRIBUTES GetProcessAttributesFunc(uint32_t NumVerts, bool IsSwizzled, bool HasConstantInterp) { - return TemplateArgUnroller::GetFunc(NumVerts, IsSwizzled, HasConstantInterp); + return TemplateArgUnroller::GetFunc(IntArg<1, 3>{NumVerts}, IsSwizzled, HasConstantInterp); } ////////////////////////////////////////////////////////////////////////// diff --git a/src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp b/src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp index 1e7da2bf81e..408d1d5bb93 100644 --- a/src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp +++ b/src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp @@ -1544,5 +1544,9 @@ PFN_WORK_FUNC GetRasterizerFunc( bool RasterizeScissorEdges ) { - return TemplateArgUnroller::GetFunc(numSamples, IsConservative, InputCoverage, RasterizeScissorEdges); + return TemplateArgUnroller::GetFunc( + IntArg<0,4>{numSamples}, + IsConservative, + IntArg{InputCoverage}, + RasterizeScissorEdges); } diff --git a/src/gallium/drivers/swr/rasterizer/core/utils.h b/src/gallium/drivers/swr/rasterizer/core/utils.h index 51d6c46ea08..0cfdb84c73b 100644 --- a/src/gallium/drivers/swr/rasterizer/core/utils.h +++ b/src/gallium/drivers/swr/rasterizer/core/utils.h @@ -989,11 +989,22 @@ public: } }; +// Ranged integer argument for TemplateArgUnroller +template +struct IntArg +{ + uint32_t val; +}; + // Recursive template used to auto-nest conditionals. Converts dynamic boolean function // arguments to static template arguments. template struct TemplateArgUnroller { + //----------------------------------------- + // Boolean value + //----------------------------------------- + // Last Arg Terminator static typename TermT::FuncType GetFunc(bool bArg) { @@ -1017,34 +1028,50 @@ struct TemplateArgUnroller return TemplateArgUnroller::GetFunc(remainingArgs...); } + //----------------------------------------- + // Integer value (within specified range) + //----------------------------------------- + // Last Arg Terminator - template - static typename TermT::FuncType GetFunc(uint32_t iArg) + template + static typename TermT::FuncType GetFunc(IntArg iArg) { - switch(iArg) + if (iArg.val == TMax) + { + return TermT::template GetFunc>(); + } + if (TMax > TMin) { - case 0: return TermT::template GetFunc>(); - case 1: return TermT::template GetFunc>(); - case 2: return TermT::template GetFunc>(); - case 3: return TermT::template GetFunc>(); - case 4: return TermT::template GetFunc>(); - default: SWR_ASSUME(false); return nullptr; + return TemplateArgUnroller::GetFunc(IntArg{iArg.val}); } + SWR_ASSUME(false); return nullptr; + } + template + static typename TermT::FuncType GetFunc(IntArg iArg) + { + SWR_ASSERT(iArg.val == TVal); + return TermT::template GetFunc>(); } // Recursively parse args - template - static typename TermT::FuncType GetFunc(uint32_t iArg, TArgsT... remainingArgs) + template + static typename TermT::FuncType GetFunc(IntArg iArg, TArgsT... remainingArgs) { - switch(iArg) + if (iArg.val == TMax) { - case 0: return TemplateArgUnroller>::GetFunc(remainingArgs...); - case 1: return TemplateArgUnroller>::GetFunc(remainingArgs...); - case 2: return TemplateArgUnroller>::GetFunc(remainingArgs...); - case 3: return TemplateArgUnroller>::GetFunc(remainingArgs...); - case 4: return TemplateArgUnroller>::GetFunc(remainingArgs...); - default: SWR_ASSUME(false); return nullptr; + return TemplateArgUnroller>::GetFunc(remainingArgs...); } + if (TMax > TMin) + { + return TemplateArgUnroller::GetFunc(IntArg{iArg.val}, remainingArgs...); + } + SWR_ASSUME(false); return nullptr; + } + template + static typename TermT::FuncType GetFunc(IntArg iArg, TArgsT... remainingArgs) + { + SWR_ASSERT(iArg.val == TVal); + return TemplateArgUnroller>::GetFunc(remainingArgs...); } };