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

Side by Side Diff: src/gpu/gl/builders/GrGLShaderStringBuilder.cpp

Issue 2337553002: Revert of Turned on SkSL->GLSL compiler (Closed)
Patch Set: Created 4 years, 3 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 | « src/gpu/gl/GrGLGpu.cpp ('k') | src/gpu/glsl/GrGLSLFragmentShaderBuilder.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 2014 Google Inc. 2 * Copyright 2014 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 "GrGLShaderStringBuilder.h" 8 #include "GrGLShaderStringBuilder.h"
9 #include "gl/GrGLGpu.h" 9 #include "gl/GrGLGpu.h"
10 #include "gl/GrGLSLPrettyPrint.h" 10 #include "gl/GrGLSLPrettyPrint.h"
11 #include "SkTraceEvent.h" 11 #include "SkTraceEvent.h"
12 #include "SkSLCompiler.h"
13 #include "ir/SkSLProgram.h"
14 12
15 #define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X) 13 #define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X)
16 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(gpu->glInterface(), R, X) 14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(gpu->glInterface(), R, X)
17 15
18 // Print the source code for all shaders generated. 16 // Print the source code for all shaders generated.
19 static const bool c_PrintShaders{false}; 17 static const bool c_PrintShaders{false};
20 18
21 static void print_shader_source(const char** strings, int* lengths, int count); 19 static void print_shader_source(const char** strings, int* lengths, int count);
22 20
23 static SkSL::GLCaps skslcaps_for_context(const GrGLContext& context) {
24 GrGLStandard standard = context.standard();
25 const GrGLCaps* caps = context.caps();
26 const GrGLSLCaps* glslCaps = caps->glslCaps();
27 SkSL::GLCaps result;
28 switch (standard) {
29 case kGL_GrGLStandard:
30 result.fStandard = SkSL::GLCaps::kGL_Standard;
31 break;
32 case kGLES_GrGLStandard:
33 result.fStandard = SkSL::GLCaps::kGLES_Standard;
34 break;
35 default:
36 SkASSERT(false);
37 result.fStandard = SkSL::GLCaps::kGL_Standard;
38 }
39
40 switch (glslCaps->generation()) {
41 case k110_GrGLSLGeneration:
42 if (kGLES_GrGLStandard == standard) {
43 // ES2's shader language is based on GLSL 1.20 but is version 1. 00 of the ES
44 // language
45 result.fVersion = 100;
46 } else {
47 SkASSERT(kGL_GrGLStandard == standard);
48 result.fVersion = 110;
49 }
50 break;
51 case k130_GrGLSLGeneration:
52 SkASSERT(kGL_GrGLStandard == standard);
53 result.fVersion = 130;
54 break;
55 case k140_GrGLSLGeneration:
56 SkASSERT(kGL_GrGLStandard == standard);
57 result.fVersion = 140;
58 break;
59 case k150_GrGLSLGeneration:
60 SkASSERT(kGL_GrGLStandard == standard);
61 result.fVersion = 150;
62 break;
63 case k330_GrGLSLGeneration:
64 if (kGLES_GrGLStandard == standard) {
65 result.fVersion = 300;
66 } else {
67 SkASSERT(kGL_GrGLStandard == standard);
68 result.fVersion = 330;
69 }
70 break;
71 case k400_GrGLSLGeneration:
72 SkASSERT(kGL_GrGLStandard == standard);
73 result.fVersion = 400;
74 break;
75 case k310es_GrGLSLGeneration:
76 SkASSERT(kGLES_GrGLStandard == standard);
77 result.fVersion = 310;
78 break;
79 case k320es_GrGLSLGeneration:
80 SkASSERT(kGLES_GrGLStandard == standard);
81 result.fVersion = 320;
82 break;
83 }
84 result.fIsCoreProfile = caps->isCoreProfile();
85 result.fUsesPrecisionModifiers = glslCaps->usesPrecisionModifiers();
86 result.fMustDeclareFragmentShaderOutput = glslCaps->mustDeclareFragmentShade rOutput();
87 result.fCanUseMinAndAbsTogether = glslCaps->canUseMinAndAbsTogether();
88 return result;
89 }
90
91 GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx, 21 GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
92 GrGLuint programId, 22 GrGLuint programId,
93 GrGLenum type, 23 GrGLenum type,
94 const char** strings, 24 const char** strings,
95 int* lengths, 25 int* lengths,
96 int count, 26 int count,
97 GrGpu::Stats* stats) { 27 GrGpu::Stats* stats) {
98 const GrGLInterface* gli = glCtx.interface(); 28 const GrGLInterface* gli = glCtx.interface();
99 29
100 GrGLuint shaderId; 30 GrGLuint shaderId;
101 GR_GL_CALL_RET(gli, shaderId, CreateShader(type)); 31 GR_GL_CALL_RET(gli, shaderId, CreateShader(type));
102 if (0 == shaderId) { 32 if (0 == shaderId) {
103 return 0; 33 return 0;
104 } 34 }
105 35
106 std::string sksl;
107 #ifdef SK_DEBUG 36 #ifdef SK_DEBUG
108 SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false); 37 SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false);
109 sksl = std::string(prettySource.c_str()); 38 const GrGLchar* sourceStr = prettySource.c_str();
39 GrGLint sourceLength = static_cast<GrGLint>(prettySource.size());
40 GR_GL_CALL(gli, ShaderSource(shaderId, 1, &sourceStr, &sourceLength));
110 #else 41 #else
111 for (int i = 0; i < count; i++) { 42 GR_GL_CALL(gli, ShaderSource(shaderId, count, strings, lengths));
112 sksl.append(strings[i], lengths[i]);
113 }
114 #endif 43 #endif
115 44
116 std::string glsl;
117 // creating Compiler is expensive, and we are single-threaded anyway, so jus t reuse a static one
118 static SkSL::Compiler compiler;
119 SkSL::GLCaps caps = skslcaps_for_context(glCtx);
120 SkASSERT(type == GR_GL_VERTEX_SHADER || type == GR_GL_FRAGMENT_SHADER);
121 SkDEBUGCODE(bool result = )compiler.toGLSL(type == GR_GL_VERTEX_SHADER
122 ? SkSL::Prog ram::kVertex_Kind
123 : SkSL::Prog ram::kFragment_Kind,
124 std::string(sksl.c_str()),
125 caps,
126 &glsl);
127 SkASSERTF(result, "SkSL errors:\n%s", compiler.errorText().c_str());
128 const char* glslChars = glsl.c_str();
129 GrGLint glslLength = (GrGLint) glsl.length();
130 GR_GL_CALL(gli, ShaderSource(shaderId, 1, &glslChars, &glslLength));
131
132 // If tracing is enabled in chrome then we pretty print 45 // If tracing is enabled in chrome then we pretty print
133 bool traceShader; 46 bool traceShader;
134 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), &t raceShader); 47 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), &t raceShader);
135 if (traceShader) { 48 if (traceShader) {
136 SkString shader = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, c ount, false); 49 SkString shader = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, c ount, false);
137 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "skia_gpu::G LShader", 50 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "skia_gpu::G LShader",
138 TRACE_EVENT_SCOPE_THREAD, "shader", TRACE_STR_COPY( shader.c_str())); 51 TRACE_EVENT_SCOPE_THREAD, "shader", TRACE_STR_COPY( shader.c_str()));
139 } 52 }
140 53
141 stats->incShaderCompilations(); 54 stats->incShaderCompilations();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 96
184 static void print_shader_source(const char** strings, int* lengths, int count) { 97 static void print_shader_source(const char** strings, int* lengths, int count) {
185 const SkString& pretty = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths , count, true); 98 const SkString& pretty = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths , count, true);
186 SkTArray<SkString> lines; 99 SkTArray<SkString> lines;
187 SkStrSplit(pretty.c_str(), "\n", &lines); 100 SkStrSplit(pretty.c_str(), "\n", &lines);
188 for (const SkString& line : lines) { 101 for (const SkString& line : lines) {
189 // Print the shader one line at the time so it doesn't get truncated by the adb log. 102 // Print the shader one line at the time so it doesn't get truncated by the adb log.
190 SkDebugf("%s\n", line.c_str()); 103 SkDebugf("%s\n", line.c_str());
191 } 104 }
192 } 105 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.cpp ('k') | src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698