Revert "skslc now uses standard Skia caps"

This reverts commit 8af38a9647.

Reason for revert: Breaking compile bots, e.g. from https://uberchromegw.corp.google.com/i/client.skia.compile/builders/Build-Ubuntu-GCC-x86_64-Debug-NoGPU/builds/10029/steps/compile_skia%20on%20Ubuntu/logs/stdio :

In function `sk_make_sp<GrGLSLCaps, GrContextOptions>'
undefined reference to `GrGLSLCaps::GrGLSLCaps(GrContextOptions const&)

In function `_Z10sk_make_spI10GrGLSLCapsI16GrContextOptionsEE5sk_spIT_EDpOT0_':
undefined reference to `GrGLSLCaps::GrGLSLCaps(GrContextOptions const&)




Original change's description:
> skslc now uses standard Skia caps
> 
> BUG=skia:
> 
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4660
> 
> Change-Id: Idaedae3f81426b97f5052bb872cdf0610e47a84f
> Reviewed-on: https://skia-review.googlesource.com/4660
> Reviewed-by: Ben Wagner <benjaminwagner@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> 

TBR=bsalomon@google.com,benjaminwagner@google.com,ethannicholas@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: Ic7f987f5c050ac2e333f5a0f16c8de85c1047a74
Reviewed-on: https://skia-review.googlesource.com/4697
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
This commit is contained in:
Leon Scroggins 2016-11-11 15:50:45 +00:00 committed by Skia Commit-Bot
parent 8af38a9647
commit b0b5360ae4
14 changed files with 196 additions and 160 deletions

View File

@ -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),
*context->caps()->glslCaps(),
GrGLSkSLCapsForContext(*context),
&glsl);
if (!result) {
SkDebugf("SkSL compilation failed:\n%s\n%s\n", sksl,

View File

@ -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::GLSLCapsFactory::Default(), &output);
(const char*)bytes->data(), SkSL::GLCaps(), &output);
if (!result) {
SkDebugf("[terminated] Couldn't compile input.\n");

View File

@ -12,10 +12,7 @@
'include_dirs': [
'../include/config',
'../include/core',
'../include/gpu',
'../include/private',
'../include/utils',
'../src/gpu',
'../src/sksl',
],
'defines': [

View File

@ -13,19 +13,13 @@
'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': [

View File

@ -21,6 +21,79 @@ 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.
@ -64,12 +137,13 @@ 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()),
*glCtx.caps()->glslCaps(),
caps,
&glsl);
#ifdef SK_DEBUG
if (!result) {

View File

@ -14,6 +14,8 @@
#include "SkSLGLSLCodeGenerator.h"
#include "SkTypes.h"
SkSL::GLCaps GrGLSkSLCapsForContext(const GrGLContext& context);
GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
GrGLuint programId,
GrGLenum type,

View File

@ -13,10 +13,6 @@
#include "GrGLSL.h"
#include "GrSwizzle.h"
namespace SkSL {
class GLSLCapsFactory;
}
class GrGLSLCaps : public GrShaderCaps {
public:
@ -235,7 +231,6 @@ private:
friend class GrGLCaps; // For initialization.
friend class GrVkCaps;
friend class SkSL::GLSLCapsFactory;
typedef GrShaderCaps INHERITED;
};

View File

@ -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, const GrGLSLCaps& caps,
bool Compiler::toGLSL(Program::Kind kind, const std::string& text, GLCaps 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, const GrGLSLCaps& caps,
bool Compiler::toGLSL(Program::Kind kind, const std::string& text, GLCaps caps,
std::string* out) {
std::stringstream buffer;
bool result = this->toGLSL(kind, text, caps, buffer);

View File

@ -43,11 +43,9 @@ public:
bool toSPIRV(Program::Kind kind, const std::string& text, std::string* 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::ostream& out);
bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps,
std::string* out);
bool toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, std::string* out);
void error(Position position, std::string msg) override;

View File

@ -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.canUseMinAndAbsTogether());
ASSERT(!fCaps.fCanUseMinAndAbsTogether);
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.canUseMinAndAbsTogether() && c.fFunction.fName == "min" && c.fFunction.fBuiltin) {
if (!fCaps.fCanUseMinAndAbsTogether && 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.mustForceNegatedAtanParamToFloat() && c.fFunction.fName == "atan" &&
if (fCaps.fMustForceNegatedAtanParamToFloat && 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 && (c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") &&
c.fFunction.fBuiltin && fCaps.shaderDerivativeExtensionString()) {
ASSERT(fCaps.shaderDerivativeSupport());
fHeader << "#extension " << fCaps.shaderDerivativeExtensionString() << " : require\n";
if (!fFoundDerivatives && fCaps.fShaderDerivativeExtensionString != "" &&
(c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") && c.fFunction.fBuiltin) {
ASSERT(fCaps.fShaderDerivativeSupport);
fHeader << "#extension " << fCaps.fShaderDerivativeExtensionString << " : 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.mustDeclareFragmentShaderOutput()) {
if (fCaps.fMustDeclareFragmentShaderOutput) {
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.generation() < GrGLSLGeneration::k130_GrGLSLGeneration) {
if (globalContext && fCaps.fVersion < 130) {
this->write(fProgramKind == Program::kVertex_Kind ? "attribute "
: "varying ");
} else {
this->write("in ");
}
} else if (modifiers.fFlags & Modifiers::kOut_Flag) {
if (globalContext && fCaps.generation() < GrGLSLGeneration::k130_GrGLSLGeneration) {
if (globalContext && fCaps.fVersion < 130) {
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.usesPrecisionModifiers()) {
if (fCaps.fUsesPrecisionModifiers) {
if (modifiers.fFlags & Modifiers::kLowp_Flag) {
this->write("lowp ");
}
@ -587,7 +587,12 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out)
ASSERT(fOut == nullptr);
fOut = &fHeader;
fProgramKind = program.fKind;
this->write(fCaps.versionDeclString());
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->writeLine();
for (const auto& e : program.fElements) {
if (e->fKind == ProgramElement::kExtension_Kind) {
@ -596,7 +601,7 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out)
}
std::stringstream body;
fOut = &body;
if (fCaps.usesPrecisionModifiers()) {
if (fCaps.fStandard == GLCaps::kGLES_Standard) {
this->write("precision ");
switch (program.fDefaultPrecision) {
case Modifiers::kLowp_Flag:
@ -627,9 +632,9 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out)
this->writeVarDeclarations(decl, true);
this->writeLine();
} else if (builtin == SK_FRAGCOLOR_BUILTIN &&
fCaps.mustDeclareFragmentShaderOutput()) {
fCaps.fMustDeclareFragmentShaderOutput) {
this->write("out ");
if (fCaps.usesPrecisionModifiers()) {
if (fCaps.fUsesPrecisionModifiers) {
this->write("mediump ");
}
this->writeLine("vec4 sk_FragColor;");

View File

@ -12,7 +12,6 @@
#include <tuple>
#include <unordered_map>
#include "glsl/GrGLSLCaps.h"
#include "SkSLCodeGenerator.h"
#include "ir/SkSLBinaryExpression.h"
#include "ir/SkSLBoolLiteral.h"
@ -45,6 +44,28 @@ 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.
*/
@ -71,9 +92,9 @@ public:
kTopLevel_Precedence = 18
};
GLSLCodeGenerator(const Context* context, const GrGLSLCaps* caps)
GLSLCodeGenerator(const Context* context, GLCaps caps)
: fContext(*context)
, fCaps(*caps) {}
, fCaps(caps) {}
void generateCode(const Program& program, std::ostream& out) override;
@ -155,7 +176,7 @@ private:
void writeReturnStatement(const ReturnStatement& r);
const Context& fContext;
const GrGLSLCaps& fCaps;
const GLCaps fCaps;
std::ostream* fOut = nullptr;
std::stringstream fHeader;
std::string fFunctionHeader;

View File

@ -8,7 +8,6 @@
#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()) {
@ -58,7 +57,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::GLSLCapsFactory::Default(), out)) {
if (!compiler.toGLSL(kind, text, SkSL::GLCaps(), out)) {
printf("%s", compiler.errorText().c_str());
exit(3);
}

View File

@ -13,66 +13,10 @@
#include <sstream>
#include "stdlib.h"
#include "assert.h"
#include "SkRefCnt.h"
#include "SkTypes.h"
#include "glsl/GrGLSLCaps.h"
#include "GrContextOptions.h"
#include "SkTypes.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);

View File

@ -9,8 +9,7 @@
#include "Test.h"
static void test(skiatest::Reporter* r, const char* src, const GrGLSLCaps& caps,
const char* expected) {
static void test(skiatest::Reporter* r, const char* src, SkSL::GLCaps caps, const char* expected) {
SkSL::Compiler compiler;
std::string output;
bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, src, caps, &output);
@ -27,14 +26,17 @@ static void test(skiatest::Reporter* r, const char* src, const GrGLSLCaps& caps,
}
}
static SkSL::GLCaps default_caps() {
return SkSL::GLCaps();
}
DEF_TEST(SkSLHelloWorld, r) {
test(r,
"void main() { sk_FragColor = vec4(0.75); }",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" sk_FragColor = vec4(0.75);\n"
" gl_FragColor = vec4(0.75);\n"
"}\n");
}
@ -50,20 +52,19 @@ DEF_TEST(SkSLControl, r) {
"}"
"return;"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" if (sqrt(2.0) > 5.0) {\n"
" sk_FragColor = vec4(0.75);\n"
" gl_FragColor = vec4(0.75);\n"
" } else {\n"
" discard;\n"
" }\n"
" int i = 0;\n"
" while (i < 10) sk_FragColor *= 0.5;\n"
" while (i < 10) gl_FragColor *= 0.5;\n"
" do {\n"
" sk_FragColor += 0.01;\n"
" } while (sk_FragColor.x < 0.7);\n"
" gl_FragColor += 0.01;\n"
" } while (gl_FragColor.x < 0.7);\n"
" for (int i = 0;i < 10; i++) {\n"
" if (i % 0 == 1) break; else continue;\n"
" }\n"
@ -76,9 +77,8 @@ 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); }",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#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"
" sk_FragColor = vec4(x);\n"
" gl_FragColor = vec4(x);\n"
"}\n");
}
@ -118,9 +118,8 @@ DEF_TEST(SkSLOperators, r) {
"z <<= 4;"
"z %= 5;"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" float x = 1.0, y = 2.0;\n"
" int z = 3;\n"
@ -152,9 +151,8 @@ DEF_TEST(SkSLMatrices, r) {
"vec3 v1 = mat3(1) * vec3(1);"
"vec3 v2 = vec3(1) * mat3(1);"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#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"
@ -174,9 +172,8 @@ DEF_TEST(SkSLInterfaceBlock, r) {
"};"
"void main() {"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"uniform testBlock {\n"
" float x;\n"
" float[2] y;\n"
@ -202,9 +199,8 @@ DEF_TEST(SkSLStructs, r) {
"B b1, b2, b3;"
"void main() {"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"struct A {\n"
" int x;\n"
" int y;\n"
@ -222,18 +218,22 @@ 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); }",
*SkSL::GLSLCapsFactory::Version450Core(),
caps,
"#version 450 core\n"
"out vec4 sk_FragColor;\n"
"in float test;\n"
"void main() {\n"
" sk_FragColor = vec4(0.75);\n"
" gl_FragColor = vec4(0.75);\n"
"}\n");
caps.fVersion = 110;
caps.fIsCoreProfile = false;
test(r,
"in float test; void main() { sk_FragColor = vec4(0.75); }",
*SkSL::GLSLCapsFactory::Version110(),
caps,
"#version 110\n"
"varying float test;\n"
"void main() {\n"
@ -241,22 +241,36 @@ DEF_TEST(SkSLVersion, r) {
"}\n");
}
DEF_TEST(SkSLUsesPrecisionModifiers, r) {
DEF_TEST(SkSLDeclareOutput, r) {
SkSL::GLCaps caps = default_caps();
caps.fMustDeclareFragmentShaderOutput = true;
test(r,
"void main() { float x = 0.75; highp float y = 1; }",
*SkSL::GLSLCapsFactory::Default(),
"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,
"#version 400\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; }",
*SkSL::GLSLCapsFactory::UsesPrecisionModifiers(),
"#version 400\n"
caps,
"#version 400 es\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"
@ -269,22 +283,22 @@ DEF_TEST(SkSLMinAbs, r) {
"float x = -5;"
"x = min(abs(x), 6);"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#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);"
"}",
*SkSL::GLSLCapsFactory::CannotUseMinAndAbsTogether(),
caps,
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" float minAbsHackVar0;\n"
" float minAbsHackVar1;\n"
@ -297,18 +311,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)); }",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#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)); }",
*SkSL::GLSLCapsFactory::MustForceNegatedAtanParamToFloat(),
caps,
"#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"
@ -319,9 +333,8 @@ DEF_TEST(SkSLModifiersDeclaration, r) {
test(r,
"layout(blend_support_all_equations) out;"
"void main() { }",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"layout (blend_support_all_equations) out ;\n"
"void main() {\n"
"}\n");
@ -340,9 +353,8 @@ DEF_TEST(SkSLHex, r) {
"uint u3 = 0x7fffffff;"
"uint u4 = 0xffffffff;"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" int i1 = 0;\n"
" int i2 = 305441741;\n"
@ -367,9 +379,8 @@ DEF_TEST(SkSLVectorConstructors, r) {
"ivec2 v7 = ivec2(1);"
"ivec2 v8 = ivec2(vec2(1, 2));"
"vec2 v9 = vec2(ivec2(1, 2));",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#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"
@ -386,9 +397,8 @@ DEF_TEST(SkSLArrayConstructors, r) {
"float test1[] = float[](1, 2, 3, 4);"
"vec2 test2[] = vec2[](vec2(1, 2), vec2(3, 4));"
"mat4 test3[] = mat4[]();",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#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");
@ -397,26 +407,25 @@ DEF_TEST(SkSLArrayConstructors, r) {
DEF_TEST(SkSLDerivatives, r) {
test(r,
"void main() { float x = dFdx(1); }",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#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; }",
*SkSL::GLSLCapsFactory::ShaderDerivativeExtensionString(),
caps,
"#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); }",
*SkSL::GLSLCapsFactory::ShaderDerivativeExtensionString(),
caps,
"#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");
@ -459,9 +468,8 @@ DEF_TEST(SkSLConstantFolding, r) {
"bool xor_f = 1 == 1 ^^ 1 == 1;"
"int ternary = 10 > 5 ? 10 : 5;"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" float f_add = 34.0;\n"
" float f_sub = 30.0;\n"
@ -508,9 +516,8 @@ DEF_TEST(SkSLStaticIf, r) {
"if (1 > 2) x = 4; else x = 5;"
"if (false) x = 6;"
"}",
*SkSL::GLSLCapsFactory::Default(),
default_caps(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" int x;\n"
" x = 1;\n"