unified ASTLayout/Layout and ASTModifiers/Modifiers

BUG=skia:

Change-Id: Ib4c2c94401e586e93e926776e13c0f7c12212f7e
Reviewed-on: https://skia-review.googlesource.com/5268
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2016-11-28 11:23:23 -05:00 committed by Skia Commit-Bot
parent 2b3dab62bc
commit 11d5397431
12 changed files with 313 additions and 518 deletions

View File

@ -162,10 +162,6 @@ std::unique_ptr<Statement> IRGenerator::convertVarDeclarationStatement(
return std::unique_ptr<Statement>(new VarDeclarationsStatement(std::move(decl)));
}
Modifiers IRGenerator::convertModifiers(const ASTModifiers& modifiers) {
return Modifiers(modifiers);
}
std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVarDeclarations& decl,
Variable::Storage storage) {
std::vector<VarDeclaration> variables;
@ -174,7 +170,6 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
return nullptr;
}
for (const auto& varDecl : decl.fVars) {
Modifiers modifiers = this->convertModifiers(decl.fModifiers);
const Type* type = baseType;
ASSERT(type->kind() != Type::kArray_Kind);
std::vector<std::unique_ptr<Expression>> sizes;
@ -205,8 +200,8 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
sizes.push_back(nullptr);
}
}
auto var = std::unique_ptr<Variable>(new Variable(decl.fPosition, modifiers, varDecl.fName,
*type, storage));
auto var = std::unique_ptr<Variable>(new Variable(decl.fPosition, decl.fModifiers,
varDecl.fName, *type, storage));
std::unique_ptr<Expression> value;
if (varDecl.fValue) {
value = this->convertExpression(*varDecl.fValue);
@ -236,8 +231,7 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
std::unique_ptr<ModifiersDeclaration> IRGenerator::convertModifiersDeclaration(
const ASTModifiersDeclaration& m) {
Modifiers modifiers = this->convertModifiers(m.fModifiers);
return std::unique_ptr<ModifiersDeclaration>(new ModifiersDeclaration(modifiers));
return std::unique_ptr<ModifiersDeclaration>(new ModifiersDeclaration(m.fModifiers));
}
std::unique_ptr<Statement> IRGenerator::convertIf(const ASTIfStatement& s) {
@ -414,9 +408,8 @@ std::unique_ptr<FunctionDefinition> IRGenerator::convertFunction(const ASTFuncti
type = newType;
}
SkString name = param->fName;
Modifiers modifiers = this->convertModifiers(param->fModifiers);
Position pos = param->fPosition;
Variable* var = new Variable(pos, modifiers, std::move(name), *type,
Variable* var = new Variable(pos, param->fModifiers, std::move(name), *type,
Variable::kParameter_Storage);
fSymbolTable->takeOwnership(var);
parameters.push_back(var);
@ -507,7 +500,6 @@ std::unique_ptr<FunctionDefinition> IRGenerator::convertFunction(const ASTFuncti
std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTInterfaceBlock& intf) {
std::shared_ptr<SymbolTable> old = fSymbolTable;
AutoSymbolTable table(this);
Modifiers mods = this->convertModifiers(intf.fModifiers);
std::vector<Type::Field> fields;
for (size_t i = 0; i < intf.fDeclarations.size(); i++) {
std::unique_ptr<VarDeclarations> decl = this->convertVarDeclarations(
@ -535,7 +527,8 @@ std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTInte
Type* type = new Type(intf.fInterfaceName, fields);
fSymbolTable->takeOwnership(type);
SkString name = intf.fValueName.size() > 0 ? intf.fValueName : intf.fInterfaceName;
Variable* var = new Variable(intf.fPosition, mods, name, *type, Variable::kGlobal_Storage);
Variable* var = new Variable(intf.fPosition, intf.fModifiers, name, *type,
Variable::kGlobal_Storage);
fSymbolTable->takeOwnership(var);
if (intf.fValueName.size()) {
old->addWithoutOwnership(intf.fValueName, var);

View File

@ -24,7 +24,6 @@
#include "ast/SkSLASTIdentifier.h"
#include "ast/SkSLASTIfStatement.h"
#include "ast/SkSLASTInterfaceBlock.h"
#include "ast/SkSLASTModifiers.h"
#include "ast/SkSLASTModifiersDeclaration.h"
#include "ast/SkSLASTPrefixExpression.h"
#include "ast/SkSLASTReturnStatement.h"
@ -135,7 +134,7 @@ private:
std::unique_ptr<Expression> convertIndex(std::unique_ptr<Expression> base,
const ASTExpression& index);
std::unique_ptr<InterfaceBlock> convertInterfaceBlock(const ASTInterfaceBlock& s);
Modifiers convertModifiers(const ASTModifiers& m);
Modifiers convertModifiers(const Modifiers& 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);

View File

@ -69,6 +69,7 @@
#include "ast/SkSLASTVarDeclarationStatement.h"
#include "ast/SkSLASTWhileStatement.h"
#include "ir/SkSLSymbolTable.h"
#include "ir/SkSLModifiers.h"
#include "ir/SkSLType.h"
namespace SkSL {
@ -280,7 +281,7 @@ std::unique_ptr<ASTDeclaration> Parser::directive() {
/* modifiers (structVarDeclaration | type IDENTIFIER ((LPAREN parameter
(COMMA parameter)* RPAREN (block | SEMICOLON)) | SEMICOLON) | interfaceBlock) */
std::unique_ptr<ASTDeclaration> Parser::declaration() {
ASTModifiers modifiers = this->modifiers();
Modifiers modifiers = this->modifiers();
Token lookahead = this->peek();
if (lookahead.fKind == Token::IDENTIFIER && !this->isType(lookahead.fText)) {
// we have an identifier that's not a type, could be the start of an interface block
@ -341,7 +342,7 @@ std::unique_ptr<ASTDeclaration> Parser::declaration() {
/* modifiers type IDENTIFIER varDeclarationEnd */
std::unique_ptr<ASTVarDeclarations> Parser::varDeclarations() {
ASTModifiers modifiers = this->modifiers();
Modifiers modifiers = this->modifiers();
std::unique_ptr<ASTType> type(this->type());
if (!type) {
return nullptr;
@ -398,7 +399,7 @@ std::unique_ptr<ASTType> Parser::structDeclaration() {
}
/* structDeclaration ((IDENTIFIER varDeclarationEnd) | SEMICOLON) */
std::unique_ptr<ASTVarDeclarations> Parser::structVarDeclaration(ASTModifiers modifiers) {
std::unique_ptr<ASTVarDeclarations> Parser::structVarDeclaration(Modifiers modifiers) {
std::unique_ptr<ASTType> type = this->structDeclaration();
if (!type) {
return nullptr;
@ -424,7 +425,7 @@ std::unique_ptr<ASTVarDeclarations> Parser::structVarDeclaration(ASTModifiers mo
/* (LBRACKET expression? RBRACKET)* (EQ expression)? (COMMA IDENTIFER
(LBRACKET expression? RBRACKET)* (EQ expression)?)* SEMICOLON */
std::unique_ptr<ASTVarDeclarations> Parser::varDeclarationEnd(ASTModifiers mods,
std::unique_ptr<ASTVarDeclarations> Parser::varDeclarationEnd(Modifiers mods,
std::unique_ptr<ASTType> type,
SkString name) {
std::vector<ASTVarDeclaration> vars;
@ -497,7 +498,7 @@ std::unique_ptr<ASTVarDeclarations> Parser::varDeclarationEnd(ASTModifiers mods,
/* modifiers type IDENTIFIER (LBRACKET INT_LITERAL RBRACKET)? */
std::unique_ptr<ASTParameter> Parser::parameter() {
ASTModifiers modifiers = this->modifiersWithDefaults(ASTModifiers::kIn_Flag);
Modifiers modifiers = this->modifiersWithDefaults(Modifiers::kIn_Flag);
std::unique_ptr<ASTType> type = this->type();
if (!type) {
return nullptr;
@ -536,7 +537,7 @@ int Parser::layoutInt() {
}
/* LAYOUT LPAREN IDENTIFIER (EQ INT_LITERAL)? (COMMA IDENTIFIER (EQ INT_LITERAL)?)* RPAREN */
ASTLayout Parser::layout() {
Layout Parser::layout() {
int location = -1;
int binding = -1;
int index = -1;
@ -546,12 +547,12 @@ ASTLayout Parser::layout() {
bool originUpperLeft = false;
bool overrideCoverage = false;
bool blendSupportAllEquations = false;
ASTLayout::Format format = ASTLayout::Format::kUnspecified;
Layout::Format format = Layout::Format::kUnspecified;
bool pushConstant = false;
if (this->peek().fKind == Token::LAYOUT) {
this->nextToken();
if (!this->expect(Token::LPAREN, "'('")) {
return ASTLayout(location, binding, index, set, builtin, inputAttachmentIndex,
return Layout(location, binding, index, set, builtin, inputAttachmentIndex,
originUpperLeft, overrideCoverage, blendSupportAllEquations, format,
pushConstant);
}
@ -575,7 +576,7 @@ ASTLayout Parser::layout() {
overrideCoverage = true;
} else if (t.fText == "blend_support_all_equations") {
blendSupportAllEquations = true;
} else if (ASTLayout::ReadFormat(t.fText, &format)) {
} else if (Layout::ReadFormat(t.fText, &format)) {
// AST::ReadFormat stored the result in 'format'.
} else if (t.fText == "push_constant") {
pushConstant = true;
@ -592,68 +593,68 @@ ASTLayout Parser::layout() {
}
}
}
return ASTLayout(location, binding, index, set, builtin, inputAttachmentIndex, originUpperLeft,
return Layout(location, binding, index, set, builtin, inputAttachmentIndex, originUpperLeft,
overrideCoverage, blendSupportAllEquations, format, pushConstant);
}
/* layout? (UNIFORM | CONST | IN | OUT | INOUT | LOWP | MEDIUMP | HIGHP | FLAT | NOPERSPECTIVE)* */
ASTModifiers Parser::modifiers() {
ASTLayout layout = this->layout();
Modifiers Parser::modifiers() {
Layout layout = this->layout();
int flags = 0;
for (;;) {
// TODO: handle duplicate / incompatible flags
switch (peek().fKind) {
case Token::UNIFORM:
this->nextToken();
flags |= ASTModifiers::kUniform_Flag;
flags |= Modifiers::kUniform_Flag;
break;
case Token::CONST:
this->nextToken();
flags |= ASTModifiers::kConst_Flag;
flags |= Modifiers::kConst_Flag;
break;
case Token::IN:
this->nextToken();
flags |= ASTModifiers::kIn_Flag;
flags |= Modifiers::kIn_Flag;
break;
case Token::OUT:
this->nextToken();
flags |= ASTModifiers::kOut_Flag;
flags |= Modifiers::kOut_Flag;
break;
case Token::INOUT:
this->nextToken();
flags |= ASTModifiers::kIn_Flag;
flags |= ASTModifiers::kOut_Flag;
flags |= Modifiers::kIn_Flag;
flags |= Modifiers::kOut_Flag;
break;
case Token::LOWP:
this->nextToken();
flags |= ASTModifiers::kLowp_Flag;
flags |= Modifiers::kLowp_Flag;
break;
case Token::MEDIUMP:
this->nextToken();
flags |= ASTModifiers::kMediump_Flag;
flags |= Modifiers::kMediump_Flag;
break;
case Token::HIGHP:
this->nextToken();
flags |= ASTModifiers::kHighp_Flag;
flags |= Modifiers::kHighp_Flag;
break;
case Token::FLAT:
this->nextToken();
flags |= ASTModifiers::kFlat_Flag;
flags |= Modifiers::kFlat_Flag;
break;
case Token::NOPERSPECTIVE:
this->nextToken();
flags |= ASTModifiers::kNoPerspective_Flag;
flags |= Modifiers::kNoPerspective_Flag;
break;
default:
return ASTModifiers(layout, flags);
return Modifiers(layout, flags);
}
}
}
ASTModifiers Parser::modifiersWithDefaults(int defaultFlags) {
ASTModifiers result = this->modifiers();
Modifiers Parser::modifiersWithDefaults(int defaultFlags) {
Modifiers result = this->modifiers();
if (!result.fFlags) {
return ASTModifiers(result.fLayout, defaultFlags);
return Modifiers(result.fLayout, defaultFlags);
}
return result;
}
@ -724,7 +725,7 @@ std::unique_ptr<ASTType> Parser::type() {
}
/* IDENTIFIER LBRACE varDeclaration* RBRACE */
std::unique_ptr<ASTDeclaration> Parser::interfaceBlock(ASTModifiers mods) {
std::unique_ptr<ASTDeclaration> Parser::interfaceBlock(Modifiers mods) {
Token name;
if (!this->expect(Token::IDENTIFIER, "an identifier", &name)) {
return nullptr;

View File

@ -31,8 +31,6 @@ struct ASTExpressionStatement;
struct ASTForStatement;
struct ASTIfStatement;
struct ASTInterfaceBlock;
struct ASTLayout;
struct ASTModifiers;
struct ASTParameter;
struct ASTPrecision;
struct ASTReturnStatement;
@ -41,6 +39,8 @@ struct ASTSuffix;
struct ASTType;
struct ASTWhileStatement;
struct ASTVarDeclarations;
struct Layout;
struct Modifiers;
class SymbolTable;
/**
@ -112,9 +112,9 @@ private:
std::unique_ptr<ASTType> structDeclaration();
std::unique_ptr<ASTVarDeclarations> structVarDeclaration(ASTModifiers modifiers);
std::unique_ptr<ASTVarDeclarations> structVarDeclaration(Modifiers modifiers);
std::unique_ptr<ASTVarDeclarations> varDeclarationEnd(ASTModifiers modifiers,
std::unique_ptr<ASTVarDeclarations> varDeclarationEnd(Modifiers modifiers,
std::unique_ptr<ASTType> type,
SkString name);
@ -122,17 +122,17 @@ private:
int layoutInt();
ASTLayout layout();
Layout layout();
ASTModifiers modifiers();
Modifiers modifiers();
ASTModifiers modifiersWithDefaults(int defaultFlags);
Modifiers modifiersWithDefaults(int defaultFlags);
std::unique_ptr<ASTStatement> statement();
std::unique_ptr<ASTType> type();
std::unique_ptr<ASTDeclaration> interfaceBlock(ASTModifiers mods);
std::unique_ptr<ASTDeclaration> interfaceBlock(Modifiers mods);
std::unique_ptr<ASTIfStatement> ifStatement();

View File

@ -9,6 +9,7 @@
#define SKSL_ASTINTERFACEBLOCK
#include "SkSLASTVarDeclaration.h"
#include "../ir/SkSLModifiers.h"
namespace SkSL {
@ -23,7 +24,7 @@ namespace SkSL {
struct ASTInterfaceBlock : public ASTDeclaration {
// valueName is empty when it was not present in the source
ASTInterfaceBlock(Position position,
ASTModifiers modifiers,
Modifiers modifiers,
SkString interfaceName,
SkString valueName,
std::vector<std::unique_ptr<ASTVarDeclarations>> declarations)
@ -45,7 +46,7 @@ struct ASTInterfaceBlock : public ASTDeclaration {
return result + ";";
}
const ASTModifiers fModifiers;
const Modifiers fModifiers;
const SkString fInterfaceName;
const SkString fValueName;
const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations;

View File

@ -1,164 +0,0 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_ASTLAYOUT
#define SKSL_ASTLAYOUT
#include "SkSLASTNode.h"
#include "SkSLUtil.h"
namespace SkSL {
/**
* Represents a layout block appearing before a variable declaration, as in:
*
* layout (location = 0) int x;
*/
struct ASTLayout : public ASTNode {
// These are used by images in GLSL. We only support a subset of what GL supports.
enum class Format {
kUnspecified = -1,
kRGBA32F,
kR32F,
kRGBA16F,
kR16F,
kRGBA8,
kR8,
kRGBA8I,
kR8I,
};
static const char* FormatToStr(Format format) {
switch (format) {
case Format::kUnspecified: return "";
case Format::kRGBA32F: return "rgba32f";
case Format::kR32F: return "r32f";
case Format::kRGBA16F: return "rgba16f";
case Format::kR16F: return "r16f";
case Format::kRGBA8: return "rgba8";
case Format::kR8: return "r8";
case Format::kRGBA8I: return "rgba8i";
case Format::kR8I: return "r8i";
}
SkFAIL("Unexpected format");
return "";
}
static bool ReadFormat(SkString str, Format* format) {
if (str == "rgba32f") {
*format = Format::kRGBA32F;
return true;
} else if (str == "r32f") {
*format = Format::kR32F;
return true;
} else if (str == "rgba16f") {
*format = Format::kRGBA16F;
return true;
} else if (str == "r16f") {
*format = Format::kR16F;
return true;
} else if (str == "rgba8") {
*format = Format::kRGBA8;
return true;
} else if (str == "r8") {
*format = Format::kR8;
return true;
} else if (str == "rgba8i") {
*format = Format::kRGBA8I;
return true;
} else if (str == "r8i") {
*format = Format::kR8I;
return true;
}
return false;
}
// For int parameters, a -1 means no value
ASTLayout(int location, int binding, int index, int set, int builtin, int inputAttachmentIndex,
bool originUpperLeft, bool overrideCoverage, bool blendSupportAllEquations,
Format format, bool pushConstant)
: fLocation(location)
, fBinding(binding)
, fIndex(index)
, fSet(set)
, fBuiltin(builtin)
, fInputAttachmentIndex(inputAttachmentIndex)
, fOriginUpperLeft(originUpperLeft)
, fOverrideCoverage(overrideCoverage)
, fBlendSupportAllEquations(blendSupportAllEquations)
, fFormat(format)
, fPushConstant(pushConstant) {}
SkString description() const {
SkString result;
SkString separator;
if (fLocation >= 0) {
result += separator + "location = " + to_string(fLocation);
separator = ", ";
}
if (fBinding >= 0) {
result += separator + "binding = " + to_string(fBinding);
separator = ", ";
}
if (fIndex >= 0) {
result += separator + "index = " + to_string(fIndex);
separator = ", ";
}
if (fSet >= 0) {
result += separator + "set = " + to_string(fSet);
separator = ", ";
}
if (fBuiltin >= 0) {
result += separator + "builtin = " + to_string(fBuiltin);
separator = ", ";
}
if (fInputAttachmentIndex >= 0) {
result += separator + "input_attachment_index = " + to_string(fBuiltin);
separator = ", ";
}
if (fOriginUpperLeft) {
result += separator + "origin_upper_left";
separator = ", ";
}
if (fOverrideCoverage) {
result += separator + "override_coverage";
separator = ", ";
}
if (fBlendSupportAllEquations) {
result += separator + "blend_support_all_equations";
separator = ", ";
}
if (fFormat != Format::kUnspecified) {
result += separator + FormatToStr(fFormat);
separator = ", ";
}
if (fPushConstant) {
result += separator + "push_constant";
separator = ", ";
}
if (result.size() > 0) {
result = "layout (" + result + ")";
}
return result;
}
const int fLocation;
const int fBinding;
const int fIndex;
const int fSet;
const int fBuiltin;
const int fInputAttachmentIndex;
const bool fOriginUpperLeft;
const bool fOverrideCoverage;
const bool fBlendSupportAllEquations;
const Format fFormat;
const bool fPushConstant;
};
} // namespace
#endif

View File

@ -1,78 +0,0 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_ASTMODIFIERS
#define SKSL_ASTMODIFIERS
#include "SkSLASTLayout.h"
#include "SkSLASTNode.h"
namespace SkSL {
/**
* A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration.
*/
struct ASTModifiers : public ASTNode {
enum Flag {
kNo_Flag = 0,
kConst_Flag = 1,
kIn_Flag = 2,
kOut_Flag = 4,
kLowp_Flag = 8,
kMediump_Flag = 16,
kHighp_Flag = 32,
kUniform_Flag = 64,
kFlat_Flag = 128,
kNoPerspective_Flag = 256
};
ASTModifiers(ASTLayout layout, int flags)
: fLayout(layout)
, fFlags(flags) {}
SkString description() const override {
SkString result = fLayout.description();
if (fFlags & kUniform_Flag) {
result += "uniform ";
}
if (fFlags & kConst_Flag) {
result += "const ";
}
if (fFlags & kLowp_Flag) {
result += "lowp ";
}
if (fFlags & kMediump_Flag) {
result += "mediump ";
}
if (fFlags & kHighp_Flag) {
result += "highp ";
}
if (fFlags & kFlat_Flag) {
result += "flat ";
}
if (fFlags & kNoPerspective_Flag) {
result += "noperspective ";
}
if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) {
result += "inout ";
} else if (fFlags & kIn_Flag) {
result += "in ";
} else if (fFlags & kOut_Flag) {
result += "out ";
}
return result;
}
const ASTLayout fLayout;
const int fFlags;
};
} // namespace
#endif

View File

@ -9,7 +9,7 @@
#define SKSL_ASTMODIFIERDECLARATION
#include "SkSLASTDeclaration.h"
#include "SkSLASTModifiers.h"
#include "../ir/SkSLModifiers.h"
namespace SkSL {
@ -19,7 +19,7 @@ namespace SkSL {
* layout(blend_support_all_equations) out;
*/
struct ASTModifiersDeclaration : public ASTDeclaration {
ASTModifiersDeclaration(ASTModifiers modifiers)
ASTModifiersDeclaration(Modifiers modifiers)
: INHERITED(Position(), kModifiers_Kind)
, fModifiers(modifiers) {}
@ -27,7 +27,7 @@ struct ASTModifiersDeclaration : public ASTDeclaration {
return fModifiers.description() + ";";
}
ASTModifiers fModifiers;
Modifiers fModifiers;
typedef ASTDeclaration INHERITED;
};

View File

@ -8,8 +8,8 @@
#ifndef SKSL_ASTPARAMETER
#define SKSL_ASTPARAMETER
#include "SkSLASTModifiers.h"
#include "SkSLASTType.h"
#include "../ir/SkSLModifiers.h"
namespace SkSL {
@ -19,7 +19,7 @@ namespace SkSL {
struct ASTParameter : public ASTPositionNode {
// 'sizes' is a list of the array sizes appearing on a parameter, in source order.
// e.g. int x[3][1] would have sizes [3, 1].
ASTParameter(Position position, ASTModifiers modifiers, std::unique_ptr<ASTType> type,
ASTParameter(Position position, Modifiers modifiers, std::unique_ptr<ASTType> type,
SkString name, std::vector<int> sizes)
: INHERITED(position)
, fModifiers(modifiers)
@ -35,7 +35,7 @@ struct ASTParameter : public ASTPositionNode {
return result;
}
const ASTModifiers fModifiers;
const Modifiers fModifiers;
const std::unique_ptr<ASTType> fType;
const SkString fName;
const std::vector<int> fSizes;

View File

@ -9,10 +9,10 @@
#define SKSL_ASTVARDECLARATIONS
#include "SkSLASTDeclaration.h"
#include "SkSLASTModifiers.h"
#include "SkSLASTStatement.h"
#include "SkSLASTType.h"
#include "../SkSLUtil.h"
#include "../ir/SkSLModifiers.h"
namespace SkSL {
@ -57,7 +57,7 @@ struct ASTVarDeclaration {
* A variable declaration statement, which may consist of one or more individual variables.
*/
struct ASTVarDeclarations : public ASTDeclaration {
ASTVarDeclarations(ASTModifiers modifiers,
ASTVarDeclarations(Modifiers modifiers,
std::unique_ptr<ASTType> type,
std::vector<ASTVarDeclaration> vars)
: INHERITED(type->fPosition, kVar_Kind)
@ -76,7 +76,7 @@ struct ASTVarDeclarations : public ASTDeclaration {
return result;
}
const ASTModifiers fModifiers;
const Modifiers fModifiers;
const std::unique_ptr<ASTType> fType;
const std::vector<ASTVarDeclaration> fVars;

View File

@ -8,6 +8,9 @@
#ifndef SKSL_LAYOUT
#define SKSL_LAYOUT
#include "SkString.h"
#include "SkSLUtil.h"
namespace SkSL {
/**
@ -16,22 +19,67 @@ namespace SkSL {
* layout (location = 0) int x;
*/
struct Layout {
Layout(const ASTLayout& layout)
: fLocation(layout.fLocation)
, fBinding(layout.fBinding)
, fIndex(layout.fIndex)
, fSet(layout.fSet)
, fBuiltin(layout.fBuiltin)
, fInputAttachmentIndex(layout.fInputAttachmentIndex)
, fOriginUpperLeft(layout.fOriginUpperLeft)
, fOverrideCoverage(layout.fOverrideCoverage)
, fBlendSupportAllEquations(layout.fBlendSupportAllEquations)
, fFormat(layout.fFormat)
, fPushConstant(layout.fPushConstant) {}
// These are used by images in GLSL. We only support a subset of what GL supports.
enum class Format {
kUnspecified = -1,
kRGBA32F,
kR32F,
kRGBA16F,
kR16F,
kRGBA8,
kR8,
kRGBA8I,
kR8I,
};
static const char* FormatToStr(Format format) {
switch (format) {
case Format::kUnspecified: return "";
case Format::kRGBA32F: return "rgba32f";
case Format::kR32F: return "r32f";
case Format::kRGBA16F: return "rgba16f";
case Format::kR16F: return "r16f";
case Format::kRGBA8: return "rgba8";
case Format::kR8: return "r8";
case Format::kRGBA8I: return "rgba8i";
case Format::kR8I: return "r8i";
}
SkFAIL("Unexpected format");
return "";
}
static bool ReadFormat(SkString str, Format* format) {
if (str == "rgba32f") {
*format = Format::kRGBA32F;
return true;
} else if (str == "r32f") {
*format = Format::kR32F;
return true;
} else if (str == "rgba16f") {
*format = Format::kRGBA16F;
return true;
} else if (str == "r16f") {
*format = Format::kR16F;
return true;
} else if (str == "rgba8") {
*format = Format::kRGBA8;
return true;
} else if (str == "r8") {
*format = Format::kR8;
return true;
} else if (str == "rgba8i") {
*format = Format::kRGBA8I;
return true;
} else if (str == "r8i") {
*format = Format::kR8I;
return true;
}
return false;
}
Layout(int location, int binding, int index, int set, int builtin, int inputAttachmentIndex,
bool originUpperLeft, bool overrideCoverage, bool blendSupportAllEquations,
ASTLayout::Format format, bool pushconstant)
Format format, bool pushconstant)
: fLocation(location)
, fBinding(binding)
, fIndex(index)
@ -54,7 +102,7 @@ struct Layout {
, fOriginUpperLeft(false)
, fOverrideCoverage(false)
, fBlendSupportAllEquations(false)
, fFormat(ASTLayout::Format::kUnspecified)
, fFormat(Format::kUnspecified)
, fPushConstant(false) {}
SkString description() const {
@ -96,8 +144,8 @@ struct Layout {
result += separator + "blend_support_all_equations";
separator = ", ";
}
if (ASTLayout::Format::kUnspecified != fFormat) {
result += separator + ASTLayout::FormatToStr(fFormat);
if (Format::kUnspecified != fFormat) {
result += separator + FormatToStr(fFormat);
separator = ", ";
}
if (fPushConstant) {
@ -140,7 +188,7 @@ struct Layout {
bool fOriginUpperLeft;
bool fOverrideCoverage;
bool fBlendSupportAllEquations;
ASTLayout::Format fFormat;
Format fFormat;
bool fPushConstant;
};

View File

@ -8,7 +8,6 @@
#ifndef SKSL_MODIFIERS
#define SKSL_MODIFIERS
#include "../ast/SkSLASTModifiers.h"
#include "SkSLLayout.h"
namespace SkSL {
@ -18,26 +17,22 @@ namespace SkSL {
*/
struct Modifiers {
enum Flag {
kNo_Flag = ASTModifiers::kNo_Flag,
kConst_Flag = ASTModifiers::kConst_Flag,
kIn_Flag = ASTModifiers::kIn_Flag,
kOut_Flag = ASTModifiers::kOut_Flag,
kLowp_Flag = ASTModifiers::kLowp_Flag,
kMediump_Flag = ASTModifiers::kMediump_Flag,
kHighp_Flag = ASTModifiers::kHighp_Flag,
kUniform_Flag = ASTModifiers::kUniform_Flag,
kFlat_Flag = ASTModifiers::kFlat_Flag,
kNoPerspective_Flag = ASTModifiers::kNoPerspective_Flag
kNo_Flag = 0,
kConst_Flag = 1,
kIn_Flag = 2,
kOut_Flag = 4,
kLowp_Flag = 8,
kMediump_Flag = 16,
kHighp_Flag = 32,
kUniform_Flag = 64,
kFlat_Flag = 128,
kNoPerspective_Flag = 256
};
Modifiers()
: fLayout(Layout())
, fFlags(0) {}
Modifiers(const ASTModifiers& modifiers)
: fLayout(modifiers.fLayout)
, fFlags(modifiers.fFlags) {}
Modifiers(Layout& layout, int flags)
: fLayout(layout)
, fFlags(flags) {}