swr: [rasterizer core] support range of values in TemplateArgUnroller
authorTim Rowley <timothy.o.rowley@intel.com>
Wed, 13 Jul 2016 21:06:13 +0000 (15:06 -0600)
committerTim Rowley <timothy.o.rowley@intel.com>
Wed, 20 Jul 2016 15:22:15 +0000 (10:22 -0500)
Fixes Linux warnings.

Signed-off-by: Tim Rowley <timothy.o.rowley@intel.com>
src/gallium/drivers/swr/rasterizer/core/frontend.cpp
src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp
src/gallium/drivers/swr/rasterizer/core/utils.h

index 8537c59033c3bd08b39d15c4f4657cb561607cc7..cb13b50df14b4ee893a6a7a868b6c8628b8a1afa 100644 (file)
@@ -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<ProcessAttributesChooser>::GetFunc(NumVerts, IsSwizzled, HasConstantInterp);
+    return TemplateArgUnroller<ProcessAttributesChooser>::GetFunc(IntArg<1, 3>{NumVerts}, IsSwizzled, HasConstantInterp);
 }
 
 //////////////////////////////////////////////////////////////////////////
index 1e7da2bf81e67403d2b0895a116f8d898a30edc4..408d1d5bb9341c879beca42926b3669fb825babc 100644 (file)
@@ -1544,5 +1544,9 @@ PFN_WORK_FUNC GetRasterizerFunc(
     bool RasterizeScissorEdges
 )
 {
-    return TemplateArgUnroller<RasterizerChooser>::GetFunc(numSamples, IsConservative, InputCoverage, RasterizeScissorEdges);
+    return TemplateArgUnroller<RasterizerChooser>::GetFunc(
+        IntArg<0,4>{numSamples},
+        IsConservative,
+        IntArg<SWR_INPUT_COVERAGE_NONE, SWR_INPUT_COVERAGE_MAX>{InputCoverage},
+        RasterizeScissorEdges);
 }
index 51d6c46ea087ed32ff0c319249a8156451d8636d..0cfdb84c73b2bd1437d516607996803ad6774d76 100644 (file)
@@ -989,11 +989,22 @@ public:
     }
 };
 
+// Ranged integer argument for TemplateArgUnroller
+template <uint32_t TMin, uint32_t TMax>
+struct IntArg
+{
+    uint32_t val;
+};
+
 // Recursive template used to auto-nest conditionals.  Converts dynamic boolean function
 // arguments to static template arguments.
 template <typename TermT, typename... ArgsB>
 struct TemplateArgUnroller
 {
+    //-----------------------------------------
+    // Boolean value
+    //-----------------------------------------
+
     // Last Arg Terminator
     static typename TermT::FuncType GetFunc(bool bArg)
     {
@@ -1017,34 +1028,50 @@ struct TemplateArgUnroller
         return TemplateArgUnroller<TermT, ArgsB..., std::false_type>::GetFunc(remainingArgs...);
     }
 
+    //-----------------------------------------
+    // Integer value (within specified range)
+    //-----------------------------------------
+
     // Last Arg Terminator
-    template <typename... TArgsT>
-    static typename TermT::FuncType GetFunc(uint32_t iArg)
+    template <uint32_t TMin, uint32_t TMax>
+    static typename TermT::FuncType GetFunc(IntArg<TMin, TMax> iArg)
     {
-        switch(iArg)
+        if (iArg.val == TMax)
+        {
+            return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, TMax>>();
+        }
+        if (TMax > TMin)
         {
-        case 0: return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, 0>>();
-        case 1: return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, 1>>();
-        case 2: return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, 2>>();
-        case 3: return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, 3>>();
-        case 4: return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, 4>>();
-        default: SWR_ASSUME(false); return nullptr;
+            return TemplateArgUnroller<TermT, ArgsB...>::GetFunc(IntArg<TMin, TMax-1>{iArg.val});
         }
+        SWR_ASSUME(false); return nullptr;
+    }
+    template <uint32_t TVal>
+    static typename TermT::FuncType GetFunc(IntArg<TVal, TVal> iArg)
+    {
+        SWR_ASSERT(iArg.val == TVal);
+        return TermT::template GetFunc<ArgsB..., std::integral_constant<uint32_t, TVal>>();
     }
 
     // Recursively parse args
-    template <typename... TArgsT>
-    static typename TermT::FuncType GetFunc(uint32_t iArg, TArgsT... remainingArgs)
+    template <uint32_t TMin, uint32_t TMax, typename... TArgsT>
+    static typename TermT::FuncType GetFunc(IntArg<TMin, TMax> iArg, TArgsT... remainingArgs)
     {
-        switch(iArg)
+        if (iArg.val == TMax)
         {
-        case 0: return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, 0>>::GetFunc(remainingArgs...);
-        case 1: return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, 1>>::GetFunc(remainingArgs...);
-        case 2: return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, 2>>::GetFunc(remainingArgs...);
-        case 3: return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, 3>>::GetFunc(remainingArgs...);
-        case 4: return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, 4>>::GetFunc(remainingArgs...);
-        default: SWR_ASSUME(false); return nullptr;
+            return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, TMax>>::GetFunc(remainingArgs...);
         }
+        if (TMax > TMin)
+        {
+            return TemplateArgUnroller<TermT, ArgsB...>::GetFunc(IntArg<TMin, 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)
+    {
+        SWR_ASSERT(iArg.val == TVal);
+        return TemplateArgUnroller<TermT, ArgsB..., std::integral_constant<uint32_t, TVal>>::GetFunc(remainingArgs...);
     }
 };