13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 2.0 Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Flush and finish tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fFlushFinishTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluObjectWrapper.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDrawUtil.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsCalibration.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
352995cc217d02c92dbca8fed6f55337b93d1a7506Pyry Haulos#include "tcuCPUWarmup.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deClock.h"
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deThread.h"
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h"
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm>
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
598852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryusing deqp::gls::theilSenLinearRegression;
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing deqp::gls::LineParameters;
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MAX_VIEWPORT_SIZE		= 128,
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MAX_SAMPLE_DURATION_US	= 1000*1000,
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	WAIT_TIME_MS			= 1200,
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NUM_SAMPLES				= 25,
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MIN_DRAW_CALL_COUNT		= 10,
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MAX_DRAW_CALL_COUNT		= 1<<20,
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NUM_ITERS_IN_SHADER		= 10
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst float		NO_CORR_COEF_THRESHOLD		= 0.1f;
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst float		FLUSH_COEF_THRESHOLD		= 0.2f;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst float		CORRELATED_COEF_THRESHOLD	= 0.5f;
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void busyWait (int milliseconds)
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint64	startTime	= deGetMicroseconds();
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			v			= 2.0f;
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (;;)
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int i = 0; i < 10; i++)
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			v = deFloatSin(v);
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (deGetMicroseconds()-startTime >= deUint64(1000*milliseconds))
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass CalibrationFailedException : public std::runtime_error
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	CalibrationFailedException (const std::string& reason) : std::runtime_error(reason) {}
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FlushFinishCase : public TestCase
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum ExpectedBehavior
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EXPECT_COEF_LESS_THAN = 0,
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EXPECT_COEF_GREATER_THAN,
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							FlushFinishCase		(Context&			context,
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												 const char*		name,
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												 const char*		description,
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												 ExpectedBehavior	waitBehavior,
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												 float				waitThreshold,
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												 ExpectedBehavior	readBehavior,
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												 float				readThreshold);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~FlushFinishCase	(void);
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init				(void);
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit				(void);
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate				(void);
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	struct Sample
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			numDrawCalls;
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	waitTime;
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	readPixelsTime;
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	struct CalibrationParams
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			maxDrawCalls;
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void			waitForGL			(void) = 0;
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							FlushFinishCase		(const FlushFinishCase&);
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FlushFinishCase&		operator=			(const FlushFinishCase&);
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	CalibrationParams		calibrate			(void);
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					analyzeResults		(const std::vector<Sample>& samples, const CalibrationParams& calibrationParams);
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					setupRenderState	(void);
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					render				(int numDrawCalls);
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					readPixels			(void);
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const ExpectedBehavior	m_waitBehavior;
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				m_waitThreshold;
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const ExpectedBehavior	m_readBehavior;
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				m_readThreshold;
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::ShaderProgram*		m_program;
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1573c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFlushFinishCase::FlushFinishCase (Context& context, const char* name, const char* description, ExpectedBehavior waitBehavior, float waitThreshold, ExpectedBehavior readBehavior, float readThreshold)
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(context, name, description)
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_waitBehavior	(waitBehavior)
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_waitThreshold	(waitThreshold)
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_readBehavior	(readBehavior)
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_readThreshold	(readThreshold)
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_program			(DE_NULL)
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFlushFinishCase::~FlushFinishCase (void)
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FlushFinishCase::deinit();
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlushFinishCase::init (void)
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_program);
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_program = new glu::ShaderProgram(m_context.getRenderContext(),
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glu::ProgramSources()
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< glu::VertexSource(
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"attribute highp vec4 a_position;\n"
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"varying highp vec4 v_coord;\n"
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"void main (void)\n"
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"{\n"
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"	gl_Position = a_position;\n"
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"	v_coord = a_position;\n"
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"}\n")
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< glu::FragmentSource(
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"uniform mediump int u_numIters;\n"
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"varying mediump vec4 v_coord;\n"
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"void main (void)\n"
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"{\n"
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"	highp vec4 color = v_coord;\n"
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"	for (int i = 0; i < " + de::toString(int(NUM_ITERS_IN_SHADER)) + "; i++)\n"
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"		color = sin(color);\n"
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"	gl_FragColor = color;\n"
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				"}\n"));
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_program->isOk())
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << *m_program;
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		delete m_program;
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_program = DE_NULL;
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_FAIL("Compile failed");
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlushFinishCase::deinit (void)
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_program;
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_program = DE_NULL;
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestLog& operator<< (tcu::TestLog& log, const FlushFinishCase::Sample& sample)
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Message << sample.numDrawCalls << " calls:\t" << sample.waitTime << " us wait,\t" << sample.readPixelsTime << " us read" << TestLog::EndMessage;
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return log;
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlushFinishCase::setupRenderState (void)
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl				= m_context.getRenderContext().getFunctions();
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				posLoc			= gl.getAttribLocation(m_program->getProgram(), "a_position");
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				viewportW		= de::min<int>(m_context.getRenderTarget().getWidth(), MAX_VIEWPORT_SIZE);
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				viewportH		= de::min<int>(m_context.getRenderTarget().getHeight(), MAX_VIEWPORT_SIZE);
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const float s_positions[] =
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		-1.0f, -1.0f,
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		+1.0f, -1.0f,
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		-1.0f, +1.0f,
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		+1.0f, +1.0f
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK(posLoc >= 0);
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.viewport(0, 0, viewportW, viewportH);
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(m_program->getProgram());
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enableVertexAttribArray(posLoc);
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.vertexAttribPointer(posLoc, 2, GL_FLOAT, GL_FALSE, 0, &s_positions[0]);
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enable(GL_BLEND);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.blendFunc(GL_ONE, GL_ONE);
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.blendEquation(GL_FUNC_ADD);
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to set up render state");
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlushFinishCase::render (int numDrawCalls)
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl	= m_context.getRenderContext().getFunctions();
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint8 indices[] = { 0, 1, 2, 2, 1, 3 };
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < numDrawCalls; ndx++)
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_BYTE, &indices[0]);
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlushFinishCase::readPixels (void)
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl		= m_context.getRenderContext().getFunctions();
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint8					tmp[4];
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &tmp);
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFlushFinishCase::CalibrationParams FlushFinishCase::calibrate (void)
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::ScopedLogSection		section				(m_testCtx.getLog(), "CalibrationInfo", "Calibration info");
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	CalibrationParams			params;
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Find draw call count that results in desired maximum time.
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64			prevDuration			= 0;
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int					prevDrawCount			= 1;
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int					curDrawCount			= 1;
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "Calibrating maximum draw call count, target duration = " << int(MAX_SAMPLE_DURATION_US) << " us" << TestLog::EndMessage;
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (;;)
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64 curDuration;
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const deUint64	startTime	= deGetMicroseconds();
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				render(curDrawCount);
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				readPixels();
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				curDuration = deGetMicroseconds()-startTime;
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << TestLog::Message << "Duration with " << curDrawCount << " draw calls = " << curDuration << " us" << TestLog::EndMessage;
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (curDuration > MAX_SAMPLE_DURATION_US)
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (curDrawCount > 1)
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					// Compute final count by using linear estimation.
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const float		a		= float(curDuration - prevDuration) / float(curDrawCount - prevDrawCount);
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const float		b		= float(prevDuration) - a*float(prevDrawCount);
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const float		est		= (float(MAX_SAMPLE_DURATION_US) - b) / a;
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					curDrawCount = de::clamp(deFloorFloatToInt32(est), 1, int(MAX_DRAW_CALL_COUNT));
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// else: Settle on 1.
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (curDrawCount >= MAX_DRAW_CALL_COUNT)
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break; // Settle on maximum.
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				prevDrawCount	= curDrawCount;
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				prevDuration	= curDuration;
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				curDrawCount	= curDrawCount*2;
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params.maxDrawCalls = curDrawCount;
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Integer("MaxDrawCalls", "Maximum number of draw calls", "", QP_KEY_TAG_NONE, params.maxDrawCalls);
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Sanity check.
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (params.maxDrawCalls < MIN_DRAW_CALL_COUNT)
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw CalibrationFailedException("Calibration failed, maximum draw call count is too low");
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return params;
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct CompareSampleDrawCount
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool operator() (const FlushFinishCase::Sample& a, const FlushFinishCase::Sample& b) const { return a.numDrawCalls < b.numDrawCalls; }
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::vector<Vec2> getPointsFromSamples (const std::vector<FlushFinishCase::Sample>& samples, const deUint64 FlushFinishCase::Sample::*field)
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<Vec2> points(samples.size());
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (size_t ndx = 0; ndx < samples.size(); ndx++)
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		points[ndx] = Vec2(float(samples[ndx].numDrawCalls), float(samples[ndx].*field));
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return points;
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T>
3443c827367444ee418f129b2c238299f49d3264554Jarkko PoyryT getMaximumValue (const std::vector<FlushFinishCase::Sample>& samples, const T FlushFinishCase::Sample::*field)
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!samples.empty());
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	T maxVal = samples[0].*field;
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (size_t ndx = 1; ndx < samples.size(); ndx++)
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		maxVal = de::max(maxVal, samples[ndx].*field);
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return maxVal;
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlushFinishCase::analyzeResults (const std::vector<Sample>& samples, const CalibrationParams& calibrationParams)
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const vector<Vec2>		waitTimes		= getPointsFromSamples(samples, &Sample::waitTime);
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const vector<Vec2>		readTimes		= getPointsFromSamples(samples, &Sample::readPixelsTime);
3608852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParameters	waitLine		= theilSenLinearRegression(waitTimes);
3618852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParameters	readLine		= theilSenLinearRegression(readTimes);
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				normWaitCoef	= waitLine.coefficient * float(calibrationParams.maxDrawCalls) / float(MAX_SAMPLE_DURATION_US);
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				normReadCoef	= readLine.coefficient * float(calibrationParams.maxDrawCalls) / float(MAX_SAMPLE_DURATION_US);
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					allOk			= true;
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::ScopedLogSection	section			(m_testCtx.getLog(), "Samples", "Samples");
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vector<Sample>			sortedSamples	(samples.begin(), samples.end());
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::sort(sortedSamples.begin(), sortedSamples.end(), CompareSampleDrawCount());
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (vector<Sample>::const_iterator iter = sortedSamples.begin(); iter != sortedSamples.end(); ++iter)
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << *iter;
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << TestLog::Float("WaitCoefficient",				"Wait coefficient", "", QP_KEY_TAG_NONE, waitLine.coefficient)
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   << TestLog::Float("ReadCoefficient",				"Read coefficient", "", QP_KEY_TAG_NONE, readLine.coefficient)
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   << TestLog::Float("NormalizedWaitCoefficient",	"Normalized wait coefficient", "", QP_KEY_TAG_NONE, normWaitCoef)
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   << TestLog::Float("NormalizedReadCoefficient",	"Normalized read coefficient", "", QP_KEY_TAG_NONE, normReadCoef);
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool		waitCorrelated		= normWaitCoef > CORRELATED_COEF_THRESHOLD;
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool		readCorrelated		= normReadCoef > CORRELATED_COEF_THRESHOLD;
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool		waitNotCorr			= normWaitCoef < NO_CORR_COEF_THRESHOLD;
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool		readNotCorr			= normReadCoef < NO_CORR_COEF_THRESHOLD;
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (waitCorrelated || waitNotCorr)
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << TestLog::Message << "Wait time is" << (waitCorrelated ? "" : " NOT") << " correlated to rendering workload size." << TestLog::EndMessage;
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << TestLog::Message << "Warning: Wait time correlation to rendering workload size is unclear." << TestLog::EndMessage;
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (readCorrelated || readNotCorr)
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << TestLog::Message << "Read time is" << (readCorrelated ? "" : " NOT") << " correlated to rendering workload size." << TestLog::EndMessage;
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << TestLog::Message << "Warning: Read time correlation to rendering workload size is unclear." << TestLog::EndMessage;
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < 2; ndx++)
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float				coef		= ndx == 0 ? normWaitCoef : normReadCoef;
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*				name		= ndx == 0 ? "wait" : "read";
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const ExpectedBehavior	behavior	= ndx == 0 ? m_waitBehavior : m_readBehavior;
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float				threshold	= ndx == 0 ? m_waitThreshold : m_readThreshold;
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool				isOk		= behavior == EXPECT_COEF_GREATER_THAN	? coef > threshold :
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  behavior == EXPECT_COEF_LESS_THAN		? coef < threshold : false;
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*				cmpName		= behavior == EXPECT_COEF_GREATER_THAN	? "greater than" :
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  behavior == EXPECT_COEF_LESS_THAN		? "less than" : DE_NULL;
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!isOk)
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << TestLog::Message << "ERROR: Expected " << name << " coefficient to be " << cmpName << " " << threshold << TestLog::EndMessage;
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			allOk = false;
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(allOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							allOk ? "Pass"				: "Suspicious performance behavior");
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFlushFinishCase::IterateResult FlushFinishCase::iterate (void)
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<Sample>		samples		(NUM_SAMPLES);
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	CalibrationParams	params;
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4252995cc217d02c92dbca8fed6f55337b93d1a7506Pyry Haulos	tcu::warmupCPU();
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	setupRenderState();
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Do one full render cycle.
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		render(1);
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		readPixels();
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Calibrate.
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params = calibrate();
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (const CalibrationFailedException& e)
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, e.what());
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Do measurement.
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		de::Random	rnd		(123);
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (size_t ndx = 0; ndx < samples.size(); ndx++)
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int	drawCallCount	= rnd.getInt(1, params.maxDrawCalls);
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64	waitStartTime;
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64	readStartTime;
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64	readFinishTime;
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			render(drawCallCount);
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			waitStartTime = deGetMicroseconds();
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			waitForGL();
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			readStartTime = deGetMicroseconds();
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			readPixels();
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			readFinishTime = deGetMicroseconds();
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			samples[ndx].numDrawCalls	= drawCallCount;
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			samples[ndx].waitTime		= readStartTime-waitStartTime;
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			samples[ndx].readPixelsTime	= readFinishTime-readStartTime;
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_testCtx.getWatchDog())
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				qpWatchDog_touch(m_testCtx.getWatchDog());
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Analyze - sets test case result.
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	analyzeResults(samples, params);
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass WaitOnlyCase : public FlushFinishCase
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	WaitOnlyCase (Context& context)
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: FlushFinishCase(context, "wait", "Wait only", EXPECT_COEF_LESS_THAN, NO_CORR_COEF_THRESHOLD, EXPECT_COEF_GREATER_THAN, -1000.0f /* practically nothing is expected */)
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void init (void)
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << int(WAIT_TIME_MS) << " ms busy wait" << TestLog::EndMessage;
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FlushFinishCase::init();
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void waitForGL (void)
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		busyWait(WAIT_TIME_MS);
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FlushOnlyCase : public FlushFinishCase
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FlushOnlyCase (Context& context)
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: FlushFinishCase(context, "flush", "Flush only", EXPECT_COEF_LESS_THAN, FLUSH_COEF_THRESHOLD, EXPECT_COEF_GREATER_THAN, CORRELATED_COEF_THRESHOLD)
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void init (void)
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "Single call to glFlush()" << TestLog::EndMessage;
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FlushFinishCase::init();
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void waitForGL (void)
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().flush();
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FlushWaitCase : public FlushFinishCase
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FlushWaitCase (Context& context)
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: FlushFinishCase(context, "flush_wait", "Wait after flushing", EXPECT_COEF_LESS_THAN, FLUSH_COEF_THRESHOLD, EXPECT_COEF_LESS_THAN, NO_CORR_COEF_THRESHOLD)
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void init (void)
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "glFlush() followed by " << int(WAIT_TIME_MS) << " ms busy wait" << TestLog::EndMessage;
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FlushFinishCase::init();
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void waitForGL (void)
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().flush();
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		busyWait(WAIT_TIME_MS);
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FinishOnlyCase : public FlushFinishCase
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FinishOnlyCase (Context& context)
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: FlushFinishCase(context, "finish", "Finish only", EXPECT_COEF_GREATER_THAN, CORRELATED_COEF_THRESHOLD, EXPECT_COEF_LESS_THAN, NO_CORR_COEF_THRESHOLD)
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void init (void)
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "Single call to glFinish()" << TestLog::EndMessage;
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FlushFinishCase::init();
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void waitForGL (void)
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().finish();
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FinishWaitCase : public FlushFinishCase
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FinishWaitCase (Context& context)
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: FlushFinishCase(context, "finish_wait", "Finish and wait", EXPECT_COEF_GREATER_THAN, CORRELATED_COEF_THRESHOLD, EXPECT_COEF_LESS_THAN, NO_CORR_COEF_THRESHOLD)
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void init (void)
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "glFinish() followed by " << int(WAIT_TIME_MS) << " ms busy wait" << TestLog::EndMessage;
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FlushFinishCase::init();
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void waitForGL (void)
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().finish();
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		busyWait(WAIT_TIME_MS);
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFlushFinishTests::FlushFinishTests (Context& context)
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "flush_finish", "Flush and Finish tests")
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFlushFinishTests::~FlushFinishTests (void)
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FlushFinishTests::init (void)
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new WaitOnlyCase	(m_context));
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new FlushOnlyCase	(m_context));
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new FlushWaitCase	(m_context));
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new FinishOnlyCase	(m_context));
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new FinishWaitCase	(m_context));
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
611