OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkImageEncoder.h" | 10 #include "SkImageEncoder.h" |
11 | 11 |
12 #if SK_SUPPORT_GPU | 12 #if SK_SUPPORT_GPU |
13 #include "GLBench.h" | 13 #include "GLBench.h" |
14 #include "gl/GrGLContext.h" | 14 #include "gl/GrGLContext.h" |
15 #include "gl/GrGLGLSL.h" | |
16 #include "gl/GrGLInterface.h" | 15 #include "gl/GrGLInterface.h" |
17 #include "gl/GrGLUtil.h" | 16 #include "gl/GrGLUtil.h" |
| 17 #include "glsl/GrGLSL.h" |
18 #include "glsl/GrGLSLCaps.h" | 18 #include "glsl/GrGLSLCaps.h" |
19 #include "glsl/GrGLSLShaderVar.h" | 19 #include "glsl/GrGLSLShaderVar.h" |
20 | 20 |
21 /* | 21 /* |
22 * This is a native GL benchmark for instanced arrays vs vertex buffer objects.
To benchmark this | 22 * This is a native GL benchmark for instanced arrays vs vertex buffer objects.
To benchmark this |
23 * functionality, we draw n * kDrawMultipier triangles per run. If this number
is less than | 23 * functionality, we draw n * kDrawMultipier triangles per run. If this number
is less than |
24 * kNumTri then we do a single draw, either with instances, or drawArrays. Othe
rwise we do | 24 * kNumTri then we do a single draw, either with instances, or drawArrays. Othe
rwise we do |
25 * multiple draws. | 25 * multiple draws. |
26 * | 26 * |
27 * Additionally, there is a divisor, which if > 0 will act as a multiplier for t
he number of draws | 27 * Additionally, there is a divisor, which if > 0 will act as a multiplier for t
he number of draws |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 uint32_t fDrawDiv; | 100 uint32_t fDrawDiv; |
101 SkTArray<GrGLuint> fBuffers; | 101 SkTArray<GrGLuint> fBuffers; |
102 GrGLuint fProgram; | 102 GrGLuint fProgram; |
103 GrGLuint fVAO; | 103 GrGLuint fVAO; |
104 GrGLuint fTexture; | 104 GrGLuint fTexture; |
105 }; | 105 }; |
106 | 106 |
107 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 107 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
108 | 108 |
109 GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { | 109 GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { |
110 const char* version = ctx->caps()->glslCaps()->versionDeclString(); | 110 const GrGLSLCaps* glslCaps = ctx->caps()->glslCaps(); |
| 111 const char* version = glslCaps->versionDeclString(); |
111 | 112 |
112 // setup vertex shader | 113 // setup vertex shader |
113 GrGLSLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttri
bute_TypeModifier); | 114 GrGLSLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttri
bute_TypeModifier); |
114 GrGLSLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_T
ypeModifier); | 115 GrGLSLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_T
ypeModifier); |
115 GrGLSLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_
TypeModifier); | 116 GrGLSLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_
TypeModifier); |
116 | 117 |
117 SkString vshaderTxt(version); | 118 SkString vshaderTxt(version); |
118 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 119 aPosition.appendDecl(glslCaps, &vshaderTxt); |
119 vshaderTxt.append(";\n"); | 120 vshaderTxt.append(";\n"); |
120 aColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 121 aColor.appendDecl(glslCaps, &vshaderTxt); |
121 vshaderTxt.append(";\n"); | 122 vshaderTxt.append(";\n"); |
122 oColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 123 oColor.appendDecl(glslCaps, &vshaderTxt); |
123 vshaderTxt.append(";\n"); | 124 vshaderTxt.append(";\n"); |
124 | 125 |
125 vshaderTxt.append( | 126 vshaderTxt.append( |
126 "void main()\n" | 127 "void main()\n" |
127 "{\n" | 128 "{\n" |
128 "gl_Position = vec4(a_position, 0.f, 1.f);\n" | 129 "gl_Position = vec4(a_position, 0.f, 1.f);\n" |
129 "o_color = a_color;\n" | 130 "o_color = a_color;\n" |
130 "}\n"); | 131 "}\n"); |
131 | 132 |
132 const GrGLInterface* gl = ctx->interface(); | 133 const GrGLInterface* gl = ctx->interface(); |
133 | 134 |
134 // setup fragment shader | 135 // setup fragment shader |
135 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut
_TypeModifier); | 136 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut
_TypeModifier); |
136 SkString fshaderTxt(version); | 137 SkString fshaderTxt(version); |
137 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, | 138 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCa
ps, &fshaderTxt); |
138 &fshaderTxt); | |
139 oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | 139 oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); |
140 oColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); | 140 oColor.appendDecl(glslCaps, &fshaderTxt); |
141 fshaderTxt.append(";\n"); | 141 fshaderTxt.append(";\n"); |
142 | 142 |
143 const char* fsOutName; | 143 const char* fsOutName; |
144 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { | 144 if (glslCaps->mustDeclareFragmentShaderOutput()) { |
145 oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); | 145 oFragColor.appendDecl(glslCaps, &fshaderTxt); |
146 fshaderTxt.append(";\n"); | 146 fshaderTxt.append(";\n"); |
147 fsOutName = oFragColor.c_str(); | 147 fsOutName = oFragColor.c_str(); |
148 } else { | 148 } else { |
149 fsOutName = "gl_FragColor"; | 149 fsOutName = "gl_FragColor"; |
150 } | 150 } |
151 | 151 |
152 fshaderTxt.appendf( | 152 fshaderTxt.appendf( |
153 "void main()\n" | 153 "void main()\n" |
154 "{\n" | 154 "{\n" |
155 "%s = vec4(o_color, 1.0f);\n" | 155 "%s = vec4(o_color, 1.0f);\n" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 1) ) | 389 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 1) ) |
390 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 1) ) | 390 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 1) ) |
391 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 2) ) | 391 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 2) ) |
392 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 2) ) | 392 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 2) ) |
393 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 4) ) | 393 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 4) ) |
394 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 4) ) | 394 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 4) ) |
395 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 8) ) | 395 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 8) ) |
396 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 8) ) | 396 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 8) ) |
397 | 397 |
398 #endif | 398 #endif |
OLD | NEW |