Support multisampled Bresenham lines

Multisampled Bresenham lines must be rendered the same
way as non multisampled Bresenham lines, so use the
same coverage mask for all samples in that case.

Bug: b/142965928
Change-Id: Ifc0e141e4f1d9ae48c064896405164db3addd521
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38788
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Device/PixelProcessor.cpp b/src/Device/PixelProcessor.cpp
index d5b5b7d..e38991f 100644
--- a/src/Device/PixelProcessor.cpp
+++ b/src/Device/PixelProcessor.cpp
@@ -192,6 +192,8 @@
 
 		state.multiSample = static_cast<unsigned int>(context->sampleCount);
 		state.multiSampleMask = context->multiSampleMask;
+		state.multiSampledBresenham = (state.multiSample > 1) && context->isDrawLine(true) &&
+		                              (context->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT);
 
 		if(state.multiSample > 1 && context->pixelShader)
 		{
diff --git a/src/Device/PixelProcessor.hpp b/src/Device/PixelProcessor.hpp
index 5537af4..d6d8736 100644
--- a/src/Device/PixelProcessor.hpp
+++ b/src/Device/PixelProcessor.hpp
@@ -81,6 +81,7 @@
 			VkFormat targetFormat[RENDERTARGETS];
 			unsigned int multiSample;
 			unsigned int multiSampleMask;
+			bool multiSampledBresenham;
 			bool alphaToCoverage;
 			bool centroid;
 			VkFrontFace frontFace;
diff --git a/src/Device/QuadRasterizer.cpp b/src/Device/QuadRasterizer.cpp
index c756d6a..b070d97 100644
--- a/src/Device/QuadRasterizer.cpp
+++ b/src/Device/QuadRasterizer.cpp
@@ -180,7 +180,8 @@
 					{
 						if (state.multiSampleMask & (1<<q))
 						{
-							Short4 mask = CmpGT(xxxx, xLeft[q]) & CmpGT(xRight[q], xxxx);
+							unsigned int i = state.multiSampledBresenham ? 0 : q;
+							Short4 mask = CmpGT(xxxx, xLeft[i]) & CmpGT(xRight[i], xxxx);
 							cMask[q] = SignMask(PackSigned(mask, mask)) & 0x0000000F;
 						}
 						else
diff --git a/src/Device/Renderer.cpp b/src/Device/Renderer.cpp
index ea68bc3..23946bb 100644
--- a/src/Device/Renderer.cpp
+++ b/src/Device/Renderer.cpp
@@ -814,14 +814,7 @@
 			return false;
 		}
 
-		// We use rectangular lines for non-Bresenham lines (cf. 'strictLines'),
-		// and for Bresenham lines when multiSampling is enabled.
-		// FIXME(b/142965928): Bresenham lines should render the same with or without
-		//                     multisampling, which will require a special case in the
-		//                     code when multisampling is on. For now, we just use
-		//                     rectangular lines when multisampling is enabled.
-		if((draw.setupState.multiSample > 1) ||
-		   (draw.lineRasterizationMode != VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT))
+		if(draw.lineRasterizationMode != VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT)
 		{
 			// Rectangle centered on the line segment