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