ShaderMetamorphicVariant::IterateResult ShaderMetamorphicVariant::iterate (void)
{
	TestLog&			log				= m_testCtx.getLog();
	const tcu::RGBA		threshold		= tcu::RGBA(1,1,1,1) + m_context.getRenderTarget().getPixelFormat().getColorThreshold();
	std::string			vertexSrc		= fileContents(m_vertexFilename);
	std::string			recipientSrc	= fileContents(m_recipientFilename);
	std::string			variantSrc		= fileContents(m_variantFilename);
	const int			width			= deMin32(m_context.getRenderTarget().getWidth(), MAX_RENDER_WIDTH);
	const int			height			= deMin32(m_context.getRenderTarget().getHeight(), MAX_RENDER_HEIGHT);
	tcu::Surface		recipientImg	= tcu::Surface(width, height);
	tcu::Surface		variantImg		= tcu::Surface(width, height);

	render(recipientImg.getAccess(), vertexSrc, recipientSrc);
	render(variantImg.getAccess(), vertexSrc, variantSrc);

	checkNondet(recipientImg, vertexSrc, recipientSrc);
	checkNondet(variantImg, vertexSrc, variantSrc);

	if (m_sanityCheck != DE_NULL)
	{
		bool isSane = m_sanityCheck(recipientImg.getAccess());
		if (!isSane)
			throw tcu::TestError("Sanity check fails on recipient");
	}

	bool isOk = tcu::pixelThresholdCompare(log, "Result", "Image comparison result", recipientImg, variantImg, threshold, tcu::COMPARE_LOG_RESULT);

	m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
							isOk ? "Pass"				: "Image comparison failed");

	return STOP;
}
Exemple #2
0
void deAssertFail (const char* reason, const char* file, int line)
{
#if defined(DE_ASSERT_FAILURE_CALLBACK)
	if (g_assertFailureCallback != DE_NULL)
	{
		/* Remove callback in case of the callback causes further asserts. */
		deAssertFailureCallbackFunc callback = g_assertFailureCallback;
		deSetAssertFailureCallback(DE_NULL);
		callback(reason, file, line);
	}
#endif

#if (((DE_OS == DE_OS_WIN32) || (DE_OS == DE_OS_WINCE)) && (DE_COMPILER == DE_COMPILER_MSC))
	{
		wchar_t	wreason[1024];
		wchar_t	wfile[128];
		int		num;
		int		i;

	/*	MessageBox(reason, "Assertion failed", MB_OK); */

		num = deMin32((int)strlen(reason), DE_LENGTH_OF_ARRAY(wreason)-1);
		for (i = 0; i < num; i++)
			wreason[i] = reason[i];
		wreason[i] = 0;

		num = deMin32((int)strlen(file), DE_LENGTH_OF_ARRAY(wfile)-1);
		for (i = 0; i < num; i++)
			wfile[i] = file[i];
		wfile[i] = 0;

#	if (DE_OS == DE_OS_WIN32)
		_wassert(wreason, wfile, line);
#	else /* WINCE */
		assert(wreason);
#	endif
	}
#elif ((DE_OS == DE_OS_WIN32) && (DE_COMPILER == DE_COMPILER_CLANG))
	_assert(reason, file, line);
#elif (DE_OS == DE_OS_UNIX)
	__assert_fail(reason, file, (unsigned int)line, "Unknown function");
#elif (DE_OS == DE_OS_SYMBIAN)
	__assert("Unknown function", file, line, reason);
#elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS)
	fprintf(stderr, "Assertion '%s' failed at %s:%d\n", reason, file, line);
	raise(SIGTRAP);
	abort();
#elif (DE_OS == DE_OS_ANDROID)
	__android_log_print(ANDROID_LOG_ERROR, "delibs", "Assertion '%s' failed at %s:%d", reason, file, line);
	__assert(file, line, reason);
#else
#	error Implement assertion function on your platform.
#endif
}
TestCase::IterateResult ReadPixelsTest::iterate (void)
{
	// Create reference
	const int					width	= 13;
	const int					height	= 13;

	de::Random					rnd(m_seed);

	tcu::TextureFormat			format(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
	int							pixelSize;
	GLint						glFormat;
	GLint						glType;

	getFormatInfo(format, glFormat, glType, pixelSize);
	m_testCtx.getLog() << tcu::TestLog::Message << "Format: " << glu::getPixelFormatStr(glFormat) << ", Type: " << glu::getTypeStr(glType) << tcu::TestLog::EndMessage;

	tcu::Texture2D reference(format, width, height);
	reference.allocLevel(0);

	GLU_CHECK_CALL(glViewport(0, 0, width, height));

	// Clear color
	{
		const float red		= rnd.getFloat();
		const float green	= rnd.getFloat();
		const float blue	= rnd.getFloat();
		const float alpha	= 1.0f;

		m_testCtx.getLog() << tcu::TestLog::Message << "Clear color: (" << red << ", " << green << ", " << blue << ", " << alpha << ")" << tcu::TestLog::EndMessage;

		// Clear target
		GLU_CHECK_CALL(glClearColor(red, green, blue, alpha));
		GLU_CHECK_CALL(glClear(GL_COLOR_BUFFER_BIT));

		tcu::clear(reference.getLevel(0), tcu::Vec4(red, green, blue, alpha));
	}

	render(reference);

	std::vector<deUint8> pixelData;
	const int rowPitch = m_alignment * deCeilFloatToInt32(pixelSize * width / (float)m_alignment);

	pixelData.resize(rowPitch * height, 0);

	GLU_CHECK_CALL(glPixelStorei(GL_PACK_ALIGNMENT, m_alignment));
	GLU_CHECK_CALL(glReadPixels(0, 0, width, height, glFormat, glType, &(pixelData[0])));

	if (m_context.getRenderTarget().getNumSamples() > 1)
	{
		const tcu::IVec4	formatBitDepths	= tcu::getTextureFormatBitDepth(format);
		const deUint8		redThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().redBits,		formatBitDepths.x()))));
		const deUint8		greenThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().greenBits,	formatBitDepths.y()))));
		const deUint8		blueThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().blueBits,		formatBitDepths.z()))));
		const deUint8		alphaThreshold	= (deUint8)deCeilFloatToInt32(256.0f * (2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().alphaBits,	formatBitDepths.w()))));

		// bilinearCompare only accepts RGBA, UINT8
		tcu::Texture2D		referenceRGBA8	(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), width, height);
		tcu::Texture2D		resultRGBA8		(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), width, height);

		referenceRGBA8.allocLevel(0);
		resultRGBA8.allocLevel(0);

		tcu::copy(referenceRGBA8.getLevel(0), reference.getLevel(0));
		tcu::copy(resultRGBA8.getLevel(0), tcu::PixelBufferAccess(format, width, height, 1, rowPitch, 0, &(pixelData[0])));

		if (tcu::bilinearCompare(m_testCtx.getLog(), "Result", "Result", referenceRGBA8.getLevel(0), resultRGBA8.getLevel(0), tcu::RGBA(redThreshold, greenThreshold, blueThreshold, alphaThreshold), tcu::COMPARE_LOG_RESULT))
			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
		else
			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
	}
	else
	{
		const tcu::IVec4	formatBitDepths	= tcu::getTextureFormatBitDepth(format);
		const float			redThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().redBits,	formatBitDepths.x()));
		const float			greenThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().greenBits,	formatBitDepths.y()));
		const float			blueThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().blueBits,	formatBitDepths.z()));
		const float			alphaThreshold	= 2.0f / (1 << deMin32(m_context.getRenderTarget().getPixelFormat().alphaBits,	formatBitDepths.w()));

		// Compare
		if (tcu::floatThresholdCompare(m_testCtx.getLog(), "Result", "Result", reference.getLevel(0), tcu::PixelBufferAccess(format, width, height, 1, rowPitch, 0, &(pixelData[0])), tcu::Vec4(redThreshold, greenThreshold, blueThreshold, alphaThreshold), tcu::COMPARE_LOG_RESULT))
			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
		else
			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
	}

	return STOP;
}