Delete GLBench and subclasses
Bug: skia:6305
Change-Id: I3b2f2a8898f25d3dd0ec47668895dd4d00668575
Reviewed-on: https://skia-review.googlesource.com/82040
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/bench/GLBench.cpp b/bench/GLBench.cpp
deleted file mode 100644
index 10a6367..0000000
--- a/bench/GLBench.cpp
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GLBench.h"
-
-#if SK_SUPPORT_GPU
-#include "GrGpu.h"
-#include "GrTest.h"
-#include "gl/GrGLContext.h"
-#include "gl/builders/GrGLShaderStringBuilder.h"
-#include "SkSLCompiler.h"
-#include <stdio.h>
-
-#include "sk_tool_utils.h"
-
-const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) {
- // This bench exclusively tests GL calls directly
- if (nullptr == canvas->getGrContext()) {
- return nullptr;
- }
- GrContext* context = canvas->getGrContext();
- GrGpu* gpu = context->getGpu();
- if (!gpu) {
- SkDebugf("Couldn't get Gr gpu.");
- return nullptr;
- }
-
- const GrGLContext* ctx = gpu->glContextForTesting();
- if (!ctx) {
- SkDebugf("Couldn't get an interface\n");
- return nullptr;
- }
-
- return this->onGetGLContext(ctx);
-}
-
-void GLBench::onPreDraw(SkCanvas* canvas) {
- // This bench exclusively tests GL calls directly
- const GrGLContext* ctx = this->getGLContext(canvas);
- if (!ctx) {
- return;
- }
- this->setup(ctx);
-}
-
-void GLBench::onPostDraw(SkCanvas* canvas) {
- // This bench exclusively tests GL calls directly
- const GrGLContext* ctx = this->getGLContext(canvas);
- if (!ctx) {
- return;
- }
- this->teardown(ctx->interface());
-}
-
-void GLBench::onDraw(int loops, SkCanvas* canvas) {
- const GrGLContext* ctx = this->getGLContext(canvas);
- if (!ctx) {
- return;
- }
- this->glDraw(loops, ctx);
- canvas->getGrContext()->resetContext();
-}
-
-GrGLuint GLBench::CompileShader(const GrGLContext* context, const char* sksl, GrGLenum type) {
- const GrGLInterface* gl = context->interface();
- SkSL::String glsl;
- SkSL::Program::Settings settings;
- settings.fCaps = context->caps()->shaderCaps();
- std::unique_ptr<SkSL::Program> program = context->compiler()->convertProgram(
- type == GR_GL_VERTEX_SHADER ? SkSL::Program::kVertex_Kind
- : SkSL::Program::kFragment_Kind,
- SkSL::String(sksl),
- settings);
- if (!program || !context->compiler()->toGLSL(*program, &glsl)) {
- SkDebugf("SkSL compilation failed:\n%s\n%s\n", sksl,
- context->compiler()->errorText().c_str());
- }
- GrGLuint shader;
- // Create the shader object
- GR_GL_CALL_RET(gl, shader, CreateShader(type));
-
- // Load the shader source
- const char* glslPtr = glsl.c_str();
- GR_GL_CALL(gl, ShaderSource(shader, 1, (const char**) &glslPtr, nullptr));
-
- // Compile the shader
- GR_GL_CALL(gl, CompileShader(shader));
-
- // Check for compile time errors
- GrGLint success = GR_GL_INIT_ZERO;
- GrGLchar infoLog[512];
- GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &success));
- if (!success) {
- GR_GL_CALL(gl, GetShaderInfoLog(shader, 512, nullptr, infoLog));
- SkDebugf("ERROR::SHADER::COMPLIATION_FAILED: %s\n", infoLog);
- }
-
- return shader;
-}
-
-GrGLuint GLBench::CreateProgram(const GrGLContext* context, const char* vshader,
- const char* fshader) {
- const GrGLInterface* gl = context->interface();
- GrGLuint vertexShader = CompileShader(context, vshader, GR_GL_VERTEX_SHADER);
- GrGLuint fragmentShader = CompileShader(context, fshader, GR_GL_FRAGMENT_SHADER);
-
- GrGLuint shaderProgram;
- GR_GL_CALL_RET(gl, shaderProgram, CreateProgram());
- GR_GL_CALL(gl, AttachShader(shaderProgram, vertexShader));
- GR_GL_CALL(gl, AttachShader(shaderProgram, fragmentShader));
- GR_GL_CALL(gl, LinkProgram(shaderProgram));
-
- // Check for linking errors
- GrGLint success = GR_GL_INIT_ZERO;
- GrGLchar infoLog[512];
- GR_GL_CALL(gl, GetProgramiv(shaderProgram, GR_GL_LINK_STATUS, &success));
- if (!success) {
- GR_GL_CALL(gl, GetProgramInfoLog(shaderProgram, 512, nullptr, infoLog));
- SkDebugf("Linker Error: %s\n", infoLog);
- }
- GR_GL_CALL(gl, DeleteShader(vertexShader));
- GR_GL_CALL(gl, DeleteShader(fragmentShader));
-
- return shaderProgram;
-}
-
-GrGLuint GLBench::SetupFramebuffer(const GrGLInterface* gl, int screenWidth, int screenHeight) {
- //Setup framebuffer
- GrGLuint texture;
- GR_GL_CALL(gl, GenTextures(1, &texture));
- GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE7));
- GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texture));
- GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST));
- GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST));
- GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_EDGE));
- GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_EDGE));
- GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D,
- 0, //level
- GR_GL_RGBA, //internal format
- screenWidth, // width
- screenHeight, // height
- 0, //border
- GR_GL_RGBA, //format
- GR_GL_UNSIGNED_BYTE, // type
- nullptr));
-
- // bind framebuffer
- GrGLuint framebuffer;
- GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
- GR_GL_CALL(gl, GenFramebuffers(1, &framebuffer));
- GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, framebuffer));
- GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER,
- GR_GL_COLOR_ATTACHMENT0,
- GR_GL_TEXTURE_2D,
- texture, 0));
- GR_GL_CALL(gl, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
- GR_GL_CALL(gl, Viewport(0, 0, screenWidth, screenHeight));
- return texture;
-}
-
-
-void GLBench::DumpImage(const GrGLInterface* gl, uint32_t screenWidth, uint32_t screenHeight,
- const char* filename) {
- // read back pixels
- SkAutoTArray<uint32_t> readback(screenWidth * screenHeight);
- GR_GL_CALL(gl, ReadPixels(0, // x
- 0, // y
- screenWidth, // width
- screenHeight, // height
- GR_GL_RGBA, //format
- GR_GL_UNSIGNED_BYTE, //type
- readback.get()));
-
- // dump png
- SkBitmap bm;
- if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(screenWidth, screenHeight))) {
- SkDebugf("couldn't allocate bitmap\n");
- return;
- }
-
- bm.setPixels(readback.get());
-
- if (!sk_tool_utils::EncodeImageToFile(filename, bm, SkEncodedImageFormat::kPNG, 100)) {
- SkDebugf("------ failed to encode %s\n", filename);
- remove(filename); // remove any partial file
- return;
- }
-}
-
-#endif
diff --git a/bench/GLBench.h b/bench/GLBench.h
deleted file mode 100644
index a358894..0000000
--- a/bench/GLBench.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GLBench_DEFINED
-#define GLBench_DEFINED
-
-#include "Benchmark.h"
-#include "SkCanvas.h"
-#include "SkImageEncoder.h"
-
-#if SK_SUPPORT_GPU
-#include "gl/GrGLFunctions.h"
-
-class GrGLContext;
-struct GrGLInterface;
-
-/*
- * A virtual base class for microbenches which want to specifically test the performance of GL
- */
-
-class GLBench : public Benchmark {
-public:
- GLBench() {}
-
-protected:
- const GrGLContext* getGLContext(SkCanvas*);
- virtual const GrGLContext* onGetGLContext(const GrGLContext* ctx) { return ctx; }
- void onPreDraw(SkCanvas*) override;
- virtual void setup(const GrGLContext*)=0;
- void onPostDraw(SkCanvas* canvas) override;
- virtual void teardown(const GrGLInterface*)=0;
- void onDraw(int loops, SkCanvas*) override;
- virtual void glDraw(int loops, const GrGLContext*)=0;
- static GrGLuint CompileShader(const GrGLContext*, const char* shaderSrc, GrGLenum type);
- static GrGLuint CreateProgram(const GrGLContext*, const char* vshader, const char* fshader);
- static GrGLuint SetupFramebuffer(const GrGLInterface*, int screenWidth, int screenHeight);
- static void DumpImage(const GrGLInterface* gl, uint32_t screenWidth, uint32_t screenHeight,
- const char* filename);
-
-
-private:
- typedef Benchmark INHERITED;
-};
-
-
-#endif
-#endif
diff --git a/bench/GLInstancedArraysBench.cpp b/bench/GLInstancedArraysBench.cpp
deleted file mode 100644
index 42cb02a..0000000
--- a/bench/GLInstancedArraysBench.cpp
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "Benchmark.h"
-#include "SkCanvas.h"
-#include "SkImageEncoder.h"
-
-#if SK_SUPPORT_GPU
-#include "GLBench.h"
-#include "GrShaderCaps.h"
-#include "GrShaderVar.h"
-#include "gl/GrGLContext.h"
-#include "gl/GrGLInterface.h"
-#include "gl/GrGLUtil.h"
-#include "../private/GrGLSL.h"
-
-/*
- * This is a native GL benchmark for instanced arrays vs vertex buffer objects. To benchmark this
- * functionality, we draw n * kDrawMultipier triangles per run. If this number is less than
- * kNumTri then we do a single draw, either with instances, or drawArrays. Otherwise we do
- * multiple draws.
- *
- * Additionally, there is a divisor, which if > 0 will act as a multiplier for the number of draws
- * issued.
- */
-
-class GLCpuPosInstancedArraysBench : public GLBench {
-public:
- /*
- * Clients can decide to use either:
- * kUseOne_VboSetup - one vertex buffer with colors and positions interleaved
- * kUseTwo_VboSetup - two vertex buffers, one for colors, one for positions
- * kUseInstance_VboSetup - two vertex buffers, one with per vertex indices, one with per
- * instance colors
- */
- enum VboSetup {
- kUseOne_VboSetup,
- kUseTwo_VboSetup,
- kUseInstance_VboSetup,
- };
-
- /*
- * drawDiv will act as a multiplier for the number of draws we issue if > 0. ie, 2 will issue
- * 2x as many draws, 4 will issue 4x as many draws etc. There is a limit however, which is
- * kDrawMultipier.
- */
- GLCpuPosInstancedArraysBench(VboSetup vboSetup, int32_t drawDiv)
- : fVboSetup(vboSetup)
- , fDrawDiv(drawDiv)
- , fProgram(0)
- , fVAO(0) {
- fName = VboSetupToStr(vboSetup, fDrawDiv);
- }
-
-protected:
- const char* onGetName() override {
- return fName.c_str();
- }
-
- const GrGLContext* onGetGLContext(const GrGLContext*) override;
- void setup(const GrGLContext*) override;
- void glDraw(int loops, const GrGLContext*) override;
- void teardown(const GrGLInterface*) override;
-
-private:
- void setupInstanceVbo(const GrGLInterface*, const SkMatrix*);
- void setupDoubleVbo(const GrGLInterface*, const SkMatrix*);
- void setupSingleVbo(const GrGLInterface*, const SkMatrix*);
- GrGLuint setupShader(const GrGLContext*);
-
- static SkString VboSetupToStr(VboSetup vboSetup, uint32_t drawDiv) {
- SkString name("GLInstancedArraysBench");
- switch (vboSetup) {
- default:
- case kUseOne_VboSetup:
- name.appendf("_one_%u", drawDiv);
- break;
- case kUseTwo_VboSetup:
- name.appendf("_two_%u", drawDiv);
- break;
- case kUseInstance_VboSetup:
- name.append("_instance");
- break;
- }
- return name;
- }
-
- static const GrGLuint kScreenWidth = 800;
- static const GrGLuint kScreenHeight = 600;
- static const uint32_t kNumTri = 10000;
- static const uint32_t kVerticesPerTri = 3;
- static const uint32_t kDrawMultiplier = 512;
-
- SkString fName;
- VboSetup fVboSetup;
- uint32_t fDrawDiv;
- SkTArray<GrGLuint> fBuffers;
- GrGLuint fProgram;
- GrGLuint fVAO;
- GrGLuint fTexture;
-};
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) {
- const GrShaderCaps* shaderCaps = ctx->caps()->shaderCaps();
- const char* version = shaderCaps->versionDeclString();
-
- // setup vertex shader
- GrShaderVar aPosition("a_position", kHalf2_GrSLType, GrShaderVar::kIn_TypeModifier);
- GrShaderVar aColor("a_color", kHalf3_GrSLType, GrShaderVar::kIn_TypeModifier);
- GrShaderVar oColor("o_color", kHalf3_GrSLType, GrShaderVar::kOut_TypeModifier);
-
- SkString vshaderTxt(version);
- aPosition.appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
- aColor.appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
- oColor.appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
-
- vshaderTxt.append(
- "void main()\n"
- "{\n"
- "sk_Position = float4(a_position, 0., 1.);\n"
- "o_color = a_color;\n"
- "}\n");
-
- // setup fragment shader
- SkString fshaderTxt(version);
- oColor.setTypeModifier(GrShaderVar::kIn_TypeModifier);
- oColor.appendDecl(shaderCaps, &fshaderTxt);
- fshaderTxt.append(";\n");
-
- fshaderTxt.append(
- "void main()\n"
- "{\n"
- "sk_FragColor = float4(o_color, 1.0);\n"
- "}\n");
-
- return CreateProgram(ctx, vshaderTxt.c_str(), fshaderTxt.c_str());
-}
-
-template<typename Func>
-static void setup_matrices(int numQuads, Func f) {
- // We draw a really small triangle so we are not fill rate limited
- for (int i = 0 ; i < numQuads; i++) {
- SkMatrix m = SkMatrix::I();
- m.setScale(0.0001f, 0.0001f);
- f(m);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-const GrGLContext* GLCpuPosInstancedArraysBench::onGetGLContext(const GrGLContext* ctx) {
- // We only care about gpus with drawArraysInstanced support
- if (!ctx->interface()->fFunctions.fDrawArraysInstanced) {
- return nullptr;
- }
- return ctx;
-}
-
-void GLCpuPosInstancedArraysBench::setupInstanceVbo(const GrGLInterface* gl,
- const SkMatrix* viewMatrices) {
- // We draw all of the instances at a single place because we aren't allowed to have per vertex
- // per instance attributes
- SkPoint positions[kVerticesPerTri];
- positions[0].set(-1.0f, -1.0f);
- positions[1].set( 1.0f, -1.0f);
- positions[2].set( 1.0f, 1.0f);
- viewMatrices[0].mapPointsWithStride(positions, sizeof(SkPoint), kVerticesPerTri);
-
- // setup colors so we can detect we are actually drawing instances(the last triangle will be
- // a different color)
- GrGLfloat colors[kVerticesPerTri * kNumTri];
- for (uint32_t i = 0; i < kNumTri; i++) {
- // set colors
- uint32_t offset = i * kVerticesPerTri;
- float color = i == kNumTri - 1 ? 1.0f : 0.0f;
- colors[offset++] = color; colors[offset++] = 0.0f; colors[offset++] = 0.0f;
- }
-
- GrGLuint posVBO;
- // setup position VBO
- GR_GL_CALL(gl, GenBuffers(1, &posVBO));
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, posVBO));
- GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(positions), positions, GR_GL_STATIC_DRAW));
- GR_GL_CALL(gl, EnableVertexAttribArray(0));
- GR_GL_CALL(gl, VertexAttribPointer(0, 2, GR_GL_FLOAT, GR_GL_FALSE, 2 * sizeof(GrGLfloat),
- (GrGLvoid*)0));
-
- // setup color VBO
- GrGLuint instanceVBO;
- GR_GL_CALL(gl, GenBuffers(1, &instanceVBO));
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, instanceVBO));
- GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(colors), colors, GR_GL_STATIC_DRAW));
- GR_GL_CALL(gl, EnableVertexAttribArray(1));
- GR_GL_CALL(gl, VertexAttribPointer(1, 3, GR_GL_FLOAT, GR_GL_FALSE, 3 * sizeof(GrGLfloat),
- (GrGLvoid*)0));
- GR_GL_CALL(gl, VertexAttribDivisor(1, 1));
- fBuffers.push_back(posVBO);
- fBuffers.push_back(instanceVBO);
-}
-
-void GLCpuPosInstancedArraysBench::setupDoubleVbo(const GrGLInterface* gl,
- const SkMatrix* viewMatrices) {
- // Constants for our various shader programs
- SkPoint positions[kVerticesPerTri * kNumTri];
- GrGLfloat colors[kVerticesPerTri * kNumTri * 3];
- for (uint32_t i = 0; i < kNumTri; i++) {
- SkPoint* position = &positions[i * kVerticesPerTri];
- position[0].set(-1.0f, -1.0f);
- position[1].set( 1.0f, -1.0f);
- position[2].set( 1.0f, 1.0f);
- viewMatrices[i].mapPointsWithStride(position, sizeof(SkPoint), kVerticesPerTri);
-
- // set colors
- float color = i == kNumTri - 1 ? 1.0f : 0.0f;
- uint32_t offset = i * kVerticesPerTri * 3;
- for (uint32_t j = 0; j < kVerticesPerTri; j++) {
- colors[offset++] = color; colors[offset++] = 0.0f; colors[offset++] = 0.0f;
- }
- }
-
- GrGLuint posVBO, colorVBO;
- // setup position VBO
- GR_GL_CALL(gl, GenBuffers(1, &posVBO));
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, posVBO));
- GR_GL_CALL(gl, EnableVertexAttribArray(0));
- GR_GL_CALL(gl, VertexAttribPointer(0, 2, GR_GL_FLOAT, GR_GL_FALSE, 2 * sizeof(GrGLfloat),
- (GrGLvoid*)0));
- GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(positions), positions, GR_GL_STATIC_DRAW));
-
- // setup color VBO
- GR_GL_CALL(gl, GenBuffers(1, &colorVBO));
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, colorVBO));
- GR_GL_CALL(gl, EnableVertexAttribArray(1));
- GR_GL_CALL(gl, VertexAttribPointer(1, 3, GR_GL_FLOAT, GR_GL_FALSE, 3 * sizeof(GrGLfloat),
- (GrGLvoid*)0));
- GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(colors), colors, GR_GL_STATIC_DRAW));
-
- fBuffers.push_back(posVBO);
- fBuffers.push_back(colorVBO);
-}
-
-struct Vertex {
- SkPoint fPositions;
- GrGLfloat fColors[3];
-};
-
-void GLCpuPosInstancedArraysBench::setupSingleVbo(const GrGLInterface* gl,
- const SkMatrix* viewMatrices) {
- // Constants for our various shader programs
- Vertex vertices[kVerticesPerTri * kNumTri];
- for (uint32_t i = 0; i < kNumTri; i++) {
- Vertex* v = &vertices[i * kVerticesPerTri];
- v[0].fPositions.set(-1.0f, -1.0f);
- v[1].fPositions.set( 1.0f, -1.0f);
- v[2].fPositions.set( 1.0f, 1.0f);
-
- SkPoint* position = reinterpret_cast<SkPoint*>(v);
- viewMatrices[i].mapPointsWithStride(position, sizeof(Vertex), kVerticesPerTri);
-
- // set colors
- float color = i == kNumTri - 1 ? 1.0f : 0.0f;
- for (uint32_t j = 0; j < kVerticesPerTri; j++) {
- uint32_t offset = 0;
- v->fColors[offset++] = color; v->fColors[offset++] = 0.0f; v->fColors[offset++] = 0.0f;
- v++;
- }
- }
-
- GrGLuint vbo;
- // setup VBO
- GR_GL_CALL(gl, GenBuffers(1, &vbo));
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, vbo));
- GR_GL_CALL(gl, EnableVertexAttribArray(0));
- GR_GL_CALL(gl, EnableVertexAttribArray(1));
- GR_GL_CALL(gl, VertexAttribPointer(0, 2, GR_GL_FLOAT, GR_GL_FALSE, sizeof(Vertex),
- (GrGLvoid*)0));
- GR_GL_CALL(gl, VertexAttribPointer(1, 3, GR_GL_FLOAT, GR_GL_FALSE, sizeof(Vertex),
- (GrGLvoid*)(sizeof(SkPoint))));
- GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(vertices), vertices, GR_GL_STATIC_DRAW));
- fBuffers.push_back(vbo);
-}
-
-void GLCpuPosInstancedArraysBench::setup(const GrGLContext* ctx) {
- const GrGLInterface* gl = ctx->interface();
- fTexture = SetupFramebuffer(gl, kScreenWidth, kScreenHeight);
-
- fProgram = this->setupShader(ctx);
-
- // setup matrices
- int index = 0;
- SkMatrix viewMatrices[kNumTri];
- setup_matrices(kNumTri, [&index, &viewMatrices](const SkMatrix& m) {
- viewMatrices[index++] = m;
- });
-
- // setup VAO
- GR_GL_CALL(gl, GenVertexArrays(1, &fVAO));
- GR_GL_CALL(gl, BindVertexArray(fVAO));
-
- switch (fVboSetup) {
- case kUseOne_VboSetup:
- this->setupSingleVbo(gl, viewMatrices);
- break;
- case kUseTwo_VboSetup:
- this->setupDoubleVbo(gl, viewMatrices);
- break;
- case kUseInstance_VboSetup:
- this->setupInstanceVbo(gl, viewMatrices);
- break;
- }
-
- // clear screen
- GR_GL_CALL(gl, ClearColor(0.03f, 0.03f, 0.03f, 1.0f));
- GR_GL_CALL(gl, Clear(GR_GL_COLOR_BUFFER_BIT));
-
- // set us up to draw
- GR_GL_CALL(gl, UseProgram(fProgram));
- GR_GL_CALL(gl, BindVertexArray(fVAO));
-}
-
-void GLCpuPosInstancedArraysBench::glDraw(int loops, const GrGLContext* ctx) {
- const GrGLInterface* gl = ctx->interface();
-
- uint32_t maxTrianglesPerFlush = fDrawDiv == 0 ? kNumTri :
- kDrawMultiplier / fDrawDiv;
- uint32_t trianglesToDraw = loops * kDrawMultiplier;
-
- if (kUseInstance_VboSetup == fVboSetup) {
- while (trianglesToDraw > 0) {
- uint32_t triangles = SkTMin(trianglesToDraw, maxTrianglesPerFlush);
- GR_GL_CALL(gl, DrawArraysInstanced(GR_GL_TRIANGLES, 0, kVerticesPerTri, triangles));
- trianglesToDraw -= triangles;
- }
- } else {
- while (trianglesToDraw > 0) {
- uint32_t triangles = SkTMin(trianglesToDraw, maxTrianglesPerFlush);
- GR_GL_CALL(gl, DrawArrays(GR_GL_TRIANGLES, 0, kVerticesPerTri * triangles));
- trianglesToDraw -= triangles;
- }
- }
-
-#if 0
- //const char* filename = "/data/local/tmp/out.png";
- SkString filename("out");
- filename.appendf("_%s.png", this->getName());
- DumpImage(gl, kScreenWidth, kScreenHeight, filename.c_str());
-#endif
-}
-
-void GLCpuPosInstancedArraysBench::teardown(const GrGLInterface* gl) {
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, 0));
- GR_GL_CALL(gl, BindVertexArray(0));
- GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
- GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
- GR_GL_CALL(gl, DeleteTextures(1, &fTexture));
- GR_GL_CALL(gl, DeleteProgram(fProgram));
- GR_GL_CALL(gl, DeleteBuffers(fBuffers.count(), fBuffers.begin()));
- GR_GL_CALL(gl, DeleteVertexArrays(1, &fVAO));
- fBuffers.reset();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseInstance_VboSetup, 0) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseOne_VboSetup, 0) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseTwo_VboSetup, 0) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseOne_VboSetup, 1) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseTwo_VboSetup, 1) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseOne_VboSetup, 2) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseTwo_VboSetup, 2) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseOne_VboSetup, 4) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseTwo_VboSetup, 4) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseOne_VboSetup, 8) )
-DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench::kUseTwo_VboSetup, 8) )
-
-#endif
diff --git a/bench/GLVec4ScalarBench.cpp b/bench/GLVec4ScalarBench.cpp
deleted file mode 100644
index b007a7a..0000000
--- a/bench/GLVec4ScalarBench.cpp
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkMatrix.h"
-#include "SkPoint.h"
-#include "SkString.h"
-
-#if SK_SUPPORT_GPU
-#include "GLBench.h"
-#include "GrShaderCaps.h"
-#include "GrShaderVar.h"
-#include "gl/GrGLContext.h"
-#include "gl/GrGLInterface.h"
-#include "gl/GrGLUtil.h"
-#include "../private/GrGLSL.h"
-
-#include <stdio.h>
-
-/**
- * This is a GL benchmark for comparing the performance of using vec4 or float for coverage in GLSL.
- * The generated shader code from this bench will draw several overlapping circles, one in each
- * stage, to simulate coverage calculations. The number of circles (i.e. the number of stages) can
- * be set as a parameter.
- */
-
-class GLVec4ScalarBench : public GLBench {
-public:
- /*
- * Use float or vec4 as GLSL data type for the output coverage
- */
- enum CoverageSetup {
- kUseScalar_CoverageSetup,
- kUseVec4_CoverageSetup,
- };
-
- /*
- * numStages determines the number of shader stages before the XP,
- * which consequently determines how many circles are drawn
- */
- GLVec4ScalarBench(CoverageSetup coverageSetup, uint32_t numStages)
- : fCoverageSetup(coverageSetup)
- , fNumStages(numStages)
- , fVboId(0)
- , fProgram(0) {
- fName = NumStagesSetupToStr(coverageSetup, numStages);
- }
-
-protected:
- const char* onGetName() override {
- return fName.c_str();
- }
-
- void setup(const GrGLContext*) override;
- void glDraw(int loops, const GrGLContext*) override;
- void teardown(const GrGLInterface*) override;
-
-private:
- void setupSingleVbo(const GrGLInterface*, const SkMatrix*);
- GrGLuint setupShader(const GrGLContext*);
-
-
- static SkString NumStagesSetupToStr(CoverageSetup coverageSetup, uint32_t numStages) {
- SkString name("GLVec4ScalarBench");
- switch (coverageSetup) {
- default:
- case kUseScalar_CoverageSetup:
- name.appendf("_scalar_%u_stage", numStages);
- break;
- case kUseVec4_CoverageSetup:
- name.appendf("_vec4_%u_stage", numStages);
- break;
- }
- return name;
- }
-
- static const GrGLuint kScreenWidth = 800;
- static const GrGLuint kScreenHeight = 600;
- static const uint32_t kNumTriPerDraw = 512;
- static const uint32_t kVerticesPerTri = 3;
-
- SkString fName;
- CoverageSetup fCoverageSetup;
- uint32_t fNumStages;
- GrGLuint fVboId;
- GrGLuint fProgram;
- GrGLuint fFboTextureId;
-};
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) {
- const GrShaderCaps* shaderCaps = ctx->caps()->shaderCaps();
- const char* version = shaderCaps->versionDeclString();
-
- // this shader draws fNumStages overlapping circles of increasing opacity (coverage) and
- // decreasing size, with the center of each subsequent circle closer to the bottom-right
- // corner of the screen than the previous circle.
-
- // set up vertex shader; this is a trivial vertex shader that passes through position and color
- GrShaderVar aPosition("a_position", kHalf2_GrSLType, GrShaderVar::kIn_TypeModifier);
- GrShaderVar oPosition("o_position", kHalf2_GrSLType, GrShaderVar::kOut_TypeModifier);
- GrShaderVar aColor("a_color", kHalf3_GrSLType, GrShaderVar::kIn_TypeModifier);
- GrShaderVar oColor("o_color", kHalf3_GrSLType, GrShaderVar::kOut_TypeModifier);
-
- SkString vshaderTxt(version);
- aPosition.appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
- aColor.appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
- oPosition.appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
- oColor.appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
-
- vshaderTxt.append(
- "void main()\n"
- "{\n"
- " sk_Position = float4(a_position, 0.0, 1.0);\n"
- " o_position = a_position;\n"
- " o_color = a_color;\n"
- "}\n");
-
- // set up fragment shader; this fragment shader will have fNumStages coverage stages plus an
- // XP stage at the end. Each coverage stage computes the pixel's distance from some hard-
- // coded center and compare that to some hard-coded circle radius to compute a coverage.
- // Then, this coverage is mixed with the coverage from the previous stage and passed to the
- // next stage.
- SkString fshaderTxt(version);
- oPosition.setTypeModifier(GrShaderVar::kIn_TypeModifier);
- oPosition.appendDecl(shaderCaps, &fshaderTxt);
- fshaderTxt.append(";\n");
- oColor.setTypeModifier(GrShaderVar::kIn_TypeModifier);
- oColor.appendDecl(shaderCaps, &fshaderTxt);
- fshaderTxt.append(";\n");
-
- fshaderTxt.appendf(
- "void main()\n"
- "{\n"
- " half4 outputColor;\n"
- " %s outputCoverage;\n"
- " outputColor = half4(%s, 1.0);\n"
- " outputCoverage = %s;\n",
- fCoverageSetup == kUseVec4_CoverageSetup ? "half4" : "half",
- oColor.getName().c_str(),
- fCoverageSetup == kUseVec4_CoverageSetup ? "half4(1.0)" : "1.0"
- );
-
- float radius = 1.0f;
- for (uint32_t i = 0; i < fNumStages; i++) {
- float centerX = 1.0f - radius;
- float centerY = 1.0f - radius;
- fshaderTxt.appendf(
- " {\n"
- " half d = length(%s - half2(%f, %f));\n"
- " half edgeAlpha = clamp(100.0 * (%f - d), 0.0, 1.0);\n"
- " outputCoverage = 0.5 * outputCoverage + 0.5 * %s;\n"
- " }\n",
- oPosition.getName().c_str(), centerX, centerY,
- radius,
- fCoverageSetup == kUseVec4_CoverageSetup ? "half4(edgeAlpha)" : "edgeAlpha"
- );
- radius *= 0.8f;
- }
- fshaderTxt.append(
- " {\n"
- " sk_FragColor = outputColor * outputCoverage;\n"
- " }\n"
- "}\n");
-
- return CreateProgram(ctx, vshaderTxt.c_str(), fshaderTxt.c_str());
-}
-
-template<typename Func>
-static void setup_matrices(int numQuads, Func f) {
- // We draw a really small triangle so we are not fill rate limited
- for (int i = 0 ; i < numQuads; i++) {
- SkMatrix m = SkMatrix::I();
- m.setScale(0.01f, 0.01f);
- f(m);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-struct Vertex {
- SkPoint fPositions;
- GrGLfloat fColors[3];
-};
-
-void GLVec4ScalarBench::setupSingleVbo(const GrGLInterface* gl, const SkMatrix* viewMatrices) {
- // triangles drawn will alternate between the top-right half of the screen and the bottom-left
- // half of the screen
- Vertex vertices[kVerticesPerTri * kNumTriPerDraw];
- for (uint32_t i = 0; i < kNumTriPerDraw; i++) {
- Vertex* v = &vertices[i * kVerticesPerTri];
- if (i % 2 == 0) {
- v[0].fPositions.set(-1.0f, -1.0f);
- v[1].fPositions.set( 1.0f, -1.0f);
- v[2].fPositions.set( 1.0f, 1.0f);
- } else {
- v[0].fPositions.set(-1.0f, -1.0f);
- v[1].fPositions.set( 1.0f, 1.0f);
- v[2].fPositions.set( -1.0f, 1.0f);
- }
- SkPoint* position = reinterpret_cast<SkPoint*>(v);
- viewMatrices[i].mapPointsWithStride(position, sizeof(Vertex), kVerticesPerTri);
-
- GrGLfloat color[3] = {1.0f, 0.0f, 1.0f};
- for (uint32_t j = 0; j < kVerticesPerTri; j++) {
- v->fColors[0] = color[0];
- v->fColors[1] = color[1];
- v->fColors[2] = color[2];
- v++;
- }
- }
-
- GR_GL_CALL(gl, GenBuffers(1, &fVboId));
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, fVboId));
- GR_GL_CALL(gl, EnableVertexAttribArray(0));
- GR_GL_CALL(gl, EnableVertexAttribArray(1));
- GR_GL_CALL(gl, VertexAttribPointer(0, 2, GR_GL_FLOAT, GR_GL_FALSE, sizeof(Vertex),
- (GrGLvoid*)0));
- GR_GL_CALL(gl, VertexAttribPointer(1, 3, GR_GL_FLOAT, GR_GL_FALSE, sizeof(Vertex),
- (GrGLvoid*)(sizeof(SkPoint))));
- GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(vertices), vertices, GR_GL_STATIC_DRAW));
-}
-
-void GLVec4ScalarBench::setup(const GrGLContext* ctx) {
- const GrGLInterface* gl = ctx->interface();
- if (!gl) {
- SK_ABORT("GL interface is nullptr in setup()!\n");
- }
- fFboTextureId = SetupFramebuffer(gl, kScreenWidth, kScreenHeight);
-
- fProgram = this->setupShader(ctx);
-
- int index = 0;
- SkMatrix viewMatrices[kNumTriPerDraw];
- setup_matrices(kNumTriPerDraw, [&index, &viewMatrices](const SkMatrix& m) {
- viewMatrices[index++] = m;
- });
- this->setupSingleVbo(gl, viewMatrices);
-
- GR_GL_CALL(gl, UseProgram(fProgram));
-}
-
-void GLVec4ScalarBench::glDraw(int loops, const GrGLContext* ctx) {
- const GrGLInterface* gl = ctx->interface();
-
- for (int i = 0; i < loops; i++) {
- GR_GL_CALL(gl, DrawArrays(GR_GL_TRIANGLES, 0, kVerticesPerTri * kNumTriPerDraw));
- }
-
-// using -w when running nanobench will not produce correct images;
-// changing this to #if 1 will write the correct images to the Skia folder.
-#if 0
- SkString filename("out");
- filename.appendf("_%s.png", this->getName());
- DumpImage(gl, kScreenWidth, kScreenHeight, filename.c_str());
-#endif
-}
-
-void GLVec4ScalarBench::teardown(const GrGLInterface* gl) {
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, 0));
- GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
- GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
- GR_GL_CALL(gl, DeleteTextures(1, &fFboTextureId));
- GR_GL_CALL(gl, DeleteProgram(fProgram));
- GR_GL_CALL(gl, DeleteBuffers(1, &fVboId));
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSetup, 1) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetup, 1) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSetup, 2) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetup, 2) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSetup, 4) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetup, 4) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSetup, 6) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetup, 6) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSetup, 8) )
-DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetup, 8) )
-
-#endif
diff --git a/bench/GLVertexAttributesBench.cpp b/bench/GLVertexAttributesBench.cpp
deleted file mode 100644
index 2c073b4..0000000
--- a/bench/GLVertexAttributesBench.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "Benchmark.h"
-#include "SkCanvas.h"
-#include "SkImageEncoder.h"
-
-#if SK_SUPPORT_GPU
-#include "GLBench.h"
-#include "GrShaderCaps.h"
-#include "GrShaderVar.h"
-#include "gl/GrGLContext.h"
-#include "gl/GrGLInterface.h"
-#include "gl/GrGLUtil.h"
-#include "../private/GrGLSL.h"
-#include <stdio.h>
-
-/*
- * This is a native GL benchmark for determining the cost of uploading vertex attributes
- */
-class GLVertexAttributesBench : public GLBench {
-public:
- GLVertexAttributesBench(uint32_t attribs)
- : fTexture(0)
- , fBuffers(0)
- , fProgram(0)
- , fVBO(0)
- , fAttribs(attribs)
- , fStride(2 * sizeof(SkPoint) + fAttribs * sizeof(GrGLfloat) * 4) {
- fName.appendf("GLVertexAttributesBench_%d", fAttribs);
- }
-
-protected:
- const char* onGetName() override { return fName.c_str(); }
- void setup(const GrGLContext*) override;
- void glDraw(int loops, const GrGLContext*) override;
- void teardown(const GrGLInterface*) override;
-
- static const GrGLuint kScreenWidth = 800;
- static const GrGLuint kScreenHeight = 600;
- static const uint32_t kNumTri = 10000;
- static const uint32_t kVerticesPerTri = 3;
- static const uint32_t kDrawMultiplier = 512;
- static const uint32_t kMaxAttribs = 7;
-
-private:
- GrGLuint setupShader(const GrGLContext*, uint32_t attribs, uint32_t maxAttribs);
-
- GrGLuint fTexture;
- SkTArray<GrGLuint> fBuffers;
- GrGLuint fProgram;
- GrGLuint fVBO;
- SkTArray<unsigned char> fVertices;
- uint32_t fAttribs;
- size_t fStride;
- SkString fName;
- typedef Benchmark INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t attribs,
- uint32_t maxAttribs) {
- const GrShaderCaps* shaderCaps = ctx->caps()->shaderCaps();
- const char* version = shaderCaps->versionDeclString();
-
- // setup vertex shader
- GrShaderVar aPosition("a_position", kFloat4_GrSLType, GrShaderVar::kIn_TypeModifier);
- SkTArray<GrShaderVar> aVars;
- SkTArray<GrShaderVar> oVars;
-
- SkString vshaderTxt(version);
- aPosition.appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
-
- for (uint32_t i = 0; i < attribs; i++) {
- SkString aname;
- aname.appendf("a_color_%d", i);
- aVars.push_back(GrShaderVar(aname.c_str(),
- kHalf4_GrSLType,
- GrShaderVar::kIn_TypeModifier));
- aVars.back().appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
-
- }
-
- for (uint32_t i = 0; i < maxAttribs; i++) {
- SkString oname;
- oname.appendf("o_color_%d", i);
- oVars.push_back(GrShaderVar(oname.c_str(),
- kHalf4_GrSLType,
- GrShaderVar::kOut_TypeModifier));
- oVars.back().appendDecl(shaderCaps, &vshaderTxt);
- vshaderTxt.append(";\n");
- }
-
- vshaderTxt.append(
- "void main()\n"
- "{\n"
- "sk_Position = a_position;\n");
-
- for (uint32_t i = 0; i < attribs; i++) {
- vshaderTxt.appendf("%s = %s;\n", oVars[i].c_str(), aVars[i].c_str());
- }
-
- // Passthrough position as a dummy
- for (uint32_t i = attribs; i < maxAttribs; i++) {
- vshaderTxt.appendf("%s = float4(0, 0, 0, 1);\n", oVars[i].c_str());
- }
-
- vshaderTxt.append("}\n");
-
- // setup fragment shader
- SkString fshaderTxt(version);
-
- for (uint32_t i = 0; i < maxAttribs; i++) {
- oVars[i].setTypeModifier(GrShaderVar::kIn_TypeModifier);
- oVars[i].appendDecl(shaderCaps, &fshaderTxt);
- fshaderTxt.append(";\n");
- }
-
- fshaderTxt.append(
- "void main()\n"
- "{\n"
- "sk_FragColor = ");
-
- fshaderTxt.appendf("%s", oVars[0].c_str());
- for (uint32_t i = 1; i < maxAttribs; i++) {
- fshaderTxt.appendf(" + %s", oVars[i].c_str());
- }
-
- fshaderTxt.append(";\n"
- "}\n");
-
- return CreateProgram(ctx, vshaderTxt.c_str(), fshaderTxt.c_str());
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-void GLVertexAttributesBench::setup(const GrGLContext* ctx) {
- const GrGLInterface* gl = ctx->interface();
- fTexture = SetupFramebuffer(gl, kScreenWidth, kScreenHeight);
-
- fProgram = setupShader(ctx, fAttribs, kMaxAttribs);
-
- // setup matrices
- SkMatrix viewMatrices[kNumTri];
- for (uint32_t i = 0 ; i < kNumTri; i++) {
- SkMatrix m = SkMatrix::I();
- m.setScale(0.0001f, 0.0001f);
- viewMatrices[i] = m;
- }
-
- // presetup vertex attributes, color is set to be a light gray no matter how many vertex
- // attributes are used
- float targetColor = 0.9f;
- float colorContribution = targetColor / fAttribs;
- fVertices.reset(static_cast<int>(kVerticesPerTri * kNumTri * fStride));
- for (uint32_t i = 0; i < kNumTri; i++) {
- unsigned char* ptr = &fVertices[static_cast<int>(i * kVerticesPerTri * fStride)];
- SkPoint* p = reinterpret_cast<SkPoint*>(ptr);
- p->set(-1.0f, -1.0f); p++; p->set( 0.0f, 1.0f);
- p = reinterpret_cast<SkPoint*>(ptr + fStride);
- p->set( 1.0f, -1.0f); p++; p->set( 0.0f, 1.0f);
- p = reinterpret_cast<SkPoint*>(ptr + fStride * 2);
- p->set( 1.0f, 1.0f); p++; p->set( 0.0f, 1.0f);
-
- SkPoint* position = reinterpret_cast<SkPoint*>(ptr);
- viewMatrices[i].mapPointsWithStride(position, fStride, kVerticesPerTri);
-
- // set colors
- for (uint32_t j = 0; j < kVerticesPerTri; j++) {
- GrGLfloat* f = reinterpret_cast<GrGLfloat*>(ptr + 2 * sizeof(SkPoint) + fStride * j);
- for (uint32_t k = 0; k < fAttribs * 4; k += 4) {
- f[k] = colorContribution;
- f[k + 1] = colorContribution;
- f[k + 2] = colorContribution;
- f[k + 3] = 1.0f;
- }
- }
- }
-
- GR_GL_CALL(gl, GenBuffers(1, &fVBO));
- fBuffers.push_back(fVBO);
-
- // clear screen
- GR_GL_CALL(gl, ClearColor(0.03f, 0.03f, 0.03f, 1.0f));
- GR_GL_CALL(gl, Clear(GR_GL_COLOR_BUFFER_BIT));
-
- // set us up to draw
- GR_GL_CALL(gl, UseProgram(fProgram));
-}
-
-void GLVertexAttributesBench::glDraw(int loops, const GrGLContext* ctx) {
- const GrGLInterface* gl = ctx->interface();
-
- // upload vertex attributes
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, fVBO));
- GR_GL_CALL(gl, EnableVertexAttribArray(0));
- GR_GL_CALL(gl, VertexAttribPointer(0, 4, GR_GL_FLOAT, GR_GL_FALSE, (GrGLsizei)fStride,
- (GrGLvoid*)0));
-
- size_t runningStride = 2 * sizeof(SkPoint);
- for (uint32_t i = 0; i < fAttribs; i++) {
- int attribId = i + 1;
- GR_GL_CALL(gl, EnableVertexAttribArray(attribId));
- GR_GL_CALL(gl, VertexAttribPointer(attribId, 4, GR_GL_FLOAT, GR_GL_FALSE,
- (GrGLsizei)fStride, (GrGLvoid*)(runningStride)));
- runningStride += sizeof(GrGLfloat) * 4;
- }
-
- GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, fVertices.count(), fVertices.begin(),
- GR_GL_STREAM_DRAW));
-
- uint32_t maxTrianglesPerFlush = kNumTri;
- uint32_t trianglesToDraw = loops * kDrawMultiplier;
-
- while (trianglesToDraw > 0) {
- uint32_t triangles = SkTMin(trianglesToDraw, maxTrianglesPerFlush);
- GR_GL_CALL(gl, DrawArrays(GR_GL_TRIANGLES, 0, kVerticesPerTri * triangles));
- trianglesToDraw -= triangles;
- }
-
-#if 0
- //const char* filename = "/data/local/tmp/out.png";
- SkString filename("out");
- filename.appendf("_%s.png", this->getName());
- DumpImage(gl, kScreenWidth, kScreenHeight, filename.c_str());
-#endif
-}
-
-void GLVertexAttributesBench::teardown(const GrGLInterface* gl) {
- // teardown
- GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, 0));
- GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
- GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
- GR_GL_CALL(gl, DeleteTextures(1, &fTexture));
- GR_GL_CALL(gl, DeleteProgram(fProgram));
- GR_GL_CALL(gl, DeleteBuffers(fBuffers.count(), fBuffers.begin()));
- fBuffers.reset();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-DEF_BENCH( return new GLVertexAttributesBench(0) )
-DEF_BENCH( return new GLVertexAttributesBench(1) )
-DEF_BENCH( return new GLVertexAttributesBench(2) )
-DEF_BENCH( return new GLVertexAttributesBench(3) )
-DEF_BENCH( return new GLVertexAttributesBench(4) )
-DEF_BENCH( return new GLVertexAttributesBench(5) )
-DEF_BENCH( return new GLVertexAttributesBench(6) )
-DEF_BENCH( return new GLVertexAttributesBench(7) )
-#endif
diff --git a/gn/bench.gni b/gn/bench.gni
index 36569e5..e56c2e5 100644
--- a/gn/bench.gni
+++ b/gn/bench.gni
@@ -47,10 +47,6 @@
"$_bench/FSRectBench.cpp",
"$_bench/GameBench.cpp",
"$_bench/GeometryBench.cpp",
- "$_bench/GLBench.cpp",
- "$_bench/GLInstancedArraysBench.cpp",
- "$_bench/GLVec4ScalarBench.cpp",
- "$_bench/GLVertexAttributesBench.cpp",
"$_bench/GMBench.cpp",
"$_bench/GradientBench.cpp",
"$_bench/GrMemoryPoolBench.cpp",