Simplify/localize the LayoutToken hash map
Uses the initializer_list constructor to avoid generating a bunch of insert calls, and then moves everything right into layout(). Change-Id: I09f5538e20ea6f7d3b6117020302a41e18b66295 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539822 Reviewed-by: John Stiles <johnstiles@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
2418c88fb1
commit
a6f57a80da
@ -395,7 +395,6 @@ generated_cc_atom(
|
||||
"//include/private:SkSLDefines_hdr",
|
||||
"//include/private:SkSLProgramKind_hdr",
|
||||
"//include/private:SkTArray_hdr",
|
||||
"//include/private:SkTHash_hdr",
|
||||
"//include/sksl:DSLCore_hdr",
|
||||
"//include/sksl:DSLExpression_hdr",
|
||||
"//include/sksl:DSLLayout_hdr",
|
||||
@ -423,6 +422,7 @@ generated_cc_atom(
|
||||
"//include/private:SkSLModifiers_hdr",
|
||||
"//include/private:SkSLProgramElement_hdr",
|
||||
"//include/private:SkSLString_hdr",
|
||||
"//include/private:SkTHash_hdr",
|
||||
"//include/sksl:DSLBlock_hdr",
|
||||
"//include/sksl:DSLCase_hdr",
|
||||
"//include/sksl:DSLFunction_hdr",
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "include/private/SkSLModifiers.h"
|
||||
#include "include/private/SkSLProgramElement.h"
|
||||
#include "include/private/SkSLString.h"
|
||||
#include "include/private/SkTHash.h"
|
||||
#include "include/sksl/DSL.h"
|
||||
#include "include/sksl/DSLBlock.h"
|
||||
#include "include/sksl/DSLCase.h"
|
||||
@ -29,6 +30,7 @@
|
||||
#include "src/sksl/ir/SkSLProgram.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
@ -99,25 +101,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
SkTHashMap<std::string_view, DSLParser::LayoutToken>* DSLParser::sLayoutTokens;
|
||||
|
||||
void DSLParser::InitLayoutMap() {
|
||||
sLayoutTokens = new SkTHashMap<std::string_view, LayoutToken>;
|
||||
#define TOKEN(name, text) sLayoutTokens->set(text, LayoutToken::name)
|
||||
TOKEN(LOCATION, "location");
|
||||
TOKEN(OFFSET, "offset");
|
||||
TOKEN(BINDING, "binding");
|
||||
TOKEN(INDEX, "index");
|
||||
TOKEN(SET, "set");
|
||||
TOKEN(BUILTIN, "builtin");
|
||||
TOKEN(INPUT_ATTACHMENT_INDEX, "input_attachment_index");
|
||||
TOKEN(ORIGIN_UPPER_LEFT, "origin_upper_left");
|
||||
TOKEN(BLEND_SUPPORT_ALL_EQUATIONS, "blend_support_all_equations");
|
||||
TOKEN(PUSH_CONSTANT, "push_constant");
|
||||
TOKEN(COLOR, "color");
|
||||
#undef TOKEN
|
||||
}
|
||||
|
||||
DSLParser::DSLParser(Compiler* compiler, const ProgramSettings& settings, ProgramKind kind,
|
||||
std::string text)
|
||||
: fCompiler(*compiler)
|
||||
@ -131,8 +114,6 @@ DSLParser::DSLParser(Compiler* compiler, const ProgramSettings& settings, Progra
|
||||
// We manage our symbol tables manually, so no need for name mangling
|
||||
fSettings.fDSLMangling = false;
|
||||
fLexer.start(*fText);
|
||||
static const bool layoutMapInitialized = []{ InitLayoutMap(); return true; }();
|
||||
(void) layoutMapInitialized;
|
||||
}
|
||||
|
||||
Token DSLParser::nextRawToken() {
|
||||
@ -796,6 +777,35 @@ std::string_view DSLParser::layoutIdentifier() {
|
||||
|
||||
/* LAYOUT LPAREN IDENTIFIER (EQ INT_LITERAL)? (COMMA IDENTIFIER (EQ INT_LITERAL)?)* RPAREN */
|
||||
DSLLayout DSLParser::layout() {
|
||||
enum class LayoutToken {
|
||||
LOCATION,
|
||||
OFFSET,
|
||||
BINDING,
|
||||
INDEX,
|
||||
SET,
|
||||
BUILTIN,
|
||||
INPUT_ATTACHMENT_INDEX,
|
||||
ORIGIN_UPPER_LEFT,
|
||||
BLEND_SUPPORT_ALL_EQUATIONS,
|
||||
PUSH_CONSTANT,
|
||||
COLOR,
|
||||
};
|
||||
|
||||
using LayoutMap = SkTHashMap<std::string_view, LayoutToken>;
|
||||
static LayoutMap* sLayoutTokens = new LayoutMap{
|
||||
{"location", LayoutToken::LOCATION},
|
||||
{"offset", LayoutToken::OFFSET},
|
||||
{"binding", LayoutToken::BINDING},
|
||||
{"index", LayoutToken::INDEX},
|
||||
{"set", LayoutToken::SET},
|
||||
{"builtin", LayoutToken::BUILTIN},
|
||||
{"input_attachment_index", LayoutToken::INPUT_ATTACHMENT_INDEX},
|
||||
{"origin_upper_left", LayoutToken::ORIGIN_UPPER_LEFT},
|
||||
{"blend_support_all_equations", LayoutToken::BLEND_SUPPORT_ALL_EQUATIONS},
|
||||
{"push_constant", LayoutToken::PUSH_CONSTANT},
|
||||
{"color", LayoutToken::COLOR},
|
||||
};
|
||||
|
||||
DSLLayout result;
|
||||
if (this->checkNext(Token::Kind::TK_LAYOUT)) {
|
||||
if (!this->expect(Token::Kind::TK_LPAREN, "'('")) {
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "include/private/SkSLDefines.h"
|
||||
#include "include/private/SkSLProgramKind.h"
|
||||
#include "include/private/SkTArray.h"
|
||||
#include "include/private/SkTHash.h"
|
||||
#include "include/sksl/DSLCore.h"
|
||||
#include "include/sksl/DSLExpression.h"
|
||||
#include "include/sksl/DSLLayout.h"
|
||||
@ -52,20 +51,6 @@ class AutoDSLDepth;
|
||||
*/
|
||||
class DSLParser {
|
||||
public:
|
||||
enum class LayoutToken {
|
||||
LOCATION,
|
||||
OFFSET,
|
||||
BINDING,
|
||||
INDEX,
|
||||
SET,
|
||||
BUILTIN,
|
||||
INPUT_ATTACHMENT_INDEX,
|
||||
ORIGIN_UPPER_LEFT,
|
||||
BLEND_SUPPORT_ALL_EQUATIONS,
|
||||
PUSH_CONSTANT,
|
||||
COLOR,
|
||||
};
|
||||
|
||||
DSLParser(Compiler* compiler, const ProgramSettings& settings, ProgramKind kind,
|
||||
std::string text);
|
||||
|
||||
@ -78,8 +63,6 @@ public:
|
||||
Position position(Token token);
|
||||
|
||||
private:
|
||||
static void InitLayoutMap();
|
||||
|
||||
/**
|
||||
* Return the next token, including whitespace tokens, from the parse stream.
|
||||
*/
|
||||
@ -355,8 +338,6 @@ private:
|
||||
bool fOldEncounteredFatalError;
|
||||
};
|
||||
|
||||
static SkTHashMap<std::string_view, LayoutToken>* sLayoutTokens;
|
||||
|
||||
Compiler& fCompiler;
|
||||
ProgramSettings fSettings;
|
||||
ErrorReporter* fErrorReporter;
|
||||
|
Loading…
Reference in New Issue
Block a user