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 data upload performance tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3pBufferDataUploadTests.hpp"
258852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry#include "glsCalibration.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVectorUtil.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuCPUWarmup.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluObjectWrapper.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp"
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deClock.h"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h"
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp"
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h"
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deThread.h"
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm>
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <iomanip>
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <limits>
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Performance
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
588852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryusing gls::theilSenSiegelLinearRegression;
598852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryusing gls::LineParametersWithConfidence;
608852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* const s_dummyVertexShader =		"#version 300 es\n"
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"in highp vec4 a_position;\n"
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"void main (void)\n"
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"{\n"
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"	gl_Position = a_position;\n"
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"}\n";
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* const s_dummyFragnentShader =	"#version 300 es\n"
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"layout(location = 0) out mediump vec4 dEQP_FragColor;\n"
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"void main (void)\n"
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"{\n"
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"	dEQP_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"}\n";
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* const s_colorVertexShader =		"#version 300 es\n"
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"in highp vec4 a_position;\n"
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"in highp vec4 a_color;\n"
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"out highp vec4 v_color;\n"
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"void main (void)\n"
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"{\n"
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"	gl_Position = a_position;\n"
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"	v_color = a_color;\n"
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"}\n";
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* const s_colorFragmentShader =	"#version 300 es\n"
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"layout(location = 0) out mediump vec4 dEQP_FragColor;\n"
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"in mediump vec4 v_color;\n"
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"void main (void)\n"
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"{\n"
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"	dEQP_FragColor = v_color;\n"
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													"}\n";
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename TrueType, int cond>
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct EnableIf
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef TrueType Type;
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename TrueType>
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct EnableIf<TrueType, 0>
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename TrueType, int cond>
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct EnableIfNot
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename TrueType>
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct EnableIfNot<TrueType, 0>
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef TrueType Type;
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SingleOperationDuration
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration; // used for fitting
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct MapBufferRangeDuration
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 mapDuration;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 unmapDuration;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 writeDuration;
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 allocDuration;
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct MapBufferRangeDurationNoAlloc
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 mapDuration;
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 unmapDuration;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 writeDuration;
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct MapBufferRangeFlushDuration
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 mapDuration;
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 unmapDuration;
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 writeDuration;
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 flushDuration;
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 allocDuration;
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct MapBufferRangeFlushDurationNoAlloc
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 mapDuration;
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 unmapDuration;
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 writeDuration;
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 flushDuration;
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct RenderReadDuration
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderDuration;
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 readDuration;
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderReadDuration;
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct UnrelatedUploadRenderReadDuration
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderDuration;
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 readDuration;
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderReadDuration;
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct UploadRenderReadDuration
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 uploadDuration;
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderDuration;
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 readDuration;
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderReadDuration;
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct UploadRenderReadDurationWithUnrelatedUploadSize
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 uploadDuration;
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderDuration;
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 readDuration;
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderReadDuration;
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct RenderUploadRenderReadDuration
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 firstRenderDuration;
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 uploadDuration;
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 secondRenderDuration;
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 readDuration;
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 totalDuration;
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 renderReadDuration;
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64 fitResponseDuration;
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleT>
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct UploadSampleResult
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef SampleT SampleType;
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			bufferSize;
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			allocatedSize;
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			writtenSize;
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SampleType	duration;
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleT>
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct RenderSampleResult
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef SampleT SampleType;
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			uploadedDataSize;
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			renderDataSize;
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			unrelatedDataSize;
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int			numVertices;
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SampleT		duration;
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SingleOperationStatistics
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float minTime;
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float maxTime;
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float medianTime;
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float min2DecileTime;		// !< minimum value in the 2nd decile
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float max9DecileTime;		// !< maximum value in the 9th decile
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SingleCallStatistics
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	result;
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRate;
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiffTime;
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiff9DecileTime;
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianDiffTime;
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxRelDiffTime;
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						max9DecileRelDiffTime;
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRelDiffTime;
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct MapCallStatistics
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	map;
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	unmap;
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	write;
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	alloc;
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	result;
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRate;
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiffTime;
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiff9DecileTime;
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianDiffTime;
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxRelDiffTime;
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						max9DecileRelDiffTime;
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRelDiffTime;
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct MapFlushCallStatistics
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	map;
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	unmap;
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	write;
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	flush;
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	alloc;
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	result;
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRate;
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiffTime;
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiff9DecileTime;
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianDiffTime;
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxRelDiffTime;
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						max9DecileRelDiffTime;
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRelDiffTime;
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct RenderReadStatistics
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	render;
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	read;
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	result;
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	total;
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRate;
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiffTime;
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiff9DecileTime;
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianDiffTime;
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxRelDiffTime;
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						max9DecileRelDiffTime;
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRelDiffTime;
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct UploadRenderReadStatistics
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	upload;
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	render;
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	read;
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	result;
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	total;
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRate;
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiffTime;
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiff9DecileTime;
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianDiffTime;
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxRelDiffTime;
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						max9DecileRelDiffTime;
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRelDiffTime;
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct RenderUploadRenderReadStatistics
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	firstRender;
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	upload;
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	secondRender;
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	read;
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	result;
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	total;
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRate;
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiffTime;
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxDiff9DecileTime;
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianDiffTime;
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						maxRelDiffTime;
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						max9DecileRelDiffTime;
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float						medianRelDiffTime;
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<SingleOperationDuration>
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef SingleCallStatistics StatsType;
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_MAP_STATS		= 0	};
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UNMAP_STATS		= 0	};
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_WRITE_STATS		= 0	};
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FLUSH_STATS		= 0	};
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_ALLOC_STATS		= 0	};
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS	= 0	};
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<MapBufferRangeDuration>
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef MapCallStatistics StatsType;
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_MAP_STATS		= 1	};
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UNMAP_STATS		= 1	};
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_WRITE_STATS		= 1	};
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FLUSH_STATS		= 0	};
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_ALLOC_STATS		= 1	};
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS	= 1	};
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<MapBufferRangeDurationNoAlloc>
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef MapCallStatistics StatsType;
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_MAP_STATS		= 1	};
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UNMAP_STATS		= 1	};
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_WRITE_STATS		= 1	};
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FLUSH_STATS		= 0	};
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_ALLOC_STATS		= 0	};
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS	= 1	};
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<MapBufferRangeFlushDuration>
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef MapFlushCallStatistics StatsType;
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_MAP_STATS		= 1	};
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UNMAP_STATS		= 1	};
4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_WRITE_STATS		= 1	};
4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FLUSH_STATS		= 1	};
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_ALLOC_STATS		= 1	};
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS	= 1	};
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<MapBufferRangeFlushDurationNoAlloc>
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef MapFlushCallStatistics StatsType;
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_MAP_STATS		= 1	};
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UNMAP_STATS		= 1	};
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_WRITE_STATS		= 1	};
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FLUSH_STATS		= 1	};
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_ALLOC_STATS		= 0	};
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS	= 1	};
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<RenderReadDuration>
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef RenderReadStatistics StatsType;
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_RENDER_STATS			= 1	};
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_READ_STATS			= 1	};
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UPLOAD_STATS			= 0	};
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_TOTAL_STATS			= 1	};
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FIRST_RENDER_STATS	= 0	};
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_SECOND_RENDER_STATS	= 0	};
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS	= 1	};
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<UnrelatedUploadRenderReadDuration>
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef RenderReadStatistics StatsType;
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_RENDER_STATS			= 1	};
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_READ_STATS			= 1	};
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UPLOAD_STATS			= 0	};
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_TOTAL_STATS			= 1	};
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FIRST_RENDER_STATS	= 0	};
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_SECOND_RENDER_STATS	= 0	};
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS	= 1	};
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<UploadRenderReadDuration>
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef UploadRenderReadStatistics StatsType;
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_RENDER_STATS			= 1	};
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_READ_STATS			= 1	};
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UPLOAD_STATS			= 1	};
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_TOTAL_STATS			= 1	};
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FIRST_RENDER_STATS	= 0	};
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_SECOND_RENDER_STATS	= 0	};
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS			= 1	};
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_UNRELATED_UPLOAD_SIZE	= 0 };
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<UploadRenderReadDurationWithUnrelatedUploadSize>
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef UploadRenderReadStatistics StatsType;
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_RENDER_STATS			= 1	};
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_READ_STATS			= 1	};
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UPLOAD_STATS			= 1	};
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_TOTAL_STATS			= 1	};
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FIRST_RENDER_STATS	= 0	};
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_SECOND_RENDER_STATS	= 0	};
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS			= 1	};
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_UNRELATED_UPLOAD_SIZE	= 1 };
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <>
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct SampleTypeTraits<RenderUploadRenderReadDuration>
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef RenderUploadRenderReadStatistics StatsType;
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_RENDER_STATS			= 0	};
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_READ_STATS			= 1	};
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_UPLOAD_STATS			= 1	};
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_TOTAL_STATS			= 1	};
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_FIRST_RENDER_STATS	= 1	};
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { HAS_SECOND_RENDER_STATS	= 1	};
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_CONTRIBUTIONS			= 1	};
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum { LOG_UNRELATED_UPLOAD_SIZE	= 1 };
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct UploadSampleAnalyzeResult
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float transferRateMedian;
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float transferRateAtRange;
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float transferRateAtInfinity;
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct RenderSampleAnalyzeResult
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float renderRateMedian;
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float renderRateAtRange;
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float renderRateAtInfinity;
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass UnmapFailureError : public std::exception
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UnmapFailureError (void) : std::exception() {}
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic std::string getHumanReadableByteSize (int numBytes)
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::ostringstream buf;
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (numBytes < 1024)
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		buf << numBytes << " byte(s)";
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (numBytes < 1024 * 1024)
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		buf << de::floatToString(numBytes/1024.0f, 1) << " KiB";
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		buf << de::floatToString(numBytes/1024.0f/1024.0f, 1) << " MiB";
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return buf.str();
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic deUint64 medianTimeMemcpy (void* dst, const void* src, int numBytes)
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Time used by memcpy is assumed to be asymptotically linear
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// With large numBytes, the probability of context switch or other random
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// event is high. Apply memcpy in parts and report how much time would
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// memcpy have used with the median transfer rate.
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Less than 1MiB, no need to do anything special
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (numBytes < 1048576)
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deYield();
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deMemcpy(dst, src, numBytes);
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return endTime - startTime;
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Do memcpy in multiple parts
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	numSections		= 5;
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	sectionAlign	= 16;
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			sectionStarts[numSections+1];
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			sectionLens[numSections];
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	sectionTimes[numSections];
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	medianTime;
5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	bestTime		= 0;
5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int sectionNdx = 0; sectionNdx < numSections; ++sectionNdx)
5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			sectionStarts[sectionNdx] = deAlign32((numBytes * sectionNdx / numSections), sectionAlign);
5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sectionStarts[numSections] = numBytes;
5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int sectionNdx = 0; sectionNdx < numSections; ++sectionNdx)
5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			sectionLens[sectionNdx] = sectionStarts[sectionNdx+1] - sectionStarts[sectionNdx];
5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Memcpy is usually called after mapbuffer range which may take
5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// a lot of time. To prevent power management from kicking in during
5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// copy, warm up more.
5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deYield();
5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::warmupCPU();
5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deYield();
5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int sectionNdx = 0; sectionNdx < numSections; ++sectionNdx)
5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64 startTime;
5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64 endTime;
5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			startTime = deGetMicroseconds();
5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deMemcpy((deUint8*)dst + sectionStarts[sectionNdx], (const deUint8*)src + sectionStarts[sectionNdx], sectionLens[sectionNdx]);
5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			endTime = deGetMicroseconds();
5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			sectionTimes[sectionNdx] = endTime - startTime;
5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!bestTime || sectionTimes[sectionNdx] < bestTime)
6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bestTime = sectionTimes[sectionNdx];
6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Detect if write takes 50% longer than it should, and warm up if that happened
6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (sectionNdx != numSections-1 && (float)sectionTimes[sectionNdx] > 1.5f * bestTime)
6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deYield();
6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::warmupCPU();
6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				deYield();
6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::sort(sectionTimes, sectionTimes + numSections);
6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if ((numSections % 2) == 0)
6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			medianTime = (sectionTimes[numSections / 2 - 1] + sectionTimes[numSections / 2]) / 2;
6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			medianTime = sectionTimes[numSections / 2];
6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return medianTime*numSections;
6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float dummyCalculation (float initial, int workSize)
6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float	a = initial;
6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		b = 123;
6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < workSize; ++ndx)
6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		a = deFloatCos(a + (float)b);
6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		b = (b + 63) % 107 + de::abs((int)(a*10.0f));
6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return a + (float)b;
6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void busyWait (int microseconds)
6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint64	maxSingleWaitTime	= 1000; // 1ms
6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint64	endTime				= deGetMicroseconds() + microseconds;
6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float			dummy				= *tcu::warmupCPUInternal::g_dummy.m_v;
6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				workSize			= 500;
6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// exponentially increase work, cap to 1ms
6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	while (deGetMicroseconds() < endTime)
6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint64	startTime		= deGetMicroseconds();
6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64		totalTime;
6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dummy = dummyCalculation(dummy, workSize);
6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		totalTime = deGetMicroseconds() - startTime;
6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (totalTime >= maxSingleWaitTime)
6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			workSize *= 2;
6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// "wait"
6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	while (deGetMicroseconds() < endTime)
6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dummy = dummyCalculation(dummy, workSize);
6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	*tcu::warmupCPUInternal::g_dummy.m_v = dummy;
6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Sample from given values using linear interpolation at a given position as if values were laid to range [0, 1]
6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float linearSample (const std::vector<T>& values, float position)
6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(position >= 0.0f);
6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(position <= 1.0f);
6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float	floatNdx			= ((int)values.size() - 1) * position;
6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	lowerNdx			= (int)deFloatFloor(floatNdx);
6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	higherNdx			= lowerNdx + 1;
6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float	interpolationFactor = floatNdx - (float)lowerNdx;
6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(lowerNdx >= 0 && lowerNdx < (int)values.size());
6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(higherNdx >= 0 && higherNdx < (int)values.size());
6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(interpolationFactor >= 0 && interpolationFactor < 1.0f);
6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::mix((float)values[lowerNdx], (float)values[higherNdx], interpolationFactor);
6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
6873c827367444ee418f129b2c238299f49d3264554Jarkko PoyrySingleOperationStatistics calculateSingleOperationStatistics (const std::vector<T>& samples, deUint64 T::SampleType::*target)
6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleOperationStatistics	stats;
6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint64>		values(samples.size());
6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)samples.size(); ++ndx)
6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		values[ndx] = samples[ndx].duration.*target;
6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::sort(values.begin(), values.end());
6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.minTime			= (float)values.front();
6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.maxTime			= (float)values.back();
6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.medianTime		= linearSample(values, 0.5f);
7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.min2DecileTime	= linearSample(values, 0.1f);
7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.max9DecileTime	= linearSample(values, 0.9f);
7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename StatisticsType, typename SampleType>
7078852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid calculateBasicStatistics (StatisticsType& stats, const LineParametersWithConfidence& fit, const std::vector<SampleType>& samples, int SampleType::*predictor)
7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint64> values(samples.size());
7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)samples.size(); ++ndx)
7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		values[ndx] = samples[ndx].duration.fitResponseDuration;
7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// median rate
7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::vector<float> processingRates(samples.size());
7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < (int)samples.size(); ++ndx)
7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const float timeInSeconds = values[ndx] / 1000.0f / 1000.0f;
7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			processingRates[ndx] = samples[ndx].*predictor / timeInSeconds;
7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::sort(processingRates.begin(), processingRates.end());
7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stats.medianRate = linearSample(processingRates, 0.5f);
7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// results compared to the approximation
7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::vector<float> timeDiffs(samples.size());
7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < (int)samples.size(); ++ndx)
7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const float prediction	= samples[ndx].*predictor * fit.coefficient + fit.offset;
7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const float actual		= (float)values[ndx];
7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			timeDiffs[ndx] = actual - prediction;
7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::sort(timeDiffs.begin(), timeDiffs.end());
7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stats.maxDiffTime			= timeDiffs.back();
7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stats.maxDiff9DecileTime	= linearSample(timeDiffs, 0.9f);
7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stats.medianDiffTime		= linearSample(timeDiffs, 0.5f);
7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// relative comparison to the approximation
7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::vector<float> relativeDiffs(samples.size());
7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < (int)samples.size(); ++ndx)
7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const float prediction	= samples[ndx].*predictor * fit.coefficient + fit.offset;
7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const float actual		= (float)values[ndx];
7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Ignore cases where we predict negative times, or if
7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// ratio would be (nearly) infinite: ignore if predicted
7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// time is less than 1 microsecond
7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (prediction < 1.0f)
7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				relativeDiffs[ndx] = 0.0f;
7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				relativeDiffs[ndx] = (actual - prediction) / prediction;
7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::sort(relativeDiffs.begin(), relativeDiffs.end());
7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stats.maxRelDiffTime		= relativeDiffs.back();
7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stats.max9DecileRelDiffTime	= linearSample(relativeDiffs, 0.9f);
7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		stats.medianRelDiffTime		= linearSample(relativeDiffs, 0.5f);
7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// values calculated using sorted timings
7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::sort(values.begin(), values.end());
7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.result.minTime = (float)values.front();
7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.result.maxTime = (float)values.back();
7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.result.medianTime = linearSample(values, 0.5f);
7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.result.min2DecileTime = linearSample(values, 0.1f);
7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.result.max9DecileTime = linearSample(values, 0.9f);
7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename StatisticsType, typename SampleType>
7828852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid calculateBasicTransferStatistics (StatisticsType& stats, const LineParametersWithConfidence& fit, const std::vector<SampleType>& samples)
7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicStatistics(stats, fit, samples, &SampleType::writtenSize);
7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename StatisticsType, typename SampleType>
7888852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid calculateBasicRenderStatistics (StatisticsType& stats, const LineParametersWithConfidence& fit, const std::vector<SampleType>& samples)
7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicStatistics(stats, fit, samples, &SampleType::renderDataSize);
7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7938852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic SingleCallStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<UploadSampleResult<SingleOperationDuration> >& samples)
7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SingleCallStatistics stats;
7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicTransferStatistics(stats, fit, samples);
7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8028852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic MapCallStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<UploadSampleResult<MapBufferRangeDuration> >& samples)
8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MapCallStatistics stats;
8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicTransferStatistics(stats, fit, samples);
8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.map	= calculateSingleOperationStatistics(samples, &MapBufferRangeDuration::mapDuration);
8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.unmap	= calculateSingleOperationStatistics(samples, &MapBufferRangeDuration::unmapDuration);
8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.write	= calculateSingleOperationStatistics(samples, &MapBufferRangeDuration::writeDuration);
8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.alloc	= calculateSingleOperationStatistics(samples, &MapBufferRangeDuration::allocDuration);
8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8168852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic MapFlushCallStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<UploadSampleResult<MapBufferRangeFlushDuration> >& samples)
8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MapFlushCallStatistics stats;
8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicTransferStatistics(stats, fit, samples);
8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.map	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDuration::mapDuration);
8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.unmap	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDuration::unmapDuration);
8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.write	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDuration::writeDuration);
8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.flush	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDuration::flushDuration);
8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.alloc	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDuration::allocDuration);
8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8318852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic MapCallStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<UploadSampleResult<MapBufferRangeDurationNoAlloc> >& samples)
8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MapCallStatistics stats;
8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicTransferStatistics(stats, fit, samples);
8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.map	= calculateSingleOperationStatistics(samples, &MapBufferRangeDurationNoAlloc::mapDuration);
8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.unmap	= calculateSingleOperationStatistics(samples, &MapBufferRangeDurationNoAlloc::unmapDuration);
8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.write	= calculateSingleOperationStatistics(samples, &MapBufferRangeDurationNoAlloc::writeDuration);
8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8448852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic MapFlushCallStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<UploadSampleResult<MapBufferRangeFlushDurationNoAlloc> >& samples)
8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	MapFlushCallStatistics stats;
8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicTransferStatistics(stats, fit, samples);
8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.map	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDurationNoAlloc::mapDuration);
8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.unmap	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDurationNoAlloc::unmapDuration);
8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.write	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDurationNoAlloc::writeDuration);
8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.flush	= calculateSingleOperationStatistics(samples, &MapBufferRangeFlushDurationNoAlloc::flushDuration);
8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8588852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic RenderReadStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<RenderSampleResult<RenderReadDuration> >& samples)
8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderReadStatistics stats;
8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicRenderStatistics(stats, fit, samples);
8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.render	= calculateSingleOperationStatistics(samples, &RenderReadDuration::renderDuration);
8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.read		= calculateSingleOperationStatistics(samples, &RenderReadDuration::readDuration);
8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.total		= calculateSingleOperationStatistics(samples, &RenderReadDuration::totalDuration);
8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8718852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic RenderReadStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<RenderSampleResult<UnrelatedUploadRenderReadDuration> >& samples)
8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderReadStatistics stats;
8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicRenderStatistics(stats, fit, samples);
8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.render	= calculateSingleOperationStatistics(samples, &UnrelatedUploadRenderReadDuration::renderDuration);
8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.read		= calculateSingleOperationStatistics(samples, &UnrelatedUploadRenderReadDuration::readDuration);
8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.total		= calculateSingleOperationStatistics(samples, &UnrelatedUploadRenderReadDuration::totalDuration);
8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8848852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic UploadRenderReadStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<RenderSampleResult<UploadRenderReadDuration> >& samples)
8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UploadRenderReadStatistics stats;
8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicRenderStatistics(stats, fit, samples);
8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.upload	= calculateSingleOperationStatistics(samples, &UploadRenderReadDuration::uploadDuration);
8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.render	= calculateSingleOperationStatistics(samples, &UploadRenderReadDuration::renderDuration);
8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.read		= calculateSingleOperationStatistics(samples, &UploadRenderReadDuration::readDuration);
8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.total		= calculateSingleOperationStatistics(samples, &UploadRenderReadDuration::totalDuration);
8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
8988852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic UploadRenderReadStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<RenderSampleResult<UploadRenderReadDurationWithUnrelatedUploadSize> >& samples)
8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UploadRenderReadStatistics stats;
9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicRenderStatistics(stats, fit, samples);
9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.upload	= calculateSingleOperationStatistics(samples, &UploadRenderReadDurationWithUnrelatedUploadSize::uploadDuration);
9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.render	= calculateSingleOperationStatistics(samples, &UploadRenderReadDurationWithUnrelatedUploadSize::renderDuration);
9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.read		= calculateSingleOperationStatistics(samples, &UploadRenderReadDurationWithUnrelatedUploadSize::readDuration);
9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.total		= calculateSingleOperationStatistics(samples, &UploadRenderReadDurationWithUnrelatedUploadSize::totalDuration);
9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9128852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic RenderUploadRenderReadStatistics calculateSampleStatistics (const LineParametersWithConfidence& fit, const std::vector<RenderSampleResult<RenderUploadRenderReadDuration> >& samples)
9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderUploadRenderReadStatistics stats;
9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	calculateBasicRenderStatistics(stats, fit, samples);
9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.firstRender	= calculateSingleOperationStatistics(samples, &RenderUploadRenderReadDuration::firstRenderDuration);
9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.upload		= calculateSingleOperationStatistics(samples, &RenderUploadRenderReadDuration::uploadDuration);
9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.secondRender	= calculateSingleOperationStatistics(samples, &RenderUploadRenderReadDuration::secondRenderDuration);
9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.read			= calculateSingleOperationStatistics(samples, &RenderUploadRenderReadDuration::readDuration);
9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stats.total			= calculateSingleOperationStatistics(samples, &RenderUploadRenderReadDuration::totalDuration);
9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stats;
9253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename DurationType>
9288852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic LineParametersWithConfidence fitLineToSamples (const std::vector<UploadSampleResult<DurationType> >& samples, int beginNdx, int endNdx, int step, deUint64 DurationType::*target = &DurationType::fitResponseDuration)
9293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<tcu::Vec2> samplePoints;
9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = beginNdx; sampleNdx < endNdx; sampleNdx += step)
9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec2 point;
9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		point.x() = (float)(samples[sampleNdx].writtenSize);
9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		point.y() = (float)(samples[sampleNdx].duration.*target);
9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		samplePoints.push_back(point);
9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9428852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	return theilSenSiegelLinearRegression(samplePoints, 0.6f);
9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename DurationType>
9468852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic LineParametersWithConfidence fitLineToSamples (const std::vector<RenderSampleResult<DurationType> >& samples, int beginNdx, int endNdx, int step, deUint64 DurationType::*target = &DurationType::fitResponseDuration)
9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<tcu::Vec2> samplePoints;
9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = beginNdx; sampleNdx < endNdx; sampleNdx += step)
9513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::Vec2 point;
9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		point.x() = (float)(samples[sampleNdx].renderDataSize);
9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		point.y() = (float)(samples[sampleNdx].duration.*target);
9563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		samplePoints.push_back(point);
9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9608852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	return theilSenSiegelLinearRegression(samplePoints, 0.6f);
9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
9648852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic LineParametersWithConfidence fitLineToSamples (const std::vector<T>& samples, int beginNdx, int endNdx, deUint64 T::SampleType::*target = &T::SampleType::fitResponseDuration)
9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return fitLineToSamples(samples, beginNdx, endNdx, 1, target);
9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
9708852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyrystatic LineParametersWithConfidence fitLineToSamples (const std::vector<T>& samples, deUint64 T::SampleType::*target = &T::SampleType::fitResponseDuration)
9713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return fitLineToSamples(samples, 0, (int)samples.size(), target);
9733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
9743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float getAreaBetweenLines (float xmin, float xmax, float lineAOffset, float lineACoefficient, float lineBOffset, float lineBCoefficient)
9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float lineAMin		= lineAOffset + lineACoefficient * xmin;
9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float lineAMax		= lineAOffset + lineACoefficient * xmax;
9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float lineBMin		= lineBOffset + lineBCoefficient * xmin;
9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float lineBMax		= lineBOffset + lineBCoefficient * xmax;
9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool	aOverBAtBegin	= (lineAMin > lineBMin);
9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool	aOverBAtEnd		= (lineAMax > lineBMax);
9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (aOverBAtBegin == aOverBAtEnd)
9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// lines do not intersect
9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float midpoint	= (xmin + xmax) / 2.0f;
9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float width		= (xmax - xmin);
9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float lineAHeight	= lineAOffset + lineACoefficient * midpoint;
9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float lineBHeight	= lineBOffset + lineBCoefficient * midpoint;
9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return width * de::abs(lineAHeight - lineBHeight);
9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
9973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// lines intersect
10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float approachCoeffient	= de::abs(lineACoefficient - lineBCoefficient);
10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float epsilon				= 0.0001f;
10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float leftHeight			= de::abs(lineAMin - lineBMin);
10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float rightHeight			= de::abs(lineAMax - lineBMax);
10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (approachCoeffient < epsilon)
10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return 0.0f;
10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return (0.5f * leftHeight * (leftHeight / approachCoeffient)) + (0.5f * rightHeight * (rightHeight / approachCoeffient));
10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float calculateSampleFitLinearity (const std::vector<T>& samples, int T::*predictor)
10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare the fitted line of first half of the samples to the fitted line of
10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// the second half of the samples. Calculate a AABB that fully contains every
10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// sample's x component and both fit lines in this range. Calculate the ratio
10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// of the area between the lines and the AABB.
10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				epsilon				= 1.e-6f;
10223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				midPoint			= (int)samples.size() / 2;
10238852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence	startApproximation	= fitLineToSamples(samples, 0, midPoint, &T::SampleType::fitResponseDuration);
10248852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence	endApproximation	= fitLineToSamples(samples, midPoint, (int)samples.size(), &T::SampleType::fitResponseDuration);
10253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbMinX			= (float)(samples.front().*predictor);
10273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbMinY			= de::min(startApproximation.offset + startApproximation.coefficient*aabbMinX, endApproximation.offset + endApproximation.coefficient*aabbMinX);
10283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbMaxX			= (float)(samples.back().*predictor);
10293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbMaxY			= de::max(startApproximation.offset + startApproximation.coefficient*aabbMaxX, endApproximation.offset + endApproximation.coefficient*aabbMaxX);
10303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbArea			= (aabbMaxX - aabbMinX) * (aabbMaxY - aabbMinY);
10323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				areaBetweenLines	= getAreaBetweenLines(aabbMinX, aabbMaxX, startApproximation.offset, startApproximation.coefficient, endApproximation.offset, endApproximation.coefficient);
10333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				errorAreaRatio		= (aabbArea < epsilon) ? (1.0f) : (areaBetweenLines / aabbArea);
10343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return de::clamp(1.0f - errorAreaRatio, 0.0f, 1.0f);
10363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename DurationType>
10393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float calculateSampleFitLinearity (const std::vector<UploadSampleResult<DurationType> >& samples)
10403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return calculateSampleFitLinearity(samples, &UploadSampleResult<DurationType>::writtenSize);
10423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename DurationType>
10453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float calculateSampleFitLinearity (const std::vector<RenderSampleResult<DurationType> >& samples)
10463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return calculateSampleFitLinearity(samples, &RenderSampleResult<DurationType>::renderDataSize);
10483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
10513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float calculateSampleTemporalStability (const std::vector<T>& samples, int T::*predictor)
10523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Samples are sampled in the following order: 1) even samples (in random order) 2) odd samples (in random order)
10543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Compare the fitted line of even samples to the fitted line of the odd samples. Calculate a AABB that fully
10553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// contains every sample's x component and both fit lines in this range. Calculate the ratio of the area between
10563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// the lines and the AABB.
10573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				epsilon				= 1.e-6f;
10598852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence	evenApproximation	= fitLineToSamples(samples, 0, (int)samples.size(), 2, &T::SampleType::fitResponseDuration);
10608852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence	oddApproximation	= fitLineToSamples(samples, 1, (int)samples.size(), 2, &T::SampleType::fitResponseDuration);
10613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbMinX			= (float)(samples.front().*predictor);
10633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbMinY			= de::min(evenApproximation.offset + evenApproximation.coefficient*aabbMinX, oddApproximation.offset + oddApproximation.coefficient*aabbMinX);
10643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbMaxX			= (float)(samples.back().*predictor);
10653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbMaxY			= de::max(evenApproximation.offset + evenApproximation.coefficient*aabbMaxX, oddApproximation.offset + oddApproximation.coefficient*aabbMaxX);
10663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				aabbArea			= (aabbMaxX - aabbMinX) * (aabbMaxY - aabbMinY);
10683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				areaBetweenLines	= getAreaBetweenLines(aabbMinX, aabbMaxX, evenApproximation.offset, evenApproximation.coefficient, oddApproximation.offset, oddApproximation.coefficient);
10693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float				errorAreaRatio		= (aabbArea < epsilon) ? (1.0f) : (areaBetweenLines / aabbArea);
10703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return de::clamp(1.0f - errorAreaRatio, 0.0f, 1.0f);
10723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename DurationType>
10753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float calculateSampleTemporalStability (const std::vector<UploadSampleResult<DurationType> >& samples)
10763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return calculateSampleTemporalStability(samples, &UploadSampleResult<DurationType>::writtenSize);
10783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10803c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename DurationType>
10813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float calculateSampleTemporalStability (const std::vector<RenderSampleResult<DurationType> >& samples)
10823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return calculateSampleTemporalStability(samples, &RenderSampleResult<DurationType>::renderDataSize);
10843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
10853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename DurationType>
10873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void bucketizeSamplesUniformly (const std::vector<UploadSampleResult<DurationType> >& samples, std::vector<UploadSampleResult<DurationType> >* buckets, int numBuckets, int& minBufferSize, int& maxBufferSize)
10883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
10893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	minBufferSize = 0;
10903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	maxBufferSize = 0;
10913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
10933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
10943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(samples[sampleNdx].allocatedSize != 0);
10953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
10963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!minBufferSize || samples[sampleNdx].allocatedSize < minBufferSize)
10973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			minBufferSize = samples[sampleNdx].allocatedSize;
10983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!maxBufferSize || samples[sampleNdx].allocatedSize > maxBufferSize)
10993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			maxBufferSize = samples[sampleNdx].allocatedSize;
11003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
11013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
11033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
11043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float bucketNdxFloat	= (samples[sampleNdx].allocatedSize - minBufferSize) / (float)(maxBufferSize - minBufferSize) * numBuckets;
11053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int bucketNdx			= de::clamp((int)deFloatFloor(bucketNdxFloat), 0, numBuckets-1);
11063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		buckets[bucketNdx].push_back(samples[sampleNdx]);
11083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
11093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_MAP_STATS>::Type logMapRangeStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("MapRangeMin", "MapRange: Min time", "us", QP_KEY_TAG_TIME, stats.map.minTime)
11153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("MapRangeMax", "MapRange: Max time", "us", QP_KEY_TAG_TIME, stats.map.maxTime)
11163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("MapRangeMin90", "MapRange: 90%-Min time", "us", QP_KEY_TAG_TIME, stats.map.min2DecileTime)
11173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("MapRangeMax90", "MapRange: 90%-Max time", "us", QP_KEY_TAG_TIME, stats.map.max9DecileTime)
11183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("MapRangeMedian", "MapRange: Median time", "us", QP_KEY_TAG_TIME, stats.map.medianTime);
11193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>::Type logUnmapStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("UnmapMin", "Unmap: Min time", "us", QP_KEY_TAG_TIME, stats.unmap.minTime)
11253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("UnmapMax", "Unmap: Max time", "us", QP_KEY_TAG_TIME, stats.unmap.maxTime)
11263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("UnmapMin90", "Unmap: 90%-Min time", "us", QP_KEY_TAG_TIME, stats.unmap.min2DecileTime)
11273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("UnmapMax90", "Unmap: 90%-Max time", "us", QP_KEY_TAG_TIME, stats.unmap.max9DecileTime)
11283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("UnmapMedian", "Unmap: Median time", "us", QP_KEY_TAG_TIME, stats.unmap.medianTime);
11293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_WRITE_STATS>::Type logWriteStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("WriteMin", "Write: Min time", "us", QP_KEY_TAG_TIME, stats.write.minTime)
11353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("WriteMax", "Write: Max time", "us", QP_KEY_TAG_TIME, stats.write.maxTime)
11363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("WriteMin90", "Write: 90%-Min time", "us", QP_KEY_TAG_TIME, stats.write.min2DecileTime)
11373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("WriteMax90", "Write: 90%-Max time", "us", QP_KEY_TAG_TIME, stats.write.max9DecileTime)
11383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("WriteMedian", "Write: Median time", "us", QP_KEY_TAG_TIME, stats.write.medianTime);
11393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>::Type logFlushStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("FlushMin", "Flush: Min time", "us", QP_KEY_TAG_TIME, stats.flush.minTime)
11453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("FlushMax", "Flush: Max time", "us", QP_KEY_TAG_TIME, stats.flush.maxTime)
11463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("FlushMin90", "Flush: 90%-Min time", "us", QP_KEY_TAG_TIME, stats.flush.min2DecileTime)
11473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("FlushMax90", "Flush: 90%-Max time", "us", QP_KEY_TAG_TIME, stats.flush.max9DecileTime)
11483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("FlushMedian", "Flush: Median time", "us", QP_KEY_TAG_TIME, stats.flush.medianTime);
11493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::Type logAllocStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("AllocMin", "Alloc: Min time", "us", QP_KEY_TAG_TIME, stats.alloc.minTime)
11553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("AllocMax", "Alloc: Max time", "us", QP_KEY_TAG_TIME, stats.alloc.maxTime)
11563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("AllocMin90", "Alloc: 90%-Min time", "us", QP_KEY_TAG_TIME, stats.alloc.min2DecileTime)
11573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("AllocMax90", "Alloc: 90%-Max time", "us", QP_KEY_TAG_TIME, stats.alloc.max9DecileTime)
11583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("AllocMedian", "Alloc: Median time", "us", QP_KEY_TAG_TIME, stats.alloc.medianTime);
11593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_MAP_STATS>::Type logMapRangeStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
11653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
11663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>::Type logUnmapStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
11723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
11733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_WRITE_STATS>::Type logWriteStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
11793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
11803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>::Type logFlushStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
11863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
11873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::Type logAllocStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
11933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
11943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
11953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
11963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
11973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_MAP_STATS>::Type logMapContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
11983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
11998852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::mapDuration);
12003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("MapConstantCost", "Map: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("MapLinearCost", "Map: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("MapMedianCost", "Map: Median cost", "us", QP_KEY_TAG_TIME, stats.map.medianTime);
12033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12053c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>::Type logUnmapContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12088852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::unmapDuration);
12093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("UnmapConstantCost", "Unmap: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("UnmapLinearCost", "Unmap: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("UnmapMedianCost", "Unmap: Median cost", "us", QP_KEY_TAG_TIME, stats.unmap.medianTime);
12123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_WRITE_STATS>::Type logWriteContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12178852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::writeDuration);
12183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("WriteConstantCost", "Write: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("WriteLinearCost", "Write: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("WriteMedianCost", "Write: Median cost", "us", QP_KEY_TAG_TIME, stats.write.medianTime);
12213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>::Type logFlushContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12268852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::flushDuration);
12273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("FlushConstantCost", "Flush: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("FlushLinearCost", "Flush: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("FlushMedianCost", "Flush: Median cost", "us", QP_KEY_TAG_TIME, stats.flush.medianTime);
12303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::Type logAllocContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12358852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::allocDuration);
12363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("AllocConstantCost", "Alloc: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("AllocLinearCost", "Alloc: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("AllocMedianCost", "Alloc: Median cost", "us", QP_KEY_TAG_TIME, stats.alloc.medianTime);
12393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_RENDER_STATS>::Type logRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12448852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::renderDuration);
12453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("DrawCallConstantCost", "DrawCall: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("DrawCallLinearCost", "DrawCall: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("DrawCallMedianCost", "DrawCall: Median cost", "us", QP_KEY_TAG_TIME, stats.render.medianTime);
12483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_READ_STATS>::Type logReadContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12538852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::readDuration);
12543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("ReadConstantCost", "Read: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("ReadLinearCost", "Read: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("ReadMedianCost", "Read: Median cost", "us", QP_KEY_TAG_TIME, stats.read.medianTime);
12573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_UPLOAD_STATS>::Type logUploadContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12628852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::uploadDuration);
12633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("UploadConstantCost", "Upload: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("UploadLinearCost", "Upload: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("UploadMedianCost", "Upload: Median cost", "us", QP_KEY_TAG_TIME, stats.upload.medianTime);
12663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_TOTAL_STATS>::Type logTotalContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12718852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::totalDuration);
12723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("TotalConstantCost", "Total: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("TotalLinearCost", "Total: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("TotalMedianCost", "Total: Median cost", "us", QP_KEY_TAG_TIME, stats.total.medianTime);
12753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_FIRST_RENDER_STATS>::Type logFirstRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12808852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::firstRenderDuration);
12813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("FirstDrawCallConstantCost", "First DrawCall: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("FirstDrawCallLinearCost", "First DrawCall: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("FirstDrawCallMedianCost", "First DrawCall: Median cost", "us", QP_KEY_TAG_TIME, stats.firstRender.medianTime);
12843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_SECOND_RENDER_STATS>::Type logSecondRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12898852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence contributionFitting = fitLineToSamples(samples, &SampleType::secondRenderDuration);
12903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log	<< tcu::TestLog::Float("SecondDrawCallConstantCost", "Second DrawCall: Approximated contant cost", "us", QP_KEY_TAG_TIME, contributionFitting.offset)
12913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("SecondDrawCallLinearCost", "Second DrawCall: Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, contributionFitting.coefficient * 1024.0f * 1024.0f)
12923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Float("SecondDrawCallMedianCost", "Second DrawCall: Median cost", "us", QP_KEY_TAG_TIME, stats.secondRender.medianTime);
12933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
12943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
12953c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
12963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_MAP_STATS>::Type logMapContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
12973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
12983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
12993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13043c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>::Type logUnmapContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_WRITE_STATS>::Type logWriteContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>::Type logFlushContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::Type logAllocContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_RENDER_STATS>::Type logRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_READ_STATS>::Type logReadContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_UPLOAD_STATS>::Type logUploadContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_TOTAL_STATS>::Type logTotalContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_FIRST_RENDER_STATS>::Type logFirstRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
13763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_SECOND_RENDER_STATS>::Type logSecondRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
13773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(log);
13793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(samples);
13803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(stats);
13813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
13823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13838852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<UploadSampleResult<SingleOperationDuration> >& samples)
13843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
13853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
13863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
13873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WrittenSize",		"Written size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
13883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("BufferSize",		"Buffer size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
13893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UploadTime",		"Upload time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
13903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",		"Fit residual",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
13913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
13923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
13933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
13943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
13953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].writtenSize);
13963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
13973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].writtenSize
13983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].bufferSize
13993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.totalDuration
14003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
14013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
14023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
14053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
14063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14078852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<UploadSampleResult<MapBufferRangeDuration> >& samples)
14083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
14103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
14113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WrittenSize",		"Written size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
14123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("BufferSize",		"Buffer size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
14133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",			"Total time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("AllocTime",			"Alloc time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("MapTime",			"Map time",				"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UnmapTime",			"Unmap time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WriteTime",			"Write time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",		"Fit residual",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
14203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
14223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
14233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].writtenSize);
14243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
14253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].writtenSize
14263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].bufferSize
14273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.totalDuration
14283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.allocDuration
14293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.mapDuration
14303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.unmapDuration
14313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.writeDuration
14323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
14333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
14343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
14373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
14383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14398852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<UploadSampleResult<MapBufferRangeDurationNoAlloc> >& samples)
14403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
14423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
14433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WrittenSize",		"Written size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
14443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("BufferSize",		"Buffer size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
14453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",			"Total time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("MapTime",			"Map time",				"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UnmapTime",			"Unmap time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WriteTime",			"Write time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",		"Fit residual",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
14513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
14533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
14543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].writtenSize);
14553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
14563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].writtenSize
14573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].bufferSize
14583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.totalDuration
14593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.mapDuration
14603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.unmapDuration
14613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.writeDuration
14623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
14633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
14643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
14673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
14683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14698852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<UploadSampleResult<MapBufferRangeFlushDuration> >& samples)
14703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
14713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
14723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
14733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WrittenSize",		"Written size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
14743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("BufferSize",		"Buffer size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
14753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",			"Total time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("AllocTime",			"Alloc time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("MapTime",			"Map time",				"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UnmapTime",			"Unmap time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WriteTime",			"Write time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FlushTime",			"Flush time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",		"Fit residual",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
14823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
14833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
14843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
14853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
14863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].writtenSize);
14873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
14883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].writtenSize
14893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].bufferSize
14903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.totalDuration
14913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.allocDuration
14923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.mapDuration
14933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.unmapDuration
14943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.writeDuration
14953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.flushDuration
14963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
14973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
14983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
14993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
15013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15038852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<UploadSampleResult<MapBufferRangeFlushDurationNoAlloc> >& samples)
15043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
15063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
15073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WrittenSize",		"Written size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("BufferSize",		"Buffer size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",			"Total time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("MapTime",			"Map time",				"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UnmapTime",			"Unmap time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("WriteTime",			"Write time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FlushTime",			"Flush time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",		"Fit residual",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
15163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
15183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
15193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].writtenSize);
15203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
15213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].writtenSize
15223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].bufferSize
15233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.totalDuration
15243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.mapDuration
15253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.unmapDuration
15263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.writeDuration
15273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.flushDuration
15283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
15293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
15303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
15313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
15333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15358852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<RenderSampleResult<RenderReadDuration> >& samples)
15363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
15383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
15393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DataSize",			"Data processed",		"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("VertexCount",		"Number of vertices",	"vertices",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",			"Total time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawCallTime",		"Draw call time",		"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("ReadTime",			"ReadPixels time",		"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",		"Fit residual",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
15463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
15483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
15493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].renderDataSize);
15503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
15513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].renderDataSize
15523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].numVertices
15533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderReadDuration
15543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderDuration
15553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.readDuration
15563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
15573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
15583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
15593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
15613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15638852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<RenderSampleResult<UnrelatedUploadRenderReadDuration> >& samples)
15643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
15663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
15673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DataSize",				"Data processed",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("VertexCount",			"Number of vertices",		"vertices",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UnrelatedUploadSize",	"Unrelated upload size",	"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",				"Total time",				"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawCallTime",			"Draw call time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("ReadTime",				"ReadPixels time",			"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",			"Fit residual",				"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
15743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
15753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
15773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
15783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].renderDataSize);
15793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
15803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].renderDataSize
15813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].numVertices
15823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].unrelatedDataSize
15833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderReadDuration
15843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderDuration
15853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.readDuration
15863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
15873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
15883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
15893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
15913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
15923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
15938852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<RenderSampleResult<UploadRenderReadDuration> >& samples)
15943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
15953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
15963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
15973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DataSize",			"Data processed",					"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UploadSize",		"Data uploaded",					"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
15993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("VertexCount",		"Number of vertices",				"vertices",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
16003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawReadTime",		"Draw call and ReadPixels time",	"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",			"Total time",						"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("Upload time",		"Upload time",						"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawCallTime",		"Draw call time",					"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("ReadTime",			"ReadPixels time",					"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",		"Fit residual",						"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
16073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
16093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
16103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].renderDataSize);
16113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
16123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].renderDataSize
16133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].uploadedDataSize
16143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].numVertices
16153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderReadDuration
16163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.totalDuration
16173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.uploadDuration
16183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderDuration
16193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.readDuration
16203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
16213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
16223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
16233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
16253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
16263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16278852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<RenderSampleResult<UploadRenderReadDurationWithUnrelatedUploadSize> >& samples)
16283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
16293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
16303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
16313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DataSize",				"Data processed",					"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
16323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UploadSize",			"Data uploaded",					"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
16333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("VertexCount",			"Number of vertices",				"vertices",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
16343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UnrelatedUploadSize",	"Unrelated upload size",			"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
16353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawReadTime",			"Draw call and ReadPixels time",	"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",				"Total time",						"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("Upload time",			"Upload time",						"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawCallTime",			"Draw call time",					"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("ReadTime",				"ReadPixels time",					"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",			"Fit residual",						"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
16423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
16443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
16453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].renderDataSize);
16463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
16473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].renderDataSize
16483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].uploadedDataSize
16493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].numVertices
16503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].unrelatedDataSize
16513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderReadDuration
16523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.totalDuration
16533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.uploadDuration
16543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderDuration
16553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.readDuration
16563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
16573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
16583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
16593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
16613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
16623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16638852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryvoid logSampleList (tcu::TestLog& log, const LineParametersWithConfidence& theilSenFitting, const std::vector<RenderSampleResult<RenderUploadRenderReadDuration> >& samples)
16643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
16653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::SampleList("Samples", "Samples")
16663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
16673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DataSize",				"Data processed",						"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
16683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("UploadSize",			"Data uploaded",						"bytes",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
16693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("VertexCount",			"Number of vertices",					"vertices",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
16703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawReadTime",			"Second draw call and ReadPixels time",	"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",				"Total time",							"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FirstDrawCallTime",		"First draw call time",					"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("Upload time",			"Upload time",							"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("SecondDrawCallTime",	"Second draw call time",				"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("ReadTime",				"ReadPixels time",						"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("FitResidual",			"Fit residual",							"us",		QP_SAMPLE_VALUE_TAG_RESPONSE)
16773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
16783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)samples.size(); ++sampleNdx)
16803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
16813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float fitResidual = samples[sampleNdx].duration.fitResponseDuration - (theilSenFitting.offset + theilSenFitting.coefficient * samples[sampleNdx].renderDataSize);
16823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Sample
16833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].renderDataSize
16843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].uploadedDataSize
16853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< samples[sampleNdx].numVertices
16863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.renderReadDuration
16873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.totalDuration
16883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.firstRenderDuration
16893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.uploadDuration
16903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.secondRenderDuration
16913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)samples[sampleNdx].duration.readDuration
16923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< fitResidual
16933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
16943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
16953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	log << tcu::TestLog::EndSampleList;
16973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
16983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
16993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
17003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic UploadSampleAnalyzeResult analyzeSampleResults (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, bool logBucketPerformance)
17013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
17023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Assume data is linear with some outliers, fit a line
17038852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence									theilSenFitting						= fitLineToSamples(samples);
17043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const typename SampleTypeTraits<SampleType>::StatsType	resultStats							= calculateSampleStatistics(theilSenFitting, samples);
17053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float													approximatedTransferRate;
17063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float													approximatedTransferRateNoConstant;
17073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Output raw samples
17093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection	section(log, "Samples", "Samples");
17113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logSampleList(log, theilSenFitting, samples);
17123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Calculate results for different ranges
17153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (logBucketPerformance)
17163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int										numBuckets				= 4;
17183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int												minBufferSize			= 0;
17193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int												maxBufferSize			= 0;
17203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::vector<UploadSampleResult<SampleType> >	buckets[numBuckets];
17213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bucketizeSamplesUniformly(samples, &buckets[0], numBuckets, minBufferSize, maxBufferSize);
17233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int bucketNdx = 0; bucketNdx < numBuckets; ++bucketNdx)
17253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
17263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (buckets[bucketNdx].empty())
17273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				continue;
17283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Print a nice result summary
17303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int												bucketRangeMin	= minBufferSize + (int)(( bucketNdx    / (float)numBuckets) * (maxBufferSize - minBufferSize));
17323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int												bucketRangeMax	= minBufferSize + (int)(((bucketNdx+1) / (float)numBuckets) * (maxBufferSize - minBufferSize));
17333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const typename SampleTypeTraits<SampleType>::StatsType	stats			= calculateSampleStatistics(theilSenFitting, buckets[bucketNdx]);
17343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const tcu::ScopedLogSection								section			(log, "BufferSizeRange", std::string("Transfer performance with buffer size in range [").append(getHumanReadableByteSize(bucketRangeMin).append(", ").append(getHumanReadableByteSize(bucketRangeMax).append("]"))));
17353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			logMapRangeStats<SampleType>(log, stats);
17373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			logUnmapStats<SampleType>(log, stats);
17383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			logWriteStats<SampleType>(log, stats);
17393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			logFlushStats<SampleType>(log, stats);
17403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			logAllocStats<SampleType>(log, stats);
17413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log	<< tcu::TestLog::Float("Min", "Total: Min time", "us", QP_KEY_TAG_TIME, stats.result.minTime)
17433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("Max", "Total: Max time", "us", QP_KEY_TAG_TIME, stats.result.maxTime)
17443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("Min90", "Total: 90%-Min time", "us", QP_KEY_TAG_TIME, stats.result.min2DecileTime)
17453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("Max90", "Total: 90%-Max time", "us", QP_KEY_TAG_TIME, stats.result.max9DecileTime)
17463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("Median", "Total: Median time", "us", QP_KEY_TAG_TIME, stats.result.medianTime)
17473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("MedianTransfer", "Median transfer rate", "MB / s", QP_KEY_TAG_PERFORMANCE, stats.medianRate / 1024.0f / 1024.0f)
17483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("MaxDiff", "Max difference to approximated", "us", QP_KEY_TAG_TIME, stats.maxDiffTime)
17493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("Max90Diff", "90%-Max difference to approximated", "us", QP_KEY_TAG_TIME, stats.maxDiff9DecileTime)
17503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("MedianDiff", "Median difference to approximated", "us", QP_KEY_TAG_TIME, stats.medianDiffTime)
17513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("MaxRelDiff", "Max relative difference to approximated", "%", QP_KEY_TAG_NONE, stats.maxRelDiffTime * 100.0f)
17523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("Max90RelDiff", "90%-Max relative difference to approximated", "%", QP_KEY_TAG_NONE, stats.max9DecileRelDiffTime * 100.0f)
17533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Float("MedianRelDiff", "Median relative difference to approximated", "%", QP_KEY_TAG_NONE, stats.medianRelDiffTime * 100.0f);
17543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
17553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Contributions
17583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (SampleTypeTraits<SampleType>::LOG_CONTRIBUTIONS)
17593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection	section(log, "Contribution", "Contributions");
17613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logMapContribution(log, samples, resultStats);
17633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logUnmapContribution(log, samples, resultStats);
17643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logWriteContribution(log, samples, resultStats);
17653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logFlushContribution(log, samples, resultStats);
17663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logAllocContribution(log, samples, resultStats);
17673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Print results
17703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection	section(log, "Results", "Results");
17723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	medianBufferSize					= (samples.front().bufferSize + samples.back().bufferSize) / 2;
17743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float	approximatedTransferTime			= (theilSenFitting.offset + theilSenFitting.coefficient * medianBufferSize) / 1000.0f / 1000.0f;
17753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float	approximatedTransferTimeNoConstant	= (theilSenFitting.coefficient * medianBufferSize) / 1000.0f / 1000.0f;
17763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float	sampleLinearity						= calculateSampleFitLinearity(samples);
17773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float	sampleTemporalStability				= calculateSampleTemporalStability(samples);
17783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		approximatedTransferRateNoConstant				= medianBufferSize / approximatedTransferTimeNoConstant;
17803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		approximatedTransferRate						= medianBufferSize / approximatedTransferTime;
17813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Float("ResultLinearity", "Sample linearity", "%", QP_KEY_TAG_QUALITY, sampleLinearity * 100.0f)
17833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("SampleTemporalStability", "Sample temporal stability", "%", QP_KEY_TAG_QUALITY, sampleTemporalStability * 100.0f)
17843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedConstantCost", "Approximated contant cost", "us", QP_KEY_TAG_TIME, theilSenFitting.offset)
17858852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedConstantCostConfidence60Lower", "Approximated contant cost 60% confidence lower limit", "us", QP_KEY_TAG_TIME, theilSenFitting.offsetConfidenceLower)
17868852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedConstantCostConfidence60Upper", "Approximated contant cost 60% confidence upper limit", "us", QP_KEY_TAG_TIME, theilSenFitting.offsetConfidenceUpper)
17873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedLinearCost", "Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, theilSenFitting.coefficient * 1024.0f * 1024.0f)
17888852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedLinearCostConfidence60Lower", "Approximated linear cost 60% confidence lower limit", "us / MB", QP_KEY_TAG_TIME, theilSenFitting.coefficientConfidenceLower * 1024.0f * 1024.0f)
17898852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedLinearCostConfidence60Upper", "Approximated linear cost 60% confidence upper limit", "us / MB", QP_KEY_TAG_TIME, theilSenFitting.coefficientConfidenceUpper * 1024.0f * 1024.0f)
17903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedTransferRate", "Approximated transfer rate", "MB / s", QP_KEY_TAG_PERFORMANCE, approximatedTransferRate / 1024.0f / 1024.0f)
17913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedTransferRateNoConstant", "Approximated transfer rate without constant cost", "MB / s", QP_KEY_TAG_PERFORMANCE, approximatedTransferRateNoConstant / 1024.0f / 1024.0f)
17923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("SampleMedianTime", "Median sample time", "us", QP_KEY_TAG_TIME, resultStats.result.medianTime)
17933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("SampleMedianTransfer", "Median transfer rate", "MB / s", QP_KEY_TAG_PERFORMANCE, resultStats.medianRate / 1024.0f / 1024.0f);
17943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
17953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
17963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// return approximated transfer rate
17973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
17983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		UploadSampleAnalyzeResult result;
17993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.transferRateMedian = resultStats.medianRate;
18013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.transferRateAtRange = approximatedTransferRate;
18023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.transferRateAtInfinity = approximatedTransferRateNoConstant;
18033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return result;
18053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
18073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
18093c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic RenderSampleAnalyzeResult analyzeSampleResults (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples)
18103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Assume data is linear with some outliers, fit a line
18128852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const LineParametersWithConfidence									theilSenFitting						= fitLineToSamples(samples);
18133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const typename SampleTypeTraits<SampleType>::StatsType	resultStats							= calculateSampleStatistics(theilSenFitting, samples);
18143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float													approximatedProcessingRate;
18153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float													approximatedProcessingRateNoConstant;
18163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// output raw samples
18183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection	section(log, "Samples", "Samples");
18203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logSampleList(log, theilSenFitting, samples);
18213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Contributions
18243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (SampleTypeTraits<SampleType>::LOG_CONTRIBUTIONS)
18253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection	section(log, "Contribution", "Contributions");
18273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logFirstRenderContribution(log, samples, resultStats);
18293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logUploadContribution(log, samples, resultStats);
18303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logRenderContribution(log, samples, resultStats);
18313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logSecondRenderContribution(log, samples, resultStats);
18323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logReadContribution(log, samples, resultStats);
18333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logTotalContribution(log, samples, resultStats);
18343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// print results
18373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection	section(log, "Results", "Results");
18393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	medianDataSize						= (samples.front().renderDataSize + samples.back().renderDataSize) / 2;
18413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float	approximatedRenderTime				= (theilSenFitting.offset + theilSenFitting.coefficient * medianDataSize) / 1000.0f / 1000.0f;
18423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float	approximatedRenderTimeNoConstant	= (theilSenFitting.coefficient * medianDataSize) / 1000.0f / 1000.0f;
18433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float	sampleLinearity						= calculateSampleFitLinearity(samples);
18443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float	sampleTemporalStability				= calculateSampleTemporalStability(samples);
18453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		approximatedProcessingRateNoConstant			= medianDataSize / approximatedRenderTimeNoConstant;
18473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		approximatedProcessingRate						= medianDataSize / approximatedRenderTime;
18483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log	<< tcu::TestLog::Float("ResultLinearity", "Sample linearity", "%", QP_KEY_TAG_QUALITY, sampleLinearity * 100.0f)
18503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("SampleTemporalStability", "Sample temporal stability", "%", QP_KEY_TAG_QUALITY, sampleTemporalStability * 100.0f)
18513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedConstantCost", "Approximated contant cost", "us", QP_KEY_TAG_TIME, theilSenFitting.offset)
18528852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedConstantCostConfidence60Lower", "Approximated contant cost 60% confidence lower limit", "us", QP_KEY_TAG_TIME, theilSenFitting.offsetConfidenceLower)
18538852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedConstantCostConfidence60Upper", "Approximated contant cost 60% confidence upper limit", "us", QP_KEY_TAG_TIME, theilSenFitting.offsetConfidenceUpper)
18543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedLinearCost", "Approximated linear cost", "us / MB", QP_KEY_TAG_TIME, theilSenFitting.coefficient * 1024.0f * 1024.0f)
18558852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedLinearCostConfidence60Lower", "Approximated linear cost 60% confidence lower limit", "us / MB", QP_KEY_TAG_TIME, theilSenFitting.coefficientConfidenceLower * 1024.0f * 1024.0f)
18568852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedLinearCostConfidence60Upper", "Approximated linear cost 60% confidence upper limit", "us / MB", QP_KEY_TAG_TIME, theilSenFitting.coefficientConfidenceUpper * 1024.0f * 1024.0f)
18573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedProcessRate", "Approximated processing rate", "MB / s", QP_KEY_TAG_PERFORMANCE, approximatedProcessingRate / 1024.0f / 1024.0f)
18583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("ApproximatedProcessRateNoConstant", "Approximated processing rate without constant cost", "MB / s", QP_KEY_TAG_PERFORMANCE, approximatedProcessingRateNoConstant / 1024.0f / 1024.0f)
18593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("SampleMedianTime", "Median sample time", "us", QP_KEY_TAG_TIME, resultStats.result.medianTime)
18603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("SampleMedianProcess", "Median processing rate", "MB / s", QP_KEY_TAG_PERFORMANCE, resultStats.medianRate / 1024.0f / 1024.0f);
18613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// return approximated render rate
18643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
18653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RenderSampleAnalyzeResult result;
18663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.renderRateMedian		= resultStats.medianRate;
18683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.renderRateAtRange	= approximatedProcessingRate;
18693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.renderRateAtInfinity = approximatedProcessingRateNoConstant;
18703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return result;
18723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
18733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return RenderSampleAnalyzeResult();
18743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
18753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void generateTwoPassRandomIterationOrder (std::vector<int>& iterationOrder, int numSamples)
18773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
18783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	de::Random	rnd			(0xabc);
18793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int	midPoint	= (numSamples+1) / 2;		// !< ceil(m_numSamples / 2)
18803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT((int)iterationOrder.size() == numSamples);
18823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Two "passes" over range, randomize order in both passes
18843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// This allows to us detect if iterations are not independent
18853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// (first run and later run samples differ significantly?)
18863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < midPoint; ++sampleNdx)
18883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		iterationOrder[sampleNdx] = sampleNdx * 2;
18893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = midPoint; sampleNdx < numSamples; ++sampleNdx)
18903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		iterationOrder[sampleNdx] = (sampleNdx - midPoint) * 2 + 1;
18913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < midPoint; ++ndx)
18933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::swap(iterationOrder[ndx], iterationOrder[rnd.getInt(0, midPoint - 1)]);
18943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = midPoint; ndx < (int)iterationOrder.size(); ++ndx)
18953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::swap(iterationOrder[ndx], iterationOrder[rnd.getInt(midPoint, (int)iterationOrder.size()-1)]);
18963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
18973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
18983c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
18993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BasicBufferCase : public TestCase
19003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
19023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum Flags
19043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_ALLOCATE_LARGER_BUFFER = 0x01,
19063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
19073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							BasicBufferCase		(Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, int numSamples, int flags);
19083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~BasicBufferCase	(void);
19093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void			init				(void);
19113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void			deinit				(void);
19123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
19143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate				(void);
19153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual bool			runSample			(int iteration, UploadSampleResult<SampleType>& sample) = 0;
19173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void			logAndSetTestResult	(const std::vector<UploadSampleResult<SampleType> >& results) = 0;
19183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					disableGLWarmup		(void);
19203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					waitGLResults		(void);
19213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum
19233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DUMMY_RENDER_AREA_SIZE = 32
19253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
19263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::ShaderProgram*		m_dummyProgram;
19283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deInt32					m_dummyProgramPosLoc;
19293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_bufferID;
19303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_numSamples;
19323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_bufferSizeMin;
19333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_bufferSizeMax;
19343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool				m_allocateLargerBuffer;
19353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
19373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_iteration;
19383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<int>		m_iterationOrder;
19393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<UploadSampleResult<SampleType> > m_results;
19403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					m_useGL;
19423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_bufferRandomizerTimer;
19433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
19443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
19463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBasicBufferCase<SampleType>::BasicBufferCase (Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, int numSamples, int flags)
19473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase					(context, tcu::NODETYPE_PERFORMANCE, name, desc)
19483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_dummyProgram			(DE_NULL)
19493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_dummyProgramPosLoc		(-1)
19503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferID				(0)
19513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numSamples				(numSamples)
19523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferSizeMin			(bufferSizeMin)
19533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferSizeMax			(bufferSizeMax)
19543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_allocateLargerBuffer	((flags & FLAG_ALLOCATE_LARGER_BUFFER) != 0)
19553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_iteration				(0)
19563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_iterationOrder			(numSamples)
19573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_results					(numSamples)
19583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_useGL					(true)
19593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferRandomizerTimer	(0)
19603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// "randomize" iteration order. Deterministic, patternless
19623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	generateTwoPassRandomIterationOrder(m_iterationOrder, m_numSamples);
19633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// choose buffer sizes
19653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < m_numSamples; ++sampleNdx)
19663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int rawBufferSize			= (int)deFloatFloor(bufferSizeMin + (bufferSizeMax - bufferSizeMin) * ((float)(sampleNdx + 1) / m_numSamples));
19683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int bufferSize			= deAlign32(rawBufferSize, 16);
19693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int allocatedBufferSize	= deAlign32((m_allocateLargerBuffer) ? ((int)(bufferSize * 1.5f)) : (bufferSize), 16);
19703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_results[sampleNdx].bufferSize		= bufferSize;
19723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_results[sampleNdx].allocatedSize	= allocatedBufferSize;
19733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_results[sampleNdx].writtenSize	= -1;
19743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
19753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
19763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
19783c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBasicBufferCase<SampleType>::~BasicBufferCase (void)
19793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
19813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
19823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
19843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicBufferCase<SampleType>::init (void)
19853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
19863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
19873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_useGL)
19893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return;
19903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \note Viewport size is not checked, it won't matter if the render target actually is smaller hhan DUMMY_RENDER_AREA_SIZE
19923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// dummy shader
19943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
19953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_dummyProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(s_dummyVertexShader) << glu::FragmentSource(s_dummyFragnentShader));
19963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_dummyProgram->isOk())
19973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
19983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << *m_dummyProgram;
19993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::TestError("failed to build shader program");
20003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
20013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_dummyProgramPosLoc = gl.getAttribLocation(m_dummyProgram->getProgram(), "a_position");
20033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_dummyProgramPosLoc == -1)
20043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::TestError("a_position location was -1");
20053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20073c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
20083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicBufferCase<SampleType>::deinit (void)
20093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_bufferID)
20113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_bufferID);
20133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_bufferID = 0;
20143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
20153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_dummyProgram;
20173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_dummyProgram = DE_NULL;
20183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
20193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
20213c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCase::IterateResult BasicBufferCase<SampleType>::iterate (void)
20223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
20233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl				= m_context.getRenderContext().getFunctions();
20243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool				buffersWarmedUp	= false;
20253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const deUint32	usages[] =
20273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY,
20293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY,
20303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, GL_DYNAMIC_COPY,
20313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
20323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Allocate some random sized buffers and remove them to
20343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// make sure the first samples too have some buffers removed
20353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// just before their allocation. This is only needed by the
20363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// the first test.
20373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_useGL && !buffersWarmedUp)
20393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int					numRandomBuffers				= 6;
20413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int					numRepeats						= 10;
20423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int					maxBufferSize					= 16777216;
20433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const std::vector<deUint8>	zeroData						(maxBufferSize, 0x00);
20443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		de::Random					rnd								(0x1234);
20453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32					bufferIDs[numRandomBuffers]		= {0};
20463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.useProgram(m_dummyProgram->getProgram());
20483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.viewport(0, 0, DUMMY_RENDER_AREA_SIZE, DUMMY_RENDER_AREA_SIZE);
20493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.enableVertexAttribArray(m_dummyProgramPosLoc);
20503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < numRepeats; ++ndx)
20523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
20533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Create buffer and maybe draw from it
20543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int randomBufferNdx = 0; randomBufferNdx < numRandomBuffers; ++randomBufferNdx)
20553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
20563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int		randomSize	= deAlign32(rnd.getInt(1, maxBufferSize), 4*4);
20573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const deUint32	usage		= usages[rnd.getUint32() % (deUint32)DE_LENGTH_OF_ARRAY(usages)];
20583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.genBuffers(1, &bufferIDs[randomBufferNdx]);
20603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bindBuffer(GL_ARRAY_BUFFER, bufferIDs[randomBufferNdx]);
20613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bufferData(GL_ARRAY_BUFFER, randomSize, &zeroData[0], usage);
20623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (rnd.getBool())
20643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
20653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					gl.vertexAttribPointer(m_dummyProgramPosLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
20663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					gl.drawArrays(GL_POINTS, 0, 1);
20673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					gl.drawArrays(GL_POINTS, randomSize / (int)sizeof(float[4]) - 1, 1);
20683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
20693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
20703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int randomBufferNdx = 0; randomBufferNdx < numRandomBuffers; ++randomBufferNdx)
20723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.deleteBuffers(1, &bufferIDs[randomBufferNdx]);
20733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			waitGLResults();
20753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer gen");
20763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.touchWatchdog();
20783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
20793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		buffersWarmedUp = true;
20813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
20823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
20833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_useGL && m_bufferRandomizerTimer++ % 8 == 0)
20843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
20853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Do some random buffer operations to every now and then
20863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// to make sure the previous test iterations won't affect
20873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// following test runs.
20883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int					numRandomBuffers				= 3;
20903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int					maxBufferSize					= 16777216;
20913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const std::vector<deUint8>	zeroData						(maxBufferSize, 0x00);
20923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		de::Random					rnd								(0x1234 + 0xabc * m_bufferRandomizerTimer);
20933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// BufferData
20953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
20963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32 bufferIDs[numRandomBuffers] = {0};
20973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
20983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int randomBufferNdx = 0; randomBufferNdx < numRandomBuffers; ++randomBufferNdx)
20993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
21003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int		randomSize	= deAlign32(rnd.getInt(1, maxBufferSize), 4*4);
21013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const deUint32	usage		= usages[rnd.getUint32() % (deUint32)DE_LENGTH_OF_ARRAY(usages)];
21023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.genBuffers(1, &bufferIDs[randomBufferNdx]);
21043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bindBuffer(GL_ARRAY_BUFFER, bufferIDs[randomBufferNdx]);
21053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bufferData(GL_ARRAY_BUFFER, randomSize, &zeroData[0], usage);
21063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
21073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int randomBufferNdx = 0; randomBufferNdx < numRandomBuffers; ++randomBufferNdx)
21093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.deleteBuffers(1, &bufferIDs[randomBufferNdx]);
21103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "buffer ops");
21133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Do some memory mappings
21153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
21163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32 bufferIDs[numRandomBuffers] = {0};
21173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int randomBufferNdx = 0; randomBufferNdx < numRandomBuffers; ++randomBufferNdx)
21193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
21203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int		randomSize	= deAlign32(rnd.getInt(1, maxBufferSize), 4*4);
21213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const deUint32	usage		= usages[rnd.getUint32() % (deUint32)DE_LENGTH_OF_ARRAY(usages)];
21223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				void*			ptr;
21233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.genBuffers(1, &bufferIDs[randomBufferNdx]);
21253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bindBuffer(GL_ARRAY_BUFFER, bufferIDs[randomBufferNdx]);
21263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bufferData(GL_ARRAY_BUFFER, randomSize, &zeroData[0], usage);
21273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.vertexAttribPointer(m_dummyProgramPosLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
21293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.drawArrays(GL_POINTS, 0, 1);
21303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.drawArrays(GL_POINTS, randomSize / (int)sizeof(float[4]) - 1, 1);
21313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (rnd.getBool())
21333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					waitGLResults();
21343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ptr = gl.mapBufferRange(GL_ARRAY_BUFFER, 0, randomSize, GL_MAP_WRITE_BIT);
21363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (ptr)
21373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
21383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					medianTimeMemcpy(ptr, &zeroData[0], randomSize);
21393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					gl.unmapBuffer(GL_ARRAY_BUFFER);
21403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
21413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
21423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int randomBufferNdx = 0; randomBufferNdx < numRandomBuffers; ++randomBufferNdx)
21443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.deleteBuffers(1, &bufferIDs[randomBufferNdx]);
21453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			waitGLResults();
21473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "buffer maps");
21503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
21513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
21523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
21533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
21543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	currentIteration	= m_iteration;
21553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int	sampleNdx			= m_iterationOrder[currentIteration];
21563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool	sampleRunSuccessful	= runSample(currentIteration, m_results[sampleNdx]);
21573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "post runSample()");
21593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Retry failed samples
21613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!sampleRunSuccessful)
21623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return CONTINUE;
21633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (++m_iteration >= m_numSamples)
21653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
21663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			logAndSetTestResult(m_results);
21673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return STOP;
21683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
21693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
21703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return CONTINUE;
21713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
21723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
21733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
21753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicBufferCase<SampleType>::disableGLWarmup (void)
21763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
21773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_useGL = false;
21783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
21793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21803c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
21813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicBufferCase<SampleType>::waitGLResults (void)
21823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
21833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface dummySurface(DUMMY_RENDER_AREA_SIZE, DUMMY_RENDER_AREA_SIZE);
21843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), 0, 0, dummySurface.getAccess());
21853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
21863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
21873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
21883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BasicUploadCase : public BasicBufferCase<SampleType>
21893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
21903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
21913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum CaseType
21923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
21933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_NO_BUFFERS = 0,
21943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_NEW_BUFFER,
21953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_UNSPECIFIED_BUFFER,
21963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_SPECIFIED_BUFFER,
21973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_USED_BUFFER,
21983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_USED_LARGER_BUFFER,
21993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CASE_LAST
22013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
22023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum CaseFlags
22043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
22053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_DONT_LOG_BUFFER_INFO				= 0x01,
22063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_RESULT_BUFFER_UNSPECIFIED_CONTENT	= 0x02,
22073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
22083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum ResultType
22103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
22113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RESULT_MEDIAN_TRANSFER_RATE = 0,
22123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RESULT_ASYMPTOTIC_TRANSFER_RATE,
22133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
22143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						BasicUploadCase		(Context& context,
22163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const char* name,
22173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 const char* desc,
22183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 int bufferSizeMin,
22193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 int bufferSizeMax,
22203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 int numSamples,
22213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 deUint32 bufferUsage,
22223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 CaseType caseType,
22233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 ResultType resultType,
22243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry											 int flags = 0);
22253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						~BasicUploadCase	(void);
22273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void		init				(void);
22293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void		deinit				(void);
22303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
22323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				runSample			(int iteration, UploadSampleResult<SampleType>& sample);
22333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				createBuffer		(int bufferSize, int iteration);
22343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				deleteBuffer		(int bufferSize);
22353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				useBuffer			(int bufferSize);
22363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void		testBufferUpload	(UploadSampleResult<SampleType>& result, int writeSize) = 0;
22383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				logAndSetTestResult	(const std::vector<UploadSampleResult<SampleType> >& results);
22393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32			m_dummyBufferID;
22413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
22433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const CaseType		m_caseType;
22443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const ResultType	m_resultType;
22453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32		m_bufferUsage;
22463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool			m_logBufferInfo;
22473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool			m_bufferUnspecifiedContent;
22483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint8> m_zeroData;
22493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_testCtx;
22513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_context;
22523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::DUMMY_RENDER_AREA_SIZE;
22543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_dummyProgram;
22553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_dummyProgramPosLoc;
22563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_bufferID;
22573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_numSamples;
22583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_bufferSizeMin;
22593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_bufferSizeMax;
22603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_allocateLargerBuffer;
22613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
22623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22633c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
22643c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBasicUploadCase<SampleType>::BasicUploadCase (Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, int numSamples, deUint32 bufferUsage, CaseType caseType, ResultType resultType, int flags)
22653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: BasicBufferCase<SampleType>	(context, name, desc, bufferSizeMin, bufferSizeMax, numSamples, (caseType == CASE_USED_LARGER_BUFFER) ? (BasicBufferCase<SampleType>::FLAG_ALLOCATE_LARGER_BUFFER) : (0))
22663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_dummyBufferID				(0)
22673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_caseType					(caseType)
22683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_resultType					(resultType)
22693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferUsage					(bufferUsage)
22703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_logBufferInfo				((flags & FLAG_DONT_LOG_BUFFER_INFO) == 0)
22713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferUnspecifiedContent	((flags & FLAG_RESULT_BUFFER_UNSPECIFIED_CONTENT) != 0)
22723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_zeroData					()
22733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
22743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_caseType < CASE_LAST);
22753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
22763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
22783c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBasicUploadCase<SampleType>::~BasicUploadCase (void)
22793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
22803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
22813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
22823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
22843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicUploadCase<SampleType>::init (void)
22853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
22863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
22873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCase<SampleType>::init();
22893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// zero buffer as upload source
22913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_zeroData.resize(m_bufferSizeMax, 0x00);
22923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// dummy buffer
22943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.genBuffers(1, &m_dummyBufferID);
22963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Gen buf");
22973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
22983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// log basic info
22993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
23013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
23023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Testing performance with " << m_numSamples << " test samples. Sample order is randomized. All samples at even positions (first = 0) are tested before samples at odd positions.\n"
23033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Buffer sizes are in range [" << getHumanReadableByteSize(m_bufferSizeMin) << ", " << getHumanReadableByteSize(m_bufferSizeMax) << "]."
23043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
23053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_logBufferInfo)
23073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
23083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		switch (m_caseType)
23093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
23103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CASE_NO_BUFFERS:
23113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
23123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CASE_NEW_BUFFER:
23143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.getLog() << tcu::TestLog::Message << "Target buffer is generated but not specified (i.e glBufferData() not called)." << tcu::TestLog::EndMessage;
23153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
23163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CASE_UNSPECIFIED_BUFFER:
23183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.getLog() << tcu::TestLog::Message << "Target buffer is allocated with glBufferData(NULL)." << tcu::TestLog::EndMessage;
23193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
23203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CASE_SPECIFIED_BUFFER:
23223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.getLog() << tcu::TestLog::Message << "Target buffer contents are specified prior testing with glBufferData(data)." << tcu::TestLog::EndMessage;
23233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
23243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CASE_USED_BUFFER:
23263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.getLog() << tcu::TestLog::Message << "Target buffer has been used in drawing before testing." << tcu::TestLog::EndMessage;
23273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
23283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			case CASE_USED_LARGER_BUFFER:
23303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.getLog() << tcu::TestLog::Message << "Target buffer is larger and has been used in drawing before testing." << tcu::TestLog::EndMessage;
23313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
23323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			default:
23343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(false);
23353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				break;
23363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
23373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
23383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_resultType == RESULT_MEDIAN_TRANSFER_RATE)
23403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Test result is the median transfer rate of the test samples." << tcu::TestLog::EndMessage;
23413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_resultType == RESULT_ASYMPTOTIC_TRANSFER_RATE)
23423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Test result is the asymptotic transfer rate as the buffer size approaches infinity." << tcu::TestLog::EndMessage;
23433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
23443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
23453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
23463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
23483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicUploadCase<SampleType>::deinit (void)
23493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
23503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_dummyBufferID)
23513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
23523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_dummyBufferID);
23533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_dummyBufferID = 0;
23543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
23553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_zeroData.clear();
23573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCase<SampleType>::deinit();
23593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
23603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
23623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool BasicUploadCase<SampleType>::runSample (int iteration, UploadSampleResult<SampleType>& sample)
23633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
23643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl					= m_context.getRenderContext().getFunctions();
23653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				allocatedBufferSize	= sample.allocatedSize;
23663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				bufferSize			= sample.bufferSize;
23673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_caseType != CASE_NO_BUFFERS)
23693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		createBuffer(iteration, allocatedBufferSize);
23703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// warmup CPU before the test to make sure the power management governor
23723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// keeps us in the "high performance" mode
23733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
23743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deYield();
23753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::warmupCPU();
23763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deYield();
23773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
23783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	testBufferUpload(sample, bufferSize);
23803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer upload sample");
23813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_caseType != CASE_NO_BUFFERS)
23833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deleteBuffer(bufferSize);
23843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return true;
23863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
23873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
23893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicUploadCase<SampleType>::createBuffer (int iteration, int bufferSize)
23903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
23913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_bufferID);
23923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_caseType != CASE_NO_BUFFERS);
23933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
23953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// create buffer
23973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
23983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_caseType == CASE_NO_BUFFERS)
23993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return;
24003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// create empty buffer
24023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.genBuffers(1, &m_bufferID);
24043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_bufferID);
24053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer gen");
24063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_caseType == CASE_NEW_BUFFER)
24083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
24093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// upload something else first, this should reduce noise in samples
24103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		de::Random					rng				(0xbadc * iteration);
24123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int					sizeDelta		= rng.getInt(0, 2097140);
24133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int					dummyUploadSize = deAlign32(1048576 + sizeDelta, 4*4); // Vary buffer size to make sure it is always reallocated
24143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const std::vector<deUint8>	dummyData		(dummyUploadSize, 0x20);
24153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, m_dummyBufferID);
24173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, dummyUploadSize, &dummyData[0], m_bufferUsage);
24183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// make sure upload won't interfere with the test
24203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		useBuffer(dummyUploadSize);
24213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// don't kill the buffer so that the following upload cannot potentially reuse the buffer
24233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return;
24253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
24263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// specify it
24283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_caseType == CASE_UNSPECIFIED_BUFFER)
24303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, DE_NULL, m_bufferUsage);
24313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
24323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
24333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const std::vector<deUint8> dummyData(bufferSize, 0x20);
24343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, &dummyData[0], m_bufferUsage);
24353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
24363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_caseType == CASE_UNSPECIFIED_BUFFER || m_caseType == CASE_SPECIFIED_BUFFER)
24383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return;
24393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// use it and make sure it is uploaded
24413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	useBuffer(bufferSize);
24433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_caseType == CASE_USED_BUFFER || m_caseType == CASE_USED_LARGER_BUFFER);
24443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
24453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
24473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicUploadCase<SampleType>::deleteBuffer (int bufferSize)
24483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
24493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_bufferID);
24503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_caseType != CASE_NO_BUFFERS);
24513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// render from the buffer to make sure it actually made it to the gpu. This is to
24533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// make sure that if the upload actually happens later or is happening right now in
24543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// the background, it will not interfere with further test runs
24553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// if buffer contains unspecified content, sourcing data from it results in undefined
24573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// results, possibly including program termination. Specify all data to prevent such
24583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// case from happening
24593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
24613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_bufferID);
24633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_bufferUnspecifiedContent)
24653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
24663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const std::vector<deUint8> dummyData(bufferSize, 0x20);
24673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, &dummyData[0], m_bufferUsage);
24683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		GLU_EXPECT_NO_ERROR(gl.getError(), "re-specify buffer");
24703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
24713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	useBuffer(bufferSize);
24733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.deleteBuffers(1, &m_bufferID);
24753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_bufferID = 0;
24763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
24773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
24793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicUploadCase<SampleType>::useBuffer (int bufferSize)
24803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
24813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
24823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(m_dummyProgram->getProgram());
24843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.viewport(0, 0, DUMMY_RENDER_AREA_SIZE, DUMMY_RENDER_AREA_SIZE);
24863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.vertexAttribPointer(m_dummyProgramPosLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
24873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enableVertexAttribArray(m_dummyProgramPosLoc);
24883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// use whole buffer to make sure buffer is uploaded by drawing first and last
24903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(bufferSize % (int)sizeof(float[4]) == 0);
24913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays(GL_POINTS, 0, 1);
24923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays(GL_POINTS, bufferSize / (int)sizeof(float[4]) - 1, 1);
24933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCase<SampleType>::waitGLResults();
24953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
24963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
24973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
24983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BasicUploadCase<SampleType>::logAndSetTestResult (const std::vector<UploadSampleResult<SampleType> >& results)
24993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadSampleAnalyzeResult	analysis	= analyzeSampleResults(m_testCtx.getLog(), results, true);
25013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// with small buffers, report the median transfer rate of the samples
25033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// with large buffers, report the expected preformance of infinitely large buffers
25043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float						rate		= (m_resultType == RESULT_ASYMPTOTIC_TRANSFER_RATE) ? (analysis.transferRateAtInfinity) : (analysis.transferRateMedian);
25053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (rate == std::numeric_limits<float>::infinity())
25073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
25083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// sample times are 1) invalid or 2) timer resolution too low
25093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// report speed 0 bytes / s since real value cannot be determined
25103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString(0.0f, 2).c_str());
25113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
25123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
25133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
25143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// report transfer rate in MB / s
25153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString(rate / 1024.0f / 1024.0f, 2).c_str());
25163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
25173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ReferenceMemcpyCase : public BasicUploadCase<SingleOperationDuration>
25203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
25223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				ReferenceMemcpyCase		(Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, bool largeBuffersCase);
25233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				~ReferenceMemcpyCase	(void);
25243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void		init					(void);
25263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void		deinit					(void);
25273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
25283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void		testBufferUpload		(UploadSampleResult<SingleOperationDuration>& result, int bufferSize);
25293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint8> m_dstBuf;
25313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
25323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25333c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReferenceMemcpyCase::ReferenceMemcpyCase (Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, bool largeBuffersCase)
25343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: BasicUploadCase<SingleOperationDuration>	(ctx, name, desc, minBufferSize, maxBufferSize, numSamples, 0, CASE_NO_BUFFERS, (largeBuffersCase) ? (RESULT_ASYMPTOTIC_TRANSFER_RATE) : (RESULT_MEDIAN_TRANSFER_RATE))
25353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_dstBuf									()
25363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	disableGLWarmup();
25383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReferenceMemcpyCase::~ReferenceMemcpyCase (void)
25413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReferenceMemcpyCase::init (void)
25453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Describe what the test tries to do
25473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::Message << "Testing performance of memcpy()." << tcu::TestLog::EndMessage;
25483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_dstBuf.resize(m_bufferSizeMax, 0x00);
25503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicUploadCase<SingleOperationDuration>::init();
25523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReferenceMemcpyCase::deinit (void)
25553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_dstBuf.clear();
25573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicUploadCase<SingleOperationDuration>::deinit();
25583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReferenceMemcpyCase::testBufferUpload (UploadSampleResult<SingleOperationDuration>& result, int bufferSize)
25613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// write
25633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.totalDuration = medianTimeMemcpy(&m_dstBuf[0], &m_zeroData[0], bufferSize);
25643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.fitResponseDuration = result.duration.totalDuration;
25653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.writtenSize = bufferSize;
25673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BufferDataUploadCase : public BasicUploadCase<SingleOperationDuration>
25703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
25723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				BufferDataUploadCase	(Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, deUint32 bufferUsage, CaseType caseType);
25733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				~BufferDataUploadCase	(void);
25743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void		init					(void);
25763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
25773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void		testBufferUpload		(UploadSampleResult<SingleOperationDuration>& result, int bufferSize);
25783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
25793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25803c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferDataUploadCase::BufferDataUploadCase (Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, deUint32 bufferUsage, CaseType caseType)
25813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: BasicUploadCase<SingleOperationDuration>(ctx, name, desc, minBufferSize, maxBufferSize, numSamples, bufferUsage, caseType, RESULT_MEDIAN_TRANSFER_RATE)
25823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25853c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferDataUploadCase::~BufferDataUploadCase (void)
25863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25893c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BufferDataUploadCase::init (void)
25903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Describe what the test tries to do
25923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::Message << "Testing glBufferData() function." << tcu::TestLog::EndMessage;
25933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicUploadCase<SingleOperationDuration>::init();
25953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
25963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
25973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BufferDataUploadCase::testBufferUpload (UploadSampleResult<SingleOperationDuration>& result, int bufferSize)
25983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
25993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
26003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_bufferID);
26023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// upload
26043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
26053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
26063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
26073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
26093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, &m_zeroData[0], m_bufferUsage);
26103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
26113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.totalDuration = endTime - startTime;
26133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.fitResponseDuration = result.duration.totalDuration;
26143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.writtenSize = bufferSize;
26153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
26163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
26173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BufferSubDataUploadCase : public BasicUploadCase<SingleOperationDuration>
26193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
26203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
26213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum Flags
26223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
26233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_FULL_UPLOAD			= 0x01,
26243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_PARTIAL_UPLOAD			= 0x02,
26253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_INVALIDATE_BEFORE_USE	= 0x04,
26263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
26273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				BufferSubDataUploadCase		(Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, deUint32 bufferUsage, CaseType parentCase, int flags);
26293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				~BufferSubDataUploadCase	(void);
26303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void		init						(void);
26323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
26333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void		testBufferUpload			(UploadSampleResult<SingleOperationDuration>& result, int bufferSize);
26343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool	m_fullUpload;
26363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool	m_invalidateBeforeUse;
26373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
26383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26393c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferSubDataUploadCase::BufferSubDataUploadCase (Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, deUint32 bufferUsage, CaseType parentCase, int flags)
26403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: BasicUploadCase<SingleOperationDuration>	(ctx, name, desc, minBufferSize, maxBufferSize, numSamples, bufferUsage, parentCase, RESULT_MEDIAN_TRANSFER_RATE)
26413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fullUpload								((flags & FLAG_FULL_UPLOAD) != 0)
26423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_invalidateBeforeUse						((flags & FLAG_INVALIDATE_BEFORE_USE) != 0)
26433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
26443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT((flags & (FLAG_FULL_UPLOAD | FLAG_PARTIAL_UPLOAD)) != 0);
26453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT((flags & (FLAG_FULL_UPLOAD | FLAG_PARTIAL_UPLOAD)) != (FLAG_FULL_UPLOAD | FLAG_PARTIAL_UPLOAD));
26463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
26473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26483c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferSubDataUploadCase::~BufferSubDataUploadCase (void)
26493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
26503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
26513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BufferSubDataUploadCase::init (void)
26533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
26543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Describe what the test tries to do
26553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
26563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
26573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Testing glBufferSubData() function call performance. "
26583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_fullUpload) ? ("The whole buffer is updated with glBufferSubData. ") : ("Half of the buffer data is updated with glBufferSubData. "))
26593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_invalidateBeforeUse) ? ("The buffer is cleared with glBufferData(..., NULL) before glBufferSubData upload.") : ("")) << "\n"
26603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
26613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicUploadCase<SingleOperationDuration>::init();
26633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
26643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BufferSubDataUploadCase::testBufferUpload (UploadSampleResult<SingleOperationDuration>& result, int bufferSize)
26663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
26673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
26683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_bufferID);
26703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// "invalidate", upload null
26723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_invalidateBeforeUse)
26733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, DE_NULL, m_bufferUsage);
26743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// upload
26763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
26773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
26783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
26793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
26813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_fullUpload)
26833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferSubData(GL_ARRAY_BUFFER, 0, bufferSize, &m_zeroData[0]);
26843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
26853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
26863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// upload to buffer center
26873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferSubData(GL_ARRAY_BUFFER, bufferSize / 4, bufferSize / 2, &m_zeroData[0]);
26883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
26893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
26913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.totalDuration = endTime - startTime;
26933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.fitResponseDuration = result.duration.totalDuration;
26943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
26953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_fullUpload)
26963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			result.writtenSize = bufferSize;
26973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
26983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			result.writtenSize = bufferSize / 2;
26993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
27003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
27013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27023c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass MapBufferRangeCase : public BasicUploadCase<MapBufferRangeDuration>
27033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
27043c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
27053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum Flags
27063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
27073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_PARTIAL						= 0x01,
27083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_MANUAL_INVALIDATION			= 0x02,
27093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_USE_UNUSED_UNSPECIFIED_BUFFER	= 0x04,
27103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_USE_UNUSED_SPECIFIED_BUFFER	= 0x08,
27113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
27123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					MapBufferRangeCase			(Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, deUint32 bufferUsage, deUint32 mapFlags, int caseFlags);
27143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					~MapBufferRangeCase			(void);
27153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			init						(void);
27173c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
27183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static CaseType getBaseCaseType				(int caseFlags);
27193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static int		getBaseFlags				(deUint32 mapFlags, int caseFlags);
27203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			testBufferUpload			(UploadSampleResult<MapBufferRangeDuration>& result, int bufferSize);
27223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			attemptBufferMap			(UploadSampleResult<MapBufferRangeDuration>& result, int bufferSize);
27233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_manualInvalidation;
27253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_fullUpload;
27263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_useUnusedUnspecifiedBuffer;
27273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_useUnusedSpecifiedBuffer;
27283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32	m_mapFlags;
27293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_unmapFailures;
27303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
27313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27323c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMapBufferRangeCase::MapBufferRangeCase (Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, deUint32 bufferUsage, deUint32 mapFlags, int caseFlags)
27333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: BasicUploadCase<MapBufferRangeDuration>	(ctx, name, desc, minBufferSize, maxBufferSize, numSamples, bufferUsage, getBaseCaseType(caseFlags), RESULT_MEDIAN_TRANSFER_RATE, getBaseFlags(mapFlags, caseFlags))
27343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_manualInvalidation						((caseFlags&FLAG_MANUAL_INVALIDATION) != 0)
27353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fullUpload								((caseFlags&FLAG_PARTIAL) == 0)
27363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_useUnusedUnspecifiedBuffer				((caseFlags&FLAG_USE_UNUSED_UNSPECIFIED_BUFFER) != 0)
27373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_useUnusedSpecifiedBuffer				((caseFlags&FLAG_USE_UNUSED_SPECIFIED_BUFFER) != 0)
27383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_mapFlags								(mapFlags)
27393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_unmapFailures							(0)
27403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
27413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!(m_useUnusedUnspecifiedBuffer && m_useUnusedSpecifiedBuffer));
27423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!((m_useUnusedUnspecifiedBuffer || m_useUnusedSpecifiedBuffer) && m_manualInvalidation));
27433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
27443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMapBufferRangeCase::~MapBufferRangeCase (void)
27463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
27473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
27483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MapBufferRangeCase::init (void)
27503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
27513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Describe what the test tries to do
27523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
27533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
27543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Testing glMapBufferRange() and glUnmapBuffer() function call performance.\n"
27553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_fullUpload) ? ("The whole buffer is mapped.") : ("Half of the buffer is mapped.")) << "\n"
27563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_useUnusedUnspecifiedBuffer) ? ("The buffer has not been used before mapping and is allocated with unspecified contents.\n") : (""))
27573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_useUnusedSpecifiedBuffer) ? ("The buffer has not been used before mapping and is allocated with specified contents.\n") : (""))
27583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((!m_useUnusedSpecifiedBuffer && !m_useUnusedUnspecifiedBuffer) ? ("The buffer has previously been used in a drawing operation.\n") : (""))
27593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_manualInvalidation) ? ("The buffer is cleared with glBufferData(..., NULL) before mapping.\n") : (""))
27603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Map bits:\n"
27613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_WRITE_BIT) ? ("\tGL_MAP_WRITE_BIT\n") : (""))
27623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_READ_BIT) ? ("\tGL_MAP_READ_BIT\n") : (""))
27633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_INVALIDATE_RANGE_BIT) ? ("\tGL_MAP_INVALIDATE_RANGE_BIT\n") : (""))
27643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_INVALIDATE_BUFFER_BIT) ? ("\tGL_MAP_INVALIDATE_BUFFER_BIT\n") : (""))
27653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_UNSYNCHRONIZED_BIT) ? ("\tGL_MAP_UNSYNCHRONIZED_BIT\n") : (""))
27663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
27673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicUploadCase<MapBufferRangeDuration>::init();
27693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
27703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27713c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMapBufferRangeCase::CaseType MapBufferRangeCase::getBaseCaseType (int caseFlags)
27723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
27733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((caseFlags & FLAG_USE_UNUSED_UNSPECIFIED_BUFFER) == 0 && (caseFlags & FLAG_USE_UNUSED_SPECIFIED_BUFFER) == 0)
27743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CASE_USED_BUFFER;
27753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
27763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CASE_NEW_BUFFER;
27773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
27783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint MapBufferRangeCase::getBaseFlags (deUint32 mapFlags, int caseFlags)
27803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
27813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int flags = FLAG_DONT_LOG_BUFFER_INFO;
27823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// If buffer contains unspecified data when it is sourced (i.e drawn)
27843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// results are undefined, and system errors may occur. Signal parent
27853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// class to take this into account
27863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (caseFlags & FLAG_PARTIAL)
27873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
27883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if ((mapFlags & GL_MAP_INVALIDATE_BUFFER_BIT) != 0			||
27893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			(caseFlags & FLAG_MANUAL_INVALIDATION) != 0				||
27903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			(caseFlags & FLAG_USE_UNUSED_UNSPECIFIED_BUFFER) != 0)
27913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
27923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			flags |= FLAG_RESULT_BUFFER_UNSPECIFIED_CONTENT;
27933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
27943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
27953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return flags;
27973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
27983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
27993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MapBufferRangeCase::testBufferUpload (UploadSampleResult<MapBufferRangeDuration>& result, int bufferSize)
28003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
28013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int unmapFailureThreshold = 4;
28023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (; m_unmapFailures < unmapFailureThreshold; ++m_unmapFailures)
28043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
28053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		try
28063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
28073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			attemptBufferMap(result, bufferSize);
28083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return;
28093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
28103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		catch (UnmapFailureError&)
28113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
28123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
28133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
28143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	throw tcu::TestError("Unmapping failures exceeded limit");
28163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
28173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MapBufferRangeCase::attemptBufferMap (UploadSampleResult<MapBufferRangeDuration>& result, int bufferSize)
28193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
28203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
28213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_bufferID);
28233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_fullUpload)
28253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.writtenSize = bufferSize;
28263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
28273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.writtenSize = bufferSize / 2;
28283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create unused buffer
28303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_manualInvalidation || m_useUnusedUnspecifiedBuffer)
28323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
28333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
28343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
28353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// "invalidate" or allocate, upload null
28373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
28383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, DE_NULL, m_bufferUsage);
28393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
28403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.allocDuration = endTime - startTime;
28423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
28433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_useUnusedSpecifiedBuffer)
28443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
28453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
28463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
28473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Specify buffer contents
28493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
28503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, &m_zeroData[0], m_bufferUsage);
28513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
28523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.allocDuration = endTime - startTime;
28543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
28553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
28563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
28573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// No alloc, no time
28583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.allocDuration = 0;
28593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
28603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// upload
28623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
28633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		void* mapPtr;
28643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Map
28663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
28673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64 startTime;
28683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64 endTime;
28693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			startTime = deGetMicroseconds();
28713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_fullUpload)
28723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				mapPtr = gl.mapBufferRange(GL_ARRAY_BUFFER, 0, result.writtenSize, m_mapFlags);
28733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
28743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
28753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// upload to buffer center
28763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				mapPtr = gl.mapBufferRange(GL_ARRAY_BUFFER, bufferSize / 4, result.writtenSize, m_mapFlags);
28773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
28783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			endTime = deGetMicroseconds();
28793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!mapPtr)
28813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::Exception("MapBufferRange returned NULL");
28823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			result.duration.mapDuration = endTime - startTime;
28843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
28853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Write
28873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
28883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			result.duration.writeDuration = medianTimeMemcpy(mapPtr, &m_zeroData[0], result.writtenSize);
28893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
28903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Unmap
28923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
28933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64		startTime;
28943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64		endTime;
28953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glw::GLboolean	unmapSuccessful;
28963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
28973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			startTime = deGetMicroseconds();
28983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			unmapSuccessful = gl.unmapBuffer(GL_ARRAY_BUFFER);
28993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			endTime = deGetMicroseconds();
29003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// if unmapping fails, just try again later
29023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!unmapSuccessful)
29033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw UnmapFailureError();
29043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			result.duration.unmapDuration = endTime - startTime;
29063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
29073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.totalDuration = result.duration.mapDuration + result.duration.writeDuration + result.duration.unmapDuration + result.duration.allocDuration;
29093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.fitResponseDuration = result.duration.totalDuration;
29103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
29113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
29123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass MapBufferRangeFlushCase : public BasicUploadCase<MapBufferRangeFlushDuration>
29143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
29153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
29163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum Flags
29173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
29183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_PARTIAL						= 0x01,
29193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_FLUSH_IN_PARTS					= 0x02,
29203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_USE_UNUSED_UNSPECIFIED_BUFFER	= 0x04,
29213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_USE_UNUSED_SPECIFIED_BUFFER	= 0x08,
29223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_FLUSH_PARTIAL					= 0x10,
29233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
29243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					MapBufferRangeFlushCase		(Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, deUint32 bufferUsage, deUint32 mapFlags, int caseFlags);
29263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					~MapBufferRangeFlushCase	(void);
29273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			init						(void);
29293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
29303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static CaseType getBaseCaseType				(int caseFlags);
29313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static int		getBaseFlags				(deUint32 mapFlags, int caseFlags);
29323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			testBufferUpload			(UploadSampleResult<MapBufferRangeFlushDuration>& result, int bufferSize);
29343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			attemptBufferMap			(UploadSampleResult<MapBufferRangeFlushDuration>& result, int bufferSize);
29353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_fullUpload;
29373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_flushInParts;
29383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_flushPartial;
29393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_useUnusedUnspecifiedBuffer;
29403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_useUnusedSpecifiedBuffer;
29413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32	m_mapFlags;
29423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_unmapFailures;
29433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
29443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMapBufferRangeFlushCase::MapBufferRangeFlushCase (Context& ctx, const char* name, const char* desc, int minBufferSize, int maxBufferSize, int numSamples, deUint32 bufferUsage, deUint32 mapFlags, int caseFlags)
29463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: BasicUploadCase<MapBufferRangeFlushDuration>	(ctx, name, desc, minBufferSize, maxBufferSize, numSamples, bufferUsage, getBaseCaseType(caseFlags), RESULT_MEDIAN_TRANSFER_RATE, getBaseFlags(mapFlags, caseFlags))
29473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_fullUpload									((caseFlags&FLAG_PARTIAL) == 0)
29483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_flushInParts								((caseFlags&FLAG_FLUSH_IN_PARTS) != 0)
29493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_flushPartial								((caseFlags&FLAG_FLUSH_PARTIAL) != 0)
29503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_useUnusedUnspecifiedBuffer					((caseFlags&FLAG_USE_UNUSED_UNSPECIFIED_BUFFER) != 0)
29513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_useUnusedSpecifiedBuffer					((caseFlags&FLAG_USE_UNUSED_SPECIFIED_BUFFER) != 0)
29523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_mapFlags									(mapFlags)
29533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_unmapFailures								(0)
29543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
29553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!(m_flushPartial && m_flushInParts));
29563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!(m_flushPartial && !m_fullUpload));
29573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
29583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29593c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMapBufferRangeFlushCase::~MapBufferRangeFlushCase (void)
29603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
29613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
29623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MapBufferRangeFlushCase::init (void)
29643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
29653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Describe what the test tries to do
29663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
29673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
29683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Testing glMapBufferRange(), glFlushMappedBufferRange() and glUnmapBuffer() function call performance.\n"
29693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_fullUpload) ? ("The whole buffer is mapped.") : ("Half of the buffer is mapped.")) << "\n"
29703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_flushInParts) ?
29713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("The mapped range is partitioned to 4 subranges and each partition is flushed separately.") :
29723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			(m_flushPartial) ?
29733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				("Half of the buffer range is flushed.") :
29743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				("The whole mapped range is flushed in one flush call.")) << "\n"
29753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_useUnusedUnspecifiedBuffer) ? ("The buffer has not been used before mapping and is allocated with unspecified contents.\n") : (""))
29763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_useUnusedSpecifiedBuffer) ? ("The buffer has not been used before mapping and is allocated with specified contents.\n") : (""))
29773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((!m_useUnusedSpecifiedBuffer && !m_useUnusedUnspecifiedBuffer) ? ("The buffer has previously been used in a drawing operation.\n") : (""))
29783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Map bits:\n"
29793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_WRITE_BIT) ? ("\tGL_MAP_WRITE_BIT\n") : (""))
29803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_READ_BIT) ? ("\tGL_MAP_READ_BIT\n") : (""))
29813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_INVALIDATE_RANGE_BIT) ? ("\tGL_MAP_INVALIDATE_RANGE_BIT\n") : (""))
29823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_INVALIDATE_BUFFER_BIT) ? ("\tGL_MAP_INVALIDATE_BUFFER_BIT\n") : (""))
29833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_UNSYNCHRONIZED_BIT) ? ("\tGL_MAP_UNSYNCHRONIZED_BIT\n") : (""))
29843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_FLUSH_EXPLICIT_BIT) ? ("\tGL_MAP_FLUSH_EXPLICIT_BIT\n") : (""))
29853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
29863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicUploadCase<MapBufferRangeFlushDuration>::init();
29883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
29893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMapBufferRangeFlushCase::CaseType MapBufferRangeFlushCase::getBaseCaseType (int caseFlags)
29913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
29923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((caseFlags & FLAG_USE_UNUSED_UNSPECIFIED_BUFFER) == 0 && (caseFlags & FLAG_USE_UNUSED_SPECIFIED_BUFFER) == 0)
29933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CASE_USED_BUFFER;
29943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
29953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CASE_NEW_BUFFER;
29963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
29973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
29983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint MapBufferRangeFlushCase::getBaseFlags (deUint32 mapFlags, int caseFlags)
29993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
30003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int flags = FLAG_DONT_LOG_BUFFER_INFO;
30013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// If buffer contains unspecified data when it is sourced (i.e drawn)
30033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// results are undefined, and system errors may occur. Signal parent
30043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// class to take this into account
30053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (caseFlags & FLAG_PARTIAL)
30063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
30073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if ((mapFlags & GL_MAP_INVALIDATE_BUFFER_BIT) != 0			||
30083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			(caseFlags & FLAG_USE_UNUSED_UNSPECIFIED_BUFFER) != 0	||
30093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			(caseFlags & FLAG_FLUSH_PARTIAL) != 0)
30103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
30113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			flags |= FLAG_RESULT_BUFFER_UNSPECIFIED_CONTENT;
30123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
30133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
30143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return flags;
30163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
30173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MapBufferRangeFlushCase::testBufferUpload (UploadSampleResult<MapBufferRangeFlushDuration>& result, int bufferSize)
30193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
30203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int unmapFailureThreshold = 4;
30213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (; m_unmapFailures < unmapFailureThreshold; ++m_unmapFailures)
30233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
30243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		try
30253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
30263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			attemptBufferMap(result, bufferSize);
30273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return;
30283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
30293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		catch (UnmapFailureError&)
30303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
30313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
30323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
30333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	throw tcu::TestError("Unmapping failures exceeded limit");
30353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
30363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MapBufferRangeFlushCase::attemptBufferMap (UploadSampleResult<MapBufferRangeFlushDuration>& result, int bufferSize)
30383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
30393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl			= m_context.getRenderContext().getFunctions();
30403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				mappedSize	= (m_fullUpload) ? (bufferSize) : (bufferSize / 2);
30413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_fullUpload && !m_flushPartial)
30433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.writtenSize = bufferSize;
30443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
30453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.writtenSize = bufferSize / 2;
30463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_bufferID);
30483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Create unused buffer
30503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_useUnusedUnspecifiedBuffer)
30523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
30533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
30543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
30553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Don't specify contents
30573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
30583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, DE_NULL, m_bufferUsage);
30593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
30603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.allocDuration = endTime - startTime;
30623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
30633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_useUnusedSpecifiedBuffer)
30643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
30653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
30663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
30673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Specify buffer contents
30693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
30703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, &m_zeroData[0], m_bufferUsage);
30713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
30723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.allocDuration = endTime - startTime;
30743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
30753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
30763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
30773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// No alloc, no time
30783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.allocDuration = 0;
30793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
30803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// upload
30823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
30833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		void* mapPtr;
30843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Map
30863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
30873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64 startTime;
30883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64 endTime;
30893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
30903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			startTime = deGetMicroseconds();
30913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_fullUpload)
30923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				mapPtr = gl.mapBufferRange(GL_ARRAY_BUFFER, 0, mappedSize, m_mapFlags);
30933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
30943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
30953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// upload to buffer center
30963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				mapPtr = gl.mapBufferRange(GL_ARRAY_BUFFER, bufferSize / 4, mappedSize, m_mapFlags);
30973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
30983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			endTime = deGetMicroseconds();
30993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!mapPtr)
31013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::Exception("MapBufferRange returned NULL");
31023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			result.duration.mapDuration = endTime - startTime;
31043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
31053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Write
31073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
31083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!m_flushPartial)
31093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				result.duration.writeDuration = medianTimeMemcpy(mapPtr, &m_zeroData[0], result.writtenSize);
31103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
31113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				result.duration.writeDuration = medianTimeMemcpy((deUint8*)mapPtr + bufferSize / 4, &m_zeroData[0], result.writtenSize);
31123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
31133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Flush
31153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
31163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64	startTime;
31173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64	endTime;
31183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			startTime = deGetMicroseconds();
31203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_flushPartial)
31223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.flushMappedBufferRange(GL_ARRAY_BUFFER, mappedSize/4, mappedSize/2);
31233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (!m_flushInParts)
31243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.flushMappedBufferRange(GL_ARRAY_BUFFER, 0, mappedSize);
31253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
31263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
31273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int p1 = 0;
31283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int p2 = mappedSize / 3;
31293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int p3 = mappedSize / 2;
31303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int p4 = mappedSize * 2 / 4;
31313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const int p5 = mappedSize;
31323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// flush in mixed order
31343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.flushMappedBufferRange(GL_ARRAY_BUFFER, p2,	p3-p2);
31353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.flushMappedBufferRange(GL_ARRAY_BUFFER, p1,	p2-p1);
31363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.flushMappedBufferRange(GL_ARRAY_BUFFER, p4,	p5-p4);
31373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.flushMappedBufferRange(GL_ARRAY_BUFFER, p3,	p4-p3);
31383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
31393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			endTime = deGetMicroseconds();
31413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			result.duration.flushDuration = endTime - startTime;
31433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
31443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Unmap
31463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
31473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64		startTime;
31483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint64		endTime;
31493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glw::GLboolean	unmapSuccessful;
31503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			startTime = deGetMicroseconds();
31523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			unmapSuccessful = gl.unmapBuffer(GL_ARRAY_BUFFER);
31533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			endTime = deGetMicroseconds();
31543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// if unmapping fails, just try again later
31563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!unmapSuccessful)
31573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw UnmapFailureError();
31583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			result.duration.unmapDuration = endTime - startTime;
31603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
31613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.totalDuration = result.duration.mapDuration + result.duration.writeDuration + result.duration.flushDuration + result.duration.unmapDuration + result.duration.allocDuration;
31633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.fitResponseDuration = result.duration.totalDuration;
31643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
31653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
31663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
31683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ModifyAfterBasicCase : public BasicBufferCase<SampleType>
31693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
31703c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
31713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						ModifyAfterBasicCase	(Context& context, const char* name, const char* description, int bufferSizeMin, int bufferSizeMax, deUint32 usage, bool bufferUnspecifiedAfterTest);
31723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						~ModifyAfterBasicCase	(void);
31733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				init					(void);
31753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				deinit					(void);
31763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
31783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				drawBufferRange			(int begin, int end);
31793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
31813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum
31823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
31833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		NUM_SAMPLES = 20,
31843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
31853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				runSample				(int iteration, UploadSampleResult<SampleType>& sample);
31883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool				prepareAndRunTest		(int iteration, UploadSampleResult<SampleType>& result, int bufferSize);
31893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				logAndSetTestResult		(const std::vector<UploadSampleResult<SampleType> >& results);
31903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void		testWithBufferSize		(UploadSampleResult<SampleType>& result, int bufferSize) = 0;
31923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_unmappingErrors;
31943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
31953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
31963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool			m_bufferUnspecifiedAfterTest;
31973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32		m_bufferUsage;
31983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint8> m_zeroData;
31993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_testCtx;
32013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_context;
32023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::DUMMY_RENDER_AREA_SIZE;
32043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_dummyProgram;
32053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_dummyProgramPosLoc;
32063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_bufferID;
32073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_numSamples;
32083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_bufferSizeMin;
32093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_bufferSizeMax;
32103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using BasicBufferCase<SampleType>::m_allocateLargerBuffer;
32113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
32123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
32143c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterBasicCase<SampleType>::ModifyAfterBasicCase (Context& context, const char* name, const char* description, int bufferSizeMin, int bufferSizeMax, deUint32 usage, bool bufferUnspecifiedAfterTest)
32153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: BasicBufferCase<SampleType>	(context, name, description, bufferSizeMin, bufferSizeMax, NUM_SAMPLES, 0)
32163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_unmappingErrors				(0)
32173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferUnspecifiedAfterTest	(bufferUnspecifiedAfterTest)
32183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferUsage					(usage)
32193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_zeroData					()
32203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
32213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
32223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
32243c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterBasicCase<SampleType>::~ModifyAfterBasicCase (void)
32253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
32263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCase<SampleType>::deinit();
32273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
32283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32293c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
32303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterBasicCase<SampleType>::init (void)
32313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
32323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
32333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// init parent
32353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCase<SampleType>::init();
32373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// upload source
32393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_zeroData.resize(m_bufferSizeMax, 0x00);
32403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// log basic info
32423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
32443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
32453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Testing performance with " << (int)NUM_SAMPLES << " test samples. Sample order is randomized. All samples at even positions (first = 0) are tested before samples at odd positions.\n"
32463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Buffer sizes are in range [" << getHumanReadableByteSize(m_bufferSizeMin) << ", " << getHumanReadableByteSize(m_bufferSizeMax) << "]."
32473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
32483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// log which transfer rate is the test result and buffer info
32503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
32523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
32533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Test result is the median transfer rate of the test samples.\n"
32543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Buffer usage = " << glu::getUsageName(m_bufferUsage)
32553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
32563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Set state for drawing so that we don't have to change these during the iteration
32583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
32593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.useProgram(m_dummyProgram->getProgram());
32603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.viewport(0, 0, DUMMY_RENDER_AREA_SIZE, DUMMY_RENDER_AREA_SIZE);
32613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.enableVertexAttribArray(m_dummyProgramPosLoc);
32623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
32633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
32643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
32663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterBasicCase<SampleType>::deinit (void)
32673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
32683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_zeroData.clear();
32693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCase<SampleType>::deinit();
32713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
32723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
32743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterBasicCase<SampleType>::drawBufferRange (int begin, int end)
32753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
32763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(begin % (int)sizeof(float[4]) == 0);
32773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(end % (int)sizeof(float[4]) == 0);
32783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
32803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// use given range
32823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays(GL_POINTS, begin / (int)sizeof(float[4]), 1);
32833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays(GL_POINTS, end / (int)sizeof(float[4]) - 1, 1);
32843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
32853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
32873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool ModifyAfterBasicCase<SampleType>::runSample (int iteration, UploadSampleResult<SampleType>& sample)
32883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
32893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl					= m_context.getRenderContext().getFunctions();
32903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				bufferSize			= sample.bufferSize;
32913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					testOk;
32923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	testOk = prepareAndRunTest(iteration, sample, bufferSize);
32943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer upload sample");
32953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
32963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!testOk)
32973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
32983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int unmapFailureThreshold = 4;
32993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// only unmapping error can cause iteration failure
33013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (++m_unmappingErrors >= unmapFailureThreshold)
33023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::TestError("Too many unmapping errors, cannot continue.");
33033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// just try again
33053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
33063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
33073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return true;
33093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
33103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
33123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool ModifyAfterBasicCase<SampleType>::prepareAndRunTest (int iteration, UploadSampleResult<SampleType>& result, int bufferSize)
33133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
33143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(iteration);
33153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!m_bufferID);
33173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(deIsAligned32(bufferSize, 4*4)); // aligned to vec4
33183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&		gl				= m_context.getRenderContext().getFunctions();
33203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool						testRunOk		= true;
33213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool						unmappingFailed	= false;
33223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Upload initial buffer to the GPU...
33243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.genBuffers(1, &m_bufferID);
33253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_bufferID);
33263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bufferData(GL_ARRAY_BUFFER, bufferSize, &m_zeroData[0], m_bufferUsage);
33273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// ...use it...
33293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.vertexAttribPointer(m_dummyProgramPosLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
33303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawBufferRange(0, bufferSize);
33313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// ..and make sure it is uploaded
33333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCase<SampleType>::waitGLResults();
33343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// warmup CPU before the test to make sure the power management governor
33363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// keeps us in the "high performance" mode
33373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
33383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deYield();
33393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::warmupCPU();
33403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deYield();
33413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
33423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// test
33443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
33453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
33463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// buffer is uploaded to the GPU. Draw from it.
33473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		drawBufferRange(0, bufferSize);
33483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// and test upload
33503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		testWithBufferSize(result, bufferSize);
33513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
33523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (UnmapFailureError&)
33533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
33543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		testRunOk = false;
33553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		unmappingFailed = true;
33563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
33573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// clean up: make sure buffer is not in upload queue and delete it
33593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// sourcing unspecified data causes undefined results, possibly program termination
33613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_bufferUnspecifiedAfterTest || unmappingFailed)
33623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, bufferSize, &m_zeroData[0], m_bufferUsage);
33633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	drawBufferRange(0, bufferSize);
33653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BasicBufferCase<SampleType>::waitGLResults();
33663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.deleteBuffers(1, &m_bufferID);
33683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_bufferID = 0;
33693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return testRunOk;
33713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
33723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
33743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterBasicCase<SampleType>::logAndSetTestResult (const std::vector<UploadSampleResult<SampleType> >& results)
33753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
33763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadSampleAnalyzeResult analysis = analyzeSampleResults(m_testCtx.getLog(), results, false);
33773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Return median transfer rate of the samples
33793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (analysis.transferRateMedian == std::numeric_limits<float>::infinity())
33813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
33823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// sample times are 1) invalid or 2) timer resolution too low
33833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// report speed 0 bytes / s since real value cannot be determined
33843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString(0.0f, 2).c_str());
33853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
33863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
33873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
33883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// report transfer rate in MB / s
33893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString(analysis.transferRateMedian / 1024.0f / 1024.0f, 2).c_str());
33903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
33913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
33923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ModifyAfterWithBufferDataCase : public ModifyAfterBasicCase<SingleOperationDuration>
33943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
33953c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
33963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
33973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum CaseFlags
33983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
33993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_RESPECIFY_SIZE		= 0x1,
34003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_UPLOAD_REPEATED	= 0x2,
34013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
34023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ModifyAfterWithBufferDataCase	(Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, deUint32 usage, int flags);
34043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					~ModifyAfterWithBufferDataCase	(void);
34053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			init							(void);
34073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			deinit							(void);
34083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
34093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			testWithBufferSize				(UploadSampleResult<SingleOperationDuration>& result, int bufferSize);
34103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum
34123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
34133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		NUM_REPEATS = 2
34143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
34153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_respecifySize;
34173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_repeatedUpload;
34183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const float		m_sizeDifferenceFactor;
34193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
34203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34213c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterWithBufferDataCase::ModifyAfterWithBufferDataCase (Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, deUint32 usage, int flags)
34223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ModifyAfterBasicCase<SingleOperationDuration> (context, name, desc, bufferSizeMin, bufferSizeMax, usage, false)
34233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_respecifySize								((flags & FLAG_RESPECIFY_SIZE) != 0)
34243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_repeatedUpload								((flags & FLAG_UPLOAD_REPEATED) != 0)
34253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_sizeDifferenceFactor						(1.3f)
34263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
34273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(!(m_repeatedUpload && m_respecifySize));
34283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
34293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34303c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterWithBufferDataCase::~ModifyAfterWithBufferDataCase (void)
34313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
34323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
34333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
34343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithBufferDataCase::init (void)
34363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
34373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log the purpose of the test
34383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_repeatedUpload)
34403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Testing performance of BufferData() command after \"specify buffer contents - draw buffer\" command pair is repeated " << (int)NUM_REPEATS << " times." << tcu::TestLog::EndMessage;
34413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
34423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Testing performance of BufferData() command after a draw command that sources data from the target buffer." << tcu::TestLog::EndMessage;
34433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
34453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
34463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_respecifySize) ?
34473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("Buffer size is increased and contents are modified with BufferData().\n") :
34483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("Buffer contents are modified with BufferData().\n"))
34493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
34503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// init parent
34523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ModifyAfterBasicCase<SingleOperationDuration>::init();
34533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// make sure our zeroBuffer is large enough
34553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_respecifySize)
34563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
34573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int largerBufferSize = deAlign32((int)(m_bufferSizeMax * m_sizeDifferenceFactor), 4*4);
34583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_zeroData.resize(largerBufferSize, 0x00);
34593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
34603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
34613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithBufferDataCase::deinit (void)
34633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
34643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ModifyAfterBasicCase<SingleOperationDuration>::deinit();
34653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
34663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithBufferDataCase::testWithBufferSize (UploadSampleResult<SingleOperationDuration>& result, int bufferSize)
34683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
34693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// always draw the same amount to make compares between cases sensible
34703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					drawStart			= deAlign32(bufferSize / 4, 4*4);
34713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					drawEnd				= deAlign32(bufferSize * 3 / 4, 4*4);
34723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&		gl					= m_context.getRenderContext().getFunctions();
34743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					largerBufferSize	= deAlign32((int)(bufferSize * m_sizeDifferenceFactor), 4*4);
34753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					newBufferSize		= (m_respecifySize) ? (largerBufferSize) : (bufferSize);
34763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64					startTime;
34773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64					endTime;
34783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// repeat upload-draw
34803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_repeatedUpload)
34813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
34823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int repeatNdx = 0; repeatNdx < NUM_REPEATS; ++repeatNdx)
34833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
34843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(GL_ARRAY_BUFFER, newBufferSize, &m_zeroData[0], m_bufferUsage);
34853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			drawBufferRange(drawStart, drawEnd);
34863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
34873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
34883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// test upload
34903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	startTime = deGetMicroseconds();
34913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bufferData(GL_ARRAY_BUFFER, newBufferSize, &m_zeroData[0], m_bufferUsage);
34923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	endTime = deGetMicroseconds();
34933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.totalDuration = endTime - startTime;
34953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.fitResponseDuration = result.duration.totalDuration;
34963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.writtenSize = newBufferSize;
34973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
34983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
34993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ModifyAfterWithBufferSubDataCase : public ModifyAfterBasicCase<SingleOperationDuration>
35003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
35013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
35023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum CaseFlags
35043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
35053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_PARTIAL			= 0x1,
35063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_UPLOAD_REPEATED	= 0x2,
35073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
35083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ModifyAfterWithBufferSubDataCase	(Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, deUint32 usage, int flags);
35103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					~ModifyAfterWithBufferSubDataCase	(void);
35113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			init								(void);
35133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			deinit								(void);
35143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
35153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			testWithBufferSize					(UploadSampleResult<SingleOperationDuration>& result, int bufferSize);
35163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum
35183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
35193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		NUM_REPEATS = 2
35203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
35213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_partialUpload;
35233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_repeatedUpload;
35243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
35253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35263c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterWithBufferSubDataCase::ModifyAfterWithBufferSubDataCase (Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, deUint32 usage, int flags)
35273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ModifyAfterBasicCase<SingleOperationDuration>	(context, name, desc, bufferSizeMin, bufferSizeMax, usage, false)
35283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_partialUpload								((flags & FLAG_PARTIAL) != 0)
35293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_repeatedUpload								((flags & FLAG_UPLOAD_REPEATED) != 0)
35303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
35313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
35323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35333c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterWithBufferSubDataCase::~ModifyAfterWithBufferSubDataCase (void)
35343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
35353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
35363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
35373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithBufferSubDataCase::init (void)
35393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
35403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log the purpose of the test
35413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_repeatedUpload)
35433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Testing performance of BufferSubData() command after \"specify buffer contents - draw buffer\" command pair is repeated " << (int)NUM_REPEATS << " times." << tcu::TestLog::EndMessage;
35443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
35453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::Message << "Testing performance of BufferSubData() command after a draw command that sources data from the target buffer." << tcu::TestLog::EndMessage;
35463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
35483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
35493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_partialUpload) ?
35503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("Half of the buffer contents are modified.\n") :
35513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("Buffer contents are fully respecified.\n"))
35523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
35533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ModifyAfterBasicCase<SingleOperationDuration>::init();
35553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
35563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithBufferSubDataCase::deinit (void)
35583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
35593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ModifyAfterBasicCase<SingleOperationDuration>::deinit();
35603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
35613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithBufferSubDataCase::testWithBufferSize (UploadSampleResult<SingleOperationDuration>& result, int bufferSize)
35633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
35643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// always draw the same amount to make compares between cases sensible
35653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					drawStart			= deAlign32(bufferSize / 4, 4*4);
35663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					drawEnd				= deAlign32(bufferSize * 3 / 4, 4*4);
35673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&		gl					= m_context.getRenderContext().getFunctions();
35693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					subdataOffset		= deAlign32((m_partialUpload) ? (bufferSize / 4) : (0), 4*4);
35703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					subdataSize			= deAlign32((m_partialUpload) ? (bufferSize / 2) : (bufferSize), 4*4);
35713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64					startTime;
35723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64					endTime;
35733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// make upload-draw stream
35753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_repeatedUpload)
35763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
35773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int repeatNdx = 0; repeatNdx < NUM_REPEATS; ++repeatNdx)
35783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
35793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferSubData(GL_ARRAY_BUFFER, subdataOffset, subdataSize, &m_zeroData[0]);
35803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			drawBufferRange(drawStart, drawEnd);
35813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
35823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
35833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// test upload
35853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	startTime = deGetMicroseconds();
35863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bufferSubData(GL_ARRAY_BUFFER, subdataOffset, subdataSize, &m_zeroData[0]);
35873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	endTime = deGetMicroseconds();
35883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.totalDuration = endTime - startTime;
35903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.fitResponseDuration = result.duration.totalDuration;
35913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.writtenSize = subdataSize;
35923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
35933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ModifyAfterWithMapBufferRangeCase : public ModifyAfterBasicCase<MapBufferRangeDurationNoAlloc>
35953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
35963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
35973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
35983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum CaseFlags
35993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
36003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_PARTIAL = 0x1,
36013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
36023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ModifyAfterWithMapBufferRangeCase	(Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, deUint32 usage, int flags, deUint32 glMapFlags);
36043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					~ModifyAfterWithMapBufferRangeCase	(void);
36053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			init								(void);
36073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			deinit								(void);
36083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
36093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool		isBufferUnspecifiedAfterUpload		(int flags, deUint32 mapFlags);
36103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			testWithBufferSize					(UploadSampleResult<MapBufferRangeDurationNoAlloc>& result, int bufferSize);
36113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_partialUpload;
36133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32	m_mapFlags;
36143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
36153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36163c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterWithMapBufferRangeCase::ModifyAfterWithMapBufferRangeCase (Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, deUint32 usage, int flags, deUint32 glMapFlags)
36173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ModifyAfterBasicCase<MapBufferRangeDurationNoAlloc>	(context, name, desc, bufferSizeMin, bufferSizeMax, usage, isBufferUnspecifiedAfterUpload(flags, glMapFlags))
36183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_partialUpload										((flags & FLAG_PARTIAL) != 0)
36193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_mapFlags											(glMapFlags)
36203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
36213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
36223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36233c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterWithMapBufferRangeCase::~ModifyAfterWithMapBufferRangeCase (void)
36243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
36253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
36263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
36273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithMapBufferRangeCase::init (void)
36293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
36303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log the purpose of the test
36313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
36333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
36343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Testing performance of MapBufferRange() command after a draw command that sources data from the target buffer.\n"
36353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_partialUpload) ?
36363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("Half of the buffer is mapped.\n") :
36373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("Whole buffer is mapped.\n"))
36383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Map bits:\n"
36393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_WRITE_BIT) ? ("\tGL_MAP_WRITE_BIT\n") : (""))
36403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_READ_BIT) ? ("\tGL_MAP_READ_BIT\n") : (""))
36413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_INVALIDATE_RANGE_BIT) ? ("\tGL_MAP_INVALIDATE_RANGE_BIT\n") : (""))
36423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_INVALIDATE_BUFFER_BIT) ? ("\tGL_MAP_INVALIDATE_BUFFER_BIT\n") : (""))
36433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_UNSYNCHRONIZED_BIT) ? ("\tGL_MAP_UNSYNCHRONIZED_BIT\n") : (""))
36443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_FLUSH_EXPLICIT_BIT) ? ("\tGL_MAP_FLUSH_EXPLICIT_BIT\n") : (""))
36453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
36463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ModifyAfterBasicCase<MapBufferRangeDurationNoAlloc>::init();
36483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
36493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithMapBufferRangeCase::deinit (void)
36513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
36523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ModifyAfterBasicCase<MapBufferRangeDurationNoAlloc>::deinit();
36533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
36543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool ModifyAfterWithMapBufferRangeCase::isBufferUnspecifiedAfterUpload (int flags, deUint32 mapFlags)
36563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
36573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((flags & FLAG_PARTIAL) != 0 && ((mapFlags & GL_MAP_INVALIDATE_BUFFER_BIT) != 0))
36583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
36593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
36613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
36623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithMapBufferRangeCase::testWithBufferSize (UploadSampleResult<MapBufferRangeDurationNoAlloc>& result, int bufferSize)
36643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
36653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&		gl					= m_context.getRenderContext().getFunctions();
36663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					subdataOffset		= deAlign32((m_partialUpload) ? (bufferSize / 4) : (0), 4*4);
36673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					subdataSize			= deAlign32((m_partialUpload) ? (bufferSize / 2) : (bufferSize), 4*4);
36683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void*						mapPtr;
36693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// map
36713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
36723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
36733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
36743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
36763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		mapPtr = gl.mapBufferRange(GL_ARRAY_BUFFER, subdataOffset, subdataSize, m_mapFlags);
36773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
36783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!mapPtr)
36803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::TestError("mapBufferRange returned null");
36813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.mapDuration = endTime - startTime;
36833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
36843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// write
36863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
36873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.writeDuration = medianTimeMemcpy(mapPtr, &m_zeroData[0], subdataSize);
36883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
36893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// unmap
36913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
36923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64		startTime;
36933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64		endTime;
36943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLboolean	unmapSucceeded;
36953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
36963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
36973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		unmapSucceeded = gl.unmapBuffer(GL_ARRAY_BUFFER);
36983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
36993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (unmapSucceeded != GL_TRUE)
37013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw UnmapFailureError();
37023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.unmapDuration = endTime - startTime;
37043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
37053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.totalDuration = result.duration.mapDuration + result.duration.writeDuration + result.duration.unmapDuration;
37073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.fitResponseDuration = result.duration.totalDuration;
37083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.writtenSize = subdataSize;
37093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
37103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ModifyAfterWithMapBufferFlushCase : public ModifyAfterBasicCase<MapBufferRangeFlushDurationNoAlloc>
37123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
37133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
37143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum CaseFlags
37163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
37173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		FLAG_PARTIAL = 0x1,
37183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
37193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ModifyAfterWithMapBufferFlushCase	(Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, deUint32 usage, int flags, deUint32 glMapFlags);
37213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					~ModifyAfterWithMapBufferFlushCase	(void);
37223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			init								(void);
37243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			deinit								(void);
37253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
37263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static bool		isBufferUnspecifiedAfterUpload		(int flags, deUint32 mapFlags);
37273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			testWithBufferSize					(UploadSampleResult<MapBufferRangeFlushDurationNoAlloc>& result, int bufferSize);
37283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool		m_partialUpload;
37303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32	m_mapFlags;
37313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
37323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37333c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterWithMapBufferFlushCase::ModifyAfterWithMapBufferFlushCase (Context& context, const char* name, const char* desc, int bufferSizeMin, int bufferSizeMax, deUint32 usage, int flags, deUint32 glMapFlags)
37343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: ModifyAfterBasicCase<MapBufferRangeFlushDurationNoAlloc>	(context, name, desc, bufferSizeMin, bufferSizeMax, usage, isBufferUnspecifiedAfterUpload(flags, glMapFlags))
37353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_partialUpload											((flags & FLAG_PARTIAL) != 0)
37363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_mapFlags												(glMapFlags)
37373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
37383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
37393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37403c827367444ee418f129b2c238299f49d3264554Jarkko PoyryModifyAfterWithMapBufferFlushCase::~ModifyAfterWithMapBufferFlushCase (void)
37413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
37423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
37433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
37443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithMapBufferFlushCase::init (void)
37463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
37473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log the purpose of the test
37483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
37503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
37513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Testing performance of MapBufferRange() command after a draw command that sources data from the target buffer.\n"
37523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_partialUpload) ?
37533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("Half of the buffer is mapped.\n") :
37543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			("Whole buffer is mapped.\n"))
37553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Map bits:\n"
37563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_WRITE_BIT) ? ("\tGL_MAP_WRITE_BIT\n") : (""))
37573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_READ_BIT) ? ("\tGL_MAP_READ_BIT\n") : (""))
37583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_INVALIDATE_RANGE_BIT) ? ("\tGL_MAP_INVALIDATE_RANGE_BIT\n") : (""))
37593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_INVALIDATE_BUFFER_BIT) ? ("\tGL_MAP_INVALIDATE_BUFFER_BIT\n") : (""))
37603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_UNSYNCHRONIZED_BIT) ? ("\tGL_MAP_UNSYNCHRONIZED_BIT\n") : (""))
37613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_mapFlags & GL_MAP_FLUSH_EXPLICIT_BIT) ? ("\tGL_MAP_FLUSH_EXPLICIT_BIT\n") : (""))
37623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
37633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ModifyAfterBasicCase<MapBufferRangeFlushDurationNoAlloc>::init();
37653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
37663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithMapBufferFlushCase::deinit (void)
37683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
37693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ModifyAfterBasicCase<MapBufferRangeFlushDurationNoAlloc>::deinit();
37703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
37713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool ModifyAfterWithMapBufferFlushCase::isBufferUnspecifiedAfterUpload (int flags, deUint32 mapFlags)
37733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
37743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if ((flags & FLAG_PARTIAL) != 0 && ((mapFlags & GL_MAP_INVALIDATE_BUFFER_BIT) != 0))
37753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
37763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
37783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
37793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ModifyAfterWithMapBufferFlushCase::testWithBufferSize (UploadSampleResult<MapBufferRangeFlushDurationNoAlloc>& result, int bufferSize)
37813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
37823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&		gl					= m_context.getRenderContext().getFunctions();
37833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					subdataOffset		= deAlign32((m_partialUpload) ? (bufferSize / 4) : (0), 4*4);
37843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int					subdataSize			= deAlign32((m_partialUpload) ? (bufferSize / 2) : (bufferSize), 4*4);
37853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void*						mapPtr;
37863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// map
37883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
37893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
37903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
37913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
37933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		mapPtr = gl.mapBufferRange(GL_ARRAY_BUFFER, subdataOffset, subdataSize, m_mapFlags);
37943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
37953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!mapPtr)
37973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::TestError("mapBufferRange returned null");
37983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.mapDuration = endTime - startTime;
38003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
38013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// write
38033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
38043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.writeDuration = medianTimeMemcpy(mapPtr, &m_zeroData[0], subdataSize);
38053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
38063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// flush
38083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
38093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 startTime;
38103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64 endTime;
38113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
38133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.flushMappedBufferRange(GL_ARRAY_BUFFER, 0, subdataSize);
38143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
38153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.flushDuration = endTime - startTime;
38173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
38183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// unmap
38203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
38213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64		startTime;
38223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64		endTime;
38233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLboolean	unmapSucceeded;
38243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
38263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		unmapSucceeded = gl.unmapBuffer(GL_ARRAY_BUFFER);
38273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
38283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (unmapSucceeded != GL_TRUE)
38303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw UnmapFailureError();
38313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.duration.unmapDuration = endTime - startTime;
38333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
38343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.totalDuration = result.duration.mapDuration + result.duration.writeDuration + result.duration.unmapDuration + result.duration.flushDuration;
38363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.duration.fitResponseDuration = result.duration.totalDuration;
38373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.writtenSize = subdataSize;
38383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
38393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum DrawMethod
38413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
38423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DRAWMETHOD_DRAW_ARRAYS = 0,
38433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DRAWMETHOD_DRAW_ELEMENTS,
38443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DRAWMETHOD_LAST
38463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
38473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum TargetBuffer
38493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
38503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TARGETBUFFER_VERTEX = 0,
38513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TARGETBUFFER_INDEX,
38523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TARGETBUFFER_LAST
38543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
38553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum BufferState
38573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
38583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BUFFERSTATE_NEW = 0,
38593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BUFFERSTATE_EXISTING,
38603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BUFFERSTATE_LAST
38623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
38633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum UploadMethod
38653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
38663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UPLOADMETHOD_BUFFER_DATA = 0,
38673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UPLOADMETHOD_BUFFER_SUB_DATA,
38683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UPLOADMETHOD_MAP_BUFFER_RANGE,
38693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UPLOADMETHOD_LAST
38713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
38723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38733c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum UnrelatedBufferType
38743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
38753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UNRELATEDBUFFERTYPE_NONE = 0,
38763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UNRELATEDBUFFERTYPE_VERTEX,
38773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UNRELATEDBUFFERTYPE_LAST
38793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
38803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum UploadRange
38823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
38833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UPLOADRANGE_FULL = 0,
38843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UPLOADRANGE_PARTIAL,
38853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	UPLOADRANGE_LAST
38873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
38883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct LayeredGridSpec
38903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
38913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int gridWidth;
38923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int gridHeight;
38933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int gridLayers;
38943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
38953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
38963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic int getLayeredGridNumVertices (const LayeredGridSpec& scene)
38973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
38983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return scene.gridWidth * scene.gridHeight * scene.gridLayers * 6;
38993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
39003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void generateLayeredGridVertexAttribData4C4V (std::vector<tcu::Vec4>& vertexData, const LayeredGridSpec& scene)
39023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
39033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// interleave color & vertex data
39043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 green	(0.0f, 1.0f, 0.0f, 0.7f);
39053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const tcu::Vec4 yellow	(1.0f, 1.0f, 0.0f, 0.8f);
39063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vertexData.resize(getLayeredGridNumVertices(scene) * 2);
39083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int cellY = 0; cellY < scene.gridHeight; ++cellY)
39103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int cellX = 0; cellX < scene.gridWidth; ++cellX)
39113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int cellZ = 0; cellZ < scene.gridLayers; ++cellZ)
39123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
39133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::Vec4	color		= (((cellX + cellY + cellZ) % 2) == 0) ? (green) : (yellow);
39143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float		cellLeft	= (float(cellX  ) / scene.gridWidth  - 0.5f) * 2.0f;
39153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float		cellRight	= (float(cellX+1) / scene.gridWidth  - 0.5f) * 2.0f;
39163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float		cellTop		= (float(cellY+1) / scene.gridHeight - 0.5f) * 2.0f;
39173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float		cellBottom	= (float(cellY  ) / scene.gridHeight - 0.5f) * 2.0f;
39183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  0] = color;
39203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  1] = tcu::Vec4(cellLeft, cellTop, 0.0f, 1.0f);
39213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  2] = color;
39233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  3] = tcu::Vec4(cellLeft, cellBottom, 0.0f, 1.0f);
39243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  4] = color;
39263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  5] = tcu::Vec4(cellRight, cellBottom, 0.0f, 1.0f);
39273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  6] = color;
39293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  7] = tcu::Vec4(cellLeft, cellTop, 0.0f, 1.0f);
39303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  8] = color;
39323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 +  9] = tcu::Vec4(cellRight, cellBottom, 0.0f, 1.0f);
39333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 + 10] = color;
39353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		vertexData[(cellY * scene.gridWidth * scene.gridLayers + cellX * scene.gridLayers + cellZ) * 12 + 11] = tcu::Vec4(cellRight, cellTop, 0.0f, 1.0f);
39363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
39373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
39383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void generateLayeredGridIndexData (std::vector<deUint32>& indexData, const LayeredGridSpec& scene)
39403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
39413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	indexData.resize(getLayeredGridNumVertices(scene) * 2);
39423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < scene.gridLayers * scene.gridHeight * scene.gridWidth * 6; ++ndx)
39443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		indexData[ndx] = ndx;
39453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
39463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass RenderPerformanceTestBase : public TestCase
39483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
39493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
39503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							RenderPerformanceTestBase	(Context& context, const char* name, const char* description);
39513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~RenderPerformanceTestBase	(void);
39523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
39543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init						(void);
39553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit						(void);
39563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					waitGLResults				(void) const;
39583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					setupVertexAttribs			(void) const;
39593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum
39613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
39623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RENDER_AREA_SIZE = 128
39633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
39643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
39663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::ShaderProgram*		m_renderProgram;
39673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_colorLoc;
39683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_positionLoc;
39693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
39703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39713c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderPerformanceTestBase::RenderPerformanceTestBase (Context& context, const char* name, const char* description)
39723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase			(context, tcu::NODETYPE_PERFORMANCE, name, description)
39733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_renderProgram	(DE_NULL)
39743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_colorLoc		(0)
39753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_positionLoc		(0)
39763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
39773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
39783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39793c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderPerformanceTestBase::~RenderPerformanceTestBase (void)
39803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
39813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
39823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
39833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderPerformanceTestBase::init (void)
39853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
39863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
39873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(s_colorVertexShader) << glu::FragmentSource(s_colorFragmentShader));
39893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_renderProgram->isOk())
39903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
39913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << *m_renderProgram;
39923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::TestError("could not build program");
39933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
39943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_colorLoc = gl.getAttribLocation(m_renderProgram->getProgram(), "a_color");
39963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_positionLoc = gl.getAttribLocation(m_renderProgram->getProgram(), "a_position");
39973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
39983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_colorLoc == -1)
39993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::TestError("Location of attribute a_color was -1");
40003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_positionLoc == -1)
40013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::TestError("Location of attribute a_position was -1");
40023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
40033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderPerformanceTestBase::deinit (void)
40053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
40063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_renderProgram;
40073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_renderProgram = DE_NULL;
40083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
40093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40103c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderPerformanceTestBase::setupVertexAttribs (void) const
40113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
40123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
40133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// buffers are bound
40153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enableVertexAttribArray(m_colorLoc);
40173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enableVertexAttribArray(m_positionLoc);
40183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.vertexAttribPointer(m_colorLoc,    4, GL_FLOAT, GL_FALSE, (glw::GLsizei)(8 * sizeof(float)), (const tcu::Vec4*)DE_NULL + 0);
40203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.vertexAttribPointer(m_positionLoc, 4, GL_FLOAT, GL_FALSE, (glw::GLsizei)(8 * sizeof(float)), (const tcu::Vec4*)DE_NULL + 1);
40213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.useProgram(m_renderProgram->getProgram());
40233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "set up rendering");
40253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
40263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderPerformanceTestBase::waitGLResults (void) const
40283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
40293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface dummySurface(RENDER_AREA_SIZE, RENDER_AREA_SIZE);
40303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), 0, 0, dummySurface.getAccess());
40313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
40323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
40343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass RenderCase : public RenderPerformanceTestBase
40353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
40363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
40373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									RenderCase						(Context& context, const char* name, const char* description, DrawMethod drawMethod);
40383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									~RenderCase						(void);
40393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
40413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void							init							(void);
40423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void							deinit							(void);
40433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
40453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult					iterate							(void);
40463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
40483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	struct SampleResult
40493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
40503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		LayeredGridSpec					scene;
40513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RenderSampleResult<SampleType>	result;
40523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
40533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								getMinWorkloadSize				(void) const;
40553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								getMaxWorkloadSize				(void) const;
40563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								getMinWorkloadDataSize			(void) const;
40573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								getMaxWorkloadDataSize			(void) const;
40583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								getVertexDataSize				(void) const;
40593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								getNumSamples					(void) const;
40603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void							uploadScene						(const LayeredGridSpec& scene);
40613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void					runSample						(SampleResult& sample) = 0;
40633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void					logAndSetTestResult				(const std::vector<SampleResult>& results);
40643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void							mapResultsToRenderRateFormat	(std::vector<RenderSampleResult<SampleType> >& dst, const std::vector<SampleResult>& src) const;
40663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const DrawMethod				m_drawMethod;
40683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
40703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLuint						m_attributeBufferID;
40713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLuint						m_indexBufferID;
40723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								m_iterationNdx;
40733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<int>				m_iterationOrder;
40743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<SampleResult>		m_results;
40753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int								m_numUnmapFailures;
40763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
40773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
40793c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderCase<SampleType>::RenderCase (Context& context, const char* name, const char* description, DrawMethod drawMethod)
40803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: RenderPerformanceTestBase	(context, name, description)
40813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_drawMethod				(drawMethod)
40823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_attributeBufferID		(0)
40833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_indexBufferID			(0)
40843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_iterationNdx			(0)
40853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numUnmapFailures		(0)
40863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
40873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(drawMethod < DRAWMETHOD_LAST);
40883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
40893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
40913c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderCase<SampleType>::~RenderCase (void)
40923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
40933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
40943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
40953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40963c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
40973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderCase<SampleType>::init (void)
40983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
40993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
41003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderPerformanceTestBase::init();
41023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// requirements
41043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_context.getRenderTarget().getWidth() < RENDER_AREA_SIZE ||
41063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderTarget().getHeight() < RENDER_AREA_SIZE)
41073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("Test case requires " + de::toString<int>(RENDER_AREA_SIZE) + "x" + de::toString<int>(RENDER_AREA_SIZE) + " render target");
41083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// gl state
41103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.viewport(0, 0, RENDER_AREA_SIZE, RENDER_AREA_SIZE);
41123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// enable bleding to prevent grid layers from being discarded
41143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
41153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.blendEquation(GL_FUNC_ADD);
41163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enable(GL_BLEND);
41173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// generate iterations
41193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
41213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int gridSizes[] = { 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80,  86,  92,  98,  104, 110, 116, 122, 128 };
41223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int gridNdx = 0; gridNdx < DE_LENGTH_OF_ARRAY(gridSizes); ++gridNdx)
41243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
41253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_results.push_back(SampleResult());
41263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_results.back().scene.gridHeight = gridSizes[gridNdx];
41283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_results.back().scene.gridWidth = gridSizes[gridNdx];
41293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_results.back().scene.gridLayers = 5;
41303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_results.back().result.numVertices = getLayeredGridNumVertices(m_results.back().scene);
41323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// test cases set these, initialize to dummy values
41343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_results.back().result.renderDataSize = -1;
41353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_results.back().result.uploadedDataSize = -1;
41363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_results.back().result.unrelatedDataSize = -1;
41373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
41383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
41393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// randomize iteration order
41413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
41423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_iterationOrder.resize(m_results.size());
41433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateTwoPassRandomIterationOrder(m_iterationOrder, (int)m_iterationOrder.size());
41443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
41453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
41463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
41483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderCase<SampleType>::deinit (void)
41493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
41503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderPerformanceTestBase::deinit();
41513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_attributeBufferID)
41533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
41543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_attributeBufferID);
41553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_attributeBufferID = 0;
41563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
41573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_indexBufferID)
41593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
41603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_indexBufferID);
41613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_indexBufferID = 0;
41623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
41633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
41643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
41663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypename RenderCase<SampleType>::IterateResult RenderCase<SampleType>::iterate (void)
41673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
41683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		unmapFailureThreshold	= 3;
41693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		currentIteration		= m_iterationNdx;
41703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int		currentConfigNdx		= m_iterationOrder[currentIteration];
41713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	SampleResult&	currentSample			= m_results[currentConfigNdx];
41723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
41743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
41753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		runSample(currentSample);
41763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		++m_iterationNdx;
41773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
41783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (const UnmapFailureError& ex)
41793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
41803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(ex);
41813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		++m_numUnmapFailures;
41823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
41833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_numUnmapFailures > unmapFailureThreshold)
41853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::TestError("Got too many unmap errors");
41863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_iterationNdx < (int)m_iterationOrder.size())
41883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
41893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	logAndSetTestResult(m_results);
41913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
41923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
41933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
41953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint RenderCase<SampleType>::getMinWorkloadSize (void) const
41963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
41973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int result = getLayeredGridNumVertices(m_results[0].scene);
41983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
41993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 1; ndx < (int)m_results.size(); ++ndx)
42003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
42013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int workloadSize = getLayeredGridNumVertices(m_results[ndx].scene);
42023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result = de::min(result, workloadSize);
42033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
42043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return result;
42063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
42073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
42093c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint RenderCase<SampleType>::getMaxWorkloadSize (void) const
42103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
42113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int result = getLayeredGridNumVertices(m_results[0].scene);
42123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 1; ndx < (int)m_results.size(); ++ndx)
42143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
42153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int workloadSize = getLayeredGridNumVertices(m_results[ndx].scene);
42163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result = de::max(result, workloadSize);
42173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
42183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return result;
42203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
42213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
42233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint RenderCase<SampleType>::getMinWorkloadDataSize (void) const
42243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
42253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return getMinWorkloadSize() * getVertexDataSize();
42263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
42273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
42293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint RenderCase<SampleType>::getMaxWorkloadDataSize (void) const
42303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
42313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return getMaxWorkloadSize() * getVertexDataSize();
42323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
42333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
42353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint RenderCase<SampleType>::getVertexDataSize (void) const
42363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
42373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int numVectors	= 2;
42383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int vec4Size		= 4 * sizeof(float);
42393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return numVectors * vec4Size;
42413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
42423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
42443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint RenderCase<SampleType>::getNumSamples (void) const
42453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
42463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (int)m_results.size();
42473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
42483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
42503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderCase<SampleType>::uploadScene (const LayeredGridSpec& scene)
42513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
42523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
42533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// vertex buffer
42553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
42563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::vector<tcu::Vec4> vertexData;
42573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridVertexAttribData4C4V(vertexData, scene);
42593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_attributeBufferID == 0)
42613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.genBuffers(1, &m_attributeBufferID);
42623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, m_attributeBufferID);
42633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (int)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], GL_STATIC_DRAW);
42643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
42653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// index buffer
42673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
42683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
42693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::vector<deUint32> indexData;
42703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridIndexData(indexData, scene);
42723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_indexBufferID == 0)
42743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.genBuffers(1, &m_indexBufferID);
42753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBufferID);
42763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (int)(indexData.size() * sizeof(deUint32)), &indexData[0], GL_STATIC_DRAW);
42773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
42783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "create buffers");
42803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
42813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
42833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderCase<SampleType>::logAndSetTestResult (const std::vector<SampleResult>& results)
42843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
42853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<RenderSampleResult<SampleType> > mappedResults;
42863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	mapResultsToRenderRateFormat(mappedResults, results);
42883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
42903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const RenderSampleAnalyzeResult	analysis	= analyzeSampleResults(m_testCtx.getLog(), mappedResults);
42913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float						rate		= analysis.renderRateAtRange;
42923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (rate == std::numeric_limits<float>::infinity())
42943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
42953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// sample times are 1) invalid or 2) timer resolution too low
42963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString(0.0f, 2).c_str());
42973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
42983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
42993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
43003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// report transfer rate in millions of MiB/s
43013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString(rate / 1024.0f / 1024.0f, 2).c_str());
43023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
43033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
43043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
43053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
43073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid RenderCase<SampleType>::mapResultsToRenderRateFormat (std::vector<RenderSampleResult<SampleType> >& dst, const std::vector<SampleResult>& src) const
43083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
43093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	dst.resize(src.size());
43103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)src.size(); ++ndx)
43123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dst[ndx] = src[ndx].result;
43133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
43143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ReferenceRenderTimeCase : public RenderCase<RenderReadDuration>
43163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
43173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
43183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ReferenceRenderTimeCase		(Context& context, const char* name, const char* description, DrawMethod drawMethod);
43193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
43213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void	init						(void);
43223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void	runSample					(SampleResult& sample);
43233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
43243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43253c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReferenceRenderTimeCase::ReferenceRenderTimeCase (Context& context, const char* name, const char* description, DrawMethod drawMethod)
43263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: RenderCase<RenderReadDuration>	(context, name, description, drawMethod)
43273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
43283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
43293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReferenceRenderTimeCase::init (void)
43313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
43323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char* const targetFunctionName = (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS) ? ("drawArrays") : ("drawElements");
43333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// init parent
43353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCase<RenderReadDuration>::init();
43363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// log
43383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
43393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
43403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Measuring the time used in " << targetFunctionName << " and readPixels call with different rendering workloads.\n"
43413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< getNumSamples() << " test samples. Sample order is randomized.\n"
43423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "All samples at even positions (first = 0) are tested before samples at odd positions.\n"
43433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Generated workload is multiple viewport-covering grids with varying number of cells, each cell is two separate triangles.\n"
43443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Workload sizes are in the range ["
43453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getMinWorkloadSize() << ",  "
43463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getMaxWorkloadSize() << "] vertices (["
43473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getHumanReadableByteSize(getMinWorkloadDataSize()) << ","
43483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getHumanReadableByteSize(getMaxWorkloadDataSize()) << "] to be processed).\n"
43493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Test result is the approximated total processing rate in MiB / s.\n"
43503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS) ? ("Note that index array size is not included in the processed size.\n") : (""))
43513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Note! Test result should only be used as a baseline reference result for buffer.data_upload.* test group results."
43523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
43533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
43543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReferenceRenderTimeCase::runSample (SampleResult& sample)
43563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
43573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl				= m_context.getRenderContext().getFunctions();
43583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			resultSurface	(RENDER_AREA_SIZE, RENDER_AREA_SIZE);
43593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				numVertices		= getLayeredGridNumVertices(sample.scene);
43603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		arrayBuffer		(m_context.getRenderContext());
43613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		indexBuffer		(m_context.getRenderContext());
43623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		unrelatedBuffer	(m_context.getRenderContext());
43633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<tcu::Vec4>	vertexData;
43643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint32>	indexData;
43653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				startTime;
43663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				endTime;
43673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// generate and upload buffers
43693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	generateLayeredGridVertexAttribData4C4V(vertexData, sample.scene);
43713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, *arrayBuffer);
43723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bufferData(GL_ARRAY_BUFFER, (int)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], GL_STATIC_DRAW);
43733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
43753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
43763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridIndexData(indexData, sample.scene);
43773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
43783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (int)(indexData.size() * sizeof(deUint32)), &indexData[0], GL_STATIC_DRAW);
43793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
43803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	setupVertexAttribs();
43823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// make sure data is uploaded
43843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
43863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawArrays(GL_TRIANGLES, 0, numVertices);
43873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
43883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
43893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
43903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
43913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	waitGLResults();
43923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
43943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
43953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	waitGLResults();
43963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::warmupCPU();
43983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
43993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Measure both draw and associated readpixels
44003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
44013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
44023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
44043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, numVertices);
44053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
44063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
44073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
44083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
44093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
44113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.renderDuration = endTime - startTime;
44133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
44143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
44163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
44173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glu::readPixels(m_context.getRenderContext(), 0, 0, resultSurface.getAccess());
44183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
44193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.readDuration = endTime - startTime;
44213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
44223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.renderDataSize = getVertexDataSize() * sample.result.numVertices;
44243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.uploadedDataSize = 0;
44253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.unrelatedDataSize = 0;
44263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.renderReadDuration = sample.result.duration.renderDuration + sample.result.duration.readDuration;
44273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.totalDuration = sample.result.duration.renderDuration + sample.result.duration.readDuration;
44283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.fitResponseDuration = sample.result.duration.renderReadDuration;
44293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
44303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass UnrelatedUploadRenderTimeCase : public RenderCase<UnrelatedUploadRenderReadDuration>
44323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
44333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
44343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									UnrelatedUploadRenderTimeCase	(Context& context, const char* name, const char* description, DrawMethod drawMethod, UploadMethod unrelatedUploadMethod);
44353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
44373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void							init							(void);
44383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void							runSample						(SampleResult& sample);
44393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadMethod				m_unrelatedUploadMethod;
44413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
44423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44433c827367444ee418f129b2c238299f49d3264554Jarkko PoyryUnrelatedUploadRenderTimeCase::UnrelatedUploadRenderTimeCase (Context& context, const char* name, const char* description, DrawMethod drawMethod, UploadMethod unrelatedUploadMethod)
44443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: RenderCase<UnrelatedUploadRenderReadDuration>	(context, name, description, drawMethod)
44453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_unrelatedUploadMethod						(unrelatedUploadMethod)
44463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
44473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_unrelatedUploadMethod < UPLOADMETHOD_LAST);
44483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
44493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UnrelatedUploadRenderTimeCase::init (void)
44513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
44523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char* const	targetFunctionName	= (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS) ? ("drawArrays") : ("drawElements");
44533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::MessageBuilder	message				(&m_testCtx.getLog());
44543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// init parent
44563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCase<UnrelatedUploadRenderReadDuration>::init();
44573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// log
44593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	message
44613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Measuring the time used in " << targetFunctionName << " and readPixels call with different rendering workloads.\n"
44623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Uploading an unrelated buffer just before issuing the rendering command with "
44633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ((m_unrelatedUploadMethod != UPLOADMETHOD_BUFFER_DATA)		? ("bufferData")		:
44643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				(m_unrelatedUploadMethod != UPLOADMETHOD_BUFFER_SUB_DATA)	? ("bufferSubData")		:
44653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				(m_unrelatedUploadMethod != UPLOADMETHOD_MAP_BUFFER_RANGE)	? ("mapBufferRange")	:
44663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				((const char*)DE_NULL))
44673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ".\n"
44683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< getNumSamples() << " test samples. Sample order is randomized.\n"
44693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "All samples at even positions (first = 0) are tested before samples at odd positions.\n"
44703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Generated workload is multiple viewport-covering grids with varying number of cells, each cell is two separate triangles.\n"
44713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Workload sizes are in the range ["
44723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getMinWorkloadSize() << ",  "
44733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getMaxWorkloadSize() << "] vertices (["
44743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getHumanReadableByteSize(getMinWorkloadDataSize()) << ","
44753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getHumanReadableByteSize(getMaxWorkloadDataSize()) << "] to be processed).\n"
44763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Unrelated upload sizes are in the range ["
44773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getHumanReadableByteSize(getMinWorkloadDataSize()) << ", "
44783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< getHumanReadableByteSize(getMaxWorkloadDataSize()) << "]\n"
44793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Test result is the approximated total processing rate in MiB / s.\n"
44803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS) ? ("Note that index array size is not included in the processed size.\n") : (""))
44813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Note that the data size and the time used in the unrelated upload is not included in the results.\n"
44823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Note! Test result may not be useful as is but instead should be compared against the reference.* group and upload_and_draw.*_and_unrelated_upload group results.\n"
44833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
44843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
44853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
44863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UnrelatedUploadRenderTimeCase::runSample (SampleResult& sample)
44873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
44883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl					= m_context.getRenderContext().getFunctions();
44893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			resultSurface		(RENDER_AREA_SIZE, RENDER_AREA_SIZE);
44903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				numVertices			= getLayeredGridNumVertices(sample.scene);
44913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		arrayBuffer			(m_context.getRenderContext());
44923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		indexBuffer			(m_context.getRenderContext());
44933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		unrelatedBuffer		(m_context.getRenderContext());
44943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						unrelatedUploadSize	= -1;
44953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						renderUploadSize;
44963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<tcu::Vec4>	vertexData;
44973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint32>	indexData;
44983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				startTime;
44993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				endTime;
45003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// generate and upload buffers
45023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	generateLayeredGridVertexAttribData4C4V(vertexData, sample.scene);
45043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	renderUploadSize = (int)(vertexData.size() * sizeof(tcu::Vec4));
45053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, *arrayBuffer);
45073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bufferData(GL_ARRAY_BUFFER, renderUploadSize, &vertexData[0], GL_STATIC_DRAW);
45083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
45103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
45113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridIndexData(indexData, sample.scene);
45123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
45133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (int)(indexData.size() * sizeof(deUint32)), &indexData[0], GL_STATIC_DRAW);
45143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
45153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	setupVertexAttribs();
45173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// make sure data is uploaded
45193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
45213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawArrays(GL_TRIANGLES, 0, numVertices);
45223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
45233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
45243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
45253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
45263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	waitGLResults();
45273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
45293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
45303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	waitGLResults();
45313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::warmupCPU();
45333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Unrelated upload
45353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_unrelatedUploadMethod == UPLOADMETHOD_BUFFER_DATA)
45363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
45373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		unrelatedUploadSize = (int)(vertexData.size() * sizeof(tcu::Vec4));
45383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, *unrelatedBuffer);
45403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, unrelatedUploadSize, &vertexData[0], GL_STATIC_DRAW);
45413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
45423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_unrelatedUploadMethod == UPLOADMETHOD_BUFFER_SUB_DATA)
45433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
45443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		unrelatedUploadSize = (int)(vertexData.size() * sizeof(tcu::Vec4));
45453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, *unrelatedBuffer);
45473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, unrelatedUploadSize, DE_NULL, GL_STATIC_DRAW);
45483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferSubData(GL_ARRAY_BUFFER, 0, unrelatedUploadSize, &vertexData[0]);
45493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
45503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_unrelatedUploadMethod == UPLOADMETHOD_MAP_BUFFER_RANGE)
45513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
45523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		void*			mapPtr;
45533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLboolean	unmapSuccessful;
45543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		unrelatedUploadSize = (int)(vertexData.size() * sizeof(tcu::Vec4));
45563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, *unrelatedBuffer);
45583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, unrelatedUploadSize, DE_NULL, GL_STATIC_DRAW);
45593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		mapPtr = gl.mapBufferRange(GL_ARRAY_BUFFER, 0, unrelatedUploadSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
45613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!mapPtr)
45623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::Exception("MapBufferRange returned NULL");
45633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deMemcpy(mapPtr, &vertexData[0], unrelatedUploadSize);
45653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// if unmapping fails, just try again later
45673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		unmapSuccessful = gl.unmapBuffer(GL_ARRAY_BUFFER);
45683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!unmapSuccessful)
45693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw UnmapFailureError();
45703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
45713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
45723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
45733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(unrelatedUploadSize != -1);
45753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Measure both draw and associated readpixels
45773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
45783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
45793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
45813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, numVertices);
45823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
45833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
45843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
45853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
45863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
45883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.renderDuration = endTime - startTime;
45903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
45913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
45933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
45943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glu::readPixels(m_context.getRenderContext(), 0, 0, resultSurface.getAccess());
45953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
45963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
45973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.readDuration = endTime - startTime;
45983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
45993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.renderDataSize = getVertexDataSize() * sample.result.numVertices;
46013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.uploadedDataSize = renderUploadSize;
46023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.unrelatedDataSize = unrelatedUploadSize;
46033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.renderReadDuration = sample.result.duration.renderDuration + sample.result.duration.readDuration;
46043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.totalDuration = sample.result.duration.renderDuration + sample.result.duration.readDuration;
46053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.fitResponseDuration = sample.result.duration.renderReadDuration;
46063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
46073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ReferenceReadPixelsTimeCase : public TestCase
46093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
46103c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
46113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					ReferenceReadPixelsTimeCase		(Context& context, const char* name, const char* description);
46123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
46143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			init							(void);
46153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult	iterate							(void);
46163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void			logAndSetTestResult				(void);
46173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum
46193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
46203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		RENDER_AREA_SIZE = 128
46213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
46223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int			m_numSamples;
46243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int					m_sampleNdx;
46253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<int>	m_samples;
46263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
46273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46283c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReferenceReadPixelsTimeCase::ReferenceReadPixelsTimeCase (Context& context, const char* name, const char* description)
46293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCase		(context, tcu::NODETYPE_PERFORMANCE, name, description)
46303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numSamples	(20)
46313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_sampleNdx	(0)
46323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_samples		(m_numSamples)
46333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
46343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
46353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReferenceReadPixelsTimeCase::init (void)
46373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
46383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
46393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
46403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Measuring the time used in a single readPixels call with " << m_numSamples << " test samples.\n"
46413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Test result is the median of the samples in microseconds.\n"
46423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Note! Test result should only be used as a baseline reference result for buffer.data_upload.* test group results."
46433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
46443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
46453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryReferenceReadPixelsTimeCase::IterateResult ReferenceReadPixelsTimeCase::iterate (void)
46473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
46483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl				= m_context.getRenderContext().getFunctions();
46493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			resultSurface	(RENDER_AREA_SIZE, RENDER_AREA_SIZE);
46503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				startTime;
46513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				endTime;
46523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deYield();
46543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::warmupCPU();
46553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deYield();
46563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// "Render" something and wait for it
46583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(0.0f, 1.0f, m_sampleNdx / float(m_numSamples), 1.0f);
46593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
46603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// wait for results
46623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), 0, 0, resultSurface.getAccess());
46633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// measure time used in readPixels
46653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	startTime = deGetMicroseconds();
46663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glu::readPixels(m_context.getRenderContext(), 0, 0, resultSurface.getAccess());
46673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	endTime = deGetMicroseconds();
46683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_samples[m_sampleNdx] = (int)(endTime - startTime);
46703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (++m_sampleNdx < m_numSamples)
46723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
46733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	logAndSetTestResult();
46753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
46763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
46773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ReferenceReadPixelsTimeCase::logAndSetTestResult (void)
46793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
46803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log sample list
46813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
46823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog()
46833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::SampleList("Samples", "Samples")
46843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::SampleInfo
46853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::ValueInfo("ReadTime", "ReadPixels time", "us", QP_SAMPLE_VALUE_TAG_RESPONSE)
46863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSampleInfo;
46873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int sampleNdx = 0; sampleNdx < (int)m_samples.size(); ++sampleNdx)
46893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog()
46903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::Sample
46913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< m_samples[sampleNdx]
46923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< tcu::TestLog::EndSample;
46933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << tcu::TestLog::EndSampleList;
46953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
46963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log median
46983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
46993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float median;
47003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float limit60Low;
47013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		float limit60Up;
47023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::sort(m_samples.begin(), m_samples.end());
47043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		median		= linearSample(m_samples, 0.5f);
47053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		limit60Low	= linearSample(m_samples, 0.2f);
47063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		limit60Up	= linearSample(m_samples, 0.8f);
47073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog()
47093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("Median", "Median", "us", QP_KEY_TAG_TIME, median)
47103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Message
47113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "60 % of samples within range:\n"
47123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndMessage
47133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("Low60Range", "Lower", "us", QP_KEY_TAG_TIME, limit60Low)
47143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Float("High60Range", "Upper", "us", QP_KEY_TAG_TIME, limit60Up);
47153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString(median, 2).c_str());
47173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
47183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
47193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
47213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GenericUploadRenderTimeCase : public RenderCase<SampleType>
47223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
47233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
47243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef typename RenderCase<SampleType>::SampleResult SampleResult;
47253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							GenericUploadRenderTimeCase	(Context&				context,
47273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 const char*			name,
47283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 const char*			description,
47293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 DrawMethod				method,
47303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 TargetBuffer			targetBuffer,
47313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 UploadMethod			uploadMethod,
47323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 BufferState			bufferState,
47333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 UploadRange			uploadRange,
47343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry														 UnrelatedBufferType	unrelatedBufferType);
47353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
47373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						init					(void);
47383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						runSample				(SampleResult& sample);
47393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using RenderCase<SampleType>::RENDER_AREA_SIZE;
47413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const TargetBuffer			m_targetBuffer;
47433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const BufferState			m_bufferState;
47443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadMethod			m_uploadMethod;
47453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UnrelatedBufferType	m_unrelatedBufferType;
47463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadRange			m_uploadRange;
47473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using RenderCase<SampleType>::m_context;
47493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using RenderCase<SampleType>::m_testCtx;
47503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	using RenderCase<SampleType>::m_drawMethod;
47513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
47523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
47543c827367444ee418f129b2c238299f49d3264554Jarkko PoyryGenericUploadRenderTimeCase<SampleType>::GenericUploadRenderTimeCase (Context&				context,
47553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	  const char*			name,
47563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	  const char*			description,
47573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	  DrawMethod			method,
47583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	  TargetBuffer			targetBuffer,
47593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	  UploadMethod			uploadMethod,
47603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	  BufferState			bufferState,
47613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	  UploadRange			uploadRange,
47623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																	  UnrelatedBufferType	unrelatedBufferType)
47633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: RenderCase<SampleType>	(context, name, description, method)
47643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_targetBuffer			(targetBuffer)
47653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferState				(bufferState)
47663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_uploadMethod			(uploadMethod)
47673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_unrelatedBufferType		(unrelatedBufferType)
47683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_uploadRange				(uploadRange)
47693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
47703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_targetBuffer < TARGETBUFFER_LAST);
47713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_bufferState < BUFFERSTATE_LAST);
47723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_uploadMethod < UPLOADMETHOD_LAST);
47733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_unrelatedBufferType < UNRELATEDBUFFERTYPE_LAST);
47743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_uploadRange < UPLOADRANGE_LAST);
47753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
47763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
47783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid GenericUploadRenderTimeCase<SampleType>::init (void)
47793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
47803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// init parent
47813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCase<SampleType>::init();
47823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// log
47843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
47853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* const	targetFunctionName		= (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS) ? ("drawArrays") : ("drawElements");
47863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			perVertexSize			= (m_targetBuffer == TARGETBUFFER_INDEX) ? (sizeof(deUint32)) : (sizeof(tcu::Vec4[2]));
47873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			fullMinUploadSize		= RenderCase<SampleType>::getMinWorkloadSize() * perVertexSize;
47883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			fullMaxUploadSize		= RenderCase<SampleType>::getMaxWorkloadSize() * perVertexSize;
47893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			minUploadSize			= (m_uploadRange == UPLOADRANGE_FULL) ? (fullMinUploadSize) : (deAlign32(fullMinUploadSize/2, 4));
47903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			maxUploadSize			= (m_uploadRange == UPLOADRANGE_FULL) ? (fullMaxUploadSize) : (deAlign32(fullMaxUploadSize/2, 4));
47913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			minUnrelatedUploadSize	= RenderCase<SampleType>::getMinWorkloadSize() * sizeof(tcu::Vec4[2]);
47923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int			maxUnrelatedUploadSize	= RenderCase<SampleType>::getMaxWorkloadSize() * sizeof(tcu::Vec4[2]);
47933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
47943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog()
47953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Message
47963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Measuring the time used in " << targetFunctionName << " and readPixels call with different rendering workloads.\n"
47973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "The "
47983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< ((m_targetBuffer == TARGETBUFFER_INDEX) ? ("index") : ("vertex attrib"))
47993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< " buffer "
48003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< ((m_bufferState == BUFFERSTATE_NEW) ? ("") : ("contents "))
48013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< "sourced by the rendering command "
48023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< ((m_bufferState == BUFFERSTATE_NEW)		? ("is uploaded ") :
48033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					(m_uploadRange == UPLOADRANGE_FULL)		? ("are specified ") :
48043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					(m_uploadRange == UPLOADRANGE_PARTIAL)	? ("are updated (partial upload) ") :
48053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					((const char*)DE_NULL))
48063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< "just before issuing the rendering command.\n"
48073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ((m_bufferState == BUFFERSTATE_EXISTING) ? ("The buffer has been used in rendering.\n") : ("The buffer is generated just before uploading.\n"))
48083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Buffer "
48093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< ((m_bufferState == BUFFERSTATE_NEW)		? ("is uploaded") :
48103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					(m_uploadRange == UPLOADRANGE_FULL)		? ("contents are specified") :
48113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					(m_uploadRange == UPLOADRANGE_PARTIAL)	? ("contents are partially updated") :
48123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					((const char*)DE_NULL))
48133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< " with "
48143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< ((m_uploadMethod == UPLOADMETHOD_BUFFER_DATA) ? ("bufferData") : (m_uploadMethod == UPLOADMETHOD_BUFFER_SUB_DATA) ? ("bufferSubData") : ("mapBufferRange"))
48153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< " command. Usage of the target buffer is DYNAMIC_DRAW.\n"
48163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ((m_uploadMethod == UPLOADMETHOD_MAP_BUFFER_RANGE) ? ("Mapping buffer with bits MAP_WRITE_BIT | MAP_INVALIDATE_RANGE_BIT | MAP_INVALIDATE_BUFFER_BIT | MAP_UNSYNCHRONIZED_BIT\n") : (""))
48173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ((m_unrelatedBufferType == UNRELATEDBUFFERTYPE_VERTEX) ? ("Uploading an unrelated buffer just before issuing the rendering command with bufferData.\n") : (""))
48183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< RenderCase<SampleType>::getNumSamples() << " test samples. Sample order is randomized.\n"
48193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "All samples at even positions (first = 0) are tested before samples at odd positions.\n"
48203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Generated workload is multiple viewport-covering grids with varying number of cells, each cell is two separate triangles.\n"
48213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Workload sizes are in the range ["
48223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< RenderCase<SampleType>::getMinWorkloadSize() << ",  "
48233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< RenderCase<SampleType>::getMaxWorkloadSize() << "] vertices "
48243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< "(["
48253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< getHumanReadableByteSize(RenderCase<SampleType>::getMinWorkloadDataSize()) << ","
48263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< getHumanReadableByteSize(RenderCase<SampleType>::getMaxWorkloadDataSize()) << "] to be processed).\n"
48273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Upload sizes are in the range ["
48283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< getHumanReadableByteSize(minUploadSize) << ","
48293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< getHumanReadableByteSize(maxUploadSize) << "].\n"
48303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ((m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS) ?
48313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				("Unrelated upload sizes are in the range [" + getHumanReadableByteSize(minUnrelatedUploadSize) + ", " + getHumanReadableByteSize(maxUnrelatedUploadSize) + "]\n") :
48323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				(""))
48333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Test result is the approximated processing rate in MiB / s.\n"
48343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Note that while upload time is measured, the time used is not included in the results.\n"
48353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ((m_unrelatedBufferType == UNRELATEDBUFFERTYPE_VERTEX) ? ("Note that the data size and the time used in the unrelated upload is not included in the results.\n") : (""))
48363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ((m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS) ? ("Note that index array size is not included in the processed size.\n") : (""))
48373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Note! Test result may not be useful as is but instead should be compared against the reference.* group and other upload_and_draw.* group results.\n"
48383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndMessage;
48393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
48403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
48413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename SampleType>
48433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid GenericUploadRenderTimeCase<SampleType>::runSample (SampleResult& sample)
48443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
48453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl					= m_context.getRenderContext().getFunctions();
48463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		arrayBuffer			(m_context.getRenderContext());
48473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		indexBuffer			(m_context.getRenderContext());
48483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		unrelatedBuffer		(m_context.getRenderContext());
48493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				numVertices			= getLayeredGridNumVertices(sample.scene);
48503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			resultSurface		(RENDER_AREA_SIZE, RENDER_AREA_SIZE);
48513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				startTime;
48523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				endTime;
48533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<tcu::Vec4>	vertexData;
48543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint32>	indexData;
48553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// create data
48573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	generateLayeredGridVertexAttribData4C4V(vertexData, sample.scene);
48593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
48603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridIndexData(indexData, sample.scene);
48613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, *arrayBuffer);
48633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
48643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCase<SampleType>::setupVertexAttribs();
48653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// target should be an exisiting buffer? Draw from it once to make sure it exists on the gpu
48673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS && m_bufferState == BUFFERSTATE_EXISTING)
48693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
48703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], GL_DYNAMIC_DRAW);
48713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawArrays(GL_TRIANGLES, 0, numVertices);
48723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
48733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS && m_bufferState == BUFFERSTATE_NEW)
48743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
48753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// do not touch the vertex buffer
48763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
48773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS && m_bufferState == BUFFERSTATE_EXISTING)
48783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
48793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// hint that the target buffer will be modified soon
48803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glw::GLenum vertexDataUsage	= (m_targetBuffer == TARGETBUFFER_VERTEX) ? (GL_DYNAMIC_DRAW) : (GL_STATIC_DRAW);
48813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glw::GLenum indexDataUsage	= (m_targetBuffer == TARGETBUFFER_INDEX) ? (GL_DYNAMIC_DRAW) : (GL_STATIC_DRAW);
48823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], vertexDataUsage);
48843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (glw::GLsizeiptr)(indexData.size() * sizeof(deUint32)), &indexData[0], indexDataUsage);
48853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
48863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
48873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS && m_bufferState == BUFFERSTATE_NEW)
48883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
48893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_targetBuffer == TARGETBUFFER_VERTEX)
48903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
48913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// make the index buffer present on the gpu
48923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// use another vertex buffer to keep original buffer in unused state
48933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const glu::Buffer vertexCopyBuffer(m_context.getRenderContext());
48943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ARRAY_BUFFER, *vertexCopyBuffer);
48963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			RenderCase<SampleType>::setupVertexAttribs();
48973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
48983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], GL_STATIC_DRAW);
48993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (glw::GLsizeiptr)(indexData.size() * sizeof(deUint32)), &indexData[0], GL_STATIC_DRAW);
49003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
49013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// restore original state
49033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ARRAY_BUFFER, *arrayBuffer);
49043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			RenderCase<SampleType>::setupVertexAttribs();
49053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
49063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_INDEX)
49073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
49083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// make the vertex buffer present on the gpu
49093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], GL_STATIC_DRAW);
49103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, numVertices);
49113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
49123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
49133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
49143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
49153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
49163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
49173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCase<SampleType>::waitGLResults();
49193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "post buffer prepare");
49203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
49223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
49233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCase<SampleType>::waitGLResults();
49243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::warmupCPU();
49263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// upload
49283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
49303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLenum		target;
49313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLsizeiptr	size;
49323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLintptr	offset = 0;
49333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const void*		source;
49343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_targetBuffer == TARGETBUFFER_VERTEX && m_uploadRange == UPLOADRANGE_FULL)
49363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
49373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			target	= GL_ARRAY_BUFFER;
49383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			size	= (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4));
49393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			source	= &vertexData[0];
49403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
49413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_INDEX && m_uploadRange == UPLOADRANGE_FULL)
49423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
49433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			target	= GL_ELEMENT_ARRAY_BUFFER;
49443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			size	= (glw::GLsizeiptr)(indexData.size() * sizeof(deUint32));
49453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			source	= &indexData[0];
49463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
49473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_VERTEX && m_uploadRange == UPLOADRANGE_PARTIAL)
49483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
49493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(m_bufferState == BUFFERSTATE_EXISTING);
49503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			target	= GL_ARRAY_BUFFER;
49523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			size	= (glw::GLsizeiptr)deAlign32((int)(vertexData.size() * sizeof(tcu::Vec4)) / 2, 4);
49533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			offset	= (glw::GLintptr)deAlign32((int)size / 2, 4);
49543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			source	= (const deUint8*)&vertexData[0] + offset;
49553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
49563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_INDEX && m_uploadRange == UPLOADRANGE_PARTIAL)
49573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
49583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(m_bufferState == BUFFERSTATE_EXISTING);
49593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// upload to 25% - 75% range
49613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			target	= GL_ELEMENT_ARRAY_BUFFER;
49623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			size	= (glw::GLsizeiptr)deAlign32((glw::GLsizeiptr)((int)(indexData.size() * sizeof(deUint32))) / 2, 4);
49633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			offset	= (glw::GLintptr)deAlign32((int)size / 2, 4);
49643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			source	= (const deUint8*)&indexData[0] + offset;
49653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
49663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
49673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
49683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
49693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return;
49703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
49713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
49733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_uploadMethod == UPLOADMETHOD_BUFFER_DATA)
49753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(target, size, source, GL_DYNAMIC_DRAW);
49763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_uploadMethod == UPLOADMETHOD_BUFFER_SUB_DATA)
49773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
49783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// create buffer storage
49793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_bufferState == BUFFERSTATE_NEW)
49803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bufferData(target, size, DE_NULL, GL_DYNAMIC_DRAW);
49813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferSubData(target, offset, size, source);
49823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
49833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_uploadMethod == UPLOADMETHOD_MAP_BUFFER_RANGE)
49843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
49853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			void*			mapPtr;
49863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glw::GLboolean	unmapSuccessful;
49873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// create buffer storage
49893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_bufferState == BUFFERSTATE_NEW)
49903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bufferData(target, size, DE_NULL, GL_DYNAMIC_DRAW);
49913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			mapPtr = gl.mapBufferRange(target, offset, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
49933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!mapPtr)
49943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::Exception("MapBufferRange returned NULL");
49953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deMemcpy(mapPtr, source, (int)size);
49973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
49983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// if unmapping fails, just try again later
49993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			unmapSuccessful = gl.unmapBuffer(target);
50003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!unmapSuccessful)
50013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw UnmapFailureError();
50023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
50033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
50043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
50053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
50073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.uploadedDataSize = (int)size;
50093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.uploadDuration = endTime - startTime;
50103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
50113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// unrelated
50133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_unrelatedBufferType == UNRELATEDBUFFERTYPE_VERTEX)
50143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
50153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int unrelatedUploadSize = (int)(vertexData.size() * sizeof(tcu::Vec4));
50163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, *unrelatedBuffer);
50183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, unrelatedUploadSize, &vertexData[0], GL_STATIC_DRAW);
50193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Attibute pointers are not modified, no need restore state
50203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.unrelatedDataSize = unrelatedUploadSize;
50223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
50233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// draw
50253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
50263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
50273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
50293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, numVertices);
50303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
50313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
50323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
50333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
50343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
50363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.renderDuration = endTime - startTime;
50383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
50393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// read
50413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
50423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
50433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glu::readPixels(m_context.getRenderContext(), 0, 0, resultSurface.getAccess());
50443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
50453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.readDuration = endTime - startTime;
50473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
50483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// set results
50503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.renderDataSize = RenderCase<SampleType>::getVertexDataSize() * sample.result.numVertices;
50523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.renderReadDuration = sample.result.duration.renderDuration + sample.result.duration.readDuration;
50543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.totalDuration = sample.result.duration.uploadDuration + sample.result.duration.renderDuration + sample.result.duration.readDuration;
50553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.fitResponseDuration = sample.result.duration.renderReadDuration;
50563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
50573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BufferInUseRenderTimeCase : public RenderCase<RenderUploadRenderReadDuration>
50593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
50603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
50613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum MapFlags
50623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
50633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		MAPFLAG_NONE = 0,
50643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		MAPFLAG_INVALIDATE_BUFFER,
50653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		MAPFLAG_INVALIDATE_RANGE,
50663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		MAPFLAG_LAST
50683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
50693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum UploadBufferTarget
50703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
50713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		UPLOADBUFFERTARGET_DIFFERENT_BUFFER = 0,
50723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		UPLOADBUFFERTARGET_SAME_BUFFER,
50733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		UPLOADBUFFERTARGET_LAST
50753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
50763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								BufferInUseRenderTimeCase	(Context&			context,
50773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const char*		name,
50783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const char*		description,
50793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 DrawMethod			method,
50803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 MapFlags			mapFlags,
50813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 TargetBuffer		targetBuffer,
50823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 UploadMethod		uploadMethod,
50833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 UploadRange		uploadRange,
50843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 UploadBufferTarget	uploadTarget);
50853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
50873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						init						(void);
50883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void						runSample					(SampleResult& sample);
50893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const TargetBuffer			m_targetBuffer;
50913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadMethod			m_uploadMethod;
50923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadRange			m_uploadRange;
50933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const MapFlags				m_mapFlags;
50943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadBufferTarget	m_uploadBufferTarget;
50953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
50963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
50973c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferInUseRenderTimeCase::BufferInUseRenderTimeCase (Context&				context,
50983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													  const char*			name,
50993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													  const char*			description,
51003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													  DrawMethod			method,
51013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													  MapFlags				mapFlags,
51023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													  TargetBuffer			targetBuffer,
51033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													  UploadMethod			uploadMethod,
51043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													  UploadRange			uploadRange,
51053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													  UploadBufferTarget	uploadTarget)
51063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: RenderCase<RenderUploadRenderReadDuration>	(context, name, description, method)
51073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_targetBuffer								(targetBuffer)
51083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_uploadMethod								(uploadMethod)
51093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_uploadRange									(uploadRange)
51103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_mapFlags									(mapFlags)
51113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_uploadBufferTarget							(uploadTarget)
51123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
51133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_targetBuffer < TARGETBUFFER_LAST);
51143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_uploadMethod < UPLOADMETHOD_LAST);
51153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_uploadRange < UPLOADRANGE_LAST);
51163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_mapFlags < MAPFLAG_LAST);
51173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_uploadBufferTarget < UPLOADBUFFERTARGET_LAST);
51183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
51193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BufferInUseRenderTimeCase::init (void)
51213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
51223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderCase<RenderUploadRenderReadDuration>::init();
51233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// log
51253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
51263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* const	targetFunctionName		= (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS) ? ("drawArrays") : ("drawElements");
51273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* const	uploadFunctionName		= (m_uploadMethod == UPLOADMETHOD_BUFFER_DATA) ? ("bufferData") : (m_uploadMethod == UPLOADMETHOD_BUFFER_SUB_DATA) ? ("bufferSubData") : ("mapBufferRange");
51283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool			isReferenceCase			= (m_uploadBufferTarget == UPLOADBUFFERTARGET_DIFFERENT_BUFFER);
51293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::MessageBuilder	message					(&m_testCtx.getLog());
51303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		message	<< "Measuring the time used in " << targetFunctionName << " call, a buffer upload, "
51323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< targetFunctionName << " call using the uploaded buffer and readPixels call with different upload sizes.\n";
51333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (isReferenceCase)
51353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			message << "Rendering:\n"
51363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "    before test: create and use buffers B and C\n"
51373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "    first draw: render using buffer B\n"
51383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< ((m_uploadRange == UPLOADRANGE_FULL)		? ("    upload: respecify buffer C contents\n")	:
51393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						(m_uploadRange == UPLOADRANGE_PARTIAL)	? ("    upload: modify buffer C contents\n")	:
51403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						((const char*)DE_NULL))
51413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "    second draw: render using buffer C\n"
51423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "    read: readPixels\n";
51433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
51443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			message << "Rendering:\n"
51453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "    before test: create and use buffer B\n"
51463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "    first draw: render using buffer B\n"
51473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< ((m_uploadRange == UPLOADRANGE_FULL)		? ("    upload: respecify buffer B contents\n")	:
51483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						(m_uploadRange == UPLOADRANGE_PARTIAL)	? ("    upload: modify buffer B contents\n")	:
51493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						((const char*)DE_NULL))
51503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "    second draw: render using buffer B\n"
51513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "    read: readPixels\n";
51523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		message	<< "Uploading using " << uploadFunctionName
51543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< ((m_mapFlags == MAPFLAG_INVALIDATE_RANGE)	? (", flags = MAP_WRITE_BIT | MAP_INVALIDATE_RANGE_BIT")	:
51553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						(m_mapFlags == MAPFLAG_INVALIDATE_BUFFER)	? (", flags = MAP_WRITE_BIT | MAP_INVALIDATE_BUFFER_BIT")	:
51563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						(m_mapFlags == MAPFLAG_NONE)				? ("")														:
51573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						((const char*)DE_NULL))
51583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "\n"
51593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< getNumSamples() << " test samples. Sample order is randomized.\n"
51603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< "All samples at even positions (first = 0) are tested before samples at odd positions.\n"
51613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< "Workload sizes are in the range ["
51623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< getMinWorkloadSize() << ",  "
51633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< getMaxWorkloadSize() << "] vertices "
51643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< "(["
51653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< getHumanReadableByteSize(getMinWorkloadDataSize()) << ","
51663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					<< getHumanReadableByteSize(getMaxWorkloadDataSize()) << "] to be processed).\n"
51673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				<< "Test result is the approximated processing rate in MiB / s of the second draw call and the readPixels call.\n";
51683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (isReferenceCase)
51703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			message	<< "Note! Test result should only be used as a baseline reference result for buffer.render_after_upload.draw_modify_draw test group results.";
51713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
51723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			message	<< "Note! Test result may not be useful as is but instead should be compared against the buffer.render_after_upload.reference.draw_upload_draw group results.\n";
51733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		message << tcu::TestLog::EndMessage;
51753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
51763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
51773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BufferInUseRenderTimeCase::runSample (SampleResult& sample)
51793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
51803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl						= m_context.getRenderContext().getFunctions();
51813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		arrayBuffer				(m_context.getRenderContext());
51823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		indexBuffer				(m_context.getRenderContext());
51833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glu::Buffer		alternativeUploadBuffer	(m_context.getRenderContext());
51843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				numVertices				= getLayeredGridNumVertices(sample.scene);
51853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			resultSurface			(RENDER_AREA_SIZE, RENDER_AREA_SIZE);
51863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				startTime;
51873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				endTime;
51883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<tcu::Vec4>	vertexData;
51893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint32>	indexData;
51903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// create data
51923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	generateLayeredGridVertexAttribData4C4V(vertexData, sample.scene);
51943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
51953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridIndexData(indexData, sample.scene);
51963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// make buffers used
51983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
51993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, *arrayBuffer);
52003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
52013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	setupVertexAttribs();
52023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
52043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
52053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], GL_STREAM_DRAW);
52063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawArrays(GL_TRIANGLES, 0, numVertices);
52073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
52083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
52093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
52103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], GL_STREAM_DRAW);
52113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (glw::GLsizeiptr)(indexData.size() * sizeof(deUint32)), &indexData[0], GL_STREAM_DRAW);
52123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
52133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
52143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
52153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
52163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// another pair of buffers for reference case
52183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_uploadBufferTarget == UPLOADBUFFERTARGET_DIFFERENT_BUFFER)
52193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
52203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_targetBuffer == TARGETBUFFER_VERTEX)
52213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
52223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ARRAY_BUFFER, *alternativeUploadBuffer);
52233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4)), &vertexData[0], GL_STREAM_DRAW);
52243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			setupVertexAttribs();
52263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, numVertices);
52273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
52283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_INDEX)
52293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
52303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *alternativeUploadBuffer);
52313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (glw::GLsizeiptr)(indexData.size() * sizeof(deUint32)), &indexData[0], GL_STREAM_DRAW);
52323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
52333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
52343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
52353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
52363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// restore state
52383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, *arrayBuffer);
52393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer);
52403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		setupVertexAttribs();
52413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
52423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	waitGLResults();
52443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "post buffer prepare");
52453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
52473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.clear(GL_COLOR_BUFFER_BIT);
52483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	waitGLResults();
52493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::warmupCPU();
52513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// first draw
52533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
52543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
52553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
52573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, numVertices);
52583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
52593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
52603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
52613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
52623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
52643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.firstRenderDuration = endTime - startTime;
52663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
52673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// upload
52693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
52703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLenum		target;
52713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLsizeiptr	size;
52723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLintptr	offset = 0;
52733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const void*		source;
52743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
52753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_targetBuffer == TARGETBUFFER_VERTEX && m_uploadRange == UPLOADRANGE_FULL)
52763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
52773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			target	= GL_ARRAY_BUFFER;
52783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			size	= (glw::GLsizeiptr)(vertexData.size() * sizeof(tcu::Vec4));
52793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			source	= &vertexData[0];
52803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
52813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_INDEX && m_uploadRange == UPLOADRANGE_FULL)
52823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
52833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			target	= GL_ELEMENT_ARRAY_BUFFER;
52843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			size	= (glw::GLsizeiptr)(indexData.size() * sizeof(deUint32));
52853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			source	= &indexData[0];
52863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
52873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_VERTEX && m_uploadRange == UPLOADRANGE_PARTIAL)
52883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
52893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			target	= GL_ARRAY_BUFFER;
52903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			size	= (glw::GLsizeiptr)deAlign32((int)(vertexData.size() * sizeof(tcu::Vec4)) / 2, 4);
52913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			offset	= (glw::GLintptr)deAlign32((int)size / 2, 4);
52923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			source	= (const deUint8*)&vertexData[0] + offset;
52933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
52943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_INDEX && m_uploadRange == UPLOADRANGE_PARTIAL)
52953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
52963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// upload to 25% - 75% range
52973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			target	= GL_ELEMENT_ARRAY_BUFFER;
52983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			size	= (glw::GLsizeiptr)deAlign32((glw::GLsizeiptr)((int)(indexData.size() * sizeof(deUint32))) / 2, 4);
52993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			offset	= (glw::GLintptr)deAlign32((int)size / 2, 4);
53003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			source	= (const deUint8*)&indexData[0] + offset;
53013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
53023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
53033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
53043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
53053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return;
53063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
53073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// reference case? don't modify the buffer in use
53093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_uploadBufferTarget == UPLOADBUFFERTARGET_DIFFERENT_BUFFER)
53103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(target, *alternativeUploadBuffer);
53113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
53133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_uploadMethod == UPLOADMETHOD_BUFFER_DATA)
53153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(target, size, source, GL_STREAM_DRAW);
53163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_uploadMethod == UPLOADMETHOD_BUFFER_SUB_DATA)
53173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferSubData(target, offset, size, source);
53183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_uploadMethod == UPLOADMETHOD_MAP_BUFFER_RANGE)
53193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
53203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int		mapFlags	= (m_mapFlags == MAPFLAG_INVALIDATE_BUFFER)	? (GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)	:
53213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  (m_mapFlags == MAPFLAG_INVALIDATE_RANGE)	? (GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT)	:
53223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										  (-1);
53233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			void*			mapPtr;
53243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			glw::GLboolean	unmapSuccessful;
53253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			mapPtr = gl.mapBufferRange(target, offset, size, mapFlags);
53273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!mapPtr)
53283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::Exception("MapBufferRange returned NULL");
53293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deMemcpy(mapPtr, source, (int)size);
53313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// if unmapping fails, just try again later
53333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			unmapSuccessful = gl.unmapBuffer(target);
53343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!unmapSuccessful)
53353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw UnmapFailureError();
53363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
53373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
53383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
53393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
53413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.uploadedDataSize = (int)size;
53433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.uploadDuration = endTime - startTime;
53443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
53453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// second draw
53473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
53483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Source vertex data from alternative buffer in refernce case
53493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_uploadBufferTarget == UPLOADBUFFERTARGET_DIFFERENT_BUFFER && m_targetBuffer == TARGETBUFFER_VERTEX)
53503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			setupVertexAttribs();
53513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
53533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
53553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, numVertices);
53563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
53573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_INT, DE_NULL);
53583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
53593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
53603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
53623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.secondRenderDuration = endTime - startTime;
53643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
53653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// read
53673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
53683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
53693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glu::readPixels(m_context.getRenderContext(), 0, 0, resultSurface.getAccess());
53703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
53713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sample.result.duration.readDuration = endTime - startTime;
53733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
53743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// set results
53763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.renderDataSize = getVertexDataSize() * sample.result.numVertices;
53783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.renderReadDuration	= sample.result.duration.secondRenderDuration + sample.result.duration.readDuration;
53803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.totalDuration		= sample.result.duration.firstRenderDuration +
53813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												  sample.result.duration.uploadDuration +
53823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												  sample.result.duration.secondRenderDuration +
53833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry												  sample.result.duration.readDuration;
53843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.result.duration.fitResponseDuration	= sample.result.duration.renderReadDuration;
53853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
53863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass UploadWaitDrawCase : public RenderPerformanceTestBase
53883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
53893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
53903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	struct Sample
53913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
53923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			numFrames;
53933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	uploadCallEndTime;
53943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
53953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	struct Result
53963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
53973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	uploadDuration;
53983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	renderDuration;
53993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	readDuration;
54003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	renderReadDuration;
54013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint64	timeBeforeUse;
54033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
54043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							UploadWaitDrawCase				(Context&		context,
54063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const char*	name,
54073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 const char*	description,
54083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 DrawMethod		drawMethod,
54093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 TargetBuffer	targetBuffer,
54103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 UploadMethod	uploadMethod,
54113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 BufferState	bufferState);
54123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~UploadWaitDrawCase				(void);
54133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
54153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					init							(void);
54163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					deinit							(void);
54173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult			iterate							(void);
54183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					uploadBuffer					(Sample& sample, Result& result);
54203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					drawFromBuffer					(Sample& sample, Result& result);
54213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					reuseAndDeleteBuffer			(void);
54223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					logAndSetTestResult				(void);
54233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					logSamples						(void);
54243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					drawMisc						(void);
54253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						findStabilizationSample			(deUint64 (Result::*target), const char* description);
54263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					checkSampleTemporalStability	(deUint64 (Result::*target), const char* description);
54273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const DrawMethod		m_drawMethod;
54293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const TargetBuffer		m_targetBuffer;
54303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const UploadMethod		m_uploadMethod;
54313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const BufferState		m_bufferState;
54323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_numSamplesPerSwap;
54343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				m_numMaxSwaps;
54353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_frameNdx;
54373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_sampleNdx;
54383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_numVertices;
54393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<tcu::Vec4>	m_vertexData;
54413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint32>	m_indexData;
54423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<Sample>		m_samples;
54433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<Result>		m_results;
54443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<int>		m_iterationOrder;
54453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_vertexBuffer;
54473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_indexBuffer;
54483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_miscBuffer;
54493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int						m_numMiscVertices;
54503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
54513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54523c827367444ee418f129b2c238299f49d3264554Jarkko PoyryUploadWaitDrawCase::UploadWaitDrawCase (Context&		context,
54533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										const char*		name,
54543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										const char*		description,
54553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										DrawMethod		drawMethod,
54563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										TargetBuffer	targetBuffer,
54573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										UploadMethod	uploadMethod,
54583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										BufferState		bufferState)
54593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: RenderPerformanceTestBase	(context, name, description)
54603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_drawMethod				(drawMethod)
54613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_targetBuffer			(targetBuffer)
54623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_uploadMethod			(uploadMethod)
54633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_bufferState				(bufferState)
54643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numSamplesPerSwap		(10)
54653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numMaxSwaps				(4)
54663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_frameNdx				(0)
54673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_sampleNdx				(0)
54683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numVertices				(-1)
54693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_vertexBuffer			(0)
54703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_indexBuffer				(0)
54713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_miscBuffer				(0)
54723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_numMiscVertices			(-1)
54733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
54743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
54753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54763c827367444ee418f129b2c238299f49d3264554Jarkko PoyryUploadWaitDrawCase::~UploadWaitDrawCase (void)
54773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
54783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deinit();
54793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
54803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UploadWaitDrawCase::init (void)
54823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
54833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl						= m_context.getRenderContext().getFunctions();
54843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				vertexAttribSize		= (int)sizeof(tcu::Vec4) * 2; // color4, position4
54853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				vertexIndexSize			= (int)sizeof(deUint32);
54863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				vertexUploadDataSize	= (m_targetBuffer == TARGETBUFFER_VERTEX) ? (vertexAttribSize) : (vertexIndexSize);
54873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderPerformanceTestBase::init();
54893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// requirements
54913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_context.getRenderTarget().getWidth() < RENDER_AREA_SIZE ||
54933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderTarget().getHeight() < RENDER_AREA_SIZE)
54943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::NotSupportedError("Test case requires " + de::toString<int>(RENDER_AREA_SIZE) + "x" + de::toString<int>(RENDER_AREA_SIZE) + " render target");
54953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// gl state
54973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
54983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.viewport(0, 0, RENDER_AREA_SIZE, RENDER_AREA_SIZE);
54993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// enable bleding to prevent grid layers from being discarded
55013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
55033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.blendEquation(GL_FUNC_ADD);
55043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.enable(GL_BLEND);
55053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// scene
55073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
55093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		LayeredGridSpec scene;
55103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// create ~8MB workload with similar characteristics as in the other test
55123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// => makes comparison to other results more straightforward
55133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		scene.gridWidth = 93;
55143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		scene.gridHeight = 93;
55153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		scene.gridLayers = 5;
55163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridVertexAttribData4C4V(m_vertexData, scene);
55183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridIndexData(m_indexData, scene);
55193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_numVertices = getLayeredGridNumVertices(scene);
55203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
55213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// buffers
55233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_bufferState == BUFFERSTATE_NEW)
55253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
55263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
55273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
55283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// reads from two buffers, prepare the static buffer
55293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_targetBuffer == TARGETBUFFER_VERTEX)
55313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
55323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// index buffer is static, use another vertex buffer to keep original buffer in unused state
55333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const glu::Buffer vertexCopyBuffer(m_context.getRenderContext());
55343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.genBuffers(1, &m_indexBuffer);
55363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bindBuffer(GL_ARRAY_BUFFER, *vertexCopyBuffer);
55373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
55383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(m_vertexData.size() * sizeof(tcu::Vec4)), &m_vertexData[0], GL_STATIC_DRAW);
55393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (glw::GLsizeiptr)(m_indexData.size() * sizeof(deUint32)), &m_indexData[0], GL_STATIC_DRAW);
55403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				setupVertexAttribs();
55423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.drawElements(GL_TRIANGLES, m_numVertices, GL_UNSIGNED_INT, DE_NULL);
55433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
55443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (m_targetBuffer == TARGETBUFFER_INDEX)
55453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
55463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// vertex buffer is static
55473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.genBuffers(1, &m_vertexBuffer);
55483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
55493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(m_vertexData.size() * sizeof(tcu::Vec4)), &m_vertexData[0], GL_STATIC_DRAW);
55503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				setupVertexAttribs();
55523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				gl.drawArrays(GL_TRIANGLES, 0, m_numVertices);
55533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
55543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
55553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DE_ASSERT(false);
55563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
55573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
55583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_bufferState == BUFFERSTATE_EXISTING)
55593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
55603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glw::GLenum vertexUsage	= (m_targetBuffer == TARGETBUFFER_VERTEX) ? (GL_STATIC_DRAW) : (GL_STATIC_DRAW);
55613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const glw::GLenum indexUsage	= (m_targetBuffer == TARGETBUFFER_INDEX) ? (GL_STATIC_DRAW) : (GL_STATIC_DRAW);
55623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.genBuffers(1, &m_vertexBuffer);
55643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
55653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(m_vertexData.size() * sizeof(tcu::Vec4)), &m_vertexData[0], vertexUsage);
55663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
55683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
55693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.genBuffers(1, &m_indexBuffer);
55703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
55713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (glw::GLsizeiptr)(m_indexData.size() * sizeof(deUint32)), &m_indexData[0], indexUsage);
55723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
55733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		setupVertexAttribs();
55753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
55773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, m_numVertices);
55783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
55793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, m_numVertices, GL_UNSIGNED_INT, DE_NULL);
55803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
55813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
55823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
55833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
55843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
55853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// misc draw buffer
55873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
55883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::vector<tcu::Vec4>	vertexData;
55893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		LayeredGridSpec			scene;
55903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// create ~1.5MB workload with similar characteristics
55923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		scene.gridWidth = 40;
55933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		scene.gridHeight = 40;
55943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		scene.gridLayers = 5;
55953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateLayeredGridVertexAttribData4C4V(vertexData, scene);
55973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
55983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.genBuffers(1, &m_miscBuffer);
55993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, m_miscBuffer);
56003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(sizeof(tcu::Vec4) * vertexData.size()), &vertexData[0], GL_STATIC_DRAW);
56013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_numMiscVertices = getLayeredGridNumVertices(scene);
56033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
56043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// iterations
56063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
56073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_samples.resize((m_numMaxSwaps+1) * m_numSamplesPerSwap);
56083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_results.resize((m_numMaxSwaps+1) * m_numSamplesPerSwap);
56093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int numSwaps = 0; numSwaps <= m_numMaxSwaps; ++numSwaps)
56113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int sampleNdx = 0; sampleNdx < m_numSamplesPerSwap; ++sampleNdx)
56123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
56133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int index = numSwaps*m_numSamplesPerSwap + sampleNdx;
56143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_samples[index].numFrames = numSwaps;
56163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
56173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_iterationOrder.resize(m_samples.size());
56193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		generateTwoPassRandomIterationOrder(m_iterationOrder, (int)m_samples.size());
56203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
56213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// log
56233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
56243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
56253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Measuring time used in " << ((m_drawMethod == DRAWMETHOD_DRAW_ARRAYS) ? ("drawArrays") : ("drawElements")) << " and readPixels call.\n"
56263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Drawing using a buffer that has been uploaded N frames ago. Testing with N within range [0, " << m_numMaxSwaps << "].\n"
56273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Uploaded buffer is a " << ((m_targetBuffer == TARGETBUFFER_VERTEX) ? ("vertex attribute") : ("index")) << " buffer.\n"
56283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Uploading using "
56293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< ((m_uploadMethod == UPLOADMETHOD_BUFFER_DATA)		? ("bufferData")																							:
56303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				(m_uploadMethod == UPLOADMETHOD_BUFFER_SUB_DATA)	? ("bufferSubData")																							:
56313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				(m_uploadMethod == UPLOADMETHOD_MAP_BUFFER_RANGE)	? ("mapBufferRange, flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT")	:
56323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				((const char*)DE_NULL))
56333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "\n"
56343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Upload size is " << getHumanReadableByteSize(m_numVertices * vertexUploadDataSize) << ".\n"
56353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< ((m_bufferState == BUFFERSTATE_EXISTING) ? ("All test samples use the same buffer object.\n") : (""))
56363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Test result is the number of frames (swaps) required for the render time to stabilize.\n"
56373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< "Assuming combined time used in the draw call and readPixels call is stabilizes to a constant value.\n"
56383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
56393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
56403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UploadWaitDrawCase::deinit (void)
56423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
56433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	RenderPerformanceTestBase::deinit();
56443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_vertexBuffer)
56463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
56473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_vertexBuffer);
56483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_vertexBuffer = 0;
56493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
56503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_indexBuffer)
56513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
56523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_indexBuffer);
56533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_indexBuffer = 0;
56543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
56553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_miscBuffer)
56563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
56573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_miscBuffer);
56583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_miscBuffer = 0;
56593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
56603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
56613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56623c827367444ee418f129b2c238299f49d3264554Jarkko PoyryUploadWaitDrawCase::IterateResult UploadWaitDrawCase::iterate (void)
56633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
56643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl								= m_context.getRenderContext().getFunctions();
56653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				betweenIterationDummyFrameCount = 5; // draw misc between test samples
56663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				frameNdx						= m_frameNdx++;
56673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				currentSampleNdx				= m_iterationOrder[m_sampleNdx];
56683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Simulate work for about 8ms
56703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	busyWait(8000);
56713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Dummy rendering during dummy frames
56733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (frameNdx != m_samples[currentSampleNdx].numFrames)
56743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
56753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// draw similar from another buffer
56763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		drawMisc();
56773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
56783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (frameNdx == 0)
56803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
56813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// upload and start the clock
56823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		uploadBuffer(m_samples[currentSampleNdx], m_results[currentSampleNdx]);
56833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
56843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (frameNdx == m_samples[currentSampleNdx].numFrames) // \note: not else if, m_samples[currentSampleNdx].numFrames can be 0
56863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
56873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// draw using the uploaded buffer
56883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		drawFromBuffer(m_samples[currentSampleNdx], m_results[currentSampleNdx]);
56893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
56903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// re-use buffer for something else to make sure test iteration do not affect each other
56913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_bufferState == BUFFERSTATE_NEW)
56923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			reuseAndDeleteBuffer();
56933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
56943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (frameNdx == m_samples[currentSampleNdx].numFrames + betweenIterationDummyFrameCount)
56953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
56963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// next sample
56973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		++m_sampleNdx;
56983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_frameNdx = 0;
56993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
57003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GLU_EXPECT_NO_ERROR(gl.getError(), "post-iterate");
57023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_sampleNdx < (int)m_samples.size())
57043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return CONTINUE;
57053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	logAndSetTestResult();
57073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return STOP;
57083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
57093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57103c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UploadWaitDrawCase::uploadBuffer (Sample& sample, Result& result)
57113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
57123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl			= m_context.getRenderContext().getFunctions();
57133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				startTime;
57143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				endTime;
57153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLenum				target;
57163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::GLsizeiptr			size;
57173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const void*				source;
57183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// data source
57203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_targetBuffer == TARGETBUFFER_VERTEX)
57223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
57233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT((m_vertexBuffer == 0) == (m_bufferState == BUFFERSTATE_NEW));
57243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		target	= GL_ARRAY_BUFFER;
57263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		size	= (glw::GLsizeiptr)(m_vertexData.size() * sizeof(tcu::Vec4));
57273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		source	= &m_vertexData[0];
57283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
57293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_targetBuffer == TARGETBUFFER_INDEX)
57303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
57313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT((m_indexBuffer == 0) == (m_bufferState == BUFFERSTATE_NEW));
57323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		target	= GL_ELEMENT_ARRAY_BUFFER;
57343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		size	= (glw::GLsizeiptr)(m_indexData.size() * sizeof(deUint32));
57353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		source	= &m_indexData[0];
57363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
57373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
57383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
57393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
57403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return;
57413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
57423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// gen buffer
57443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_bufferState == BUFFERSTATE_NEW)
57463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
57473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_targetBuffer == TARGETBUFFER_VERTEX)
57483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
57493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.genBuffers(1, &m_vertexBuffer);
57503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
57513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
57523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_INDEX)
57533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
57543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.genBuffers(1, &m_indexBuffer);
57553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
57563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
57573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
57583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
57593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_uploadMethod == UPLOADMETHOD_BUFFER_SUB_DATA ||
57613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_uploadMethod == UPLOADMETHOD_MAP_BUFFER_RANGE)
57623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
57633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bufferData(target, size, DE_NULL, GL_STATIC_DRAW);
57643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
57653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
57663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_bufferState == BUFFERSTATE_EXISTING)
57673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
57683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_targetBuffer == TARGETBUFFER_VERTEX)
57693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
57703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_targetBuffer == TARGETBUFFER_INDEX)
57713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
57723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
57733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
57743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
57753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
57763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
57773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// upload
57793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	startTime = deGetMicroseconds();
57813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_uploadMethod == UPLOADMETHOD_BUFFER_DATA)
57833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(target, size, source, GL_STATIC_DRAW);
57843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_uploadMethod == UPLOADMETHOD_BUFFER_SUB_DATA)
57853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferSubData(target, 0, size, source);
57863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_uploadMethod == UPLOADMETHOD_MAP_BUFFER_RANGE)
57873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
57883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		void*			mapPtr;
57893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glw::GLboolean	unmapSuccessful;
57903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		mapPtr = gl.mapBufferRange(target, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
57923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!mapPtr)
57933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::Exception("MapBufferRange returned NULL");
57943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deMemcpy(mapPtr, source, (int)size);
57963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
57973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// if unmapping fails, just try again later
57983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		unmapSuccessful = gl.unmapBuffer(target);
57993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!unmapSuccessful)
58003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw UnmapFailureError();
58013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
58023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
58033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
58043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	endTime = deGetMicroseconds();
58063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	sample.uploadCallEndTime = endTime;
58083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.uploadDuration = endTime - startTime;
58093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
58103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UploadWaitDrawCase::drawFromBuffer (Sample& sample, Result& result)
58123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
58133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	gl				= m_context.getRenderContext().getFunctions();
58143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::Surface			resultSurface	(RENDER_AREA_SIZE, RENDER_AREA_SIZE);
58153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				startTime;
58163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint64				endTime;
58173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(m_vertexBuffer != 0);
58193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
58203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_indexBuffer == 0);
58213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
58223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_indexBuffer != 0);
58233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
58243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(false);
58253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// draw
58273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
58283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
58293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
58303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
58313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		setupVertexAttribs();
58333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// microseconds passed since return from upload call
58353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.timeBeforeUse = deGetMicroseconds() - sample.uploadCallEndTime;
58363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
58383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (m_drawMethod == DRAWMETHOD_DRAW_ARRAYS)
58403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawArrays(GL_TRIANGLES, 0, m_numVertices);
58413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (m_drawMethod == DRAWMETHOD_DRAW_ELEMENTS)
58423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			gl.drawElements(GL_TRIANGLES, m_numVertices, GL_UNSIGNED_INT, DE_NULL);
58433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
58443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
58453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
58473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.renderDuration = endTime - startTime;
58493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
58503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// read
58523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
58533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		startTime = deGetMicroseconds();
58543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		glu::readPixels(m_context.getRenderContext(), 0, 0, resultSurface.getAccess());
58553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		endTime = deGetMicroseconds();
58563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.readDuration = endTime - startTime;
58583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
58593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result.renderReadDuration = result.renderDuration + result.readDuration;
58613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
58623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UploadWaitDrawCase::reuseAndDeleteBuffer (void)
58643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
58653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
58663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_targetBuffer == TARGETBUFFER_INDEX)
58683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
58693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// respecify and delete index buffer
58703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const deUint32 indices[3] = {1, 3, 8};
58713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_indexBuffer != 0);
58733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
58753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, DE_NULL);
58763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.deleteBuffers(1, &m_indexBuffer);
58773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_indexBuffer = 0;
58783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
58793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (m_targetBuffer == TARGETBUFFER_VERTEX)
58803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
58813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// respecify and delete vertex buffer
58823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const tcu::Vec4 coloredTriangle[6] =
58833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
58843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(-0.4f, -0.4f, 0.0f, 1.0f),
58853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(-0.2f,  0.4f, 0.0f, 1.0f),
58863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4( 0.8f, -0.1f, 0.0f, 1.0f),
58873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
58883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(m_vertexBuffer != 0);
58903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.bufferData(GL_ARRAY_BUFFER, sizeof(coloredTriangle), coloredTriangle, GL_STATIC_DRAW);
58923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.drawArrays(GL_TRIANGLES, 0, 3);
58933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		gl.deleteBuffers(1, &m_vertexBuffer);
58943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_vertexBuffer = 0;
58953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
58963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
58973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	waitGLResults();
58983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
58993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UploadWaitDrawCase::logAndSetTestResult (void)
59013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
59023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		uploadStabilization;
59033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		renderReadStabilization;
59043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		renderStabilization;
59053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int		readStabilization;
59063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	temporallyStable;
59073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
59093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Samples", "Result samples");
59103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		logSamples();
59113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
59123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
59143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Stabilization", "Sample stability");
59153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// log stabilization points
59173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		renderReadStabilization	= findStabilizationSample(&Result::renderReadDuration, "Combined draw and read");
59183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		uploadStabilization		= findStabilizationSample(&Result::uploadDuration, "Upload time");
59193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		renderStabilization		= findStabilizationSample(&Result::renderDuration, "Draw call time");
59203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		readStabilization		= findStabilizationSample(&Result::readDuration, "ReadPixels time");
59213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		temporallyStable		= true;
59233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		temporallyStable		&= checkSampleTemporalStability(&Result::renderReadDuration, "Combined draw and read");
59243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		temporallyStable		&= checkSampleTemporalStability(&Result::uploadDuration, "Upload time");
59253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		temporallyStable		&= checkSampleTemporalStability(&Result::renderDuration, "Draw call time");
59263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		temporallyStable		&= checkSampleTemporalStability(&Result::readDuration, "ReadPixels time");
59273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
59283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
59303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Results", "Results");
59313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Check result sanily
59333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (uploadStabilization != 0)
59343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << tcu::TestLog::Message << "Warning! Upload times are not stable, test result may not be accurate." << tcu::TestLog::EndMessage;
59353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!temporallyStable)
59363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << tcu::TestLog::Message << "Warning! Time samples do not seem to be temporally stable, sample times seem to drift to one direction during test execution." << tcu::TestLog::EndMessage;
59373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// render & read
59393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (renderReadStabilization == -1)
59403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << tcu::TestLog::Message << "Combined time used in draw call and ReadPixels did not stabilize." << tcu::TestLog::EndMessage;
59413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
59423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << tcu::TestLog::Integer("RenderReadStabilizationPoint", "Combined draw call and ReadPixels call time stabilization time", "frames", QP_KEY_TAG_TIME, renderReadStabilization);
59433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// draw call
59453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (renderStabilization == -1)
59463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << tcu::TestLog::Message << "Time used in draw call did not stabilize." << tcu::TestLog::EndMessage;
59473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
59483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << tcu::TestLog::Integer("DrawCallStabilizationPoint", "Draw call time stabilization time", "frames", QP_KEY_TAG_TIME, renderStabilization);
59493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// readpixels
59513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (readStabilization == -1)
59523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << tcu::TestLog::Message << "Time used in ReadPixels did not stabilize." << tcu::TestLog::EndMessage;
59533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
59543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.getLog() << tcu::TestLog::Integer("ReadPixelsStabilizationPoint", "ReadPixels call time stabilization time", "frames", QP_KEY_TAG_TIME, readStabilization);
59553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Report renderReadStabilization
59573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (renderReadStabilization != -1)
59583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::toString(renderReadStabilization).c_str());
59593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
59603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::toString(m_numMaxSwaps).c_str()); // don't report -1
59613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
59623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
59633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UploadWaitDrawCase::logSamples (void)
59653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
59663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Inverse m_iterationOrder
59673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<int> runOrder(m_iterationOrder.size());
59693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)m_iterationOrder.size(); ++ndx)
59703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		runOrder[m_iterationOrder[ndx]] = ndx;
59713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Log samples
59733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
59753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleList("Samples", "Samples")
59763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::SampleInfo
59773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("NumSwaps",		"SwapBuffers before use",			"",		QP_SAMPLE_VALUE_TAG_PREDICTOR)
59783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("Delay",			"Time before use",					"us",	QP_SAMPLE_VALUE_TAG_PREDICTOR)
59793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("RunOrder",		"Sample run order",					"",		QP_SAMPLE_VALUE_TAG_PREDICTOR)
59803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawReadTime",	"Draw call and ReadPixels time",	"us",	QP_SAMPLE_VALUE_TAG_RESPONSE)
59813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("TotalTime",		"Total time",						"us",	QP_SAMPLE_VALUE_TAG_RESPONSE)
59823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("Upload time",	"Upload time",						"us",	QP_SAMPLE_VALUE_TAG_RESPONSE)
59833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("DrawCallTime",	"Draw call time",					"us",	QP_SAMPLE_VALUE_TAG_RESPONSE)
59843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::ValueInfo("ReadTime",		"ReadPixels time",					"us",	QP_SAMPLE_VALUE_TAG_RESPONSE)
59853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndSampleInfo;
59863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
59873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)m_samples.size(); ++sampleNdx)
59883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog()
59893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Sample
59903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< m_samples[sampleNdx].numFrames
59913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)m_results[sampleNdx].timeBeforeUse
59923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< runOrder[sampleNdx]
59933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)m_results[sampleNdx].renderReadDuration
59943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)(m_results[sampleNdx].renderReadDuration + m_results[sampleNdx].uploadDuration)
59953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)m_results[sampleNdx].uploadDuration
59963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)m_results[sampleNdx].renderDuration
59973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< (int)m_results[sampleNdx].readDuration
59983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndSample;
59993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog() << tcu::TestLog::EndSampleList;
60013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
60023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60033c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid UploadWaitDrawCase::drawMisc (void)
60043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
60053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
60063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.bindBuffer(GL_ARRAY_BUFFER, m_miscBuffer);
60083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	setupVertexAttribs();
60093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	gl.drawArrays(GL_TRIANGLES, 0, m_numMiscVertices);
60103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
60113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct DistributionCompareResult
60133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
60143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool	equal;
60153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float	standardDeviations;
60163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
60173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60183c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename Comparer>
60193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic float sumOfRanks (const std::vector<deUint64>& testSamples, const std::vector<deUint64>& allSamples, const Comparer& comparer)
60203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
60213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float sum = 0;
60223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = 0; sampleNdx < (int)testSamples.size(); ++sampleNdx)
60243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
60253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint64	testSample		= testSamples[sampleNdx];
60263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int		lowerIndex		= (int)(std::lower_bound(allSamples.begin(), allSamples.end(), testSample, comparer) - allSamples.begin());
60273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int		upperIndex		= (int)(std::upper_bound(allSamples.begin(), allSamples.end(), testSample, comparer) - allSamples.begin());
60283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int		lowerRank		= lowerIndex + 1;	// convert zero-indexed to rank
60293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int		upperRank		= upperIndex;		// convert zero-indexed to rank, upperIndex is last equal + 1
60303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float		rankMidpoint	= (lowerRank + upperRank) / 2.0f;
60313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sum += rankMidpoint;
60333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
60343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return sum;
60363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
60373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename Comparer>
60393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic DistributionCompareResult distributionCompare (const std::vector<deUint64>& orderedObservationsA, const std::vector<deUint64>& orderedObservationsB, const Comparer& comparer)
60403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
60413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Mann�Whitney U test
60423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				n1			= (int)orderedObservationsA.size();
60443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				n2			= (int)orderedObservationsB.size();
60453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint64>	allSamples	(n1 + n2);
60463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::copy(orderedObservationsA.begin(), orderedObservationsA.end(), allSamples.begin());
60483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::copy(orderedObservationsB.begin(), orderedObservationsB.end(), allSamples.begin() + n1);
60493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::sort(allSamples.begin(), allSamples.end());
60503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
60523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float					R1		= sumOfRanks(orderedObservationsA, allSamples, comparer);
60533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float					U1		= n1*n2 + n1*(n1 + 1)/2 - R1;
60553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float					U2		= (n1 * n2) - U1;
60563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float					U		= de::min(U1, U2);
60573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// \note: sample sizes might not be large enough to expect normal distribution but we do it anyway
60593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float					mU		= n1*n2 / 2.0f;
60613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float					sigmaU	= deFloatSqrt((n1*n2*(n1+n2+1)) / 12.0f);
60623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float					z		= (U - mU) / sigmaU;
60633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DistributionCompareResult	result;
60653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.equal				= (de::abs(z) <= 1.96f); // accept within 95% confidence interval
60673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		result.standardDeviations	= z;
60683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return result;
60703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
60713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
60723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T>
60743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ThresholdComparer
60753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
60763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	float	relativeThreshold;
60773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	T		absoluteThreshold;
60783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool operator() (const T& a, const T& b) const
60803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
60813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const float diff = de::abs((float)a - (float)b);
60823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// thresholds
60843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (diff <= (float)absoluteThreshold)
60853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return false;
60863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (diff <= a*relativeThreshold ||
60873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			diff <= b*relativeThreshold)
60883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return false;
60893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// cmp
60913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return a < b;
60923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
60933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
60943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
60953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryint UploadWaitDrawCase::findStabilizationSample (deUint64 (UploadWaitDrawCase::Result::*target), const char* description)
60963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
60973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<std::vector<deUint64> >	sampleObservations(m_numMaxSwaps+1);
60983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ThresholdComparer<deUint64>			comparer;
60993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	comparer.relativeThreshold = 0.15f;	// 15%
61013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	comparer.absoluteThreshold = 100;	// (us), assumed sampling precision
61023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// get observations and order them
61043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int swapNdx = 0; swapNdx <= m_numMaxSwaps; ++swapNdx)
61063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
61073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int insertNdx = 0;
61083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		sampleObservations[swapNdx].resize(m_numSamplesPerSwap);
61103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < (int)m_samples.size(); ++ndx)
61123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_samples[ndx].numFrames == swapNdx)
61133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				sampleObservations[swapNdx][insertNdx++] = m_results[ndx].*target;
61143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_ASSERT(insertNdx == m_numSamplesPerSwap);
61163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::sort(sampleObservations[swapNdx].begin(), sampleObservations[swapNdx].end());
61183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
61193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// find stabilization point
61213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int sampleNdx = m_numMaxSwaps-1; sampleNdx != -1; --sampleNdx )
61233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
61243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Distribution is equal to all following distributions
61253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int cmpTargetDistribution = sampleNdx+1; cmpTargetDistribution <= m_numMaxSwaps; ++cmpTargetDistribution)
61263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
61273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Stable section ends here?
61283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const DistributionCompareResult result = distributionCompare(sampleObservations[sampleNdx], sampleObservations[cmpTargetDistribution], comparer);
61293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!result.equal)
61303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
61313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Last two samples are not equal? Samples never stabilized
61323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (sampleNdx == m_numMaxSwaps-1)
61333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
61343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_testCtx.getLog()
61353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< tcu::TestLog::Message
61363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< description << ": Samples with swap count " << sampleNdx << " and " << cmpTargetDistribution << " do not seem to have the same distribution:\n"
61373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< "\tDifference in standard deviations: " << result.standardDeviations << "\n"
61383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< "\tSwap count " << sampleNdx << " median: " << linearSample(sampleObservations[sampleNdx], 0.5f) << "\n"
61393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< "\tSwap count " << cmpTargetDistribution << " median: " << linearSample(sampleObservations[cmpTargetDistribution], 0.5f) << "\n"
61403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< tcu::TestLog::EndMessage;
61413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					return -1;
61423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
61433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				else
61443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
61453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_testCtx.getLog()
61463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< tcu::TestLog::Message
61473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< description << ": Samples with swap count " << sampleNdx << " and " << cmpTargetDistribution << " do not seem to have the same distribution:\n"
61483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< "\tSamples with swap count " << sampleNdx << " are not part of the tail of stable results.\n"
61493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< "\tDifference in standard deviations: " << result.standardDeviations << "\n"
61503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< "\tSwap count " << sampleNdx << " median: " << linearSample(sampleObservations[sampleNdx], 0.5f) << "\n"
61513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< "\tSwap count " << cmpTargetDistribution << " median: " << linearSample(sampleObservations[cmpTargetDistribution], 0.5f) << "\n"
61523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						<< tcu::TestLog::EndMessage;
61533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					return sampleNdx+1;
61553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
61563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
61573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
61583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
61593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx.getLog()
61613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::Message
61623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< description << ": All samples seem to have the same distribution"
61633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		<< tcu::TestLog::EndMessage;
61643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// all distributions equal
61663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return 0;
61673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
61683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool UploadWaitDrawCase::checkSampleTemporalStability (deUint64 (UploadWaitDrawCase::Result::*target), const char* description)
61703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
61713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Try to find correlation with sample order and sample times
61723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61738852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	const int						numDataPoints	= (int)m_iterationOrder.size();
61748852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	std::vector<tcu::Vec2>			dataPoints		(m_iterationOrder.size());
61758852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	LineParametersWithConfidence	lineFit;
61763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < (int)m_iterationOrder.size(); ++ndx)
61783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
61793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dataPoints[m_iterationOrder[ndx]].x() = (float)ndx;
61803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		dataPoints[m_iterationOrder[ndx]].y() = (float)(m_results[m_iterationOrder[ndx]].*target);
61813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
61823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61838852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	lineFit = theilSenSiegelLinearRegression(dataPoints, 0.6f);
61843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Difference of more than 25% of the offset along the whole sample range
61863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (de::abs(lineFit.coefficient) * numDataPoints > de::abs(lineFit.offset) * 0.25f)
61873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
61883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog()
61893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::Message
61903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< description << ": Correlation with data point observation order and result time. Results are not temporally stable, observations are not independent.\n"
61913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "\tCoefficient: " << lineFit.coefficient << " (us / observation)\n"
61923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< tcu::TestLog::EndMessage;
61933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
61943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return false;
61953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
61963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
61973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return true;
61983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
61993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
62013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62023c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferDataUploadTests::BufferDataUploadTests (Context& context)
62033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(context, "data_upload", "Buffer data upload performance tests")
62043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
62053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
62063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBufferDataUploadTests::~BufferDataUploadTests (void)
62083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
62093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
62103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BufferDataUploadTests::init (void)
62123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
62133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct BufferUsage
62143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
62153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char* name;
62163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		deUint32	usage;
62173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		bool		primaryUsage;
62183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} bufferUsages[] =
62193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
62203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "stream_draw",	GL_STREAM_DRAW,		true	},
62213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "stream_read",	GL_STREAM_READ,		false	},
62223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "stream_copy",	GL_STREAM_COPY,		false	},
62233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "static_draw",	GL_STATIC_DRAW,		true	},
62243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "static_read",	GL_STATIC_READ,		false	},
62253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "static_copy",	GL_STATIC_COPY,		false	},
62263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "dynamic_draw",	GL_DYNAMIC_DRAW,	true	},
62273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "dynamic_read",	GL_DYNAMIC_READ,	false	},
62283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "dynamic_copy",	GL_DYNAMIC_COPY,	false	},
62293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
62303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const referenceGroup			= new tcu::TestCaseGroup(m_testCtx, "reference",			"Reference functions");
62323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const functionCallGroup			= new tcu::TestCaseGroup(m_testCtx, "function_call",		"Function call timing");
62333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const modifyAfterUseGroup		= new tcu::TestCaseGroup(m_testCtx, "modify_after_use",		"Function call time after buffer has been used");
62343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestCaseGroup* const renderAfterUploadGroup	= new tcu::TestCaseGroup(m_testCtx, "render_after_upload",	"Function call time of draw commands after buffer has been modified");
62353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(referenceGroup);
62373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(functionCallGroup);
62383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(modifyAfterUseGroup);
62393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(renderAfterUploadGroup);
62403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .reference
62423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
62433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const struct BufferSizeRange
62443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
62453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const char* name;
62463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int			minBufferSize;
62473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int			maxBufferSize;
62483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			int			numSamples;
62493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			bool		largeBuffersCase;
62503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		} sizeRanges[] =
62513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
62523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "small_buffers", 0,		1 << 18,	64,		false	}, // !< 0kB - 256kB
62533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "large_buffers", 1 << 18,	1 << 24,	32,		true	}, // !< 256kB - 16MB
62543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
62553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int bufferSizeRangeNdx = 0; bufferSizeRangeNdx < DE_LENGTH_OF_ARRAY(sizeRanges); ++bufferSizeRangeNdx)
62573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
62583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			referenceGroup->addChild(new ReferenceMemcpyCase(m_context,
62593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 std::string("memcpy_").append(sizeRanges[bufferSizeRangeNdx].name).c_str(),
62603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 "Test memcpy performance",
62613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 sizeRanges[bufferSizeRangeNdx].minBufferSize,
62623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 sizeRanges[bufferSizeRangeNdx].maxBufferSize,
62633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 sizeRanges[bufferSizeRangeNdx].numSamples,
62643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry															 sizeRanges[bufferSizeRangeNdx].largeBuffersCase));
62653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
62663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
62673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .function_call
62693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
62703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int minBufferSize		= 0;		// !< 0kiB
62713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int maxBufferSize		= 1 << 24;	// !< 16MiB
62723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int numDataSamples	= 25;
62733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int numMapSamples		= 25;
62743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* const bufferDataMethodGroup		= new tcu::TestCaseGroup(m_testCtx, "buffer_data", "Use glBufferData");
62763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* const bufferSubDataMethodGroup	= new tcu::TestCaseGroup(m_testCtx, "buffer_sub_data", "Use glBufferSubData");
62773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* const mapBufferRangeMethodGroup	= new tcu::TestCaseGroup(m_testCtx, "map_buffer_range", "Use glMapBufferRange");
62783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		functionCallGroup->addChild(bufferDataMethodGroup);
62803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		functionCallGroup->addChild(bufferSubDataMethodGroup);
62813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		functionCallGroup->addChild(mapBufferRangeMethodGroup);
62823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// .buffer_data
62843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
62853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct TargetCase
62863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
62873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::TestCaseGroup*				group;
62883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				BufferDataUploadCase::CaseType	caseType;
62893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool							allUsages;
62903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} targetCases[] =
62913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
62923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "new_buffer",				"Target new buffer"),							BufferDataUploadCase::CASE_NEW_BUFFER,			true	},
62933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "unspecified_buffer",		"Target new unspecified buffer"),				BufferDataUploadCase::CASE_UNSPECIFIED_BUFFER,	true	},
62943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "specified_buffer",			"Target new specified buffer"),					BufferDataUploadCase::CASE_SPECIFIED_BUFFER,	true	},
62953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "used_buffer",				"Target buffer that was used in draw"),			BufferDataUploadCase::CASE_USED_BUFFER,			true	},
62963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "larger_used_buffer",		"Target larger buffer that was used in draw"),	BufferDataUploadCase::CASE_USED_LARGER_BUFFER,	false	},
62973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
62983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
62993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targetCases); ++targetNdx)
63003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bufferDataMethodGroup->addChild(targetCases[targetNdx].group);
63023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
63033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int usageNdx = 0; usageNdx < DE_LENGTH_OF_ARRAY(bufferUsages); ++usageNdx)
63043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (bufferUsages[usageNdx].primaryUsage || targetCases[targetNdx].allUsages)
63053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						targetCases[targetNdx].group->addChild(new BufferDataUploadCase(m_context,
63063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						std::string("usage_").append(bufferUsages[usageNdx].name).c_str(),
63073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						std::string("Test with usage = ").append(bufferUsages[usageNdx].name).c_str(),
63083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						minBufferSize,
63093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						maxBufferSize,
63103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						numDataSamples,
63113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						bufferUsages[usageNdx].usage,
63123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						targetCases[targetNdx].caseType));
63133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
63143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
63153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
63163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// .buffer_sub_data
63173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
63183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct FlagCase
63193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::TestCaseGroup*					group;
63213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				BufferSubDataUploadCase::CaseType	parentCase;
63223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool								allUsages;
63233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				int									flags;
63243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} flagCases[] =
63253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "used_buffer_full_upload",					    ""),															BufferSubDataUploadCase::CASE_USED_BUFFER,	true,	BufferSubDataUploadCase::FLAG_FULL_UPLOAD															},
63273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "used_buffer_invalidate_before_full_upload",    "Clear buffer with bufferData(...,NULL) before sub data call"),	BufferSubDataUploadCase::CASE_USED_BUFFER,	false,	BufferSubDataUploadCase::FLAG_FULL_UPLOAD    | BufferSubDataUploadCase::FLAG_INVALIDATE_BEFORE_USE	},
63283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "used_buffer_partial_upload",                   ""),															BufferSubDataUploadCase::CASE_USED_BUFFER,	true,	BufferSubDataUploadCase::FLAG_PARTIAL_UPLOAD														},
63293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ new tcu::TestCaseGroup(m_testCtx, "used_buffer_invalidate_before_partial_upload", "Clear buffer with bufferData(...,NULL) before sub data call"),	BufferSubDataUploadCase::CASE_USED_BUFFER,	false,	BufferSubDataUploadCase::FLAG_PARTIAL_UPLOAD | BufferSubDataUploadCase::FLAG_INVALIDATE_BEFORE_USE	},
63303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
63313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
63323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int flagNdx = 0; flagNdx < DE_LENGTH_OF_ARRAY(flagCases); ++flagNdx)
63333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bufferSubDataMethodGroup->addChild(flagCases[flagNdx].group);
63353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
63363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int usageNdx = 0; usageNdx < DE_LENGTH_OF_ARRAY(bufferUsages); ++usageNdx)
63373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (bufferUsages[usageNdx].primaryUsage || flagCases[flagNdx].allUsages)
63383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							flagCases[flagNdx].group->addChild(new BufferSubDataUploadCase(m_context,
63393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						   std::string("usage_").append(bufferUsages[usageNdx].name).c_str(),
63403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						   std::string("Test with usage = ").append(bufferUsages[usageNdx].name).c_str(),
63413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						   minBufferSize,
63423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						   maxBufferSize,
63433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						   numDataSamples,
63443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						   bufferUsages[usageNdx].usage,
63453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						   flagCases[flagNdx].parentCase,
63463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																						   flagCases[flagNdx].flags));
63473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
63483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
63493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
63503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// .map_buffer_range
63513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
63523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct FlagCase
63533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*	name;
63553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool		usefulForUnusedBuffers;
63563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool		allUsages;
63573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				int			glFlags;
63583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				int			caseFlags;
63593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} flagCases[] =
63603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_write_full",										true,	true,	GL_MAP_WRITE_BIT,																0																				},
63623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_write_partial",										true,	true,	GL_MAP_WRITE_BIT,																MapBufferRangeCase::FLAG_PARTIAL												},
63633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_read_write_full",									true,	true,	GL_MAP_WRITE_BIT | GL_MAP_READ_BIT,												0																				},
63643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_read_write_partial",								true,	true,	GL_MAP_WRITE_BIT | GL_MAP_READ_BIT,												MapBufferRangeCase::FLAG_PARTIAL												},
63653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_invalidate_range_full",								true,	false,	GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT,									0																				},
63663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_invalidate_range_partial",							true,	false,	GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT,									MapBufferRangeCase::FLAG_PARTIAL												},
63673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_invalidate_buffer_full",							true,	false,	GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT,								0																				},
63683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_invalidate_buffer_partial",							true,	false,	GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT,								MapBufferRangeCase::FLAG_PARTIAL												},
63693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_write_full_manual_invalidate_buffer",				false,	false,	GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT,									MapBufferRangeCase::FLAG_MANUAL_INVALIDATION									},
63703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_write_partial_manual_invalidate_buffer",			false,	false,	GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT,									MapBufferRangeCase::FLAG_PARTIAL | MapBufferRangeCase::FLAG_MANUAL_INVALIDATION	},
63713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_unsynchronized_full",								true,	false,	GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT,									0																				},
63723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_unsynchronized_partial",							true,	false,	GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT,									MapBufferRangeCase::FLAG_PARTIAL												},
63733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_unsynchronized_and_invalidate_buffer_full",			true,	false,	GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_INVALIDATE_BUFFER_BIT,	0																				},
63743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_unsynchronized_and_invalidate_buffer_partial",		true,	false,	GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_INVALIDATE_BUFFER_BIT,	MapBufferRangeCase::FLAG_PARTIAL												},
63753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
63763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct FlushCases
63773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*	name;
63793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				int			glFlags;
63803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				int			caseFlags;
63813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} flushCases[] =
63823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_flush_explicit_map_full",					GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT,	0												},
63843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_flush_explicit_map_partial",				GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT,	MapBufferRangeFlushCase::FLAG_PARTIAL			},
63853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_flush_explicit_map_full_flush_in_parts",	GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT,	MapBufferRangeFlushCase::FLAG_FLUSH_IN_PARTS	},
63863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "flag_flush_explicit_map_full_flush_partial",		GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT,	MapBufferRangeFlushCase::FLAG_FLUSH_PARTIAL		},
63873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
63883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct MapTestGroup
63893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				int					flags;
63913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool				unusedBufferCase;
63923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::TestCaseGroup* group;
63933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} groups[] =
63943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
63953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ MapBufferRangeCase::FLAG_USE_UNUSED_UNSPECIFIED_BUFFER,	true,	new tcu::TestCaseGroup(m_testCtx, "new_unspecified_buffer", "Test with unused, unspecified buffers"),				},
63963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ MapBufferRangeCase::FLAG_USE_UNUSED_SPECIFIED_BUFFER,		true,	new tcu::TestCaseGroup(m_testCtx, "new_specified_buffer", "Test with unused, specified buffers"),					},
63973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ 0,														false,	new tcu::TestCaseGroup(m_testCtx, "used_buffer", "Test with used (data has been sourced from a buffer) buffers")	},
63983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
63993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// we OR same flags to both range and flushRange cases, make sure it is legal
64013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_STATIC_ASSERT((int)MapBufferRangeCase::FLAG_USE_UNUSED_SPECIFIED_BUFFER == (int)MapBufferRangeFlushCase::FLAG_USE_UNUSED_SPECIFIED_BUFFER);
64023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_STATIC_ASSERT((int)MapBufferRangeCase::FLAG_USE_UNUSED_UNSPECIFIED_BUFFER == (int)MapBufferRangeFlushCase::FLAG_USE_UNUSED_UNSPECIFIED_BUFFER);
64033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int groupNdx = 0; groupNdx < DE_LENGTH_OF_ARRAY(groups); ++groupNdx)
64053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
64063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::TestCaseGroup* const bufferTypeGroup = groups[groupNdx].group;
64073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				mapBufferRangeMethodGroup->addChild(bufferTypeGroup);
64093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(flagCases); ++caseNdx)
64113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
64123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (groups[groupNdx].unusedBufferCase && !flagCases[caseNdx].usefulForUnusedBuffers)
64133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						continue;
64143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					tcu::TestCaseGroup* const bufferUsageGroup = new tcu::TestCaseGroup(m_testCtx, flagCases[caseNdx].name, "");
64163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					bufferTypeGroup->addChild(bufferUsageGroup);
64173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					for (int usageNdx = 0; usageNdx < DE_LENGTH_OF_ARRAY(bufferUsages); ++usageNdx)
64193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						if (bufferUsages[usageNdx].primaryUsage || flagCases[caseNdx].allUsages)
64203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							bufferUsageGroup->addChild(new MapBufferRangeCase(m_context,
64213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			  bufferUsages[usageNdx].name,
64223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			  std::string("Test with usage = ").append(bufferUsages[usageNdx].name).c_str(),
64233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			  minBufferSize,
64243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			  maxBufferSize,
64253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			  numMapSamples,
64263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			  bufferUsages[usageNdx].usage,
64273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			  flagCases[caseNdx].glFlags,
64283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			  flagCases[caseNdx].caseFlags | groups[groupNdx].flags));
64293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
64303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(flushCases); ++caseNdx)
64323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
64333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					tcu::TestCaseGroup* const bufferUsageGroup = new tcu::TestCaseGroup(m_testCtx, flushCases[caseNdx].name, "");
64343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					bufferTypeGroup->addChild(bufferUsageGroup);
64353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					for (int usageNdx = 0; usageNdx < DE_LENGTH_OF_ARRAY(bufferUsages); ++usageNdx)
64373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						if (bufferUsages[usageNdx].primaryUsage)
64383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							bufferUsageGroup->addChild(new MapBufferRangeFlushCase(m_context,
64393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				   bufferUsages[usageNdx].name,
64403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				   std::string("Test with usage = ").append(bufferUsages[usageNdx].name).c_str(),
64413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				   minBufferSize,
64423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				   maxBufferSize,
64433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				   numMapSamples,
64443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				   bufferUsages[usageNdx].usage,
64453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				   flushCases[caseNdx].glFlags,
64463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				   flushCases[caseNdx].caseFlags | groups[groupNdx].flags));
64473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
64483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
64493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
64503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
64513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .modify_after_use
64533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
64543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int minBufferSize	= 0;		// !< 0kiB
64553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const int maxBufferSize	= 1 << 24;	// !< 16MiB
64563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const struct Usage
64583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
64593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const char* name;
64603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const char* description;
64613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			deUint32	usage;
64623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		} usages[] =
64633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
64643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "static_draw",	"Test with GL_STATIC_DRAW",		GL_STATIC_DRAW	},
64653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "dynamic_draw",	"Test with GL_DYNAMIC_DRAW",	GL_DYNAMIC_DRAW	},
64663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ "stream_draw",	"Test with GL_STREAM_DRAW",		GL_STREAM_DRAW },
64673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
64693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int usageNdx = 0; usageNdx < DE_LENGTH_OF_ARRAY(usages); ++usageNdx)
64713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
64723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::TestCaseGroup* const usageGroup = new tcu::TestCaseGroup(m_testCtx, usages[usageNdx].name, usages[usageNdx].description);
64733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			modifyAfterUseGroup->addChild(usageGroup);
64743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithBufferDataCase		(m_context, "buffer_data",							"Respecify buffer contents after use",					minBufferSize, maxBufferSize, usages[usageNdx].usage, 0));
64763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithBufferDataCase		(m_context, "buffer_data_different_size",			"Respecify buffer contents and size after use",			minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithBufferDataCase::FLAG_RESPECIFY_SIZE));
64773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithBufferDataCase		(m_context, "buffer_data_repeated",					"Respecify buffer contents after upload and use",		minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithBufferDataCase::FLAG_UPLOAD_REPEATED));
64783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithBufferSubDataCase	(m_context, "buffer_sub_data_full",					"Respecify buffer contents after use",					minBufferSize, maxBufferSize, usages[usageNdx].usage, 0));
64803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithBufferSubDataCase	(m_context, "buffer_sub_data_partial",				"Respecify buffer contents partially use",				minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithBufferSubDataCase::FLAG_PARTIAL));
64813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithBufferSubDataCase	(m_context, "buffer_sub_data_full_repeated",		"Respecify buffer contents after upload and use",		minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithBufferSubDataCase::FLAG_UPLOAD_REPEATED));
64823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithBufferSubDataCase	(m_context, "buffer_sub_data_partial_repeated",		"Respecify buffer contents partially upload and use",	minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithBufferSubDataCase::FLAG_UPLOAD_REPEATED | ModifyAfterWithBufferSubDataCase::FLAG_PARTIAL));
64833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_write_full",					"Respecify buffer contents after use",					minBufferSize, maxBufferSize, usages[usageNdx].usage, 0,												GL_MAP_WRITE_BIT));
64853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_write_partial",				"Respecify buffer contents partially after use",		minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithMapBufferRangeCase::FLAG_PARTIAL,	GL_MAP_WRITE_BIT));
64863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_read_write_full",				"Respecify buffer contents after use",					minBufferSize, maxBufferSize, usages[usageNdx].usage, 0,												GL_MAP_READ_BIT | GL_MAP_WRITE_BIT));
64873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_read_write_partial",			"Respecify buffer contents partially after use",		minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithMapBufferRangeCase::FLAG_PARTIAL,	GL_MAP_READ_BIT | GL_MAP_WRITE_BIT));
64883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_invalidate_range_full",		"Respecify buffer contents after use",					minBufferSize, maxBufferSize, usages[usageNdx].usage, 0,												GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT));
64893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_invalidate_range_partial",	"Respecify buffer contents partially after use",		minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithMapBufferRangeCase::FLAG_PARTIAL,	GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT));
64903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_invalidate_buffer_full",		"Respecify buffer contents after use",					minBufferSize, maxBufferSize, usages[usageNdx].usage, 0,												GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));
64913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_invalidate_buffer_partial",	"Respecify buffer contents partially after use",		minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithMapBufferRangeCase::FLAG_PARTIAL,	GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));
64923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_unsynchronized_full",			"Respecify buffer contents after use",					minBufferSize, maxBufferSize, usages[usageNdx].usage, 0,												GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT));
64933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferRangeCase	(m_context, "map_flag_unsynchronized_partial",		"Respecify buffer contents partially after use",		minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithMapBufferRangeCase::FLAG_PARTIAL,	GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT));
64943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
64953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferFlushCase	(m_context, "map_flag_flush_explicit_full",			"Respecify buffer contents after use",					minBufferSize, maxBufferSize, usages[usageNdx].usage, 0,												GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT));
64963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			usageGroup->addChild(new ModifyAfterWithMapBufferFlushCase	(m_context, "map_flag_flush_explicit_partial",		"Respecify buffer contents partially after use",		minBufferSize, maxBufferSize, usages[usageNdx].usage, ModifyAfterWithMapBufferFlushCase::FLAG_PARTIAL,	GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT));
64973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
64983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
64993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// .render_after_upload
65013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
65023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// .reference
65033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
65043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::TestCaseGroup* const renderReferenceGroup = new tcu::TestCaseGroup(m_testCtx, "reference", "Baseline results");
65053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			renderAfterUploadGroup->addChild(renderReferenceGroup);
65063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// .draw
65083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
65093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::TestCaseGroup* const drawGroup = new tcu::TestCaseGroup(m_testCtx, "draw", "Time usage of functions with non-modified buffers");
65103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				renderReferenceGroup->addChild(drawGroup);
65113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Time consumed by readPixels
65133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				drawGroup->addChild(new ReferenceReadPixelsTimeCase	(m_context, "read_pixels",		"Measure time consumed by readPixels() function call"));
65143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Time consumed by rendering
65163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				drawGroup->addChild(new ReferenceRenderTimeCase		(m_context, "draw_arrays",		"Measure time consumed by drawArrays() function call",		DRAWMETHOD_DRAW_ARRAYS));
65173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				drawGroup->addChild(new ReferenceRenderTimeCase		(m_context, "draw_elements",	"Measure time consumed by drawElements() function call",	DRAWMETHOD_DRAW_ELEMENTS));
65183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
65193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// .draw_upload_draw
65213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
65223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				static const struct
65233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
65243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*		name;
65253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*		description;
65263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DrawMethod		drawMethod;
65273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TargetBuffer	targetBuffer;
65283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					bool			partial;
65293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				} uploadTargets[] =
65303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
65313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
65323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_arrays_upload_vertices",
65333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by drawArrays, vertex attribute upload, another drawArrays, and readPixels function calls.",
65343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ARRAYS,
65353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_VERTEX,
65363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						false
65373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
65383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
65393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_arrays_upload_vertices_partial",
65403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by drawArrays, partial vertex attribute upload, another drawArrays, and readPixels function calls.",
65413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ARRAYS,
65423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_VERTEX,
65433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						true
65443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
65453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
65463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_elements_upload_vertices",
65473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by drawElements, vertex attribute upload, another drawElements, and readPixels function calls.",
65483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ELEMENTS,
65493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_VERTEX,
65503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						false
65513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
65523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
65533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_elements_upload_indices",
65543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by drawElements, index upload, another drawElements, and readPixels function calls.",
65553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ELEMENTS,
65563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_INDEX,
65573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						false
65583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
65593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
65603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_elements_upload_indices_partial",
65613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by drawElements, partial index upload, another drawElements, and readPixels function calls.",
65623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ELEMENTS,
65633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_INDEX,
65643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						true
65653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
65663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				};
65673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				static const struct
65683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
65693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*							name;
65703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*							description;
65713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					UploadMethod						uploadMethod;
65723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					BufferInUseRenderTimeCase::MapFlags	mapFlags;
65733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					bool								supportsPartialUpload;
65743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				} uploadMethods[] =
65753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
65763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{ "buffer_data",						"bufferData",		UPLOADMETHOD_BUFFER_DATA,		BufferInUseRenderTimeCase::MAPFLAG_NONE,				false	},
65773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{ "buffer_sub_data",					"bufferSubData",	UPLOADMETHOD_BUFFER_SUB_DATA,	BufferInUseRenderTimeCase::MAPFLAG_NONE,				true	},
65783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{ "map_buffer_range_invalidate_range",	"mapBufferRange",	UPLOADMETHOD_MAP_BUFFER_RANGE,	BufferInUseRenderTimeCase::MAPFLAG_INVALIDATE_RANGE,	true	},
65793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{ "map_buffer_range_invalidate_buffer",	"mapBufferRange",	UPLOADMETHOD_MAP_BUFFER_RANGE,	BufferInUseRenderTimeCase::MAPFLAG_INVALIDATE_BUFFER,	false	},
65803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				};
65813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::TestCaseGroup* const drawUploadDrawGroup = new tcu::TestCaseGroup(m_testCtx, "draw_upload_draw", "Time usage of functions draw, upload and another draw");
65833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				renderReferenceGroup->addChild(drawUploadDrawGroup);
65843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int uploadTargetNdx = 0; uploadTargetNdx < DE_LENGTH_OF_ARRAY(uploadTargets); ++uploadTargetNdx)
65863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int uploadMethodNdx = 0; uploadMethodNdx < DE_LENGTH_OF_ARRAY(uploadMethods); ++uploadMethodNdx)
65873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
65883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const std::string name = std::string() + uploadTargets[uploadTargetNdx].name + "_with_" + uploadMethods[uploadMethodNdx].name;
65893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (uploadTargets[uploadTargetNdx].partial && !uploadMethods[uploadMethodNdx].supportsPartialUpload)
65913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						continue;
65923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
65933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					drawUploadDrawGroup->addChild(new BufferInUseRenderTimeCase(m_context,
65943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				name.c_str(),
65953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				uploadTargets[uploadTargetNdx].description,
65963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				uploadTargets[uploadTargetNdx].drawMethod,
65973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				uploadMethods[uploadMethodNdx].mapFlags,
65983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				uploadTargets[uploadTargetNdx].targetBuffer,
65993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				uploadMethods[uploadMethodNdx].uploadMethod,
66003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				(uploadTargets[uploadTargetNdx].partial) ? (UPLOADRANGE_PARTIAL) : (UPLOADRANGE_FULL),
66013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																				BufferInUseRenderTimeCase::UPLOADBUFFERTARGET_DIFFERENT_BUFFER));
66023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
66033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
66043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
66053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// .upload_unrelated_and_draw
66073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
66083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
66093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
66103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		name;
66113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		description;
66123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DrawMethod		drawMethod;
66133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} drawMethods[] =
66143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
66153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "draw_arrays",	"drawArrays",	DRAWMETHOD_DRAW_ARRAYS		},
66163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "draw_elements",	"drawElements",	DRAWMETHOD_DRAW_ELEMENTS	},
66173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
66183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
66203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
66213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		name;
66223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				UploadMethod	uploadMethod;
66233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} uploadMethods[] =
66243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
66253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "buffer_data",		UPLOADMETHOD_BUFFER_DATA		},
66263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "buffer_sub_data",	UPLOADMETHOD_BUFFER_SUB_DATA	},
66273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "map_buffer_range",	UPLOADMETHOD_MAP_BUFFER_RANGE	},
66283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
66293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::TestCaseGroup* const uploadUnrelatedGroup = new tcu::TestCaseGroup(m_testCtx, "upload_unrelated_and_draw", "Time usage of functions after an unrelated upload");
66313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			renderAfterUploadGroup->addChild(uploadUnrelatedGroup);
66323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int drawMethodNdx = 0; drawMethodNdx < DE_LENGTH_OF_ARRAY(drawMethods); ++drawMethodNdx)
66343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int uploadMethodNdx = 0; uploadMethodNdx < DE_LENGTH_OF_ARRAY(uploadMethods); ++uploadMethodNdx)
66353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
66363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const std::string name = std::string() + drawMethods[drawMethodNdx].name + "_upload_unrelated_with_" + uploadMethods[uploadMethodNdx].name;
66373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const std::string desc = std::string() + "Measure time consumed by " + drawMethods[drawMethodNdx].description + " function call after an unrelated upload";
66383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				// Time consumed by rendering command after an unrelated upload
66403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				uploadUnrelatedGroup->addChild(new UnrelatedUploadRenderTimeCase(m_context, name.c_str(), desc.c_str(), drawMethods[drawMethodNdx].drawMethod, uploadMethods[uploadMethodNdx].uploadMethod));
66423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
66433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
66443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// .upload_and_draw
66463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
66473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
66483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
66493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*			name;
66503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*			description;
66513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				BufferState			bufferState;
66523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				UnrelatedBufferType	unrelatedBuffer;
66533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool				supportsPartialUpload;
66543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} bufferConfigs[] =
66553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
66563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "used_buffer",						"Upload to an used buffer",											BUFFERSTATE_EXISTING,	UNRELATEDBUFFERTYPE_NONE,	true	},
66573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "new_buffer",							"Upload to a new buffer",											BUFFERSTATE_NEW,		UNRELATEDBUFFERTYPE_NONE,	false	},
66583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "used_buffer_and_unrelated_upload",	"Upload to an used buffer and an unrelated buffer and then draw",	BUFFERSTATE_EXISTING,	UNRELATEDBUFFERTYPE_VERTEX,	true	},
66593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "new_buffer_and_unrelated_upload",	"Upload to a new buffer and an unrelated buffer and then draw",		BUFFERSTATE_NEW,		UNRELATEDBUFFERTYPE_VERTEX,	false	},
66603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
66613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::TestCaseGroup* const uploadAndDrawGroup = new tcu::TestCaseGroup(m_testCtx, "upload_and_draw", "Time usage of rendering functions with modified buffers");
66633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			renderAfterUploadGroup->addChild(uploadAndDrawGroup);
66643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
66653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// .used_buffer
66663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// .new_buffer
66673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// .used_buffer_and_unrelated_upload
66683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// .new_buffer_and_unrelated_upload
66693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int stateNdx = 0; stateNdx < DE_LENGTH_OF_ARRAY(bufferConfigs); ++stateNdx)
66703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
66713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				static const struct
66723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
66733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*		name;
66743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*		description;
66753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DrawMethod		drawMethod;
66763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TargetBuffer	targetBuffer;
66773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					bool			partial;
66783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				} uploadTargets[] =
66793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
66803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
66813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_arrays_upload_vertices",
66823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by vertex attribute upload, drawArrays, and readPixels function calls",
66833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ARRAYS,
66843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_VERTEX,
66853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						false
66863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
66873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
66883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_arrays_upload_vertices_partial",
66893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by partial vertex attribute upload, drawArrays, and readPixels function calls",
66903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ARRAYS,
66913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_VERTEX,
66923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						true
66933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
66943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
66953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_elements_upload_vertices",
66963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by vertex attribute upload, drawElements, and readPixels function calls",
66973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ELEMENTS,
66983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_VERTEX,
66993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						false
67003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
67013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
67023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_elements_upload_indices",
67033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by index upload, drawElements, and readPixels function calls",
67043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ELEMENTS,
67053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_INDEX,
67063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						false
67073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
67083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
67093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"draw_elements_upload_indices_partial",
67103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						"Measure time consumed by partial index upload, drawElements, and readPixels function calls",
67113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						DRAWMETHOD_DRAW_ELEMENTS,
67123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						TARGETBUFFER_INDEX,
67133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						true
67143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					},
67153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				};
67163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				static const struct
67173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
67183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*		name;
67193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const char*		description;
67203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					UploadMethod	uploadMethod;
67213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					bool			supportsPartialUpload;
67223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				} uploadMethods[] =
67233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
67243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{ "buffer_data",		"bufferData",		UPLOADMETHOD_BUFFER_DATA,		false	},
67253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{ "buffer_sub_data",	"bufferSubData",	UPLOADMETHOD_BUFFER_SUB_DATA,	true	},
67263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{ "map_buffer_range",	"mapBufferRange",	UPLOADMETHOD_MAP_BUFFER_RANGE,	true	},
67273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				};
67283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, bufferConfigs[stateNdx].name, bufferConfigs[stateNdx].description);
67303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				uploadAndDrawGroup->addChild(group);
67313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int uploadTargetNdx = 0; uploadTargetNdx < DE_LENGTH_OF_ARRAY(uploadTargets); ++uploadTargetNdx)
67333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int uploadMethodNdx = 0; uploadMethodNdx < DE_LENGTH_OF_ARRAY(uploadMethods); ++uploadMethodNdx)
67343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
67353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const std::string name = std::string() + uploadTargets[uploadTargetNdx].name + "_with_" + uploadMethods[uploadMethodNdx].name;
67363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (uploadTargets[uploadTargetNdx].partial && !uploadMethods[uploadMethodNdx].supportsPartialUpload)
67383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						continue;
67393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (uploadTargets[uploadTargetNdx].partial && !bufferConfigs[stateNdx].supportsPartialUpload)
67403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						continue;
67413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					// Don't log unrelated buffer information to samples if there is no such buffer
67433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					if (bufferConfigs[stateNdx].unrelatedBuffer == UNRELATEDBUFFERTYPE_NONE)
67453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
67463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						typedef UploadRenderReadDuration				SampleType;
67473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						typedef GenericUploadRenderTimeCase<SampleType>	TestType;
67483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						group->addChild(new TestType(m_context,
67503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 name.c_str(),
67513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 uploadTargets[uploadTargetNdx].description,
67523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 uploadTargets[uploadTargetNdx].drawMethod,
67533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 uploadTargets[uploadTargetNdx].targetBuffer,
67543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 uploadMethods[uploadMethodNdx].uploadMethod,
67553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 bufferConfigs[stateNdx].bufferState,
67563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 (uploadTargets[uploadTargetNdx].partial) ? (UPLOADRANGE_PARTIAL) : (UPLOADRANGE_FULL),
67573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 bufferConfigs[stateNdx].unrelatedBuffer));
67583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
67593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					else
67603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					{
67613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						typedef UploadRenderReadDurationWithUnrelatedUploadSize	SampleType;
67623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						typedef GenericUploadRenderTimeCase<SampleType>			TestType;
67633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						group->addChild(new TestType(m_context,
67653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 name.c_str(),
67663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 uploadTargets[uploadTargetNdx].description,
67673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 uploadTargets[uploadTargetNdx].drawMethod,
67683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 uploadTargets[uploadTargetNdx].targetBuffer,
67693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 uploadMethods[uploadMethodNdx].uploadMethod,
67703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 bufferConfigs[stateNdx].bufferState,
67713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 (uploadTargets[uploadTargetNdx].partial) ? (UPLOADRANGE_PARTIAL) : (UPLOADRANGE_FULL),
67723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry													 bufferConfigs[stateNdx].unrelatedBuffer));
67733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					}
67743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
67753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
67763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
67773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
67783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// .draw_modify_draw
67793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
67803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
67813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
67823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		name;
67833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		description;
67843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DrawMethod		drawMethod;
67853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				TargetBuffer	targetBuffer;
67863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool			partial;
67873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} uploadTargets[] =
67883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
67893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
67903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"draw_arrays_upload_vertices",
67913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"Measure time consumed by drawArrays, vertex attribute upload, another drawArrays, and readPixels function calls.",
67923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DRAWMETHOD_DRAW_ARRAYS,
67933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TARGETBUFFER_VERTEX,
67943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					false
67953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				},
67963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
67973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"draw_arrays_upload_vertices_partial",
67983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"Measure time consumed by drawArrays, partial vertex attribute upload, another drawArrays, and readPixels function calls.",
67993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DRAWMETHOD_DRAW_ARRAYS,
68003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TARGETBUFFER_VERTEX,
68013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					true
68023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				},
68033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
68043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"draw_elements_upload_vertices",
68053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"Measure time consumed by drawElements, vertex attribute upload, another drawElements, and readPixels function calls.",
68063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DRAWMETHOD_DRAW_ELEMENTS,
68073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TARGETBUFFER_VERTEX,
68083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					false
68093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				},
68103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
68113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"draw_elements_upload_indices",
68123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"Measure time consumed by drawElements, index upload, another drawElements, and readPixels function calls.",
68133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DRAWMETHOD_DRAW_ELEMENTS,
68143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TARGETBUFFER_INDEX,
68153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					false
68163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				},
68173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
68183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"draw_elements_upload_indices_partial",
68193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					"Measure time consumed by drawElements, partial index upload, another drawElements, and readPixels function calls.",
68203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					DRAWMETHOD_DRAW_ELEMENTS,
68213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TARGETBUFFER_INDEX,
68223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					true
68233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				},
68243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
68253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
68263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*							name;
68283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*							description;
68293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				UploadMethod						uploadMethod;
68303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				BufferInUseRenderTimeCase::MapFlags	mapFlags;
68313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				bool								supportsPartialUpload;
68323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} uploadMethods[] =
68333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "buffer_data",						"bufferData",		UPLOADMETHOD_BUFFER_DATA,		BufferInUseRenderTimeCase::MAPFLAG_NONE,				false	},
68353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "buffer_sub_data",					"bufferSubData",	UPLOADMETHOD_BUFFER_SUB_DATA,	BufferInUseRenderTimeCase::MAPFLAG_NONE,				true	},
68363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "map_buffer_range_invalidate_range",	"mapBufferRange",	UPLOADMETHOD_MAP_BUFFER_RANGE,	BufferInUseRenderTimeCase::MAPFLAG_INVALIDATE_RANGE,	true	},
68373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "map_buffer_range_invalidate_buffer",	"mapBufferRange",	UPLOADMETHOD_MAP_BUFFER_RANGE,	BufferInUseRenderTimeCase::MAPFLAG_INVALIDATE_BUFFER,	false	},
68383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
68393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
68403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::TestCaseGroup* const drawModifyDrawGroup = new tcu::TestCaseGroup(m_testCtx, "draw_modify_draw", "Time used in rendering functions with modified buffers while original buffer is still in use");
68413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			renderAfterUploadGroup->addChild(drawModifyDrawGroup);
68423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
68433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int uploadTargetNdx = 0; uploadTargetNdx < DE_LENGTH_OF_ARRAY(uploadTargets); ++uploadTargetNdx)
68443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int uploadMethodNdx = 0; uploadMethodNdx < DE_LENGTH_OF_ARRAY(uploadMethods); ++uploadMethodNdx)
68453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const std::string name = std::string() + uploadTargets[uploadTargetNdx].name + "_with_" + uploadMethods[uploadMethodNdx].name;
68473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
68483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (uploadTargets[uploadTargetNdx].partial && !uploadMethods[uploadMethodNdx].supportsPartialUpload)
68493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					continue;
68503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
68513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				drawModifyDrawGroup->addChild(new BufferInUseRenderTimeCase(m_context,
68523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			name.c_str(),
68533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			uploadTargets[uploadTargetNdx].description,
68543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			uploadTargets[uploadTargetNdx].drawMethod,
68553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			uploadMethods[uploadMethodNdx].mapFlags,
68563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			uploadTargets[uploadTargetNdx].targetBuffer,
68573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			uploadMethods[uploadMethodNdx].uploadMethod,
68583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			(uploadTargets[uploadTargetNdx].partial) ? (UPLOADRANGE_PARTIAL) : (UPLOADRANGE_FULL),
68593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																			BufferInUseRenderTimeCase::UPLOADBUFFERTARGET_SAME_BUFFER));
68603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
68613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
68623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
68633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// .upload_wait_draw
68643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
68653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
68663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*	name;
68683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*	description;
68693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				BufferState	bufferState;
68703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} bufferStates[] =
68713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "new_buffer",		"Uploading to just generated name",	BUFFERSTATE_NEW			},
68733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "used_buffer",	"Uploading to a used buffer",		BUFFERSTATE_EXISTING	},
68743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
68753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
68763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		name;
68783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		description;
68793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				DrawMethod		drawMethod;
68803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				TargetBuffer	targetBuffer;
68813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} uploadTargets[] =
68823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "draw_arrays_vertices",	"Upload vertex data, draw with drawArrays",		DRAWMETHOD_DRAW_ARRAYS,		TARGETBUFFER_VERTEX	},
68843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "draw_elements_vertices",	"Upload vertex data, draw with drawElements",	DRAWMETHOD_DRAW_ELEMENTS,	TARGETBUFFER_VERTEX	},
68853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "draw_elements_indices",	"Upload index data, draw with drawElements",	DRAWMETHOD_DRAW_ELEMENTS,	TARGETBUFFER_INDEX	},
68863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
68873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			static const struct
68883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		name;
68903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				const char*		description;
68913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				UploadMethod	uploadMethod;
68923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			} uploadMethods[] =
68933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
68943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "buffer_data",		"bufferData",		UPLOADMETHOD_BUFFER_DATA		},
68953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "buffer_sub_data",	"bufferSubData",	UPLOADMETHOD_BUFFER_SUB_DATA	},
68963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{ "map_buffer_range",	"mapBufferRange",	UPLOADMETHOD_MAP_BUFFER_RANGE	},
68973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
68983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
68993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::TestCaseGroup* const uploadSwapDrawGroup = new tcu::TestCaseGroup(m_testCtx, "upload_wait_draw", "Time used in rendering functions after a buffer upload N frames ago");
69003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			renderAfterUploadGroup->addChild(uploadSwapDrawGroup);
69013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
69023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			for (int bufferStateNdx = 0; bufferStateNdx < DE_LENGTH_OF_ARRAY(bufferStates); ++bufferStateNdx)
69033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
69043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				tcu::TestCaseGroup* const bufferGroup = new tcu::TestCaseGroup(m_testCtx, bufferStates[bufferStateNdx].name, bufferStates[bufferStateNdx].description);
69053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				uploadSwapDrawGroup->addChild(bufferGroup);
69063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
69073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int uploadTargetNdx = 0; uploadTargetNdx < DE_LENGTH_OF_ARRAY(uploadTargets); ++uploadTargetNdx)
69083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				for (int uploadMethodNdx = 0; uploadMethodNdx < DE_LENGTH_OF_ARRAY(uploadMethods); ++uploadMethodNdx)
69093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
69103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					const std::string name = std::string() + uploadTargets[uploadTargetNdx].name + "_with_" + uploadMethods[uploadMethodNdx].name;
69113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
69123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					bufferGroup->addChild(new UploadWaitDrawCase(m_context,
69133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																 name.c_str(),
69143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																 uploadTargets[uploadTargetNdx].description,
69153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																 uploadTargets[uploadTargetNdx].drawMethod,
69163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																 uploadTargets[uploadTargetNdx].targetBuffer,
69173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																 uploadMethods[uploadMethodNdx].uploadMethod,
69183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry																 bufferStates[bufferStateNdx].bufferState));
69193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
69203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
69213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
69223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
69233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
69243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
69253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Performance
69263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3
69273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
6928