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 Texture upload performance tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \todo [2012-10-01 pyry]
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *  - Test different pixel unpack alignments
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *  - Use multiple textures
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *  - Trash cache prior to uploading from data ptr
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2pTextureUploadTests.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deClock.h"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsCalibration.hpp"
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm>
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector>
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Performance
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3;
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec4;
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TextureFormat;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glw; // GL types
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int	VIEWPORT_SIZE	= 64;
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const float	quadCoords[] =
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	-1.0f, -1.0f,
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	 1.0f, -1.0f,
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	-1.0f,  1.0f,
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	 1.0f,  1.0f
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureUploadCase : public TestCase
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TextureUploadCase	(Context& context, const char* name, const char* description, UploadFunction uploadFunction, deUint32 format, deUint32 type, int texSize);
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								~TextureUploadCase	(void);
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void				init				(void);
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						deinit				(void);
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual IterateResult		iterate				(void) = 0;
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						logResults			(void);
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UploadFunction				m_uploadFunction;
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_format;
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_type;
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							m_texSize;
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int							m_alignment;
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::TheilSenCalibrator		m_calibrator;
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::ShaderProgram*			m_program;
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32					m_texture;
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random					m_rnd;
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&					m_log;
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<deUint8>				m_texData;
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureUploadCase::TextureUploadCase (Context& context, const char* name, const char* description, UploadFunction uploadFunction, deUint32 format, deUint32 type, int texSize)
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(context, tcu::NODETYPE_PERFORMANCE, name, description)
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_uploadFunction	(uploadFunction)
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_format			(format)
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_type			(type)
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texSize			(texSize)
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_alignment		(4)
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_calibrator		()
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_program			(DE_NULL)
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texture			(0)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_rnd				(deStringHash(name))
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_log				(context.getTestContext().getLog())
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1193c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureUploadCase::~TextureUploadCase (void)
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureUploadCase::deinit();
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureUploadCase::deinit (void)
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_program)
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		delete m_program;
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_program = DE_NULL;
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.deleteTextures(1, &m_texture);
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texture = 0;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_texData.clear();
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureUploadCase::init (void)
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int maxTextureSize;
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_texSize > maxTextureSize)
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Unsupported texture size");
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return;
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create program
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string vertexShaderSource = "";
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string fragmentShaderSource = "";
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vertexShaderSource.append(	"precision mediump	float;\n"
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"attribute vec2		a_pos;\n"
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"varying   vec2		v_texCoord;\n"
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"\n"
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"void main (void)\n"
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"{\n"
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	v_texCoord	= a_pos;\n"
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	gl_Position = vec4(a_pos, 0.5, 1.0);\n"
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"}\n");
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	fragmentShaderSource.append("precision	mediump	float;\n"
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"uniform	lowp sampler2D	u_sampler;\n"
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"varying	vec2			v_texCoord;\n"
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"\n"
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"void main (void)\n"
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"{\n"
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"	gl_FragColor = texture2D(u_sampler, v_texCoord.xy);\n"
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								"}\n");
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_program);
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_program = new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_program->isOk())
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_log << *m_program;
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_FAIL("Failed to create shader program (m_programRender)");
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram (m_program->getProgram());
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Init GL state
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.viewport		(0, 0, VIEWPORT_SIZE, VIEWPORT_SIZE);
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.disable		(GL_DEPTH_TEST);
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.disable		(GL_CULL_FACE);
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enable		(GL_BLEND);
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.blendFunc	(GL_ONE, GL_ONE);
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor	(0.0f, 0.0f, 0.0f, 1.0f);
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear		(GL_COLOR_BUFFER_BIT);
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 uSampler	= gl.getUniformLocation(m_program->getProgram(), "u_sampler");
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 aPos		= gl.getAttribLocation (m_program->getProgram(), "a_pos");
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enableVertexAttribArray	(aPos);
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.vertexAttribPointer		(aPos,	2, GL_FLOAT, GL_FALSE, 0, &quadCoords[0]);
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform1i				(uSampler, 0);
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create texture
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.activeTexture	(GL_TEXTURE0);
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.genTextures		(1, &m_texture);
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindTexture		(GL_TEXTURE_2D, m_texture);
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.pixelStorei		(GL_UNPACK_ALIGNMENT, m_alignment);
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Prepare texture data
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::TextureFormat&	texFmt		= glu::mapGLTransferFormat(m_format, m_type);
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int							pixelSize	= texFmt.getPixelSize();
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int							stride		= deAlign32(pixelSize*m_texSize, m_alignment);
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_texData.resize(stride*m_texSize);
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::PixelBufferAccess		access		(texFmt, m_texSize, m_texSize, 1, stride, 0, &m_texData[0]);
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::fillWithComponentGradients(access, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Do a dry-run to ensure the pipes are hot
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.texImage2D	(GL_TEXTURE_2D, 0, m_format, m_texSize, m_texSize, 0, m_format, m_type, &m_texData[0]);
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays	(GL_TRIANGLE_STRIP, 0, 4);
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.finish		();
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureUploadCase::logResults (void)
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const gls::MeasureState& measureState = m_calibrator.getMeasureState();
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log measurement details
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Section("Measurement details", "Measurement details");
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message << "Uploading texture with " << (m_uploadFunction == UPLOAD_TEXIMAGE2D ? "glTexImage2D" : "glTexSubImage2D") << "." << TestLog::EndMessage; // \todo [arttu] Change enum to struct with name included
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message << "Texture size = "	<< m_texSize	 << "x" << m_texSize	 << "." << TestLog::EndMessage;
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message << "Viewport size = " << VIEWPORT_SIZE << "x" << VIEWPORT_SIZE << "." << TestLog::EndMessage;
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::Message << measureState.numDrawCalls << " upload calls / iteration" << TestLog::EndMessage;
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_log << TestLog::EndSection;
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log results
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog& log = m_testCtx.getLog();
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Section("Results", "Results");
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log individual frame durations
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//for (int i = 0; i < m_calibrator.measureState.numFrames; i++)
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	//	m_log << TestLog::Message	<< "Frame "	<< i+1 << " duration: \t" << m_calibrator.measureState.frameTimes[i] << " us."<< TestLog::EndMessage;
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint64> sortedFrameTimes(measureState.frameTimes.begin(), measureState.frameTimes.end());
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::sort(sortedFrameTimes.begin(), sortedFrameTimes.end());
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<deUint64>::const_iterator first	= sortedFrameTimes.begin();
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<deUint64>::const_iterator last	= sortedFrameTimes.end();
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<deUint64>::const_iterator middle	= first + (last - first) / 2;
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 medianFrameTime			=  *middle;
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	double medianMTexelsPerSeconds		= (double)(m_texSize*m_texSize*measureState.numDrawCalls) / medianFrameTime;
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	double medianTexelDrawDurationNs	= (double)medianFrameTime * 1000.0 / (double)(m_texSize*m_texSize*measureState.numDrawCalls);
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64	totalTime			= measureState.getTotalTime();
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			numFrames			= (int)measureState.frameTimes.size();
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deInt64		numTexturesDrawn	= measureState.numDrawCalls * numFrames;
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deInt64		numPixels			= (deInt64)m_texSize * (deInt64)m_texSize * numTexturesDrawn;
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	double		framesPerSecond			= (double)numFrames / ((double)totalTime / 1000000.0);
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	double		avgFrameTime			= (double)totalTime / (double)numFrames;
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	double		avgMTexelsPerSeconds	= (double)numPixels / (double)totalTime;
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	double		avgTexelDrawDurationNs	= (double)totalTime * 1000.0 / (double)numPixels;
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Float("FramesPerSecond",	"Frames per second in measurement\t\t",		"Frames/s",		QP_KEY_TAG_PERFORMANCE,	(float)framesPerSecond);
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Float("AverageFrameTime",	"Average frame duration in measurement\t",	"us",			QP_KEY_TAG_PERFORMANCE,	(float)avgFrameTime);
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Float("AverageTexelPerf",	"Average texel upload performance\t\t",		"MTex/s",		QP_KEY_TAG_PERFORMANCE,	(float)avgMTexelsPerSeconds);
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Float("AverageTexelTime",	"Average texel upload duration\t\t",		"ns",			QP_KEY_TAG_PERFORMANCE,	(float)avgTexelDrawDurationNs);
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Float("MedianTexelPerf",	"Median texel upload performance\t\t",		"MTex/s",		QP_KEY_TAG_PERFORMANCE,	(float)medianMTexelsPerSeconds);
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::Float("MedianTexelTime",	"Median texel upload duration\t\t",			"ns",			QP_KEY_TAG_PERFORMANCE,	(float)medianTexelDrawDurationNs);
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << TestLog::EndSection;
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::logCalibrationInfo(log, m_calibrator);	// Log calibration details
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString((float)avgMTexelsPerSeconds, 2).c_str());
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture upload call case
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureUploadCallCase : public TextureUploadCase
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							TextureUploadCallCase	(Context& context, const char* name, const char* description, UploadFunction uploadFunction, deUint32 format, deUint32 type, int texSize);
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~TextureUploadCallCase	(void);
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate					(void);
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					render					(void);
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3023c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureUploadCallCase::TextureUploadCallCase (Context& context, const char* name, const char* description, UploadFunction uploadFunction, deUint32 format, deUint32 type, int texSize)
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TextureUploadCase (context, name, description, uploadFunction, format, type, texSize)
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureUploadCallCase::~TextureUploadCallCase (void)
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureUploadCase::deinit();
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureUploadCallCase::render (void)
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw multiple quads to ensure enough workload
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_uploadFunction)
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case UPLOAD_TEXIMAGE2D:
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.texImage2D(GL_TEXTURE_2D, 0, m_format, m_texSize, m_texSize, 0, m_format, m_type, &m_texData[0]);
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case UPLOAD_TEXSUBIMAGE2D:
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_texSize, m_texSize, m_format, m_type, &m_texData[0]);
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestNode::IterateResult TextureUploadCallCase::iterate (void)
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_testCtx.getTestResult() == QP_TEST_RESULT_NOT_SUPPORTED)
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (;;)
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gls::TheilSenCalibrator::State state = m_calibrator.getState();
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (state == gls::TheilSenCalibrator::STATE_MEASURE)
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int			numCalls	= m_calibrator.getCallCount();
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64	startTime	= deGetMicroseconds();
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int i = 0; i < numCalls; i++)
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				render();
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.finish();
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64	endTime		= deGetMicroseconds();
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64	duration	= endTime-startTime;
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_calibrator.recordIteration(duration);
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (state == gls::TheilSenCalibrator::STATE_RECOMPUTE_PARAMS)
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_calibrator.recomputeParameters();
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(state == gls::TheilSenCalibrator::STATE_FINISHED);
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Touch watchdog between iterations to avoid timeout.
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			qpWatchDog* dog = m_testCtx.getWatchDog();
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (dog)
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				qpWatchDog_touch(dog);
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "iterate");
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	logResults();
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture upload and draw case
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureUploadAndDrawCase : public TextureUploadCase
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								TextureUploadAndDrawCase	(Context& context, const char* name, const char* description, UploadFunction uploadFunction, deUint32 format, deUint32 type, int texSize);
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								~TextureUploadAndDrawCase	(void);
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult				iterate						(void);
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						render						(void);
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool						m_lastIterationRender;
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64					m_renderStart;
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3963c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureUploadAndDrawCase::TextureUploadAndDrawCase (Context& context, const char* name, const char* description, UploadFunction uploadFunction, deUint32 format, deUint32 type, int texSize)
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TextureUploadCase		(context, name, description, uploadFunction, format, type, texSize)
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_lastIterationRender	(false)
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderStart			(0)
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4033c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureUploadAndDrawCase::~TextureUploadAndDrawCase (void)
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureUploadCase::deinit();
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureUploadAndDrawCase::render (void)
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Draw multiple quads to ensure enough workload
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_uploadFunction)
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case UPLOAD_TEXIMAGE2D:
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.texImage2D(GL_TEXTURE_2D, 0, m_format, m_texSize, m_texSize, 0, m_format, m_type, &m_texData[0]);
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case UPLOAD_TEXSUBIMAGE2D:
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_texSize, m_texSize, m_format, m_type, &m_texData[0]);
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestNode::IterateResult TextureUploadAndDrawCase::iterate (void)
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_testCtx.getTestResult() == QP_TEST_RESULT_NOT_SUPPORTED)
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_lastIterationRender && (m_calibrator.getState() == gls::TheilSenCalibrator::STATE_MEASURE))
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 curTime = deGetMicroseconds();
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_calibrator.recordIteration(curTime - m_renderStart);
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gls::TheilSenCalibrator::State state = m_calibrator.getState();
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (state == gls::TheilSenCalibrator::STATE_MEASURE)
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Render
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int	numCalls = m_calibrator.getCallCount();
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_renderStart			= deGetMicroseconds();
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_lastIterationRender	= true;
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int i = 0; i < numCalls; i++)
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			render();
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (state == gls::TheilSenCalibrator::STATE_RECOMPUTE_PARAMS)
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_calibrator.recomputeParameters();
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_lastIterationRender = false;
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(state == gls::TheilSenCalibrator::STATE_FINISHED);
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(m_context.getRenderContext().getFunctions().getError(), "finish");
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logResults();
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture upload tests
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4723c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureUploadTests::TextureUploadTests (Context& context)
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "upload", "Texture upload tests")
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4773c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureUploadTests::~TextureUploadTests (void)
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureUploadTests::deinit();
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureUploadTests::deinit (void)
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureUploadTests::init (void)
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestCaseGroup* uploadCall		= new TestCaseGroup(m_context, "upload",			"Texture upload");
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestCaseGroup* uploadAndDraw	= new TestCaseGroup(m_context, "upload_draw_swap",	"Texture upload, draw & buffer swap");
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(uploadCall);
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(uploadAndDraw);
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		nameLower;
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		UploadFunction	func;
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} uploadFunctions[] =
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "texImage2D",		"teximage2d",		UPLOAD_TEXIMAGE2D },
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "texSubImage2D",	"texsubimage2d",	UPLOAD_TEXSUBIMAGE2D }
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	name;
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	format;
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	type;
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} textureCombinations[] =
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgb_ubyte",				GL_RGB,				GL_UNSIGNED_BYTE },
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgba_ubyte",				GL_RGBA,			GL_UNSIGNED_BYTE },
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "alpha_ubyte",			GL_ALPHA,			GL_UNSIGNED_BYTE },
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "luminance_ubyte",		GL_LUMINANCE,		GL_UNSIGNED_BYTE },
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "luminance-alpha_ubyte",	GL_LUMINANCE_ALPHA,	GL_UNSIGNED_BYTE },
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgb_ushort565",			GL_RGB,				GL_UNSIGNED_SHORT_5_6_5 },
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgba_ushort4444",		GL_RGBA,			GL_UNSIGNED_SHORT_4_4_4_4 },
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgba_ushort5551",		GL_RGBA,			GL_UNSIGNED_SHORT_5_5_5_1 },
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				size;
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup*	uploadCallGroup;
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestCaseGroup*	uploadAndDrawGroup;
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} textureSizes[] =
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ 16,	new TestCaseGroup(m_context, "16x16",		"Texture size 16x16"),		new TestCaseGroup(m_context, "16x16",		"Texture size 16x16") },
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ 256,	new TestCaseGroup(m_context, "256x256",		"Texture size 256x256"),	new TestCaseGroup(m_context, "256x256",		"Texture size 256x256") },
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ 257,	new TestCaseGroup(m_context, "257x257",		"Texture size 257x257"),	new TestCaseGroup(m_context, "257x257",		"Texture size 257x257") },
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ 1024,	new TestCaseGroup(m_context, "1024x1024",	"Texture size 1024x1024"),	new TestCaseGroup(m_context, "1024x1024",	"Texture size 1024x1024") },
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ 2048,	new TestCaseGroup(m_context, "2048x2048",	"Texture size 2048x2048"),	new TestCaseGroup(m_context, "2048x2048",	"Texture size 2048x2048") },
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define FOR_EACH(ITERATOR, ARRAY, BODY)	\
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ITERATOR = 0; ITERATOR < DE_LENGTH_OF_ARRAY(ARRAY); ITERATOR++)	\
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		BODY
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(uploadFunc,	 uploadFunctions,
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(texSize,		 textureSizes,
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FOR_EACH(texCombination, textureCombinations,
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		string			caseName	= string("") + uploadFunctions[uploadFunc].nameLower + "_" + textureCombinations[texCombination].name;
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		UploadFunction	function	= uploadFunctions[uploadFunc].func;
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		format		= textureCombinations[texCombination].format;
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		type		= textureCombinations[texCombination].type;
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				size		= textureSizes[texSize].size;
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		textureSizes[texSize].uploadCallGroup->addChild		(new TextureUploadCallCase		(m_context, caseName.c_str(), "", function, format, type, size));
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		textureSizes[texSize].uploadAndDrawGroup->addChild	(new TextureUploadAndDrawCase	(m_context, caseName.c_str(), "", function, format, type, size));
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	})));
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < DE_LENGTH_OF_ARRAY(textureSizes); i++)
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		uploadCall->addChild	(textureSizes[i].uploadCallGroup);
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		uploadAndDraw->addChild	(textureSizes[i].uploadAndDrawGroup);
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Performance
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
565