es31fAdvancedBlendTests.cpp revision 57c60b3189ce3ac3e738d715313313cd140ef87c
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 Advanced blending (GL_KHR_blend_equation_advanced) tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es31fAdvancedBlendTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsFragmentOpUtil.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluObjectWrapper.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluContextInfo.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuPixelFormat.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuStringTemplate.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rrFragmentOperations.hpp"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrReferenceUtils.hpp"
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string>
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector>
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing gls::FragmentOpUtil::IntegerQuad;
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing gls::FragmentOpUtil::ReferenceQuadRenderer;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TextureLevel;
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2;
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4;
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::UVec4;
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TextureFormat;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::map;
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles31
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MAX_VIEWPORT_WIDTH		= 128,
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MAX_VIEWPORT_HEIGHT		= 128
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum RenderTargetType
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RENDERTARGETTYPE_DEFAULT	= 0,	//!< Default framebuffer
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RENDERTARGETTYPE_SRGB_FBO,
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RENDERTARGETTYPE_MSAA_FBO,
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RENDERTARGETTYPE_LAST
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass AdvancedBlendCase : public TestCase
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							AdvancedBlendCase	(Context& context, const char* name, const char* desc, deUint32 mode, int overdrawCount, bool coherent, RenderTargetType rtType);
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~AdvancedBlendCase	(void);
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init				(void);
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit				(void);
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate		(void);
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							AdvancedBlendCase	(const AdvancedBlendCase&);
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	AdvancedBlendCase&		operator=			(const AdvancedBlendCase&);
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32			m_blendMode;
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_overdrawCount;
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool				m_coherentBlending;
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const RenderTargetType	m_rtType;
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_numIters;
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10757c60b3189ce3ac3e738d715313313cd140ef87cJarkko Pöyry	bool					m_coherentExtensionSupported;
10857c60b3189ce3ac3e738d715313313cd140ef87cJarkko Pöyry
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_colorRbo;
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_fbo;
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_resolveColorRbo;
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_resolveFbo;
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::ShaderProgram*		m_program;
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ReferenceQuadRenderer*	m_referenceRenderer;
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureLevel*			m_refColorBuffer;
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_renderWidth;
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_renderHeight;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_viewportWidth;
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_viewportHeight;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_iterNdx;
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAdvancedBlendCase::AdvancedBlendCase (Context&			context,
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  const char*		name,
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  const char*		desc,
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  deUint32			mode,
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  int				overdrawCount,
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  bool				coherent,
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  RenderTargetType	rtType)
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase				(context, name, desc)
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_blendMode			(mode)
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_overdrawCount		(overdrawCount)
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_coherentBlending	(coherent)
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_rtType				(rtType)
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numIters			(5)
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_colorRbo			(0)
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fbo					(0)
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_resolveColorRbo		(0)
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_resolveFbo			(0)
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_program				(DE_NULL)
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_referenceRenderer	(DE_NULL)
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_refColorBuffer		(DE_NULL)
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderWidth			(rtType != RENDERTARGETTYPE_DEFAULT ? 2*MAX_VIEWPORT_WIDTH	: m_context.getRenderTarget().getWidth())
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderHeight		(rtType != RENDERTARGETTYPE_DEFAULT ? 2*MAX_VIEWPORT_HEIGHT	: m_context.getRenderTarget().getHeight())
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_viewportWidth		(de::min<int>(m_renderWidth,	MAX_VIEWPORT_WIDTH))
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_viewportHeight		(de::min<int>(m_renderHeight,	MAX_VIEWPORT_HEIGHT))
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_iterNdx				(0)
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst char* getBlendLayoutQualifier (rr::BlendEquationAdvanced equation)
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char* s_qualifiers[] =
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_multiply",
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_screen",
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_overlay",
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_darken",
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_lighten",
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_colordodge",
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_colorburn",
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_hardlight",
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_softlight",
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_difference",
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_exclusion",
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_hsl_hue",
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_hsl_saturation",
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_hsl_color",
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		"blend_support_hsl_luminosity",
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qualifiers) == rr::BLENDEQUATION_ADVANCED_LAST);
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(de::inBounds<int>(equation, 0, rr::BLENDEQUATION_ADVANCED_LAST));
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return s_qualifiers[equation];
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryglu::ProgramSources getBlendProgramSrc (rr::BlendEquationAdvanced equation)
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char*	s_vertSrc	= "#version 310 es\n"
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "in highp vec4 a_position;\n"
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "in mediump vec4 a_color;\n"
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "out mediump vec4 v_color;\n"
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "void main()\n"
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "{\n"
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "	gl_Position = a_position;\n"
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "	v_color = a_color;\n"
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "}\n";
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const char*	s_fragSrc	= "#version 310 es\n"
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "#extension GL_KHR_blend_equation_advanced : require\n"
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "in mediump vec4 v_color;\n"
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "layout(${SUPPORT_QUALIFIER}) out;\n"
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "layout(location = 0) out mediump vec4 o_color;\n"
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "void main()\n"
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "{\n"
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "	o_color = v_color;\n"
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									  "}\n";
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	map<string, string> args;
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	args["SUPPORT_QUALIFIER"] = getBlendLayoutQualifier(equation);
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return glu::ProgramSources()
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< glu::VertexSource(s_vertSrc)
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< glu::FragmentSource(tcu::StringTemplate(s_fragSrc).specialize(args));
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid AdvancedBlendCase::init (void)
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl				= m_context.getRenderContext().getFunctions();
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool				useFbo			= m_rtType != RENDERTARGETTYPE_DEFAULT;
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool				useSRGB			= m_rtType == RENDERTARGETTYPE_SRGB_FBO;
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_context.getContextInfo().isExtensionSupported("GL_KHR_blend_equation_advanced"))
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("GL_KHR_blend_equation_advanced is not supported", DE_NULL, __FILE__, __LINE__);
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_coherentBlending && !m_context.getContextInfo().isExtensionSupported("GL_KHR_blend_equation_advanced_coherent"))
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("GL_KHR_blend_equation_advanced_coherent is not supported", DE_NULL, __FILE__, __LINE__);
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK(gl.blendBarrierKHR);
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_program);
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_referenceRenderer);
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_refColorBuffer);
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22957c60b3189ce3ac3e738d715313313cd140ef87cJarkko Pöyry	m_coherentExtensionSupported = m_context.getContextInfo().isExtensionSupported("GL_KHR_blend_equation_advanced_coherent");
23057c60b3189ce3ac3e738d715313313cd140ef87cJarkko Pöyry
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_program = new glu::ShaderProgram(m_context.getRenderContext(), getBlendProgramSrc(sglr::rr_util::mapGLBlendEquationAdvanced(m_blendMode)));
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << *m_program;
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_program->isOk())
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		delete m_program;
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_program = DE_NULL;
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_FAIL("Compile failed");
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_referenceRenderer	= new ReferenceQuadRenderer;
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refColorBuffer	= new TextureLevel(TextureFormat(useSRGB ? TextureFormat::sRGBA : TextureFormat::RGBA, TextureFormat::UNORM_INT8), m_viewportWidth, m_viewportHeight);
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (useFbo)
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32	format		= useSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA8;
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int		numSamples	= m_rtType == RENDERTARGETTYPE_MSAA_FBO ? 4 : 0;
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << "Using FBO of size (" << m_renderWidth << ", " << m_renderHeight << ") with format "
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											   << glu::getPixelFormatStr(format) << " and " << numSamples << " samples"
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						   << TestLog::EndMessage;
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.genRenderbuffers(1, &m_colorRbo);
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindRenderbuffer(GL_RENDERBUFFER, m_colorRbo);
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.renderbufferStorageMultisample(GL_RENDERBUFFER, numSamples, format, m_renderWidth, m_renderHeight);
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create color RBO");
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.genFramebuffers(1, &m_fbo);
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRbo);
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create FBO");
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (numSamples > 0)
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Create resolve FBO
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.genRenderbuffers(1, &m_resolveColorRbo);
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindRenderbuffer(GL_RENDERBUFFER, m_resolveColorRbo);
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.renderbufferStorageMultisample(GL_RENDERBUFFER, 0, format, m_renderWidth, m_renderHeight);
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create resolve color RBO");
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.genFramebuffers(1, &m_resolveFbo);
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindFramebuffer(GL_FRAMEBUFFER, m_resolveFbo);
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_resolveColorRbo);
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create FBO");
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TCU_CHECK(gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_rtType == RENDERTARGETTYPE_DEFAULT);
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_iterNdx = 0;
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2893c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAdvancedBlendCase::~AdvancedBlendCase (void)
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	AdvancedBlendCase::deinit();
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid AdvancedBlendCase::deinit (void)
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_program;
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_referenceRenderer;
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_refColorBuffer;
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_program			= DE_NULL;
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_referenceRenderer	= DE_NULL;
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_refColorBuffer	= DE_NULL;
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_colorRbo || m_fbo)
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_colorRbo != 0)
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteRenderbuffers(1, &m_colorRbo);
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_colorRbo = 0;
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_fbo != 0)
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteFramebuffers(1, &m_fbo);
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_fbo = 0;
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_resolveColorRbo)
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteRenderbuffers(1, &m_resolveColorRbo);
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_resolveColorRbo = 0;
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_resolveFbo)
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.deleteRenderbuffers(1, &m_resolveFbo);
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_resolveFbo = 0;
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic tcu::Vec4 randomColor (de::Random* rnd)
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float rgbValues[]		= { 0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f };
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float alphaValues[]	= { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f };
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34224f9049882d302a83a4788f829863f123f2aeae1Pyry Haulos	// \note Spec assumes premultiplied inputs.
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float a = rnd->choose<float>(DE_ARRAY_BEGIN(alphaValues), DE_ARRAY_END(alphaValues));
34424f9049882d302a83a4788f829863f123f2aeae1Pyry Haulos	const float r = a * rnd->choose<float>(DE_ARRAY_BEGIN(rgbValues), DE_ARRAY_END(rgbValues));
34524f9049882d302a83a4788f829863f123f2aeae1Pyry Haulos	const float g = a * rnd->choose<float>(DE_ARRAY_BEGIN(rgbValues), DE_ARRAY_END(rgbValues));
34624f9049882d302a83a4788f829863f123f2aeae1Pyry Haulos	const float b = a * rnd->choose<float>(DE_ARRAY_BEGIN(rgbValues), DE_ARRAY_END(rgbValues));
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::Vec4(r, g, b, a);
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic tcu::ConstPixelBufferAccess getLinearAccess (const tcu::ConstPixelBufferAccess& access)
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (access.getFormat().order == TextureFormat::sRGBA)
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return tcu::ConstPixelBufferAccess(TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8),
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										   access.getWidth(), access.getHeight(), access.getDepth(),
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										   access.getRowPitch(), access.getSlicePitch(), access.getDataPtr());
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return access;
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAdvancedBlendCase::IterateResult AdvancedBlendCase::iterate (void)
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::RenderContext&		renderCtx		= m_context.getRenderContext();
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&			gl				= renderCtx.getFunctions();
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random						rnd				(deStringHash(getName()) ^ deInt32Hash(m_iterNdx));
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int						viewportX		= rnd.getInt(0, m_renderWidth - m_viewportWidth);
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int						viewportY		= rnd.getInt(0, m_renderHeight - m_viewportHeight);
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool						useFbo			= m_rtType != RENDERTARGETTYPE_DEFAULT;
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool						requiresResolve	= m_rtType == RENDERTARGETTYPE_MSAA_FBO;
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int						numQuads		= m_overdrawCount+1;
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TextureLevel					renderedImg		(TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8), m_viewportWidth, m_viewportHeight);
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<Vec4>					colors			(numQuads*4);
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (vector<Vec4>::iterator col = colors.begin(); col != colors.end(); ++col)
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		*col = randomColor(&rnd);
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render with GL.
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32		program				= m_program->getProgram();
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			posLoc				= gl.getAttribLocation(program, "a_position");
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			colorLoc			= gl.getAttribLocation(program, "a_color");
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glu::Buffer	indexBuffer			(renderCtx);
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glu::Buffer	positionBuffer		(renderCtx);
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glu::Buffer	colorBuffer			(renderCtx);
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vector<Vec2>		positions			(numQuads*4);
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vector<deUint16>	indices				(numQuads*6);
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint16		singleQuadIndices[]	= { 0, 2, 1, 1, 2, 3 };
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const Vec2			singleQuadPos[]		=
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec2(-1.0f, -1.0f),
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec2(-1.0f, +1.0f),
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec2(+1.0f, -1.0f),
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			Vec2(+1.0f, +1.0f),
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(posLoc >= 0 && colorLoc >= 0);
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int quadNdx = 0; quadNdx < numQuads; quadNdx++)
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			std::copy(DE_ARRAY_BEGIN(singleQuadPos), DE_ARRAY_END(singleQuadPos), &positions[quadNdx*4]);
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(singleQuadIndices); ndx++)
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				indices[quadNdx*6 + ndx] = (deUint16)(quadNdx*4 + singleQuadIndices[ndx]);
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (glw::GLsizeiptr)(indices.size()*sizeof(indices[0])), &indices[0], GL_STATIC_DRAW);
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, *positionBuffer);
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(positions.size()*sizeof(positions[0])), &positions[0], GL_STATIC_DRAW);
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.enableVertexAttribArray(posLoc);
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.vertexAttribPointer(posLoc, 2, GL_FLOAT, GL_FALSE, 0, DE_NULL);
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, *colorBuffer);
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(colors.size()*sizeof(colors[0])), &colors[0], GL_STATIC_DRAW);
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.enableVertexAttribArray(colorLoc);
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.vertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create buffers");
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.useProgram(program);
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.viewport(viewportX, viewportY, m_viewportWidth, m_viewportHeight);
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.blendEquation(m_blendMode);
42157c60b3189ce3ac3e738d715313313cd140ef87cJarkko Pöyry
42257c60b3189ce3ac3e738d715313313cd140ef87cJarkko Pöyry		// \note coherent extension enables GL_BLEND_ADVANCED_COHERENT_KHR by default
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_coherentBlending)
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.enable(GL_BLEND_ADVANCED_COHERENT_KHR);
42557c60b3189ce3ac3e738d715313313cd140ef87cJarkko Pöyry		else if (m_coherentExtensionSupported)
42657c60b3189ce3ac3e738d715313313cd140ef87cJarkko Pöyry			gl.disable(GL_BLEND_ADVANCED_COHERENT_KHR);
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to set render state");
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
430f8540a99d85b322eb826249746f08111f0137fa8Pyry Haulos		gl.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
431f8540a99d85b322eb826249746f08111f0137fa8Pyry Haulos
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.disable(GL_BLEND);
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, DE_NULL);
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.enable(GL_BLEND);
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
436f8540a99d85b322eb826249746f08111f0137fa8Pyry Haulos		if (!m_coherentBlending)
437f8540a99d85b322eb826249746f08111f0137fa8Pyry Haulos			gl.blendBarrierKHR();
438f8540a99d85b322eb826249746f08111f0137fa8Pyry Haulos
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_coherentBlending)
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, 6*(numQuads-1), GL_UNSIGNED_SHORT, (const void*)(deUintptr)(6*sizeof(deUint16)));
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int quadNdx = 1; quadNdx < numQuads; quadNdx++)
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (const void*)(deUintptr)(quadNdx*6*sizeof(deUint16)));
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.blendBarrierKHR();
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.flush();
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Render failed");
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Render reference.
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		rr::FragmentOperationState		referenceState;
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::PixelBufferAccess	colorAccess		= gls::FragmentOpUtil::getMultisampleAccess(m_refColorBuffer->getAccess());
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::PixelBufferAccess	nullAccess		(TextureFormat(), 0, 0, 0, DE_NULL);
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		IntegerQuad						quad;
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!useFbo && m_context.getRenderTarget().getPixelFormat().alphaBits == 0)
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Emulate lack of alpha by clearing to 1 and masking out alpha writes
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::clear(*m_refColorBuffer, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			referenceState.colorMask = tcu::BVec4(true, true, true, false);
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		referenceState.blendEquationAdvaced	= sglr::rr_util::mapGLBlendEquationAdvanced(m_blendMode);
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		quad.posA = tcu::IVec2(0, 0);
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		quad.posB = tcu::IVec2(m_viewportWidth-1, m_viewportHeight-1);
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int quadNdx = 0; quadNdx < numQuads; quadNdx++)
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			referenceState.blendMode = quadNdx == 0 ? rr::BLENDMODE_NONE : rr::BLENDMODE_ADVANCED;
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			std::copy(&colors[4*quadNdx], &colors[4*quadNdx] + 4, &quad.color[0]);
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_referenceRenderer->render(colorAccess, nullAccess /* no depth */, nullAccess /* no stencil */, quad, referenceState);
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (requiresResolve)
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_resolveFbo);
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.blitFramebuffer(0, 0, m_renderWidth, m_renderHeight, 0, 0, m_renderWidth, m_renderHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "Resolve blit failed");
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindFramebuffer(GL_READ_FRAMEBUFFER, m_resolveFbo);
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(renderCtx, viewportX, viewportY, renderedImg.getAccess());
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (requiresResolve)
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool	isHSLMode	= m_blendMode == GL_HSL_HUE_KHR			||
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  m_blendMode == GL_HSL_SATURATION_KHR	||
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  m_blendMode == GL_HSL_COLOR_KHR		||
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								  m_blendMode == GL_HSL_LUMINOSITY_KHR;
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		comparePass	= false;
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (isHSLMode)
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Compensate for more demanding HSL code by using fuzzy comparison.
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const float threshold = 0.002f;
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			comparePass = tcu::fuzzyCompare(m_testCtx.getLog(), "CompareResult", "Image Comparison Result",
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											getLinearAccess(m_refColorBuffer->getAccess()),
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											renderedImg.getAccess(),
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											threshold, tcu::COMPARE_LOG_RESULT);
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const UVec4 compareThreshold = (useFbo ? tcu::PixelFormat(8, 8, 8, 8) : m_context.getRenderTarget().getPixelFormat()).getColorThreshold().toIVec().asUint()
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									 * UVec4(5) / UVec4(2) + UVec4(3 * m_overdrawCount);
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			comparePass = tcu::bilinearCompare(m_testCtx.getLog(), "CompareResult", "Image Comparison Result",
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  getLinearAccess(m_refColorBuffer->getAccess()),
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  renderedImg.getAccess(),
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  tcu::RGBA(compareThreshold[0], compareThreshold[1], compareThreshold[2], compareThreshold[3]),
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											  tcu::COMPARE_LOG_RESULT);
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!comparePass)
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return STOP;
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_iterNdx += 1;
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_iterNdx < m_numIters)
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAdvancedBlendTests::AdvancedBlendTests (Context& context)
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "blend_equation_advanced", "GL_KHR_blend_equation_advanced Tests")
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5513c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAdvancedBlendTests::~AdvancedBlendTests (void)
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid AdvancedBlendTests::init (void)
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	mode;
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	name;
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} s_blendModes[] =
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_MULTIPLY_KHR,			"multiply"			},
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_SCREEN_KHR,			"screen"			},
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_OVERLAY_KHR,			"overlay"			},
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_DARKEN_KHR,			"darken"			},
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_LIGHTEN_KHR,			"lighten"			},
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_COLORDODGE_KHR,		"colordodge"		},
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_COLORBURN_KHR,			"colorburn"			},
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_HARDLIGHT_KHR,			"hardlight"			},
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_SOFTLIGHT_KHR,			"softlight"			},
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_DIFFERENCE_KHR,		"difference"		},
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_EXCLUSION_KHR,			"exclusion"			},
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_HSL_HUE_KHR,			"hsl_hue"			},
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_HSL_SATURATION_KHR,	"hsl_saturation"	},
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_HSL_COLOR_KHR,			"hsl_color"			},
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ GL_HSL_LUMINOSITY_KHR,	"hsl_luminosity"	}
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const	basicGroup			= new tcu::TestCaseGroup(m_testCtx, "basic",			"Single quad only");
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const	srgbGroup			= new tcu::TestCaseGroup(m_testCtx, "srgb",				"Advanced blending with sRGB FBO");
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const	msaaGroup			= new tcu::TestCaseGroup(m_testCtx, "msaa",				"Advanced blending with MSAA FBO");
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const	barrierGroup		= new tcu::TestCaseGroup(m_testCtx, "barrier",			"Multiple overlapping quads with blend barriers");
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const	coherentGroup		= new tcu::TestCaseGroup(m_testCtx, "coherent",			"Overlapping quads with coherent blending");
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const	coherentMsaaGroup	= new tcu::TestCaseGroup(m_testCtx, "coherent_msaa",	"Overlapping quads with coherent blending with MSAA FBO");
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(basicGroup);
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(srgbGroup);
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(msaaGroup);
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(barrierGroup);
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(coherentGroup);
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(coherentMsaaGroup);
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int modeNdx = 0; modeNdx < DE_LENGTH_OF_ARRAY(s_blendModes); modeNdx++)
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* const		name		= s_blendModes[modeNdx].name;
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* const		desc		= "";
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32			mode		= s_blendModes[modeNdx].mode;
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		basicGroup->addChild		(new AdvancedBlendCase(m_context, name, desc, mode, 1, false,	RENDERTARGETTYPE_DEFAULT));
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		srgbGroup->addChild			(new AdvancedBlendCase(m_context, name, desc, mode, 1, false,	RENDERTARGETTYPE_SRGB_FBO));
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		msaaGroup->addChild			(new AdvancedBlendCase(m_context, name, desc, mode, 1, false,	RENDERTARGETTYPE_MSAA_FBO));
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		barrierGroup->addChild		(new AdvancedBlendCase(m_context, name, desc, mode, 4, false,	RENDERTARGETTYPE_DEFAULT));
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		coherentGroup->addChild		(new AdvancedBlendCase(m_context, name, desc, mode, 4, true,	RENDERTARGETTYPE_DEFAULT));
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		coherentMsaaGroup->addChild	(new AdvancedBlendCase(m_context, name, desc, mode, 4, true,	RENDERTARGETTYPE_MSAA_FBO));
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles31
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
612