From 7f3be3f0b8df1eb85130c58e545a7e73f4369069 Mon Sep 17 00:00:00 2001 From: Tim Rowley Date: Tue, 6 Jun 2017 18:41:40 -0500 Subject: [PATCH] swr/rast: Add support for dynamic vertex size for VS output 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 --- .../drivers/swr/rasterizer/core/frontend.cpp | 30 +++++++++---------- .../drivers/swr/rasterizer/core/state.h | 4 +++ src/gallium/drivers/swr/swr_draw.cpp | 4 +++ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/gallium/drivers/swr/rasterizer/core/frontend.cpp b/src/gallium/drivers/swr/rasterizer/core/frontend.cpp index b9cee0e2c09..157a3180092 100644 --- a/src/gallium/drivers/swr/rasterizer/core/frontend.cpp +++ b/src/gallium/drivers/swr/rasterizer/core/frontend.cpp @@ -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(AlignedMalloc(gVertexStoreSize * sizeof(pVertexStore[0]), 64)); + pVertexStore = reinterpret_cast(AlignedMalloc(vertexStoreSize, 64)); + gVertexStoreSize = vertexStoreSize; SWR_ASSERT(pVertexStore != nullptr); } // choose primitive assembler - PA_FACTORY paFactory(pDC, state.topology, work.numVerts, pVertexStore, gVertexStoreSize, SWR_VTX_NUM_SLOTS); + PA_FACTORY paFactory(pDC, state.topology, work.numVerts, pVertexStore, numVerts, state.frontendState.vsVertexSize); PA_STATE& pa = paFactory.GetPA(); #if USE_SIMD16_FRONTEND diff --git a/src/gallium/drivers/swr/rasterizer/core/state.h b/src/gallium/drivers/swr/rasterizer/core/state.h index 4c0c1db412c..0cf9ad65dbc 100644 --- a/src/gallium/drivers/swr/rasterizer/core/state.h +++ b/src/gallium/drivers/swr/rasterizer/core/state.h @@ -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; }; ////////////////////////////////////////////////////////////////////////// diff --git a/src/gallium/drivers/swr/swr_draw.cpp b/src/gallium/drivers/swr/swr_draw.cpp index 03c82a7e510..4e6426d7ec0 100644 --- a/src/gallium/drivers/swr/swr_draw.cpp +++ b/src/gallium/drivers/swr/swr_draw.cpp @@ -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 { -- 2.30.2