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 Texture State Query tests. 22 *//*--------------------------------------------------------------------*/ 23 24 #include "es3fSamplerStateQueryTests.hpp" 25 #include "glsStateQueryUtil.hpp" 26 #include "es3fApiCase.hpp" 27 #include "gluRenderContext.hpp" 28 #include "glwEnums.hpp" 29 #include "glwFunctions.hpp" 30 #include "deRandom.hpp" 31 #include "deMath.h" 32 33 using namespace glw; // GLint and other GL types 34 using namespace deqp::gls; 35 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard; 36 37 38 namespace deqp 39 { 40 namespace gles3 41 { 42 namespace Functional 43 { 44 45 namespace SamplerParamVerifiers 46 { 47 48 class SamplerParamVerifier : protected glu::CallLogWrapper 49 { 50 public: 51 SamplerParamVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix); 52 virtual ~SamplerParamVerifier (); // make GCC happy 53 54 const char* getTestNamePostfix (void) const; 55 56 virtual void verifyInteger (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLint reference) = DE_NULL; 57 virtual void verifyFloat (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLfloat reference) = DE_NULL; 58 private: 59 const char* const m_testNamePostfix; 60 }; 61 62 SamplerParamVerifier::SamplerParamVerifier (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 SamplerParamVerifier::~SamplerParamVerifier () 69 { 70 } 71 72 const char* SamplerParamVerifier::getTestNamePostfix (void) const 73 { 74 return m_testNamePostfix; 75 } 76 77 class GetSamplerParameterIVerifier : public SamplerParamVerifier 78 { 79 public: 80 GetSamplerParameterIVerifier (const glw::Functions& gl, tcu::TestLog& log); 81 82 void verifyInteger (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLint reference); 83 void verifyFloat (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLfloat reference); 84 }; 85 86 GetSamplerParameterIVerifier::GetSamplerParameterIVerifier (const glw::Functions& gl, tcu::TestLog& log) 87 : SamplerParamVerifier(gl, log, "_getsamplerparameteri") 88 { 89 } 90 91 void GetSamplerParameterIVerifier::verifyInteger (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLint reference) 92 { 93 using tcu::TestLog; 94 95 StateQueryMemoryWriteGuard<GLint> state; 96 glGetSamplerParameteriv(sampler, name, &state); 97 98 if (!state.verifyValidity(testCtx)) 99 return; 100 101 if (state != reference) 102 { 103 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage; 104 105 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS) 106 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid sampler param value"); 107 } 108 } 109 110 void GetSamplerParameterIVerifier::verifyFloat (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLfloat reference) 111 { 112 using tcu::TestLog; 113 114 StateQueryMemoryWriteGuard<GLint> state; 115 glGetSamplerParameteriv(sampler, name, &state); 116 117 if (!state.verifyValidity(testCtx)) 118 return; 119 120 const GLint expectedGLStateMax = StateQueryUtil::roundGLfloatToNearestIntegerHalfUp<GLint>(reference); 121 const GLint expectedGLStateMin = StateQueryUtil::roundGLfloatToNearestIntegerHalfDown<GLint>(reference); 122 123 if (state < expectedGLStateMin || state > expectedGLStateMax) 124 { 125 testCtx.getLog() << TestLog::Message << "// ERROR: expected in range [" << expectedGLStateMin << ", " << expectedGLStateMax << "]; got " << state << TestLog::EndMessage; 126 127 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS) 128 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got sampler texture param value"); 129 } 130 } 131 132 class GetSamplerParameterFVerifier : public SamplerParamVerifier 133 { 134 public: 135 GetSamplerParameterFVerifier (const glw::Functions& gl, tcu::TestLog& log); 136 137 void verifyInteger (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLint reference); 138 void verifyFloat (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLfloat reference); 139 }; 140 141 GetSamplerParameterFVerifier::GetSamplerParameterFVerifier (const glw::Functions& gl, tcu::TestLog& log) 142 : SamplerParamVerifier(gl, log, "_getsamplerparameterf") 143 { 144 } 145 146 void GetSamplerParameterFVerifier::verifyInteger (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLint reference) 147 { 148 using tcu::TestLog; 149 150 const GLfloat referenceAsFloat = GLfloat(reference); 151 DE_ASSERT(reference == GLint(referenceAsFloat)); // reference integer must have 1:1 mapping to float for this to work. Reference value is always such value in these tests 152 153 StateQueryMemoryWriteGuard<GLfloat> state; 154 glGetSamplerParameterfv(sampler, name, &state); 155 156 if (!state.verifyValidity(testCtx)) 157 return; 158 159 if (state != referenceAsFloat) 160 { 161 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << referenceAsFloat << "; got " << state << TestLog::EndMessage; 162 163 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS) 164 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value"); 165 } 166 } 167 168 void GetSamplerParameterFVerifier::verifyFloat (tcu::TestContext& testCtx, GLuint sampler, GLenum name, GLfloat reference) 169 { 170 using tcu::TestLog; 171 172 StateQueryMemoryWriteGuard<GLfloat> state; 173 glGetSamplerParameterfv(sampler, name, &state); 174 175 if (!state.verifyValidity(testCtx)) 176 return; 177 178 if (state != reference) 179 { 180 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage; 181 182 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS) 183 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value"); 184 } 185 } 186 187 } // SamplerParamVerifiers 188 189 namespace 190 { 191 192 using namespace SamplerParamVerifiers; 193 194 // Tests 195 196 class SamplerCase : public ApiCase 197 { 198 public: 199 SamplerCase (Context& context, SamplerParamVerifier* verifier, const char* name, const char* description) 200 : ApiCase (context, name, description) 201 , m_sampler (0) 202 , m_verifier (verifier) 203 { 204 } 205 206 virtual void testSampler (void) = DE_NULL; 207 208 void test (void) 209 { 210 glGenSamplers(1, &m_sampler); 211 expectError(GL_NO_ERROR); 212 213 testSampler(); 214 215 glDeleteTextures(1, &m_sampler); 216 expectError(GL_NO_ERROR); 217 } 218 219 protected: 220 GLuint m_sampler; 221 SamplerParamVerifier* m_verifier; 222 }; 223 224 class SamplerWrapCase : public SamplerCase 225 { 226 public: 227 SamplerWrapCase (Context& context, SamplerParamVerifier* verifier, const char* name, const char* description, GLenum valueName) 228 : SamplerCase (context, verifier, name, description) 229 , m_valueName (valueName) 230 { 231 } 232 233 void testSampler (void) 234 { 235 m_verifier->verifyInteger(m_testCtx, m_sampler, m_valueName, GL_REPEAT); 236 expectError(GL_NO_ERROR); 237 238 const GLenum wrapValues[] = {GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT}; 239 240 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx) 241 { 242 glSamplerParameteri(m_sampler, m_valueName, wrapValues[ndx]); 243 expectError(GL_NO_ERROR); 244 245 m_verifier->verifyInteger(m_testCtx, m_sampler, m_valueName, wrapValues[ndx]); 246 expectError(GL_NO_ERROR); 247 } 248 249 //check unit conversions with float 250 251 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx) 252 { 253 glSamplerParameterf(m_sampler, m_valueName, (GLfloat)wrapValues[ndx]); 254 expectError(GL_NO_ERROR); 255 256 m_verifier->verifyInteger(m_testCtx, m_sampler, m_valueName, wrapValues[ndx]); 257 expectError(GL_NO_ERROR); 258 } 259 } 260 261 private: 262 GLenum m_valueName; 263 }; 264 265 class SamplerMagFilterCase : public SamplerCase 266 { 267 public: 268 SamplerMagFilterCase (Context& context, SamplerParamVerifier* verifier, const char* name, const char* description) 269 : SamplerCase(context, verifier, name, description) 270 { 271 } 272 273 void testSampler (void) 274 { 275 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 276 expectError(GL_NO_ERROR); 277 278 const GLenum magValues[] = {GL_NEAREST, GL_LINEAR}; 279 280 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(magValues); ++ndx) 281 { 282 glSamplerParameteri(m_sampler, GL_TEXTURE_MAG_FILTER, magValues[ndx]); 283 expectError(GL_NO_ERROR); 284 285 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_MAG_FILTER, magValues[ndx]); 286 expectError(GL_NO_ERROR); 287 } 288 289 //check unit conversions with float 290 291 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(magValues); ++ndx) 292 { 293 glSamplerParameterf(m_sampler, GL_TEXTURE_MAG_FILTER, (GLfloat)magValues[ndx]); 294 expectError(GL_NO_ERROR); 295 296 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_MAG_FILTER, magValues[ndx]); 297 expectError(GL_NO_ERROR); 298 } 299 } 300 }; 301 302 class SamplerMinFilterCase : public SamplerCase 303 { 304 public: 305 SamplerMinFilterCase (Context& context, SamplerParamVerifier* verifier, const char* name, const char* description) 306 : SamplerCase(context, verifier, name, description) 307 { 308 } 309 310 void testSampler (void) 311 { 312 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 313 expectError(GL_NO_ERROR); 314 315 const GLenum minValues[] = {GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}; 316 317 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(minValues); ++ndx) 318 { 319 glSamplerParameteri(m_sampler, GL_TEXTURE_MIN_FILTER, minValues[ndx]); 320 expectError(GL_NO_ERROR); 321 322 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_MIN_FILTER, minValues[ndx]); 323 expectError(GL_NO_ERROR); 324 } 325 326 //check unit conversions with float 327 328 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(minValues); ++ndx) 329 { 330 glSamplerParameterf(m_sampler, GL_TEXTURE_MIN_FILTER, (GLfloat)minValues[ndx]); 331 expectError(GL_NO_ERROR); 332 333 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_MIN_FILTER, minValues[ndx]); 334 expectError(GL_NO_ERROR); 335 } 336 } 337 }; 338 339 class SamplerLODCase : public SamplerCase 340 { 341 public: 342 SamplerLODCase (Context& context, SamplerParamVerifier* verifier, const char* name, const char* description, GLenum lodTarget, int initialValue) 343 : SamplerCase (context, verifier, name, description) 344 , m_lodTarget (lodTarget) 345 , m_initialValue (initialValue) 346 { 347 } 348 349 void testSampler (void) 350 { 351 de::Random rnd(0xabcdef); 352 353 m_verifier->verifyInteger(m_testCtx, m_sampler, m_lodTarget, m_initialValue); 354 expectError(GL_NO_ERROR); 355 356 const int numIterations = 60; 357 for (int ndx = 0; ndx < numIterations; ++ndx) 358 { 359 const GLfloat ref = rnd.getFloat(-64000, 64000); 360 361 glSamplerParameterf(m_sampler, m_lodTarget, ref); 362 expectError(GL_NO_ERROR); 363 364 m_verifier->verifyFloat(m_testCtx, m_sampler, m_lodTarget, ref); 365 expectError(GL_NO_ERROR); 366 } 367 368 // check unit conversions with int 369 370 for (int ndx = 0; ndx < numIterations; ++ndx) 371 { 372 const GLint ref = rnd.getInt(-64000, 64000); 373 374 glSamplerParameteri(m_sampler, m_lodTarget, ref); 375 expectError(GL_NO_ERROR); 376 377 m_verifier->verifyFloat(m_testCtx, m_sampler, m_lodTarget, (GLfloat)ref); 378 expectError(GL_NO_ERROR); 379 } 380 } 381 private: 382 GLenum m_lodTarget; 383 int m_initialValue; 384 }; 385 386 class SamplerCompareModeCase : public SamplerCase 387 { 388 public: 389 SamplerCompareModeCase (Context& context, SamplerParamVerifier* verifier, const char* name, const char* description) 390 : SamplerCase(context, verifier, name, description) 391 { 392 } 393 394 void testSampler (void) 395 { 396 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_COMPARE_MODE, GL_NONE); 397 expectError(GL_NO_ERROR); 398 399 const GLenum modes[] = {GL_COMPARE_REF_TO_TEXTURE, GL_NONE}; 400 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx) 401 { 402 glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_MODE, modes[ndx]); 403 expectError(GL_NO_ERROR); 404 405 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_COMPARE_MODE, modes[ndx]); 406 expectError(GL_NO_ERROR); 407 } 408 409 // with float too 410 411 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(modes); ++ndx) 412 { 413 glSamplerParameterf(m_sampler, GL_TEXTURE_COMPARE_MODE, (GLfloat)modes[ndx]); 414 expectError(GL_NO_ERROR); 415 416 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_COMPARE_MODE, modes[ndx]); 417 expectError(GL_NO_ERROR); 418 } 419 } 420 }; 421 422 class SamplerCompareFuncCase : public SamplerCase 423 { 424 public: 425 SamplerCompareFuncCase (Context& context, SamplerParamVerifier* verifier, const char* name, const char* description) 426 : SamplerCase(context, verifier, name, description) 427 { 428 } 429 430 void testSampler (void) 431 { 432 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 433 expectError(GL_NO_ERROR); 434 435 const GLenum compareFuncs[] = {GL_LEQUAL, GL_GEQUAL, GL_LESS, GL_GREATER, GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS, GL_NEVER}; 436 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx) 437 { 438 glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, compareFuncs[ndx]); 439 expectError(GL_NO_ERROR); 440 441 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_COMPARE_FUNC, compareFuncs[ndx]); 442 expectError(GL_NO_ERROR); 443 } 444 445 // with float too 446 447 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(compareFuncs); ++ndx) 448 { 449 glSamplerParameterf(m_sampler, GL_TEXTURE_COMPARE_FUNC, (GLfloat)compareFuncs[ndx]); 450 expectError(GL_NO_ERROR); 451 452 m_verifier->verifyInteger(m_testCtx, m_sampler, GL_TEXTURE_COMPARE_FUNC, compareFuncs[ndx]); 453 expectError(GL_NO_ERROR); 454 } 455 } 456 }; 457 458 459 460 } // anonymous 461 462 #define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK) \ 463 for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++) \ 464 { \ 465 SamplerParamVerifier* verifier = VERIFIERS[_verifierNdx]; \ 466 CODE_BLOCK; \ 467 } 468 469 SamplerStateQueryTests::SamplerStateQueryTests (Context& context) 470 : TestCaseGroup (context, "sampler", "Sampler State Query tests") 471 , m_verifierInt (DE_NULL) 472 , m_verifierFloat (DE_NULL) 473 { 474 } 475 476 SamplerStateQueryTests::~SamplerStateQueryTests (void) 477 { 478 deinit(); 479 } 480 481 void SamplerStateQueryTests::init (void) 482 { 483 using namespace SamplerParamVerifiers; 484 485 DE_ASSERT(m_verifierInt == DE_NULL); 486 DE_ASSERT(m_verifierFloat == DE_NULL); 487 488 m_verifierInt = new GetSamplerParameterIVerifier(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog()); 489 m_verifierFloat = new GetSamplerParameterFVerifier(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog()); 490 SamplerParamVerifier* verifiers[] = {m_verifierInt, m_verifierFloat}; 491 492 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerWrapCase (m_context, verifier, (std::string("sampler_texture_wrap_s") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_WRAP_S", GL_TEXTURE_WRAP_S))); 493 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerWrapCase (m_context, verifier, (std::string("sampler_texture_wrap_t") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_WRAP_T", GL_TEXTURE_WRAP_T))); 494 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerWrapCase (m_context, verifier, (std::string("sampler_texture_wrap_r") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_WRAP_R", GL_TEXTURE_WRAP_R))); 495 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerMagFilterCase (m_context, verifier, (std::string("sampler_texture_mag_filter") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_MAG_FILTER"))); 496 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerMinFilterCase (m_context, verifier, (std::string("sampler_texture_min_filter") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_MIN_FILTER"))); 497 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerLODCase (m_context, verifier, (std::string("sampler_texture_min_lod") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_MIN_LOD", GL_TEXTURE_MIN_LOD, -1000))); 498 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerLODCase (m_context, verifier, (std::string("sampler_texture_max_lod") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_MAX_LOD", GL_TEXTURE_MAX_LOD, 1000))); 499 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerCompareModeCase(m_context, verifier, (std::string("sampler_texture_compare_mode") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_COMPARE_MODE"))); 500 FOR_EACH_VERIFIER(verifiers, addChild(new SamplerCompareFuncCase(m_context, verifier, (std::string("sampler_texture_compare_func") + verifier->getTestNamePostfix()).c_str(), "TEXTURE_COMPARE_FUNC"))); 501 } 502 503 void SamplerStateQueryTests::deinit (void) 504 { 505 if (m_verifierInt) 506 { 507 delete m_verifierInt; 508 m_verifierInt = NULL; 509 } 510 if (m_verifierFloat) 511 { 512 delete m_verifierFloat; 513 m_verifierFloat = NULL; 514 } 515 516 this->TestCaseGroup::deinit(); 517 } 518 519 } // Functional 520 } // gles3 521 } // deqp 522