13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.0 Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Buffer copying tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fBufferCopyTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsBufferTestUtil.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm>
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace gls::BufferTestUtil;
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BasicBufferCopyCase : public BufferCase
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCopyCase (Context&		context,
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 const char*	name,
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 const char*	desc,
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 deUint32		srcTarget,
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 int			srcSize,
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 deUint32		srcHint,
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 deUint32		dstTarget,
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 int			dstSize,
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 deUint32		dstHint,
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 int			copySrcOffset,
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 int			copyDstOffset,
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 int			copySize,
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 VerifyType		verifyType)
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: BufferCase		(context.getTestContext(), context.getRenderContext(), name, desc)
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_srcTarget		(srcTarget)
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_srcSize			(srcSize)
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_srcHint			(srcHint)
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_dstTarget		(dstTarget)
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_dstSize			(dstSize)
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_dstHint			(dstHint)
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_copySrcOffset	(copySrcOffset)
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_copyDstOffset	(copyDstOffset)
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_copySize		(copySize)
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_verifyType		(verifyType)
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(de::inBounds(m_copySrcOffset, 0, m_srcSize) && de::inRange(m_copySrcOffset+m_copySize, m_copySrcOffset, m_srcSize));
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(de::inBounds(m_copyDstOffset, 0, m_dstSize) && de::inRange(m_copyDstOffset+m_copySize, m_copyDstOffset, m_dstSize));
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult iterate (void)
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		BufferVerifier	verifier	(m_renderCtx, m_testCtx.getLog(), m_verifyType);
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ReferenceBuffer	srcRef;
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ReferenceBuffer	dstRef;
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		srcBuf		= 0;
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		dstBuf		= 0;
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		srcSeed		= deStringHash(getName()) ^ 0xabcd;
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		dstSeed		= deStringHash(getName()) ^ 0xef01;
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool			isOk		= true;
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		srcRef.setSize(m_srcSize);
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		fillWithRandomBytes(srcRef.getPtr(), m_srcSize, srcSeed);
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dstRef.setSize(m_dstSize);
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		fillWithRandomBytes(dstRef.getPtr(), m_dstSize, dstSeed);
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Create source buffer and fill with data.
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		srcBuf = genBuffer();
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glBindBuffer(m_srcTarget, srcBuf);
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glBufferData(m_srcTarget, m_srcSize, srcRef.getPtr(), m_srcHint);
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_MSG("glBufferData");
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Create destination buffer and fill with data.
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dstBuf = genBuffer();
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glBindBuffer(m_dstTarget, dstBuf);
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glBufferData(m_dstTarget, m_dstSize, dstRef.getPtr(), m_dstHint);
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_MSG("glBufferData");
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Verify both buffers before executing copy.
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		isOk = verifier.verify(srcBuf, srcRef.getPtr(), 0, m_srcSize, m_srcTarget) && isOk;
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		isOk = verifier.verify(dstBuf, dstRef.getPtr(), 0, m_dstSize, m_dstTarget) && isOk;
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Execute copy.
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deMemcpy(dstRef.getPtr()+m_copyDstOffset, srcRef.getPtr()+m_copySrcOffset, m_copySize);
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glBindBuffer(m_srcTarget, srcBuf);
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glBindBuffer(m_dstTarget, dstBuf);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glCopyBufferSubData(m_srcTarget, m_dstTarget, m_copySrcOffset, m_copyDstOffset, m_copySize);
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_CHECK_MSG("glCopyBufferSubData");
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Verify both buffers after copy.
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		isOk = verifier.verify(srcBuf, srcRef.getPtr(), 0, m_srcSize, m_srcTarget) && isOk;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		isOk = verifier.verify(dstBuf, dstRef.getPtr(), 0, m_dstSize, m_dstTarget) && isOk;
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								isOk ? "Pass"				: "Buffer verification failed");
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	m_srcTarget;
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			m_srcSize;
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	m_srcHint;
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	m_dstTarget;
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			m_dstSize;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	m_dstHint;
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			m_copySrcOffset;
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			m_copyDstOffset;
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			m_copySize;
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VerifyType	m_verifyType;
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Case B: same buffer, take range as parameter
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass SingleBufferCopyCase : public BufferCase
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleBufferCopyCase (Context&		context,
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						  const char*	name,
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						  const char*	desc,
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						  deUint32		srcTarget,
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						  deUint32		dstTarget,
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						  deUint32		hint,
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						  VerifyType	verifyType)
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: BufferCase		(context.getTestContext(), context.getRenderContext(), name, desc)
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_srcTarget		(srcTarget)
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_dstTarget		(dstTarget)
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_hint			(hint)
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_verifyType		(verifyType)
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult iterate (void)
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int		size		= 1000;
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		BufferVerifier	verifier	(m_renderCtx, m_testCtx.getLog(), m_verifyType);
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ReferenceBuffer	ref;
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		buf			= 0;
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32		baseSeed	= deStringHash(getName());
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool			isOk		= true;
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		ref.setSize(size);
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Create buffer.
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		buf = genBuffer();
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glBindBuffer(m_srcTarget, buf);
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const struct
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				srcOffset;
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				dstOffset;
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				copySize;
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		} copyRanges[] =
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 57,		701,	101 },	// Non-adjecent, from low to high.
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 640,		101,	101 },	// Non-adjecent, from high to low.
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 0,		500,	500 },	// Lower half to upper half.
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 500,		0,		500 }	// Upper half to lower half.
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(copyRanges) && isOk; ndx++)
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int	srcOffset	= copyRanges[ndx].srcOffset;
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int	dstOffset	= copyRanges[ndx].dstOffset;
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int	copySize	= copyRanges[ndx].copySize;
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			fillWithRandomBytes(ref.getPtr(), size, baseSeed ^ deInt32Hash(ndx));
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Fill with data.
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glBindBuffer(m_srcTarget, buf);
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glBufferData(m_srcTarget, size, ref.getPtr(), m_hint);
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_CHECK_MSG("glBufferData");
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Execute copy.
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deMemcpy(ref.getPtr()+dstOffset, ref.getPtr()+srcOffset, copySize);
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glBindBuffer(m_dstTarget, buf);
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glCopyBufferSubData(m_srcTarget, m_dstTarget, srcOffset, dstOffset, copySize);
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_CHECK_MSG("glCopyBufferSubData");
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Verify buffer after copy.
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			isOk = verifier.verify(buf, ref.getPtr(), 0, size, m_dstTarget) && isOk;
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								isOk ? "Pass"				: "Buffer verification failed");
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	m_srcTarget;
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	m_dstTarget;
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	m_hint;
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	VerifyType	m_verifyType;
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2303c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferCopyTests::BufferCopyTests (Context& context)
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "copy", "Buffer copy tests")
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferCopyTests::~BufferCopyTests (void)
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BufferCopyTests::init (void)
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const deUint32 bufferTargets[] =
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_ARRAY_BUFFER,
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_COPY_READ_BUFFER,
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_COPY_WRITE_BUFFER,
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_ELEMENT_ARRAY_BUFFER,
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_PIXEL_PACK_BUFFER,
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_PIXEL_UNPACK_BUFFER,
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_TRANSFORM_FEEDBACK_BUFFER,
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_UNIFORM_BUFFER
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .basic
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* basicGroup = new tcu::TestCaseGroup(m_testCtx, "basic", "Basic buffer copy cases");
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(basicGroup);
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int srcTargetNdx = 0; srcTargetNdx < DE_LENGTH_OF_ARRAY(bufferTargets); srcTargetNdx++)
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int dstTargetNdx = 0; dstTargetNdx < DE_LENGTH_OF_ARRAY(bufferTargets); dstTargetNdx++)
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (srcTargetNdx == dstTargetNdx)
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					continue;
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32		srcTarget		= bufferTargets[srcTargetNdx];
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32		dstTarget		= bufferTargets[dstTargetNdx];
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int		size			= 1017;
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const deUint32	hint			= GL_STATIC_DRAW;
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				VerifyType		verify			= VERIFY_AS_VERTEX_ARRAY;
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				string			name			= string(getBufferTargetName(srcTarget)) + "_" + getBufferTargetName(dstTarget);
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				basicGroup->addChild(new BasicBufferCopyCase(m_context, name.c_str(), "", srcTarget, size, hint, dstTarget, size, hint, 0, 0, size, verify));
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .subrange
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* subrangeGroup = new tcu::TestCaseGroup(m_testCtx, "subrange", "Buffer subrange copy tests");
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(subrangeGroup);
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const struct
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const char*		name;
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				srcSize;
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				dstSize;
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				srcOffset;
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				dstOffset;
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int				copySize;
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		} cases[] =
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			//						srcSize		dstSize		srcOffs		dstOffs		copySize
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "middle",				1000,		1000,		250,		250,		500 },
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "small_to_large",		100,		1000,		0,			409,		100 },
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "large_to_small",		1000,		100,		409,		0,			100 },
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "low_to_high_1",		1000,		1000,		0,			500,		500 },
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "low_to_high_2",		997,		1027,		0,			701,		111 },
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "high_to_low_1",		1000,		1000,		500,		0,			500 },
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "high_to_low_2",		1027,		997,		701,		17,			111 }
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(cases); ndx++)
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32		srcTarget		= GL_COPY_READ_BUFFER;
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32		dstTarget		= GL_COPY_WRITE_BUFFER;
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32		hint			= GL_STATIC_DRAW;
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			VerifyType		verify			= VERIFY_AS_VERTEX_ARRAY;
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			subrangeGroup->addChild(new BasicBufferCopyCase(m_context, cases[ndx].name, "",
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															srcTarget, cases[ndx].srcSize, hint,
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															dstTarget, cases[ndx].dstSize, hint,
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															cases[ndx].srcOffset, cases[ndx].dstOffset, cases[ndx].copySize,
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															verify));
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .single_buffer
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* singleBufGroup = new tcu::TestCaseGroup(m_testCtx, "single_buffer", "Copies within single buffer");
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(singleBufGroup);
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int srcTargetNdx = 0; srcTargetNdx < DE_LENGTH_OF_ARRAY(bufferTargets); srcTargetNdx++)
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int dstTargetNdx = 0; dstTargetNdx < DE_LENGTH_OF_ARRAY(bufferTargets); dstTargetNdx++)
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (srcTargetNdx == dstTargetNdx)
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					continue;
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32		srcTarget		= bufferTargets[srcTargetNdx];
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deUint32		dstTarget		= bufferTargets[dstTargetNdx];
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const deUint32	hint			= GL_STATIC_DRAW;
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				VerifyType		verify			= VERIFY_AS_VERTEX_ARRAY;
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				string			name			= string(getBufferTargetName(srcTarget)) + "_" + getBufferTargetName(dstTarget);
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				singleBufGroup->addChild(new SingleBufferCopyCase(m_context, name.c_str(), "", srcTarget, dstTarget, hint, verify));
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
344