xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fShaderUniformIntegerFunctionTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.1 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2018 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 Built-in function tests for uniform constants.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es31fShaderUniformIntegerFunctionTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsShaderExecUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
28*35238bceSAndroid Build Coastguard Worker #include <iostream>
29*35238bceSAndroid Build Coastguard Worker 
30*35238bceSAndroid Build Coastguard Worker namespace deqp
31*35238bceSAndroid Build Coastguard Worker {
32*35238bceSAndroid Build Coastguard Worker namespace gles31
33*35238bceSAndroid Build Coastguard Worker {
34*35238bceSAndroid Build Coastguard Worker namespace Functional
35*35238bceSAndroid Build Coastguard Worker {
36*35238bceSAndroid Build Coastguard Worker 
37*35238bceSAndroid Build Coastguard Worker using std::string;
38*35238bceSAndroid Build Coastguard Worker using std::vector;
39*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
40*35238bceSAndroid Build Coastguard Worker using namespace gls::ShaderExecUtil;
41*35238bceSAndroid Build Coastguard Worker 
42*35238bceSAndroid Build Coastguard Worker class UniformIntegerFunctionCase : public TestCase
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker public:
45*35238bceSAndroid Build Coastguard Worker     UniformIntegerFunctionCase(Context &context, const char *description, int inputValue, glu::Precision precision,
46*35238bceSAndroid Build Coastguard Worker                                glu::ShaderType shaderType);
47*35238bceSAndroid Build Coastguard Worker     ~UniformIntegerFunctionCase(void);
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker     void init(void);
50*35238bceSAndroid Build Coastguard Worker     void deinit(void);
51*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
52*35238bceSAndroid Build Coastguard Worker     virtual const char *getFunctionName()            = 0;
53*35238bceSAndroid Build Coastguard Worker     virtual int computeExpectedResult(int32_t value) = 0;
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker protected:
56*35238bceSAndroid Build Coastguard Worker     UniformIntegerFunctionCase(const UniformIntegerFunctionCase &other);
57*35238bceSAndroid Build Coastguard Worker     UniformIntegerFunctionCase &operator=(const UniformIntegerFunctionCase &other);
58*35238bceSAndroid Build Coastguard Worker 
59*35238bceSAndroid Build Coastguard Worker private:
60*35238bceSAndroid Build Coastguard Worker     ShaderSpec m_spec;
61*35238bceSAndroid Build Coastguard Worker     glu::ShaderType m_shaderType;
62*35238bceSAndroid Build Coastguard Worker     int m_input;
63*35238bceSAndroid Build Coastguard Worker     int m_value;
64*35238bceSAndroid Build Coastguard Worker     ShaderExecutor *m_executor;
65*35238bceSAndroid Build Coastguard Worker };
66*35238bceSAndroid Build Coastguard Worker 
67*35238bceSAndroid Build Coastguard Worker static std::string getCaseName(glu::Precision precision, glu::ShaderType shaderType);
68*35238bceSAndroid Build Coastguard Worker 
UniformIntegerFunctionCase(Context & context,const char * description,int inputValue,glu::Precision precision,glu::ShaderType shaderType)69*35238bceSAndroid Build Coastguard Worker UniformIntegerFunctionCase::UniformIntegerFunctionCase(Context &context, const char *description, int inputValue,
70*35238bceSAndroid Build Coastguard Worker                                                        glu::Precision precision, glu::ShaderType shaderType)
71*35238bceSAndroid Build Coastguard Worker     : TestCase(context, getCaseName(precision, shaderType).c_str(), description)
72*35238bceSAndroid Build Coastguard Worker     , m_shaderType(shaderType)
73*35238bceSAndroid Build Coastguard Worker     , m_input(inputValue)
74*35238bceSAndroid Build Coastguard Worker     , m_value(0)
75*35238bceSAndroid Build Coastguard Worker     , m_executor(DE_NULL)
76*35238bceSAndroid Build Coastguard Worker {
77*35238bceSAndroid Build Coastguard Worker     m_spec.version = glu::GLSL_VERSION_310_ES;
78*35238bceSAndroid Build Coastguard Worker 
79*35238bceSAndroid Build Coastguard Worker     std::ostringstream oss;
80*35238bceSAndroid Build Coastguard Worker     glu::VarType varType(glu::TYPE_INT, precision);
81*35238bceSAndroid Build Coastguard Worker     oss << "uniform " << glu::declare(varType, "value", 0) << ";\n";
82*35238bceSAndroid Build Coastguard Worker     m_spec.globalDeclarations = oss.str();
83*35238bceSAndroid Build Coastguard Worker     m_spec.outputs.push_back(Symbol("result", glu::VarType(glu::TYPE_INT, glu::PRECISION_LOWP)));
84*35238bceSAndroid Build Coastguard Worker     m_spec.outputs.push_back(Symbol("comparison", glu::VarType(glu::TYPE_BOOL, glu::PRECISION_LAST)));
85*35238bceSAndroid Build Coastguard Worker }
86*35238bceSAndroid Build Coastguard Worker 
~UniformIntegerFunctionCase(void)87*35238bceSAndroid Build Coastguard Worker UniformIntegerFunctionCase::~UniformIntegerFunctionCase(void)
88*35238bceSAndroid Build Coastguard Worker {
89*35238bceSAndroid Build Coastguard Worker     UniformIntegerFunctionCase::deinit();
90*35238bceSAndroid Build Coastguard Worker }
91*35238bceSAndroid Build Coastguard Worker 
deinit(void)92*35238bceSAndroid Build Coastguard Worker void UniformIntegerFunctionCase::deinit(void)
93*35238bceSAndroid Build Coastguard Worker {
94*35238bceSAndroid Build Coastguard Worker     delete m_executor;
95*35238bceSAndroid Build Coastguard Worker     m_executor = DE_NULL;
96*35238bceSAndroid Build Coastguard Worker }
97*35238bceSAndroid Build Coastguard Worker 
init(void)98*35238bceSAndroid Build Coastguard Worker void UniformIntegerFunctionCase::init(void)
99*35238bceSAndroid Build Coastguard Worker {
100*35238bceSAndroid Build Coastguard Worker     std::ostringstream oss;
101*35238bceSAndroid Build Coastguard Worker     oss << "result = " << getFunctionName() << "(value);\n"
102*35238bceSAndroid Build Coastguard Worker         << "comparison = (" << getFunctionName() << "(value) == " << computeExpectedResult(m_input) << ");\n";
103*35238bceSAndroid Build Coastguard Worker     m_spec.source = oss.str();
104*35238bceSAndroid Build Coastguard Worker 
105*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_executor);
106*35238bceSAndroid Build Coastguard Worker     m_executor = createExecutor(m_context.getRenderContext(), m_shaderType, m_spec);
107*35238bceSAndroid Build Coastguard Worker     m_testCtx.getLog() << m_executor;
108*35238bceSAndroid Build Coastguard Worker 
109*35238bceSAndroid Build Coastguard Worker     if (!m_executor->isOk())
110*35238bceSAndroid Build Coastguard Worker         throw tcu::TestError("Compile failed");
111*35238bceSAndroid Build Coastguard Worker 
112*35238bceSAndroid Build Coastguard Worker     m_value = m_context.getRenderContext().getFunctions().getUniformLocation(m_executor->getProgram(), "value");
113*35238bceSAndroid Build Coastguard Worker }
114*35238bceSAndroid Build Coastguard Worker 
iterate(void)115*35238bceSAndroid Build Coastguard Worker tcu::TestNode::IterateResult UniformIntegerFunctionCase::iterate(void)
116*35238bceSAndroid Build Coastguard Worker {
117*35238bceSAndroid Build Coastguard Worker     int32_t result;
118*35238bceSAndroid Build Coastguard Worker     int32_t comparison; // A bool in the shader, but we must use a 32-bit type to copy out into.
119*35238bceSAndroid Build Coastguard Worker     vector<void *> outputPointers(2);
120*35238bceSAndroid Build Coastguard Worker 
121*35238bceSAndroid Build Coastguard Worker     outputPointers[0] = &result;
122*35238bceSAndroid Build Coastguard Worker     outputPointers[1] = &comparison;
123*35238bceSAndroid Build Coastguard Worker 
124*35238bceSAndroid Build Coastguard Worker     m_executor->useProgram();
125*35238bceSAndroid Build Coastguard Worker     m_context.getRenderContext().getFunctions().uniform1i(m_value, m_input);
126*35238bceSAndroid Build Coastguard Worker     m_executor->execute(1, DE_NULL, &outputPointers[0]);
127*35238bceSAndroid Build Coastguard Worker 
128*35238bceSAndroid Build Coastguard Worker     int expectedResult = computeExpectedResult(m_input);
129*35238bceSAndroid Build Coastguard Worker     if (result != expectedResult)
130*35238bceSAndroid Build Coastguard Worker     {
131*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "ERROR: comparison failed for " << getFunctionName() << "(" << m_input
132*35238bceSAndroid Build Coastguard Worker                            << ") == " << expectedResult << TestLog::EndMessage;
133*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "input: " << m_input << TestLog::EndMessage;
134*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "result: " << result << TestLog::EndMessage;
135*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result comparison failed");
136*35238bceSAndroid Build Coastguard Worker         return STOP;
137*35238bceSAndroid Build Coastguard Worker     }
138*35238bceSAndroid Build Coastguard Worker     else if (!comparison)
139*35238bceSAndroid Build Coastguard Worker     {
140*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message
141*35238bceSAndroid Build Coastguard Worker                            << "ERROR: result is as expected, but not when use in condition statement ("
142*35238bceSAndroid Build Coastguard Worker                            << getFunctionName() << "(" << m_input << ") == " << expectedResult << ") == true"
143*35238bceSAndroid Build Coastguard Worker                            << TestLog::EndMessage;
144*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "input:" << m_input << TestLog::EndMessage;
145*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "result: " << result << TestLog::EndMessage;
146*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "comparison: " << comparison << TestLog::EndMessage;
147*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result comparison failed");
148*35238bceSAndroid Build Coastguard Worker         return STOP;
149*35238bceSAndroid Build Coastguard Worker     }
150*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
151*35238bceSAndroid Build Coastguard Worker     return STOP;
152*35238bceSAndroid Build Coastguard Worker }
153*35238bceSAndroid Build Coastguard Worker 
getCaseName(glu::Precision precision,glu::ShaderType shaderType)154*35238bceSAndroid Build Coastguard Worker static std::string getCaseName(glu::Precision precision, glu::ShaderType shaderType)
155*35238bceSAndroid Build Coastguard Worker {
156*35238bceSAndroid Build Coastguard Worker     return string(getPrecisionName(precision)) + getShaderTypePostfix(shaderType);
157*35238bceSAndroid Build Coastguard Worker }
158*35238bceSAndroid Build Coastguard Worker 
159*35238bceSAndroid Build Coastguard Worker class FindMSBEdgeCase : public UniformIntegerFunctionCase
160*35238bceSAndroid Build Coastguard Worker {
161*35238bceSAndroid Build Coastguard Worker public:
FindMSBEdgeCase(Context & context,int inputValue,glu::Precision precision,glu::ShaderType shaderType)162*35238bceSAndroid Build Coastguard Worker     FindMSBEdgeCase(Context &context, int inputValue, glu::Precision precision, glu::ShaderType shaderType)
163*35238bceSAndroid Build Coastguard Worker         : UniformIntegerFunctionCase(context, "findMSB", inputValue, precision, shaderType)
164*35238bceSAndroid Build Coastguard Worker     {
165*35238bceSAndroid Build Coastguard Worker     }
166*35238bceSAndroid Build Coastguard Worker 
167*35238bceSAndroid Build Coastguard Worker protected:
getFunctionName()168*35238bceSAndroid Build Coastguard Worker     const char *getFunctionName()
169*35238bceSAndroid Build Coastguard Worker     {
170*35238bceSAndroid Build Coastguard Worker         return "findMSB";
171*35238bceSAndroid Build Coastguard Worker     }
172*35238bceSAndroid Build Coastguard Worker 
computeExpectedResult(int32_t input)173*35238bceSAndroid Build Coastguard Worker     int computeExpectedResult(int32_t input)
174*35238bceSAndroid Build Coastguard Worker     {
175*35238bceSAndroid Build Coastguard Worker         return de::findMSB(input);
176*35238bceSAndroid Build Coastguard Worker     }
177*35238bceSAndroid Build Coastguard Worker };
178*35238bceSAndroid Build Coastguard Worker 
179*35238bceSAndroid Build Coastguard Worker class FindLSBEdgeCase : public UniformIntegerFunctionCase
180*35238bceSAndroid Build Coastguard Worker {
181*35238bceSAndroid Build Coastguard Worker public:
FindLSBEdgeCase(Context & context,int inputValue,glu::Precision precision,glu::ShaderType shaderType)182*35238bceSAndroid Build Coastguard Worker     FindLSBEdgeCase(Context &context, int inputValue, glu::Precision precision, glu::ShaderType shaderType)
183*35238bceSAndroid Build Coastguard Worker         : UniformIntegerFunctionCase(context, "findLSB", inputValue, precision, shaderType)
184*35238bceSAndroid Build Coastguard Worker     {
185*35238bceSAndroid Build Coastguard Worker     }
186*35238bceSAndroid Build Coastguard Worker 
187*35238bceSAndroid Build Coastguard Worker protected:
getFunctionName()188*35238bceSAndroid Build Coastguard Worker     const char *getFunctionName()
189*35238bceSAndroid Build Coastguard Worker     {
190*35238bceSAndroid Build Coastguard Worker         return "findLSB";
191*35238bceSAndroid Build Coastguard Worker     }
192*35238bceSAndroid Build Coastguard Worker 
computeExpectedResult(int32_t input)193*35238bceSAndroid Build Coastguard Worker     int computeExpectedResult(int32_t input)
194*35238bceSAndroid Build Coastguard Worker     {
195*35238bceSAndroid Build Coastguard Worker         return de::findLSB(input);
196*35238bceSAndroid Build Coastguard Worker     }
197*35238bceSAndroid Build Coastguard Worker };
198*35238bceSAndroid Build Coastguard Worker 
199*35238bceSAndroid Build Coastguard Worker template <class TestClass>
addFunctionCases(TestCaseGroup * parent,const char * functionName,int input)200*35238bceSAndroid Build Coastguard Worker static void addFunctionCases(TestCaseGroup *parent, const char *functionName, int input)
201*35238bceSAndroid Build Coastguard Worker {
202*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *group = new tcu::TestCaseGroup(parent->getTestContext(), functionName, functionName);
203*35238bceSAndroid Build Coastguard Worker     parent->addChild(group);
204*35238bceSAndroid Build Coastguard Worker     for (int prec = glu::PRECISION_LOWP; prec <= glu::PRECISION_HIGHP; prec++)
205*35238bceSAndroid Build Coastguard Worker     {
206*35238bceSAndroid Build Coastguard Worker         for (int shaderTypeNdx = 0; shaderTypeNdx < glu::SHADERTYPE_LAST; shaderTypeNdx++)
207*35238bceSAndroid Build Coastguard Worker         {
208*35238bceSAndroid Build Coastguard Worker             if (executorSupported(glu::ShaderType(shaderTypeNdx)))
209*35238bceSAndroid Build Coastguard Worker             {
210*35238bceSAndroid Build Coastguard Worker                 group->addChild(
211*35238bceSAndroid Build Coastguard Worker                     new TestClass(parent->getContext(), input, glu::Precision(prec), glu::ShaderType(shaderTypeNdx)));
212*35238bceSAndroid Build Coastguard Worker             }
213*35238bceSAndroid Build Coastguard Worker         }
214*35238bceSAndroid Build Coastguard Worker     }
215*35238bceSAndroid Build Coastguard Worker }
216*35238bceSAndroid Build Coastguard Worker 
ShaderUniformIntegerFunctionTests(Context & context)217*35238bceSAndroid Build Coastguard Worker ShaderUniformIntegerFunctionTests::ShaderUniformIntegerFunctionTests(Context &context)
218*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "uniform", "Function on uniform")
219*35238bceSAndroid Build Coastguard Worker {
220*35238bceSAndroid Build Coastguard Worker }
221*35238bceSAndroid Build Coastguard Worker 
~ShaderUniformIntegerFunctionTests()222*35238bceSAndroid Build Coastguard Worker ShaderUniformIntegerFunctionTests::~ShaderUniformIntegerFunctionTests()
223*35238bceSAndroid Build Coastguard Worker {
224*35238bceSAndroid Build Coastguard Worker }
init()225*35238bceSAndroid Build Coastguard Worker void ShaderUniformIntegerFunctionTests::init()
226*35238bceSAndroid Build Coastguard Worker {
227*35238bceSAndroid Build Coastguard Worker     addFunctionCases<FindMSBEdgeCase>(this, "findMSBZero", 0);
228*35238bceSAndroid Build Coastguard Worker     addFunctionCases<FindMSBEdgeCase>(this, "findMSBMinusOne", -1);
229*35238bceSAndroid Build Coastguard Worker     addFunctionCases<FindLSBEdgeCase>(this, "findLSBZero", 0);
230*35238bceSAndroid Build Coastguard Worker     addFunctionCases<FindLSBEdgeCase>(this, "findLSBMinusOne", -1);
231*35238bceSAndroid Build Coastguard Worker }
232*35238bceSAndroid Build Coastguard Worker 
233*35238bceSAndroid Build Coastguard Worker } // namespace Functional
234*35238bceSAndroid Build Coastguard Worker } // namespace gles31
235*35238bceSAndroid Build Coastguard Worker } // namespace deqp
236