diff options
author | ethannicholas <ethannicholas@google.com> | 2016-10-10 10:09:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-10 10:09:00 -0700 |
commit | dcfe6dba4a335e50e86ff68e3252065d4197432c (patch) | |
tree | 6953805849e283220d56f4feac3358b5efea3cc9 /bench | |
parent | 95304e395c46bdd40decbb7ccd46939886cc1244 (diff) |
Turned on SkSL->GLSL compiler
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2288033003
Committed: https://skia.googlesource.com/skia/+/9b0fe3d125f237d9884732a48414fa85fc71b4e3
Committed: https://skia.googlesource.com/skia/+/b12b3c6908c62c908b3680be01e3b5bfd30de310
Committed: https://skia.googlesource.com/skia/+/f008b0a59f45c0d4bea3e66faf3b01805009ec89
Committed: https://skia.googlesource.com/skia/+/08b2ccf398e2b81bc05d2c105837e5419899469b
Review-Url: https://codereview.chromium.org/2288033003
Diffstat (limited to 'bench')
-rw-r--r-- | bench/GLBench.cpp | 29 | ||||
-rw-r--r-- | bench/GLBench.h | 4 | ||||
-rw-r--r-- | bench/GLInstancedArraysBench.cpp | 4 | ||||
-rw-r--r-- | bench/GLVec4ScalarBench.cpp | 4 | ||||
-rw-r--r-- | bench/GLVertexAttributesBench.cpp | 6 |
5 files changed, 29 insertions, 18 deletions
diff --git a/bench/GLBench.cpp b/bench/GLBench.cpp index 8cf41c2056..b6975508cf 100644 --- a/bench/GLBench.cpp +++ b/bench/GLBench.cpp @@ -11,7 +11,10 @@ #include "GrGpu.h" #include "GrTest.h" #include "gl/GrGLContext.h" +#include "gl/builders/GrGLShaderStringBuilder.h" +#include "SkSLCompiler.h" #include <stdio.h> +#include <string> const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) { // This bench exclusively tests GL calls directly @@ -61,13 +64,26 @@ void GLBench::onDraw(int loops, SkCanvas* canvas) { canvas->getGrContext()->resetContext(); } -GrGLuint GLBench::CompileShader(const GrGLInterface* gl, const char* shaderSrc, GrGLenum type) { +GrGLuint GLBench::CompileShader(const GrGLContext* context, const char* sksl, GrGLenum type) { + const GrGLInterface* gl = context->interface(); + std::string glsl; + bool result = context->compiler()->toGLSL(type == GR_GL_VERTEX_SHADER + ? SkSL::Program::kVertex_Kind + : SkSL::Program::kFragment_Kind, + std::string(sksl), + GrGLSkSLCapsForContext(*context), + &glsl); + if (!result) { + 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 - GR_GL_CALL(gl, ShaderSource(shader, 1, &shaderSrc, nullptr)); + 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)); @@ -84,10 +100,11 @@ GrGLuint GLBench::CompileShader(const GrGLInterface* gl, const char* shaderSrc, return shader; } -GrGLuint GLBench::CreateProgram(const GrGLInterface* gl, const char* vshader, const char* fshader) { - - GrGLuint vertexShader = CompileShader(gl, vshader, GR_GL_VERTEX_SHADER); - GrGLuint fragmentShader = CompileShader(gl, fshader, GR_GL_FRAGMENT_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()); diff --git a/bench/GLBench.h b/bench/GLBench.h index 9033b12e55..a358894cb4 100644 --- a/bench/GLBench.h +++ b/bench/GLBench.h @@ -35,8 +35,8 @@ protected: virtual void teardown(const GrGLInterface*)=0; void onDraw(int loops, SkCanvas*) override; virtual void glDraw(int loops, const GrGLContext*)=0; - static GrGLuint CompileShader(const GrGLInterface*, const char* shaderSrc, GrGLenum type); - static GrGLuint CreateProgram(const GrGLInterface*, const char* vshader, const char* fshader); + 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); diff --git a/bench/GLInstancedArraysBench.cpp b/bench/GLInstancedArraysBench.cpp index d89c087605..e98ab72587 100644 --- a/bench/GLInstancedArraysBench.cpp +++ b/bench/GLInstancedArraysBench.cpp @@ -130,8 +130,6 @@ GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { "o_color = a_color;\n" "}\n"); - const GrGLInterface* gl = ctx->interface(); - // setup fragment shader GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier); SkString fshaderTxt(version); @@ -155,7 +153,7 @@ GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { "%s = vec4(o_color, 1.0);\n" "}\n", fsOutName); - return CreateProgram(gl, vshaderTxt.c_str(), fshaderTxt.c_str()); + return CreateProgram(ctx, vshaderTxt.c_str(), fshaderTxt.c_str()); } template<typename Func> diff --git a/bench/GLVec4ScalarBench.cpp b/bench/GLVec4ScalarBench.cpp index e3837a7225..373ae6b7bc 100644 --- a/bench/GLVec4ScalarBench.cpp +++ b/bench/GLVec4ScalarBench.cpp @@ -124,8 +124,6 @@ GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { " o_color = a_color;\n" "}\n"); - const GrGLInterface* gl = ctx->interface(); - // 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. @@ -186,7 +184,7 @@ GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { "}\n", fsOutName); - return CreateProgram(gl, vshaderTxt.c_str(), fshaderTxt.c_str()); + return CreateProgram(ctx, vshaderTxt.c_str(), fshaderTxt.c_str()); } template<typename Func> diff --git a/bench/GLVertexAttributesBench.cpp b/bench/GLVertexAttributesBench.cpp index 040ca18300..f579a3ea39 100644 --- a/bench/GLVertexAttributesBench.cpp +++ b/bench/GLVertexAttributesBench.cpp @@ -114,8 +114,6 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a vshaderTxt.append("}\n"); - const GrGLInterface* gl = ctx->interface(); - // setup fragment shader GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier); SkString fshaderTxt(version); @@ -127,7 +125,7 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a fshaderTxt.append(";\n"); fsOutName = oFragColor.c_str(); } else { - fsOutName = "gl_FragColor"; + fsOutName = "sk_FragColor"; } for (uint32_t i = 0; i < maxAttribs; i++) { @@ -149,7 +147,7 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a fshaderTxt.append(";\n" "}\n"); - return CreateProgram(gl, vshaderTxt.c_str(), fshaderTxt.c_str()); + return CreateProgram(ctx, vshaderTxt.c_str(), fshaderTxt.c_str()); } /////////////////////////////////////////////////////////////////////////////////////////////////// |