Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: bench/GLBench.cpp

Issue 2288033003: Turned on SkSL->GLSL compiler (Closed)
Patch Set: changed <iostream> to <ostream> Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/GLBench.h ('k') | bench/GLInstancedArraysBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GLBench.h" 8 #include "GLBench.h"
9 9
10 #if SK_SUPPORT_GPU 10 #if SK_SUPPORT_GPU
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 #include "GrTest.h" 12 #include "GrTest.h"
13 #include "gl/GrGLContext.h" 13 #include "gl/GrGLContext.h"
14 #include "gl/builders/GrGLShaderStringBuilder.h"
15 #include "SkSLCompiler.h"
14 #include <stdio.h> 16 #include <stdio.h>
17 #include <string>
15 18
16 const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) { 19 const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) {
17 // This bench exclusively tests GL calls directly 20 // This bench exclusively tests GL calls directly
18 if (nullptr == canvas->getGrContext()) { 21 if (nullptr == canvas->getGrContext()) {
19 return nullptr; 22 return nullptr;
20 } 23 }
21 GrContext* context = canvas->getGrContext(); 24 GrContext* context = canvas->getGrContext();
22 GrGpu* gpu = context->getGpu(); 25 GrGpu* gpu = context->getGpu();
23 if (!gpu) { 26 if (!gpu) {
24 SkDebugf("Couldn't get Gr gpu."); 27 SkDebugf("Couldn't get Gr gpu.");
(...skipping 29 matching lines...) Expand all
54 57
55 void GLBench::onDraw(int loops, SkCanvas* canvas) { 58 void GLBench::onDraw(int loops, SkCanvas* canvas) {
56 const GrGLContext* ctx = this->getGLContext(canvas); 59 const GrGLContext* ctx = this->getGLContext(canvas);
57 if (!ctx) { 60 if (!ctx) {
58 return; 61 return;
59 } 62 }
60 this->glDraw(loops, ctx); 63 this->glDraw(loops, ctx);
61 canvas->getGrContext()->resetContext(); 64 canvas->getGrContext()->resetContext();
62 } 65 }
63 66
64 GrGLuint GLBench::CompileShader(const GrGLInterface* gl, const char* shaderSrc, GrGLenum type) { 67 GrGLuint GLBench::CompileShader(const GrGLContext* context, const char* sksl, Gr GLenum type) {
68 const GrGLInterface* gl = context->interface();
69 std::string glsl;
70 bool result = context->compiler()->toGLSL(type == GR_GL_VERTEX_SHADER
71 ? SkSL::Prog ram::kVertex_Kind
72 : SkSL::Prog ram::kFragment_Kind,
73 std::string(sksl),
74 GrGLSkSLCapsForContext(*context),
75 &glsl);
76 if (!result) {
77 SkDebugf("SkSL compilation failed:\n%s\n%s\n", sksl,
78 context->compiler()->errorText().c_str());
79 }
65 GrGLuint shader; 80 GrGLuint shader;
66 // Create the shader object 81 // Create the shader object
67 GR_GL_CALL_RET(gl, shader, CreateShader(type)); 82 GR_GL_CALL_RET(gl, shader, CreateShader(type));
68 83
69 // Load the shader source 84 // Load the shader source
70 GR_GL_CALL(gl, ShaderSource(shader, 1, &shaderSrc, nullptr)); 85 const char* glslPtr = glsl.c_str();
86 GR_GL_CALL(gl, ShaderSource(shader, 1, (const char**) &glslPtr, nullptr));
71 87
72 // Compile the shader 88 // Compile the shader
73 GR_GL_CALL(gl, CompileShader(shader)); 89 GR_GL_CALL(gl, CompileShader(shader));
74 90
75 // Check for compile time errors 91 // Check for compile time errors
76 GrGLint success = GR_GL_INIT_ZERO; 92 GrGLint success = GR_GL_INIT_ZERO;
77 GrGLchar infoLog[512]; 93 GrGLchar infoLog[512];
78 GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &success)); 94 GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &success));
79 if (!success) { 95 if (!success) {
80 GR_GL_CALL(gl, GetShaderInfoLog(shader, 512, nullptr, infoLog)); 96 GR_GL_CALL(gl, GetShaderInfoLog(shader, 512, nullptr, infoLog));
81 SkDebugf("ERROR::SHADER::COMPLIATION_FAILED: %s\n", infoLog); 97 SkDebugf("ERROR::SHADER::COMPLIATION_FAILED: %s\n", infoLog);
82 } 98 }
83 99
84 return shader; 100 return shader;
85 } 101 }
86 102
87 GrGLuint GLBench::CreateProgram(const GrGLInterface* gl, const char* vshader, co nst char* fshader) { 103 GrGLuint GLBench::CreateProgram(const GrGLContext* context, const char* vshader,
88 104 const char* fshader) {
89 GrGLuint vertexShader = CompileShader(gl, vshader, GR_GL_VERTEX_SHADER); 105 const GrGLInterface* gl = context->interface();
90 GrGLuint fragmentShader = CompileShader(gl, fshader, GR_GL_FRAGMENT_SHADER); 106 GrGLuint vertexShader = CompileShader(context, vshader, GR_GL_VERTEX_SHADER) ;
107 GrGLuint fragmentShader = CompileShader(context, fshader, GR_GL_FRAGMENT_SHA DER);
91 108
92 GrGLuint shaderProgram; 109 GrGLuint shaderProgram;
93 GR_GL_CALL_RET(gl, shaderProgram, CreateProgram()); 110 GR_GL_CALL_RET(gl, shaderProgram, CreateProgram());
94 GR_GL_CALL(gl, AttachShader(shaderProgram, vertexShader)); 111 GR_GL_CALL(gl, AttachShader(shaderProgram, vertexShader));
95 GR_GL_CALL(gl, AttachShader(shaderProgram, fragmentShader)); 112 GR_GL_CALL(gl, AttachShader(shaderProgram, fragmentShader));
96 GR_GL_CALL(gl, LinkProgram(shaderProgram)); 113 GR_GL_CALL(gl, LinkProgram(shaderProgram));
97 114
98 // Check for linking errors 115 // Check for linking errors
99 GrGLint success = GR_GL_INIT_ZERO; 116 GrGLint success = GR_GL_INIT_ZERO;
100 GrGLchar infoLog[512]; 117 GrGLchar infoLog[512];
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 bm.setPixels(readback.get()); 183 bm.setPixels(readback.get());
167 184
168 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100 )) { 185 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100 )) {
169 SkDebugf("------ failed to encode %s\n", filename); 186 SkDebugf("------ failed to encode %s\n", filename);
170 remove(filename); // remove any partial file 187 remove(filename); // remove any partial file
171 return; 188 return;
172 } 189 }
173 } 190 }
174 191
175 #endif 192 #endif
OLDNEW
« no previous file with comments | « bench/GLBench.h ('k') | bench/GLInstancedArraysBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698