xref: /aosp_15_r20/external/deqp/modules/gles2/performance/es2pBlendTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 2.0 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Blend performance tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es2pBlendTests.hpp"
25 #include "glsShaderPerformanceCase.hpp"
26 #include "tcuTestLog.hpp"
27 #include "gluStrUtil.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
30 
31 namespace deqp
32 {
33 namespace gles2
34 {
35 namespace Performance
36 {
37 
38 using namespace gls;
39 using namespace glw; // GL types
40 using tcu::TestLog;
41 using tcu::Vec4;
42 
43 class BlendCase : public ShaderPerformanceCase
44 {
45 public:
46     BlendCase(Context &context, const char *name, const char *description, GLenum modeRGB, GLenum modeAlpha,
47               GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
48     ~BlendCase(void);
49 
50     void init(void);
51 
52 private:
53     void setupRenderState(void);
54 
55     GLenum m_modeRGB;
56     GLenum m_modeAlpha;
57     GLenum m_srcRGB;
58     GLenum m_dstRGB;
59     GLenum m_srcAlpha;
60     GLenum m_dstAlpha;
61 };
62 
BlendCase(Context & context,const char * name,const char * description,GLenum modeRGB,GLenum modeAlpha,GLenum srcRGB,GLenum dstRGB,GLenum srcAlpha,GLenum dstAlpha)63 BlendCase::BlendCase(Context &context, const char *name, const char *description, GLenum modeRGB, GLenum modeAlpha,
64                      GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
65     : ShaderPerformanceCase(context.getTestContext(), context.getRenderContext(), name, description, CASETYPE_FRAGMENT)
66     , m_modeRGB(modeRGB)
67     , m_modeAlpha(modeAlpha)
68     , m_srcRGB(srcRGB)
69     , m_dstRGB(dstRGB)
70     , m_srcAlpha(srcAlpha)
71     , m_dstAlpha(dstAlpha)
72 {
73 }
74 
~BlendCase(void)75 BlendCase::~BlendCase(void)
76 {
77 }
78 
init(void)79 void BlendCase::init(void)
80 {
81     TestLog &log = m_testCtx.getLog();
82 
83     log << TestLog::Message << "modeRGB: " << glu::getBlendEquationStr(m_modeRGB) << TestLog::EndMessage;
84     log << TestLog::Message << "modeAlpha: " << glu::getBlendEquationStr(m_modeAlpha) << TestLog::EndMessage;
85     log << TestLog::Message << "srcRGB: " << glu::getBlendFactorStr(m_srcRGB) << TestLog::EndMessage;
86     log << TestLog::Message << "dstRGB: " << glu::getBlendFactorStr(m_dstRGB) << TestLog::EndMessage;
87     log << TestLog::Message << "srcAlpha: " << glu::getBlendFactorStr(m_srcAlpha) << TestLog::EndMessage;
88     log << TestLog::Message << "dstAlpha: " << glu::getBlendFactorStr(m_dstAlpha) << TestLog::EndMessage;
89 
90     m_vertShaderSource = "attribute highp vec4 a_position;\n"
91                          "attribute mediump vec4 a_color;\n"
92                          "varying mediump vec4 v_color;\n"
93                          "void main (void)\n"
94                          "{\n"
95                          "    gl_Position = a_position;\n"
96                          "    v_color = a_color;\n"
97                          "}\n";
98     m_fragShaderSource = "varying mediump vec4 v_color;\n"
99                          "void main (void)\n"
100                          "{\n"
101                          "    gl_FragColor = v_color;\n"
102                          "}\n";
103 
104     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                                       Vec4(0.5f, 0.0f, 1.0f, 0.5f), Vec4(1.0f, 0.5f, 0.5f, 0.0f)));
106 
107     ShaderPerformanceCase::init();
108 }
109 
setupRenderState(void)110 void BlendCase::setupRenderState(void)
111 {
112     const glw::Functions &gl = m_renderCtx.getFunctions();
113 
114     gl.enable(GL_BLEND);
115     gl.blendEquationSeparate(m_modeRGB, m_modeAlpha);
116     gl.blendFuncSeparate(m_srcRGB, m_dstRGB, m_srcAlpha, m_dstAlpha);
117 
118     GLU_EXPECT_NO_ERROR(gl.getError(), "After render state setup");
119 }
120 
BlendTests(Context & context)121 BlendTests::BlendTests(Context &context) : TestCaseGroup(context, "blend", "Blend Performance Tests")
122 {
123 }
124 
~BlendTests(void)125 BlendTests::~BlendTests(void)
126 {
127 }
128 
init(void)129 void BlendTests::init(void)
130 {
131     static const struct
132     {
133         const char *name;
134         GLenum modeRGB;
135         GLenum modeAlpha;
136         GLenum srcRGB;
137         GLenum dstRGB;
138         GLenum srcAlpha;
139         GLenum dstAlpha;
140     } cases[] = {
141         // Single blend func, factor one.
142         {"add", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
143         {"subtract", GL_FUNC_SUBTRACT, GL_FUNC_SUBTRACT, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
144         {"reverse_subtract", GL_FUNC_REVERSE_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT, GL_ONE, GL_ONE, GL_ONE, GL_ONE},
145 
146         // Porter-duff modes that can be implemented.
147         {"dst_atop", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA, GL_ONE, GL_ZERO},
148         {"dst_in", GL_FUNC_ADD, GL_FUNC_ADD, GL_ZERO, GL_SRC_ALPHA, GL_ZERO, GL_SRC_ALPHA},
149         {"dst_out", GL_FUNC_ADD, GL_FUNC_ADD, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA},
150         {"dst_over", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
151         {"src_atop", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE},
152         {"src_in", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_ALPHA, GL_ZERO, GL_DST_ALPHA, GL_ZERO},
153         {"src_out", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE_MINUS_DST_ALPHA, GL_ZERO, GL_ONE_MINUS_DST_ALPHA, GL_ZERO},
154         {"src_over", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
155         {"multiply", GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO},
156         {"screen", GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ONE_MINUS_SRC_COLOR, GL_ONE, GL_ONE_MINUS_SRC_ALPHA}};
157 
158     for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
159         addChild(new BlendCase(m_context, cases[caseNdx].name, "", cases[caseNdx].modeRGB, cases[caseNdx].modeAlpha,
160                                cases[caseNdx].srcRGB, cases[caseNdx].dstRGB, cases[caseNdx].srcAlpha,
161                                cases[caseNdx].dstAlpha));
162 }
163 
164 } // namespace Performance
165 } // namespace gles2
166 } // namespace deqp
167