aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/GLBench.cpp2
-rw-r--r--fuzz/fuzz.cpp2
-rw-r--r--gyp/sksl.gyp3
-rw-r--r--gyp/skslc.gyp6
-rw-r--r--src/gpu/gl/builders/GrGLShaderStringBuilder.cpp76
-rw-r--r--src/gpu/gl/builders/GrGLShaderStringBuilder.h2
-rw-r--r--src/gpu/glsl/GrGLSLCaps.h5
-rw-r--r--src/sksl/SkSLCompiler.cpp6
-rw-r--r--src/sksl/SkSLCompiler.h6
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.cpp35
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.h29
-rw-r--r--src/sksl/SkSLMain.cpp3
-rw-r--r--src/sksl/SkSLUtil.h58
-rw-r--r--tests/SkSLGLSLTest.cpp121
14 files changed, 159 insertions, 195 deletions
diff --git a/bench/GLBench.cpp b/bench/GLBench.cpp
index b6975508cf..df9ee9bb0d 100644
--- a/bench/GLBench.cpp
+++ b/bench/GLBench.cpp
@@ -71,7 +71,7 @@ GrGLuint GLBench::CompileShader(const GrGLContext* context, const char* sksl, Gr
? SkSL::Program::kVertex_Kind
: SkSL::Program::kFragment_Kind,
std::string(sksl),
- GrGLSkSLCapsForContext(*context),
+ *context->caps()->glslCaps(),
&glsl);
if (!result) {
SkDebugf("SkSL compilation failed:\n%s\n%s\n", sksl,
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp
index d6534f1aff..9fc199ec3a 100644
--- a/fuzz/fuzz.cpp
+++ b/fuzz/fuzz.cpp
@@ -397,7 +397,7 @@ int fuzz_sksl2glsl(sk_sp<SkData> bytes) {
SkSL::Compiler compiler;
std::string output;
bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind,
- (const char*)bytes->data(), SkSL::GLCaps(), &output);
+ (const char*)bytes->data(), *SkSL::GLSLCapsFactory::Default(), &output);
if (!result) {
SkDebugf("[terminated] Couldn't compile input.\n");
diff --git a/gyp/sksl.gyp b/gyp/sksl.gyp
index c2fbbdd8cd..5ec29796bf 100644
--- a/gyp/sksl.gyp
+++ b/gyp/sksl.gyp
@@ -12,7 +12,10 @@
'include_dirs': [
'../include/config',
'../include/core',
+ '../include/gpu',
'../include/private',
+ '../include/utils',
+ '../src/gpu',
'../src/sksl',
],
'defines': [
diff --git a/gyp/skslc.gyp b/gyp/skslc.gyp
index c465aa4772..6f9ed608b7 100644
--- a/gyp/skslc.gyp
+++ b/gyp/skslc.gyp
@@ -13,13 +13,19 @@
'include_dirs': [
'../include/config',
'../include/core',
+ '../include/gpu',
'../include/private',
+ '../include/utils',
+ '../src/gpu',
'../src/sksl',
],
'sources': [
'<!@(python read_gni.py ../gn/sksl.gni skia_sksl_sources)',
'../src/sksl/SkSLMain.cpp',
],
+ 'dependencies': [
+ 'skia_lib.gyp:skia_lib',
+ ],
'configurations': {
'Debug': {
'defines': [
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
index 8a5b700a90..1e42259128 100644
--- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
@@ -21,79 +21,6 @@ static const bool c_PrintShaders{false};
static void print_shader_source(const char** strings, int* lengths, int count);
-SkSL::GLCaps GrGLSkSLCapsForContext(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.fShaderDerivativeSupport = glslCaps->shaderDerivativeSupport();
- if (result.fShaderDerivativeSupport && glslCaps->shaderDerivativeExtensionString()) {
- result.fShaderDerivativeExtensionString = glslCaps->shaderDerivativeExtensionString();
- }
- result.fCanUseMinAndAbsTogether = glslCaps->canUseMinAndAbsTogether();
- result.fMustForceNegatedAtanParamToFloat = glslCaps->mustForceNegatedAtanParamToFloat();
- 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.
@@ -137,13 +64,12 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
std::string glsl;
SkSL::Compiler& compiler = *glCtx.compiler();
- SkSL::GLCaps caps = GrGLSkSLCapsForContext(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,
+ *glCtx.caps()->glslCaps(),
&glsl);
#ifdef SK_DEBUG
if (!result) {
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.h b/src/gpu/gl/builders/GrGLShaderStringBuilder.h
index 4365751c3a..71fce6a95a 100644
--- a/src/gpu/gl/builders/GrGLShaderStringBuilder.h
+++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.h
@@ -14,8 +14,6 @@
#include "SkSLGLSLCodeGenerator.h"
#include "SkTypes.h"
-SkSL::GLCaps GrGLSkSLCapsForContext(const GrGLContext& context);
-
GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
GrGLuint programId,
GrGLenum type,
diff --git a/src/gpu/glsl/GrGLSLCaps.h b/src/gpu/glsl/GrGLSLCaps.h
index ac409a36ba..1a89d1690b 100644
--- a/src/gpu/glsl/GrGLSLCaps.h
+++ b/src/gpu/glsl/GrGLSLCaps.h
@@ -13,6 +13,10 @@
#include "GrGLSL.h"
#include "GrSwizzle.h"
+namespace SkSL {
+ class GLSLCapsFactory;
+}
+
class GrGLSLCaps : public GrShaderCaps {
public:
@@ -231,6 +235,7 @@ private:
friend class GrGLCaps; // For initialization.
friend class GrVkCaps;
+ friend class SkSL::GLSLCapsFactory;
typedef GrShaderCaps INHERITED;
};
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index c3adaea682..27fd662732 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -444,18 +444,18 @@ bool Compiler::toSPIRV(Program::Kind kind, const std::string& text, std::string*
return result;
}
-bool Compiler::toGLSL(Program::Kind kind, const std::string& text, GLCaps caps,
+bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
std::ostream& out) {
auto program = this->convertProgram(kind, text);
if (fErrorCount == 0) {
- SkSL::GLSLCodeGenerator cg(&fContext, caps);
+ SkSL::GLSLCodeGenerator cg(&fContext, &caps);
cg.generateCode(*program.get(), out);
ASSERT(!out.rdstate());
}
return fErrorCount == 0;
}
-bool Compiler::toGLSL(Program::Kind kind, const std::string& text, GLCaps caps,
+bool Compiler::toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
std::string* out) {
std::stringstream buffer;
bool result = this->toGLSL(kind, text, caps, buffer);
diff --git a/src/sksl/SkSLCompiler.h b/src/sksl/SkSLCompiler.h
index 275fc58b3f..e69db5997d 100644
--- a/src/sksl/SkSLCompiler.h
+++ b/src/sksl/SkSLCompiler.h
@@ -43,9 +43,11 @@ public:
bool toSPIRV(Program::Kind kind, const std::string& text, std::string* out);
- bool toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, std::ostream& out);
+ bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
+ std::ostream& out);
- bool toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, std::string* out);
+ bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
+ std::string* out);
void error(Position position, std::string msg) override;
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index 8a26f6a713..c6d2e6ed66 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
@@ -137,7 +137,7 @@ static bool is_abs(Expression& expr) {
// turns min(abs(x), y) into ((tmpVar1 = abs(x)) < (tmpVar2 = y) ? tmpVar1 : tmpVar2) to avoid a
// Tegra3 compiler bug.
void GLSLCodeGenerator::writeMinAbsHack(Expression& absExpr, Expression& otherExpr) {
- ASSERT(!fCaps.fCanUseMinAndAbsTogether);
+ ASSERT(!fCaps.canUseMinAndAbsTogether());
std::string tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
std::string tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
this->fFunctionHeader += " " + absExpr.fType.name() + " " + tmpVar1 + ";\n";
@@ -150,7 +150,7 @@ void GLSLCodeGenerator::writeMinAbsHack(Expression& absExpr, Expression& otherEx
}
void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
- if (!fCaps.fCanUseMinAndAbsTogether && c.fFunction.fName == "min" && c.fFunction.fBuiltin) {
+ if (!fCaps.canUseMinAndAbsTogether() && c.fFunction.fName == "min" && c.fFunction.fBuiltin) {
ASSERT(c.fArguments.size() == 2);
if (is_abs(*c.fArguments[0])) {
this->writeMinAbsHack(*c.fArguments[0], *c.fArguments[1]);
@@ -163,7 +163,7 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
return;
}
}
- if (fCaps.fMustForceNegatedAtanParamToFloat && c.fFunction.fName == "atan" &&
+ if (fCaps.mustForceNegatedAtanParamToFloat() && c.fFunction.fName == "atan" &&
c.fFunction.fBuiltin && c.fArguments.size() == 2 &&
c.fArguments[1]->fKind == Expression::kPrefix_Kind) {
const PrefixExpression& p = (PrefixExpression&) *c.fArguments[1];
@@ -176,10 +176,10 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
return;
}
}
- if (!fFoundDerivatives && fCaps.fShaderDerivativeExtensionString != "" &&
- (c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") && c.fFunction.fBuiltin) {
- ASSERT(fCaps.fShaderDerivativeSupport);
- fHeader << "#extension " << fCaps.fShaderDerivativeExtensionString << " : require\n";
+ if (!fFoundDerivatives && (c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") &&
+ c.fFunction.fBuiltin && fCaps.shaderDerivativeExtensionString()) {
+ ASSERT(fCaps.shaderDerivativeSupport());
+ fHeader << "#extension " << fCaps.shaderDerivativeExtensionString() << " : require\n";
fFoundDerivatives = true;
}
this->write(c.fFunction.fName + "(");
@@ -205,7 +205,7 @@ void GLSLCodeGenerator::writeConstructor(const Constructor& c) {
void GLSLCodeGenerator::writeVariableReference(const VariableReference& ref) {
if (ref.fVariable.fModifiers.fLayout.fBuiltin == SK_FRAGCOLOR_BUILTIN) {
- if (fCaps.fMustDeclareFragmentShaderOutput) {
+ if (fCaps.mustDeclareFragmentShaderOutput()) {
this->write("sk_FragColor");
} else {
this->write("gl_FragColor");
@@ -405,14 +405,14 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
(modifiers.fFlags & Modifiers::kOut_Flag)) {
this->write("inout ");
} else if (modifiers.fFlags & Modifiers::kIn_Flag) {
- if (globalContext && fCaps.fVersion < 130) {
+ if (globalContext && fCaps.generation() < GrGLSLGeneration::k130_GrGLSLGeneration) {
this->write(fProgramKind == Program::kVertex_Kind ? "attribute "
: "varying ");
} else {
this->write("in ");
}
} else if (modifiers.fFlags & Modifiers::kOut_Flag) {
- if (globalContext && fCaps.fVersion < 130) {
+ if (globalContext && fCaps.generation() < GrGLSLGeneration::k130_GrGLSLGeneration) {
this->write("varying ");
} else {
this->write("out ");
@@ -424,7 +424,7 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
if (modifiers.fFlags & Modifiers::kConst_Flag) {
this->write("const ");
}
- if (fCaps.fUsesPrecisionModifiers) {
+ if (fCaps.usesPrecisionModifiers()) {
if (modifiers.fFlags & Modifiers::kLowp_Flag) {
this->write("lowp ");
}
@@ -587,12 +587,7 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out)
ASSERT(fOut == nullptr);
fOut = &fHeader;
fProgramKind = program.fKind;
- this->write("#version " + to_string(fCaps.fVersion));
- if (fCaps.fStandard == GLCaps::kGLES_Standard && fCaps.fVersion >= 300) {
- this->write(" es");
- } else if (fCaps.fIsCoreProfile) {
- this->write(" core");
- }
+ this->write(fCaps.versionDeclString());
this->writeLine();
for (const auto& e : program.fElements) {
if (e->fKind == ProgramElement::kExtension_Kind) {
@@ -601,7 +596,7 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out)
}
std::stringstream body;
fOut = &body;
- if (fCaps.fStandard == GLCaps::kGLES_Standard) {
+ if (fCaps.usesPrecisionModifiers()) {
this->write("precision ");
switch (program.fDefaultPrecision) {
case Modifiers::kLowp_Flag:
@@ -632,9 +627,9 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out)
this->writeVarDeclarations(decl, true);
this->writeLine();
} else if (builtin == SK_FRAGCOLOR_BUILTIN &&
- fCaps.fMustDeclareFragmentShaderOutput) {
+ fCaps.mustDeclareFragmentShaderOutput()) {
this->write("out ");
- if (fCaps.fUsesPrecisionModifiers) {
+ if (fCaps.usesPrecisionModifiers()) {
this->write("mediump ");
}
this->writeLine("vec4 sk_FragColor;");
diff --git a/src/sksl/SkSLGLSLCodeGenerator.h b/src/sksl/SkSLGLSLCodeGenerator.h
index 97e6038146..5ed6104a09 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.h
+++ b/src/sksl/SkSLGLSLCodeGenerator.h
@@ -12,6 +12,7 @@
#include <tuple>
#include <unordered_map>
+#include "glsl/GrGLSLCaps.h"
#include "SkSLCodeGenerator.h"
#include "ir/SkSLBinaryExpression.h"
#include "ir/SkSLBoolLiteral.h"
@@ -44,28 +45,6 @@ namespace SkSL {
#define kLast_Capability SpvCapabilityMultiViewport
-struct GLCaps {
- GLCaps() {}
-
- int fVersion = 400;
- enum {
- kGL_Standard,
- kGLES_Standard
- } fStandard = kGL_Standard;
- bool fIsCoreProfile = false;
- bool fUsesPrecisionModifiers = false;
- bool fMustDeclareFragmentShaderOutput = false;
- bool fShaderDerivativeSupport = true;
- // extension string to enable derivative support, or null if unnecessary
- std::string fShaderDerivativeExtensionString;
- // The Tegra3 compiler will sometimes never return if we have min(abs(x), y)
- bool fCanUseMinAndAbsTogether = true;
- // On Intel GPU there is an issue where it misinterprets an atan argument (second argument only,
- // apparently) of the form "-<expr>" as an int, so we rewrite it as "-1.0 * <expr>" to avoid
- // this problem
- bool fMustForceNegatedAtanParamToFloat = false;
-};
-
/**
* Converts a Program into GLSL code.
*/
@@ -92,9 +71,9 @@ public:
kTopLevel_Precedence = 18
};
- GLSLCodeGenerator(const Context* context, GLCaps caps)
+ GLSLCodeGenerator(const Context* context, const GrGLSLCaps* caps)
: fContext(*context)
- , fCaps(caps) {}
+ , fCaps(*caps) {}
void generateCode(const Program& program, std::ostream& out) override;
@@ -176,7 +155,7 @@ private:
void writeReturnStatement(const ReturnStatement& r);
const Context& fContext;
- const GLCaps fCaps;
+ const GrGLSLCaps& fCaps;
std::ostream* fOut = nullptr;
std::stringstream fHeader;
std::string fFunctionHeader;
diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp
index eb07b4d032..3658992412 100644
--- a/src/sksl/SkSLMain.cpp
+++ b/src/sksl/SkSLMain.cpp
@@ -8,6 +8,7 @@
#include "stdio.h"
#include <fstream>
#include "SkSLCompiler.h"
+#include "GrContextOptions.h"
bool endsWith(const std::string& s, const std::string& ending) {
if (s.length() >= ending.length()) {
@@ -57,7 +58,7 @@ int main(int argc, const char** argv) {
} else if (endsWith(name, ".glsl")) {
std::ofstream out(argv[2], std::ofstream::binary);
SkSL::Compiler compiler;
- if (!compiler.toGLSL(kind, text, SkSL::GLCaps(), out)) {
+ if (!compiler.toGLSL(kind, text, *SkSL::GLSLCapsFactory::Default(), out)) {
printf("%s", compiler.errorText().c_str());
exit(3);
}
diff --git a/src/sksl/SkSLUtil.h b/src/sksl/SkSLUtil.h
index efffaaec01..ede21830e5 100644
--- a/src/sksl/SkSLUtil.h
+++ b/src/sksl/SkSLUtil.h
@@ -13,10 +13,66 @@
#include <sstream>
#include "stdlib.h"
#include "assert.h"
-#include "SkTypes.h"
+#include "SkRefCnt.h"
+#include "SkTypes.h"
+#include "glsl/GrGLSLCaps.h"
+#include "GrContextOptions.h"
namespace SkSL {
+// Various sets of caps for use in tests
+class GLSLCapsFactory {
+public:
+ static sk_sp<GrGLSLCaps> Default() {
+ sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
+ result->fVersionDeclString = "#version 400";
+ result->fShaderDerivativeSupport = true;
+ return result;
+ }
+
+ static sk_sp<GrGLSLCaps> Version450Core() {
+ sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
+ result->fVersionDeclString = "#version 450 core";
+ return result;
+ }
+
+ static sk_sp<GrGLSLCaps> Version110() {
+ sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
+ result->fVersionDeclString = "#version 110";
+ result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
+ return result;
+ }
+
+ static sk_sp<GrGLSLCaps> UsesPrecisionModifiers() {
+ sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
+ result->fVersionDeclString = "#version 400";
+ result->fUsesPrecisionModifiers = true;
+ return result;
+ }
+
+ static sk_sp<GrGLSLCaps> CannotUseMinAndAbsTogether() {
+ sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
+ result->fVersionDeclString = "#version 400";
+ result->fCanUseMinAndAbsTogether = false;
+ return result;
+ }
+
+ static sk_sp<GrGLSLCaps> MustForceNegatedAtanParamToFloat() {
+ sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
+ result->fVersionDeclString = "#version 400";
+ result->fMustForceNegatedAtanParamToFloat = true;
+ return result;
+ }
+
+ static sk_sp<GrGLSLCaps> ShaderDerivativeExtensionString() {
+ sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
+ result->fVersionDeclString = "#version 400";
+ result->fShaderDerivativeSupport = true;
+ result->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
+ return result;
+ }
+};
+
// our own definitions of certain std:: functions, because they are not always present on Android
std::string to_string(double value);
diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp
index 38fce87e87..937fd6749a 100644
--- a/tests/SkSLGLSLTest.cpp
+++ b/tests/SkSLGLSLTest.cpp
@@ -9,7 +9,8 @@
#include "Test.h"
-static void test(skiatest::Reporter* r, const char* src, SkSL::GLCaps caps, const char* expected) {
+static void test(skiatest::Reporter* r, const char* src, const GrGLSLCaps& caps,
+ const char* expected) {
SkSL::Compiler compiler;
std::string output;
bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, src, caps, &output);
@@ -26,17 +27,14 @@ static void test(skiatest::Reporter* r, const char* src, SkSL::GLCaps caps, cons
}
}
-static SkSL::GLCaps default_caps() {
- return SkSL::GLCaps();
-}
-
DEF_TEST(SkSLHelloWorld, r) {
test(r,
"void main() { sk_FragColor = vec4(0.75); }",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
- " gl_FragColor = vec4(0.75);\n"
+ " sk_FragColor = vec4(0.75);\n"
"}\n");
}
@@ -52,19 +50,20 @@ DEF_TEST(SkSLControl, r) {
"}"
"return;"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" if (sqrt(2.0) > 5.0) {\n"
- " gl_FragColor = vec4(0.75);\n"
+ " sk_FragColor = vec4(0.75);\n"
" } else {\n"
" discard;\n"
" }\n"
" int i = 0;\n"
- " while (i < 10) gl_FragColor *= 0.5;\n"
+ " while (i < 10) sk_FragColor *= 0.5;\n"
" do {\n"
- " gl_FragColor += 0.01;\n"
- " } while (gl_FragColor.x < 0.7);\n"
+ " sk_FragColor += 0.01;\n"
+ " } while (sk_FragColor.x < 0.7);\n"
" for (int i = 0;i < 10; i++) {\n"
" if (i % 0 == 1) break; else continue;\n"
" }\n"
@@ -77,8 +76,9 @@ DEF_TEST(SkSLFunctions, r) {
"float foo(float v[2]) { return v[0] * v[1]; }"
"void bar(inout float x) { float y[2], z; y[0] = x; y[1] = x * 2; z = foo(y); x = z; }"
"void main() { float x = 10; bar(x); sk_FragColor = vec4(x); }",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"float foo(in float v[2]) {\n"
" return v[0] * v[1];\n"
"}\n"
@@ -92,7 +92,7 @@ DEF_TEST(SkSLFunctions, r) {
"void main() {\n"
" float x = 10.0;\n"
" bar(x);\n"
- " gl_FragColor = vec4(x);\n"
+ " sk_FragColor = vec4(x);\n"
"}\n");
}
@@ -118,8 +118,9 @@ DEF_TEST(SkSLOperators, r) {
"z <<= 4;"
"z %= 5;"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" float x = 1.0, y = 2.0;\n"
" int z = 3;\n"
@@ -151,8 +152,9 @@ DEF_TEST(SkSLMatrices, r) {
"vec3 v1 = mat3(1) * vec3(1);"
"vec3 v2 = vec3(1) * mat3(1);"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" mat2x4 x = mat2x4(1.0);\n"
" mat3x2 y = mat3x2(1.0, 0.0, 0.0, 1.0, vec2(2.0, 2.0));\n"
@@ -172,8 +174,9 @@ DEF_TEST(SkSLInterfaceBlock, r) {
"};"
"void main() {"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"uniform testBlock {\n"
" float x;\n"
" float[2] y;\n"
@@ -199,8 +202,9 @@ DEF_TEST(SkSLStructs, r) {
"B b1, b2, b3;"
"void main() {"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"struct A {\n"
" int x;\n"
" int y;\n"
@@ -218,22 +222,18 @@ DEF_TEST(SkSLStructs, r) {
}
DEF_TEST(SkSLVersion, r) {
- SkSL::GLCaps caps = default_caps();
- caps.fVersion = 450;
- caps.fIsCoreProfile = true;
test(r,
"in float test; void main() { sk_FragColor = vec4(0.75); }",
- caps,
+ *SkSL::GLSLCapsFactory::Version450Core(),
"#version 450 core\n"
+ "out vec4 sk_FragColor;\n"
"in float test;\n"
"void main() {\n"
- " gl_FragColor = vec4(0.75);\n"
+ " sk_FragColor = vec4(0.75);\n"
"}\n");
- caps.fVersion = 110;
- caps.fIsCoreProfile = false;
test(r,
"in float test; void main() { sk_FragColor = vec4(0.75); }",
- caps,
+ *SkSL::GLSLCapsFactory::Version110(),
"#version 110\n"
"varying float test;\n"
"void main() {\n"
@@ -241,36 +241,22 @@ DEF_TEST(SkSLVersion, r) {
"}\n");
}
-DEF_TEST(SkSLDeclareOutput, r) {
- SkSL::GLCaps caps = default_caps();
- caps.fMustDeclareFragmentShaderOutput = true;
- test(r,
- "void main() { sk_FragColor = vec4(0.75); }",
- caps,
- "#version 400\n"
- "out vec4 sk_FragColor;\n"
- "void main() {\n"
- " sk_FragColor = vec4(0.75);\n"
- "}\n");
-}
-
DEF_TEST(SkSLUsesPrecisionModifiers, r) {
- SkSL::GLCaps caps = default_caps();
test(r,
"void main() { float x = 0.75; highp float y = 1; }",
- caps,
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" float x = 0.75;\n"
" float y = 1.0;\n"
"}\n");
- caps.fStandard = SkSL::GLCaps::kGLES_Standard;
- caps.fUsesPrecisionModifiers = true;
test(r,
"void main() { float x = 0.75; highp float y = 1; }",
- caps,
- "#version 400 es\n"
+ *SkSL::GLSLCapsFactory::UsesPrecisionModifiers(),
+ "#version 400\n"
"precision highp float;\n"
+ "out mediump vec4 sk_FragColor;\n"
"void main() {\n"
" float x = 0.75;\n"
" highp float y = 1.0;\n"
@@ -283,22 +269,22 @@ DEF_TEST(SkSLMinAbs, r) {
"float x = -5;"
"x = min(abs(x), 6);"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" float x = -5.0;\n"
" x = min(abs(x), 6.0);\n"
"}\n");
- SkSL::GLCaps caps = default_caps();
- caps.fCanUseMinAndAbsTogether = false;
test(r,
"void main() {"
"float x = -5.0;"
"x = min(abs(x), 6.0);"
"}",
- caps,
+ *SkSL::GLSLCapsFactory::CannotUseMinAndAbsTogether(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" float minAbsHackVar0;\n"
" float minAbsHackVar1;\n"
@@ -311,18 +297,18 @@ DEF_TEST(SkSLMinAbs, r) {
DEF_TEST(SkSLNegatedAtan, r) {
test(r,
"void main() { vec2 x = vec2(1, 2); float y = atan(x.x, -(2 * x.y)); }",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" vec2 x = vec2(1.0, 2.0);\n"
" float y = atan(x.x, -(2.0 * x.y));\n"
"}\n");
- SkSL::GLCaps caps = default_caps();
- caps.fMustForceNegatedAtanParamToFloat = true;
test(r,
"void main() { vec2 x = vec2(1, 2); float y = atan(x.x, -(2 * x.y)); }",
- caps,
+ *SkSL::GLSLCapsFactory::MustForceNegatedAtanParamToFloat(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" vec2 x = vec2(1.0, 2.0);\n"
" float y = atan(x.x, -1.0 * (2.0 * x.y));\n"
@@ -333,8 +319,9 @@ DEF_TEST(SkSLModifiersDeclaration, r) {
test(r,
"layout(blend_support_all_equations) out;"
"void main() { }",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"layout (blend_support_all_equations) out ;\n"
"void main() {\n"
"}\n");
@@ -353,8 +340,9 @@ DEF_TEST(SkSLHex, r) {
"uint u3 = 0x7fffffff;"
"uint u4 = 0xffffffff;"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" int i1 = 0;\n"
" int i2 = 305441741;\n"
@@ -379,8 +367,9 @@ DEF_TEST(SkSLVectorConstructors, r) {
"ivec2 v7 = ivec2(1);"
"ivec2 v8 = ivec2(vec2(1, 2));"
"vec2 v9 = vec2(ivec2(1, 2));",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"vec2 v1 = vec2(1.0);\n"
"vec2 v2 = vec2(1.0, 2.0);\n"
"vec2 v3 = vec2(1.0);\n"
@@ -397,8 +386,9 @@ DEF_TEST(SkSLArrayConstructors, r) {
"float test1[] = float[](1, 2, 3, 4);"
"vec2 test2[] = vec2[](vec2(1, 2), vec2(3, 4));"
"mat4 test3[] = mat4[]();",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"float test1[] = float[](1.0, 2.0, 3.0, 4.0);\n"
"vec2 test2[] = vec2[](vec2(1.0, 2.0), vec2(3.0, 4.0));\n"
"mat4 test3[] = mat4[]();\n");
@@ -407,25 +397,26 @@ DEF_TEST(SkSLArrayConstructors, r) {
DEF_TEST(SkSLDerivatives, r) {
test(r,
"void main() { float x = dFdx(1); }",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" float x = dFdx(1.0);\n"
"}\n");
- SkSL::GLCaps caps = default_caps();
- caps.fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
test(r,
"void main() { float x = 1; }",
- caps,
+ *SkSL::GLSLCapsFactory::ShaderDerivativeExtensionString(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" float x = 1.0;\n"
"}\n");
test(r,
"void main() { float x = dFdx(1); }",
- caps,
+ *SkSL::GLSLCapsFactory::ShaderDerivativeExtensionString(),
"#version 400\n"
"#extension GL_OES_standard_derivatives : require\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" float x = dFdx(1.0);\n"
"}\n");
@@ -468,8 +459,9 @@ DEF_TEST(SkSLConstantFolding, r) {
"bool xor_f = 1 == 1 ^^ 1 == 1;"
"int ternary = 10 > 5 ? 10 : 5;"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" float f_add = 34.0;\n"
" float f_sub = 30.0;\n"
@@ -516,8 +508,9 @@ DEF_TEST(SkSLStaticIf, r) {
"if (1 > 2) x = 4; else x = 5;"
"if (false) x = 6;"
"}",
- default_caps(),
+ *SkSL::GLSLCapsFactory::Default(),
"#version 400\n"
+ "out vec4 sk_FragColor;\n"
"void main() {\n"
" int x;\n"
" x = 1;\n"