13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.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 Shader operators tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fShaderOperatorTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsShaderRenderCase.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderUtil.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuStringTemplate.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVectorUtil.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deInt32.h"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <map>
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <limits>
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace tcu;
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glu;
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace deqp::gls;
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::map;
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::pair;
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::ostringstream;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if defined(abs)
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#	undef abs
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing de::min;
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing de::max;
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing de::clamp;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \note VS2013 gets confused without these
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::asinh;
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::acosh;
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::atanh;
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::exp2;
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::log2;
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::trunc;
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float abs		(float v)			{ return deFloatAbs(v); }
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool logicalAnd	(bool a, bool b)	{ return (a && b); }
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool logicalOr	(bool a, bool b)	{ return (a || b); }
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool logicalXor	(bool a, bool b)	{ return (a != b); }
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \note stdlib.h defines div() that is not compatible with the macros.
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> inline T div (T a, T b) { return a / b; }
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> inline T leftShift (T value, int amount) { return value << amount; }
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint32	rightShift (deUint32 value, int amount)		{ return value >> amount; }
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline int		rightShift (int value, int amount)			{ return (value >> amount) | (value >= 0 ? 0 : ~(~0U >> amount)); } // \note Arithmetic shift.
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> Vector<T, Size> leftShift (const Vector<T, Size>& value, const Vector<int, Size>& amount)
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<T, Size> result;
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result[i] = leftShift(value[i], amount[i]);
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return result;
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> Vector<T, Size> rightShift (const Vector<T, Size>& value, const Vector<int, Size>& amount)
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<T, Size> result;
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result[i] = rightShift(value[i], amount[i]);
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return result;
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> Vector<T, Size> leftShiftVecScalar	(const Vector<T, Size>& value, int amount) { return leftShift(value, Vector<int, Size>(amount)); }
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> Vector<T, Size> rightShiftVecScalar	(const Vector<T, Size>& value, int amount) { return rightShift(value, Vector<int, Size>(amount)); }
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<T, Size> minVecScalar (const Vector<T, Size>& v, T s)
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<T, Size> res;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = min(v[i], s);
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<T, Size> maxVecScalar (const Vector<T, Size>& v, T s)
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<T, Size> res;
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = max(v[i], s);
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<T, Size> clampVecScalarScalar (const Vector<T, Size>& v, T s0, T s1)
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<T, Size> res;
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = clamp(v[i], s0, s1);
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<T, Size> mixVecVecScalar (const Vector<T, Size>& v0, const Vector<T, Size>& v1, T s)
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<T, Size> res;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = mix(v0[i], v1[i], s);
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<T, Size> stepScalarVec (T s, const Vector<T, Size>& v)
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<T, Size> res;
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = step(s, v[i]);
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<T, Size> smoothStepScalarScalarVec (T s0, T s1, const Vector<T, Size>& v)
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<T, Size> res;
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = smoothStep(s0, s1, v[i]);
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float	addOne (float v)	{ return v + 1.0f; };
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float	subOne (float v)	{ return v - 1.0f; };
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline int		addOne (int v)		{ return v + 1; };
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline int		subOne (int v)		{ return v - 1; };
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint32	addOne (deUint32 v)	{ return v + 1; };
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint32	subOne (deUint32 v)	{ return v - 1; };
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<float, Size>		addOne (const Vector<float, Size>& v)		{ return v + 1.0f; };
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<float, Size>		subOne (const Vector<float, Size>& v)		{ return v - 1.0f; };
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<int, Size>			addOne (const Vector<int, Size>& v)			{ return v + 1; };
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<int, Size>			subOne (const Vector<int, Size>& v)			{ return v - 1; };
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<deUint32, Size>	addOne (const Vector<deUint32, Size>& v)	{ return v + 1U; };
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<deUint32, Size>	subOne (const Vector<deUint32, Size>& v)	{ return (v.asInt() - 1).asUint(); };
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> inline T selection	(bool cond, T a, T b)	{ return cond ? a : b; };
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Vec-scalar and scalar-vec binary operators.
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \note This one is done separately due to how the overloaded minus operator is implemented for vector-scalar operands.
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size>				inline Vector<deUint32, Size>	subVecScalar			(const Vector<deUint32, Size>& v, deUint32 s)	{ return (v.asInt() - (int)s).asUint(); };
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>	inline Vector<T, Size>			addVecScalar			(const Vector<T, Size>& v, T s)					{ return v + s; };
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>	inline Vector<T, Size>			subVecScalar			(const Vector<T, Size>& v, T s)					{ return v - s; };
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>	inline Vector<T, Size>			mulVecScalar			(const Vector<T, Size>& v, T s)					{ return v * s; };
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>	inline Vector<T, Size>			divVecScalar			(const Vector<T, Size>& v, T s)					{ return v / s; };
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>	inline Vector<T, Size>			modVecScalar			(const Vector<T, Size>& v, T s)					{ return mod(v, Vector<T, Size>(s)); };
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>	inline Vector<T, Size>			bitwiseAndVecScalar		(const Vector<T, Size>& v, T s)					{ return bitwiseAnd(v, Vector<T, Size>(s)); };
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>	inline Vector<T, Size>			bitwiseOrVecScalar		(const Vector<T, Size>& v, T s)					{ return bitwiseOr(v, Vector<T, Size>(s)); };
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size>	inline Vector<T, Size>			bitwiseXorVecScalar		(const Vector<T, Size>& v, T s)					{ return bitwiseXor(v, Vector<T, Size>(s)); };
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size>			addScalarVec			(T s, const Vector<T, Size>& v) 				{ return s + v; };
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size>			subScalarVec			(T s, const Vector<T, Size>& v) 				{ return s - v; };
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size>			mulScalarVec			(T s, const Vector<T, Size>& v) 				{ return s * v; };
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size>			divScalarVec			(T s, const Vector<T, Size>& v) 				{ return s / v; };
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size>			modScalarVec			(T s, const Vector<T, Size>& v)					{ return mod(Vector<T, Size>(s), v); };
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size>			bitwiseAndScalarVec		(T s, const Vector<T, Size>& v)					{ return bitwiseAnd(Vector<T, Size>(s), v); };
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size>			bitwiseOrScalarVec		(T s, const Vector<T, Size>& v)					{ return bitwiseOr(Vector<T, Size>(s), v); };
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size>			bitwiseXorScalarVec		(T s, const Vector<T, Size>& v)					{ return bitwiseXor(Vector<T, Size>(s), v); };
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference functions for specific sequence operations for the sequence operator tests.
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0, in2 + in1, in1 + in0"
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vec4		sequenceNoSideEffCase0 (const Vec4& in0, const Vec4& in1, const Vec4& in2)		{ DE_UNREF(in2); return in1 + in0; }
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0, in2 + in1, in1 + in0"
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint32	sequenceNoSideEffCase1 (float in0, deUint32 in1, float in2)						{ DE_UNREF(in0); DE_UNREF(in2); return in1 + in1; }
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0 && in1, in0, ivec2(vec2(in0) + in2)"
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline IVec2	sequenceNoSideEffCase2 (bool in0, bool in1, const Vec2& in2)					{ DE_UNREF(in1); return IVec2((int)((float)in0 + in2.x()), (int)((float)in0 + in2.y())); }
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0 + vec4(in1), in2, in1"
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline IVec4	sequenceNoSideEffCase3 (const Vec4& in0, const IVec4& in1, const BVec4& in2)	{ DE_UNREF(in0); DE_UNREF(in2); return in1; }
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0++, in1 = in0 + in2, in2 = in1"
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vec4		sequenceSideEffCase0 (const Vec4& in0, const Vec4& in1, const Vec4& in2)		{ DE_UNREF(in1); return in0 + 1.0f + in2; }
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in1++, in0 = float(in1), in1 = uint(in0 + in2)"
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint32	sequenceSideEffCase1 (float in0, deUint32 in1, float in2)						{ DE_UNREF(in0); return (deUint32)(in1 + 1.0f + in2); }
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in1 = in0, in2++, in2 = in2 + vec2(in1), ivec2(in2)"
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline IVec2	sequenceSideEffCase2 (bool in0, bool in1, const Vec2& in2)						{ DE_UNREF(in1); return (in2 + Vec2(1.0f) + Vec2((float)in0)).asInt(); }
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0 = in0 + vec4(in2), in1 = in1 + ivec4(in0), in1++"
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline IVec4	sequenceSideEffCase3 (const Vec4& in0, const IVec4& in1, const BVec4& in2)		{ return in1 + (in0 + Vec4((float)in2.x(), (float)in2.y(), (float)in2.z(), (float)in2.w())).asInt(); }
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ShaderEvalFunc-type wrappers for the above functions.
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceNoSideEffCase0	(ShaderEvalContext& ctx) { ctx.color		= sequenceNoSideEffCase0		(ctx.in[0].swizzle(1, 2, 3, 0),	ctx.in[1].swizzle(3, 2, 1, 0),			ctx.in[2].swizzle(0, 3, 2, 1)); }
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceNoSideEffCase1	(ShaderEvalContext& ctx) { ctx.color.x()	= (float)sequenceNoSideEffCase1	(ctx.in[0].z(),					(deUint32)ctx.in[1].x(),				ctx.in[2].y()); }
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceNoSideEffCase2	(ShaderEvalContext& ctx) { ctx.color.yz()	= sequenceNoSideEffCase2		(ctx.in[0].z() > 0.0f,			ctx.in[1].x() > 0.0f,					ctx.in[2].swizzle(2, 1)).asFloat(); }
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceNoSideEffCase3	(ShaderEvalContext& ctx) { ctx.color		= sequenceNoSideEffCase3		(ctx.in[0].swizzle(1, 2, 3, 0),	ctx.in[1].swizzle(3, 2, 1, 0).asInt(),	greaterThan(ctx.in[2].swizzle(0, 3, 2, 1), Vec4(0.0f, 0.0f, 0.0f, 0.0f))).asFloat(); }
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceSideEffCase0	(ShaderEvalContext& ctx) { ctx.color		= sequenceSideEffCase0			(ctx.in[0].swizzle(1, 2, 3, 0),	ctx.in[1].swizzle(3, 2, 1, 0),			ctx.in[2].swizzle(0, 3, 2, 1)); }
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceSideEffCase1	(ShaderEvalContext& ctx) { ctx.color.x()	= (float)sequenceSideEffCase1	(ctx.in[0].z(),					(deUint32)ctx.in[1].x(),				ctx.in[2].y()); }
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceSideEffCase2	(ShaderEvalContext& ctx) { ctx.color.yz()	= sequenceSideEffCase2			(ctx.in[0].z() > 0.0f,			ctx.in[1].x() > 0.0f,					ctx.in[2].swizzle(2, 1)).asFloat(); }
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceSideEffCase3	(ShaderEvalContext& ctx) { ctx.color		= sequenceSideEffCase3			(ctx.in[0].swizzle(1, 2, 3, 0),	ctx.in[1].swizzle(3, 2, 1, 0).asInt(),	greaterThan(ctx.in[2].swizzle(0, 3, 2, 1), Vec4(0.0f, 0.0f, 0.0f, 0.0f))).asFloat(); }
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic string stringJoin (const vector<string>& elems, const string& delim)
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string result;
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < (int)elems.size(); i++)
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result += (i > 0 ? delim : "") + elems[i];
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return result;
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic string twoValuedVec4 (const string& first, const string& second, const BVec4& firstMask)
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<string> elems(4);
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < 4; i++)
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		elems[i] = firstMask[i] ? first : second;
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return "vec4(" + stringJoin(elems, ", ") + ")";
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MAX_INPUTS = 3
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum PrecisionMask
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_NA				= 0,						//!< Precision not applicable (booleans)
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_LOWP			= (1<<PRECISION_LOWP),
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_MEDIUMP		= (1<<PRECISION_MEDIUMP),
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_HIGHP			= (1<<PRECISION_HIGHP),
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_LOWP_MEDIUMP	= PRECMASK_LOWP | PRECMASK_MEDIUMP,
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_MEDIUMP_HIGHP	= PRECMASK_MEDIUMP | PRECMASK_HIGHP,
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_ALL			= PRECMASK_LOWP | PRECMASK_MEDIUMP | PRECMASK_HIGHP
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum ValueType
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_NONE			= 0,
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_FLOAT			= (1<<0),	// float scalar
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_FLOAT_VEC		= (1<<1),	// float vector
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_FLOAT_GENTYPE	= (1<<2),	// float scalar/vector
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_VEC3			= (1<<3),	// vec3 only
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_MATRIX		= (1<<4),	// matrix
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_BOOL			= (1<<5),	// boolean scalar
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_BOOL_VEC		= (1<<6),	// boolean vector
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_BOOL_GENTYPE	= (1<<7),	// boolean scalar/vector
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_INT			= (1<<8),	// int scalar
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_INT_VEC		= (1<<9),	// int vector
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_INT_GENTYPE	= (1<<10),	// int scalar/vector
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_UINT			= (1<<11),	// uint scalar
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_UINT_VEC		= (1<<12),	// uint vector
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_UINT_GENTYPE	= (1<<13),	// uint scalar/vector
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Shorthands.
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	F				= VALUE_FLOAT,
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FV				= VALUE_FLOAT_VEC,
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GT				= VALUE_FLOAT_GENTYPE,
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	V3				= VALUE_VEC3,
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	M				= VALUE_MATRIX,
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	B				= VALUE_BOOL,
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BV				= VALUE_BOOL_VEC,
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BGT				= VALUE_BOOL_GENTYPE,
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	I				= VALUE_INT,
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IV				= VALUE_INT_VEC,
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IGT				= VALUE_INT_GENTYPE,
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	U				= VALUE_UINT,
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UV				= VALUE_UINT_VEC,
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UGT				= VALUE_UINT_GENTYPE
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool isScalarType (ValueType type)
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return type == VALUE_FLOAT || type == VALUE_BOOL || type == VALUE_INT || type == VALUE_UINT;
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool isFloatType (ValueType type)
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (type & (VALUE_FLOAT | VALUE_FLOAT_VEC | VALUE_FLOAT_GENTYPE)) != 0;
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool isIntType (ValueType type)
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (type & (VALUE_INT | VALUE_INT_VEC | VALUE_INT_GENTYPE)) != 0;
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool isUintType (ValueType type)
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (type & (VALUE_UINT | VALUE_UINT_VEC | VALUE_UINT_GENTYPE)) != 0;
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool isBoolType (ValueType type)
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (type & (VALUE_BOOL | VALUE_BOOL_VEC | VALUE_BOOL_GENTYPE)) != 0;
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline float getGLSLUintMaxAsFloat (const glw::Functions& gl, ShaderType shaderType, Precision uintPrecision)
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 intPrecisionGL;
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 shaderTypeGL;
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (uintPrecision)
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case PRECISION_LOWP:		intPrecisionGL = GL_LOW_INT;		break;
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case PRECISION_MEDIUMP:		intPrecisionGL = GL_MEDIUM_INT;		break;
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case PRECISION_HIGHP:		intPrecisionGL = GL_HIGH_INT;		break;
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			intPrecisionGL = 0;
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (shaderType)
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case SHADERTYPE_VERTEX:		shaderTypeGL = GL_VERTEX_SHADER;	break;
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case SHADERTYPE_FRAGMENT:	shaderTypeGL = GL_FRAGMENT_SHADER;	break;
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			shaderTypeGL = 0;
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLint range[2]		= { -1, -1 };
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLint precision	= -1;
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.getShaderPrecisionFormat(shaderTypeGL, intPrecisionGL, &range[0], &precision);
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderPrecisionFormat failed");
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK(de::inBounds(range[0], 8, 32));
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int numBitsInType = range[0] + 1;
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (float)((1ull << numBitsInType) - 1);
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Float scalar that can be either constant or a symbol that can be evaluated later.
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FloatScalar
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum Symbol
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SYMBOL_LOWP_UINT_MAX = 0,
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SYMBOL_MEDIUMP_UINT_MAX,
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SYMBOL_LOWP_UINT_MAX_RECIPROCAL,
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SYMBOL_MEDIUMP_UINT_MAX_RECIPROCAL,
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SYMBOL_ONE_MINUS_UINT32MAX_DIV_LOWP_UINT_MAX,
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SYMBOL_ONE_MINUS_UINT32MAX_DIV_MEDIUMP_UINT_MAX,
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		SYMBOL_LAST
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar (float c)	: m_isConstant(true),	m_value(c) {}
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar (Symbol s)	: m_isConstant(false),	m_value(s) {}
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float getValue (const glw::Functions& gl, ShaderType shaderType) const
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_isConstant)
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return m_value.constant;
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			switch (m_value.symbol)
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case SYMBOL_LOWP_UINT_MAX:								return getGLSLUintMaxAsFloat(gl, shaderType, PRECISION_LOWP);
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case SYMBOL_MEDIUMP_UINT_MAX:							return getGLSLUintMaxAsFloat(gl, shaderType, PRECISION_MEDIUMP);
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case SYMBOL_LOWP_UINT_MAX_RECIPROCAL:					return 1.0f / getGLSLUintMaxAsFloat(gl, shaderType, PRECISION_LOWP);
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case SYMBOL_MEDIUMP_UINT_MAX_RECIPROCAL:				return 1.0f / getGLSLUintMaxAsFloat(gl, shaderType, PRECISION_MEDIUMP);
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case SYMBOL_ONE_MINUS_UINT32MAX_DIV_LOWP_UINT_MAX:		return 1.0f - (float)std::numeric_limits<deUint32>::max() / getGLSLUintMaxAsFloat(gl, shaderType, PRECISION_LOWP);
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case SYMBOL_ONE_MINUS_UINT32MAX_DIV_MEDIUMP_UINT_MAX:	return 1.0f - (float)std::numeric_limits<deUint32>::max() / getGLSLUintMaxAsFloat(gl, shaderType, PRECISION_MEDIUMP);
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				default:
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DE_ASSERT(false);
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					return 0.0f;
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool m_isConstant;
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	union ConstantOrSymbol
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float	constant;
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Symbol	symbol;
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ConstantOrSymbol (float c)	: constant	(c) {}
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ConstantOrSymbol (Symbol s)	: symbol	(s) {}
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} m_value;
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct Value
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Value (ValueType valueType_, const FloatScalar& rangeMin_, const FloatScalar& rangeMax_)
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: valueType	(valueType_)
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMin	(rangeMin_)
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMax	(rangeMax_)
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ValueType		valueType;
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		rangeMin;
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		rangeMax;
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum OperationType
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION = 0,
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OPERATOR,
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SIDE_EFFECT_OPERATOR // Test the side-effect (as opposed to the result) of a side-effect operator.
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct BuiltinFuncInfo
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BuiltinFuncInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_,
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 Value input0_, Value input1_, Value input2_,
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 const FloatScalar& resultScale_, const FloatScalar& resultBias_,
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 deUint32 precisionMask_,
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_,
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 OperationType type_=FUNCTION, bool isUnaryPrefix_=true)
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: caseName			(caseName_)
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, shaderFuncName	(shaderFuncName_)
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, outValue			(outValue_)
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input0			(input0_)
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input1			(input1_)
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input2			(input2_)
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, resultScale		(resultScale_)
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, resultBias		(resultBias_)
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, referenceScale	(resultScale_)
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, referenceBias		(resultBias_)
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, precisionMask		(precisionMask_)
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncScalar	(evalFuncScalar_)
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec2		(evalFuncVec2_)
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec3		(evalFuncVec3_)
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec4		(evalFuncVec4_)
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, type				(type_)
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, isUnaryPrefix		(isUnaryPrefix_)
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BuiltinFuncInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_,
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 Value input0_, Value input1_, Value input2_,
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 const FloatScalar& resultScale_, const FloatScalar& resultBias_, const FloatScalar& referenceScale_, const FloatScalar& referenceBias_,
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 deUint32 precisionMask_,
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_,
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					 OperationType type_=FUNCTION, bool isUnaryPrefix_=true)
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: caseName			(caseName_)
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, shaderFuncName	(shaderFuncName_)
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, outValue			(outValue_)
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input0			(input0_)
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input1			(input1_)
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input2			(input2_)
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, resultScale		(resultScale_)
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, resultBias		(resultBias_)
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, referenceScale	(referenceScale_)
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, referenceBias		(referenceBias_)
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, precisionMask		(precisionMask_)
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncScalar	(evalFuncScalar_)
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec2		(evalFuncVec2_)
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec3		(evalFuncVec3_)
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec4		(evalFuncVec4_)
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, type				(type_)
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, isUnaryPrefix		(isUnaryPrefix_)
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*		caseName;			//!< Name of case.
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*		shaderFuncName;		//!< Name in shading language.
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ValueType		outValue;
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Value			input0;
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Value			input1;
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Value			input2;
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		resultScale;
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		resultBias;
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		referenceScale;
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		referenceBias;
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32		precisionMask;
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	evalFuncScalar;
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	evalFuncVec2;
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	evalFuncVec3;
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	evalFuncVec4;
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OperationType	type;
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			isUnaryPrefix;		//!< Whether a unary operator is a prefix operator; redundant unless unary.
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinOperInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, const FloatScalar& resultScale_, const FloatScalar& resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_)
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, resultScale_, resultBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, OPERATOR);
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinOperInfoSeparateRefScaleBias (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, const FloatScalar& resultScale_, const FloatScalar& resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_, const FloatScalar& referenceScale_, const FloatScalar& referenceBias_)
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, referenceScale_, referenceBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, OPERATOR);
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// For postfix (unary) operators.
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinPostOperInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, const FloatScalar& resultScale_, const FloatScalar& resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_)
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, resultScale_, resultBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, OPERATOR, false);
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinSideEffOperInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, const FloatScalar& resultScale_, const FloatScalar& resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_)
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, resultScale_, resultBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, SIDE_EFFECT_OPERATOR);
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// For postfix (unary) operators, testing side-effect.
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinPostSideEffOperInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, const FloatScalar& resultScale_, const FloatScalar& resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_)
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, resultScale_, resultBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, SIDE_EFFECT_OPERATOR, false);
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// BuiltinFuncGroup
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct BuiltinFuncGroup
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						BuiltinFuncGroup	(const char* name_, const char* description_) : name(name_), description(description_) {}
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BuiltinFuncGroup&	operator<<			(const BuiltinFuncInfo& info) { funcInfos.push_back(info); return *this; }
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*						name;
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*						description;
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<BuiltinFuncInfo>	funcInfos;
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_inSwizzles[MAX_INPUTS][4] =
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{ "z", "wy", "zxy", "yzwx" },
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{ "x", "yx", "yzx", "wzyx" },
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{ "y", "zy", "wyz", "xwzy" }
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_outSwizzles[]	= { "x", "yz", "xyz", "xyzw" };
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const BVec4 s_outSwizzleChannelMasks[] =
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BVec4(true,  false, false, false),
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BVec4(false, true,  true,  false),
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BVec4(true,  true,  true,  false),
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BVec4(true,  true,  true,  true )
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// OperatorShaderEvaluator
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass OperatorShaderEvaluator : public ShaderEvaluator
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OperatorShaderEvaluator (const glw::Functions& gl, ShaderType shaderType, ShaderEvalFunc evalFunc, const FloatScalar& scale, const FloatScalar& bias, int resultScalarSize)
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: m_gl							(gl)
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_shaderType					(shaderType)
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_evalFunc					(evalFunc)
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_scale						(scale)
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_bias						(bias)
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_resultScalarSize			(resultScalarSize)
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_areScaleAndBiasEvaluated	(false)
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_evaluatedScale				(-1.0f)
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_evaluatedBias				(-1.0f)
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(de::inRange(resultScalarSize, 1, 4));
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual ~OperatorShaderEvaluator (void)
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void evaluate (ShaderEvalContext& ctx)
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_evalFunc(ctx);
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!m_areScaleAndBiasEvaluated)
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_evaluatedScale	= m_scale.getValue(m_gl, m_shaderType);
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_evaluatedBias		= m_bias.getValue(m_gl, m_shaderType);
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_areScaleAndBiasEvaluated = true;
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int i = 0; i < 4; i++)
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (s_outSwizzleChannelMasks[m_resultScalarSize-1][i])
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ctx.color[i] = ctx.color[i] * m_evaluatedScale + m_evaluatedBias;
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	m_gl;
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderType				m_shaderType;
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc			m_evalFunc;
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar				m_scale;
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar				m_bias;
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_resultScalarSize;
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					m_areScaleAndBiasEvaluated;
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float					m_evaluatedScale;
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float					m_evaluatedBias;
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Concrete value.
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ShaderValue
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderValue (DataType type_, const FloatScalar& rangeMin_, const FloatScalar& rangeMax_)
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: type		(type_)
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMin	(rangeMin_)
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMax	(rangeMax_)
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderValue (void)
6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: type		(TYPE_LAST)
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMin	(0.0f)
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMax	(0.0f)
6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DataType		type;
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		rangeMin;
6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		rangeMax;
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ShaderDataSpec
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderDataSpec (void)
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: resultScale		(1.0f)
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, resultBias		(0.0f)
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, referenceScale	(1.0f)
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, referenceBias		(0.0f)
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, precision			(PRECISION_LAST)
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, output			(TYPE_LAST)
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, numInputs			(0)
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		resultScale;
6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		resultBias;
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		referenceScale;
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FloatScalar		referenceBias;
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Precision		precision;
6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DataType		output;
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				numInputs;
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderValue		inputs[MAX_INPUTS];
6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ShaderOperatorCase
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ShaderOperatorCase : public ShaderRenderCase
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								ShaderOperatorCase		(Context& context, const char* caseName, const char* description, bool isVertexCase, ShaderEvalFunc evalFunc, const string& shaderOp, const ShaderDataSpec& spec);
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual						~ShaderOperatorCase		(void);
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						setupShaderData			(void);
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								ShaderOperatorCase		(const ShaderOperatorCase&);	// not allowed!
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderOperatorCase&			operator=				(const ShaderOperatorCase&);	// not allowed!
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderDataSpec				m_spec;
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string						m_shaderOp;
6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OperatorShaderEvaluator		m_evaluator;
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6833c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderOperatorCase::ShaderOperatorCase (Context& context, const char* caseName, const char* description, bool isVertexCase, ShaderEvalFunc evalFunc, const string& shaderOp, const ShaderDataSpec& spec)
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ShaderRenderCase	(context.getTestContext(), context.getRenderContext(), context.getContextInfo(), caseName, description, isVertexCase, m_evaluator)
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_spec			(spec)
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_shaderOp		(shaderOp)
6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_evaluator		(m_renderCtx.getFunctions(), isVertexCase ? SHADERTYPE_VERTEX : SHADERTYPE_FRAGMENT, evalFunc, spec.referenceScale, spec.referenceBias, getDataTypeScalarSize(spec.output))
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ShaderOperatorCase::setupShaderData (void)
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderType		shaderType	= m_isVertexCase ? SHADERTYPE_VERTEX : SHADERTYPE_FRAGMENT;
6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*		precision	= m_spec.precision != PRECISION_LAST ? getPrecisionName(m_spec.precision) : DE_NULL;
6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*		inputPrecision[MAX_INPUTS];
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ostringstream	vtx;
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ostringstream	frag;
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ostringstream&	op			= m_isVertexCase ? vtx : frag;
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "#version 300 es\n";
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "#version 300 es\n";
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compute precision for inputs.
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < m_spec.numInputs; i++)
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		isBoolVal	= de::inRange<int>(m_spec.inputs[i].type, TYPE_BOOL, TYPE_BOOL_VEC4);
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		isIntVal	= de::inRange<int>(m_spec.inputs[i].type, TYPE_INT, TYPE_INT_VEC4);
7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		isUintVal	= de::inRange<int>(m_spec.inputs[i].type, TYPE_UINT, TYPE_UINT_VEC4);
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// \note Mediump interpolators are used for booleans, and highp for integers.
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Precision	prec		= isBoolVal	? PRECISION_MEDIUMP
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								: isIntVal || isUintVal ? PRECISION_HIGHP
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								: m_spec.precision;
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		inputPrecision[i] = getPrecisionName(prec);
7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Attributes.
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "in highp vec4 a_position;\n";
7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < m_spec.numInputs; i++)
7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vtx << "in " << inputPrecision[i] << " vec4 a_in" << i << ";\n";
7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Color output.
7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "layout(location = 0) out mediump vec4 o_color;\n";
7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_isVertexCase)
7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vtx << "out mediump vec4 v_color;\n";
7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "in mediump vec4 v_color;\n";
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int i = 0; i < m_spec.numInputs; i++)
7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vtx << "out " << inputPrecision[i] << " vec4 v_in" << i << ";\n";
7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			frag << "in " << inputPrecision[i] << " vec4 v_in" << i << ";\n";
7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "\n";
7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "void main()\n";
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "{\n";
7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "	gl_Position = a_position;\n";
7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "\n";
7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "void main()\n";
7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "{\n";
7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Expression inputs.
7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string prefix = m_isVertexCase ? "a_" : "v_";
7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < m_spec.numInputs; i++)
7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DataType		inType		= m_spec.inputs[i].type;
7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				inSize		= getDataTypeScalarSize(inType);
7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool			isInt		= de::inRange<int>(inType, TYPE_INT, TYPE_INT_VEC4);
7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool			isUint		= de::inRange<int>(inType, TYPE_UINT, TYPE_UINT_VEC4);
7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool			isBool		= de::inRange<int>(inType, TYPE_BOOL, TYPE_BOOL_VEC4);
7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		typeName	= getDataTypeName(inType);
7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		swizzle		= s_inSwizzles[i][inSize-1];
7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "\t";
7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (precision && !isBool) op << precision << " ";
7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << typeName << " in" << i << " = ";
7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (isBool)
7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (inSize == 1)	op << "(";
7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else				op << "greaterThan(";
7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (isInt || isUint)
7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			op << typeName << "(";
7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << prefix << "in" << i << "." << swizzle;
7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (isBool)
7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (inSize == 1)	op << " > 0.0)";
7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else				op << ", vec" << inSize << "(0.0))";
7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (isInt || isUint)
7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			op << ")";
7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << ";\n";
7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Result variable.
7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* outTypeName = getDataTypeName(m_spec.output);
7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		isBoolOut	= de::inRange<int>(m_spec.output, TYPE_BOOL, TYPE_BOOL_VEC4);
7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "\t";
7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (precision && !isBoolOut) op << precision << " ";
7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << outTypeName << " res = " << outTypeName << "(0.0);\n\n";
7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Expression.
7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << "\t" << m_shaderOp << "\n\n";
7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Convert to color.
8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	isResFloatVec	= de::inRange<int>(m_spec.output, TYPE_FLOAT, TYPE_FLOAT_VEC4);
8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		outScalarSize	= getDataTypeScalarSize(m_spec.output);
8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << "\thighp vec4 color = vec4(0.0, 0.0, 0.0, 1.0);\n";
8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << "\tcolor." << s_outSwizzles[outScalarSize-1] << " = ";
8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!isResFloatVec && outScalarSize == 1)
8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "float(res)";
8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (!isResFloatVec)
8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "vec" << outScalarSize << "(res)";
8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "res";
8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << ";\n";
8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Scale & bias.
8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float	resultScale		= m_spec.resultScale.getValue(m_renderCtx.getFunctions(), shaderType);
8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float	resultBias		= m_spec.resultBias.getValue(m_renderCtx.getFunctions(), shaderType);
8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((resultScale != 1.0f) || (resultBias != 0.0f))
8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "\tcolor = color";
8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (resultScale != 1.0f) op << " * " << twoValuedVec4(de::toString(resultScale),		"1.0", s_outSwizzleChannelMasks[outScalarSize-1]);
8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (resultBias != 0.0f)  op << " + " << twoValuedVec4(de::floatToString(resultBias, 2),	"0.0", s_outSwizzleChannelMasks[outScalarSize-1]);
8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << ";\n";
8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// ..
8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_isVertexCase)
8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vtx << "	v_color = color;\n";
8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "	o_color = v_color;\n";
8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int i = 0; i < m_spec.numInputs; i++)
8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vtx << "	v_in" << i << " = a_in" << i << ";\n";
8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "	o_color = color;\n";
8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "}\n";
8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "}\n";
8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_vertShaderSource = vtx.str();
8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_fragShaderSource = frag.str();
8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Setup the user attributes.
8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_userAttribTransforms.resize(m_spec.numInputs);
8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int inputNdx = 0; inputNdx < m_spec.numInputs; inputNdx++)
8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const ShaderValue& v = m_spec.inputs[inputNdx];
8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(v.type != TYPE_LAST);
8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float rangeMin	= v.rangeMin.getValue(m_renderCtx.getFunctions(), shaderType);
8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float rangeMax	= v.rangeMax.getValue(m_renderCtx.getFunctions(), shaderType);
8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float scale		= rangeMax - rangeMin;
8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float minBias	= rangeMin;
8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float maxBias	= rangeMax;
8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Mat4  attribMatrix;
8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int rowNdx = 0; rowNdx < 4; rowNdx++)
8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec4 row;
8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			switch ((rowNdx + inputNdx) % 4)
8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 0:	row = Vec4(scale, 0.0f, 0.0f, minBias);		break;
8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 1:	row = Vec4(0.0f, scale, 0.0f, minBias);		break;
8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 2:	row = Vec4(-scale, 0.0f, 0.0f, maxBias);	break;
8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 3:	row = Vec4(0.0f, -scale, 0.0f, maxBias);	break;
8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				default: DE_ASSERT(false);
8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			attribMatrix.setRow(rowNdx, row);
8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_userAttribTransforms[inputNdx] = attribMatrix;
8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8793c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderOperatorCase::~ShaderOperatorCase (void)
8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ShaderOperatorTests.
8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8853c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderOperatorTests::ShaderOperatorTests(Context& context)
8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "operator", "Operator tests.")
8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderOperatorTests::~ShaderOperatorTests (void)
8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Vector math functions.
8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> inline T nop (T f) { return f; }
8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T, int Size>
8983c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVector<T, Size> nop (const Vector<T, Size>& v) { return v; }
8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_UNARY_GENTYPE_FUNCS(FUNC_NAME)																			\
9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].z()); }					\
9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1)); }		\
9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1)); }	\
9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0)); }
9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_BINARY_GENTYPE_FUNCS(FUNC_NAME)																											\
9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].z(),                 c.in[1].x()); }					\
9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1),       c.in[1].swizzle(1, 0)); }			\
9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1),    c.in[1].swizzle(1, 2, 0)); }		\
9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0), c.in[1].swizzle(3, 2, 1, 0)); }
9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_TERNARY_GENTYPE_FUNCS(FUNC_NAME)																																	\
9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].z(),                 c.in[1].x(),                 c.in[2].y()); }					\
9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1),       c.in[1].swizzle(1, 0),       c.in[2].swizzle(2, 1)); }			\
9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1),    c.in[1].swizzle(1, 2, 0),    c.in[2].swizzle(3, 1, 2)); }		\
9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0), c.in[1].swizzle(3, 2, 1, 0), c.in[2].swizzle(0, 3, 2, 1)); }
9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_UNARY_SCALAR_GENTYPE_FUNCS(FUNC_NAME)																	\
9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].z()); }					\
920