swr: [rasterizer] Correctly select optimized primitive assembly.
authorBruce Cherniak <bruce.cherniak@intel.com>
Tue, 24 May 2016 20:00:17 +0000 (15:00 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Wed, 25 May 2016 23:47:16 +0000 (18:47 -0500)
Indexed primitives were always using cut-aware primitive assembly,
whether primitive_restart was enabled or not.  Correctly pass down
primitive_restart and select optimized PA when possible.

Reviewed-by: Tim Rowley <timothy.o.rowley@intel.com>
src/gallium/drivers/swr/rasterizer/core/api.cpp
src/gallium/drivers/swr/rasterizer/core/frontend.cpp
src/gallium/drivers/swr/rasterizer/core/frontend.h
src/gallium/drivers/swr/rasterizer/core/pa.h
src/gallium/drivers/swr/rasterizer/core/state.h
src/gallium/drivers/swr/swr_draw.cpp
src/gallium/drivers/swr/swr_state.cpp

index 8e0c1e1d2d818d24becca815d5566f21316c28c7..2e6f8b3a16da3793288a51e19c6bcc445023d92f 100644 (file)
@@ -1069,6 +1069,7 @@ void DrawInstanced(
         pDC->FeWork.type = DRAW;
         pDC->FeWork.pfnWork = GetProcessDrawFunc(
             false,  // IsIndexed
+            false, // bEnableCutIndex
             pState->tsState.tsEnable,
             pState->gsState.gsEnable,
             pState->soState.soEnable,
@@ -1202,6 +1203,7 @@ void DrawIndexedInstance(
         pDC->FeWork.type = DRAW;
         pDC->FeWork.pfnWork = GetProcessDrawFunc(
             true,   // IsIndexed
+            pState->frontendState.bEnableCutIndex,
             pState->tsState.tsEnable,
             pState->gsState.gsEnable,
             pState->soState.soEnable,
index d6643c65ae051c3c3e08321d2bcd2d163f15e1a5..ef90a24fe75d21af7ee1b9b1804f05afe5014e6d 100644 (file)
@@ -1159,6 +1159,7 @@ static void TessellationStages(
 /// @param pUserData - Pointer to DRAW_WORK
 template <
     typename IsIndexedT,
+    typename IsCutIndexEnabledT,
     typename HasTessellationT,
     typename HasGeometryShaderT,
     typename HasStreamOutT,
@@ -1283,7 +1284,7 @@ void ProcessDraw(
     }
 
     // choose primitive assembler
-    PA_FACTORY<IsIndexedT> paFactory(pDC, state.topology, work.numVerts);
+    PA_FACTORY<IsIndexedT, IsCutIndexEnabledT> paFactory(pDC, state.topology, work.numVerts);
     PA_STATE& pa = paFactory.GetPA();
 
     /// @todo: temporarily move instance loop in the FE to ensure SO ordering
@@ -1434,12 +1435,13 @@ struct FEDrawChooser
 // Selector for correct templated Draw front-end function
 PFN_FE_WORK_FUNC GetProcessDrawFunc(
     bool IsIndexed,
+    bool IsCutIndexEnabled,
     bool HasTessellation,
     bool HasGeometryShader,
     bool HasStreamOut,
     bool HasRasterization)
 {
-    return TemplateArgUnroller<FEDrawChooser>::GetFunc(IsIndexed, HasTessellation, HasGeometryShader, HasStreamOut, HasRasterization);
+    return TemplateArgUnroller<FEDrawChooser>::GetFunc(IsIndexed, IsCutIndexEnabled, HasTessellation, HasGeometryShader, HasStreamOut, HasRasterization);
 }
 
 
index e1b040015a931d89e7a95f3518eedb78817c9e61..dfd3987bdfb93d2e53d309e2ab0cb39981cb40e5 100644 (file)
@@ -322,6 +322,7 @@ uint32_t NumVertsPerPrim(PRIMITIVE_TOPOLOGY topology, bool includeAdjVerts);
 // ProcessDraw front-end function.  All combinations of parameter values are available
 PFN_FE_WORK_FUNC GetProcessDrawFunc(
     bool IsIndexed,
+    bool IsCutIndexEnabled,
     bool HasTessellation,
     bool HasGeometryShader,
     bool HasStreamOut,
index c98ea14e24453d7b717ff6b162f55ae84aaf99a1..6aa73c1ddf1b2820bbbacf05b5491936c8db3fd2 100644 (file)
@@ -1149,14 +1149,14 @@ private:
 
 // Primitive Assembler factory class, responsible for creating and initializing the correct assembler
 // based on state.
-template <typename IsIndexedT>
+template <typename IsIndexedT, typename IsCutIndexEnabledT>
 struct PA_FACTORY
 {
     PA_FACTORY(DRAW_CONTEXT* pDC, PRIMITIVE_TOPOLOGY in_topo, uint32_t numVerts) : topo(in_topo)
     {
 #if KNOB_ENABLE_CUT_AWARE_PA == TRUE
         const API_STATE& state = GetApiState(pDC);
-        if ((IsIndexedT::value && (
+        if ((IsIndexedT::value && IsCutIndexEnabledT::value && (
             topo == TOP_TRIANGLE_STRIP || topo == TOP_POINT_LIST ||
             topo == TOP_LINE_LIST || topo == TOP_LINE_STRIP ||
             topo == TOP_TRIANGLE_LIST || topo == TOP_LINE_LIST_ADJ ||
index f4813e4239587d679736e2df0fd1668f69c591a4..5156c6b1322ae923b9adddee4b6167199cebaaa6 100644 (file)
@@ -799,6 +799,7 @@ struct SWR_FRONTEND_STATE
     // skip clip test, perspective divide, and viewport transform
     // intended for verts in screen space
     bool vpTransformDisable;
+    bool bEnableCutIndex;
     union
     {
         struct
@@ -808,7 +809,7 @@ struct SWR_FRONTEND_STATE
             uint32_t triStripList : 2;
         };
         uint32_t bits;
-    }provokingVertex;
+    } provokingVertex;
     uint32_t topologyProvokingVertex; // provoking vertex for the draw topology
 };
 
index 428bf78cb5548f46b1ef712692920571dbff54e8..7a4c89626fb14637f8a3aaf044b1851a2224f69a 100644 (file)
@@ -159,6 +159,12 @@ swr_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
 
    SwrSetFetchFunc(ctx->swrContext, velems->fsFunc);
 
+   /* Set up frontend state
+    * XXX setup provokingVertex & topologyProvokingVertex */
+   SWR_FRONTEND_STATE feState = {0};
+   feState.bEnableCutIndex = info->primitive_restart;
+   SwrSetFrontendState(ctx->swrContext, &feState);
+
    if (info->indexed)
       SwrDrawIndexedInstanced(ctx->swrContext,
                               swr_convert_prim_topology(info->mode),
index a7ae9df2d3ef54f98f768ff1bc1e249c36953fda..f9326f352308cdcb641290556010453a623ef9a5 100644 (file)
@@ -1347,10 +1347,6 @@ swr_update_derived(struct pipe_context *pipe,
 
    SwrSetLinkage(ctx->swrContext, linkage, NULL);
 
-   // set up frontend state
-   SWR_FRONTEND_STATE feState = {0};
-   SwrSetFrontendState(ctx->swrContext, &feState);
-
    // set up backend state
    SWR_BACKEND_STATE backendState = {0};
    backendState.numAttributes = 1;