xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fInteger64StateQueryTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.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 Integer64 State Query tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es3fInteger64StateQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "es3fApiCase.hpp"
27 #include "gluRenderContext.hpp"
28 #include "tcuRenderTarget.hpp"
29 #include "glwEnums.hpp"
30 
31 #include <limits>
32 
33 using namespace glw; // GLint and other
34 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
35 
36 namespace deqp
37 {
38 namespace gles3
39 {
40 namespace Functional
41 {
42 namespace Integer64StateQueryVerifiers
43 {
44 
45 // StateVerifier
46 
47 class StateVerifier : protected glu::CallLogWrapper
48 {
49 public:
50     StateVerifier(const glw::Functions &gl, tcu::TestLog &log, const char *testNamePostfix);
51     virtual ~StateVerifier(); // make GCC happy
52 
53     const char *getTestNamePostfix(void) const;
54 
55     virtual void verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext &testCtx, GLenum name,
56                                                        GLuint64 reference) = DE_NULL;
57 
58 private:
59     const char *const m_testNamePostfix;
60 };
61 
StateVerifier(const glw::Functions & gl,tcu::TestLog & log,const char * testNamePostfix)62 StateVerifier::StateVerifier(const glw::Functions &gl, tcu::TestLog &log, const char *testNamePostfix)
63     : glu::CallLogWrapper(gl, log)
64     , m_testNamePostfix(testNamePostfix)
65 {
66     enableLogging(true);
67 }
68 
~StateVerifier()69 StateVerifier::~StateVerifier()
70 {
71 }
72 
getTestNamePostfix(void) const73 const char *StateVerifier::getTestNamePostfix(void) const
74 {
75     return m_testNamePostfix;
76 }
77 
78 // GetBooleanVerifier
79 
80 class GetBooleanVerifier : public StateVerifier
81 {
82 public:
83     GetBooleanVerifier(const glw::Functions &gl, tcu::TestLog &log);
84     void verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext &testCtx, GLenum name, GLuint64 reference);
85 };
86 
GetBooleanVerifier(const glw::Functions & gl,tcu::TestLog & log)87 GetBooleanVerifier::GetBooleanVerifier(const glw::Functions &gl, tcu::TestLog &log)
88     : StateVerifier(gl, log, "_getboolean")
89 {
90 }
91 
verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext & testCtx,GLenum name,GLuint64 reference)92 void GetBooleanVerifier::verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext &testCtx, GLenum name,
93                                                                GLuint64 reference)
94 {
95     using tcu::TestLog;
96 
97     StateQueryMemoryWriteGuard<GLboolean> state;
98     glGetBooleanv(name, &state);
99 
100     if (!state.verifyValidity(testCtx))
101         return;
102 
103     if (state == GL_TRUE) // state is non-zero, could be greater than reference (correct)
104         return;
105 
106     if (state == GL_FALSE) // state is zero
107     {
108         if (reference > 0) // and reference is greater than zero?
109         {
110             testCtx.getLog() << TestLog::Message << "// ERROR: expected GL_TRUE" << TestLog::EndMessage;
111             if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
112                 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
113         }
114     }
115     else
116     {
117         testCtx.getLog() << TestLog::Message << "// ERROR: expected GL_TRUE or GL_FALSE" << TestLog::EndMessage;
118         if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
119             testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
120     }
121 }
122 
123 //GetIntegerVerifier
124 
125 class GetIntegerVerifier : public StateVerifier
126 {
127 public:
128     GetIntegerVerifier(const glw::Functions &gl, tcu::TestLog &log);
129     void verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext &testCtx, GLenum name, GLuint64 reference);
130 };
131 
GetIntegerVerifier(const glw::Functions & gl,tcu::TestLog & log)132 GetIntegerVerifier::GetIntegerVerifier(const glw::Functions &gl, tcu::TestLog &log)
133     : StateVerifier(gl, log, "_getinteger")
134 {
135 }
136 
verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext & testCtx,GLenum name,GLuint64 reference)137 void GetIntegerVerifier::verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext &testCtx, GLenum name,
138                                                                GLuint64 reference)
139 {
140     using tcu::TestLog;
141 
142     StateQueryMemoryWriteGuard<GLint> state;
143     glGetIntegerv(name, &state);
144 
145     if (!state.verifyValidity(testCtx))
146         return;
147 
148     // check that the converted value would be in the correct range, otherwise checking wont tell us anything
149     if (reference > (GLuint64)std::numeric_limits<GLint>::max())
150         return;
151 
152     if (GLuint(state) < reference)
153     {
154         testCtx.getLog() << TestLog::Message << "// ERROR: expected greater or equal to " << reference << "; got "
155                          << state << TestLog::EndMessage;
156         if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
157             testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
158     }
159 }
160 
161 //GetFloatVerifier
162 
163 class GetFloatVerifier : public StateVerifier
164 {
165 public:
166     GetFloatVerifier(const glw::Functions &gl, tcu::TestLog &log);
167     void verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext &testCtx, GLenum name, GLuint64 reference);
168 };
169 
GetFloatVerifier(const glw::Functions & gl,tcu::TestLog & log)170 GetFloatVerifier::GetFloatVerifier(const glw::Functions &gl, tcu::TestLog &log) : StateVerifier(gl, log, "_getfloat")
171 {
172 }
173 
verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext & testCtx,GLenum name,GLuint64 reference)174 void GetFloatVerifier::verifyUnsignedInteger64GreaterOrEqual(tcu::TestContext &testCtx, GLenum name, GLuint64 reference)
175 {
176     using tcu::TestLog;
177 
178     StateQueryMemoryWriteGuard<GLfloat> state;
179     glGetFloatv(name, &state);
180 
181     if (!state.verifyValidity(testCtx))
182         return;
183 
184     if (state < GLfloat(reference))
185     {
186         testCtx.getLog() << TestLog::Message << "// ERROR: expected greater or equal to " << GLfloat(reference)
187                          << "; got " << state << TestLog::EndMessage;
188         if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
189             testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value");
190     }
191 }
192 
193 } // namespace Integer64StateQueryVerifiers
194 
195 namespace
196 {
197 
198 using namespace Integer64StateQueryVerifiers;
199 
200 class ConstantMinimumValue64TestCase : public ApiCase
201 {
202 public:
ConstantMinimumValue64TestCase(Context & context,StateVerifier * verifier,const char * name,const char * description,GLenum targetName,GLuint64 minValue)203     ConstantMinimumValue64TestCase(Context &context, StateVerifier *verifier, const char *name, const char *description,
204                                    GLenum targetName, GLuint64 minValue)
205         : ApiCase(context, name, description)
206         , m_targetName(targetName)
207         , m_minValue(minValue)
208         , m_verifier(verifier)
209     {
210     }
211 
test(void)212     void test(void)
213     {
214         m_verifier->verifyUnsignedInteger64GreaterOrEqual(m_testCtx, m_targetName, m_minValue);
215         expectError(GL_NO_ERROR);
216     }
217 
218 private:
219     GLenum m_targetName;
220     GLuint64 m_minValue;
221     StateVerifier *m_verifier;
222 };
223 
224 class MaxCombinedStageUniformComponentsCase : public ApiCase
225 {
226 public:
MaxCombinedStageUniformComponentsCase(Context & context,StateVerifier * verifier,const char * name,const char * description,GLenum targetName,GLenum targetMaxUniformBlocksName,GLenum targetMaxUniformComponentsName)227     MaxCombinedStageUniformComponentsCase(Context &context, StateVerifier *verifier, const char *name,
228                                           const char *description, GLenum targetName, GLenum targetMaxUniformBlocksName,
229                                           GLenum targetMaxUniformComponentsName)
230         : ApiCase(context, name, description)
231         , m_targetName(targetName)
232         , m_targetMaxUniformBlocksName(targetMaxUniformBlocksName)
233         , m_targetMaxUniformComponentsName(targetMaxUniformComponentsName)
234         , m_verifier(verifier)
235     {
236     }
237 
test(void)238     void test(void)
239     {
240         GLint uniformBlockSize = 0;
241         glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &uniformBlockSize);
242         expectError(GL_NO_ERROR);
243 
244         GLint maxUniformBlocks     = 0;
245         GLint maxUniformComponents = 0;
246         glGetIntegerv(m_targetMaxUniformBlocksName, &maxUniformBlocks);
247         glGetIntegerv(m_targetMaxUniformComponentsName, &maxUniformComponents);
248         expectError(GL_NO_ERROR);
249 
250         // MAX_stage_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4 + MAX_stage_UNIFORM_COMPONENTS
251         const GLuint64 minCombinedUniformComponents =
252             GLuint64(maxUniformBlocks) * uniformBlockSize / 4 + maxUniformComponents;
253 
254         m_verifier->verifyUnsignedInteger64GreaterOrEqual(m_testCtx, m_targetName, minCombinedUniformComponents);
255         expectError(GL_NO_ERROR);
256     }
257 
258 private:
259     GLenum m_targetName;
260     GLenum m_targetMaxUniformBlocksName;
261     GLenum m_targetMaxUniformComponentsName;
262     StateVerifier *m_verifier;
263 };
264 
265 #define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK)                                                 \
266     do                                                                                           \
267     {                                                                                            \
268         for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++) \
269         {                                                                                        \
270             StateVerifier *verifier = (VERIFIERS)[_verifierNdx];                                 \
271             CODE_BLOCK;                                                                          \
272         }                                                                                        \
273     } while (0)
274 
275 } // namespace
276 
Integer64StateQueryTests(Context & context)277 Integer64StateQueryTests::Integer64StateQueryTests(Context &context)
278     : TestCaseGroup(context, "integers64", "Integer (64) Values")
279     , m_verifierBoolean(DE_NULL)
280     , m_verifierInteger(DE_NULL)
281     , m_verifierFloat(DE_NULL)
282 {
283 }
284 
~Integer64StateQueryTests(void)285 Integer64StateQueryTests::~Integer64StateQueryTests(void)
286 {
287     deinit();
288 }
289 
init(void)290 void Integer64StateQueryTests::init(void)
291 {
292     DE_ASSERT(m_verifierBoolean == DE_NULL);
293     DE_ASSERT(m_verifierInteger == DE_NULL);
294     DE_ASSERT(m_verifierFloat == DE_NULL);
295 
296     m_verifierBoolean =
297         new GetBooleanVerifier(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
298     m_verifierInteger =
299         new GetIntegerVerifier(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
300     m_verifierFloat =
301         new GetFloatVerifier(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
302 
303     const struct LimitedStateInteger64
304     {
305         const char *name;
306         const char *description;
307         GLenum targetName;
308         GLuint64 minValue;
309     } implementationLimits[] = {{"max_element_index", "MAX_ELEMENT_INDEX", GL_MAX_ELEMENT_INDEX, 0x00FFFFFF /*2^24-1*/},
310                                 {"max_server_wait_timeout", "MAX_SERVER_WAIT_TIMEOUT", GL_MAX_SERVER_WAIT_TIMEOUT, 0},
311                                 {"max_uniform_block_size", "MAX_UNIFORM_BLOCK_SIZE", GL_MAX_UNIFORM_BLOCK_SIZE, 16384}};
312 
313     // \note do not check the values with integer64 verifier as that has already been checked in implementation_limits
314     StateVerifier *verifiers[] = {m_verifierBoolean, m_verifierInteger, m_verifierFloat};
315 
316     for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(implementationLimits); testNdx++)
317         FOR_EACH_VERIFIER(
318             verifiers, addChild(new ConstantMinimumValue64TestCase(
319                            m_context, verifier,
320                            (std::string(implementationLimits[testNdx].name) + verifier->getTestNamePostfix()).c_str(),
321                            implementationLimits[testNdx].description, implementationLimits[testNdx].targetName,
322                            implementationLimits[testNdx].minValue)));
323 
324     FOR_EACH_VERIFIER(
325         verifiers, addChild(new MaxCombinedStageUniformComponentsCase(
326                        m_context, verifier,
327                        (std::string("max_combined_vertex_uniform_components") + verifier->getTestNamePostfix()).c_str(),
328                        "MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS,
329                        GL_MAX_VERTEX_UNIFORM_BLOCKS, GL_MAX_VERTEX_UNIFORM_COMPONENTS)));
330     FOR_EACH_VERIFIER(
331         verifiers,
332         addChild(new MaxCombinedStageUniformComponentsCase(
333             m_context, verifier,
334             (std::string("max_combined_fragment_uniform_components") + verifier->getTestNamePostfix()).c_str(),
335             "MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS,
336             GL_MAX_FRAGMENT_UNIFORM_BLOCKS, GL_MAX_FRAGMENT_UNIFORM_COMPONENTS)));
337 }
338 
deinit(void)339 void Integer64StateQueryTests::deinit(void)
340 {
341     if (m_verifierBoolean)
342     {
343         delete m_verifierBoolean;
344         m_verifierBoolean = DE_NULL;
345     }
346     if (m_verifierInteger)
347     {
348         delete m_verifierInteger;
349         m_verifierInteger = DE_NULL;
350     }
351     if (m_verifierFloat)
352     {
353         delete m_verifierFloat;
354         m_verifierFloat = DE_NULL;
355     }
356 
357     this->TestCaseGroup::deinit();
358 }
359 
360 } // namespace Functional
361 } // namespace gles3
362 } // namespace deqp
363