diff options
author | csmartdalton <csmartdalton@google.com> | 2017-02-17 14:52:48 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-21 22:50:57 +0000 |
commit | c663953504e7cd6ad0e673e926203a3a38478d05 (patch) | |
tree | 71441f33177ce06ecf39b717ab53b66aec16025b /src | |
parent | 94cce4cb2cf40b5ed3a1928c02618c1a98b1e0fa (diff) |
Print GL shader source with line numbers when there is a compile error
BUG=skia:
Change-Id: I06bad4aacf5992d8207881f59f20615479536481
Reviewed-on: https://skia-review.googlesource.com/8562
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/gl/builders/GrGLShaderStringBuilder.cpp | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp index 6c719fe305..46530f2e30 100644 --- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp +++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp @@ -20,24 +20,7 @@ // Print the source code for all shaders generated. static const bool c_PrintShaders{false}; -static void print_shader_source(const char** strings, int* lengths, int count); - -static void dump_string(SkString s) { - // on Android, SkDebugf only displays the first 1K characters of output, which results in - // incomplete shader source code. Print each line individually to avoid this problem. - const char* chars = s.c_str(); - for (;;) { - const char* next = strchr(chars, '\n'); - if (next) { - next++; - SkDebugf("%s", SkString(chars, next - chars).c_str()); - chars = next; - } else { - SkDebugf("%s", chars); - break; - } - } -} +static void print_source_with_line_numbers(const SkString&); GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx, GrGLuint programId, @@ -77,7 +60,7 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx, if (!program || !compiler.toGLSL(*program, &glsl)) { SkDebugf("SKSL compilation error\n----------------------\n"); SkDebugf("SKSL:\n"); - dump_string(sksl); + print_source_with_line_numbers(sksl); SkDebugf("\nErrors:\n%s\n", compiler.errorText().c_str()); SkDEBUGFAIL("SKSL compilation failed!\n"); } @@ -124,9 +107,9 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx, GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1, &length, (char*)log.get())); SkDebugf("GLSL compilation error\n----------------------\n"); SkDebugf("SKSL:\n"); - dump_string(sksl); + print_source_with_line_numbers(sksl); SkDebugf("GLSL:\n"); - dump_string(glsl); + print_source_with_line_numbers(glsl); SkDebugf("Errors:\n%s\n", (const char*) log.get()); } SkDEBUGFAIL("GLSL compilation failed!"); @@ -143,7 +126,7 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx, case GR_GL_FRAGMENT_SHADER: typeName = "Fragment"; break; } SkDebugf("---- %s shader ----------------------------------------------------\n", typeName); - print_shader_source(strings, lengths, count); + print_source_with_line_numbers(sksl); } // Attach the shader, but defer deletion until after we have linked the program. @@ -155,12 +138,11 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx, return shaderId; } -static void print_shader_source(const char** strings, int* lengths, int count) { - const SkString& pretty = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, true); +static void print_source_with_line_numbers(const SkString& source) { SkTArray<SkString> lines; - SkStrSplit(pretty.c_str(), "\n", &lines); - for (const SkString& line : lines) { + SkStrSplit(source.c_str(), "\n", kStrict_SkStrSplitMode, &lines); + for (int line = 0; line < lines.count(); ++line) { // Print the shader one line at the time so it doesn't get truncated by the adb log. - SkDebugf("%s\n", line.c_str()); + SkDebugf("%4i\t%s\n", line + 1, lines[line].c_str()); } } |