swr: [rasterizer core] Reduce templates to speed compile
authorTim Rowley <timothy.o.rowley@intel.com>
Fri, 31 Mar 2017 21:50:40 +0000 (16:50 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Tue, 11 Apr 2017 23:01:03 +0000 (18:01 -0500)
Quick patch to remove some unused template params to cut down
rasterizer compile time.

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/core/binner.cpp
src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp
src/gallium/drivers/swr/rasterizer/core/rasterizer.h

index 9ec5bea76ee21570b3f34092bc1f7ee586c01254..eb1f20b5a3572eca880a8a2e441eafc0f207e20b 100644 (file)
@@ -795,7 +795,7 @@ void BinTriangles(
     {
         // degenerate triangles won't be sent to rasterizer; just enable all edges
         pfnWork = GetRasterizerFunc(rastState.sampleCount, rastState.bIsCenterPattern, (rastState.conservativeRast > 0), 
-            (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, ALL_EDGES_VALID, (state.scissorsTileAligned == false));
+            (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, EdgeValToEdgeState(ALL_EDGES_VALID), (state.scissorsTileAligned == false));
     }
 
     if (!triMask)
@@ -941,7 +941,7 @@ endBinTriangles:
             // only rasterize valid edges if we have a degenerate primitive
             int32_t triEdgeEnable = (edgeEnable >> (triIndex * 3)) & ALL_EDGES_VALID;
             work.pfnWork = GetRasterizerFunc(rastState.sampleCount, rastState.bIsCenterPattern, (rastState.conservativeRast > 0), 
-                (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, triEdgeEnable, (state.scissorsTileAligned == false));
+                (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, EdgeValToEdgeState(triEdgeEnable), (state.scissorsTileAligned == false));
 
             // Degenerate triangles are required to be constant interpolated
             isDegenerate = (triEdgeEnable != ALL_EDGES_VALID) ? true : false;
@@ -1236,7 +1236,7 @@ void BinTriangles_simd16(
     {
         // degenerate triangles won't be sent to rasterizer; just enable all edges
         pfnWork = GetRasterizerFunc(rastState.sampleCount, rastState.bIsCenterPattern, (rastState.conservativeRast > 0),
-            (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, ALL_EDGES_VALID, (state.scissorsTileAligned == false));
+            (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, EdgeValToEdgeState(ALL_EDGES_VALID), (state.scissorsTileAligned == false));
     }
 
     if (!triMask)
@@ -1396,7 +1396,7 @@ endBinTriangles:
             // only rasterize valid edges if we have a degenerate primitive
             int32_t triEdgeEnable = (edgeEnable >> (triIndex * 3)) & ALL_EDGES_VALID;
             work.pfnWork = GetRasterizerFunc(rastState.sampleCount, rastState.bIsCenterPattern, (rastState.conservativeRast > 0),
-                (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, triEdgeEnable, (state.scissorsTileAligned == false));
+                (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, EdgeValToEdgeState(triEdgeEnable), (state.scissorsTileAligned == false));
 
             // Degenerate triangles are required to be constant interpolated
             isDegenerate = (triEdgeEnable != ALL_EDGES_VALID) ? true : false;
index 0837841746efdb038977a4f83def89f108845ced..af54779653eff947f0a8115a0011b5145d6f3222 100644 (file)
@@ -1343,7 +1343,7 @@ void RasterizeTriPoint(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile,
     PFN_WORK_FUNC pfnTriRast;
     // conservative rast not supported for points/lines
     pfnTriRast = GetRasterizerFunc(rastState.sampleCount, rastState.bIsCenterPattern, false, 
-                                   SWR_INPUT_COVERAGE_NONE, ALL_EDGES_VALID, (pDC->pState->state.scissorsTileAligned == false));
+                                   SWR_INPUT_COVERAGE_NONE, EdgeValToEdgeState(ALL_EDGES_VALID), (pDC->pState->state.scissorsTileAligned == false));
 
     // overwrite texcoords for point sprites
     if (isPointSpriteTexCoordEnabled)
@@ -1676,7 +1676,7 @@ void RasterizeLine(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile, voi
     PFN_WORK_FUNC pfnTriRast;
     // conservative rast not supported for points/lines
     pfnTriRast = GetRasterizerFunc(rastState.sampleCount, rastState.bIsCenterPattern, false, 
-                                   SWR_INPUT_COVERAGE_NONE, ALL_EDGES_VALID, (pDC->pState->state.scissorsTileAligned == false));
+                                   SWR_INPUT_COVERAGE_NONE, EdgeValToEdgeState(ALL_EDGES_VALID), (pDC->pState->state.scissorsTileAligned == false));
 
     // make sure this macrotile intersects the triangle
     __m128i vXai = fpToFixedPoint(vXa);
@@ -1798,6 +1798,6 @@ PFN_WORK_FUNC GetRasterizerFunc(
         IsCenter,
         IsConservative,
         IntArg<SWR_INPUT_COVERAGE_NONE, SWR_INPUT_COVERAGE_COUNT-1>{InputCoverage},
-        IntArg<0, VALID_TRI_EDGE_COUNT-1>{EdgeEnable},
+        IntArg<0, STATE_VALID_TRI_EDGE_COUNT-1>{EdgeEnable},
         RasterizeScissorEdges);
 }
index f4aa6eb9f906014fafdc719b4221a89212e2ac55..e99920aef2e0182bf1264fe28619c8598e5e01c0 100644 (file)
@@ -52,7 +52,17 @@ PFN_WORK_FUNC GetRasterizerFunc(
     uint32_t EdgeEnable,
     bool RasterizeScissorEdges);
 
-enum ValidTriEdges
+enum TriEdgesStates
+{
+    STATE_NO_VALID_EDGES = 0,
+    STATE_E0_E1_VALID,
+    STATE_E0_E2_VALID,
+    STATE_E1_E2_VALID,
+    STATE_ALL_EDGES_VALID,
+    STATE_VALID_TRI_EDGE_COUNT,
+};
+
+enum TriEdgesValues
 {
     NO_VALID_EDGES = 0,
     E0_E1_VALID = 0x3,
@@ -71,6 +81,56 @@ typedef std::integral_constant<uint32_t, E0_E2_VALID> E0E2ValidT;
 typedef std::integral_constant<uint32_t, E1_E2_VALID> E1E2ValidT;
 typedef std::integral_constant<uint32_t, NO_VALID_EDGES> NoEdgesValidT;
 
+typedef std::integral_constant<uint32_t, STATE_ALL_EDGES_VALID> StateAllEdgesValidT;
+typedef std::integral_constant<uint32_t, STATE_E0_E1_VALID> StateE0E1ValidT;
+typedef std::integral_constant<uint32_t, STATE_E0_E2_VALID> StateE0E2ValidT;
+typedef std::integral_constant<uint32_t, STATE_E1_E2_VALID> StateE1E2ValidT;
+typedef std::integral_constant<uint32_t, STATE_NO_VALID_EDGES> StateNoEdgesValidT;
+
+// some specializations to convert from edge state to edge bitmask values
+template <typename EdgeMask>
+struct EdgeMaskVal
+{
+    static_assert(EdgeMask::value > STATE_ALL_EDGES_VALID, "Primary EdgeMaskVal shouldn't be instantiated");
+};
+
+template <>
+struct EdgeMaskVal<StateAllEdgesValidT>
+{
+    typedef AllEdgesValidT T;
+};
+
+template <>
+struct EdgeMaskVal<StateE0E1ValidT>
+{
+    typedef E0E1ValidT T;
+};
+
+template <>
+struct EdgeMaskVal<StateE0E2ValidT>
+{
+    typedef E0E2ValidT T;
+};
+
+template <>
+struct EdgeMaskVal<StateE1E2ValidT>
+{
+    typedef E1E2ValidT T;
+};
+
+template <>
+struct EdgeMaskVal<StateNoEdgesValidT>
+{
+    typedef NoEdgesValidT T;
+};
+
+INLINE uint32_t EdgeValToEdgeState(uint32_t val)
+{
+    SWR_ASSERT(val < VALID_TRI_EDGE_COUNT, "Unexpected tri edge mask");
+    static const uint32_t edgeValToEdgeState[VALID_TRI_EDGE_COUNT] = { 0, 0, 0, 1, 0, 2, 3, 4 };
+    return  edgeValToEdgeState[val];
+}
+
 //////////////////////////////////////////////////////////////////////////
 /// @struct RasterScissorEdgesT
 /// @brief Primary RasterScissorEdgesT templated struct that holds compile 
@@ -86,7 +146,8 @@ struct RasterEdgeTraits
 {
     typedef std::true_type RasterizeScissorEdgesT;
     typedef std::integral_constant<uint32_t, 7> NumEdgesT;
-    typedef std::integral_constant<uint32_t, EdgeMaskT::value> ValidEdgeMaskT;
+    //typedef std::integral_constant<uint32_t, EdgeMaskT::value> ValidEdgeMaskT;
+    typedef typename EdgeMaskVal<EdgeMaskT>::T ValidEdgeMaskT;
 };
 
 //////////////////////////////////////////////////////////////////////////
@@ -113,7 +174,7 @@ struct RasterEdgeTraits<std::false_type, std::false_type, EdgeMaskT>
 /// @tparam RasterScissorEdgesT: do we need to rasterize with a scissor?
 template <typename NumSamplesT, typename CenterPatternT, typename ConservativeT, typename InputCoverageT, typename EdgeEnableT, typename RasterScissorEdgesT>
 struct RasterizerTraits final : public ConservativeRastBETraits<ConservativeT, InputCoverageT>,
-                                public RasterEdgeTraits<RasterScissorEdgesT, ConservativeT, std::integral_constant<uint32_t, EdgeEnableT::value>>
+                                public RasterEdgeTraits<RasterScissorEdgesT, ConservativeT, EdgeEnableT>
 {
     typedef MultisampleTraits<static_cast<SWR_MULTISAMPLE_COUNT>(NumSamplesT::value), CenterPatternT::value> MT;