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