Commit 2d676313 by Olli Etuaho Committed by Commit Bot

Refactor common functionality out of draw call perf tests

Common functionality across some perf tests is moved to a separate utility file, draw_call_perf_utils. This will make it simpler to add more perf tests, such as tests for multiview drawing. BUG=angleproject:1669 TEST=angle_perftests Change-Id: I2108d7425f7d8f43f333ea9daa6779e42862350b Reviewed-on: https://chromium-review.googlesource.com/422332 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent acd1898e
......@@ -19,6 +19,8 @@
'<(angle_path)/src/tests/perf_tests/ANGLEPerfTest.h',
'<(angle_path)/src/tests/perf_tests/BufferSubData.cpp',
'<(angle_path)/src/tests/perf_tests/DrawCallPerf.cpp',
'<(angle_path)/src/tests/perf_tests/DrawCallPerfParams.cpp',
'<(angle_path)/src/tests/perf_tests/DrawCallPerfParams.h',
'<(angle_path)/src/tests/perf_tests/DynamicPromotionPerfTest.cpp',
'<(angle_path)/src/tests/perf_tests/EGLInitializePerf.cpp',
'<(angle_path)/src/tests/perf_tests/IndexConversionPerf.cpp',
......@@ -36,6 +38,8 @@
'<(angle_path)/src/tests/test_utils/angle_test_configs.h',
'<(angle_path)/src/tests/test_utils/angle_test_instantiate.cpp',
'<(angle_path)/src/tests/test_utils/angle_test_instantiate.h',
'<(angle_path)/src/tests/test_utils/draw_call_perf_utils.cpp',
'<(angle_path)/src/tests/test_utils/draw_call_perf_utils.h',
],
'angle_perf_tests_win_sources':
[
......
......@@ -10,7 +10,7 @@
#include <sstream>
#include "ANGLEPerfTest.h"
#include "shader_utils.h"
#include "test_utils/draw_call_perf_utils.h"
using namespace angle;
......@@ -269,35 +269,19 @@ void BufferSubDataBenchmark::initializeBenchmark()
ASSERT_LT(1, params.vertexComponentCount);
ASSERT_LT(0u, params.iterations);
const std::string vs = SHADER_SOURCE
(
attribute vec2 vPosition;
uniform float uScale;
uniform float uOffset;
void main()
{
gl_Position = vec4(vPosition * vec2(uScale) - vec2(uOffset), 0, 1);
}
);
const std::string fs = SHADER_SOURCE
(
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
);
mProgram = CompileProgram(vs, fs);
mProgram = SetupSimpleScaleAndOffsetProgram();
ASSERT_NE(0u, mProgram);
// Use the program object
glUseProgram(mProgram);
if (params.vertexNormalized == GL_TRUE)
{
GLfloat scale = 2.0f;
GLfloat offset = -0.5f;
glUniform1f(glGetUniformLocation(mProgram, "uScale"), scale);
glUniform1f(glGetUniformLocation(mProgram, "uOffset"), offset);
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
std::vector<uint8_t> zeroData(params.bufferSize);
memset(&zeroData[0], 0, zeroData.size());
......@@ -335,18 +319,6 @@ void BufferSubDataBenchmark::initializeBenchmark()
// Set the viewport
glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
GLfloat scale = 0.5f;
GLfloat offset = 0.5f;
if (params.vertexNormalized == GL_TRUE)
{
scale = 2.0f;
offset = 0.5f;
}
glUniform1f(glGetUniformLocation(mProgram, "uScale"), scale);
glUniform1f(glGetUniformLocation(mProgram, "uOffset"), offset);
ASSERT_GL_NO_ERROR();
}
......
......@@ -7,63 +7,13 @@
// Performance tests for ANGLE draw call overhead.
//
#include <sstream>
#include "ANGLEPerfTest.h"
#include "shader_utils.h"
using namespace angle;
#include "DrawCallPerfParams.h"
#include "test_utils/draw_call_perf_utils.h"
namespace
{
struct DrawCallPerfParams final : public RenderTestParams
{
// Common default options
DrawCallPerfParams()
{
majorVersion = 2;
minorVersion = 0;
windowWidth = 256;
windowHeight = 256;
}
std::string suffix() const override
{
std::stringstream strstr;
strstr << RenderTestParams::suffix();
if (numTris == 0)
{
strstr << "_validation_only";
}
if (useFBO)
{
strstr << "_render_to_texture";
}
if (eglParameters.deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{
strstr << "_null";
}
return strstr.str();
}
unsigned int iterations = 50;
double runTimeSeconds = 10.0;
int numTris = 1;
bool useFBO = false;
};
std::ostream &operator<<(std::ostream &os, const DrawCallPerfParams &params)
{
os << params.suffix().substr(1);
return os;
}
class DrawCallPerfBenchmark : public ANGLERenderTest,
public ::testing::WithParamInterface<DrawCallPerfParams>
{
......@@ -93,56 +43,12 @@ void DrawCallPerfBenchmark::initializeBenchmark()
ASSERT_LT(0u, params.iterations);
const std::string vs = SHADER_SOURCE
(
attribute vec2 vPosition;
uniform float uScale;
uniform float uOffset;
void main()
{
gl_Position = vec4(vPosition * vec2(uScale) - vec2(uOffset), 0, 1);
}
);
const std::string fs = SHADER_SOURCE
(
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
);
mProgram = CompileProgram(vs, fs);
mProgram = SetupSimpleScaleAndOffsetProgram();
ASSERT_NE(0u, mProgram);
// Use the program object
glUseProgram(mProgram);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
std::vector<GLfloat> floatData;
for (int quadIndex = 0; quadIndex < mNumTris; ++quadIndex)
{
floatData.push_back(1);
floatData.push_back(2);
floatData.push_back(0);
floatData.push_back(0);
floatData.push_back(2);
floatData.push_back(0);
}
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
// To avoid generating GL errors when testing validation-only
if (floatData.empty())
{
floatData.push_back(0.0f);
}
glBufferData(GL_ARRAY_BUFFER, floatData.size() * sizeof(GLfloat), &floatData[0], GL_STATIC_DRAW);
mBuffer = Create2DTriangleBuffer(mNumTris, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
......@@ -150,21 +56,9 @@ void DrawCallPerfBenchmark::initializeBenchmark()
// Set the viewport
glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
GLfloat scale = 0.5f;
GLfloat offset = 0.5f;
glUniform1f(glGetUniformLocation(mProgram, "uScale"), scale);
glUniform1f(glGetUniformLocation(mProgram, "uOffset"), offset);
if (params.useFBO)
{
glGenFramebuffers(1, &mFBO);
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindow()->getWidth(), getWindow()->getHeight(),
0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0);
CreateColorFBO(getWindow()->getWidth(), getWindow()->getHeight(), &mTexture, &mFBO);
}
ASSERT_GL_NO_ERROR();
......@@ -201,42 +95,6 @@ void DrawCallPerfBenchmark::drawBenchmark()
ASSERT_GL_NO_ERROR();
}
using namespace egl_platform;
DrawCallPerfParams DrawCallPerfD3D11Params(bool useNullDevice, bool renderToTexture)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? D3D11_NULL() : D3D11();
params.useFBO = renderToTexture;
return params;
}
DrawCallPerfParams DrawCallPerfD3D9Params(bool useNullDevice, bool renderToTexture)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? D3D9_NULL() : D3D9();
params.useFBO = renderToTexture;
return params;
}
DrawCallPerfParams DrawCallPerfOpenGLParams(bool useNullDevice, bool renderToTexture)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? OPENGL_NULL() : OPENGL();
params.useFBO = renderToTexture;
return params;
}
DrawCallPerfParams DrawCallPerfValidationOnly()
{
DrawCallPerfParams params;
params.eglParameters = DEFAULT();
params.iterations = 10000;
params.numTris = 0;
params.runTimeSeconds = 5.0;
return params;
}
TEST_P(DrawCallPerfBenchmark, Run)
{
run();
......
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DrawCallPerfParams.cpp:
// Parametrization for performance tests for ANGLE draw call overhead.
//
#include "DrawCallPerfParams.h"
#include <sstream>
std::ostream &operator<<(std::ostream &os, const DrawCallPerfParams &params)
{
os << params.suffix().substr(1);
return os;
}
std::string DrawCallPerfParams::suffix() const
{
std::stringstream strstr;
strstr << RenderTestParams::suffix();
if (numTris == 0)
{
strstr << "_validation_only";
}
if (useFBO)
{
strstr << "_render_to_texture";
}
if (eglParameters.deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{
strstr << "_null";
}
return strstr.str();
}
using namespace angle::egl_platform;
DrawCallPerfParams DrawCallPerfD3D11Params(bool useNullDevice, bool renderToTexture)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? D3D11_NULL() : D3D11();
params.useFBO = renderToTexture;
return params;
}
DrawCallPerfParams DrawCallPerfD3D9Params(bool useNullDevice, bool renderToTexture)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? D3D9_NULL() : D3D9();
params.useFBO = renderToTexture;
return params;
}
DrawCallPerfParams DrawCallPerfOpenGLParams(bool useNullDevice, bool renderToTexture)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? OPENGL_NULL() : OPENGL();
params.useFBO = renderToTexture;
return params;
}
DrawCallPerfParams DrawCallPerfValidationOnly()
{
DrawCallPerfParams params;
params.eglParameters = DEFAULT();
params.iterations = 10000;
params.numTris = 0;
params.runTimeSeconds = 5.0;
return params;
}
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DrawCallPerfParams.h:
// Parametrization for performance tests for ANGLE draw call overhead.
//
#ifndef TESTS_PERF_TESTS_DRAW_CALL_PERF_PARAMS_H_
#define TESTS_PERF_TESTS_DRAW_CALL_PERF_PARAMS_H_
#include <ostream>
#include "ANGLEPerfTest.h"
struct DrawCallPerfParams final : public RenderTestParams
{
// Common default options
DrawCallPerfParams()
{
majorVersion = 2;
minorVersion = 0;
windowWidth = 256;
windowHeight = 256;
}
std::string suffix() const override;
unsigned int iterations = 50;
double runTimeSeconds = 10.0;
int numTris = 1;
bool useFBO = false;
};
std::ostream &operator<<(std::ostream &os, const DrawCallPerfParams &params);
DrawCallPerfParams DrawCallPerfD3D11Params(bool useNullDevice, bool renderToTexture);
DrawCallPerfParams DrawCallPerfD3D9Params(bool useNullDevice, bool renderToTexture);
DrawCallPerfParams DrawCallPerfOpenGLParams(bool useNullDevice, bool renderToTexture);
DrawCallPerfParams DrawCallPerfValidationOnly();
#endif // TESTS_PERF_TESTS_DRAW_CALL_PERF_PARAMS_H_
......@@ -10,7 +10,7 @@
#include <sstream>
#include "ANGLEPerfTest.h"
#include "shader_utils.h"
#include "tests/test_utils/draw_call_perf_utils.h"
using namespace angle;
......@@ -84,51 +84,14 @@ void IndexConversionPerfTest::initializeBenchmark()
ASSERT_LT(0u, params.iterations);
ASSERT_LT(0u, params.numIndexTris);
const std::string vs = SHADER_SOURCE
(
attribute vec2 vPosition;
uniform float uScale;
uniform float uOffset;
void main()
{
gl_Position = vec4(vPosition * vec2(uScale) - vec2(uOffset), 0, 1);
}
);
const std::string fs = SHADER_SOURCE
(
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
);
mProgram = CompileProgram(vs, fs);
mProgram = SetupSimpleScaleAndOffsetProgram();
ASSERT_NE(0u, mProgram);
// Use the program object
glUseProgram(mProgram);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Initialize the vertex data
std::vector<GLfloat> floatData;
size_t numTris = std::numeric_limits<GLushort>::max() / 3 + 1;
for (size_t triIndex = 0; triIndex < numTris; ++triIndex)
{
floatData.push_back(1);
floatData.push_back(2);
floatData.push_back(0);
floatData.push_back(0);
floatData.push_back(2);
floatData.push_back(0);
}
glGenBuffers(1, &mVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, floatData.size() * sizeof(GLfloat), &floatData[0], GL_STATIC_DRAW);
mVertexBuffer = Create2DTriangleBuffer(numTris, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
......@@ -157,12 +120,6 @@ void IndexConversionPerfTest::initializeBenchmark()
// Set the viewport
glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
GLfloat scale = 0.5f;
GLfloat offset = 0.5f;
glUniform1f(glGetUniformLocation(mProgram, "uScale"), scale);
glUniform1f(glGetUniformLocation(mProgram, "uOffset"), offset);
ASSERT_GL_NO_ERROR();
}
......
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// draw_call_perf_utils.cpp:
// Common utilities for performance tests that need to do a large amount of draw calls.
//
#include "draw_call_perf_utils.h"
#include <vector>
#include "shader_utils.h"
namespace
{
const char *SimpleScaleAndOffsetVertexShaderSource()
{
// clang-format off
return SHADER_SOURCE
(
attribute vec2 vPosition;
uniform float uScale;
uniform float uOffset;
void main()
{
gl_Position = vec4(vPosition * vec2(uScale) + vec2(uOffset), 0, 1);
}
);
// clang-format on
}
const char *SimpleFragmentShaderSource()
{
// clang-format off
return SHADER_SOURCE
(
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
);
// clang-format on
}
void Generate2DTriangleData(int numTris, std::vector<float> *floatData)
{
for (int triIndex = 0; triIndex < numTris; ++triIndex)
{
floatData->push_back(1.0f);
floatData->push_back(2.0f);
floatData->push_back(0.0f);
floatData->push_back(0.0f);
floatData->push_back(2.0f);
floatData->push_back(0.0f);
}
}
} // anonymous namespace
GLuint SetupSimpleScaleAndOffsetProgram()
{
const std::string vs = SimpleScaleAndOffsetVertexShaderSource();
const std::string fs = SimpleFragmentShaderSource();
GLuint program = CompileProgram(vs, fs);
if (program == 0u)
{
return program;
}
// Use the program object
glUseProgram(program);
GLfloat scale = 0.5f;
GLfloat offset = -0.5f;
glUniform1f(glGetUniformLocation(program, "uScale"), scale);
glUniform1f(glGetUniformLocation(program, "uOffset"), offset);
return program;
}
GLuint Create2DTriangleBuffer(int numTris, GLenum usage)
{
GLuint buffer = 0u;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
std::vector<GLfloat> floatData;
Generate2DTriangleData(numTris, &floatData);
// To avoid generating GL errors when testing validation-only with zero triangles.
if (floatData.empty())
{
floatData.push_back(0.0f);
}
glBufferData(GL_ARRAY_BUFFER, floatData.size() * sizeof(GLfloat), &floatData[0], usage);
return buffer;
}
void CreateColorFBO(GLsizei width, GLsizei height, GLuint *fbo, GLuint *texture)
{
glGenFramebuffers(1, fbo);
glBindFramebuffer(GL_FRAMEBUFFER, *fbo);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *texture, 0);
}
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// draw_call_perf_utils.h:
// Common utilities for performance tests that need to do a large amount of draw calls.
//
#ifndef TESTS_TEST_UTILS_DRAW_CALL_PERF_UTILS_H_
#define TESTS_TEST_UTILS_DRAW_CALL_PERF_UTILS_H_
#include "angle_gl.h"
// Returns program ID. The program is left in use and the uniforms are set to default values:
// uScale = 0.5, uOffset = -0.5
GLuint SetupSimpleScaleAndOffsetProgram();
// Returns buffer ID filled with 2-component triangle coordinates. The buffer is left as bound.
// Generates triangles like this with 2-component coordinates:
// A
// / \
// / \
// B-----C
GLuint Create2DTriangleBuffer(int numTris, GLenum usage);
// Creates an FBO with a texture color attachment. The texture is GL_RGBA and has dimensions
// width/height. The FBO and texture ids are written to the out parameters.
void CreateColorFBO(GLsizei width, GLsizei height, GLuint *fbo, GLuint *texture);
#endif // TESTS_TEST_UTILS_DRAW_CALL_PERF_UTILS_H_
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