Move sample count hack from GraphicsState to Renderer::draw

A hack to set sample count to 1 is moved from GraphicsState's
constructor to Renderer::draw itself.  This is where batch size is
derived from sample count.  A side effect of this change is that the
batch size is now based on sample count == 1 on an otherwise
multisampled pipeline that has rasterizer discard dynamically enabled.

Bug: b/245568070
Tests: dEQP-VK.*
Change-Id: I9f2ddfd9b0a7f94eca417d8a521ed6f7d793846b
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/68150
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
Presubmit-Ready: Shahbaz Youssefi <syoussefi@google.com>
diff --git a/src/Device/Context.cpp b/src/Device/Context.cpp
index cf440af..a72f30e 100644
--- a/src/Device/Context.cpp
+++ b/src/Device/Context.cpp
@@ -493,10 +493,6 @@
 		extensionCreateInfo = extensionCreateInfo->pNext;
 	}
 
-	// The sample count affects the batch size, so it needs initialization even if rasterization is disabled.
-	// TODO(b/147812380): Eliminate the dependency between multisampling and batch size.
-	sampleCount = 1;
-
 	// Only access rasterization state if rasterization is not disabled.
 	if(rasterizationState->rasterizerDiscardEnable == VK_FALSE || dynamicStateFlags.dynamicRasterizerDiscardEnable)
 	{
diff --git a/src/Device/Renderer.cpp b/src/Device/Renderer.cpp
index 2b6949a..b61fa95 100644
--- a/src/Device/Renderer.cpp
+++ b/src/Device/Renderer.cpp
@@ -197,6 +197,8 @@
 	draw->id = id;
 
 	const vk::GraphicsState &pipelineState = pipeline->getState(dynamicState);
+	const bool hasRasterizerDiscard = pipelineState.hasRasterizerDiscard();
+
 	pixelProcessor.setBlendConstant(pipelineState.getBlendConstants());
 
 	const vk::Inputs &inputs = pipeline->getInputs();
@@ -221,10 +223,14 @@
 
 	draw->containsImageWrite = pipeline->containsImageWrite();
 
-	DrawCall::SetupFunction setupPrimitives = nullptr;
-	int ms = pipelineState.getSampleCount();
+	// The sample count affects the batch size even if rasterization is disabled.
+	// TODO(b/147812380): Eliminate the dependency between multisampling and batch size.
+	int ms = hasRasterizerDiscard ? 1 : pipelineState.getSampleCount();
+	ASSERT(ms > 0);
+
 	unsigned int numPrimitivesPerBatch = MaxBatchSize / ms;
 
+	DrawCall::SetupFunction setupPrimitives = nullptr;
 	if(pipelineState.isDrawTriangle(false))
 	{
 		switch(pipelineState.getPolygonMode())