13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 2.0 Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Shader operators tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fShaderOperatorTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsShaderRenderCase.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderUtil.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVectorUtil.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deInt32.h"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <map>
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace tcu;
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glu;
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace deqp::gls;
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::map;
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::pair;
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::ostringstream;
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if defined(abs)
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#	undef abs
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing de::min;
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing de::max;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing de::clamp;
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \note VS2013 gets confused without these
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::exp2;
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::log2;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float abs		(float v)			{ return deFloatAbs(v); }
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool logicalAnd	(bool a, bool b)	{ return (a && b); }
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool logicalOr	(bool a, bool b)	{ return (a || b); }
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool logicalXor	(bool a, bool b)	{ return (a != b); }
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DEFINE_VEC_FLOAT_FUNCTION(FUNC_NAME, SCALAR_OP_NAME)					\
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size>																\
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<float, Size> FUNC_NAME (const Vector<float, Size>& v, float s)	\
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{																				\
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<float, Size> res;													\
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)												\
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = SCALAR_OP_NAME(v[i], s);										\
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;																	\
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DEFINE_FLOAT_VEC_FUNCTION(FUNC_NAME, SCALAR_OP_NAME)					\
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size>																\
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<float, Size> FUNC_NAME (float s, const Vector<float, Size>& v)	\
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{																				\
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<float, Size> res;													\
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)												\
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = SCALAR_OP_NAME(s, v[i]);										\
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;																	\
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DEFINE_VEC_VEC_FLOAT_FUNCTION(FUNC_NAME, SCALAR_OP_NAME)												\
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size>																								\
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<float, Size> FUNC_NAME (const Vector<float, Size>& v0, const Vector<float, Size>& v1, float s)	\
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{																												\
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<float, Size> res;																					\
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)																				\
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = SCALAR_OP_NAME(v0[i], v1[i], s);																\
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;																									\
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DEFINE_VEC_FLOAT_FLOAT_FUNCTION(FUNC_NAME, SCALAR_OP_NAME)							\
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size>																			\
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<float, Size> FUNC_NAME (const Vector<float, Size>& v, float s0, float s1)		\
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{																							\
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<float, Size> res;																\
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)															\
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = SCALAR_OP_NAME(v[i], s0, s1);												\
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;																				\
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DEFINE_FLOAT_FLOAT_VEC_FUNCTION(FUNC_NAME, SCALAR_OP_NAME)							\
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size>																			\
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vector<float, Size> FUNC_NAME (float s0, float s1, const Vector<float, Size>& v)		\
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{																							\
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Vector<float, Size> res;																\
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < Size; i++)															\
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res[i] = SCALAR_OP_NAME(s0, s1, v[i]);												\
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res;																				\
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDEFINE_VEC_FLOAT_FUNCTION		(modVecFloat,				mod)
1213c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDEFINE_VEC_FLOAT_FUNCTION		(minVecFloat,				min)
1223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDEFINE_VEC_FLOAT_FUNCTION		(maxVecFloat,				max)
1233c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDEFINE_VEC_FLOAT_FLOAT_FUNCTION	(clampVecFloatFloat,		clamp)
1243c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDEFINE_VEC_VEC_FLOAT_FUNCTION	(mixVecVecFloat,			mix)
1253c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDEFINE_FLOAT_VEC_FUNCTION		(stepFloatVec,				step)
1263c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDEFINE_FLOAT_FLOAT_VEC_FUNCTION	(smoothStepFloatFloatVec,	smoothStep)
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#undef DEFINE_VEC_FLOAT_FUNCTION
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#undef DEFINE_VEC_VEC_FLOAT_FUNCTION
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#undef DEFINE_VEC_FLOAT_FLOAT_FUNCTION
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#undef DEFINE_FLOAT_FLOAT_VEC_FUNCTION
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float	addOne (float v)	{ return v + 1.0f; };
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float	subOne (float v)	{ return v - 1.0f; };
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline int		addOne (int v)		{ return v + 1; };
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline int		subOne (int v)		{ return v - 1; };
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<float, Size>	addOne (const Vector<float, Size>& v)	{ return v + 1.0f; };
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<float, Size>	subOne (const Vector<float, Size>& v)	{ return v - 1.0f; };
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<int, Size>		addOne (const Vector<int, Size>& v)		{ return v + 1; };
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Size> inline Vector<int, Size>		subOne (const Vector<int, Size>& v)		{ return v - 1; };
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> inline T selection	(bool cond, T a, T b)	{ return cond ? a : b; };
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size> addVecScalar	(const Vector<T, Size>& v, T s) { return v + s; };
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size> subVecScalar	(const Vector<T, Size>& v, T s) { return v - s; };
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size> mulVecScalar	(const Vector<T, Size>& v, T s) { return v * s; };
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size> divVecScalar	(const Vector<T, Size>& v, T s) { return v / s; };
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size> addScalarVec	(T s, const Vector<T, Size>& v) { return s + v; };
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size> subScalarVec	(T s, const Vector<T, Size>& v) { return s - v; };
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size> mulScalarVec	(T s, const Vector<T, Size>& v) { return s * v; };
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T, int Size> inline Vector<T, Size> divScalarVec	(T s, const Vector<T, Size>& v) { return s / v; };
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference functions for specific sequence operations for the sequence operator tests.
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0, in2 + in1, in1 + in0"
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vec4		sequenceNoSideEffCase0 (const Vec4& in0, const Vec4& in1, const Vec4& in2)		{ DE_UNREF(in2); return in1 + in0; }
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0, in2 + in1, in1 + in0"
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline int		sequenceNoSideEffCase1 (float in0, int in1, float in2)							{ DE_UNREF(in0); DE_UNREF(in2); return in1 + in1; }
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0 && in1, in0, ivec2(vec2(in0) + in2)"
1623c827367444ee418f129b2c238299f49d3264554Jarkko 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())); }
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0 + vec4(in1), in2, in1"
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline IVec4	sequenceNoSideEffCase3 (const Vec4& in0, const IVec4& in1, const BVec4& in2)	{ DE_UNREF(in0); DE_UNREF(in2); return in1; }
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0++, in1 = in0 + in2, in2 = in1"
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Vec4		sequenceSideEffCase0 (const Vec4& in0, const Vec4& in1, const Vec4& in2)		{ DE_UNREF(in1); return in0 + 1.0f + in2; }
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in1++, in0 = float(in1), in1 = int(in0 + in2)"
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline int		sequenceSideEffCase1 (float in0, int in1, float in2)							{ DE_UNREF(in0); return (int)(in1 + 1.0f + in2); }
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in1 = in0, in2++, in2 = in2 + vec2(in1), ivec2(in2)"
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline IVec2	sequenceSideEffCase2 (bool in0, bool in1, const Vec2& in2)						{ DE_UNREF(in1); return (in2 + Vec2(1.0f) + Vec2((float)in0)).asInt(); }
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Reference for expression "in0 = in0 + vec4(in2), in1 = in1 + ivec4(in0), in1++"
1723c827367444ee418f129b2c238299f49d3264554Jarkko 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(); }
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ShaderEvalFunc-type wrappers for the above functions.
1753c827367444ee418f129b2c238299f49d3264554Jarkko 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)); }
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceNoSideEffCase1	(ShaderEvalContext& ctx) { ctx.color.x()	= (float)sequenceNoSideEffCase1(ctx.in[0].z(), (int)ctx.in[1].x(), ctx.in[2].y()); }
1773c827367444ee418f129b2c238299f49d3264554Jarkko 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(); }
1783c827367444ee418f129b2c238299f49d3264554Jarkko 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(); }
1793c827367444ee418f129b2c238299f49d3264554Jarkko 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)); }
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid evalSequenceSideEffCase1	(ShaderEvalContext& ctx) { ctx.color.x()	= (float)sequenceSideEffCase1(ctx.in[0].z(), (int)ctx.in[1].x(), ctx.in[2].y()); }
1813c827367444ee418f129b2c238299f49d3264554Jarkko 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(); }
1823c827367444ee418f129b2c238299f49d3264554Jarkko 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(); }
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MAX_INPUTS = 3
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum PrecisionMask
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_NA				= 0,						//!< Precision not applicable (booleans)
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_LOWP			= (1<<PRECISION_LOWP),
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_MEDIUMP		= (1<<PRECISION_MEDIUMP),
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_HIGHP			= (1<<PRECISION_HIGHP),
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_MEDIUMP_HIGHP	= (1<<PRECISION_MEDIUMP) | (1<<PRECISION_HIGHP),
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	PRECMASK_ALL			= (1<<PRECISION_LOWP) | (1<<PRECISION_MEDIUMP) | (1<<PRECISION_HIGHP)
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum ValueType
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_NONE			= 0,
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_FLOAT			= (1<<0),	// float scalar
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_FLOAT_VEC		= (1<<1),	// float vector
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_FLOAT_GENTYPE	= (1<<2),	// float scalar/vector
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_VEC3			= (1<<3),	// vec3 only
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_MATRIX		= (1<<4),	// matrix
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_BOOL			= (1<<5),	// boolean scalar
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_BOOL_VEC		= (1<<6),	// boolean vector
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_BOOL_GENTYPE	= (1<<7),	// boolean scalar/vector
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_INT			= (1<<8),	// int scalar
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_INT_VEC		= (1<<9),	// int vector
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VALUE_INT_GENTYPE	= (1<<10),	// int scalar/vector
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Shorthands.
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	F				= VALUE_FLOAT,
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FV				= VALUE_FLOAT_VEC,
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GT				= VALUE_FLOAT_GENTYPE,
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	V3				= VALUE_VEC3,
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	M				= VALUE_MATRIX,
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	B				= VALUE_BOOL,
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BV				= VALUE_BOOL_VEC,
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BGT				= VALUE_BOOL_GENTYPE,
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	I				= VALUE_INT,
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IV				= VALUE_INT_VEC,
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IGT				= VALUE_INT_GENTYPE
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool isScalarType (ValueType type)
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return type == VALUE_FLOAT || type == VALUE_BOOL || type == VALUE_INT;
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct Value
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Value (ValueType valueType_, float rangeMin_, float rangeMax_)
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: valueType	(valueType_)
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMin	(rangeMin_)
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMax	(rangeMax_)
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ValueType	valueType;
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float		rangeMin;
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float		rangeMax;
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum OperationType
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	FUNCTION = 0,
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OPERATOR,
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SIDE_EFFECT_OPERATOR // Test the side-effect (as opposed to the result) of a side-effect operator.
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct BuiltinFuncInfo
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BuiltinFuncInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, float resultScale_, float resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_, OperationType type_=FUNCTION, bool isUnaryPrefix_=true)
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: caseName			(caseName_)
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, shaderFuncName	(shaderFuncName_)
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, outValue			(outValue_)
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input0			(input0_)
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input1			(input1_)
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, input2			(input2_)
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, resultScale		(resultScale_)
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, resultBias		(resultBias_)
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, precisionMask		(precisionMask_)
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncScalar	(evalFuncScalar_)
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec2		(evalFuncVec2_)
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec3		(evalFuncVec3_)
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, evalFuncVec4		(evalFuncVec4_)
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, type				(type_)
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, isUnaryPrefix		(isUnaryPrefix_)
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*		caseName;			//!< Name of case.
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*		shaderFuncName;		//!< Name in shading language.
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ValueType		outValue;
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Value			input0;
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Value			input1;
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Value			input2;
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			resultScale;
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			resultBias;
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32		precisionMask;
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	evalFuncScalar;
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	evalFuncVec2;
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	evalFuncVec3;
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	evalFuncVec4;
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OperationType	type;
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool			isUnaryPrefix;		//!< Whether a unary operator is a prefix operator; redundant unless unary.
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinOperInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, float resultScale_, float resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_)
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, OPERATOR);
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// For postfix (unary) operators.
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinPostOperInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, float resultScale_, float resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_)
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, OPERATOR, false);
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinSideEffOperInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, float resultScale_, float resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_)
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, SIDE_EFFECT_OPERATOR);
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// For postfix (unary) operators, testing side-effect.
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline BuiltinFuncInfo BuiltinPostSideEffOperInfo (const char* caseName_, const char* shaderFuncName_, ValueType outValue_, Value input0_, Value input1_, Value input2_, float resultScale_, float resultBias_, deUint32 precisionMask_, ShaderEvalFunc evalFuncScalar_, ShaderEvalFunc evalFuncVec2_, ShaderEvalFunc evalFuncVec3_, ShaderEvalFunc evalFuncVec4_)
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return BuiltinFuncInfo(caseName_, shaderFuncName_, outValue_, input0_, input1_, input2_, resultScale_, resultBias_, precisionMask_, evalFuncScalar_, evalFuncVec2_, evalFuncVec3_, evalFuncVec4_, SIDE_EFFECT_OPERATOR, false);
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// BuiltinFuncGroup
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct BuiltinFuncGroup
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						BuiltinFuncGroup	(const char* name_, const char* description_) : name(name_), description(description_) {}
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BuiltinFuncGroup&	operator<<			(const BuiltinFuncInfo& info) { funcInfos.push_back(info); return *this; }
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*						name;
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*						description;
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<BuiltinFuncInfo>	funcInfos;
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_inSwizzles[MAX_INPUTS][4] =
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{ "z", "wy", "zxy", "yzwx" },
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{ "x", "yx", "yzx", "wzyx" },
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{ "y", "zy", "wyz", "xwzy" }
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* s_outSwizzles[]	= { "x", "yz", "xyz", "xyzw" };
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// OperatorShaderEvaluator
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass OperatorShaderEvaluator : public ShaderEvaluator
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OperatorShaderEvaluator (ShaderEvalFunc evalFunc, float scale, float bias)
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_evalFunc	= evalFunc;
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_scale		= scale;
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_bias		= bias;
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual ~OperatorShaderEvaluator (void)
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void evaluate (ShaderEvalContext& ctx)
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_evalFunc(ctx);
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ctx.color = ctx.color * m_scale + m_bias;
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderEvalFunc	m_evalFunc;
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			m_scale;
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			m_bias;
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Concrete value.
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ShaderValue
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderValue (DataType type_, float rangeMin_, float rangeMax_)
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: type		(type_)
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMin	(rangeMin_)
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMax	(rangeMax_)
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderValue (void)
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: type		(TYPE_LAST)
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMin	(0.0f)
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, rangeMax	(0.0f)
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DataType	type;
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float		rangeMin;
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float		rangeMax;
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ShaderDataSpec
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderDataSpec (void)
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: resultScale	(1.0f)
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, resultBias	(0.0f)
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, precision		(PRECISION_LAST)
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, output		(TYPE_LAST)
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, numInputs		(0)
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			resultScale;
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			resultBias;
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	Precision		precision;
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DataType		output;
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				numInputs;
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderValue		inputs[MAX_INPUTS];
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ShaderOperatorCase
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ShaderOperatorCase : public ShaderRenderCase
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								ShaderOperatorCase		(Context& context, const char* caseName, const char* description, bool isVertexCase, ShaderEvalFunc evalFunc, const char* shaderOp, const ShaderDataSpec& spec);
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual						~ShaderOperatorCase		(void);
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								ShaderOperatorCase		(const ShaderOperatorCase&);	// not allowed!
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ShaderOperatorCase&			operator=				(const ShaderOperatorCase&);	// not allowed!
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OperatorShaderEvaluator		m_evaluator;
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4213c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderOperatorCase::ShaderOperatorCase (Context& context, const char* caseName, const char* description, bool isVertexCase, ShaderEvalFunc evalFunc, const char* shaderOp, const ShaderDataSpec& spec)
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ShaderRenderCase(context.getTestContext(), context.getRenderContext(), context.getContextInfo(), caseName, description, isVertexCase, m_evaluator)
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_evaluator(evalFunc, spec.resultScale, spec.resultBias)
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*		precision	= spec.precision != PRECISION_LAST ? getPrecisionName(spec.precision) : DE_NULL;
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*		inputPrecision[MAX_INPUTS];
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ostringstream	vtx;
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ostringstream	frag;
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ostringstream&	op			= isVertexCase ? vtx : frag;
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compute precision for inputs.
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < spec.numInputs; i++)
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		isBoolVal	= de::inRange<int>(spec.inputs[i].type, TYPE_BOOL, TYPE_BOOL_VEC4);
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		isIntVal	= de::inRange<int>(spec.inputs[i].type, TYPE_INT, TYPE_INT_VEC4);
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// \note Mediump interpolators are used for booleans and lowp ints.
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Precision	prec		= isBoolVal || (isIntVal && spec.precision == PRECISION_LOWP) ? PRECISION_MEDIUMP : spec.precision;
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		inputPrecision[i] = getPrecisionName(prec);
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Attributes.
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "attribute highp vec4 a_position;\n";
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < spec.numInputs; i++)
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vtx << "attribute " << inputPrecision[i] << " vec4 a_in" << i << ";\n";
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (isVertexCase)
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vtx << "varying mediump vec4 v_color;\n";
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "varying mediump vec4 v_color;\n";
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int i = 0; i < spec.numInputs; i++)
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			vtx << "varying " << inputPrecision[i] << " vec4 v_in" << i << ";\n";
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			frag << "varying " << inputPrecision[i] << " vec4 v_in" << i << ";\n";
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "\n";
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "void main()\n";
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "{\n";
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "	gl_Position = a_position;\n";
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "\n";
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "void main()\n";
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "{\n";
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Expression inputs.
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	string prefix = isVertexCase ? "a_" : "v_";
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int i = 0; i < spec.numInputs; i++)
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DataType		inType		= spec.inputs[i].type;
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int				inSize		= getDataTypeScalarSize(inType);
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool			isInt		= de::inRange<int>(inType, TYPE_INT, TYPE_INT_VEC4);
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool			isBool		= de::inRange<int>(inType, TYPE_BOOL, TYPE_BOOL_VEC4);
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		typeName	= getDataTypeName(inType);
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		swizzle		= s_inSwizzles[i][inSize-1];
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "\t";
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (precision && !isBool) op << precision << " ";
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << typeName << " in" << i << " = ";
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (isBool)
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (inSize == 1)	op << "(";
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else				op << "greaterThan(";
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (isInt)
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			op << typeName << "(";
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << prefix << "in" << i << "." << swizzle;
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (isBool)
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (inSize == 1)	op << " > 0.0)";
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else				op << ", vec" << inSize << "(0.0))";
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (isInt)
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			op << ")";
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << ";\n";
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Result variable.
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* outTypeName = getDataTypeName(spec.output);
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		isBoolOut	= de::inRange<int>(spec.output, TYPE_BOOL, TYPE_BOOL_VEC4);
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "\t";
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (precision && !isBoolOut) op << precision << " ";
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << outTypeName << " res = " << outTypeName << "(0.0);\n\n";
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Expression.
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << "\t" << shaderOp << "\n\n";
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Convert to color.
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	isResFloatVec	= de::inRange<int>(spec.output, TYPE_FLOAT, TYPE_FLOAT_VEC4);
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		outScalarSize	= getDataTypeScalarSize(spec.output);
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << "\tmediump vec4 color = vec4(0.0, 0.0, 0.0, 1.0);\n";
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << "\tcolor." << s_outSwizzles[outScalarSize-1] << " = ";
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!isResFloatVec && outScalarSize == 1)
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "float(res)";
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (!isResFloatVec)
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "vec" << outScalarSize << "(res)";
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "res";
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	op << ";\n";
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Scale & bias.
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float	resultScale		= spec.resultScale;
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float	resultBias		= spec.resultBias;
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((resultScale != 1.0f) || (resultBias != 0.0f))
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << "\tcolor = color";
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (resultScale != 1.0f) op << " * " << de::floatToString(resultScale, 2);
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (resultBias != 0.0f)  op << " + " << de::floatToString(resultBias, 2);
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		op << ";\n";
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// ..
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (isVertexCase)
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vtx << "	v_color = color;\n";
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "	gl_FragColor = v_color;\n";
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int i = 0; i < spec.numInputs; i++)
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vtx << "	v_in" << i << " = a_in" << i << ";\n";
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		frag << "	gl_FragColor = color;\n";
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vtx << "}\n";
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	frag << "}\n";
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_vertShaderSource = vtx.str();
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_fragShaderSource = frag.str();
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Setup the user attributes.
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_userAttribTransforms.resize(spec.numInputs);
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int inputNdx = 0; inputNdx < spec.numInputs; inputNdx++)
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const ShaderValue& v = spec.inputs[inputNdx];
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(v.type != TYPE_LAST);
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float scale		= (v.rangeMax - v.rangeMin);
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float minBias	= v.rangeMin;
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float maxBias	= v.rangeMax;
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		Mat4  attribMatrix;
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int rowNdx = 0; rowNdx < 4; rowNdx++)
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec4 row;
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			switch ((rowNdx + inputNdx) % 4)
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 0:	row = Vec4(scale, 0.0f, 0.0f, minBias);		break;
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 1:	row = Vec4(0.0f, scale, 0.0f, minBias);		break;
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 2:	row = Vec4(-scale, 0.0f, 0.0f, maxBias);	break;
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				case 3:	row = Vec4(0.0f, -scale, 0.0f, maxBias);	break;
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				default: DE_ASSERT(false);
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			attribMatrix.setRow(rowNdx, row);
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_userAttribTransforms[inputNdx] = attribMatrix;
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5983c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderOperatorCase::~ShaderOperatorCase (void)
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ShaderOperatorTests.
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6043c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderOperatorTests::ShaderOperatorTests(Context& context)
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "operator", "Operator tests.")
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6093c827367444ee418f129b2c238299f49d3264554Jarkko PoyryShaderOperatorTests::~ShaderOperatorTests (void)
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Vector math functions.
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> inline T nop (T f) { return f; }
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T, int Size>
6173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVector<T, Size> nop (const Vector<T, Size>& v) { return v; }
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_UNARY_GENTYPE_FUNCS(FUNC_NAME)																			\
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].z()); }					\
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1)); }		\
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1)); }	\
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0)); }
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_BINARY_GENTYPE_FUNCS(FUNC_NAME)																											\
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].z(),                 c.in[1].x()); }					\
6273c827367444ee418f129b2c238299f49d3264554Jarkko 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)); }			\
6283c827367444ee418f129b2c238299f49d3264554Jarkko 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)); }		\
6293c827367444ee418f129b2c238299f49d3264554Jarkko 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)); }
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_TERNARY_GENTYPE_FUNCS(FUNC_NAME)																																	\
6323c827367444ee418f129b2c238299f49d3264554Jarkko 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()); }					\
6333c827367444ee418f129b2c238299f49d3264554Jarkko 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)); }			\
6343c827367444ee418f129b2c238299f49d3264554Jarkko 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)); }		\
6353c827367444ee418f129b2c238299f49d3264554Jarkko 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)); }
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_UNARY_SCALAR_GENTYPE_FUNCS(FUNC_NAME)																	\
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].z()); }					\
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].swizzle(3, 1)); }		\
6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1)); }	\
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0)); }
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_BINARY_SCALAR_GENTYPE_FUNCS(FUNC_NAME)																									\
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].z(),                 c.in[1].x()); }					\
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].swizzle(3, 1),       c.in[1].swizzle(1, 0)); }			\
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1),    c.in[1].swizzle(1, 2, 0)); }		\
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color.x()	= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0), c.in[1].swizzle(3, 2, 1, 0)); }
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_BINARY_BOOL_FUNCS(FUNC_NAME)																		\
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bool	(ShaderEvalContext& c) { c.color.x()	= (float)FUNC_NAME(c.in[0].z() > 0.0f, c.in[1].x() > 0.0f); }
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_UNARY_BOOL_GENTYPE_FUNCS(FUNC_NAME)																											\
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bool	(ShaderEvalContext& c) { c.color.x()	= (float)FUNC_NAME(c.in[0].z() > 0.0f); }										\
6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(greaterThan(c.in[0].swizzle(3, 1), Vec2(0.0f))).asFloat(); }		\
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(greaterThan(c.in[0].swizzle(2, 0, 1), Vec3(0.0f))).asFloat(); }		\
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(greaterThan(c.in[0].swizzle(1, 2, 3, 0), Vec4(0.0f))).asFloat(); }
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_TERNARY_BOOL_GENTYPE_FUNCS(FUNC_NAME)																																																					\
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bool	(ShaderEvalContext& c) { c.color.x()	= (float)FUNC_NAME(c.in[0].z() > 0.0f,                            c.in[1].x() > 0.0f,                                   c.in[2].y() > 0.0f); }												\
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(greaterThan(c.in[0].swizzle(3, 1), Vec2(0.0f)),       greaterThan(c.in[1].swizzle(1, 0), Vec2(0.0f)),       greaterThan(c.in[2].swizzle(2, 1), Vec2(0.0f))).asFloat(); }		\
6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(greaterThan(c.in[0].swizzle(2, 0, 1), Vec3(0.0f)),    greaterThan(c.in[1].swizzle(1, 2, 0), Vec3(0.0f)),    greaterThan(c.in[2].swizzle(3, 1, 2), Vec3(0.0f))).asFloat(); }		\
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(greaterThan(c.in[0].swizzle(1, 2, 3, 0), Vec4(0.0f)), greaterThan(c.in[1].swizzle(3, 2, 1, 0), Vec4(0.0f)), greaterThan(c.in[2].swizzle(0, 3, 2, 1), Vec4(0.0f))).asFloat(); }
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_UNARY_INT_GENTYPE_FUNCS(FUNC_NAME)																						\
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_int		(ShaderEvalContext& c) { c.color.x()	= (float)FUNC_NAME((int)c.in[0].z()); }						\
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1).asInt()).asFloat(); }		\
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1).asInt()).asFloat(); }	\
6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0).asInt()).asFloat(); }
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_BINARY_INT_GENTYPE_FUNCS(FUNC_NAME)																																\
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_int		(ShaderEvalContext& c) { c.color.x()	= (float)tcu::FUNC_NAME((int)c.in[0].z(),				(int)c.in[1].x()); }						\
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1).asInt(),			c.in[1].swizzle(1, 0).asInt()).asFloat(); }		\
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1).asInt(),		c.in[1].swizzle(1, 2, 0).asInt()).asFloat(); }	\
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0).asInt(),	c.in[1].swizzle(3, 2, 1, 0).asInt()).asFloat(); }
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_TERNARY_INT_GENTYPE_FUNCS(FUNC_NAME)																																								\
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_int		(ShaderEvalContext& c) { c.color.x()	= (float)FUNC_NAME((int)c.in[0].z(),                 (int)c.in[1].x(),                (int)c.in[2].y()); }								\
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1).asInt(),       c.in[1].swizzle(1, 0).asInt(),       c.in[2].swizzle(2, 1).asInt()).asFloat(); }		\
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1).asInt(),    c.in[1].swizzle(1, 2, 0).asInt(),    c.in[2].swizzle(3, 1, 2).asInt()).asFloat(); }	\
6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0).asInt(), c.in[1].swizzle(3, 2, 1, 0).asInt(), c.in[2].swizzle(0, 3, 2, 1).asInt()).asFloat(); }
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_VEC_FLOAT_FUNCS(FUNC_NAME) \
6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1),			c.in[1].x()); } \
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1),		c.in[1].x()); } \
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0),	c.in[1].x()); }
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_VEC_FLOAT_FLOAT_FUNCS(FUNC_NAME) \
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1),			c.in[1].x(), c.in[2].y()); } \
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1),		c.in[1].x(), c.in[2].y()); } \
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0),	c.in[1].x(), c.in[2].y()); }
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_VEC_VEC_FLOAT_FUNCS(FUNC_NAME) \
6933c827367444ee418f129b2c238299f49d3264554Jarkko 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].y()); } \
6943c827367444ee418f129b2c238299f49d3264554Jarkko 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].y()); } \
6953c827367444ee418f129b2c238299f49d3264554Jarkko 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].y()); }
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_FLOAT_FLOAT_VEC_FUNCS(FUNC_NAME) \
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].z(), c.in[1].x(), c.in[2].swizzle(2, 1)); }			\
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].z(), c.in[1].x(), c.in[2].swizzle(3, 1, 2)); }		\
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].z(), c.in[1].x(), c.in[2].swizzle(0, 3, 2, 1)); }
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_FLOAT_VEC_FUNCS(FUNC_NAME) \
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].z(),					c.in[1].swizzle(1, 0)); } \
7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].z(),					c.in[1].swizzle(1, 2, 0)); } \
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].z(),					c.in[1].swizzle(3, 2, 1, 0)); }
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_IVEC_INT_FUNCS(FUNC_NAME) \
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(c.in[0].swizzle(3, 1).asInt(),			(int)c.in[1].x()).asFloat(); } \
7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(c.in[0].swizzle(2, 0, 1).asInt(),		(int)c.in[1].x()).asFloat(); } \
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0).asInt(),	(int)c.in[1].x()).asFloat(); }
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_INT_IVEC_FUNCS(FUNC_NAME) \
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME((int)c.in[0].z(),					c.in[1].swizzle(1, 0).asInt()).asFloat(); } \
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME((int)c.in[0].z(),					c.in[1].swizzle(1, 2, 0).asInt()).asFloat(); } \
7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME((int)c.in[0].z(),					c.in[1].swizzle(3, 2, 1, 0).asInt()).asFloat(); }
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Operators.
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7193c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(nop)
7203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(negate)
7213c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(addOne)
7223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(subOne)
7233c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(add)
7243c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(sub)
7253c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(mul)
7263c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(div)
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_float	(ShaderEvalContext& c) { c.color.x()	= selection(c.in[0].z() > 0.0f,		c.in[1].x(),					c.in[2].y()); }
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_vec2	(ShaderEvalContext& c) { c.color.yz()	= selection(c.in[0].z() > 0.0f,		c.in[1].swizzle(1, 0),			c.in[2].swizzle(2, 1)); }
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_vec3	(ShaderEvalContext& c) { c.color.xyz()	= selection(c.in[0].z() > 0.0f,		c.in[1].swizzle(1, 2, 0),		c.in[2].swizzle(3, 1, 2)); }
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_vec4	(ShaderEvalContext& c) { c.color		= selection(c.in[0].z() > 0.0f,		c.in[1].swizzle(3, 2, 1, 0),	c.in[2].swizzle(0, 3, 2, 1)); }
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7333c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_INT_GENTYPE_FUNCS(nop)
7343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_INT_GENTYPE_FUNCS(negate)
7353c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_INT_GENTYPE_FUNCS(addOne)
7363c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_INT_GENTYPE_FUNCS(subOne)
7373c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_INT_GENTYPE_FUNCS(add)
7383c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_INT_GENTYPE_FUNCS(sub)
7393c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_INT_GENTYPE_FUNCS(mul)
7403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_INT_GENTYPE_FUNCS(div)
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_int		(ShaderEvalContext& c) { c.color.x()	= (float)selection(c.in[0].z() > 0.0f,	(int)c.in[1].x(),						(int)c.in[2].y()); }
7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_ivec2	(ShaderEvalContext& c) { c.color.yz()	= selection(c.in[0].z() > 0.0f,			c.in[1].swizzle(1, 0).asInt(),			c.in[2].swizzle(2, 1).asInt()).asFloat(); }
7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_ivec3	(ShaderEvalContext& c) { c.color.xyz()	= selection(c.in[0].z() > 0.0f,			c.in[1].swizzle(1, 2, 0).asInt(),		c.in[2].swizzle(3, 1, 2).asInt()).asFloat(); }
7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_ivec4	(ShaderEvalContext& c) { c.color		= selection(c.in[0].z() > 0.0f,			c.in[1].swizzle(3, 2, 1, 0).asInt(),	c.in[2].swizzle(0, 3, 2, 1).asInt()).asFloat(); }
7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7473c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_BOOL_GENTYPE_FUNCS(boolNot)
7483c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_BOOL_FUNCS(logicalAnd)
7493c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_BOOL_FUNCS(logicalOr)
7503c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_BOOL_FUNCS(logicalXor)
7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_bool	(ShaderEvalContext& c) { c.color.x()	= (float)selection(c.in[0].z() > 0.0f,	c.in[1].x() > 0.0f,														c.in[2].y() > 0.0f); }
7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_bvec2	(ShaderEvalContext& c) { c.color.yz()	= selection(c.in[0].z() > 0.0f,			greaterThan(c.in[1].swizzle(1, 0), Vec2(0.0f, 0.0f)),					greaterThan(c.in[2].swizzle(2, 1), Vec2(0.0f, 0.0f))).asFloat(); }
7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_bvec3	(ShaderEvalContext& c) { c.color.xyz()	= selection(c.in[0].z() > 0.0f,			greaterThan(c.in[1].swizzle(1, 2, 0), Vec3(0.0f, 0.0f, 0.0f)),			greaterThan(c.in[2].swizzle(3, 1, 2), Vec3(0.0f, 0.0f, 0.0f))).asFloat(); }
7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_selection_bvec4	(ShaderEvalContext& c) { c.color		= selection(c.in[0].z() > 0.0f,			greaterThan(c.in[1].swizzle(3, 2, 1, 0), Vec4(0.0f, 0.0f, 0.0f, 0.0f)),	greaterThan(c.in[2].swizzle(0, 3, 2, 1), Vec4(0.0f, 0.0f, 0.0f, 0.0f))).asFloat(); }
7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7573c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_FLOAT_FUNCS(addVecScalar)
7583c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_FLOAT_FUNCS(subVecScalar)
7593c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_FLOAT_FUNCS(mulVecScalar)
7603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_FLOAT_FUNCS(divVecScalar)
7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7623c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_VEC_FUNCS(addScalarVec)
7633c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_VEC_FUNCS(subScalarVec)
7643c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_VEC_FUNCS(mulScalarVec)
7653c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_VEC_FUNCS(divScalarVec)
7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7673c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_IVEC_INT_FUNCS(addVecScalar)
7683c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_IVEC_INT_FUNCS(subVecScalar)
7693c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_IVEC_INT_FUNCS(mulVecScalar)
7703c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_IVEC_INT_FUNCS(divVecScalar)
7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7723c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_INT_IVEC_FUNCS(addScalarVec)
7733c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_INT_IVEC_FUNCS(subScalarVec)
7743c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_INT_IVEC_FUNCS(mulScalarVec)
7753c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_INT_IVEC_FUNCS(divScalarVec)
7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Built-in functions.
7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7793c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(radians)
7803c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(degrees)
7813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(sin)
7823c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(cos)
7833c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(tan)
7843c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(asin)
7853c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(acos)
7863c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(atan)
7873c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(atan2)
7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7893c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(pow)
7903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(exp)
7913c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(log)
7923c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(exp2)
7933c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(log2)
7943c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(sqrt)
7953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(inverseSqrt)
7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7973c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(abs)
7983c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(sign)
7993c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(floor)
8003c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(ceil)
8013c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(fract)
8023c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(mod)
8033c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_FLOAT_FUNCS(modVecFloat)
8043c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(min)
8053c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_FLOAT_FUNCS(minVecFloat)
8063c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(max)
8073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_FLOAT_FUNCS(maxVecFloat)
8083c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_TERNARY_GENTYPE_FUNCS(clamp)
8093c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_FLOAT_FLOAT_FUNCS(clampVecFloatFloat)
8103c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_TERNARY_GENTYPE_FUNCS(mix)
8113c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_VEC_VEC_FLOAT_FUNCS(mixVecVecFloat)
8123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(step)
8133c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_VEC_FUNCS(stepFloatVec)
8143c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_TERNARY_GENTYPE_FUNCS(smoothStep)
8153c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_FLOAT_VEC_FUNCS(smoothStepFloatFloatVec)
8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_SCALAR_GENTYPE_FUNCS(length)
8183c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_SCALAR_GENTYPE_FUNCS(distance)
8193c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_SCALAR_GENTYPE_FUNCS(dot)
8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_cross_vec3 (ShaderEvalContext& c) { c.color.xyz()	= cross(c.in[0].swizzle(2, 0, 1), c.in[1].swizzle(1, 2, 0)); }
8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_UNARY_GENTYPE_FUNCS(normalize)
8233c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_TERNARY_GENTYPE_FUNCS(faceForward)
8243c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_BINARY_GENTYPE_FUNCS(reflect)
8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_refract_float	(ShaderEvalContext& c) { c.color.x()	= refract(c.in[0].z(),                 c.in[1].x(),                 c.in[2].y()); }
8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_refract_vec2	(ShaderEvalContext& c) { c.color.yz()	= refract(c.in[0].swizzle(3, 1),       c.in[1].swizzle(1, 0),       c.in[2].y()); }
8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_refract_vec3	(ShaderEvalContext& c) { c.color.xyz()	= refract(c.in[0].swizzle(2, 0, 1),    c.in[1].swizzle(1, 2, 0),    c.in[2].y()); }
8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid eval_refract_vec4	(ShaderEvalContext& c) { c.color		= refract(c.in[0].swizzle(1, 2, 3, 0), c.in[1].swizzle(3, 2, 1, 0), c.in[2].y()); }
8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Compare functions.
8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_FLOAT_COMPARE_FUNCS(FUNC_NAME)																											\
8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(c.in[0].z(),          c.in[1].x()); }						\
8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec2	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(c.in[0].swizzle(3, 1),       c.in[1].swizzle(1, 0)); }		\
8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec3	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(c.in[0].swizzle(2, 0, 1),    c.in[1].swizzle(1, 2, 0)); }	\
8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_vec4	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(c.in[0].swizzle(1, 2, 3, 0), c.in[1].swizzle(3, 2, 1, 0)); }
8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_FLOAT_CWISE_COMPARE_FUNCS(FUNC_NAME)																											\
8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_float	(ShaderEvalContext& c) { c.color.x()	= (float)FUNC_NAME(c.in[0].z(),          c.in[1].x()); }							\
8413c827367444ee418f129b2c238299f49d3264554Jarkko 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)).asFloat(); }		\
8423c827367444ee418f129b2c238299f49d3264554Jarkko 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)).asFloat(); }		\
8433c827367444ee418f129b2c238299f49d3264554Jarkko 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)).asFloat(); }
8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_INT_COMPARE_FUNCS(FUNC_NAME)																																	\
8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_int		(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(chopToInt(c.in[0].z()), chopToInt(c.in[1].x())); }									\
8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec2	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(chopToInt(c.in[0].swizzle(3, 1)),       chopToInt(c.in[1].swizzle(1, 0))); }		\
8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec3	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(chopToInt(c.in[0].swizzle(2, 0, 1)),    chopToInt(c.in[1].swizzle(1, 2, 0))); }		\
8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec4	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(chopToInt(c.in[0].swizzle(1, 2, 3, 0)), chopToInt(c.in[1].swizzle(3, 2, 1, 0))); }
8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_INT_CWISE_COMPARE_FUNCS(FUNC_NAME)																																	\
8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_int		(ShaderEvalContext& c) { c.color.x()	= (float)FUNC_NAME(chopToInt(c.in[0].z()), chopToInt(c.in[1].x())); }									\
8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(chopToInt(c.in[0].swizzle(3, 1)),       chopToInt(c.in[1].swizzle(1, 0))).asFloat(); }		\
8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(chopToInt(c.in[0].swizzle(2, 0, 1)),    chopToInt(c.in[1].swizzle(1, 2, 0))).asFloat(); }	\
8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_ivec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(chopToInt(c.in[0].swizzle(1, 2, 3, 0)), chopToInt(c.in[1].swizzle(3, 2, 1, 0))).asFloat(); }
8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_BOOL_COMPARE_FUNCS(FUNC_NAME)																																								\
8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bool	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(c.in[0].z() > 0.0f, c.in[1].x() > 0.0f); }																		\
8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec2	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(greaterThan(c.in[0].swizzle(3, 1), Vec2(0.0f)),       greaterThan(c.in[1].swizzle(1, 0), Vec2(0.0f))); }		\
8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec3	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(greaterThan(c.in[0].swizzle(2, 0, 1), Vec3(0.0f)),    greaterThan(c.in[1].swizzle(1, 2, 0), Vec3(0.0f))); }		\
8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec4	(ShaderEvalContext& c) { c.color.x() = (float)FUNC_NAME(greaterThan(c.in[0].swizzle(1, 2, 3, 0), Vec4(0.0f)), greaterThan(c.in[1].swizzle(3, 2, 1, 0), Vec4(0.0f))); }
8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define DECLARE_BOOL_CWISE_COMPARE_FUNCS(FUNC_NAME)																																								\
8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bool	(ShaderEvalContext& c) { c.color.x()	= (float)FUNC_NAME(c.in[0].z() > 0.0f, c.in[1].x() > 0.0f); }																		\
8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec2	(ShaderEvalContext& c) { c.color.yz()	= FUNC_NAME(greaterThan(c.in[0].swizzle(3, 1), Vec2(0.0f)),       greaterThan(c.in[1].swizzle(1, 0), Vec2(0.0f))).asFloat(); }		\
8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec3	(ShaderEvalContext& c) { c.color.xyz()	= FUNC_NAME(greaterThan(c.in[0].swizzle(2, 0, 1), Vec3(0.0f)),    greaterThan(c.in[1].swizzle(1, 2, 0), Vec3(0.0f))).asFloat(); }	\
8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void eval_##FUNC_NAME##_bvec4	(ShaderEvalContext& c) { c.color		= FUNC_NAME(greaterThan(c.in[0].swizzle(1, 2, 3, 0), Vec4(0.0f)), greaterThan(c.in[1].swizzle(3, 2, 1, 0), Vec4(0.0f))).asFloat(); }
8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8693c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_COMPARE_FUNCS(allEqual)
8703c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_COMPARE_FUNCS(anyNotEqual)
8713c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_CWISE_COMPARE_FUNCS(lessThan)
8723c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDECLARE_FLOAT_CWISE_COMPARE_FUNCS(lessThanEqual)
873