swr/rast: Add support for dynamic vertex size for VS output
authorTim Rowley <timothy.o.rowley@intel.com>
Tue, 6 Jun 2017 23:41:40 +0000 (18:41 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Fri, 16 Jun 2017 21:20:16 +0000 (16:20 -0500)
Add support for dynamic vertex size for the vertex shader output.

Add new state in SWR_FRONTEND_STATE to specify the size.

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

index b9cee0e2c09198f9c167ac6b54c1dac0520c6d80..157a318009212b06678d077e03ba82e610784496 100644 (file)
@@ -1475,36 +1475,36 @@ void ProcessDraw(
         pSoPrimData = (uint32_t*)pDC->pArena->AllocAligned(4096, 16);
     }
 
-    const uint32_t vertexCount = NumVertsPerPrim(state.topology, state.gsState.gsEnable);
+    const uint32_t vertexCount = NumVertsPerPrim(state.topology, true);
+#if USE_SIMD16_FRONTEND
+    uint32_t simdVertexSizeBytes = state.frontendState.vsVertexSize * sizeof(simd16vector);
+#else
+    uint32_t simdVertexSizeBytes = state.frontendState.vsVertexSize * sizeof(simdvector);
+#endif
 
     SWR_ASSERT(vertexCount <= MAX_NUM_VERTS_PER_PRIM);
 
+    // Compute storage requirements for vertex store
+    // TODO: allocation needs to be rethought for better cut support
+    uint32_t numVerts = vertexCount + 2; // Need extra space for PA state machine
+    uint32_t vertexStoreSize = numVerts * simdVertexSizeBytes;
+
     // grow the vertex store for the PA as necessary
-    if (gVertexStoreSize < vertexCount)
+    if (gVertexStoreSize < vertexStoreSize)
     {
         if (pVertexStore != nullptr)
         {
             AlignedFree(pVertexStore);
         }
 
-        while (gVertexStoreSize < vertexCount)
-        {
-#if USE_SIMD16_FRONTEND
-            gVertexStoreSize += 4;  // grow in chunks of 4 simd16vertex
-#else
-            gVertexStoreSize += 8;  // grow in chunks of 8 simdvertex
-#endif
-        }
-
-        SWR_ASSERT(gVertexStoreSize <= MAX_NUM_VERTS_PER_PRIM);
-
-        pVertexStore = reinterpret_cast<PA_STATE::SIMDVERTEX *>(AlignedMalloc(gVertexStoreSize * sizeof(pVertexStore[0]), 64));
+        pVertexStore = reinterpret_cast<PA_STATE::SIMDVERTEX *>(AlignedMalloc(vertexStoreSize, 64));
+        gVertexStoreSize = vertexStoreSize;
 
         SWR_ASSERT(pVertexStore != nullptr);
     }
 
     // choose primitive assembler
-    PA_FACTORY<IsIndexedT, IsCutIndexEnabledT> paFactory(pDC, state.topology, work.numVerts, pVertexStore, gVertexStoreSize, SWR_VTX_NUM_SLOTS);
+    PA_FACTORY<IsIndexedT, IsCutIndexEnabledT> paFactory(pDC, state.topology, work.numVerts, pVertexStore, numVerts, state.frontendState.vsVertexSize);
     PA_STATE& pa = paFactory.GetPA();
 
 #if USE_SIMD16_FRONTEND
index 4c0c1db412cd9800130d8ae66bd34c60d5aa2323..0cf9ad65dbc0a1c21e6ff226802d898c91722958 100644 (file)
@@ -856,6 +856,10 @@ struct SWR_FRONTEND_STATE
         uint32_t bits;
     } provokingVertex;
     uint32_t topologyProvokingVertex; // provoking vertex for the draw topology
+
+    // Size of a vertex in simdvector units. Should be sized to the 
+    // maximum of the input/output of the vertex shader.
+    uint32_t vsVertexSize;
 };
 
 //////////////////////////////////////////////////////////////////////////
index 03c82a7e510577c5764705b261a0a756a21e5f1b..4e6426d7ec0cb201e48ea16406554ad9ab0b701d 100644 (file)
@@ -128,6 +128,10 @@ swr_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
    /* Set up frontend state
     * XXX setup provokingVertex & topologyProvokingVertex */
    SWR_FRONTEND_STATE feState = {0};
+
+   /* XXX this value should be minimized based on the shader set */
+   feState.vsVertexSize = SWR_VTX_NUM_SLOTS;
+
    if (ctx->rasterizer->flatshade_first) {
       feState.provokingVertex = {1, 0, 0};
    } else {