Validate the GPU processing against the CPU one.
| 386 | |
| 387 | // Validate the GPU processing against the CPU one. |
| 388 | void ValidateImageTexture(OCIO::OglAppRcPtr & app, OCIOGPUTestRcPtr & test) |
| 389 | { |
| 390 | // Each retest is rebuilding a cpu proc. |
| 391 | OCIO::ConstCPUProcessorRcPtr processor = test->getProcessor()->getDefaultCPUProcessor(); |
| 392 | |
| 393 | const float epsilon = test->getErrorThreshold(); |
| 394 | const float expectMinValue = test->getExpectedMinimalValue(); |
| 395 | |
| 396 | // Compute the width & height to avoid testing the padded values. |
| 397 | |
| 398 | const size_t numPixels = test->getCustomValues().m_originalInputValueSize / g_components; |
| 399 | |
| 400 | size_t width, height = 0; |
| 401 | if(numPixels<=g_winWidth) |
| 402 | { |
| 403 | width = numPixels; |
| 404 | height = 1; |
| 405 | } |
| 406 | else |
| 407 | { |
| 408 | width = g_winWidth; |
| 409 | height = numPixels/g_winWidth; |
| 410 | if((numPixels%g_winWidth)>0) height += 1; |
| 411 | } |
| 412 | |
| 413 | if(width==0 || width>g_winWidth || height==0 || height>g_winHeight) |
| 414 | { |
| 415 | throw OCIO::Exception("Mismatch with the expected image size"); |
| 416 | } |
| 417 | |
| 418 | // Step 1: Compute the output using the CPU engine. |
| 419 | |
| 420 | OCIOGPUTest::CustomValues::Values cpuImage = test->getCustomValues().m_inputValues; |
| 421 | OCIO::PackedImageDesc desc(&cpuImage[0], (long)width, (long)height, g_components); |
| 422 | processor->apply(desc); |
| 423 | |
| 424 | // Step 2: Grab the GPU output from the rendering buffer. |
| 425 | |
| 426 | OCIOGPUTest::CustomValues::Values gpuImage(g_winWidth*g_winHeight*g_components, 0.0f); |
| 427 | app->readImage(&gpuImage[0]); |
| 428 | |
| 429 | // Step 3: Compare the two results. |
| 430 | |
| 431 | const OCIOGPUTest::CustomValues::Values & image = test->getCustomValues().m_inputValues; |
| 432 | float diff = 0.0f; |
| 433 | // Initialize these to a known reference value, if any of the four component checks |
| 434 | // below fail, it will be set to the index of the last failure. Only the last failure |
| 435 | // is printed below. |
| 436 | size_t idxDiff = invalidIndex; |
| 437 | size_t idxNan = invalidIndex; |
| 438 | size_t idxInf = invalidIndex; |
| 439 | constexpr float huge = std::numeric_limits<float>::max(); |
| 440 | float minVals[4] = {huge, huge, huge, huge}; |
| 441 | float maxVals[4] = {-huge, -huge, -huge, -huge}; |
| 442 | const bool relativeTest = test->getRelativeComparison(); |
| 443 | for(size_t idx=0; idx<(width*height); ++idx) |
| 444 | { |
| 445 | for(size_t chan=0; chan<4; ++chan) |
no test coverage detected