aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLIRGenerator.h
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2016-11-21 15:59:48 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-22 14:20:27 +0000
commit3605ace7ddaf0b576bf6df1c7a550ab4f44d22a8 (patch)
tree929ee78317ba05e8f2c36c0f1b4bafea87794ca0 /src/sksl/SkSLIRGenerator.h
parent9bcca6a2124b60ce9fab18ba697b28fc6a1354db (diff)
sksl programs can now directly query GLSL caps
This adds support for querying "sk_Caps.<cap>" directly from within an SkSL program. Combined with the existing support for collapsing 'if' statements with constant tests, this means we can query caps using ordinary 'if' statements and the tests will collapse out at compile time. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4795 Change-Id: I24d716a7fe6abf1489760bf08189164264269076 Reviewed-on: https://skia-review.googlesource.com/4795 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Diffstat (limited to 'src/sksl/SkSLIRGenerator.h')
-rw-r--r--src/sksl/SkSLIRGenerator.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h
index d7bd59ad02..5b56689517 100644
--- a/src/sksl/SkSLIRGenerator.h
+++ b/src/sksl/SkSLIRGenerator.h
@@ -49,6 +49,28 @@
namespace SkSL {
+struct CapValue {
+ CapValue()
+ : fKind(kInt_Kind)
+ , fValue(-1) {
+ ASSERT(false);
+ }
+
+ CapValue(bool b)
+ : fKind(kBool_Kind)
+ , fValue(b) {}
+
+ CapValue(int i)
+ : fKind(kInt_Kind)
+ , fValue(i) {}
+
+ enum {
+ kBool_Kind,
+ kInt_Kind,
+ } fKind;
+ int fValue;
+};
+
/**
* Performs semantic analysis on an abstract syntax tree (AST) and produces the corresponding
* (unoptimized) intermediate representation (IR).
@@ -67,6 +89,17 @@ public:
const ASTModifiersDeclaration& m);
private:
+ /**
+ * Prepare to compile a program. Pushes a new symbol table and installs the caps so that
+ * references to sk_Caps.<cap> can be resolved.
+ */
+ void start(std::unordered_map<SkString, CapValue>* caps);
+
+ /**
+ * Performs cleanup after compilation is complete.
+ */
+ void finish();
+
void pushSymbolTable();
void popSymbolTable();
@@ -105,6 +138,7 @@ private:
Modifiers convertModifiers(const ASTModifiers& m);
std::unique_ptr<Expression> convertPrefixExpression(const ASTPrefixExpression& expression);
std::unique_ptr<Statement> convertReturn(const ASTReturnStatement& r);
+ std::unique_ptr<Expression> getCap(Position position, SkString name);
std::unique_ptr<Expression> convertSuffixExpression(const ASTSuffixExpression& expression);
std::unique_ptr<Expression> convertField(std::unique_ptr<Expression> base,
const SkString& field);
@@ -120,6 +154,7 @@ private:
const Context& fContext;
const FunctionDeclaration* fCurrentFunction;
+ const std::unordered_map<SkString, CapValue>* fCapsMap;
std::shared_ptr<SymbolTable> fSymbolTable;
int fLoopLevel;
ErrorReporter& fErrors;