aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLGLSLCodeGenerator.cpp
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2016-12-12 17:20:42 +0000
committerGravatar Greg Daniel <egdaniel@google.com>2016-12-12 17:22:28 +0000
commite8e4a3e6782586680086a0279eafb89969c29f3d (patch)
tree93e27a37cd75c69fe85fab990f6daf17c80ed794 /src/sksl/SkSLGLSLCodeGenerator.cpp
parentd737bee1470bbba8af5c9d74cbec2d731da33804 (diff)
Revert "added sk_FragCoord support to skslc"
This reverts commit ce33f10677630e34187b661a02161378d8304d68. Reason for revert: Breaking many gpu bots Change-Id: I94c813ed6a9311458c872f74bb1b0792f46ff414 Reviewed-on: https://skia-review.googlesource.com/5737 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/sksl/SkSLGLSLCodeGenerator.cpp')
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.cpp118
1 files changed, 37 insertions, 81 deletions
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index caf6ec841d..5b747240e9 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
@@ -11,13 +11,14 @@
#include "GLSL.std.450.h"
-#include "SkSLCompiler.h"
#include "ir/SkSLExpressionStatement.h"
#include "ir/SkSLExtension.h"
#include "ir/SkSLIndexExpression.h"
#include "ir/SkSLModifiersDeclaration.h"
#include "ir/SkSLVariableReference.h"
+#define SK_FRAGCOLOR_BUILTIN 10001
+
namespace SkSL {
void GLSLCodeGenerator::write(const char* s) {
@@ -133,10 +134,10 @@ static bool is_abs(Expression& expr) {
return ((FunctionCall&) expr).fFunction.fName == "abs";
}
-// turns min(abs(x), y) into ((tmpVar1 = abs(x)) < (tmpVar2 = y) ? tmpVar1 : tmpVar2) to avoid a
+// 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(!fProgram.fSettings.fCaps->canUseMinAndAbsTogether());
+ ASSERT(!fCaps.canUseMinAndAbsTogether());
SkString tmpVar1 = "minAbsHackVar" + to_string(fVarCount++);
SkString tmpVar2 = "minAbsHackVar" + to_string(fVarCount++);
this->fFunctionHeader += " " + absExpr.fType.name() + " " + tmpVar1 + ";\n";
@@ -149,8 +150,7 @@ void GLSLCodeGenerator::writeMinAbsHack(Expression& absExpr, Expression& otherEx
}
void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
- if (!fProgram.fSettings.fCaps->canUseMinAndAbsTogether() && 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,9 +163,8 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
return;
}
}
- if (fProgram.fSettings.fCaps->mustForceNegatedAtanParamToFloat() &&
- c.fFunction.fName == "atan" &&
- c.fFunction.fBuiltin && c.fArguments.size() == 2 &&
+ 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];
if (p.fOperator == Token::MINUS) {
@@ -177,11 +176,11 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
return;
}
}
- if (!fFoundDerivatives && (c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") &&
- c.fFunction.fBuiltin && fProgram.fSettings.fCaps->shaderDerivativeExtensionString()) {
- ASSERT(fProgram.fSettings.fCaps->shaderDerivativeSupport());
+ if (!fFoundDerivatives && (c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") &&
+ c.fFunction.fBuiltin && fCaps.shaderDerivativeExtensionString()) {
+ ASSERT(fCaps.shaderDerivativeSupport());
fHeader.writeText("#extension ");
- fHeader.writeText(fProgram.fSettings.fCaps->shaderDerivativeExtensionString());
+ fHeader.writeText(fCaps.shaderDerivativeExtensionString());
fHeader.writeText(" : require\n");
fFoundDerivatives = true;
}
@@ -236,7 +235,7 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
break;
}
this->write("texture");
- if (fProgram.fSettings.fCaps->generation() < k130_GrGLSLGeneration) {
+ if (fCaps.generation() < k130_GrGLSLGeneration) {
this->write(dim);
}
if (proj) {
@@ -267,56 +266,15 @@ void GLSLCodeGenerator::writeConstructor(const Constructor& c) {
this->write(")");
}
-void GLSLCodeGenerator::writeFragCoord() {
- // We only declare "gl_FragCoord" when we're in the case where we want to use layout qualifiers
- // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier appears in the
- // declaration varies in earlier GLSL specs. So it is simpler to omit it.
- if (!fProgram.fSettings.fFlipY) {
- fSetupFragPosition = true;
- this->write("gl_FragCoord");
- } else if (const char* extension =
- fProgram.fSettings.fCaps->fragCoordConventionsExtensionString()) {
- if (!fSetupFragPosition) {
- if (fProgram.fSettings.fCaps->generation() < k150_GrGLSLGeneration) {
- fHeader.writeText("#extension ");
- fHeader.writeText(extension);
- fHeader.writeText(" : require\n");
- }
- fHeader.writeText("layout(origin_upper_left) in vec4 gl_FragCoord;\n");
- fSetupFragPosition = true;
+void GLSLCodeGenerator::writeVariableReference(const VariableReference& ref) {
+ if (ref.fVariable.fModifiers.fLayout.fBuiltin == SK_FRAGCOLOR_BUILTIN) {
+ if (fCaps.mustDeclareFragmentShaderOutput()) {
+ this->write("sk_FragColor");
+ } else {
+ this->write("gl_FragColor");
}
- this->write("gl_FragCoord");
} else {
- if (!fSetupFragPosition) {
- // The Adreno compiler seems to be very touchy about access to "gl_FragCoord".
- // Accessing glFragCoord.zw can cause a program to fail to link. Additionally,
- // depending on the surrounding code, accessing .xy with a uniform involved can
- // do the same thing. Copying gl_FragCoord.xy into a temp vec2 beforehand
- // (and only accessing .xy) seems to "fix" things.
- fHeader.writeText("uniform float " SKSL_RTHEIGHT_NAME ";\n"
- "highp vec2 _sktmpCoord = gl_FragCoord.xy;\n"
- "highp vec4 sk_FragCoord = vec4(_sktmpCoord.x, " SKSL_RTHEIGHT_NAME
- " - _sktmpCoord.y, 1.0, 1.0);\n");
- fSetupFragPosition = true;
- }
- this->write("sk_FragCoord");
- }
-}
-
-void GLSLCodeGenerator::writeVariableReference(const VariableReference& ref) {
- switch (ref.fVariable.fModifiers.fLayout.fBuiltin) {
- case SK_FRAGCOLOR_BUILTIN:
- if (fProgram.fSettings.fCaps->mustDeclareFragmentShaderOutput()) {
- this->write("sk_FragColor");
- } else {
- this->write("gl_FragColor");
- }
- break;
- case SK_FRAGCOORD_BUILTIN:
- this->writeFragCoord();
- break;
- default:
- this->write(ref.fVariable.fName);
+ this->write(ref.fVariable.fName);
}
}
@@ -526,16 +484,14 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
(modifiers.fFlags & Modifiers::kOut_Flag)) {
this->write("inout ");
} else if (modifiers.fFlags & Modifiers::kIn_Flag) {
- if (globalContext &&
- fProgram.fSettings.fCaps->generation() < GrGLSLGeneration::k130_GrGLSLGeneration) {
+ 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 &&
- fProgram.fSettings.fCaps->generation() < GrGLSLGeneration::k130_GrGLSLGeneration) {
+ if (globalContext && fCaps.generation() < GrGLSLGeneration::k130_GrGLSLGeneration) {
this->write("varying ");
} else {
this->write("out ");
@@ -547,7 +503,7 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
if (modifiers.fFlags & Modifiers::kConst_Flag) {
this->write("const ");
}
- if (fProgram.fSettings.fCaps->usesPrecisionModifiers()) {
+ if (fCaps.usesPrecisionModifiers()) {
if (modifiers.fFlags & Modifiers::kLowp_Flag) {
this->write("lowp ");
}
@@ -598,9 +554,9 @@ void GLSLCodeGenerator::writeVarDeclarations(const VarDeclarations& decl, bool g
this->writeExpression(*var.fValue, kTopLevel_Precedence);
}
if (!fFoundImageDecl && var.fVar->fType == *fContext.fImage2D_Type) {
- if (fProgram.fSettings.fCaps->imageLoadStoreExtensionString()) {
+ if (fCaps.imageLoadStoreExtensionString()) {
fHeader.writeText("#extension ");
- fHeader.writeText(fProgram.fSettings.fCaps->imageLoadStoreExtensionString());
+ fHeader.writeText(fCaps.imageLoadStoreExtensionString());
fHeader.writeText(" : require\n");
}
fFoundImageDecl = true;
@@ -714,22 +670,23 @@ void GLSLCodeGenerator::writeReturnStatement(const ReturnStatement& r) {
this->write(";");
}
-bool GLSLCodeGenerator::generateCode() {
- SkWStream* rawOut = fOut;
+void GLSLCodeGenerator::generateCode(const Program& program, ErrorReporter& errors,
+ SkWStream& out) {
+ ASSERT(fOut == nullptr);
fOut = &fHeader;
- fProgramKind = fProgram.fKind;
- this->write(fProgram.fSettings.fCaps->versionDeclString());
+ fProgramKind = program.fKind;
+ this->write(fCaps.versionDeclString());
this->writeLine();
- for (const auto& e : fProgram.fElements) {
+ for (const auto& e : program.fElements) {
if (e->fKind == ProgramElement::kExtension_Kind) {
this->writeExtension((Extension&) *e);
}
}
SkDynamicMemoryWStream body;
fOut = &body;
- if (fProgram.fSettings.fCaps->usesPrecisionModifiers()) {
+ if (fCaps.usesPrecisionModifiers()) {
this->write("precision ");
- switch (fProgram.fDefaultPrecision) {
+ switch (program.fDefaultPrecision) {
case Modifiers::kLowp_Flag:
this->write("lowp");
break;
@@ -745,7 +702,7 @@ bool GLSLCodeGenerator::generateCode() {
}
this->writeLine(" float;");
}
- for (const auto& e : fProgram.fElements) {
+ for (const auto& e : program.fElements) {
switch (e->fKind) {
case ProgramElement::kExtension_Kind:
break;
@@ -758,9 +715,9 @@ bool GLSLCodeGenerator::generateCode() {
this->writeVarDeclarations(decl, true);
this->writeLine();
} else if (builtin == SK_FRAGCOLOR_BUILTIN &&
- fProgram.fSettings.fCaps->mustDeclareFragmentShaderOutput()) {
+ fCaps.mustDeclareFragmentShaderOutput()) {
this->write("out ");
- if (fProgram.fSettings.fCaps->usesPrecisionModifiers()) {
+ if (fCaps.usesPrecisionModifiers()) {
this->write("mediump ");
}
this->writeLine("vec4 sk_FragColor;");
@@ -785,9 +742,8 @@ bool GLSLCodeGenerator::generateCode() {
}
fOut = nullptr;
- write_data(*fHeader.detachAsData(), *rawOut);
- write_data(*body.detachAsData(), *rawOut);
- return true;
+ write_data(*fHeader.detachAsData(), out);
+ write_data(*body.detachAsData(), out);
}
}