1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Test Log C++ Wrapper.
22 *//*--------------------------------------------------------------------*/
24 #include "deCommandLine.h"
25 #include "tcuTestLog.hpp"
26 #include "tcuTextureUtil.hpp"
27 #include "tcuSurface.hpp"
35 class LogWriteFailedError : public ResourceError
38 LogWriteFailedError (void) : ResourceError("Writing to test log failed") {}
43 MAX_IMAGE_SIZE_2D = 4096,
44 MAX_IMAGE_SIZE_3D = 128
49 LogImage::LogImage (const std::string& name, const std::string& description, const Surface& surface, qpImageCompressionMode compression)
51 , m_description (description)
52 , m_access (surface.getAccess())
53 , m_scale (1.0f, 1.0f, 1.0f, 1.0f)
54 , m_bias (0.0f, 0.0f, 0.0f, 0.0f)
55 , m_compression (compression)
59 LogImage::LogImage (const std::string& name, const std::string& description, const ConstPixelBufferAccess& access, qpImageCompressionMode compression)
61 , m_description (description)
63 , m_scale (1.0f, 1.0f, 1.0f, 1.0f)
64 , m_bias (0.0f, 0.0f, 0.0f, 0.0f)
65 , m_compression (compression)
67 // Simplify combined formats that only use a single channel
68 if (tcu::isCombinedDepthStencilType(m_access.getFormat().type))
70 if (m_access.getFormat().order == tcu::TextureFormat::D)
71 m_access = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_DEPTH);
72 else if (m_access.getFormat().order == tcu::TextureFormat::S)
73 m_access = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_STENCIL);
76 // Implicit scale and bias
77 if (m_access.getFormat().order != tcu::TextureFormat::DS)
78 computePixelScaleBias(m_access, m_scale, m_bias);
81 // Pack D and S bias and scale to R and G
82 const ConstPixelBufferAccess depthAccess = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_DEPTH);
83 const ConstPixelBufferAccess stencilAccess = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_STENCIL);
86 tcu::Vec4 stencilScale;
87 tcu::Vec4 stencilBias;
89 computePixelScaleBias(depthAccess, depthScale, depthBias);
90 computePixelScaleBias(stencilAccess, stencilScale, stencilBias);
92 m_scale = tcu::Vec4(depthScale.x(), stencilScale.x(), 0.0f, 0.0f);
93 m_bias = tcu::Vec4(depthBias.x(), stencilBias.x(), 0.0f, 0.0f);
97 LogImage::LogImage (const std::string& name, const std::string& description, const ConstPixelBufferAccess& access, const Vec4& scale, const Vec4& bias, qpImageCompressionMode compression)
99 , m_description (description)
103 , m_compression (compression)
105 // Cannot set scale and bias of combined formats
106 DE_ASSERT(access.getFormat().order != tcu::TextureFormat::DS);
109 if (tcu::isCombinedDepthStencilType(access.getFormat().type))
111 if (access.getFormat().order == tcu::TextureFormat::D)
112 m_access = tcu::getEffectiveDepthStencilAccess(access, tcu::Sampler::MODE_DEPTH);
113 if (access.getFormat().order == tcu::TextureFormat::S)
114 m_access = tcu::getEffectiveDepthStencilAccess(access, tcu::Sampler::MODE_STENCIL);
117 // Cannot log a DS format
124 void LogImage::write (TestLog& log) const
126 if (m_access.getFormat().order != tcu::TextureFormat::DS)
127 log.writeImage(m_name.c_str(), m_description.c_str(), m_access, m_scale, m_bias, m_compression);
130 const ConstPixelBufferAccess depthAccess = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_DEPTH);
131 const ConstPixelBufferAccess stencilAccess = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_STENCIL);
133 log.startImageSet(m_name.c_str(), m_description.c_str());
134 log.writeImage("Depth", "Depth channel", depthAccess, m_scale.swizzle(0, 0, 0, 0), m_bias.swizzle(0, 0, 0, 0), m_compression);
135 log.writeImage("Stencil", "Stencil channel", stencilAccess, m_scale.swizzle(1, 1, 1, 1), m_bias.swizzle(1, 1, 1, 1), m_compression);
142 MessageBuilder::MessageBuilder (const MessageBuilder& other)
145 m_str.str(other.m_str.str());
148 MessageBuilder& MessageBuilder::operator= (const MessageBuilder& other)
151 m_str.str(other.m_str.str());
155 TestLog& MessageBuilder::operator<< (const TestLog::EndMessageToken&)
157 m_log->writeMessage(m_str.str().c_str());
163 TestLog& SampleBuilder::operator<< (const TestLog::EndSampleToken&)
165 m_log->startSample();
167 for (std::vector<Value>::const_iterator val = m_values.begin(); val != m_values.end(); ++val)
169 if (val->type == Value::TYPE_FLOAT64)
170 m_log->writeSampleValue(val->value.float64);
171 else if (val->type == Value::TYPE_INT64)
172 m_log->writeSampleValue(val->value.int64);
184 TestLog::TestLog (const char* fileName, deUint32 flags)
185 : m_log(qpTestLog_createFileLog(fileName, flags)), m_logSupressed(false)
188 throw ResourceError(std::string("Failed to open test log file '") + fileName + "'");
191 void TestLog::writeSessionInfo(std::string additionalInfo)
193 qpTestLog_beginSession(m_log, additionalInfo.c_str());
196 TestLog::~TestLog (void)
198 qpTestLog_destroy(m_log);
201 void TestLog::writeMessage (const char* msgStr)
203 if (m_logSupressed) return;
204 if (qpTestLog_writeText(m_log, DE_NULL, DE_NULL, QP_KEY_TAG_NONE, msgStr) == DE_FALSE)
205 throw LogWriteFailedError();
208 void TestLog::startImageSet (const char* name, const char* description)
210 if (m_logSupressed) return;
211 if (qpTestLog_startImageSet(m_log, name, description) == DE_FALSE)
212 throw LogWriteFailedError();
215 void TestLog::endImageSet (void)
217 if (m_logSupressed) return;
218 if (qpTestLog_endImageSet(m_log) == DE_FALSE)
219 throw LogWriteFailedError();
223 static Vector<int, Size> computeScaledSize (const Vector<int, Size>& imageSize, int maxSize)
225 bool allInRange = true;
226 for (int i = 0; i < Size; i++)
227 allInRange = allInRange && (imageSize[i] <= maxSize);
234 for (int i = 0; i < Size; i++)
235 d = de::max(d, (float)imageSize[i] / (float)maxSize);
237 Vector<int, Size> res;
238 for (int i = 0; i < Size; i++)
239 res[i] = de::max(1, deRoundFloatToInt32((float)imageSize[i] / d));
245 void TestLog::writeImage (const char* name, const char* description, const ConstPixelBufferAccess& access, const Vec4& pixelScale, const Vec4& pixelBias, qpImageCompressionMode compressionMode)
247 if (m_logSupressed) return;
248 const TextureFormat& format = access.getFormat();
249 int width = access.getWidth();
250 int height = access.getHeight();
251 int depth = access.getDepth();
253 // Writing a combined image does not make sense
254 DE_ASSERT(!tcu::isCombinedDepthStencilType(access.getFormat().type));
256 // Do not bother with preprocessing if images are not stored
257 if ((qpTestLog_getLogFlags(m_log) & QP_TEST_LOG_EXCLUDE_IMAGES) != 0)
260 if (depth == 1 && format.type == TextureFormat::UNORM_INT8
261 && width <= MAX_IMAGE_SIZE_2D && height <= MAX_IMAGE_SIZE_2D
262 && (format.order == TextureFormat::RGB || format.order == TextureFormat::RGBA)
263 && access.getPixelPitch() == access.getFormat().getPixelSize()
264 && pixelBias[0] == 0.0f && pixelBias[1] == 0.0f && pixelBias[2] == 0.0f && pixelBias[3] == 0.0f
265 && pixelScale[0] == 1.0f && pixelScale[1] == 1.0f && pixelScale[2] == 1.0f && pixelScale[3] == 1.0f)
268 bool isRGBA = format.order == TextureFormat::RGBA;
270 writeImage(name, description, compressionMode,
271 isRGBA ? QP_IMAGE_FORMAT_RGBA8888 : QP_IMAGE_FORMAT_RGB888,
272 width, height, access.getRowPitch(), access.getDataPtr());
276 Sampler sampler (Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::LINEAR, Sampler::NEAREST);
277 IVec2 logImageSize = computeScaledSize(IVec2(width, height), MAX_IMAGE_SIZE_2D);
278 tcu::TextureLevel logImage (TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8), logImageSize.x(), logImageSize.y(), 1);
279 PixelBufferAccess logImageAccess = logImage.getAccess();
280 std::ostringstream longDesc;
282 longDesc << description << " (p' = p * " << pixelScale << " + " << pixelBias << ")";
284 for (int y = 0; y < logImage.getHeight(); y++)
286 for (int x = 0; x < logImage.getWidth(); x++)
288 float yf = ((float)y + 0.5f) / (float)logImage.getHeight();
289 float xf = ((float)x + 0.5f) / (float)logImage.getWidth();
290 Vec4 s = access.sample2D(sampler, sampler.minFilter, xf, yf, 0)*pixelScale + pixelBias;
292 logImageAccess.setPixel(s, x, y);
296 writeImage(name, longDesc.str().c_str(), compressionMode, QP_IMAGE_FORMAT_RGBA8888,
297 logImageAccess.getWidth(), logImageAccess.getHeight(), logImageAccess.getRowPitch(),
298 logImageAccess.getDataPtr());
302 // Isometric splat volume rendering.
303 const float blendFactor = 0.85f;
304 IVec3 scaledSize = computeScaledSize(IVec3(width, height, depth), MAX_IMAGE_SIZE_3D);
305 int w = scaledSize.x();
306 int h = scaledSize.y();
307 int d = scaledSize.z();
308 int logImageW = w+d - 1;
309 int logImageH = w+d+h;
310 std::vector<float> blendImage (logImageW*logImageH*4, 0.0f);
311 PixelBufferAccess blendImageAccess (TextureFormat(TextureFormat::RGBA, TextureFormat::FLOAT), logImageW, logImageH, 1, &blendImage[0]);
312 tcu::TextureLevel logImage (TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8), logImageW, logImageH, 1);
313 PixelBufferAccess logImageAccess = logImage.getAccess();
314 Sampler sampler (Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::NEAREST, Sampler::NEAREST);
315 std::ostringstream longDesc;
317 // \note Back-to-front.
318 for (int z = d-1; z >= 0; z--)
320 for (int y = 0; y < h; y++)
322 for (int x = 0; x < w; x++)
324 int px = w - (x + 1) + z;
325 int py = (w + d + h) - (x + y + z + 1);
327 float xf = ((float)x + 0.5f) / (float)w;
328 float yf = ((float)y + 0.5f) / (float)h;
329 float zf = ((float)z + 0.5f) / (float)d;
331 Vec4 p = blendImageAccess.getPixel(px, py);
332 Vec4 s = access.sample3D(sampler, sampler.minFilter, xf, yf, zf);
333 Vec4 b = s + p*blendFactor;
335 blendImageAccess.setPixel(b, px, py);
340 // Scale blend image nicely.
341 longDesc << description << " (p' = p * " << pixelScale << " + " << pixelBias << ")";
343 // Write to final image.
344 tcu::clear(logImageAccess, tcu::IVec4(0x33, 0x66, 0x99, 0xff));
346 for (int z = 0; z < d; z++)
348 for (int y = 0; y < h; y++)
350 for (int x = 0; x < w; x++)
352 if (z != 0 && !(x == 0 || y == h-1 || y == h-2))
355 int px = w - (x + 1) + z;
356 int py = (w + d + h) - (x + y + z + 1);
357 Vec4 s = blendImageAccess.getPixel(px, py)*pixelScale + pixelBias;
359 logImageAccess.setPixel(s, px, py);
364 writeImage(name, longDesc.str().c_str(), compressionMode, QP_IMAGE_FORMAT_RGBA8888,
365 logImageAccess.getWidth(), logImageAccess.getHeight(), logImageAccess.getRowPitch(),
366 logImageAccess.getDataPtr());
370 void TestLog::writeImage (const char* name, const char* description, qpImageCompressionMode compressionMode, qpImageFormat format, int width, int height, int stride, const void* data)
372 if (m_logSupressed) return;
373 if (qpTestLog_writeImage(m_log, name, description, compressionMode, format, width, height, stride, data) == DE_FALSE)
374 throw LogWriteFailedError();
377 void TestLog::startSection (const char* name, const char* description)
379 if (m_logSupressed) return;
380 if (qpTestLog_startSection(m_log, name, description) == DE_FALSE)
381 throw LogWriteFailedError();
384 void TestLog::endSection (void)
386 if (m_logSupressed) return;
387 if (qpTestLog_endSection(m_log) == DE_FALSE)
388 throw LogWriteFailedError();
391 void TestLog::startShaderProgram (bool linkOk, const char* linkInfoLog)
393 if (m_logSupressed) return;
394 if (qpTestLog_startShaderProgram(m_log, linkOk?DE_TRUE:DE_FALSE, linkInfoLog) == DE_FALSE)
395 throw LogWriteFailedError();
398 void TestLog::endShaderProgram (void)
400 if (m_logSupressed) return;
401 if (qpTestLog_endShaderProgram(m_log) == DE_FALSE)
402 throw LogWriteFailedError();
405 void TestLog::writeShader (qpShaderType type, const char* source, bool compileOk, const char* infoLog)
407 if (m_logSupressed) return;
408 if (qpTestLog_writeShader(m_log, type, source, compileOk?DE_TRUE:DE_FALSE, infoLog) == DE_FALSE)
409 throw LogWriteFailedError();
412 void TestLog::writeSpirVAssemblySource (const char* source)
414 if (m_logSupressed) return;
415 if (qpTestLog_writeSpirVAssemblySource(m_log, source) == DE_FALSE)
416 throw LogWriteFailedError();
419 void TestLog::writeKernelSource (const char* source)
421 if (m_logSupressed) return;
422 if (qpTestLog_writeKernelSource(m_log, source) == DE_FALSE)
423 throw LogWriteFailedError();
426 void TestLog::writeCompileInfo (const char* name, const char* description, bool compileOk, const char* infoLog)
428 if (m_logSupressed) return;
429 if (qpTestLog_writeCompileInfo(m_log, name, description, compileOk ? DE_TRUE : DE_FALSE, infoLog) == DE_FALSE)
430 throw LogWriteFailedError();
433 void TestLog::writeFloat (const char* name, const char* description, const char* unit, qpKeyValueTag tag, float value)
435 if (m_logSupressed) return;
436 if (qpTestLog_writeFloat(m_log, name, description, unit, tag, value) == DE_FALSE)
437 throw LogWriteFailedError();
440 void TestLog::writeInteger (const char* name, const char* description, const char* unit, qpKeyValueTag tag, deInt64 value)
442 if (m_logSupressed) return;
443 if (qpTestLog_writeInteger(m_log, name, description, unit, tag, value) == DE_FALSE)
444 throw LogWriteFailedError();
447 void TestLog::startEglConfigSet (const char* name, const char* description)
449 if (m_logSupressed) return;
450 if (qpTestLog_startEglConfigSet(m_log, name, description) == DE_FALSE)
451 throw LogWriteFailedError();
454 void TestLog::writeEglConfig (const qpEglConfigInfo* config)
456 if (m_logSupressed) return;
457 if (qpTestLog_writeEglConfig(m_log, config) == DE_FALSE)
458 throw LogWriteFailedError();
461 void TestLog::endEglConfigSet (void)
463 if (m_logSupressed) return;
464 if (qpTestLog_endEglConfigSet(m_log) == DE_FALSE)
465 throw LogWriteFailedError();
468 void TestLog::startCase (const char* testCasePath, qpTestCaseType testCaseType)
470 if (m_logSupressed) return;
471 if (qpTestLog_startCase(m_log, testCasePath, testCaseType) == DE_FALSE)
472 throw LogWriteFailedError();
475 void TestLog::endCase (qpTestResult result, const char* description)
477 if (m_logSupressed) return;
478 if (qpTestLog_endCase(m_log, result, description) == DE_FALSE)
479 throw LogWriteFailedError();
482 void TestLog::terminateCase (qpTestResult result)
484 if (m_logSupressed) return;
485 if (qpTestLog_terminateCase(m_log, result) == DE_FALSE)
486 throw LogWriteFailedError();
489 void TestLog::startTestsCasesTime (void)
491 if (m_logSupressed) return;
492 if (qpTestLog_startTestsCasesTime(m_log) == DE_FALSE)
493 throw LogWriteFailedError();
496 void TestLog::endTestsCasesTime (void)
498 if (m_logSupressed) return;
499 if (qpTestLog_endTestsCasesTime(m_log) == DE_FALSE)
500 throw LogWriteFailedError();
503 void TestLog::startSampleList (const std::string& name, const std::string& description)
505 if (m_logSupressed) return;
506 if (qpTestLog_startSampleList(m_log, name.c_str(), description.c_str()) == DE_FALSE)
507 throw LogWriteFailedError();
510 void TestLog::startSampleInfo (void)
512 if (m_logSupressed) return;
513 if (qpTestLog_startSampleInfo(m_log) == DE_FALSE)
514 throw LogWriteFailedError();
517 void TestLog::writeValueInfo (const std::string& name, const std::string& description, const std::string& unit, qpSampleValueTag tag)
519 if (m_logSupressed) return;
520 if (qpTestLog_writeValueInfo(m_log, name.c_str(), description.c_str(), unit.empty() ? DE_NULL : unit.c_str(), tag) == DE_FALSE)
521 throw LogWriteFailedError();
524 void TestLog::endSampleInfo (void)
526 if (m_logSupressed) return;
527 if (qpTestLog_endSampleInfo(m_log) == DE_FALSE)
528 throw LogWriteFailedError();
531 void TestLog::startSample (void)
533 if (m_logSupressed) return;
534 if (qpTestLog_startSample(m_log) == DE_FALSE)
535 throw LogWriteFailedError();
538 void TestLog::writeSampleValue (double value)
540 if (m_logSupressed) return;
541 if (qpTestLog_writeValueFloat(m_log, value) == DE_FALSE)
542 throw LogWriteFailedError();
545 void TestLog::writeSampleValue (deInt64 value)
547 if (m_logSupressed) return;
548 if (qpTestLog_writeValueInteger(m_log, value) == DE_FALSE)
549 throw LogWriteFailedError();
552 void TestLog::endSample (void)
554 if (m_logSupressed) return;
555 if (qpTestLog_endSample(m_log) == DE_FALSE)
556 throw LogWriteFailedError();
559 void TestLog::endSampleList (void)
561 if (m_logSupressed) return;
562 if (qpTestLog_endSampleList(m_log) == DE_FALSE)
563 throw LogWriteFailedError();
566 void TestLog::writeRaw(const char* rawContents)
568 if (m_logSupressed) return;
569 qpTestLog_writeRaw(m_log, rawContents);
572 bool TestLog::isShaderLoggingEnabled (void)
574 return (qpTestLog_getLogFlags(m_log) & QP_TEST_LOG_EXCLUDE_SHADER_SOURCES) == 0;
577 void TestLog::supressLogging (bool value)
579 m_logSupressed = value;
582 bool TestLog::isSupressLogging (void)
584 return m_logSupressed;
587 const TestLog::BeginMessageToken TestLog::Message = TestLog::BeginMessageToken();
588 const TestLog::EndMessageToken TestLog::EndMessage = TestLog::EndMessageToken();
589 const TestLog::EndImageSetToken TestLog::EndImageSet = TestLog::EndImageSetToken();
590 const TestLog::EndSectionToken TestLog::EndSection = TestLog::EndSectionToken();
591 const TestLog::EndShaderProgramToken TestLog::EndShaderProgram = TestLog::EndShaderProgramToken();
592 const TestLog::SampleInfoToken TestLog::SampleInfo = TestLog::SampleInfoToken();
593 const TestLog::EndSampleInfoToken TestLog::EndSampleInfo = TestLog::EndSampleInfoToken();
594 const TestLog::BeginSampleToken TestLog::Sample = TestLog::BeginSampleToken();
595 const TestLog::EndSampleToken TestLog::EndSample = TestLog::EndSampleToken();
596 const TestLog::EndSampleListToken TestLog::EndSampleList = TestLog::EndSampleListToken();