Hash :
84b0c3b7
Author :
Date :
2015-11-05T15:15:28
Re-land "In D3D, cache static vertex buffers to prevent wasteful recreation" BUG=angleproject:197 Changes since first failed patch: - Optimized BufferD3D::getStaticVertexBuffer() - Removed loop to commit static buffers - Out-of-date static buffers (which are much rarer anyway after this patch) are marked for deletion at the *next* draw call, rather than searched for before each draw call. That search was expensive. The change should see a net improvement to DrawCallPerfBenchmark for D3D null. Change-Id: If4942e0afd9e8fefadce8820a1305e13636547ef Reviewed-on: https://chromium-review.googlesource.com/311115 Tested-by: Austin Kinross <aukinros@microsoft.com> Tryjob-Request: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
//
// Copyright (c) 2014 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.
//
// DrawCallPerf:
// Performance tests for ANGLE draw call overhead.
//
#include <sstream>
#include "ANGLEPerfTest.h"
#include "shader_utils.h"
using namespace angle;
namespace
{
struct DrawCallPerfParams final : public RenderTestParams
{
// Common default options
DrawCallPerfParams()
{
majorVersion = 2;
minorVersion = 0;
windowWidth = 256;
windowHeight = 256;
iterations = 50;
numTris = 1;
runTimeSeconds = 10.0;
}
std::string suffix() const override
{
std::stringstream strstr;
strstr << RenderTestParams::suffix();
if (numTris == 0)
{
strstr << "_validation_only";
}
if (eglParameters.deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{
strstr << "_null";
}
return strstr.str();
}
unsigned int iterations;
double runTimeSeconds;
int numTris;
};
std::ostream &operator<<(std::ostream &os, const DrawCallPerfParams ¶ms)
{
os << params.suffix().substr(1);
return os;
}
class DrawCallPerfBenchmark : public ANGLERenderTest,
public ::testing::WithParamInterface<DrawCallPerfParams>
{
public:
DrawCallPerfBenchmark();
void initializeBenchmark() override;
void destroyBenchmark() override;
void beginDrawBenchmark() override;
void drawBenchmark() override;
private:
GLuint mProgram;
GLuint mBuffer;
int mNumTris;
};
DrawCallPerfBenchmark::DrawCallPerfBenchmark()
: ANGLERenderTest("DrawCallPerf", GetParam()),
mProgram(0),
mBuffer(0),
mNumTris(GetParam().numTris)
{
mRunTimeSeconds = GetParam().runTimeSeconds;
}
void DrawCallPerfBenchmark::initializeBenchmark()
{
const auto ¶ms = GetParam();
ASSERT_TRUE(params.iterations > 0);
mDrawIterations = 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);
ASSERT_TRUE(mProgram != 0);
// 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);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
// 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();
}
void DrawCallPerfBenchmark::destroyBenchmark()
{
glDeleteProgram(mProgram);
glDeleteBuffers(1, &mBuffer);
}
void DrawCallPerfBenchmark::beginDrawBenchmark()
{
// Clear the color buffer
glClear(GL_COLOR_BUFFER_BIT);
}
void DrawCallPerfBenchmark::drawBenchmark()
{
const auto ¶ms = GetParam();
for (unsigned int it = 0; it < params.iterations; it++)
{
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(3 * mNumTris));
}
ASSERT_GL_NO_ERROR();
}
using namespace egl_platform;
DrawCallPerfParams DrawCallPerfD3D11Params(bool useNullDevice)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? D3D11_NULL() : D3D11();
return params;
}
DrawCallPerfParams DrawCallPerfD3D9Params(bool useNullDevice)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? D3D9_NULL() : D3D9();
return params;
}
DrawCallPerfParams DrawCallPerfOpenGLParams(bool useNullDevice)
{
DrawCallPerfParams params;
params.eglParameters = useNullDevice ? OPENGL_NULL() : OPENGL();
return params;
}
DrawCallPerfParams DrawCallPerfValidationOnly()
{
DrawCallPerfParams params;
params.eglParameters = DEFAULT();
params.iterations = 100;
params.numTris = 0;
params.runTimeSeconds = 5.0;
return params;
}
TEST_P(DrawCallPerfBenchmark, Run)
{
run();
}
ANGLE_INSTANTIATE_TEST(DrawCallPerfBenchmark,
DrawCallPerfD3D11Params(false),
DrawCallPerfD3D9Params(false),
DrawCallPerfOpenGLParams(false),
DrawCallPerfD3D11Params(true),
DrawCallPerfD3D9Params(true),
DrawCallPerfOpenGLParams(true),
DrawCallPerfValidationOnly());
} // namespace