Retry lesser FBO sample counts if UNSUPPORTED

On some of our implementations we return GL_FRAMEBUFFER_UNSUPPORTED
when the no-attachment maximum width, height and samples are all
used in combination. This is because the combination goes beyond
some of our hardware limits. It would be fine to use either
maximum width/height or maximum samples, but not all
together.

Since GL_FRAMEBUFFER_UNSUPPORTED is a valid FBO status for
implementation-defined reasons, the test should recognize this
and try again with lesser limits until the FBO is complete.

Affects:

dEQP-GL45.functional.fbo.no_attachments.maximums.all

Components: OpenGL

VK-GL-CTS issue: 2973

Change-Id: I8db2e9f802b3f4d1ee59bbfbfa1935bbe3cc6d00
diff --git a/modules/gles31/functional/es31fFboNoAttachmentTests.cpp b/modules/gles31/functional/es31fFboNoAttachmentTests.cpp
index 4d18459..ee215de 100644
--- a/modules/gles31/functional/es31fFboNoAttachmentTests.cpp
+++ b/modules/gles31/functional/es31fFboNoAttachmentTests.cpp
@@ -364,13 +364,40 @@
 	GLuint					framebuffer	= 0;
 	const int				width		= getWidth();
 	const int				height		= getHeight();
-	const int				samples		= getSamples();
+	int						samples		= getSamples();
 
-	gl.genFramebuffers(1, &framebuffer);
-	gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
-	gl.framebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, width);
-	gl.framebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, height);
-	gl.framebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, samples);
+	for (;;) {
+		gl.genFramebuffers(1, &framebuffer);
+		gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
+		gl.framebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, width);
+		gl.framebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, height);
+		gl.framebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, samples);
+
+		GLenum status = gl.checkFramebufferStatus(GL_DRAW_FRAMEBUFFER);
+		if (status == GL_FRAMEBUFFER_COMPLETE)
+			break;
+		else
+		{
+			gl.deleteFramebuffers(1, &framebuffer);
+			framebuffer = 0;
+
+			if (status == GL_FRAMEBUFFER_UNSUPPORTED)
+				if (samples >= 2)
+					samples /= 2;
+				else
+					break;
+			else
+			{
+				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected no-attachment framebuffer status");
+				return STOP;
+			}
+		}
+	}
+	if (!framebuffer)
+	{
+		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unable to find a supported no-attachment framebuffer width/height/samples");
+		return STOP;
+	}
 
 	log << TestLog::Message << "Verifying " << width << "x" << height << " framebuffer with " << samples << "x multisampling" << TestLog::EndMessage;