aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLContext.cpp12
-rw-r--r--src/gpu/gl/GrGLContext.h17
-rw-r--r--src/gpu/gl/GrGLGpu.cpp44
-rw-r--r--src/gpu/gl/builders/GrGLShaderStringBuilder.cpp128
4 files changed, 44 insertions, 157 deletions
diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp
index 2126314a7b..9e70b472c5 100644
--- a/src/gpu/gl/GrGLContext.cpp
+++ b/src/gpu/gl/GrGLContext.cpp
@@ -7,7 +7,6 @@
#include "GrGLContext.h"
#include "GrGLGLSL.h"
-#include "SkSLCompiler.h"
////////////////////////////////////////////////////////////////////////////////
@@ -64,17 +63,6 @@ GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContext
return new GrGLContext(args);
}
-GrGLContext::~GrGLContext() {
- delete fCompiler;
-}
-
-SkSL::Compiler* GrGLContext::compiler() const {
- if (!fCompiler) {
- fCompiler = new SkSL::Compiler();
- }
- return fCompiler;
-}
-
GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) {
fInterface.reset(SkRef(args.fInterface));
fGLVersion = args.fGLVersion;
diff --git a/src/gpu/gl/GrGLContext.h b/src/gpu/gl/GrGLContext.h
index 8207ac89b0..6016f6859a 100644
--- a/src/gpu/gl/GrGLContext.h
+++ b/src/gpu/gl/GrGLContext.h
@@ -15,9 +15,6 @@
#include "GrGLUtil.h"
struct GrContextOptions;
-namespace SkSL {
- class Compiler;
-}
/**
* Encapsulates information about an OpenGL context including the OpenGL
@@ -42,8 +39,6 @@ public:
const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
- virtual ~GrGLContextInfo() {}
-
protected:
struct ConstructorArgs {
const GrGLInterface* fInterface;
@@ -69,7 +64,7 @@ protected:
};
/**
- * Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
+ * Extension of GrGLContextInfo that also provides access to GrGLInterface.
*/
class GrGLContext : public GrGLContextInfo {
public:
@@ -81,16 +76,8 @@ public:
const GrGLInterface* interface() const { return fInterface; }
- SkSL::Compiler* compiler() const;
-
- ~GrGLContext() override;
-
private:
- GrGLContext(const ConstructorArgs& args)
- : INHERITED(args)
- , fCompiler(nullptr) {}
-
- mutable SkSL::Compiler* fCompiler;
+ GrGLContext(const ConstructorArgs& args) : INHERITED(args) {}
typedef GrGLContextInfo INHERITED;
};
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 341216aa30..fcd3270ba2 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -3790,11 +3790,20 @@ bool GrGLGpu::createCopyProgram(int progIdx) {
fshaderTxt.append(";");
uTexture.appendDecl(glslCaps, &fshaderTxt);
fshaderTxt.append(";");
+ const char* fsOutName;
+ if (glslCaps->mustDeclareFragmentShaderOutput()) {
+ oFragColor.appendDecl(glslCaps, &fshaderTxt);
+ fshaderTxt.append(";");
+ fsOutName = oFragColor.c_str();
+ } else {
+ fsOutName = "gl_FragColor";
+ }
fshaderTxt.appendf(
"// Copy Program FS\n"
"void main() {"
- " sk_FragColor = %s(u_texture, v_texCoord);"
+ " %s = %s(u_texture, v_texCoord);"
"}",
+ fsOutName,
GrGLSLTexture2DFunctionName(kVec2f_GrSLType, kSamplerTypes[progIdx], this->glslGeneration())
);
@@ -3927,6 +3936,14 @@ bool GrGLGpu::createMipmapProgram(int progIdx) {
}
uTexture.appendDecl(glslCaps, &fshaderTxt);
fshaderTxt.append(";");
+ const char* fsOutName;
+ if (glslCaps->mustDeclareFragmentShaderOutput()) {
+ oFragColor.appendDecl(glslCaps, &fshaderTxt);
+ fshaderTxt.append(";");
+ fsOutName = oFragColor.c_str();
+ } else {
+ fsOutName = "gl_FragColor";
+ }
const char* sampleFunction = GrGLSLTexture2DFunctionName(kVec2f_GrSLType,
kTexture2DSampler_GrSLType,
this->glslGeneration());
@@ -3937,19 +3954,19 @@ bool GrGLGpu::createMipmapProgram(int progIdx) {
if (oddWidth && oddHeight) {
fshaderTxt.appendf(
- " sk_FragColor = (%s(u_texture, v_texCoord0) + %s(u_texture, v_texCoord1) + "
- " %s(u_texture, v_texCoord2) + %s(u_texture, v_texCoord3)) * 0.25;",
- sampleFunction, sampleFunction, sampleFunction, sampleFunction
+ " %s = (%s(u_texture, v_texCoord0) + %s(u_texture, v_texCoord1) + "
+ " %s(u_texture, v_texCoord2) + %s(u_texture, v_texCoord3)) * 0.25;",
+ fsOutName, sampleFunction, sampleFunction, sampleFunction, sampleFunction
);
} else if (oddWidth || oddHeight) {
fshaderTxt.appendf(
- " sk_FragColor = (%s(u_texture, v_texCoord0) + %s(u_texture, v_texCoord1)) * 0.5;",
- sampleFunction, sampleFunction
+ " %s = (%s(u_texture, v_texCoord0) + %s(u_texture, v_texCoord1)) * 0.5;",
+ fsOutName, sampleFunction, sampleFunction
);
} else {
fshaderTxt.appendf(
- " sk_FragColor = %s(u_texture, v_texCoord0);",
- sampleFunction
+ " %s = %s(u_texture, v_texCoord0);",
+ fsOutName, sampleFunction
);
}
@@ -4036,11 +4053,20 @@ bool GrGLGpu::createWireRectProgram() {
&fshaderTxt);
uColor.appendDecl(this->glCaps().glslCaps(), &fshaderTxt);
fshaderTxt.append(";");
+ const char* fsOutName;
+ if (this->glCaps().glslCaps()->mustDeclareFragmentShaderOutput()) {
+ oFragColor.appendDecl(this->glCaps().glslCaps(), &fshaderTxt);
+ fshaderTxt.append(";");
+ fsOutName = oFragColor.c_str();
+ } else {
+ fsOutName = "gl_FragColor";
+ }
fshaderTxt.appendf(
"// Write Rect Program FS\n"
"void main() {"
- " sk_FragColor = %s;"
+ " %s = %s;"
"}",
+ fsOutName,
uColor.c_str()
);
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
index 04d90ee343..d2e49a5cfb 100644
--- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
@@ -9,8 +9,6 @@
#include "gl/GrGLGpu.h"
#include "gl/GrGLSLPrettyPrint.h"
#include "SkTraceEvent.h"
-#include "SkSLCompiler.h"
-#include "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)
@@ -20,90 +18,6 @@ static const bool c_PrintShaders{false};
static void print_shader_source(const char** strings, int* lengths, int count);
-static SkSL::GLCaps skslcaps_for_context(const GrGLContext& context) {
- GrGLStandard standard = context.standard();
- const GrGLCaps* caps = context.caps();
- const GrGLSLCaps* glslCaps = caps->glslCaps();
- SkSL::GLCaps result;
- switch (standard) {
- case kGL_GrGLStandard:
- result.fStandard = SkSL::GLCaps::kGL_Standard;
- break;
- case kGLES_GrGLStandard:
- result.fStandard = SkSL::GLCaps::kGLES_Standard;
- break;
- default:
- SkASSERT(false);
- result.fStandard = SkSL::GLCaps::kGL_Standard;
- }
-
- switch (glslCaps->generation()) {
- case k110_GrGLSLGeneration:
- if (kGLES_GrGLStandard == standard) {
- // ES2's shader language is based on GLSL 1.20 but is version 1.00 of the ES
- // language
- result.fVersion = 100;
- } else {
- SkASSERT(kGL_GrGLStandard == standard);
- result.fVersion = 110;
- }
- break;
- case k130_GrGLSLGeneration:
- SkASSERT(kGL_GrGLStandard == standard);
- result.fVersion = 130;
- break;
- case k140_GrGLSLGeneration:
- SkASSERT(kGL_GrGLStandard == standard);
- result.fVersion = 140;
- break;
- case k150_GrGLSLGeneration:
- SkASSERT(kGL_GrGLStandard == standard);
- result.fVersion = 150;
- break;
- case k330_GrGLSLGeneration:
- if (kGLES_GrGLStandard == standard) {
- result.fVersion = 300;
- } else {
- SkASSERT(kGL_GrGLStandard == standard);
- result.fVersion = 330;
- }
- break;
- case k400_GrGLSLGeneration:
- SkASSERT(kGL_GrGLStandard == standard);
- result.fVersion = 400;
- break;
- case k310es_GrGLSLGeneration:
- SkASSERT(kGLES_GrGLStandard == standard);
- result.fVersion = 310;
- break;
- case k320es_GrGLSLGeneration:
- SkASSERT(kGLES_GrGLStandard == standard);
- result.fVersion = 320;
- break;
- }
- result.fIsCoreProfile = caps->isCoreProfile();
- result.fUsesPrecisionModifiers = glslCaps->usesPrecisionModifiers();
- result.fMustDeclareFragmentShaderOutput = glslCaps->mustDeclareFragmentShaderOutput();
- result.fCanUseMinAndAbsTogether = glslCaps->canUseMinAndAbsTogether();
- return result;
-}
-
-static void dump_string(std::string 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.
- size_t index = 0;
- for (;;) {
- size_t next = s.find("\n", index);
- if (next == std::string::npos) {
- SkDebugf("%s", s.substr(index).c_str());
- break;
- } else {
- SkDebugf("%s", s.substr(index, next - index + 1).c_str());
- index = next + 1;
- }
- }
-}
-
GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
GrGLuint programId,
GrGLenum type,
@@ -119,38 +33,14 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
return 0;
}
- std::string sksl;
#ifdef SK_DEBUG
SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, false);
- sksl = std::string(prettySource.c_str());
+ const GrGLchar* sourceStr = prettySource.c_str();
+ GrGLint sourceLength = static_cast<GrGLint>(prettySource.size());
+ GR_GL_CALL(gli, ShaderSource(shaderId, 1, &sourceStr, &sourceLength));
#else
- for (int i = 0; i < count; i++) {
- sksl.append(strings[i], lengths[i]);
- }
-#endif
-
- std::string glsl;
- SkSL::Compiler& compiler = *glCtx.compiler();
- SkSL::GLCaps caps = skslcaps_for_context(glCtx);
- SkASSERT(type == GR_GL_VERTEX_SHADER || type == GR_GL_FRAGMENT_SHADER);
- SkDEBUGCODE(bool result = )compiler.toGLSL(type == GR_GL_VERTEX_SHADER
- ? SkSL::Program::kVertex_Kind
- : SkSL::Program::kFragment_Kind,
- std::string(sksl.c_str()),
- caps,
- &glsl);
-#ifdef SK_DEBUG
- if (!result) {
- SkDebugf("SKSL compilation error\n----------------------\n");
- SkDebugf("SKSL:\n");
- dump_string(sksl);
- SkDebugf("\nErrors:\n%s\n", compiler.errorText().c_str());
- SkDEBUGFAIL("SKSL compilation failed!\n");
- }
+ GR_GL_CALL(gli, ShaderSource(shaderId, count, strings, lengths));
#endif
- const char* glslChars = glsl.c_str();
- GrGLint glslLength = (GrGLint) glsl.length();
- GR_GL_CALL(gli, ShaderSource(shaderId, 1, &glslChars, &glslLength));
// If tracing is enabled in chrome then we pretty print
bool traceShader;
@@ -182,14 +72,10 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
// buffer param validation.
GrGLsizei length = GR_GL_INIT_ZERO;
GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1, &length, (char*)log.get()));
- SkDebugf("GLSL compilation error\n----------------------\n");
- SkDebugf("SKSL:\n");
- dump_string(sksl);
- SkDebugf("GLSL:\n");
- dump_string(glsl);
- SkDebugf("Errors:\n%s\n", (const char*) log.get());
+ print_shader_source(strings, lengths, count);
+ SkDebugf("\n%s", (const char*)log.get());
}
- SkDEBUGFAIL("GLSL compilation failed!");
+ SkDEBUGFAIL("Shader compilation failed!");
GR_GL_CALL(gli, DeleteShader(shaderId));
return 0;
}