Commit 9bd4dbef by Jamie Madill

Split ANGLEPerfTest into a Render and basic test.

The basic test we can use for perf testing internal classes with mocks. The render tests are more specific to doing draw calls. BUG=angleproject:956 Change-Id: Iade393facc30c8d7288b1b94a159ce3afe993021 Reviewed-on: https://chromium-review.googlesource.com/262775Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent fd1bf4e6
...@@ -11,7 +11,63 @@ ...@@ -11,7 +11,63 @@
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
std::string PerfTestParams::suffix() const ANGLEPerfTest::ANGLEPerfTest(const std::string &name, const std::string &suffix)
: mName(name),
mSuffix(suffix),
mRunning(false),
mNumFrames(0)
{
mTimer.reset(CreateTimer());
}
void ANGLEPerfTest::run()
{
mTimer->start();
double prevTime = 0.0;
while (mRunning)
{
double elapsedTime = mTimer->getElapsedTime();
double deltaTime = elapsedTime - prevTime;
++mNumFrames;
step(static_cast<float>(deltaTime), elapsedTime);
if (!mRunning)
{
break;
}
prevTime = elapsedTime;
}
}
void ANGLEPerfTest::printResult(const std::string &trace, double value, const std::string &units, bool important) const
{
perf_test::PrintResult(mName, mSuffix, trace, value, units, important);
}
void ANGLEPerfTest::printResult(const std::string &trace, size_t value, const std::string &units, bool important) const
{
perf_test::PrintResult(mName, mSuffix, trace, value, units, important);
}
void ANGLEPerfTest::SetUp()
{
mRunning = true;
}
void ANGLEPerfTest::TearDown()
{
double totalTime = mTimer->getElapsedTime();
double averageTime = 1000.0 * totalTime / static_cast<double>(mNumFrames);
printResult("total_time", totalTime, "s", true);
printResult("frames", static_cast<size_t>(mNumFrames), "frames", true);
printResult("average_time", averageTime, "ms", true);
}
std::string RenderTestParams::suffix() const
{ {
switch (requestedRenderer) switch (requestedRenderer)
{ {
...@@ -21,18 +77,15 @@ std::string PerfTestParams::suffix() const ...@@ -21,18 +77,15 @@ std::string PerfTestParams::suffix() const
} }
} }
ANGLEPerfTest::ANGLEPerfTest(const std::string &name, const PerfTestParams &testParams) ANGLERenderTest::ANGLERenderTest(const std::string &name, const RenderTestParams &testParams)
: mTestParams(testParams), : ANGLEPerfTest(name, testParams.suffix()),
mNumFrames(0), mTestParams(testParams),
mName(name),
mRunning(false),
mSuffix(testParams.suffix()),
mDrawIterations(10), mDrawIterations(10),
mRunTimeSeconds(5.0) mRunTimeSeconds(5.0)
{ {
} }
void ANGLEPerfTest::SetUp() void ANGLERenderTest::SetUp()
{ {
EGLPlatformParameters platformParams(mTestParams.requestedRenderer, EGLPlatformParameters platformParams(mTestParams.requestedRenderer,
EGL_DONT_CARE, EGL_DONT_CARE,
...@@ -44,7 +97,6 @@ void ANGLEPerfTest::SetUp() ...@@ -44,7 +97,6 @@ void ANGLEPerfTest::SetUp()
mTestParams.windowHeight, mTestParams.windowHeight,
mTestParams.glesMajorVersion, mTestParams.glesMajorVersion,
platformParams)); platformParams));
mTimer.reset(CreateTimer());
if (!mOSWindow->initialize(mName, mEGLWindow->getWidth(), mEGLWindow->getHeight())) if (!mOSWindow->initialize(mName, mEGLWindow->getWidth(), mEGLWindow->getHeight()))
{ {
...@@ -64,27 +116,12 @@ void ANGLEPerfTest::SetUp() ...@@ -64,27 +116,12 @@ void ANGLEPerfTest::SetUp()
return; return;
} }
mRunning = true; ANGLEPerfTest::SetUp();
} }
void ANGLEPerfTest::printResult(const std::string &trace, double value, const std::string &units, bool important) const void ANGLERenderTest::TearDown()
{ {
perf_test::PrintResult(mName, mSuffix, trace, value, units, important); ANGLEPerfTest::TearDown();
}
void ANGLEPerfTest::printResult(const std::string &trace, size_t value, const std::string &units, bool important) const
{
perf_test::PrintResult(mName, mSuffix, trace, value, units, important);
}
void ANGLEPerfTest::TearDown()
{
double totalTime = mTimer->getElapsedTime();
double averageTime = 1000.0 * totalTime / static_cast<double>(mNumFrames);
printResult("total_time", totalTime, "s", true);
printResult("frames", static_cast<size_t>(mNumFrames), "frames", true);
printResult("average_time", averageTime, "ms", true);
destroyBenchmark(); destroyBenchmark();
...@@ -92,14 +129,33 @@ void ANGLEPerfTest::TearDown() ...@@ -92,14 +129,33 @@ void ANGLEPerfTest::TearDown()
mOSWindow->destroy(); mOSWindow->destroy();
} }
void ANGLEPerfTest::step(float dt, double totalTime) void ANGLERenderTest::step(float dt, double totalTime)
{ {
stepBenchmark(dt, totalTime); stepBenchmark(dt, totalTime);
// Clear events that the application did not process from this frame
Event event;
while (popEvent(&event))
{
// If the application did not catch a close event, close now
if (event.Type == Event::EVENT_CLOSED)
{
mRunning = false;
}
}
if (mRunning)
{
draw();
mEGLWindow->swap();
mOSWindow->messageLoop();
}
} }
void ANGLEPerfTest::draw() void ANGLERenderTest::draw()
{ {
if (mTimer->getElapsedTime() > mRunTimeSeconds) { if (mTimer->getElapsedTime() > mRunTimeSeconds)
{
mRunning = false; mRunning = false;
return; return;
} }
...@@ -116,49 +172,12 @@ void ANGLEPerfTest::draw() ...@@ -116,49 +172,12 @@ void ANGLEPerfTest::draw()
endDrawBenchmark(); endDrawBenchmark();
} }
void ANGLEPerfTest::run() bool ANGLERenderTest::popEvent(Event *event)
{
mTimer->start();
double prevTime = 0.0;
while (mRunning)
{
double elapsedTime = mTimer->getElapsedTime();
double deltaTime = elapsedTime - prevTime;
step(static_cast<float>(deltaTime), elapsedTime);
// Clear events that the application did not process from this frame
Event event;
while (popEvent(&event))
{
// If the application did not catch a close event, close now
if (event.Type == Event::EVENT_CLOSED)
{
mRunning = false;
}
}
if (!mRunning)
{
break;
}
draw();
mEGLWindow->swap();
mOSWindow->messageLoop();
prevTime = elapsedTime;
}
}
bool ANGLEPerfTest::popEvent(Event *event)
{ {
return mOSWindow->popEvent(event); return mOSWindow->popEvent(event);
} }
OSWindow *ANGLEPerfTest::getWindow() OSWindow *ANGLERenderTest::getWindow()
{ {
return mOSWindow.get(); return mOSWindow.get();
} }
...@@ -24,23 +24,46 @@ ...@@ -24,23 +24,46 @@
class Event; class Event;
struct PerfTestParams class ANGLEPerfTest : public testing::Test
{ {
public:
ANGLEPerfTest(const std::string &name, const std::string &suffix);
virtual ~ANGLEPerfTest() { };
virtual void step(float dt, double totalTime) = 0;
DISALLOW_COPY_AND_ASSIGN(ANGLEPerfTest);
protected:
void run();
void printResult(const std::string &trace, double value, const std::string &units, bool important) const;
void printResult(const std::string &trace, size_t value, const std::string &units, bool important) const;
void SetUp() override;
void TearDown() override;
std::string mName;
std::string mSuffix;
bool mRunning;
std::unique_ptr<Timer> mTimer;
int mNumFrames;
};
struct RenderTestParams
{
virtual std::string suffix() const;
EGLint requestedRenderer; EGLint requestedRenderer;
EGLint deviceType; EGLint deviceType;
EGLint glesMajorVersion; EGLint glesMajorVersion;
EGLint widowWidth; EGLint widowWidth;
EGLint windowHeight; EGLint windowHeight;
virtual std::string suffix() const;
}; };
class ANGLEPerfTest : public testing::Test class ANGLERenderTest : public ANGLEPerfTest
{ {
public: public:
ANGLEPerfTest(const std::string &name, const PerfTestParams &testParams); ANGLERenderTest(const std::string &name, const RenderTestParams &testParams);
virtual ~ANGLEPerfTest() { };
virtual bool initializeBenchmark() { return true; } virtual bool initializeBenchmark() { return true; }
virtual void destroyBenchmark() { } virtual void destroyBenchmark() { }
...@@ -56,31 +79,21 @@ class ANGLEPerfTest : public testing::Test ...@@ -56,31 +79,21 @@ class ANGLEPerfTest : public testing::Test
OSWindow *getWindow(); OSWindow *getWindow();
protected: protected:
void printResult(const std::string &trace, double value, const std::string &units, bool important) const; const RenderTestParams &mTestParams;
void printResult(const std::string &trace, size_t value, const std::string &units, bool important) const;
void run();
const PerfTestParams &mTestParams;
unsigned int mDrawIterations; unsigned int mDrawIterations;
double mRunTimeSeconds; double mRunTimeSeconds;
int mNumFrames;
private: private:
DISALLOW_COPY_AND_ASSIGN(ANGLEPerfTest); DISALLOW_COPY_AND_ASSIGN(ANGLERenderTest);
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
void step(float dt, double totalTime); void step(float dt, double totalTime) override;
void draw(); void draw();
std::string mName;
bool mRunning;
std::string mSuffix;
std::unique_ptr<EGLWindow> mEGLWindow; std::unique_ptr<EGLWindow> mEGLWindow;
std::unique_ptr<OSWindow> mOSWindow; std::unique_ptr<OSWindow> mOSWindow;
std::unique_ptr<Timer> mTimer;
}; };
#endif // PERF_TESTS_ANGLE_PERF_TEST_H_ #endif // PERF_TESTS_ANGLE_PERF_TEST_H_
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
namespace namespace
{ {
struct BufferSubDataParams final : public PerfTestParams struct BufferSubDataParams final : public RenderTestParams
{ {
std::string suffix() const override; std::string suffix() const override;
...@@ -31,7 +31,7 @@ struct BufferSubDataParams final : public PerfTestParams ...@@ -31,7 +31,7 @@ struct BufferSubDataParams final : public PerfTestParams
unsigned int iterations; unsigned int iterations;
}; };
class BufferSubDataBenchmark : public ANGLEPerfTest, class BufferSubDataBenchmark : public ANGLERenderTest,
public ::testing::WithParamInterface<BufferSubDataParams> public ::testing::WithParamInterface<BufferSubDataParams>
{ {
public: public:
...@@ -165,7 +165,7 @@ std::string BufferSubDataParams::suffix() const ...@@ -165,7 +165,7 @@ std::string BufferSubDataParams::suffix() const
{ {
std::stringstream strstr; std::stringstream strstr;
strstr << PerfTestParams::suffix(); strstr << RenderTestParams::suffix();
if (vertexNormalized) if (vertexNormalized)
{ {
...@@ -191,7 +191,7 @@ std::string BufferSubDataParams::suffix() const ...@@ -191,7 +191,7 @@ std::string BufferSubDataParams::suffix() const
} }
BufferSubDataBenchmark::BufferSubDataBenchmark() BufferSubDataBenchmark::BufferSubDataBenchmark()
: ANGLEPerfTest("BufferSubData", GetParam()), : ANGLERenderTest("BufferSubData", GetParam()),
mProgram(0), mProgram(0),
mBuffer(0), mBuffer(0),
mUpdateData(NULL), mUpdateData(NULL),
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace namespace
{ {
struct PointSpritesParams final : public PerfTestParams struct PointSpritesParams final : public RenderTestParams
{ {
std::string suffix() const override; std::string suffix() const override;
...@@ -30,7 +30,7 @@ struct PointSpritesParams final : public PerfTestParams ...@@ -30,7 +30,7 @@ struct PointSpritesParams final : public PerfTestParams
unsigned int iterations; unsigned int iterations;
}; };
class PointSpritesBenchmark : public ANGLEPerfTest, class PointSpritesBenchmark : public ANGLERenderTest,
public ::testing::WithParamInterface<PointSpritesParams> public ::testing::WithParamInterface<PointSpritesParams>
{ {
public: public:
...@@ -52,7 +52,7 @@ std::string PointSpritesParams::suffix() const ...@@ -52,7 +52,7 @@ std::string PointSpritesParams::suffix() const
{ {
std::stringstream strstr; std::stringstream strstr;
strstr << PerfTestParams::suffix() strstr << RenderTestParams::suffix()
<< "_" << count << "_" << size << "px" << "_" << count << "_" << size << "px"
<< "_" << numVaryings << "vars"; << "_" << numVaryings << "vars";
...@@ -60,7 +60,7 @@ std::string PointSpritesParams::suffix() const ...@@ -60,7 +60,7 @@ std::string PointSpritesParams::suffix() const
} }
PointSpritesBenchmark::PointSpritesBenchmark() PointSpritesBenchmark::PointSpritesBenchmark()
: ANGLEPerfTest("PointSprites", GetParam()) : ANGLERenderTest("PointSprites", GetParam())
{ {
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
namespace namespace
{ {
struct TexSubImageParams final : public PerfTestParams struct TexSubImageParams final : public RenderTestParams
{ {
std::string suffix() const override; std::string suffix() const override;
...@@ -28,7 +28,7 @@ struct TexSubImageParams final : public PerfTestParams ...@@ -28,7 +28,7 @@ struct TexSubImageParams final : public PerfTestParams
unsigned int iterations; unsigned int iterations;
}; };
class TexSubImageBenchmark : public ANGLEPerfTest, class TexSubImageBenchmark : public ANGLERenderTest,
public ::testing::WithParamInterface<TexSubImageParams> public ::testing::WithParamInterface<TexSubImageParams>
{ {
public: public:
...@@ -66,11 +66,11 @@ class TexSubImageBenchmark : public ANGLEPerfTest, ...@@ -66,11 +66,11 @@ class TexSubImageBenchmark : public ANGLEPerfTest,
std::string TexSubImageParams::suffix() const std::string TexSubImageParams::suffix() const
{ {
// TODO(jmadill) // TODO(jmadill)
return PerfTestParams::suffix(); return RenderTestParams::suffix();
} }
TexSubImageBenchmark::TexSubImageBenchmark() TexSubImageBenchmark::TexSubImageBenchmark()
: ANGLEPerfTest("TexSubImage", GetParam()), : ANGLERenderTest("TexSubImage", GetParam()),
mProgram(0), mProgram(0),
mPositionLoc(-1), mPositionLoc(-1),
mTexCoordLoc(-1), mTexCoordLoc(-1),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment