xref: /aosp_15_r20/external/deqp/modules/gles2/performance/es2pBlendTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 2.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 Blend performance tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es2pBlendTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsShaderPerformanceCase.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
30*35238bceSAndroid Build Coastguard Worker 
31*35238bceSAndroid Build Coastguard Worker namespace deqp
32*35238bceSAndroid Build Coastguard Worker {
33*35238bceSAndroid Build Coastguard Worker namespace gles2
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker namespace Performance
36*35238bceSAndroid Build Coastguard Worker {
37*35238bceSAndroid Build Coastguard Worker 
38*35238bceSAndroid Build Coastguard Worker using namespace gls;
39*35238bceSAndroid Build Coastguard Worker using namespace glw; // GL types
40*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
41*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
42*35238bceSAndroid Build Coastguard Worker 
43*35238bceSAndroid Build Coastguard Worker class BlendCase : public ShaderPerformanceCase
44*35238bceSAndroid Build Coastguard Worker {
45*35238bceSAndroid Build Coastguard Worker public:
46*35238bceSAndroid Build Coastguard Worker     BlendCase(Context &context, const char *name, const char *description, GLenum modeRGB, GLenum modeAlpha,
47*35238bceSAndroid Build Coastguard Worker               GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
48*35238bceSAndroid Build Coastguard Worker     ~BlendCase(void);
49*35238bceSAndroid Build Coastguard Worker 
50*35238bceSAndroid Build Coastguard Worker     void init(void);
51*35238bceSAndroid Build Coastguard Worker 
52*35238bceSAndroid Build Coastguard Worker private:
53*35238bceSAndroid Build Coastguard Worker     void setupRenderState(void);
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker     GLenum m_modeRGB;
56*35238bceSAndroid Build Coastguard Worker     GLenum m_modeAlpha;
57*35238bceSAndroid Build Coastguard Worker     GLenum m_srcRGB;
58*35238bceSAndroid Build Coastguard Worker     GLenum m_dstRGB;
59*35238bceSAndroid Build Coastguard Worker     GLenum m_srcAlpha;
60*35238bceSAndroid Build Coastguard Worker     GLenum m_dstAlpha;
61*35238bceSAndroid Build Coastguard Worker };
62*35238bceSAndroid Build Coastguard Worker 
BlendCase(Context & context,const char * name,const char * description,GLenum modeRGB,GLenum modeAlpha,GLenum srcRGB,GLenum dstRGB,GLenum srcAlpha,GLenum dstAlpha)63*35238bceSAndroid Build Coastguard Worker BlendCase::BlendCase(Context &context, const char *name, const char *description, GLenum modeRGB, GLenum modeAlpha,
64*35238bceSAndroid Build Coastguard Worker                      GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
65*35238bceSAndroid Build Coastguard Worker     : ShaderPerformanceCase(context.getTestContext(), context.getRenderContext(), name, description, CASETYPE_FRAGMENT)
66*35238bceSAndroid Build Coastguard Worker     , m_modeRGB(modeRGB)
67*35238bceSAndroid Build Coastguard Worker     , m_modeAlpha(modeAlpha)
68*35238bceSAndroid Build Coastguard Worker     , m_srcRGB(srcRGB)
69*35238bceSAndroid Build Coastguard Worker     , m_dstRGB(dstRGB)
70*35238bceSAndroid Build Coastguard Worker     , m_srcAlpha(srcAlpha)
71*35238bceSAndroid Build Coastguard Worker     , m_dstAlpha(dstAlpha)
72*35238bceSAndroid Build Coastguard Worker {
73*35238bceSAndroid Build Coastguard Worker }
74*35238bceSAndroid Build Coastguard Worker 
~BlendCase(void)75*35238bceSAndroid Build Coastguard Worker BlendCase::~BlendCase(void)
76*35238bceSAndroid Build Coastguard Worker {
77*35238bceSAndroid Build Coastguard Worker }
78*35238bceSAndroid Build Coastguard Worker 
init(void)79*35238bceSAndroid Build Coastguard Worker void BlendCase::init(void)
80*35238bceSAndroid Build Coastguard Worker {
81*35238bceSAndroid Build Coastguard Worker     TestLog &log = m_testCtx.getLog();
82*35238bceSAndroid Build Coastguard Worker 
83*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "modeRGB: " << glu::getBlendEquationStr(m_modeRGB) << TestLog::EndMessage;
84*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "modeAlpha: " << glu::getBlendEquationStr(m_modeAlpha) << TestLog::EndMessage;
85*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "srcRGB: " << glu::getBlendFactorStr(m_srcRGB) << TestLog::EndMessage;
86*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "dstRGB: " << glu::getBlendFactorStr(m_dstRGB) << TestLog::EndMessage;
87*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "srcAlpha: " << glu::getBlendFactorStr(m_srcAlpha) << TestLog::EndMessage;
88*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "dstAlpha: " << glu::getBlendFactorStr(m_dstAlpha) << TestLog::EndMessage;
89*35238bceSAndroid Build Coastguard Worker 
90*35238bceSAndroid Build Coastguard Worker     m_vertShaderSource = "attribute highp vec4 a_position;\n"
91*35238bceSAndroid Build Coastguard Worker                          "attribute mediump vec4 a_color;\n"
92*35238bceSAndroid Build Coastguard Worker                          "varying mediump vec4 v_color;\n"
93*35238bceSAndroid Build Coastguard Worker                          "void main (void)\n"
94*35238bceSAndroid Build Coastguard Worker                          "{\n"
95*35238bceSAndroid Build Coastguard Worker                          "    gl_Position = a_position;\n"
96*35238bceSAndroid Build Coastguard Worker                          "    v_color = a_color;\n"
97*35238bceSAndroid Build Coastguard Worker                          "}\n";
98*35238bceSAndroid Build Coastguard Worker     m_fragShaderSource = "varying mediump vec4 v_color;\n"
99*35238bceSAndroid Build Coastguard Worker                          "void main (void)\n"
100*35238bceSAndroid Build Coastguard Worker                          "{\n"
101*35238bceSAndroid Build Coastguard Worker                          "    gl_FragColor = v_color;\n"
102*35238bceSAndroid Build Coastguard Worker                          "}\n";
103*35238bceSAndroid Build Coastguard Worker 
104*35238bceSAndroid Build Coastguard Worker     m_attributes.push_back(AttribSpec("a_color", Vec4(0.0f, 0.5f, 0.5f, 1.0f), Vec4(0.5f, 1.0f, 0.0f, 0.5f),
105*35238bceSAndroid Build Coastguard Worker                                       Vec4(0.5f, 0.0f, 1.0f, 0.5f), Vec4(1.0f, 0.5f, 0.5f, 0.0f)));
106*35238bceSAndroid Build Coastguard Worker 
107*35238bceSAndroid Build Coastguard Worker     ShaderPerformanceCase::init();
108*35238bceSAndroid Build Coastguard Worker }
109*35238bceSAndroid Build Coastguard Worker 
setupRenderState(void)110*35238bceSAndroid Build Coastguard Worker void BlendCase::setupRenderState(void)
111*35238bceSAndroid Build Coastguard Worker {
112*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
113*35238bceSAndroid Build Coastguard Worker 
114*35238bceSAndroid Build Coastguard Worker     gl.enable(GL_BLEND);
115*35238bceSAndroid Build Coastguard Worker     gl.blendEquationSeparate(m_modeRGB, m_modeAlpha);
116*35238bceSAndroid Build Coastguard Worker     gl.blendFuncSeparate(m_srcRGB, m_dstRGB, m_srcAlpha, m_dstAlpha);
117*35238bceSAndroid Build Coastguard Worker 
118*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "After render state setup");
119*35238bceSAndroid Build Coastguard Worker }
120*35238bceSAndroid Build Coastguard Worker 
BlendTests(Context & context)121*35238bceSAndroid Build Coastguard Worker BlendTests::BlendTests(Context &context) : TestCaseGroup(context, "blend", "Blend Performance Tests")
122*35238bceSAndroid Build Coastguard Worker {
123*35238bceSAndroid Build Coastguard Worker }
124*35238bceSAndroid Build Coastguard Worker 
~BlendTests(void)125*35238bceSAndroid Build Coastguard Worker BlendTests::~BlendTests(void)
126*35238bceSAndroid Build Coastguard Worker {
127*35238bceSAndroid Build Coastguard Worker }
128*35238bceSAndroid Build Coastguard Worker 
init(void)129*35238bceSAndroid Build Coastguard Worker void BlendTests::init(void)
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker     static const struct
132*35238bceSAndroid Build Coastguard Worker     {
133*35238bceSAndroid Build Coastguard Worker         const char *name;
134*35238bceSAndroid Build Coastguard Worker         GLenum modeRGB;
135*35238bceSAndroid Build Coastguard Worker         GLenum modeAlpha;
136*35238bceSAndroid Build Coastguard Worker         GLenum srcRGB;
137*35238bceSAndroid Build Coastguard Worker         GLenum dstRGB;
138*35238bceSAndroid Build Coastguard Worker         GLenum srcAlpha;
139*35238bceSAndroid Build Coastguard Worker         GLenum dstAlpha;
140*35238bceSAndroid Build Coastguard Worker     } cases[] = {
141*35238bceSAndroid Build Coastguard Worker         // Single blend func, factor one.
142*35238bceSAndroid Build Coastguard Worker         {"add", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
143*35238bceSAndroid Build Coastguard Worker         {"subtract", GL_FUNC_SUBTRACT, GL_FUNC_SUBTRACT, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
144*35238bceSAndroid Build Coastguard Worker         {"reverse_subtract", GL_FUNC_REVERSE_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
145*35238bceSAndroid Build Coastguard Worker 
146*35238bceSAndroid Build Coastguard Worker         // Porter-duff modes that can be implemented.
147*35238bceSAndroid Build Coastguard Worker         {"dst_atop", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA, GL_ONE, GL_ZERO},
148*35238bceSAndroid Build Coastguard Worker         {"dst_in", GL_FUNC_ADD, GL_FUNC_ADD, GL_ZERO, GL_SRC_ALPHA, GL_ZERO, GL_SRC_ALPHA},
149*35238bceSAndroid Build Coastguard Worker         {"dst_out", GL_FUNC_ADD, GL_FUNC_ADD, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA},
150*35238bceSAndroid Build Coastguard Worker         {"dst_over", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
151*35238bceSAndroid Build Coastguard Worker         {"src_atop", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE},
152*35238bceSAndroid Build Coastguard Worker         {"src_in", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_ALPHA, GL_ZERO, GL_DST_ALPHA, GL_ZERO},
153*35238bceSAndroid Build Coastguard Worker         {"src_out", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_ZERO, GL_ONE_MINUS_DST_ALPHA, GL_ZERO},
154*35238bceSAndroid Build Coastguard Worker         {"src_over", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
155*35238bceSAndroid Build Coastguard Worker         {"multiply", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO},
156*35238bceSAndroid Build Coastguard Worker         {"screen", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE_MINUS_SRC_COLOR, GL_ONE, GL_ONE_MINUS_SRC_ALPHA}};
157*35238bceSAndroid Build Coastguard Worker 
158*35238bceSAndroid Build Coastguard Worker     for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
159*35238bceSAndroid Build Coastguard Worker         addChild(new BlendCase(m_context, cases[caseNdx].name, "", cases[caseNdx].modeRGB, cases[caseNdx].modeAlpha,
160*35238bceSAndroid Build Coastguard Worker                                cases[caseNdx].srcRGB, cases[caseNdx].dstRGB, cases[caseNdx].srcAlpha,
161*35238bceSAndroid Build Coastguard Worker                                cases[caseNdx].dstAlpha));
162*35238bceSAndroid Build Coastguard Worker }
163*35238bceSAndroid Build Coastguard Worker 
164*35238bceSAndroid Build Coastguard Worker } // namespace Performance
165*35238bceSAndroid Build Coastguard Worker } // namespace gles2
166*35238bceSAndroid Build Coastguard Worker } // namespace deqp
167