From: Tim Rowley Date: Tue, 28 Mar 2017 18:29:22 +0000 (-0500) Subject: swr: [rasterizer core] Fix center sample pattern X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e5fdfcf83666bace5330907ac39ad88817d154cb;p=mesa.git swr: [rasterizer core] Fix center sample pattern Fix long hidden bug in rasterizer handling of center sample pattern. Reviewed-by: Bruce Cherniak --- diff --git a/src/gallium/drivers/swr/rasterizer/core/binner.cpp b/src/gallium/drivers/swr/rasterizer/core/binner.cpp index 63eab33ac0b..3d42718a374 100644 --- a/src/gallium/drivers/swr/rasterizer/core/binner.cpp +++ b/src/gallium/drivers/swr/rasterizer/core/binner.cpp @@ -599,9 +599,6 @@ void BinTriangles( uint32_t *pPrimID = (uint32_t *)&primID; const uint32_t *pViewportIndex = (uint32_t *)&viewportIdx; DWORD triIndex = 0; - // for center sample pattern, all samples are at pixel center; calculate coverage - // once at center and broadcast the results in the backend - const SWR_MULTISAMPLE_COUNT sampleCount = (rastState.samplePattern == SWR_MSAA_STANDARD_PATTERN) ? rastState.sampleCount : SWR_MULTISAMPLE_1X; uint32_t edgeEnable; PFN_WORK_FUNC pfnWork; if (CT::IsConservativeT::value) @@ -643,8 +640,8 @@ void BinTriangles( else { // degenerate triangles won't be sent to rasterizer; just enable all edges - pfnWork = GetRasterizerFunc(sampleCount, (rastState.conservativeRast > 0), - (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, ALL_EDGES_VALID, + pfnWork = GetRasterizerFunc(rastState.sampleCount, (rastState.samplePattern == SWR_MSAA_CENTER_PATTERN), + (rastState.conservativeRast > 0), (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, ALL_EDGES_VALID, (state.scissorsTileAligned == false)); } @@ -661,7 +658,8 @@ void BinTriangles( // only discard for non-MSAA case and when conservative rast is disabled // (xmin + 127) & ~255 // (xmax + 128) & ~255 - if (rastState.sampleCount == SWR_MULTISAMPLE_1X && (!CT::IsConservativeT::value)) + if((rastState.sampleCount == SWR_MULTISAMPLE_1X || rastState.samplePattern == SWR_MSAA_CENTER_PATTERN) && + (!CT::IsConservativeT::value)) { origTriMask = triMask; @@ -789,8 +787,8 @@ endBinTriangles: { // only rasterize valid edges if we have a degenerate primitive int32_t triEdgeEnable = (edgeEnable >> (triIndex * 3)) & ALL_EDGES_VALID; - work.pfnWork = GetRasterizerFunc(sampleCount, (rastState.conservativeRast > 0), - (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, triEdgeEnable, + work.pfnWork = GetRasterizerFunc(rastState.sampleCount, (rastState.samplePattern == SWR_MSAA_CENTER_PATTERN), + (rastState.conservativeRast > 0), (SWR_INPUT_COVERAGE)pDC->pState->state.psState.inputCoverage, triEdgeEnable, (state.scissorsTileAligned == false)); // Degenerate triangles are required to be constant interpolated diff --git a/src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp b/src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp index a8a052a73c3..d0fdf4882ff 100644 --- a/src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp +++ b/src/gallium/drivers/swr/rasterizer/core/rasterizer.cpp @@ -814,7 +814,7 @@ struct UpdateEdgeMasksInnerConservative(vAi, vBi, vTempEdge[1]); adjustEdgeConservative(vAi, vBi, vTempEdge[2]); - UpdateEdgeMasks(vEdgeTileBbox, vTempEdge, mask0, mask1, mask2); + UpdateEdgeMasks(vEdgeTileBbox, vTempEdge, mask0, mask1, mask2); } }; @@ -1037,11 +1037,11 @@ void RasterizeTriangle(DRAW_CONTEXT* pDC, uint32_t workerId, uint32_t macroTile, int32_t y = AlignDown(intersect.ymin, (FIXED_POINT_SCALE * KNOB_TILE_Y_DIM)); // convenience typedef - typedef typename RT::NumRasterSamplesT NumRasterSamplesT; + typedef typename RT::NumCoverageSamplesT NumCoverageSamplesT; // single sample rasterization evaluates edges at pixel center, // multisample evaluates edges UL pixel corner and steps to each sample position - if(std::is_same::value) + if(std::is_same::value) { // Add 0.5, in fixed point, to offset to pixel center x += (FIXED_POINT_SCALE / 2); @@ -1116,7 +1116,7 @@ void RasterizeTriangle(DRAW_CONTEXT* pDC, uint32_t workerId, uint32_t macroTile, // | | // min(xSamples),max(ySamples) ------ max(xSamples),max(ySamples) __m256d vEdgeTileBbox[3]; - if (NumRasterSamplesT::value > 1) + if (NumCoverageSamplesT::value > 1) { __m128i vTileSampleBBoxXh = RT::MT::TileSampleOffsetsX(); __m128i vTileSampleBBoxYh = RT::MT::TileSampleOffsetsY(); @@ -1163,9 +1163,9 @@ void RasterizeTriangle(DRAW_CONTEXT* pDC, uint32_t workerId, uint32_t macroTile, // is the corner of the edge outside of the raster tile? (vEdge < 0) int mask0, mask1, mask2; - UpdateEdgeMasks(vEdgeTileBbox, vEdgeFix16, mask0, mask1, mask2); + UpdateEdgeMasks(vEdgeTileBbox, vEdgeFix16, mask0, mask1, mask2); - for (uint32_t sampleNum = 0; sampleNum < NumRasterSamplesT::value; sampleNum++) + for (uint32_t sampleNum = 0; sampleNum < NumCoverageSamplesT::value; sampleNum++) { // trivial reject, at least one edge has all 4 corners of raster tile outside bool trivialReject = TrivialRejectTest(mask0, mask1, mask2); @@ -1196,7 +1196,7 @@ void RasterizeTriangle(DRAW_CONTEXT* pDC, uint32_t workerId, uint32_t macroTile, else { __m256d vEdgeAtSample[RT::NumEdgesT::value]; - if(std::is_same::value) + if(std::is_same::value) { // should get optimized out for single sample case (global value numbering or copy propagation) for (uint32_t e = 0; e < RT::NumEdgesT::value; ++e) @@ -1242,7 +1242,7 @@ void RasterizeTriangle(DRAW_CONTEXT* pDC, uint32_t workerId, uint32_t macroTile, else { // if we're calculating coverage per sample, need to store it off. otherwise no covered samples, don't need to do anything - if(NumRasterSamplesT::value > 1) + if(NumCoverageSamplesT::value > 1) { triDesc.coverageMask[sampleNum] = 0; } @@ -1339,11 +1339,9 @@ void RasterizeTriPoint(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile, // setup triangle rasterizer function PFN_WORK_FUNC pfnTriRast; - // for center sample pattern, all samples are at pixel center; calculate coverage - // once at center and broadcast the results in the backend - uint32_t sampleCount = (rastState.samplePattern == SWR_MSAA_STANDARD_PATTERN) ? rastState.sampleCount : SWR_MULTISAMPLE_1X; // conservative rast not supported for points/lines - pfnTriRast = GetRasterizerFunc(sampleCount, false, SWR_INPUT_COVERAGE_NONE, ALL_EDGES_VALID, (pDC->pState->state.scissorsTileAligned == false)); + pfnTriRast = GetRasterizerFunc(rastState.sampleCount, (rastState.samplePattern == SWR_MSAA_CENTER_PATTERN), false, + SWR_INPUT_COVERAGE_NONE, ALL_EDGES_VALID, (pDC->pState->state.scissorsTileAligned == false)); // overwrite texcoords for point sprites if (isPointSpriteTexCoordEnabled) @@ -1674,9 +1672,9 @@ void RasterizeLine(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile, voi // setup triangle rasterizer function PFN_WORK_FUNC pfnTriRast; - uint32_t sampleCount = (rastState.samplePattern == SWR_MSAA_STANDARD_PATTERN) ? rastState.sampleCount : SWR_MULTISAMPLE_1X; // conservative rast not supported for points/lines - pfnTriRast = GetRasterizerFunc(sampleCount, false, SWR_INPUT_COVERAGE_NONE, ALL_EDGES_VALID, (pDC->pState->state.scissorsTileAligned == false)); + pfnTriRast = GetRasterizerFunc(rastState.sampleCount, (rastState.samplePattern == SWR_MSAA_CENTER_PATTERN), false, + SWR_INPUT_COVERAGE_NONE, ALL_EDGES_VALID, (pDC->pState->state.scissorsTileAligned == false)); // make sure this macrotile intersects the triangle __m128i vXai = fpToFixedPoint(vXa); @@ -1786,6 +1784,7 @@ struct RasterizerChooser // Selector for correct templated RasterizeTriangle function PFN_WORK_FUNC GetRasterizerFunc( uint32_t numSamples, + bool IsCenter, bool IsConservative, uint32_t InputCoverage, uint32_t EdgeEnable, @@ -1794,6 +1793,7 @@ PFN_WORK_FUNC GetRasterizerFunc( { return TemplateArgUnroller::GetFunc( IntArg{numSamples}, + IsCenter, IsConservative, IntArg{InputCoverage}, IntArg<0, VALID_TRI_EDGE_COUNT-1>{EdgeEnable}, diff --git a/src/gallium/drivers/swr/rasterizer/core/rasterizer.h b/src/gallium/drivers/swr/rasterizer/core/rasterizer.h index 457153b7fbd..96b12ae4196 100644 --- a/src/gallium/drivers/swr/rasterizer/core/rasterizer.h +++ b/src/gallium/drivers/swr/rasterizer/core/rasterizer.h @@ -46,6 +46,7 @@ __m128i fpToFixedPoint(const __m128 vIn) // Selector for correct templated RasterizeTriangle function PFN_WORK_FUNC GetRasterizerFunc( uint32_t numSamples, + bool IsCenter, bool IsConservative, uint32_t InputCoverage, uint32_t EdgeEnable, @@ -110,19 +111,20 @@ struct RasterEdgeTraits /// @tparam InputCoverageT: what type of input coverage is the PS expecting? /// (only used with conservative rasterization) /// @tparam RasterScissorEdgesT: do we need to rasterize with a scissor? -template +template struct RasterizerTraits final : public ConservativeRastBETraits, public RasterEdgeTraits> { - typedef MultisampleTraits(NumSamplesT::value)> MT; + typedef MultisampleTraits(NumSamplesT::value), + (CenterPatternT::value ? SWR_MSAA_CENTER_PATTERN : SWR_MSAA_STANDARD_PATTERN)> MT; /// Fixed point precision the rasterizer is using typedef FixedPointTraits PrecisionT; /// Fixed point precision of the edge tests used during rasterization typedef FixedPointTraits EdgePrecisionT; - // If conservative rast is enabled, only need a single sample coverage test, with the result copied to all samples - typedef std::integral_constant NumRasterSamplesT; + // If conservative rast or MSAA center pattern is enabled, only need a single sample coverage test, with the result copied to all samples + typedef std::integral_constant NumCoverageSamplesT; static_assert(EdgePrecisionT::BitsT::value >= ConservativeRastBETraits::ConservativePrecisionT::BitsT::value, "Rasterizer edge fixed point precision < required conservative rast precision");