13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.1 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 Multisample texture size tests
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es31fShaderTextureSizeTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluContextInfo.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuStringTemplate.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glw;
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles31
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* const s_positionVertexShaderSource =	"#version 310 es\n"
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														"in highp vec4 a_position;\n"
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														"void main (void)\n"
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														"{\n"
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														"	gl_Position = a_position;\n"
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														"}\n";
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureSizeCase : public TestCase
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum TextureType
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TEXTURE_FLOAT_2D = 0,
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TEXTURE_FLOAT_2D_ARRAY,
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TEXTURE_INT_2D,
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TEXTURE_INT_2D_ARRAY,
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TEXTURE_UINT_2D,
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TEXTURE_UINT_2D_ARRAY,
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TEXTURE_LAST
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							TextureSizeCase		(Context& context, const char* name, const char* desc, TextureType type, int samples);
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~TextureSizeCase	(void);
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init				(void);
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit				(void);
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate				(void);
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string				genFragmentSource	(void);
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLenum				getTextureGLTarget	(void);
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLenum				getTextureGLInternalFormat (void);
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					createTexture		(const tcu::IVec3& size);
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deleteTexture		(void);
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					runShader			(tcu::Surface& dst, const tcu::IVec3& size);
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					verifyImage			(const tcu::Surface& dst);
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const TextureType		m_type;
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_numSamples;
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool				m_isArrayType;
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLuint				m_texture;
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLuint				m_vbo;
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::ShaderProgram*		m_shader;
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<tcu::IVec3>	m_iterations;
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_iteration;
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					m_allIterationsPassed;
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					m_allCasesSkipped;
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1013c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureSizeCase::TextureSizeCase (Context& context, const char* name, const char* desc, TextureType type, int samples)
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase				(context, name, desc)
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_type				(type)
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numSamples			(samples)
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_isArrayType			(m_type == TEXTURE_FLOAT_2D_ARRAY || m_type == TEXTURE_INT_2D_ARRAY || m_type == TEXTURE_UINT_2D_ARRAY)
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_texture				(0)
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_vbo					(0)
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_shader				(DE_NULL)
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_iteration			(0)
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_allIterationsPassed	(true)
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_allCasesSkipped		(true)
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(type < TEXTURE_LAST);
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1163c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureSizeCase::~TextureSizeCase (void)
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureSizeCase::init (void)
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const tcu::IVec2 testSizes2D[] =
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec2(1,	1),
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec2(1,	4),
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec2(4,	8),
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec2(21,	11),
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec2(107,	254),
1308852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		tcu::IVec2(-1,	3),
1318852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		tcu::IVec2(3,	-1),
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const tcu::IVec3 testSizes3D[] =
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec3(1,	1,		1),
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec3(1,	4,		7),
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec3(4,	8,		12),
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec3(21,	11,		9),
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec3(107,	254,	2),
1408852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		tcu::IVec3(-1,	3,		3),
1418852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		tcu::IVec3(3,	-1,		3),
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::IVec3(4,	4,		-1),
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const tcu::Vec4 fullscreenQuad[] =
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(-1.0f,  1.0f, 0.0f, 1.0f),
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4( 1.0f,  1.0f, 0.0f, 1.0f),
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec4( 1.0f, -1.0f, 0.0f, 1.0f)
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl					= m_context.getRenderContext().getFunctions();
15326a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi
15426a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi	// requirements
15526a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi	if (m_isArrayType && !m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array"))
15626a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi		TCU_THROW(NotSupportedError, "Test requires OES_texture_storage_multisample_2d_array extension");
15726a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi
15826a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi	if (m_context.getRenderTarget().getWidth() < 1 || m_context.getRenderTarget().getHeight() < 1)
15926a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi		TCU_THROW(NotSupportedError, "rendertarget size must be at least 1x1");
16026a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLint				maxTextureSize		= 0;
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLint				maxTextureLayers	= 0;
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLint				maxSamples			= 0;
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxTextureLayers);
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.getInternalformativ(getTextureGLTarget(), getTextureGLInternalFormat(), GL_SAMPLES, 1, &maxSamples);
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_numSamples > maxSamples)
17026a744d584f1275414dd430c34086ca934993bc4Mika Isojärvi		TCU_THROW(NotSupportedError, "sample count is not supported");
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// gen shade
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_shader = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(s_positionVertexShaderSource) << glu::FragmentSource(genFragmentSource()));
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << *m_shader;
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_shader->isOk())
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::TestError("shader build failed");
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// gen buffer
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.genBuffers(1, &m_vbo);
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo);
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bufferData(GL_ARRAY_BUFFER, sizeof(fullscreenQuad), fullscreenQuad, GL_STATIC_DRAW);
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// gen iterations
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "GL_MAX_TEXTURE_SIZE = " << maxTextureSize << "\n"
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "GL_MAX_ARRAY_TEXTURE_LAYERS = " << maxTextureLayers
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_isArrayType)
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(testSizes2D); ++ndx)
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (testSizes2D[ndx].x() <= maxTextureSize && testSizes2D[ndx].y() <= maxTextureSize)
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int w = (testSizes2D[ndx].x() < 0) ? (maxTextureSize) : (testSizes2D[ndx].x());
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int h = (testSizes2D[ndx].y() < 0) ? (maxTextureSize) : (testSizes2D[ndx].y());
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_iterations.push_back(tcu::IVec3(w, h, 0));
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(testSizes3D); ++ndx)
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (testSizes3D[ndx].x() <= maxTextureSize && testSizes3D[ndx].y() <= maxTextureSize && testSizes3D[ndx].z() <= maxTextureLayers)
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int w = (testSizes3D[ndx].x() < 0) ? (maxTextureSize)		: (testSizes3D[ndx].x());
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int h = (testSizes3D[ndx].y() < 0) ? (maxTextureSize)		: (testSizes3D[ndx].y());
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int d = (testSizes3D[ndx].z() < 0) ? (maxTextureLayers)	: (testSizes3D[ndx].z());
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_iterations.push_back(tcu::IVec3(w, h, d));
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureSizeCase::deinit (void)
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_texture)
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteTextures(1, &m_texture);
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_texture = 0;
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_vbo)
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_vbo);
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_vbo = 0;
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_shader)
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		delete m_shader;
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_shader = DE_NULL;
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2433c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureSizeCase::IterateResult TextureSizeCase::iterate (void)
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface	result		(1, 1);
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			skipTest	= false;
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::Message << "\nIteration " << (m_iteration+1) << " / " << (int)m_iterations.size() << tcu::TestLog::EndMessage;
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// set texture size
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		createTexture(m_iterations[m_iteration]);
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// query texture size
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		runShader(result, m_iterations[m_iteration]);
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (glu::OutOfMemoryError&)
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Got GL_OUT_OF_MEMORY, skipping this size" << tcu::TestLog::EndMessage;
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		skipTest = true;
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// free resources
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deleteTexture();
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// queried value was correct?
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!skipTest)
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_allCasesSkipped = false;
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!verifyImage(result))
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_allIterationsPassed = false;
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// final result
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (++m_iteration < (int)m_iterations.size())
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_allIterationsPassed)
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "One or more test sizes failed." << tcu::TestLog::EndMessage;
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid texture size");
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_allCasesSkipped)
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Could not test any texture size, texture creation failed." << tcu::TestLog::EndMessage;
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "All test texture creations failed");
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "All texture sizes passed." << tcu::TestLog::EndMessage;
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::string TextureSizeCase::genFragmentSource (void)
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* const templateSource =	"#version 310 es\n"
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"${EXTENSION_STATEMENT}"
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"layout(location = 0) out highp vec4 fragColor;\n"
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"uniform highp ${SAMPLERTYPE} u_sampler;\n"
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"uniform highp ${SIZETYPE} u_size;\n"
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"void main (void)\n"
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"{\n"
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"	const highp vec4 okColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"	const highp vec4 failColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"	fragColor = (textureSize(u_sampler) == u_size) ? (okColor) : (failColor);\n"
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												"}\n";
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::map<std::string, std::string> args;
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_type)
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_FLOAT_2D:			args["SAMPLERTYPE"] = "sampler2DMS";		break;
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_FLOAT_2D_ARRAY:	args["SAMPLERTYPE"] = "sampler2DMSArray";	break;
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_INT_2D:			args["SAMPLERTYPE"] = "isampler2DMS";		break;
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_INT_2D_ARRAY:		args["SAMPLERTYPE"] = "isampler2DMSArray";	break;
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_UINT_2D:			args["SAMPLERTYPE"] = "usampler2DMS";		break;
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_UINT_2D_ARRAY:		args["SAMPLERTYPE"] = "usampler2DMSArray";	break;
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_isArrayType)
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		args["SIZETYPE"] = "ivec2";
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		args["SIZETYPE"] = "ivec3";
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_isArrayType)
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		args["EXTENSION_STATEMENT"] = "#extension GL_OES_texture_storage_multisample_2d_array : require\n";
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		args["EXTENSION_STATEMENT"] = "";
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::StringTemplate(templateSource).specialize(args);
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryglw::GLenum TextureSizeCase::getTextureGLTarget (void)
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_type)
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_FLOAT_2D:			return GL_TEXTURE_2D_MULTISAMPLE;
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_FLOAT_2D_ARRAY:	return GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_INT_2D:			return GL_TEXTURE_2D_MULTISAMPLE;
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_INT_2D_ARRAY:		return GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_UINT_2D:			return GL_TEXTURE_2D_MULTISAMPLE;
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_UINT_2D_ARRAY:		return GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 0;
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryglw::GLenum TextureSizeCase::getTextureGLInternalFormat (void)
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (m_type)
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_FLOAT_2D:			return GL_RGBA8;
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_FLOAT_2D_ARRAY:	return GL_RGBA8;
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_INT_2D:			return GL_R8I;
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_INT_2D_ARRAY:		return GL_R8I;
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_UINT_2D:			return GL_R8UI;
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case TEXTURE_UINT_2D_ARRAY:		return GL_R8UI;
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(DE_FALSE);
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 0;
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureSizeCase::createTexture (const tcu::IVec3& size)
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_isArrayType)
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Creating texture with size " << size.x() << "x" << size.y() << tcu::TestLog::EndMessage;
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Creating texture with size " << size.x() << "x" << size.y() << "x" << size.z() << tcu::TestLog::EndMessage;
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.genTextures(1, &m_texture);
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindTexture(getTextureGLTarget(), m_texture);
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "texture gen");
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_isArrayType)
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.texStorage2DMultisample(getTextureGLTarget(), m_numSamples, getTextureGLInternalFormat(), size.x(), size.y(), GL_FALSE);
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.texStorage3DMultisample(getTextureGLTarget(), m_numSamples, getTextureGLInternalFormat(), size.x(), size.y(), size.z(), GL_FALSE);
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "texStorage");
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureSizeCase::deleteTexture (void)
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_texture)
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.deleteTextures(1, &m_texture);
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_texture = 0;
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "texture delete");
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureSizeCase::runShader (tcu::Surface& dst, const tcu::IVec3& size)
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl					= m_context.getRenderContext().getFunctions();
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				positionLoc			= gl.getAttribLocation(m_shader->getProgram(), "a_position");
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				shaderSamplerLoc	= gl.getUniformLocation(m_shader->getProgram(), "u_sampler");
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				shaderSizeLoc		= gl.getUniformLocation(m_shader->getProgram(), "u_size");
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::Message << "Running the verification shader." << tcu::TestLog::EndMessage;
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "preclear");
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.viewport(0, 0, 1, 1);
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "clear");
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo);
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enableVertexAttribArray(positionLoc);
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "vertexAttrib");
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(m_shader->getProgram());
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform1i(shaderSamplerLoc, 0);
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_isArrayType)
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform3iv(shaderSizeLoc, 1, size.getPtr());
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.uniform2iv(shaderSizeLoc, 1, size.getPtr());
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "setup program");
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindTexture(getTextureGLTarget(), m_texture);
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "bindtex");
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "drawArrays");
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.disableVertexAttribArray(positionLoc);
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(0);
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "cleanup");
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.finish();
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), 0, 0, dst.getAccess());
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "readPixels");
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool TextureSizeCase::verifyImage (const tcu::Surface& dst)
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(dst.getWidth() == 1 && dst.getHeight() == 1);
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		colorThresholdRed	= 1 << (8 - m_context.getRenderTarget().getPixelFormat().redBits);
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		colorThresholdGreen	= 1 << (8 - m_context.getRenderTarget().getPixelFormat().greenBits);
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		colorThresholdBlue	= 1 << (8 - m_context.getRenderTarget().getPixelFormat().blueBits);
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::RGBA	color				= dst.getPixel(0,0);
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::Message << "Verifying image." << tcu::TestLog::EndMessage;
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// green
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (color.getRed() < colorThresholdRed && color.getGreen() > 255 - colorThresholdGreen && color.getBlue() < colorThresholdBlue)
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Result ok." << tcu::TestLog::EndMessage;
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// red
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (color.getRed() > 255 - colorThresholdRed && color.getGreen() < colorThresholdGreen && color.getBlue() < colorThresholdBlue)
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Image size incorrect." << tcu::TestLog::EndMessage;
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::Message << "Expected either green or red pixel, got " << color << tcu::TestLog::EndMessage;
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4843c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderTextureSizeTests::ShaderTextureSizeTests (Context& context)
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "texture_size", "Texture size tests")
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4893c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderTextureSizeTests::~ShaderTextureSizeTests (void)
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderTextureSizeTests::init (void)
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct SamplerType
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TextureSizeCase::TextureType	type;
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*						name;
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} samplerTypes[] =
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ TextureSizeCase::TEXTURE_FLOAT_2D,		"texture_2d"			},
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ TextureSizeCase::TEXTURE_FLOAT_2D_ARRAY,	"texture_2d_array"		},
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ TextureSizeCase::TEXTURE_INT_2D,			"texture_int_2d"		},
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ TextureSizeCase::TEXTURE_INT_2D_ARRAY,	"texture_int_2d_array"	},
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ TextureSizeCase::TEXTURE_UINT_2D,			"texture_uint_2d"		},
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ TextureSizeCase::TEXTURE_UINT_2D_ARRAY,	"texture_uint_2d_array"	},
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const int sampleCounts[] = { 1, 4 };
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int samplerTypeNdx = 0; samplerTypeNdx < DE_LENGTH_OF_ARRAY(samplerTypes); ++samplerTypeNdx)
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int sampleCountNdx = 0; sampleCountNdx < DE_LENGTH_OF_ARRAY(sampleCounts); ++sampleCountNdx)
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const std::string name = std::string() + "samples_" + de::toString(sampleCounts[sampleCountNdx]) + "_" + samplerTypes[samplerTypeNdx].name;
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const std::string desc = std::string() + "samples count = " + de::toString(sampleCounts[sampleCountNdx]) + ", type = " + samplerTypes[samplerTypeNdx].name;
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			addChild(new TextureSizeCase(m_context, name.c_str(), desc.c_str(), samplerTypes[samplerTypeNdx].type, sampleCounts[sampleCountNdx]));
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles31
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
526