xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fAdvancedBlendTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Advanced blending (GL_KHR_blend_equation_advanced) tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es31fAdvancedBlendTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "glsFragmentOpUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "glsStateQueryUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluObjectWrapper.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluCallLogWrapper.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuPixelFormat.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "tcuStringTemplate.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "rrFragmentOperations.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceUtils.hpp"
45*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
46*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
47*35238bceSAndroid Build Coastguard Worker 
48*35238bceSAndroid Build Coastguard Worker #include <string>
49*35238bceSAndroid Build Coastguard Worker #include <vector>
50*35238bceSAndroid Build Coastguard Worker 
51*35238bceSAndroid Build Coastguard Worker namespace deqp
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker 
54*35238bceSAndroid Build Coastguard Worker using gls::FragmentOpUtil::IntegerQuad;
55*35238bceSAndroid Build Coastguard Worker using gls::FragmentOpUtil::ReferenceQuadRenderer;
56*35238bceSAndroid Build Coastguard Worker using std::map;
57*35238bceSAndroid Build Coastguard Worker using std::string;
58*35238bceSAndroid Build Coastguard Worker using std::vector;
59*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
60*35238bceSAndroid Build Coastguard Worker using tcu::TextureFormat;
61*35238bceSAndroid Build Coastguard Worker using tcu::TextureLevel;
62*35238bceSAndroid Build Coastguard Worker using tcu::UVec4;
63*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
64*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker namespace gles31
67*35238bceSAndroid Build Coastguard Worker {
68*35238bceSAndroid Build Coastguard Worker namespace Functional
69*35238bceSAndroid Build Coastguard Worker {
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker namespace
72*35238bceSAndroid Build Coastguard Worker {
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker enum
75*35238bceSAndroid Build Coastguard Worker {
76*35238bceSAndroid Build Coastguard Worker     MAX_VIEWPORT_WIDTH  = 128,
77*35238bceSAndroid Build Coastguard Worker     MAX_VIEWPORT_HEIGHT = 128
78*35238bceSAndroid Build Coastguard Worker };
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker enum RenderTargetType
81*35238bceSAndroid Build Coastguard Worker {
82*35238bceSAndroid Build Coastguard Worker     RENDERTARGETTYPE_DEFAULT = 0, //!< Default framebuffer
83*35238bceSAndroid Build Coastguard Worker     RENDERTARGETTYPE_SRGB_FBO,
84*35238bceSAndroid Build Coastguard Worker     RENDERTARGETTYPE_MSAA_FBO,
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker     RENDERTARGETTYPE_LAST
87*35238bceSAndroid Build Coastguard Worker };
88*35238bceSAndroid Build Coastguard Worker 
getEquationName(glw::GLenum equation)89*35238bceSAndroid Build Coastguard Worker static const char *getEquationName(glw::GLenum equation)
90*35238bceSAndroid Build Coastguard Worker {
91*35238bceSAndroid Build Coastguard Worker     switch (equation)
92*35238bceSAndroid Build Coastguard Worker     {
93*35238bceSAndroid Build Coastguard Worker     case GL_MULTIPLY:
94*35238bceSAndroid Build Coastguard Worker         return "multiply";
95*35238bceSAndroid Build Coastguard Worker     case GL_SCREEN:
96*35238bceSAndroid Build Coastguard Worker         return "screen";
97*35238bceSAndroid Build Coastguard Worker     case GL_OVERLAY:
98*35238bceSAndroid Build Coastguard Worker         return "overlay";
99*35238bceSAndroid Build Coastguard Worker     case GL_DARKEN:
100*35238bceSAndroid Build Coastguard Worker         return "darken";
101*35238bceSAndroid Build Coastguard Worker     case GL_LIGHTEN:
102*35238bceSAndroid Build Coastguard Worker         return "lighten";
103*35238bceSAndroid Build Coastguard Worker     case GL_COLORDODGE:
104*35238bceSAndroid Build Coastguard Worker         return "colordodge";
105*35238bceSAndroid Build Coastguard Worker     case GL_COLORBURN:
106*35238bceSAndroid Build Coastguard Worker         return "colorburn";
107*35238bceSAndroid Build Coastguard Worker     case GL_HARDLIGHT:
108*35238bceSAndroid Build Coastguard Worker         return "hardlight";
109*35238bceSAndroid Build Coastguard Worker     case GL_SOFTLIGHT:
110*35238bceSAndroid Build Coastguard Worker         return "softlight";
111*35238bceSAndroid Build Coastguard Worker     case GL_DIFFERENCE:
112*35238bceSAndroid Build Coastguard Worker         return "difference";
113*35238bceSAndroid Build Coastguard Worker     case GL_EXCLUSION:
114*35238bceSAndroid Build Coastguard Worker         return "exclusion";
115*35238bceSAndroid Build Coastguard Worker     case GL_HSL_HUE:
116*35238bceSAndroid Build Coastguard Worker         return "hsl_hue";
117*35238bceSAndroid Build Coastguard Worker     case GL_HSL_SATURATION:
118*35238bceSAndroid Build Coastguard Worker         return "hsl_saturation";
119*35238bceSAndroid Build Coastguard Worker     case GL_HSL_COLOR:
120*35238bceSAndroid Build Coastguard Worker         return "hsl_color";
121*35238bceSAndroid Build Coastguard Worker     case GL_HSL_LUMINOSITY:
122*35238bceSAndroid Build Coastguard Worker         return "hsl_luminosity";
123*35238bceSAndroid Build Coastguard Worker     default:
124*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
125*35238bceSAndroid Build Coastguard Worker         return DE_NULL;
126*35238bceSAndroid Build Coastguard Worker     }
127*35238bceSAndroid Build Coastguard Worker }
128*35238bceSAndroid Build Coastguard Worker 
129*35238bceSAndroid Build Coastguard Worker class AdvancedBlendCase : public TestCase
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker public:
132*35238bceSAndroid Build Coastguard Worker     AdvancedBlendCase(Context &context, const char *name, const char *desc, uint32_t mode, int overdrawCount,
133*35238bceSAndroid Build Coastguard Worker                       bool coherent, RenderTargetType rtType);
134*35238bceSAndroid Build Coastguard Worker 
135*35238bceSAndroid Build Coastguard Worker     ~AdvancedBlendCase(void);
136*35238bceSAndroid Build Coastguard Worker 
137*35238bceSAndroid Build Coastguard Worker     void init(void);
138*35238bceSAndroid Build Coastguard Worker     void deinit(void);
139*35238bceSAndroid Build Coastguard Worker 
140*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker private:
143*35238bceSAndroid Build Coastguard Worker     AdvancedBlendCase(const AdvancedBlendCase &);
144*35238bceSAndroid Build Coastguard Worker     AdvancedBlendCase &operator=(const AdvancedBlendCase &);
145*35238bceSAndroid Build Coastguard Worker 
146*35238bceSAndroid Build Coastguard Worker     const uint32_t m_blendMode;
147*35238bceSAndroid Build Coastguard Worker     const int m_overdrawCount;
148*35238bceSAndroid Build Coastguard Worker     const bool m_coherentBlending;
149*35238bceSAndroid Build Coastguard Worker     const RenderTargetType m_rtType;
150*35238bceSAndroid Build Coastguard Worker     const int m_numIters;
151*35238bceSAndroid Build Coastguard Worker 
152*35238bceSAndroid Build Coastguard Worker     bool m_coherentExtensionSupported;
153*35238bceSAndroid Build Coastguard Worker 
154*35238bceSAndroid Build Coastguard Worker     uint32_t m_colorRbo;
155*35238bceSAndroid Build Coastguard Worker     uint32_t m_fbo;
156*35238bceSAndroid Build Coastguard Worker 
157*35238bceSAndroid Build Coastguard Worker     uint32_t m_resolveColorRbo;
158*35238bceSAndroid Build Coastguard Worker     uint32_t m_resolveFbo;
159*35238bceSAndroid Build Coastguard Worker 
160*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgram *m_program;
161*35238bceSAndroid Build Coastguard Worker 
162*35238bceSAndroid Build Coastguard Worker     ReferenceQuadRenderer *m_referenceRenderer;
163*35238bceSAndroid Build Coastguard Worker     TextureLevel *m_refColorBuffer;
164*35238bceSAndroid Build Coastguard Worker 
165*35238bceSAndroid Build Coastguard Worker     const int m_renderWidth;
166*35238bceSAndroid Build Coastguard Worker     const int m_renderHeight;
167*35238bceSAndroid Build Coastguard Worker     const int m_viewportWidth;
168*35238bceSAndroid Build Coastguard Worker     const int m_viewportHeight;
169*35238bceSAndroid Build Coastguard Worker 
170*35238bceSAndroid Build Coastguard Worker     int m_iterNdx;
171*35238bceSAndroid Build Coastguard Worker };
172*35238bceSAndroid Build Coastguard Worker 
AdvancedBlendCase(Context & context,const char * name,const char * desc,uint32_t mode,int overdrawCount,bool coherent,RenderTargetType rtType)173*35238bceSAndroid Build Coastguard Worker AdvancedBlendCase::AdvancedBlendCase(Context &context, const char *name, const char *desc, uint32_t mode,
174*35238bceSAndroid Build Coastguard Worker                                      int overdrawCount, bool coherent, RenderTargetType rtType)
175*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, desc)
176*35238bceSAndroid Build Coastguard Worker     , m_blendMode(mode)
177*35238bceSAndroid Build Coastguard Worker     , m_overdrawCount(overdrawCount)
178*35238bceSAndroid Build Coastguard Worker     , m_coherentBlending(coherent)
179*35238bceSAndroid Build Coastguard Worker     , m_rtType(rtType)
180*35238bceSAndroid Build Coastguard Worker     , m_numIters(5)
181*35238bceSAndroid Build Coastguard Worker     , m_coherentExtensionSupported(false)
182*35238bceSAndroid Build Coastguard Worker     , m_colorRbo(0)
183*35238bceSAndroid Build Coastguard Worker     , m_fbo(0)
184*35238bceSAndroid Build Coastguard Worker     , m_resolveColorRbo(0)
185*35238bceSAndroid Build Coastguard Worker     , m_resolveFbo(0)
186*35238bceSAndroid Build Coastguard Worker     , m_program(DE_NULL)
187*35238bceSAndroid Build Coastguard Worker     , m_referenceRenderer(DE_NULL)
188*35238bceSAndroid Build Coastguard Worker     , m_refColorBuffer(DE_NULL)
189*35238bceSAndroid Build Coastguard Worker     , m_renderWidth(rtType != RENDERTARGETTYPE_DEFAULT ? 2 * MAX_VIEWPORT_WIDTH :
190*35238bceSAndroid Build Coastguard Worker                                                          m_context.getRenderTarget().getWidth())
191*35238bceSAndroid Build Coastguard Worker     , m_renderHeight(rtType != RENDERTARGETTYPE_DEFAULT ? 2 * MAX_VIEWPORT_HEIGHT :
192*35238bceSAndroid Build Coastguard Worker                                                           m_context.getRenderTarget().getHeight())
193*35238bceSAndroid Build Coastguard Worker     , m_viewportWidth(de::min<int>(m_renderWidth, MAX_VIEWPORT_WIDTH))
194*35238bceSAndroid Build Coastguard Worker     , m_viewportHeight(de::min<int>(m_renderHeight, MAX_VIEWPORT_HEIGHT))
195*35238bceSAndroid Build Coastguard Worker     , m_iterNdx(0)
196*35238bceSAndroid Build Coastguard Worker {
197*35238bceSAndroid Build Coastguard Worker }
198*35238bceSAndroid Build Coastguard Worker 
getBlendLayoutQualifier(rr::BlendEquationAdvanced equation)199*35238bceSAndroid Build Coastguard Worker const char *getBlendLayoutQualifier(rr::BlendEquationAdvanced equation)
200*35238bceSAndroid Build Coastguard Worker {
201*35238bceSAndroid Build Coastguard Worker     static const char *s_qualifiers[] = {
202*35238bceSAndroid Build Coastguard Worker         "blend_support_multiply",       "blend_support_screen",    "blend_support_overlay",
203*35238bceSAndroid Build Coastguard Worker         "blend_support_darken",         "blend_support_lighten",   "blend_support_colordodge",
204*35238bceSAndroid Build Coastguard Worker         "blend_support_colorburn",      "blend_support_hardlight", "blend_support_softlight",
205*35238bceSAndroid Build Coastguard Worker         "blend_support_difference",     "blend_support_exclusion", "blend_support_hsl_hue",
206*35238bceSAndroid Build Coastguard Worker         "blend_support_hsl_saturation", "blend_support_hsl_color", "blend_support_hsl_luminosity",
207*35238bceSAndroid Build Coastguard Worker     };
208*35238bceSAndroid Build Coastguard Worker     DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_qualifiers) == rr::BLENDEQUATION_ADVANCED_LAST);
209*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(de::inBounds<int>(equation, 0, rr::BLENDEQUATION_ADVANCED_LAST));
210*35238bceSAndroid Build Coastguard Worker     return s_qualifiers[equation];
211*35238bceSAndroid Build Coastguard Worker }
212*35238bceSAndroid Build Coastguard Worker 
getBlendProgramSrc(rr::BlendEquationAdvanced equation,glu::RenderContext & renderContext)213*35238bceSAndroid Build Coastguard Worker glu::ProgramSources getBlendProgramSrc(rr::BlendEquationAdvanced equation, glu::RenderContext &renderContext)
214*35238bceSAndroid Build Coastguard Worker {
215*35238bceSAndroid Build Coastguard Worker     const bool supportsES32 = glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2));
216*35238bceSAndroid Build Coastguard Worker 
217*35238bceSAndroid Build Coastguard Worker     static const char *s_vertSrc = "${GLSL_VERSION_DECL}\n"
218*35238bceSAndroid Build Coastguard Worker                                    "in highp vec4 a_position;\n"
219*35238bceSAndroid Build Coastguard Worker                                    "in mediump vec4 a_color;\n"
220*35238bceSAndroid Build Coastguard Worker                                    "out mediump vec4 v_color;\n"
221*35238bceSAndroid Build Coastguard Worker                                    "void main()\n"
222*35238bceSAndroid Build Coastguard Worker                                    "{\n"
223*35238bceSAndroid Build Coastguard Worker                                    "    gl_Position = a_position;\n"
224*35238bceSAndroid Build Coastguard Worker                                    "    v_color = a_color;\n"
225*35238bceSAndroid Build Coastguard Worker                                    "}\n";
226*35238bceSAndroid Build Coastguard Worker     static const char *s_fragSrc = "${GLSL_VERSION_DECL}\n"
227*35238bceSAndroid Build Coastguard Worker                                    "${EXTENSION}"
228*35238bceSAndroid Build Coastguard Worker                                    "in mediump vec4 v_color;\n"
229*35238bceSAndroid Build Coastguard Worker                                    "layout(${SUPPORT_QUALIFIER}) out;\n"
230*35238bceSAndroid Build Coastguard Worker                                    "layout(location = 0) out mediump vec4 o_color;\n"
231*35238bceSAndroid Build Coastguard Worker                                    "void main()\n"
232*35238bceSAndroid Build Coastguard Worker                                    "{\n"
233*35238bceSAndroid Build Coastguard Worker                                    "    o_color = v_color;\n"
234*35238bceSAndroid Build Coastguard Worker                                    "}\n";
235*35238bceSAndroid Build Coastguard Worker 
236*35238bceSAndroid Build Coastguard Worker     map<string, string> args;
237*35238bceSAndroid Build Coastguard Worker     args["GLSL_VERSION_DECL"] = supportsES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) :
238*35238bceSAndroid Build Coastguard Worker                                                getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
239*35238bceSAndroid Build Coastguard Worker     args["EXTENSION"]         = supportsES32 ? "\n" : "#extension GL_KHR_blend_equation_advanced : require\n";
240*35238bceSAndroid Build Coastguard Worker     args["SUPPORT_QUALIFIER"] = getBlendLayoutQualifier(equation);
241*35238bceSAndroid Build Coastguard Worker 
242*35238bceSAndroid Build Coastguard Worker     return glu::ProgramSources() << glu::VertexSource(tcu::StringTemplate(s_vertSrc).specialize(args))
243*35238bceSAndroid Build Coastguard Worker                                  << glu::FragmentSource(tcu::StringTemplate(s_fragSrc).specialize(args));
244*35238bceSAndroid Build Coastguard Worker }
245*35238bceSAndroid Build Coastguard Worker 
init(void)246*35238bceSAndroid Build Coastguard Worker void AdvancedBlendCase::init(void)
247*35238bceSAndroid Build Coastguard Worker {
248*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
249*35238bceSAndroid Build Coastguard Worker     const bool useFbo        = m_rtType != RENDERTARGETTYPE_DEFAULT;
250*35238bceSAndroid Build Coastguard Worker     const bool useSRGB       = m_rtType == RENDERTARGETTYPE_SRGB_FBO;
251*35238bceSAndroid Build Coastguard Worker 
252*35238bceSAndroid Build Coastguard Worker     m_coherentExtensionSupported =
253*35238bceSAndroid Build Coastguard Worker         m_context.getContextInfo().isExtensionSupported("GL_KHR_blend_equation_advanced_coherent");
254*35238bceSAndroid Build Coastguard Worker 
255*35238bceSAndroid Build Coastguard Worker     if (!glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::es(3, 2)))
256*35238bceSAndroid Build Coastguard Worker         if (!m_context.getContextInfo().isExtensionSupported("GL_KHR_blend_equation_advanced"))
257*35238bceSAndroid Build Coastguard Worker             TCU_THROW(NotSupportedError, "GL_KHR_blend_equation_advanced is not supported");
258*35238bceSAndroid Build Coastguard Worker 
259*35238bceSAndroid Build Coastguard Worker     if (m_coherentBlending && !m_coherentExtensionSupported)
260*35238bceSAndroid Build Coastguard Worker         TCU_THROW(NotSupportedError, "GL_KHR_blend_equation_advanced_coherent is not supported");
261*35238bceSAndroid Build Coastguard Worker 
262*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(gl.blendBarrier);
263*35238bceSAndroid Build Coastguard Worker 
264*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_program);
265*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_referenceRenderer);
266*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_refColorBuffer);
267*35238bceSAndroid Build Coastguard Worker 
268*35238bceSAndroid Build Coastguard Worker     m_program = new glu::ShaderProgram(
269*35238bceSAndroid Build Coastguard Worker         m_context.getRenderContext(),
270*35238bceSAndroid Build Coastguard Worker         getBlendProgramSrc(sglr::rr_util::mapGLBlendEquationAdvanced(m_blendMode), m_context.getRenderContext()));
271*35238bceSAndroid Build Coastguard Worker     m_testCtx.getLog() << *m_program;
272*35238bceSAndroid Build Coastguard Worker 
273*35238bceSAndroid Build Coastguard Worker     if (!m_program->isOk())
274*35238bceSAndroid Build Coastguard Worker     {
275*35238bceSAndroid Build Coastguard Worker         delete m_program;
276*35238bceSAndroid Build Coastguard Worker         m_program = DE_NULL;
277*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Compile failed");
278*35238bceSAndroid Build Coastguard Worker     }
279*35238bceSAndroid Build Coastguard Worker 
280*35238bceSAndroid Build Coastguard Worker     m_referenceRenderer = new ReferenceQuadRenderer;
281*35238bceSAndroid Build Coastguard Worker     m_refColorBuffer =
282*35238bceSAndroid Build Coastguard Worker         new TextureLevel(TextureFormat(useSRGB ? TextureFormat::sRGBA : TextureFormat::RGBA, TextureFormat::UNORM_INT8),
283*35238bceSAndroid Build Coastguard Worker                          m_viewportWidth, m_viewportHeight);
284*35238bceSAndroid Build Coastguard Worker 
285*35238bceSAndroid Build Coastguard Worker     if (useFbo)
286*35238bceSAndroid Build Coastguard Worker     {
287*35238bceSAndroid Build Coastguard Worker         const uint32_t format = useSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA8;
288*35238bceSAndroid Build Coastguard Worker         const int numSamples  = m_rtType == RENDERTARGETTYPE_MSAA_FBO ? 4 : 0;
289*35238bceSAndroid Build Coastguard Worker 
290*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "Using FBO of size (" << m_renderWidth << ", " << m_renderHeight
291*35238bceSAndroid Build Coastguard Worker                            << ") with format " << glu::getTextureFormatStr(format) << " and " << numSamples
292*35238bceSAndroid Build Coastguard Worker                            << " samples" << TestLog::EndMessage;
293*35238bceSAndroid Build Coastguard Worker 
294*35238bceSAndroid Build Coastguard Worker         gl.genRenderbuffers(1, &m_colorRbo);
295*35238bceSAndroid Build Coastguard Worker         gl.bindRenderbuffer(GL_RENDERBUFFER, m_colorRbo);
296*35238bceSAndroid Build Coastguard Worker         gl.renderbufferStorageMultisample(GL_RENDERBUFFER, numSamples, format, m_renderWidth, m_renderHeight);
297*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create color RBO");
298*35238bceSAndroid Build Coastguard Worker 
299*35238bceSAndroid Build Coastguard Worker         gl.genFramebuffers(1, &m_fbo);
300*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
301*35238bceSAndroid Build Coastguard Worker         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRbo);
302*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create FBO");
303*35238bceSAndroid Build Coastguard Worker 
304*35238bceSAndroid Build Coastguard Worker         TCU_CHECK(gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
305*35238bceSAndroid Build Coastguard Worker 
306*35238bceSAndroid Build Coastguard Worker         if (numSamples > 0)
307*35238bceSAndroid Build Coastguard Worker         {
308*35238bceSAndroid Build Coastguard Worker             // Create resolve FBO
309*35238bceSAndroid Build Coastguard Worker             gl.genRenderbuffers(1, &m_resolveColorRbo);
310*35238bceSAndroid Build Coastguard Worker             gl.bindRenderbuffer(GL_RENDERBUFFER, m_resolveColorRbo);
311*35238bceSAndroid Build Coastguard Worker             gl.renderbufferStorageMultisample(GL_RENDERBUFFER, 0, format, m_renderWidth, m_renderHeight);
312*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create resolve color RBO");
313*35238bceSAndroid Build Coastguard Worker 
314*35238bceSAndroid Build Coastguard Worker             gl.genFramebuffers(1, &m_resolveFbo);
315*35238bceSAndroid Build Coastguard Worker             gl.bindFramebuffer(GL_FRAMEBUFFER, m_resolveFbo);
316*35238bceSAndroid Build Coastguard Worker             gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_resolveColorRbo);
317*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create FBO");
318*35238bceSAndroid Build Coastguard Worker 
319*35238bceSAndroid Build Coastguard Worker             TCU_CHECK(gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
320*35238bceSAndroid Build Coastguard Worker 
321*35238bceSAndroid Build Coastguard Worker             gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
322*35238bceSAndroid Build Coastguard Worker         }
323*35238bceSAndroid Build Coastguard Worker 
324*35238bceSAndroid Build Coastguard Worker         if (glu::isContextTypeGLCore(m_context.getRenderContext().getType()) && useSRGB)
325*35238bceSAndroid Build Coastguard Worker             gl.enable(GL_FRAMEBUFFER_SRGB);
326*35238bceSAndroid Build Coastguard Worker     }
327*35238bceSAndroid Build Coastguard Worker     else
328*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_rtType == RENDERTARGETTYPE_DEFAULT);
329*35238bceSAndroid Build Coastguard Worker 
330*35238bceSAndroid Build Coastguard Worker     m_iterNdx = 0;
331*35238bceSAndroid Build Coastguard Worker }
332*35238bceSAndroid Build Coastguard Worker 
~AdvancedBlendCase(void)333*35238bceSAndroid Build Coastguard Worker AdvancedBlendCase::~AdvancedBlendCase(void)
334*35238bceSAndroid Build Coastguard Worker {
335*35238bceSAndroid Build Coastguard Worker     AdvancedBlendCase::deinit();
336*35238bceSAndroid Build Coastguard Worker }
337*35238bceSAndroid Build Coastguard Worker 
deinit(void)338*35238bceSAndroid Build Coastguard Worker void AdvancedBlendCase::deinit(void)
339*35238bceSAndroid Build Coastguard Worker {
340*35238bceSAndroid Build Coastguard Worker     delete m_program;
341*35238bceSAndroid Build Coastguard Worker     delete m_referenceRenderer;
342*35238bceSAndroid Build Coastguard Worker     delete m_refColorBuffer;
343*35238bceSAndroid Build Coastguard Worker 
344*35238bceSAndroid Build Coastguard Worker     m_program           = DE_NULL;
345*35238bceSAndroid Build Coastguard Worker     m_referenceRenderer = DE_NULL;
346*35238bceSAndroid Build Coastguard Worker     m_refColorBuffer    = DE_NULL;
347*35238bceSAndroid Build Coastguard Worker 
348*35238bceSAndroid Build Coastguard Worker     if (m_colorRbo || m_fbo)
349*35238bceSAndroid Build Coastguard Worker     {
350*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
351*35238bceSAndroid Build Coastguard Worker 
352*35238bceSAndroid Build Coastguard Worker         gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
353*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
354*35238bceSAndroid Build Coastguard Worker 
355*35238bceSAndroid Build Coastguard Worker         if (m_colorRbo != 0)
356*35238bceSAndroid Build Coastguard Worker         {
357*35238bceSAndroid Build Coastguard Worker             gl.deleteRenderbuffers(1, &m_colorRbo);
358*35238bceSAndroid Build Coastguard Worker             m_colorRbo = 0;
359*35238bceSAndroid Build Coastguard Worker         }
360*35238bceSAndroid Build Coastguard Worker 
361*35238bceSAndroid Build Coastguard Worker         if (m_fbo != 0)
362*35238bceSAndroid Build Coastguard Worker         {
363*35238bceSAndroid Build Coastguard Worker             gl.deleteFramebuffers(1, &m_fbo);
364*35238bceSAndroid Build Coastguard Worker             m_fbo = 0;
365*35238bceSAndroid Build Coastguard Worker         }
366*35238bceSAndroid Build Coastguard Worker 
367*35238bceSAndroid Build Coastguard Worker         if (m_resolveColorRbo)
368*35238bceSAndroid Build Coastguard Worker         {
369*35238bceSAndroid Build Coastguard Worker             gl.deleteRenderbuffers(1, &m_resolveColorRbo);
370*35238bceSAndroid Build Coastguard Worker             m_resolveColorRbo = 0;
371*35238bceSAndroid Build Coastguard Worker         }
372*35238bceSAndroid Build Coastguard Worker 
373*35238bceSAndroid Build Coastguard Worker         if (m_resolveFbo)
374*35238bceSAndroid Build Coastguard Worker         {
375*35238bceSAndroid Build Coastguard Worker             gl.deleteRenderbuffers(1, &m_resolveFbo);
376*35238bceSAndroid Build Coastguard Worker             m_resolveFbo = 0;
377*35238bceSAndroid Build Coastguard Worker         }
378*35238bceSAndroid Build Coastguard Worker 
379*35238bceSAndroid Build Coastguard Worker         if (glu::isContextTypeGLCore(m_context.getRenderContext().getType()) && RENDERTARGETTYPE_SRGB_FBO == m_rtType)
380*35238bceSAndroid Build Coastguard Worker             gl.disable(GL_FRAMEBUFFER_SRGB);
381*35238bceSAndroid Build Coastguard Worker     }
382*35238bceSAndroid Build Coastguard Worker }
383*35238bceSAndroid Build Coastguard Worker 
randomColor(de::Random * rnd)384*35238bceSAndroid Build Coastguard Worker static tcu::Vec4 randomColor(de::Random *rnd)
385*35238bceSAndroid Build Coastguard Worker {
386*35238bceSAndroid Build Coastguard Worker     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};
387*35238bceSAndroid Build Coastguard Worker     const float alphaValues[] = {0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f};
388*35238bceSAndroid Build Coastguard Worker 
389*35238bceSAndroid Build Coastguard Worker     // \note Spec assumes premultiplied inputs.
390*35238bceSAndroid Build Coastguard Worker     const float a = rnd->choose<float>(DE_ARRAY_BEGIN(alphaValues), DE_ARRAY_END(alphaValues));
391*35238bceSAndroid Build Coastguard Worker     const float r = a * rnd->choose<float>(DE_ARRAY_BEGIN(rgbValues), DE_ARRAY_END(rgbValues));
392*35238bceSAndroid Build Coastguard Worker     const float g = a * rnd->choose<float>(DE_ARRAY_BEGIN(rgbValues), DE_ARRAY_END(rgbValues));
393*35238bceSAndroid Build Coastguard Worker     const float b = a * rnd->choose<float>(DE_ARRAY_BEGIN(rgbValues), DE_ARRAY_END(rgbValues));
394*35238bceSAndroid Build Coastguard Worker     return tcu::Vec4(r, g, b, a);
395*35238bceSAndroid Build Coastguard Worker }
396*35238bceSAndroid Build Coastguard Worker 
getLinearAccess(const tcu::ConstPixelBufferAccess & access)397*35238bceSAndroid Build Coastguard Worker static tcu::ConstPixelBufferAccess getLinearAccess(const tcu::ConstPixelBufferAccess &access)
398*35238bceSAndroid Build Coastguard Worker {
399*35238bceSAndroid Build Coastguard Worker     if (access.getFormat().order == TextureFormat::sRGBA)
400*35238bceSAndroid Build Coastguard Worker         return tcu::ConstPixelBufferAccess(TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8),
401*35238bceSAndroid Build Coastguard Worker                                            access.getWidth(), access.getHeight(), access.getDepth(),
402*35238bceSAndroid Build Coastguard Worker                                            access.getRowPitch(), access.getSlicePitch(), access.getDataPtr());
403*35238bceSAndroid Build Coastguard Worker     else
404*35238bceSAndroid Build Coastguard Worker         return access;
405*35238bceSAndroid Build Coastguard Worker }
406*35238bceSAndroid Build Coastguard Worker 
iterate(void)407*35238bceSAndroid Build Coastguard Worker AdvancedBlendCase::IterateResult AdvancedBlendCase::iterate(void)
408*35238bceSAndroid Build Coastguard Worker {
409*35238bceSAndroid Build Coastguard Worker     const glu::RenderContext &renderCtx = m_context.getRenderContext();
410*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl            = renderCtx.getFunctions();
411*35238bceSAndroid Build Coastguard Worker     de::Random rnd(deStringHash(getName()) ^ deInt32Hash(m_iterNdx));
412*35238bceSAndroid Build Coastguard Worker     const int viewportX        = rnd.getInt(0, m_renderWidth - m_viewportWidth);
413*35238bceSAndroid Build Coastguard Worker     const int viewportY        = rnd.getInt(0, m_renderHeight - m_viewportHeight);
414*35238bceSAndroid Build Coastguard Worker     const bool useFbo          = m_rtType != RENDERTARGETTYPE_DEFAULT;
415*35238bceSAndroid Build Coastguard Worker     const bool requiresResolve = m_rtType == RENDERTARGETTYPE_MSAA_FBO;
416*35238bceSAndroid Build Coastguard Worker     const int numQuads         = m_overdrawCount + 1;
417*35238bceSAndroid Build Coastguard Worker     TextureLevel renderedImg(TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8), m_viewportWidth,
418*35238bceSAndroid Build Coastguard Worker                              m_viewportHeight);
419*35238bceSAndroid Build Coastguard Worker     vector<Vec4> colors(numQuads * 4);
420*35238bceSAndroid Build Coastguard Worker 
421*35238bceSAndroid Build Coastguard Worker     for (vector<Vec4>::iterator col = colors.begin(); col != colors.end(); ++col)
422*35238bceSAndroid Build Coastguard Worker         *col = randomColor(&rnd);
423*35238bceSAndroid Build Coastguard Worker 
424*35238bceSAndroid Build Coastguard Worker     // Render with GL.
425*35238bceSAndroid Build Coastguard Worker     {
426*35238bceSAndroid Build Coastguard Worker         const uint32_t program = m_program->getProgram();
427*35238bceSAndroid Build Coastguard Worker         const int posLoc       = gl.getAttribLocation(program, "a_position");
428*35238bceSAndroid Build Coastguard Worker         const int colorLoc     = gl.getAttribLocation(program, "a_color");
429*35238bceSAndroid Build Coastguard Worker         uint32_t vao           = 0;
430*35238bceSAndroid Build Coastguard Worker         const glu::Buffer indexBuffer(renderCtx);
431*35238bceSAndroid Build Coastguard Worker         const glu::Buffer positionBuffer(renderCtx);
432*35238bceSAndroid Build Coastguard Worker         const glu::Buffer colorBuffer(renderCtx);
433*35238bceSAndroid Build Coastguard Worker         vector<Vec2> positions(numQuads * 4);
434*35238bceSAndroid Build Coastguard Worker         vector<uint16_t> indices(numQuads * 6);
435*35238bceSAndroid Build Coastguard Worker         const uint16_t singleQuadIndices[] = {0, 2, 1, 1, 2, 3};
436*35238bceSAndroid Build Coastguard Worker         const Vec2 singleQuadPos[]         = {
437*35238bceSAndroid Build Coastguard Worker             Vec2(-1.0f, -1.0f),
438*35238bceSAndroid Build Coastguard Worker             Vec2(-1.0f, +1.0f),
439*35238bceSAndroid Build Coastguard Worker             Vec2(+1.0f, -1.0f),
440*35238bceSAndroid Build Coastguard Worker             Vec2(+1.0f, +1.0f),
441*35238bceSAndroid Build Coastguard Worker         };
442*35238bceSAndroid Build Coastguard Worker 
443*35238bceSAndroid Build Coastguard Worker         TCU_CHECK(posLoc >= 0 && colorLoc >= 0);
444*35238bceSAndroid Build Coastguard Worker 
445*35238bceSAndroid Build Coastguard Worker         for (int quadNdx = 0; quadNdx < numQuads; quadNdx++)
446*35238bceSAndroid Build Coastguard Worker         {
447*35238bceSAndroid Build Coastguard Worker             std::copy(DE_ARRAY_BEGIN(singleQuadPos), DE_ARRAY_END(singleQuadPos), &positions[quadNdx * 4]);
448*35238bceSAndroid Build Coastguard Worker             for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(singleQuadIndices); ndx++)
449*35238bceSAndroid Build Coastguard Worker                 indices[quadNdx * 6 + ndx] = (uint16_t)(quadNdx * 4 + singleQuadIndices[ndx]);
450*35238bceSAndroid Build Coastguard Worker         }
451*35238bceSAndroid Build Coastguard Worker 
452*35238bceSAndroid Build Coastguard Worker         if (!glu::isContextTypeES(renderCtx.getType()))
453*35238bceSAndroid Build Coastguard Worker         {
454*35238bceSAndroid Build Coastguard Worker             gl.genVertexArrays(1, &vao);
455*35238bceSAndroid Build Coastguard Worker             gl.bindVertexArray(vao);
456*35238bceSAndroid Build Coastguard Worker         }
457*35238bceSAndroid Build Coastguard Worker 
458*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
459*35238bceSAndroid Build Coastguard Worker         gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (glw::GLsizeiptr)(indices.size() * sizeof(indices[0])), &indices[0],
460*35238bceSAndroid Build Coastguard Worker                       GL_STATIC_DRAW);
461*35238bceSAndroid Build Coastguard Worker 
462*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ARRAY_BUFFER, *positionBuffer);
463*35238bceSAndroid Build Coastguard Worker         gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(positions.size() * sizeof(positions[0])), &positions[0],
464*35238bceSAndroid Build Coastguard Worker                       GL_STATIC_DRAW);
465*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(posLoc);
466*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(posLoc, 2, GL_FLOAT, GL_FALSE, 0, DE_NULL);
467*35238bceSAndroid Build Coastguard Worker 
468*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ARRAY_BUFFER, *colorBuffer);
469*35238bceSAndroid Build Coastguard Worker         gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(colors.size() * sizeof(colors[0])), &colors[0],
470*35238bceSAndroid Build Coastguard Worker                       GL_STATIC_DRAW);
471*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(colorLoc);
472*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
473*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create buffers");
474*35238bceSAndroid Build Coastguard Worker 
475*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program);
476*35238bceSAndroid Build Coastguard Worker         gl.viewport(viewportX, viewportY, m_viewportWidth, m_viewportHeight);
477*35238bceSAndroid Build Coastguard Worker         gl.blendEquation(m_blendMode);
478*35238bceSAndroid Build Coastguard Worker 
479*35238bceSAndroid Build Coastguard Worker         // \note coherent extension enables GL_BLEND_ADVANCED_COHERENT_KHR by default
480*35238bceSAndroid Build Coastguard Worker         if (m_coherentBlending)
481*35238bceSAndroid Build Coastguard Worker             gl.enable(GL_BLEND_ADVANCED_COHERENT_KHR);
482*35238bceSAndroid Build Coastguard Worker         else if (m_coherentExtensionSupported)
483*35238bceSAndroid Build Coastguard Worker             gl.disable(GL_BLEND_ADVANCED_COHERENT_KHR);
484*35238bceSAndroid Build Coastguard Worker 
485*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to set render state");
486*35238bceSAndroid Build Coastguard Worker 
487*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
488*35238bceSAndroid Build Coastguard Worker 
489*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_BLEND);
490*35238bceSAndroid Build Coastguard Worker         gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, DE_NULL);
491*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_BLEND);
492*35238bceSAndroid Build Coastguard Worker 
493*35238bceSAndroid Build Coastguard Worker         if (!m_coherentBlending)
494*35238bceSAndroid Build Coastguard Worker             gl.blendBarrier();
495*35238bceSAndroid Build Coastguard Worker 
496*35238bceSAndroid Build Coastguard Worker         if (m_coherentBlending)
497*35238bceSAndroid Build Coastguard Worker         {
498*35238bceSAndroid Build Coastguard Worker             gl.drawElements(GL_TRIANGLES, 6 * (numQuads - 1), GL_UNSIGNED_SHORT,
499*35238bceSAndroid Build Coastguard Worker                             (const void *)(uintptr_t)(6 * sizeof(uint16_t)));
500*35238bceSAndroid Build Coastguard Worker         }
501*35238bceSAndroid Build Coastguard Worker         else
502*35238bceSAndroid Build Coastguard Worker         {
503*35238bceSAndroid Build Coastguard Worker             for (int quadNdx = 1; quadNdx < numQuads; quadNdx++)
504*35238bceSAndroid Build Coastguard Worker             {
505*35238bceSAndroid Build Coastguard Worker                 gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
506*35238bceSAndroid Build Coastguard Worker                                 (const void *)(uintptr_t)(quadNdx * 6 * sizeof(uint16_t)));
507*35238bceSAndroid Build Coastguard Worker                 gl.blendBarrier();
508*35238bceSAndroid Build Coastguard Worker             }
509*35238bceSAndroid Build Coastguard Worker         }
510*35238bceSAndroid Build Coastguard Worker 
511*35238bceSAndroid Build Coastguard Worker         if (vao)
512*35238bceSAndroid Build Coastguard Worker             gl.deleteVertexArrays(1, &vao);
513*35238bceSAndroid Build Coastguard Worker 
514*35238bceSAndroid Build Coastguard Worker         gl.flush();
515*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Render failed");
516*35238bceSAndroid Build Coastguard Worker     }
517*35238bceSAndroid Build Coastguard Worker 
518*35238bceSAndroid Build Coastguard Worker     // Render reference.
519*35238bceSAndroid Build Coastguard Worker     {
520*35238bceSAndroid Build Coastguard Worker         rr::FragmentOperationState referenceState;
521*35238bceSAndroid Build Coastguard Worker         const tcu::PixelBufferAccess colorAccess =
522*35238bceSAndroid Build Coastguard Worker             gls::FragmentOpUtil::getMultisampleAccess(m_refColorBuffer->getAccess());
523*35238bceSAndroid Build Coastguard Worker         const tcu::PixelBufferAccess nullAccess = tcu::PixelBufferAccess();
524*35238bceSAndroid Build Coastguard Worker         IntegerQuad quad;
525*35238bceSAndroid Build Coastguard Worker 
526*35238bceSAndroid Build Coastguard Worker         if (!useFbo && m_context.getRenderTarget().getPixelFormat().alphaBits == 0)
527*35238bceSAndroid Build Coastguard Worker         {
528*35238bceSAndroid Build Coastguard Worker             // Emulate lack of alpha by clearing to 1 and masking out alpha writes
529*35238bceSAndroid Build Coastguard Worker             tcu::clear(*m_refColorBuffer, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
530*35238bceSAndroid Build Coastguard Worker             referenceState.colorMask = tcu::BVec4(true, true, true, false);
531*35238bceSAndroid Build Coastguard Worker         }
532*35238bceSAndroid Build Coastguard Worker 
533*35238bceSAndroid Build Coastguard Worker         referenceState.blendEquationAdvaced = sglr::rr_util::mapGLBlendEquationAdvanced(m_blendMode);
534*35238bceSAndroid Build Coastguard Worker 
535*35238bceSAndroid Build Coastguard Worker         quad.posA = tcu::IVec2(0, 0);
536*35238bceSAndroid Build Coastguard Worker         quad.posB = tcu::IVec2(m_viewportWidth - 1, m_viewportHeight - 1);
537*35238bceSAndroid Build Coastguard Worker 
538*35238bceSAndroid Build Coastguard Worker         for (int quadNdx = 0; quadNdx < numQuads; quadNdx++)
539*35238bceSAndroid Build Coastguard Worker         {
540*35238bceSAndroid Build Coastguard Worker             referenceState.blendMode = quadNdx == 0 ? rr::BLENDMODE_NONE : rr::BLENDMODE_ADVANCED;
541*35238bceSAndroid Build Coastguard Worker             std::copy(&colors[4 * quadNdx], &colors[4 * quadNdx] + 4, &quad.color[0]);
542*35238bceSAndroid Build Coastguard Worker             m_referenceRenderer->render(colorAccess, nullAccess /* no depth */, nullAccess /* no stencil */, quad,
543*35238bceSAndroid Build Coastguard Worker                                         referenceState);
544*35238bceSAndroid Build Coastguard Worker         }
545*35238bceSAndroid Build Coastguard Worker     }
546*35238bceSAndroid Build Coastguard Worker 
547*35238bceSAndroid Build Coastguard Worker     if (requiresResolve)
548*35238bceSAndroid Build Coastguard Worker     {
549*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_resolveFbo);
550*35238bceSAndroid Build Coastguard Worker         gl.blitFramebuffer(0, 0, m_renderWidth, m_renderHeight, 0, 0, m_renderWidth, m_renderHeight,
551*35238bceSAndroid Build Coastguard Worker                            GL_COLOR_BUFFER_BIT, GL_NEAREST);
552*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Resolve blit failed");
553*35238bceSAndroid Build Coastguard Worker 
554*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_READ_FRAMEBUFFER, m_resolveFbo);
555*35238bceSAndroid Build Coastguard Worker     }
556*35238bceSAndroid Build Coastguard Worker 
557*35238bceSAndroid Build Coastguard Worker     glu::readPixels(renderCtx, viewportX, viewportY, renderedImg.getAccess());
558*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels()");
559*35238bceSAndroid Build Coastguard Worker 
560*35238bceSAndroid Build Coastguard Worker     if (requiresResolve)
561*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
562*35238bceSAndroid Build Coastguard Worker 
563*35238bceSAndroid Build Coastguard Worker     {
564*35238bceSAndroid Build Coastguard Worker         const bool isHSLMode = m_blendMode == GL_HSL_HUE || m_blendMode == GL_HSL_SATURATION ||
565*35238bceSAndroid Build Coastguard Worker                                m_blendMode == GL_HSL_COLOR || m_blendMode == GL_HSL_LUMINOSITY;
566*35238bceSAndroid Build Coastguard Worker         bool comparePass = false;
567*35238bceSAndroid Build Coastguard Worker 
568*35238bceSAndroid Build Coastguard Worker         if (isHSLMode)
569*35238bceSAndroid Build Coastguard Worker         {
570*35238bceSAndroid Build Coastguard Worker             // Compensate for more demanding HSL code by using fuzzy comparison.
571*35238bceSAndroid Build Coastguard Worker             const float threshold = 0.002f;
572*35238bceSAndroid Build Coastguard Worker             comparePass           = tcu::fuzzyCompare(m_testCtx.getLog(), "CompareResult", "Image Comparison Result",
573*35238bceSAndroid Build Coastguard Worker                                                       getLinearAccess(m_refColorBuffer->getAccess()), renderedImg.getAccess(),
574*35238bceSAndroid Build Coastguard Worker                                                       threshold, tcu::COMPARE_LOG_RESULT);
575*35238bceSAndroid Build Coastguard Worker         }
576*35238bceSAndroid Build Coastguard Worker         else
577*35238bceSAndroid Build Coastguard Worker         {
578*35238bceSAndroid Build Coastguard Worker             const UVec4 compareThreshold =
579*35238bceSAndroid Build Coastguard Worker                 (useFbo ? tcu::PixelFormat(8, 8, 8, 8) : m_context.getRenderTarget().getPixelFormat())
580*35238bceSAndroid Build Coastguard Worker                         .getColorThreshold()
581*35238bceSAndroid Build Coastguard Worker                         .toIVec()
582*35238bceSAndroid Build Coastguard Worker                         .asUint() *
583*35238bceSAndroid Build Coastguard Worker                     UVec4(5) / UVec4(2) +
584*35238bceSAndroid Build Coastguard Worker                 UVec4(3 * m_overdrawCount);
585*35238bceSAndroid Build Coastguard Worker 
586*35238bceSAndroid Build Coastguard Worker             comparePass = tcu::bilinearCompare(
587*35238bceSAndroid Build Coastguard Worker                 m_testCtx.getLog(), "CompareResult", "Image Comparison Result",
588*35238bceSAndroid Build Coastguard Worker                 getLinearAccess(m_refColorBuffer->getAccess()), renderedImg.getAccess(),
589*35238bceSAndroid Build Coastguard Worker                 tcu::RGBA(compareThreshold[0], compareThreshold[1], compareThreshold[2], compareThreshold[3]),
590*35238bceSAndroid Build Coastguard Worker                 tcu::COMPARE_LOG_RESULT);
591*35238bceSAndroid Build Coastguard Worker         }
592*35238bceSAndroid Build Coastguard Worker 
593*35238bceSAndroid Build Coastguard Worker         if (!comparePass)
594*35238bceSAndroid Build Coastguard Worker         {
595*35238bceSAndroid Build Coastguard Worker             m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
596*35238bceSAndroid Build Coastguard Worker             return STOP;
597*35238bceSAndroid Build Coastguard Worker         }
598*35238bceSAndroid Build Coastguard Worker     }
599*35238bceSAndroid Build Coastguard Worker 
600*35238bceSAndroid Build Coastguard Worker     m_iterNdx += 1;
601*35238bceSAndroid Build Coastguard Worker 
602*35238bceSAndroid Build Coastguard Worker     if (m_iterNdx < m_numIters)
603*35238bceSAndroid Build Coastguard Worker         return CONTINUE;
604*35238bceSAndroid Build Coastguard Worker     else
605*35238bceSAndroid Build Coastguard Worker     {
606*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
607*35238bceSAndroid Build Coastguard Worker         return STOP;
608*35238bceSAndroid Build Coastguard Worker     }
609*35238bceSAndroid Build Coastguard Worker }
610*35238bceSAndroid Build Coastguard Worker 
611*35238bceSAndroid Build Coastguard Worker class BlendAdvancedCoherentStateCase : public TestCase
612*35238bceSAndroid Build Coastguard Worker {
613*35238bceSAndroid Build Coastguard Worker public:
614*35238bceSAndroid Build Coastguard Worker     BlendAdvancedCoherentStateCase(Context &context, const char *name, const char *description,
615*35238bceSAndroid Build Coastguard Worker                                    gls::StateQueryUtil::QueryType type);
616*35238bceSAndroid Build Coastguard Worker 
617*35238bceSAndroid Build Coastguard Worker private:
618*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
619*35238bceSAndroid Build Coastguard Worker 
620*35238bceSAndroid Build Coastguard Worker     const gls::StateQueryUtil::QueryType m_type;
621*35238bceSAndroid Build Coastguard Worker };
622*35238bceSAndroid Build Coastguard Worker 
BlendAdvancedCoherentStateCase(Context & context,const char * name,const char * description,gls::StateQueryUtil::QueryType type)623*35238bceSAndroid Build Coastguard Worker BlendAdvancedCoherentStateCase::BlendAdvancedCoherentStateCase(Context &context, const char *name,
624*35238bceSAndroid Build Coastguard Worker                                                                const char *description,
625*35238bceSAndroid Build Coastguard Worker                                                                gls::StateQueryUtil::QueryType type)
626*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
627*35238bceSAndroid Build Coastguard Worker     , m_type(type)
628*35238bceSAndroid Build Coastguard Worker {
629*35238bceSAndroid Build Coastguard Worker }
630*35238bceSAndroid Build Coastguard Worker 
iterate(void)631*35238bceSAndroid Build Coastguard Worker BlendAdvancedCoherentStateCase::IterateResult BlendAdvancedCoherentStateCase::iterate(void)
632*35238bceSAndroid Build Coastguard Worker {
633*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_AND_THROW(NotSupportedError,
634*35238bceSAndroid Build Coastguard Worker                         m_context.getContextInfo().isExtensionSupported("GL_KHR_blend_equation_advanced_coherent"),
635*35238bceSAndroid Build Coastguard Worker                         "GL_KHR_blend_equation_advanced_coherent is not supported");
636*35238bceSAndroid Build Coastguard Worker 
637*35238bceSAndroid Build Coastguard Worker     glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
638*35238bceSAndroid Build Coastguard Worker     tcu::ResultCollector result(m_testCtx.getLog(), " // ERROR: ");
639*35238bceSAndroid Build Coastguard Worker 
640*35238bceSAndroid Build Coastguard Worker     gl.enableLogging(true);
641*35238bceSAndroid Build Coastguard Worker 
642*35238bceSAndroid Build Coastguard Worker     // check inital value
643*35238bceSAndroid Build Coastguard Worker     {
644*35238bceSAndroid Build Coastguard Worker         const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
645*35238bceSAndroid Build Coastguard Worker         gls::StateQueryUtil::verifyStateBoolean(result, gl, GL_BLEND_ADVANCED_COHERENT_KHR, true, m_type);
646*35238bceSAndroid Build Coastguard Worker     }
647*35238bceSAndroid Build Coastguard Worker 
648*35238bceSAndroid Build Coastguard Worker     // check toggle
649*35238bceSAndroid Build Coastguard Worker     {
650*35238bceSAndroid Build Coastguard Worker         const tcu::ScopedLogSection section(m_testCtx.getLog(), "Toggle", "Toggle");
651*35238bceSAndroid Build Coastguard Worker         gl.glDisable(GL_BLEND_ADVANCED_COHERENT_KHR);
652*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.glGetError(), "glDisable");
653*35238bceSAndroid Build Coastguard Worker 
654*35238bceSAndroid Build Coastguard Worker         gls::StateQueryUtil::verifyStateBoolean(result, gl, GL_BLEND_ADVANCED_COHERENT_KHR, false, m_type);
655*35238bceSAndroid Build Coastguard Worker 
656*35238bceSAndroid Build Coastguard Worker         gl.glEnable(GL_BLEND_ADVANCED_COHERENT_KHR);
657*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.glGetError(), "glEnable");
658*35238bceSAndroid Build Coastguard Worker 
659*35238bceSAndroid Build Coastguard Worker         gls::StateQueryUtil::verifyStateBoolean(result, gl, GL_BLEND_ADVANCED_COHERENT_KHR, true, m_type);
660*35238bceSAndroid Build Coastguard Worker     }
661*35238bceSAndroid Build Coastguard Worker 
662*35238bceSAndroid Build Coastguard Worker     result.setTestContextResult(m_testCtx);
663*35238bceSAndroid Build Coastguard Worker     return STOP;
664*35238bceSAndroid Build Coastguard Worker }
665*35238bceSAndroid Build Coastguard Worker 
666*35238bceSAndroid Build Coastguard Worker class BlendEquationStateCase : public TestCase
667*35238bceSAndroid Build Coastguard Worker {
668*35238bceSAndroid Build Coastguard Worker public:
669*35238bceSAndroid Build Coastguard Worker     BlendEquationStateCase(Context &context, const char *name, const char *description, const glw::GLenum *equations,
670*35238bceSAndroid Build Coastguard Worker                            int numEquations, gls::StateQueryUtil::QueryType type);
671*35238bceSAndroid Build Coastguard Worker 
672*35238bceSAndroid Build Coastguard Worker private:
673*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
674*35238bceSAndroid Build Coastguard Worker 
675*35238bceSAndroid Build Coastguard Worker     const gls::StateQueryUtil::QueryType m_type;
676*35238bceSAndroid Build Coastguard Worker     const glw::GLenum *m_equations;
677*35238bceSAndroid Build Coastguard Worker     const int m_numEquations;
678*35238bceSAndroid Build Coastguard Worker };
679*35238bceSAndroid Build Coastguard Worker 
BlendEquationStateCase(Context & context,const char * name,const char * description,const glw::GLenum * equations,int numEquations,gls::StateQueryUtil::QueryType type)680*35238bceSAndroid Build Coastguard Worker BlendEquationStateCase::BlendEquationStateCase(Context &context, const char *name, const char *description,
681*35238bceSAndroid Build Coastguard Worker                                                const glw::GLenum *equations, int numEquations,
682*35238bceSAndroid Build Coastguard Worker                                                gls::StateQueryUtil::QueryType type)
683*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
684*35238bceSAndroid Build Coastguard Worker     , m_type(type)
685*35238bceSAndroid Build Coastguard Worker     , m_equations(equations)
686*35238bceSAndroid Build Coastguard Worker     , m_numEquations(numEquations)
687*35238bceSAndroid Build Coastguard Worker {
688*35238bceSAndroid Build Coastguard Worker }
689*35238bceSAndroid Build Coastguard Worker 
iterate(void)690*35238bceSAndroid Build Coastguard Worker BlendEquationStateCase::IterateResult BlendEquationStateCase::iterate(void)
691*35238bceSAndroid Build Coastguard Worker {
692*35238bceSAndroid Build Coastguard Worker     if (!glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::es(3, 2)))
693*35238bceSAndroid Build Coastguard Worker         TCU_CHECK_AND_THROW(NotSupportedError,
694*35238bceSAndroid Build Coastguard Worker                             m_context.getContextInfo().isExtensionSupported("GL_KHR_blend_equation_advanced"),
695*35238bceSAndroid Build Coastguard Worker                             "GL_KHR_blend_equation_advanced is not supported");
696*35238bceSAndroid Build Coastguard Worker 
697*35238bceSAndroid Build Coastguard Worker     glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
698*35238bceSAndroid Build Coastguard Worker     tcu::ResultCollector result(m_testCtx.getLog(), " // ERROR: ");
699*35238bceSAndroid Build Coastguard Worker 
700*35238bceSAndroid Build Coastguard Worker     gl.enableLogging(true);
701*35238bceSAndroid Build Coastguard Worker 
702*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < m_numEquations; ++ndx)
703*35238bceSAndroid Build Coastguard Worker     {
704*35238bceSAndroid Build Coastguard Worker         const tcu::ScopedLogSection section(m_testCtx.getLog(), "Type",
705*35238bceSAndroid Build Coastguard Worker                                             "Test " + de::toString(glu::getBlendEquationStr(m_equations[ndx])));
706*35238bceSAndroid Build Coastguard Worker 
707*35238bceSAndroid Build Coastguard Worker         gl.glBlendEquation(m_equations[ndx]);
708*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.glGetError(), "glBlendEquation");
709*35238bceSAndroid Build Coastguard Worker 
710*35238bceSAndroid Build Coastguard Worker         gls::StateQueryUtil::verifyStateInteger(result, gl, GL_BLEND_EQUATION, m_equations[ndx], m_type);
711*35238bceSAndroid Build Coastguard Worker     }
712*35238bceSAndroid Build Coastguard Worker 
713*35238bceSAndroid Build Coastguard Worker     result.setTestContextResult(m_testCtx);
714*35238bceSAndroid Build Coastguard Worker     return STOP;
715*35238bceSAndroid Build Coastguard Worker }
716*35238bceSAndroid Build Coastguard Worker 
717*35238bceSAndroid Build Coastguard Worker class BlendEquationIndexedStateCase : public TestCase
718*35238bceSAndroid Build Coastguard Worker {
719*35238bceSAndroid Build Coastguard Worker public:
720*35238bceSAndroid Build Coastguard Worker     BlendEquationIndexedStateCase(Context &context, const char *name, const char *description,
721*35238bceSAndroid Build Coastguard Worker                                   const glw::GLenum *equations, int numEquations, gls::StateQueryUtil::QueryType type);
722*35238bceSAndroid Build Coastguard Worker 
723*35238bceSAndroid Build Coastguard Worker private:
724*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
725*35238bceSAndroid Build Coastguard Worker 
726*35238bceSAndroid Build Coastguard Worker     const gls::StateQueryUtil::QueryType m_type;
727*35238bceSAndroid Build Coastguard Worker     const glw::GLenum *m_equations;
728*35238bceSAndroid Build Coastguard Worker     const int m_numEquations;
729*35238bceSAndroid Build Coastguard Worker };
730*35238bceSAndroid Build Coastguard Worker 
BlendEquationIndexedStateCase(Context & context,const char * name,const char * description,const glw::GLenum * equations,int numEquations,gls::StateQueryUtil::QueryType type)731*35238bceSAndroid Build Coastguard Worker BlendEquationIndexedStateCase::BlendEquationIndexedStateCase(Context &context, const char *name,
732*35238bceSAndroid Build Coastguard Worker                                                              const char *description, const glw::GLenum *equations,
733*35238bceSAndroid Build Coastguard Worker                                                              int numEquations, gls::StateQueryUtil::QueryType type)
734*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
735*35238bceSAndroid Build Coastguard Worker     , m_type(type)
736*35238bceSAndroid Build Coastguard Worker     , m_equations(equations)
737*35238bceSAndroid Build Coastguard Worker     , m_numEquations(numEquations)
738*35238bceSAndroid Build Coastguard Worker {
739*35238bceSAndroid Build Coastguard Worker }
740*35238bceSAndroid Build Coastguard Worker 
iterate(void)741*35238bceSAndroid Build Coastguard Worker BlendEquationIndexedStateCase::IterateResult BlendEquationIndexedStateCase::iterate(void)
742*35238bceSAndroid Build Coastguard Worker {
743*35238bceSAndroid Build Coastguard Worker     const auto &renderContext = m_context.getRenderContext();
744*35238bceSAndroid Build Coastguard Worker     if (!glu::contextSupports(renderContext.getType(), glu::ApiType::es(3, 2)) &&
745*35238bceSAndroid Build Coastguard Worker         !glu::contextSupports(renderContext.getType(), glu::ApiType::core(4, 5)))
746*35238bceSAndroid Build Coastguard Worker     {
747*35238bceSAndroid Build Coastguard Worker         TCU_CHECK_AND_THROW(NotSupportedError,
748*35238bceSAndroid Build Coastguard Worker                             m_context.getContextInfo().isExtensionSupported("GL_KHR_blend_equation_advanced"),
749*35238bceSAndroid Build Coastguard Worker                             "GL_KHR_blend_equation_advanced is not supported");
750*35238bceSAndroid Build Coastguard Worker         TCU_CHECK_AND_THROW(NotSupportedError,
751*35238bceSAndroid Build Coastguard Worker                             m_context.getContextInfo().isExtensionSupported("GL_EXT_draw_buffers_indexed"),
752*35238bceSAndroid Build Coastguard Worker                             "GL_EXT_draw_buffers_indexed is not supported");
753*35238bceSAndroid Build Coastguard Worker     }
754*35238bceSAndroid Build Coastguard Worker 
755*35238bceSAndroid Build Coastguard Worker     glu::CallLogWrapper gl(renderContext.getFunctions(), m_testCtx.getLog());
756*35238bceSAndroid Build Coastguard Worker     tcu::ResultCollector result(m_testCtx.getLog(), " // ERROR: ");
757*35238bceSAndroid Build Coastguard Worker 
758*35238bceSAndroid Build Coastguard Worker     gl.enableLogging(true);
759*35238bceSAndroid Build Coastguard Worker 
760*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < m_numEquations; ++ndx)
761*35238bceSAndroid Build Coastguard Worker     {
762*35238bceSAndroid Build Coastguard Worker         const tcu::ScopedLogSection section(m_testCtx.getLog(), "Type",
763*35238bceSAndroid Build Coastguard Worker                                             "Test " + de::toString(glu::getBlendEquationStr(m_equations[ndx])));
764*35238bceSAndroid Build Coastguard Worker 
765*35238bceSAndroid Build Coastguard Worker         gl.glBlendEquationi(2, m_equations[ndx]);
766*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.glGetError(), "glBlendEquationi");
767*35238bceSAndroid Build Coastguard Worker 
768*35238bceSAndroid Build Coastguard Worker         gls::StateQueryUtil::verifyStateIndexedInteger(result, gl, GL_BLEND_EQUATION, 2, m_equations[ndx], m_type);
769*35238bceSAndroid Build Coastguard Worker     }
770*35238bceSAndroid Build Coastguard Worker 
771*35238bceSAndroid Build Coastguard Worker     result.setTestContextResult(m_testCtx);
772*35238bceSAndroid Build Coastguard Worker     return STOP;
773*35238bceSAndroid Build Coastguard Worker }
774*35238bceSAndroid Build Coastguard Worker 
775*35238bceSAndroid Build Coastguard Worker } // namespace
776*35238bceSAndroid Build Coastguard Worker 
AdvancedBlendTests(Context & context)777*35238bceSAndroid Build Coastguard Worker AdvancedBlendTests::AdvancedBlendTests(Context &context)
778*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "blend_equation_advanced", "GL_blend_equation_advanced Tests")
779*35238bceSAndroid Build Coastguard Worker {
780*35238bceSAndroid Build Coastguard Worker }
781*35238bceSAndroid Build Coastguard Worker 
~AdvancedBlendTests(void)782*35238bceSAndroid Build Coastguard Worker AdvancedBlendTests::~AdvancedBlendTests(void)
783*35238bceSAndroid Build Coastguard Worker {
784*35238bceSAndroid Build Coastguard Worker }
785*35238bceSAndroid Build Coastguard Worker 
init(void)786*35238bceSAndroid Build Coastguard Worker void AdvancedBlendTests::init(void)
787*35238bceSAndroid Build Coastguard Worker {
788*35238bceSAndroid Build Coastguard Worker     static const glw::GLenum s_blendEquations[] = {
789*35238bceSAndroid Build Coastguard Worker         GL_MULTIPLY,   GL_SCREEN,    GL_OVERLAY,        GL_DARKEN,    GL_LIGHTEN,
790*35238bceSAndroid Build Coastguard Worker         GL_COLORDODGE, GL_COLORBURN, GL_HARDLIGHT,      GL_SOFTLIGHT, GL_DIFFERENCE,
791*35238bceSAndroid Build Coastguard Worker         GL_EXCLUSION,  GL_HSL_HUE,   GL_HSL_SATURATION, GL_HSL_COLOR, GL_HSL_LUMINOSITY,
792*35238bceSAndroid Build Coastguard Worker 
793*35238bceSAndroid Build Coastguard Worker     };
794*35238bceSAndroid Build Coastguard Worker 
795*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *const stateQueryGroup = new tcu::TestCaseGroup(m_testCtx, "state_query", "State query tests");
796*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *const basicGroup      = new tcu::TestCaseGroup(m_testCtx, "basic", "Single quad only");
797*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *const srgbGroup = new tcu::TestCaseGroup(m_testCtx, "srgb", "Advanced blending with sRGB FBO");
798*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *const msaaGroup = new tcu::TestCaseGroup(m_testCtx, "msaa", "Advanced blending with MSAA FBO");
799*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *const barrierGroup =
800*35238bceSAndroid Build Coastguard Worker         new tcu::TestCaseGroup(m_testCtx, "barrier", "Multiple overlapping quads with blend barriers");
801*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *const coherentGroup =
802*35238bceSAndroid Build Coastguard Worker         new tcu::TestCaseGroup(m_testCtx, "coherent", "Overlapping quads with coherent blending");
803*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *const coherentMsaaGroup =
804*35238bceSAndroid Build Coastguard Worker         new tcu::TestCaseGroup(m_testCtx, "coherent_msaa", "Overlapping quads with coherent blending with MSAA FBO");
805*35238bceSAndroid Build Coastguard Worker 
806*35238bceSAndroid Build Coastguard Worker     addChild(stateQueryGroup);
807*35238bceSAndroid Build Coastguard Worker     addChild(basicGroup);
808*35238bceSAndroid Build Coastguard Worker     addChild(srgbGroup);
809*35238bceSAndroid Build Coastguard Worker     addChild(msaaGroup);
810*35238bceSAndroid Build Coastguard Worker     addChild(barrierGroup);
811*35238bceSAndroid Build Coastguard Worker     addChild(coherentGroup);
812*35238bceSAndroid Build Coastguard Worker     addChild(coherentMsaaGroup);
813*35238bceSAndroid Build Coastguard Worker 
814*35238bceSAndroid Build Coastguard Worker     // .state_query
815*35238bceSAndroid Build Coastguard Worker     {
816*35238bceSAndroid Build Coastguard Worker         using namespace gls::StateQueryUtil;
817*35238bceSAndroid Build Coastguard Worker 
818*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendAdvancedCoherentStateCase(
819*35238bceSAndroid Build Coastguard Worker             m_context, "blend_advanced_coherent_getboolean", "Test BLEND_ADVANCED_COHERENT_KHR", QUERY_BOOLEAN));
820*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendAdvancedCoherentStateCase(
821*35238bceSAndroid Build Coastguard Worker             m_context, "blend_advanced_coherent_isenabled", "Test BLEND_ADVANCED_COHERENT_KHR", QUERY_ISENABLED));
822*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendAdvancedCoherentStateCase(
823*35238bceSAndroid Build Coastguard Worker             m_context, "blend_advanced_coherent_getinteger", "Test BLEND_ADVANCED_COHERENT_KHR", QUERY_INTEGER));
824*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendAdvancedCoherentStateCase(
825*35238bceSAndroid Build Coastguard Worker             m_context, "blend_advanced_coherent_getinteger64", "Test BLEND_ADVANCED_COHERENT_KHR", QUERY_INTEGER64));
826*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendAdvancedCoherentStateCase(m_context, "blend_advanced_coherent_getfloat",
827*35238bceSAndroid Build Coastguard Worker                                                                      "Test BLEND_ADVANCED_COHERENT_KHR", QUERY_FLOAT));
828*35238bceSAndroid Build Coastguard Worker 
829*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendEquationStateCase(m_context, "blend_equation_getboolean",
830*35238bceSAndroid Build Coastguard Worker                                                              "Test BLEND_EQUATION", s_blendEquations,
831*35238bceSAndroid Build Coastguard Worker                                                              DE_LENGTH_OF_ARRAY(s_blendEquations), QUERY_BOOLEAN));
832*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendEquationStateCase(m_context, "blend_equation_getinteger",
833*35238bceSAndroid Build Coastguard Worker                                                              "Test BLEND_EQUATION", s_blendEquations,
834*35238bceSAndroid Build Coastguard Worker                                                              DE_LENGTH_OF_ARRAY(s_blendEquations), QUERY_INTEGER));
835*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendEquationStateCase(m_context, "blend_equation_getinteger64",
836*35238bceSAndroid Build Coastguard Worker                                                              "Test BLEND_EQUATION", s_blendEquations,
837*35238bceSAndroid Build Coastguard Worker                                                              DE_LENGTH_OF_ARRAY(s_blendEquations), QUERY_INTEGER64));
838*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendEquationStateCase(m_context, "blend_equation_getfloat",
839*35238bceSAndroid Build Coastguard Worker                                                              "Test BLEND_EQUATION", s_blendEquations,
840*35238bceSAndroid Build Coastguard Worker                                                              DE_LENGTH_OF_ARRAY(s_blendEquations), QUERY_FLOAT));
841*35238bceSAndroid Build Coastguard Worker 
842*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendEquationIndexedStateCase(
843*35238bceSAndroid Build Coastguard Worker             m_context, "blend_equation_getbooleani_v", "Test per-attchment BLEND_EQUATION", s_blendEquations,
844*35238bceSAndroid Build Coastguard Worker             DE_LENGTH_OF_ARRAY(s_blendEquations), QUERY_INDEXED_BOOLEAN));
845*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendEquationIndexedStateCase(
846*35238bceSAndroid Build Coastguard Worker             m_context, "blend_equation_getintegeri_v", "Test per-attchment BLEND_EQUATION", s_blendEquations,
847*35238bceSAndroid Build Coastguard Worker             DE_LENGTH_OF_ARRAY(s_blendEquations), QUERY_INDEXED_INTEGER));
848*35238bceSAndroid Build Coastguard Worker         stateQueryGroup->addChild(new BlendEquationIndexedStateCase(
849*35238bceSAndroid Build Coastguard Worker             m_context, "blend_equation_getinteger64i_v", "Test per-attchment BLEND_EQUATION", s_blendEquations,
850*35238bceSAndroid Build Coastguard Worker             DE_LENGTH_OF_ARRAY(s_blendEquations), QUERY_INDEXED_INTEGER64));
851*35238bceSAndroid Build Coastguard Worker     }
852*35238bceSAndroid Build Coastguard Worker 
853*35238bceSAndroid Build Coastguard Worker     // others
854*35238bceSAndroid Build Coastguard Worker     for (int modeNdx = 0; modeNdx < DE_LENGTH_OF_ARRAY(s_blendEquations); modeNdx++)
855*35238bceSAndroid Build Coastguard Worker     {
856*35238bceSAndroid Build Coastguard Worker         const char *const name = getEquationName(s_blendEquations[modeNdx]);
857*35238bceSAndroid Build Coastguard Worker         const char *const desc = "";
858*35238bceSAndroid Build Coastguard Worker         const uint32_t mode    = s_blendEquations[modeNdx];
859*35238bceSAndroid Build Coastguard Worker 
860*35238bceSAndroid Build Coastguard Worker         basicGroup->addChild(new AdvancedBlendCase(m_context, name, desc, mode, 1, false, RENDERTARGETTYPE_DEFAULT));
861*35238bceSAndroid Build Coastguard Worker         srgbGroup->addChild(new AdvancedBlendCase(m_context, name, desc, mode, 1, false, RENDERTARGETTYPE_SRGB_FBO));
862*35238bceSAndroid Build Coastguard Worker         msaaGroup->addChild(new AdvancedBlendCase(m_context, name, desc, mode, 1, false, RENDERTARGETTYPE_MSAA_FBO));
863*35238bceSAndroid Build Coastguard Worker         barrierGroup->addChild(new AdvancedBlendCase(m_context, name, desc, mode, 4, false, RENDERTARGETTYPE_DEFAULT));
864*35238bceSAndroid Build Coastguard Worker         coherentGroup->addChild(new AdvancedBlendCase(m_context, name, desc, mode, 4, true, RENDERTARGETTYPE_DEFAULT));
865*35238bceSAndroid Build Coastguard Worker         coherentMsaaGroup->addChild(
866*35238bceSAndroid Build Coastguard Worker             new AdvancedBlendCase(m_context, name, desc, mode, 4, true, RENDERTARGETTYPE_MSAA_FBO));
867*35238bceSAndroid Build Coastguard Worker     }
868*35238bceSAndroid Build Coastguard Worker }
869*35238bceSAndroid Build Coastguard Worker 
870*35238bceSAndroid Build Coastguard Worker } // namespace Functional
871*35238bceSAndroid Build Coastguard Worker } // namespace gles31
872*35238bceSAndroid Build Coastguard Worker } // namespace deqp
873