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 Compute Shader Built-in variable tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es31fComputeShaderBuiltinVarTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderUtil.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluObjectWrapper.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluProgramInterfaceQuery.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVectorUtil.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deSharedPtr.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <map>
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles31
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::map;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::UVec3;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec3;
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glu;
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct LexicalCompareVec
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	inline bool operator() (const tcu::Vector<T, Size>& a, const tcu::Vector<T, Size>& b) const
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < Size; ndx++)
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (a[ndx] < b[ndx])
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				return true;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (a[ndx] > b[ndx])
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				return false;
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef de::SharedPtr<glu::ShaderProgram>										ShaderProgramSp;
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef std::map<tcu::UVec3, ShaderProgramSp, LexicalCompareVec<deUint32, 3> >	LocalSizeProgramMap;
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ComputeBuiltinVarCase : public TestCase
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							ComputeBuiltinVarCase	(Context& context, const char* name, const char* varName, DataType varType);
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~ComputeBuiltinVarCase	(void);
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init					(void);
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit					(void);
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate					(void);
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual UVec3			computeReference		(const UVec3& numWorkGroups, const UVec3& workGroupSize, const UVec3& workGroupID, const UVec3& localInvocationID) const = 0;
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	struct SubCase
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		UVec3		localSize;
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		UVec3		numWorkGroups;
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SubCase (void) {}
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SubCase (const UVec3& localSize_, const UVec3& numWorkGroups_) : localSize(localSize_), numWorkGroups(numWorkGroups_) {}
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<SubCase>			m_subCases;
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							ComputeBuiltinVarCase	(const ComputeBuiltinVarCase& other);
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ComputeBuiltinVarCase&	operator=				(const ComputeBuiltinVarCase& other);
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				getProgram				(const UVec3& localSize);
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const string			m_varName;
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const DataType			m_varType;
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	LocalSizeProgramMap		m_progMap;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_subCaseNdx;
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeBuiltinVarCase::ComputeBuiltinVarCase (Context& context, const char* name, const char* varName, DataType varType)
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase		(context, name, varName)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_varName		(varName)
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_varType		(varType)
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_subCaseNdx	(0)
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeBuiltinVarCase::~ComputeBuiltinVarCase (void)
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ComputeBuiltinVarCase::deinit();
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeBuiltinVarCase::init (void)
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_subCaseNdx = 0;
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeBuiltinVarCase::deinit (void)
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_progMap.clear();
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic string genBuiltinVarSource (const string& varName, DataType varType, const UVec3& localSize)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostringstream src;
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	src << "#version 310 es\n"
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "layout (local_size_x = " << localSize.x() << ", local_size_y = " << localSize.y() << ", local_size_z = " << localSize.z() << ") in;\n"
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "uniform highp uvec2 u_stride;\n"
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "layout(binding = 0) buffer Output\n"
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "{\n"
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "	" << glu::getDataTypeName(varType) << " result[];\n"
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "} sb_out;\n"
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "\n"
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "void main (void)\n"
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "{\n"
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "	highp uint offset = u_stride.x*gl_GlobalInvocationID.z + u_stride.y*gl_GlobalInvocationID.y + gl_GlobalInvocationID.x;\n"
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "	sb_out.result[offset] = " << varName << ";\n"
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "}\n";
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return src.str();
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1573c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint32 ComputeBuiltinVarCase::getProgram (const UVec3& localSize)
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	LocalSizeProgramMap::const_iterator cachePos = m_progMap.find(localSize);
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (cachePos != m_progMap.end())
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return cachePos->second->getProgram();
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ShaderProgramSp program(new ShaderProgram(m_context.getRenderContext(),
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												  ProgramSources() << ComputeSource(genBuiltinVarSource(m_varName, m_varType, localSize))));
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Log all compiled programs.
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << *program;
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!program->isOk())
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::TestError("Compile failed");
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_progMap[localSize] = program;
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return program->getProgram();
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline UVec3 readResultVec (const deUint32* ptr, int numComps)
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UVec3 res;
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < numComps; ndx++)
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[ndx] = ptr[ndx];
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool compareComps (const UVec3& a, const UVec3& b, int numComps)
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(numComps == 1 || numComps == 3);
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return numComps == 3 ? tcu::allEqual(a, b) : a.x() == b.x();
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct LogComps
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UVec3&	v;
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				numComps;
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	LogComps (const UVec3& v_, int numComps_) : v(v_), numComps(numComps_) {}
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline std::ostream& operator<< (std::ostream& str, const LogComps& c)
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(c.numComps == 1 || c.numComps == 3);
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return c.numComps == 3 ? str << c.v : str << c.v.x();
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2053c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeBuiltinVarCase::IterateResult ComputeBuiltinVarCase::iterate (void)
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::ScopedLogSection		section			(m_testCtx.getLog(), string("Iteration") + de::toString(m_subCaseNdx), string("Iteration ") + de::toString(m_subCaseNdx));
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&			gl				= m_context.getRenderContext().getFunctions();
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const SubCase&					subCase			= m_subCases[m_subCaseNdx];
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32					program			= getProgram(subCase.localSize);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::UVec3				globalSize		= subCase.localSize*subCase.numWorkGroups;
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::UVec2				stride			(globalSize[0]*globalSize[1], globalSize[0]);
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32					numInvocations	= subCase.localSize[0]*subCase.localSize[1]*subCase.localSize[2]*subCase.numWorkGroups[0]*subCase.numWorkGroups[1]*subCase.numWorkGroups[2];
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32					outVarIndex		= gl.getProgramResourceIndex(program, GL_BUFFER_VARIABLE, "Output.result");
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const InterfaceVariableInfo		outVarInfo		= getProgramInterfaceVariableInfo(gl, program, GL_BUFFER_VARIABLE, outVarIndex);
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32					bufferSize		= numInvocations*outVarInfo.arrayStride;
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Buffer							outputBuffer	(m_context.getRenderContext());
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK(outVarInfo.arraySize == 0); // Unsized variable.
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << TestLog::Message << "Number of work groups = " << subCase.numWorkGroups << TestLog::EndMessage
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					   << TestLog::Message << "Work group size = " << subCase.localSize << TestLog::EndMessage;
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_SHADER_STORAGE_BUFFER, *outputBuffer);
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bufferData(GL_SHADER_STORAGE_BUFFER, (glw::GLsizeiptr)bufferSize, DE_NULL, GL_STREAM_READ);
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, *outputBuffer);
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer setup failed");
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(program);
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.uniform2uiv(gl.getUniformLocation(program, "u_stride"), 1, stride.getPtr());
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Program setup failed");
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.dispatchCompute(subCase.numWorkGroups[0], subCase.numWorkGroups[1], subCase.numWorkGroups[2]);
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "glDispatchCompute() failed");
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const void*	ptr				= gl.mapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, bufferSize, GL_MAP_READ_BIT);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			numFailed		= 0;
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	numScalars		= getDataTypeScalarSize(m_varType);
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	maxLogPrints	= 10;
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange() failed");
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(ptr);
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (deUint32 groupZ = 0; groupZ < subCase.numWorkGroups.z(); groupZ++)
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (deUint32 groupY = 0; groupY < subCase.numWorkGroups.y(); groupY++)
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (deUint32 groupX = 0; groupX < subCase.numWorkGroups.x(); groupX++)
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (deUint32 localZ = 0; localZ < subCase.localSize.z(); localZ++)
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (deUint32 localY = 0; localY < subCase.localSize.y(); localY++)
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (deUint32 localX = 0; localX < subCase.localSize.x(); localX++)
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const UVec3			refGroupID		(groupX, groupY, groupZ);
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const UVec3			refLocalID		(localX, localY, localZ);
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const UVec3			refGlobalID		= refGroupID * subCase.localSize + refLocalID;
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const deUint32		refOffset		= stride.x()*refGlobalID.z() + stride.y()*refGlobalID.y() + refGlobalID.x();
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const UVec3			refValue		= computeReference(subCase.numWorkGroups, subCase.localSize, refGroupID, refLocalID);
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const deUint32*		resPtr			= (const deUint32*)((const deUint8*)ptr + refOffset*outVarInfo.arrayStride);
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const UVec3			resValue		= readResultVec(resPtr, numScalars);
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!compareComps(refValue, resValue, numScalars))
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (numFailed < maxLogPrints)
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_testCtx.getLog() << TestLog::Message << "ERROR: comparison failed at offset " << refOffset
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   << ": expected " << LogComps(refValue, numScalars)
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														   << ", got " << LogComps(resValue, numScalars)
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									   << TestLog::EndMessage;
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else if (numFailed == maxLogPrints)
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_testCtx.getLog() << TestLog::Message << "..." << TestLog::EndMessage;
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				numFailed += 1;
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << (numInvocations-numFailed) << " / " << numInvocations << " values passed" << TestLog::EndMessage;
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (numFailed > 0)
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Comparison failed");
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.unmapBuffer(GL_SHADER_STORAGE_BUFFER);
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_subCaseNdx += 1;
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (m_subCaseNdx < (int)m_subCases.size() && m_testCtx.getTestResult() == QP_TEST_RESULT_PASS) ? CONTINUE : STOP;
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Test cases
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass NumWorkGroupsCase : public ComputeBuiltinVarCase
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NumWorkGroupsCase (Context& context)
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ComputeBuiltinVarCase(context, "num_work_groups", "gl_NumWorkGroups", TYPE_UINT_VEC3)
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,1)));
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(52,1,1)));
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,39,1)));
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,78)));
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(4,7,11)));
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(2,3,4), UVec3(4,7,11)));
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UVec3 computeReference (const UVec3& numWorkGroups, const UVec3& workGroupSize, const UVec3& workGroupID, const UVec3& localInvocationID) const
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(numWorkGroups);
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(workGroupSize);
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(workGroupID);
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(localInvocationID);
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return numWorkGroups;
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass WorkGroupSizeCase : public ComputeBuiltinVarCase
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	WorkGroupSizeCase (Context& context)
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ComputeBuiltinVarCase(context, "work_group_size", "gl_WorkGroupSize", TYPE_UINT_VEC3)
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,1)));
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(2,7,3)));
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(2,1,1), UVec3(1,1,1)));
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(2,1,1), UVec3(1,3,5)));
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,3,1), UVec3(1,1,1)));
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,7), UVec3(1,1,1)));
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,7), UVec3(3,3,1)));
3288852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(10,3,4), UVec3(1,1,1)));
3298852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(10,3,4), UVec3(3,1,2)));
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UVec3 computeReference (const UVec3& numWorkGroups, const UVec3& workGroupSize, const UVec3& workGroupID, const UVec3& localInvocationID) const
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(numWorkGroups);
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(workGroupID);
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(localInvocationID);
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return workGroupSize;
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass WorkGroupIDCase : public ComputeBuiltinVarCase
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	WorkGroupIDCase (Context& context)
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ComputeBuiltinVarCase(context, "work_group_id", "gl_WorkGroupID", TYPE_UINT_VEC3)
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,1)));
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(52,1,1)));
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,39,1)));
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,78)));
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(4,7,11)));
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(2,3,4), UVec3(4,7,11)));
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UVec3 computeReference (const UVec3& numWorkGroups, const UVec3& workGroupSize, const UVec3& workGroupID, const UVec3& localInvocationID) const
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(numWorkGroups);
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(workGroupSize);
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(localInvocationID);
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return workGroupID;
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass LocalInvocationIDCase : public ComputeBuiltinVarCase
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	LocalInvocationIDCase (Context& context)
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ComputeBuiltinVarCase(context, "local_invocation_id", "gl_LocalInvocationID", TYPE_UINT_VEC3)
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,1)));
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(2,7,3)));
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(2,1,1), UVec3(1,1,1)));
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(2,1,1), UVec3(1,3,5)));
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,3,1), UVec3(1,1,1)));
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,7), UVec3(1,1,1)));
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,7), UVec3(3,3,1)));
3778852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(10,3,4), UVec3(1,1,1)));
3788852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(10,3,4), UVec3(3,1,2)));
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UVec3 computeReference (const UVec3& numWorkGroups, const UVec3& workGroupSize, const UVec3& workGroupID, const UVec3& localInvocationID) const
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(numWorkGroups);
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(workGroupSize);
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(workGroupID);
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return localInvocationID;
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GlobalInvocationIDCase : public ComputeBuiltinVarCase
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GlobalInvocationIDCase (Context& context)
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ComputeBuiltinVarCase(context, "global_invocation_id", "gl_GlobalInvocationID", TYPE_UINT_VEC3)
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,1)));
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(52,1,1)));
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,39,1)));
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,78)));
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(4,7,11)));
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(2,3,4), UVec3(4,7,11)));
4028852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(10,3,4), UVec3(1,1,1)));
4038852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(10,3,4), UVec3(3,1,2)));
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UVec3 computeReference (const UVec3& numWorkGroups, const UVec3& workGroupSize, const UVec3& workGroupID, const UVec3& localInvocationID) const
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(numWorkGroups);
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return workGroupID * workGroupSize + localInvocationID;
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass LocalInvocationIndexCase : public ComputeBuiltinVarCase
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	LocalInvocationIndexCase (Context& context)
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ComputeBuiltinVarCase(context, "local_invocation_index", "gl_LocalInvocationIndex", TYPE_UINT)
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,1,1)));
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(1,39,1)));
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(1,1,1), UVec3(4,7,11)));
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(2,3,4), UVec3(4,7,11)));
4238852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(10,3,4), UVec3(1,1,1)));
4248852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry		m_subCases.push_back(SubCase(UVec3(10,3,4), UVec3(3,1,2)));
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UVec3 computeReference (const UVec3& numWorkGroups, const UVec3& workGroupSize, const UVec3& workGroupID, const UVec3& localInvocationID) const
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(workGroupID);
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(numWorkGroups);
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return UVec3(localInvocationID.z()*workGroupSize.x()*workGroupSize.y() + localInvocationID.y()*workGroupSize.x() + localInvocationID.x(), 0, 0);
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4353c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderBuiltinVarTests::ComputeShaderBuiltinVarTests (Context& context)
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "compute", "Compute Shader Builtin Variables")
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryComputeShaderBuiltinVarTests::~ComputeShaderBuiltinVarTests (void)
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ComputeShaderBuiltinVarTests::init (void)
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new NumWorkGroupsCase			(m_context));
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new WorkGroupSizeCase			(m_context));
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new WorkGroupIDCase			(m_context));
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new LocalInvocationIDCase		(m_context));
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new GlobalInvocationIDCase		(m_context));
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new LocalInvocationIndexCase	(m_context));
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles31
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
457