Remove shader text trace events and simplify the SKSL/GLSL printing code

- Moves the pretty-printer and line-by-line printer into a new GrShaderUtils.
- Maintain strings as SkSL::String longer, to avoid possibly re-converting
  from char* when we need to print them.
- GL shader compilation doesn't need the SkSL settings, so stop plumbing that.
- Converting SkSL to GLSL was taking the GL enum to specify the kind of shader,
  but only used it to convert to a SkSL::Program::Kind. Just take that. To make
  this simpler, move the GLSL printing code into that function, clumped with
  the SkSL printing code. Reuse that banner printer in GrGLPrintShader, too.

Change-Id: I4536547604612a6fa1596e5a8e97f6322e12a1fb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/211583
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/gn/gpu.gni b/gn/gpu.gni
index dbce1fc..3f8c4d2 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -209,10 +209,10 @@
   "$_src/gpu/GrTracing.h",
   "$_src/gpu/GrTestUtils.cpp",
   "$_src/gpu/GrTestUtils.h",
+  "$_src/gpu/GrShaderUtils.cpp",
+  "$_src/gpu/GrShaderUtils.h",
   "$_src/gpu/GrShaderVar.cpp",
   "$_src/gpu/GrShaderVar.h",
-  "$_src/gpu/GrSKSLPrettyPrint.cpp",
-  "$_src/gpu/GrSKSLPrettyPrint.h",
   "$_src/gpu/GrSoftwarePathRenderer.cpp",
   "$_src/gpu/GrSoftwarePathRenderer.h",
   "$_src/gpu/GrSurfacePriv.h",
diff --git a/src/gpu/GrSKSLPrettyPrint.h b/src/gpu/GrSKSLPrettyPrint.h
deleted file mode 100644
index 9ca1de2..0000000
--- a/src/gpu/GrSKSLPrettyPrint.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef GrSKSLPrettyPrint_DEFINED
-#define GrSKSLPrettyPrint_DEFINED
-
-#include "src/sksl/SkSLString.h"
-
-namespace GrSKSLPrettyPrint {
-SkSL::String PrettyPrint(const SkSL::String& string);
-};
-
-#endif
diff --git a/src/gpu/GrSKSLPrettyPrint.cpp b/src/gpu/GrShaderUtils.cpp
similarity index 91%
rename from src/gpu/GrSKSLPrettyPrint.cpp
rename to src/gpu/GrShaderUtils.cpp
index 0b4bd21..5367202 100644
--- a/src/gpu/GrSKSLPrettyPrint.cpp
+++ b/src/gpu/GrShaderUtils.cpp
@@ -1,13 +1,15 @@
 /*
- * Copyright 2014 Google Inc.
+ * Copyright 2019 Google LLC
  *
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
-#include "src/gpu/GrSKSLPrettyPrint.h"
+
+#include "include/core/SkString.h"
+#include "src/gpu/GrShaderUtils.h"
 #include "src/sksl/SkSLString.h"
 
-namespace GrSKSLPrettyPrint {
+namespace GrShaderUtils {
 
 class GLSLPrettyPrint {
 public:
@@ -186,4 +188,15 @@
     return pp.prettify(string);
 }
 
-}  // namespace GrSKSLPrettyPrint
+// Prints shaders one line at the time. This ensures they don't get truncated by the adb log.
+void PrintLineByLine(const char* header, const SkSL::String& text) {
+    SkSL::String pretty = PrettyPrint(text);
+    SkDebugf("%s\n", header);
+    SkTArray<SkString> lines;
+    SkStrSplit(pretty.c_str(), "\n", kStrict_SkStrSplitMode, &lines);
+    for (int i = 0; i < lines.count(); ++i) {
+        SkDebugf("%4i\t%s\n", i + 1, lines[i].c_str());
+    }
+}
+
+}  // namespace
diff --git a/src/gpu/GrShaderUtils.h b/src/gpu/GrShaderUtils.h
new file mode 100644
index 0000000..731d546
--- /dev/null
+++ b/src/gpu/GrShaderUtils.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2019 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrShaderUtils_DEFINED
+#define GrShaderUtils_DEFINED
+
+#include "include/core/SkTypes.h"
+#include "src/sksl/SkSLString.h"
+
+namespace GrShaderUtils {
+
+SkSL::String PrettyPrint(const SkSL::String& string);
+void PrintLineByLine(const char* header, const SkSL::String& text);
+
+}
+
+#endif
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 62d882d..d90a91e 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -3443,18 +3443,16 @@
     SkSL::Program::Settings settings;
     settings.fCaps = shaderCaps;
     SkSL::String glsl;
-    std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, GR_GL_VERTEX_SHADER,
+    std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kVertex_Kind,
                                                           sksl, settings, &glsl);
     GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[progIdx].fProgram,
-                                                  GR_GL_VERTEX_SHADER, glsl.c_str(), glsl.size(),
-                                                  &fStats, settings);
+                                                  GR_GL_VERTEX_SHADER, glsl, &fStats);
     SkASSERT(program->fInputs.isEmpty());
 
     sksl.assign(fshaderTxt.c_str(), fshaderTxt.size());
-    program = GrSkSLtoGLSL(*fGLContext, GR_GL_FRAGMENT_SHADER, sksl, settings, &glsl);
+    program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kFragment_Kind, sksl, settings, &glsl);
     GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[progIdx].fProgram,
-                                                  GR_GL_FRAGMENT_SHADER, glsl.c_str(), glsl.size(),
-                                                  &fStats, settings);
+                                                  GR_GL_FRAGMENT_SHADER, glsl, &fStats);
     SkASSERT(program->fInputs.isEmpty());
 
     GL_CALL(LinkProgram(fCopyPrograms[progIdx].fProgram));
@@ -3597,18 +3595,16 @@
     SkSL::Program::Settings settings;
     settings.fCaps = shaderCaps;
     SkSL::String glsl;
-    std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, GR_GL_VERTEX_SHADER,
+    std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kVertex_Kind,
                                                           sksl, settings, &glsl);
     GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fMipmapPrograms[progIdx].fProgram,
-                                                  GR_GL_VERTEX_SHADER, glsl.c_str(), glsl.size(),
-                                                  &fStats, settings);
+                                                  GR_GL_VERTEX_SHADER, glsl, &fStats);
     SkASSERT(program->fInputs.isEmpty());
 
     sksl.assign(fshaderTxt.c_str(), fshaderTxt.size());
-    program = GrSkSLtoGLSL(*fGLContext, GR_GL_FRAGMENT_SHADER, sksl, settings, &glsl);
+    program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kFragment_Kind, sksl, settings, &glsl);
     GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fMipmapPrograms[progIdx].fProgram,
-                                                  GR_GL_FRAGMENT_SHADER, glsl.c_str(), glsl.size(),
-                                                  &fStats, settings);
+                                                  GR_GL_FRAGMENT_SHADER, glsl, &fStats);
     SkASSERT(program->fInputs.isEmpty());
 
     GL_CALL(LinkProgram(fMipmapPrograms[progIdx].fProgram));
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 08c56b2..ddd3525 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -18,8 +18,8 @@
 #include "src/gpu/GrCoordTransform.h"
 #include "src/gpu/GrPersistentCacheUtils.h"
 #include "src/gpu/GrProgramDesc.h"
-#include "src/gpu/GrSKSLPrettyPrint.h"
 #include "src/gpu/GrShaderCaps.h"
+#include "src/gpu/GrShaderUtils.h"
 #include "src/gpu/GrSwizzle.h"
 #include "src/gpu/gl/GrGLGpu.h"
 #include "src/gpu/gl/GrGLProgram.h"
@@ -85,21 +85,17 @@
     return fGpu->caps();
 }
 
-bool GrGLProgramBuilder::compileAndAttachShaders(const char* glsl,
-                                                 int length,
+bool GrGLProgramBuilder::compileAndAttachShaders(const SkSL::String& glsl,
                                                  GrGLuint programId,
                                                  GrGLenum type,
                                                  SkTDArray<GrGLuint>* shaderIds,
-                                                 const SkSL::Program::Settings& settings,
                                                  const SkSL::Program::Inputs& inputs) {
     GrGLGpu* gpu = this->gpu();
     GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(),
                                                    programId,
                                                    type,
                                                    glsl,
-                                                   length,
-                                                   gpu->stats(),
-                                                   settings);
+                                                   gpu->stats());
     if (!shaderId) {
         return false;
     }
@@ -283,7 +279,7 @@
                 settings.fForceHighPrecision = true;
             }
             std::unique_ptr<SkSL::Program> fs = GrSkSLtoGLSL(gpu()->glContext(),
-                                                             GR_GL_FRAGMENT_SHADER,
+                                                             SkSL::Program::kFragment_Kind,
                                                              *sksl[kFragment_GrShaderType],
                                                              settings,
                                                              &glsl[kFragment_GrShaderType]);
@@ -298,10 +294,8 @@
             this->addInputVars(inputs);
             this->computeCountsAndStrides(programID, primProc, false);
         }
-        if (!this->compileAndAttachShaders(glsl[kFragment_GrShaderType].c_str(),
-                                           glsl[kFragment_GrShaderType].size(), programID,
-                                           GR_GL_FRAGMENT_SHADER, &shadersToDelete, settings,
-                                           inputs)) {
+        if (!this->compileAndAttachShaders(glsl[kFragment_GrShaderType], programID,
+                                           GR_GL_FRAGMENT_SHADER, &shadersToDelete, inputs)) {
             this->cleanupProgram(programID, shadersToDelete);
             return nullptr;
         }
@@ -309,7 +303,7 @@
         if (glsl[kVertex_GrShaderType].empty()) {
             // Don't have cached GLSL, need to compile SkSL->GLSL
             std::unique_ptr<SkSL::Program> vs = GrSkSLtoGLSL(gpu()->glContext(),
-                                                             GR_GL_VERTEX_SHADER,
+                                                             SkSL::Program::kVertex_Kind,
                                                              *sksl[kVertex_GrShaderType],
                                                              settings,
                                                              &glsl[kVertex_GrShaderType]);
@@ -318,10 +312,8 @@
                 return nullptr;
             }
         }
-        if (!this->compileAndAttachShaders(glsl[kVertex_GrShaderType].c_str(),
-                                           glsl[kVertex_GrShaderType].size(), programID,
-                                           GR_GL_VERTEX_SHADER, &shadersToDelete, settings,
-                                           inputs)) {
+        if (!this->compileAndAttachShaders(glsl[kVertex_GrShaderType], programID,
+                                           GR_GL_VERTEX_SHADER, &shadersToDelete, inputs)) {
             this->cleanupProgram(programID, shadersToDelete);
             return nullptr;
         }
@@ -337,7 +329,7 @@
                 // Don't have cached GLSL, need to compile SkSL->GLSL
                 std::unique_ptr<SkSL::Program> gs;
                 gs = GrSkSLtoGLSL(gpu()->glContext(),
-                                  GR_GL_GEOMETRY_SHADER,
+                                  SkSL::Program::kGeometry_Kind,
                                   *sksl[kGeometry_GrShaderType],
                                   settings,
                                   &glsl[kGeometry_GrShaderType]);
@@ -346,10 +338,8 @@
                     return nullptr;
                 }
             }
-            if (!this->compileAndAttachShaders(glsl[kGeometry_GrShaderType].c_str(),
-                                               glsl[kGeometry_GrShaderType].size(), programID,
-                                               GR_GL_GEOMETRY_SHADER, &shadersToDelete, settings,
-                                               inputs)) {
+            if (!this->compileAndAttachShaders(glsl[kGeometry_GrShaderType], programID,
+                                               GR_GL_GEOMETRY_SHADER, &shadersToDelete, inputs)) {
                 this->cleanupProgram(programID, shadersToDelete);
                 return nullptr;
             }
@@ -360,21 +350,18 @@
         if (checkLinked) {
             if (!this->checkLinkStatus(programID)) {
                 GL_CALL(DeleteProgram(programID));
-                SkDebugf("VS:\n");
                 GrGLPrintShader(fGpu->glContext(),
-                                GR_GL_VERTEX_SHADER,
+                                SkSL::Program::kVertex_Kind,
                                 fVS.fCompilerString,
                                 settings);
                 if (primProc.willUseGeoShader()) {
-                    SkDebugf("\nGS:\n");
                     GrGLPrintShader(fGpu->glContext(),
-                                    GR_GL_GEOMETRY_SHADER,
+                                    SkSL::Program::kGeometry_Kind,
                                     fGS.fCompilerString,
                                     settings);
                 }
-                SkDebugf("\nFS:\n");
                 GrGLPrintShader(fGpu->glContext(),
-                                GR_GL_FRAGMENT_SHADER,
+                                SkSL::Program::kFragment_Kind,
                                 fFS.fCompilerString,
                                 settings);
                 return nullptr;
@@ -389,7 +376,7 @@
 #if GR_TEST_UTILS
         if (fGpu->getContext()->priv().options().fCacheSKSL) {
             for (int i = 0; i < kGrShaderTypeCount; ++i) {
-                glsl[i] = GrSKSLPrettyPrint::PrettyPrint(*sksl[i]);
+                glsl[i] = GrShaderUtils::PrettyPrint(*sksl[i]);
             }
             isSkSL = true;
         }
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index 54fc57b..cde80ae 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -52,12 +52,10 @@
                        const GrTextureProxy* const primProcProxies[], GrProgramDesc*);
 
     void addInputVars(const SkSL::Program::Inputs& inputs);
-    bool compileAndAttachShaders(const char* glsl,
-                                 int length,
+    bool compileAndAttachShaders(const SkSL::String& glsl,
                                  GrGLuint programId,
                                  GrGLenum type,
                                  SkTDArray<GrGLuint>* shaderIds,
-                                 const SkSL::Program::Settings& settings,
                                  const SkSL::Program::Inputs& inputs);
 
     void computeCountsAndStrides(GrGLuint programID, const GrPrimitiveProcessor& primProc,
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
index b885e09..0d7a29b 100644
--- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
@@ -6,109 +6,62 @@
  */
 
 #include "src/core/SkAutoMalloc.h"
-#include "src/core/SkTraceEvent.h"
-#include "src/gpu/GrSKSLPrettyPrint.h"
+#include "src/gpu/GrShaderUtils.h"
 #include "src/gpu/gl/GrGLGpu.h"
 #include "src/gpu/gl/builders/GrGLShaderStringBuilder.h"
 #include "src/sksl/SkSLCompiler.h"
 #include "src/sksl/SkSLGLSLCodeGenerator.h"
 #include "src/sksl/ir/SkSLProgram.h"
 
-#define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X)
-#define GL_CALL_RET(R, X) GR_GL_CALL_RET(gpu->glInterface(), R, X)
-
 // Print the source code for all shaders generated.
 static const bool gPrintSKSL = false;
 static const bool gPrintGLSL = false;
 
-static void print_source_lines_with_numbers(const char* source,
-                                            std::function<void(const char*)> println) {
-    SkTArray<SkString> lines;
-    SkStrSplit(source, "\n", kStrict_SkStrSplitMode, &lines);
-    for (int i = 0; i < lines.count(); ++i) {
-        SkString& line = lines[i];
-        line.prependf("%4i\t", i + 1);
-        println(line.c_str());
-    }
-}
-
-// Prints shaders one line at the time. This ensures they don't get truncated by the adb log.
-static void print_sksl_line_by_line(const SkSL::String& sksl,
-                                    std::function<void(const char*)> println = [](const char* ln) {
-                                        SkDebugf("%s\n", ln);
-                                    }) {
-    SkSL::String pretty = GrSKSLPrettyPrint::PrettyPrint(sksl);
-    println("SKSL:");
-    print_source_lines_with_numbers(pretty.c_str(), println);
-}
-
-static void print_glsl_line_by_line(const SkSL::String& glsl,
-                                    std::function<void(const char*)> println = [](const char* ln) {
-                                        SkDebugf("%s\n", ln);
-                                    }) {
-    println("GLSL:");
-    print_source_lines_with_numbers(glsl.c_str(), println);
-}
-
-void print_shader_banner(GrGLenum type) {
+void print_shader_banner(SkSL::Program::Kind programKind) {
     const char* typeName = "Unknown";
-    switch (type) {
-        case GR_GL_VERTEX_SHADER: typeName = "Vertex"; break;
-        case GR_GL_GEOMETRY_SHADER: typeName = "Geometry"; break;
-        case GR_GL_FRAGMENT_SHADER: typeName = "Fragment"; break;
+    switch (programKind) {
+        case SkSL::Program::kVertex_Kind:   typeName = "Vertex";   break;
+        case SkSL::Program::kGeometry_Kind: typeName = "Geometry"; break;
+        case SkSL::Program::kFragment_Kind: typeName = "Fragment"; break;
+        default: break;
     }
     SkDebugf("---- %s shader ----------------------------------------------------\n", typeName);
 }
 
-std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context, GrGLenum type,
+std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context,
+                                            SkSL::Program::Kind programKind,
                                             const SkSL::String& sksl,
                                             const SkSL::Program::Settings& settings,
                                             SkSL::String* glsl) {
-    // Trace event for shader preceding driver compilation
-    bool traceShader;
-    TRACE_EVENT_CATEGORY_GROUP_ENABLED("skia.gpu", &traceShader);
-    if (traceShader) {
-        SkString shaderDebugString;
-        print_sksl_line_by_line(sksl, [&](const char* ln) {
-            shaderDebugString.append(ln);
-            shaderDebugString.append("\n");
-        });
-        TRACE_EVENT_INSTANT1("skia.gpu", "skia_gpu::GLShader",
-                             TRACE_EVENT_SCOPE_THREAD, "shader",
-                             TRACE_STR_COPY(shaderDebugString.c_str()));
-    }
-
     SkSL::Compiler* compiler = context.compiler();
     std::unique_ptr<SkSL::Program> program;
-    SkSL::Program::Kind programKind;
-    switch (type) {
-        case GR_GL_VERTEX_SHADER:   programKind = SkSL::Program::kVertex_Kind;   break;
-        case GR_GL_FRAGMENT_SHADER: programKind = SkSL::Program::kFragment_Kind; break;
-        case GR_GL_GEOMETRY_SHADER: programKind = SkSL::Program::kGeometry_Kind; break;
-        default: SK_ABORT("unsupported shader kind");
-    }
     program = compiler->convertProgram(programKind, sksl, settings);
     if (!program || !compiler->toGLSL(*program, glsl)) {
         SkDebugf("SKSL compilation error\n----------------------\n");
-        print_sksl_line_by_line(sksl);
+        GrShaderUtils::PrintLineByLine("SKSL:", sksl);
         SkDebugf("\nErrors:\n%s\n", compiler->errorText().c_str());
         SkDEBUGFAIL("SKSL compilation failed!\n");
         return nullptr;
     }
-    if (gPrintSKSL) {
-        print_shader_banner(type);
-        print_sksl_line_by_line(sksl);
+
+    if (gPrintSKSL || gPrintGLSL) {
+        print_shader_banner(programKind);
+        if (gPrintSKSL) {
+            GrShaderUtils::PrintLineByLine("SKSL:", sksl);
+        }
+        if (gPrintGLSL) {
+            GrShaderUtils::PrintLineByLine("GLSL:", *glsl);
+        }
     }
+
     return program;
 }
 
 GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
                                     GrGLuint programId,
                                     GrGLenum type,
-                                    const char* glsl,
-                                    int glslLength,
-                                    GrGpu::Stats* stats,
-                                    const SkSL::Program::Settings& settings) {
+                                    const SkSL::String& glsl,
+                                    GrGpu::Stats* stats) {
     const GrGLInterface* gli = glCtx.interface();
 
     // Specify GLSL source to the driver.
@@ -117,7 +70,9 @@
     if (0 == shaderId) {
         return 0;
     }
-    GR_GL_CALL(gli, ShaderSource(shaderId, 1, &glsl, &glslLength));
+    const GrGLchar* source = glsl.c_str();
+    GrGLint sourceLength = glsl.size();
+    GR_GL_CALL(gli, ShaderSource(shaderId, 1, &source, &sourceLength));
 
     stats->incShaderCompilations();
     GR_GL_CALL(gli, CompileShader(shaderId));
@@ -133,7 +88,7 @@
 
         if (!compiled) {
             SkDebugf("GLSL compilation error\n----------------------\n");
-            print_glsl_line_by_line(glsl);
+            GrShaderUtils::PrintLineByLine("GLSL:", glsl);
             GrGLint infoLen = GR_GL_INIT_ZERO;
             GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_INFO_LOG_LENGTH, &infoLen));
             SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
@@ -154,11 +109,6 @@
         }
     }
 
-    if (gPrintGLSL) {
-        print_shader_banner(type);
-        print_glsl_line_by_line(glsl);
-    }
-
     // Attach the shader, but defer deletion until after we have linked the program.
     // This works around a bug in the Android emulator's GLES2 wrapper which
     // will immediately delete the shader object and free its memory even though it's
@@ -167,11 +117,12 @@
     return shaderId;
 }
 
-void GrGLPrintShader(const GrGLContext& context, GrGLenum type, const SkSL::String& sksl,
-                     const SkSL::Program::Settings& settings) {
-    print_sksl_line_by_line(sksl);
+void GrGLPrintShader(const GrGLContext& context, SkSL::Program::Kind programKind,
+                     const SkSL::String& sksl, const SkSL::Program::Settings& settings) {
+    print_shader_banner(programKind);
+    GrShaderUtils::PrintLineByLine("SKSL:", sksl);
     SkSL::String glsl;
-    if (GrSkSLtoGLSL(context, type, sksl, settings, &glsl)) {
-        print_glsl_line_by_line(glsl);
+    if (GrSkSLtoGLSL(context, programKind, sksl, settings, &glsl)) {
+        GrShaderUtils::PrintLineByLine("GLSL:", glsl);
     }
 }
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.h b/src/gpu/gl/builders/GrGLShaderStringBuilder.h
index 2cbff90..bb861c3 100644
--- a/src/gpu/gl/builders/GrGLShaderStringBuilder.h
+++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.h
@@ -14,7 +14,8 @@
 #include "src/gpu/gl/GrGLContext.h"
 #include "src/sksl/SkSLGLSLCodeGenerator.h"
 
-std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context, GrGLenum type,
+std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context,
+                                            SkSL::Program::Kind programKind,
                                             const SkSL::String& sksl,
                                             const SkSL::Program::Settings& settings,
                                             SkSL::String* glsl);
@@ -22,12 +23,10 @@
 GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
                                     GrGLuint programId,
                                     GrGLenum type,
-                                    const char* glsl,
-                                    int glslLength,
-                                    GrGpu::Stats*,
-                                    const SkSL::Program::Settings& settings);
+                                    const SkSL::String& glsl,
+                                    GrGpu::Stats*);
 
-void GrGLPrintShader(const GrGLContext&, GrGLenum type, const SkSL::String& sksl,
+void GrGLPrintShader(const GrGLContext&, SkSL::Program::Kind programKind, const SkSL::String& sksl,
                      const SkSL::Program::Settings&);
 
 #endif
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.cpp b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
index 2c5f04c..fcd885e 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.cpp
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
@@ -9,7 +9,7 @@
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrPersistentCacheUtils.h"
 #include "src/gpu/GrShaderCaps.h"
-#include "src/gpu/GrSKSLPrettyPrint.h"
+#include "src/gpu/GrShaderUtils.h"
 #include "src/gpu/GrStencilSettings.h"
 #include "src/gpu/vk/GrVkDescriptorSetManager.h"
 #include "src/gpu/vk/GrVkGpu.h"
@@ -281,7 +281,7 @@
 #if GR_TEST_UTILS
             if (fGpu->getContext()->priv().options().fCacheSKSL) {
                 for (int i = 0; i < kGrShaderTypeCount; ++i) {
-                    shaders[i] = GrSKSLPrettyPrint::PrettyPrint(*sksl[i]);
+                    shaders[i] = GrShaderUtils::PrettyPrint(*sksl[i]);
                 }
                 isSkSL = true;
             }