moved SkSL Extension data into IRNode

Change-Id: I6689bfc78e407ddd840d81ea56c844da92f3a65a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/320724
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
Ethan Nicholas 2020-09-30 10:17:00 -04:00 committed by Skia Commit-Bot
parent 4c1fcdb4e8
commit efb09e2caf
7 changed files with 40 additions and 9 deletions

View File

@ -1495,7 +1495,7 @@ void GLSLCodeGenerator::writeHeader() {
void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) {
switch (e.kind()) {
case ProgramElement::Kind::kExtension:
this->writeExtension(e.as<Extension>().fName);
this->writeExtension(e.as<Extension>().name());
break;
case ProgramElement::Kind::kVar: {
const VarDeclarations& decl = e.as<VarDeclarations>();

View File

@ -73,7 +73,7 @@ void MetalCodeGenerator::writeLine() {
}
void MetalCodeGenerator::writeExtension(const Extension& ext) {
this->writeLine("#extension " + ext.fName + " : enable");
this->writeLine("#extension " + ext.name() + " : enable");
}
String MetalCodeGenerator::typeName(const Type& type) {

View File

@ -3272,7 +3272,7 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream&
}
for (const auto& e : program) {
if (e.kind() == ProgramElement::Kind::kExtension) {
this->writeInstruction(SpvOpSourceExtension, ((Extension&) e).fName.c_str(), out);
this->writeInstruction(SpvOpSourceExtension, ((Extension&) e).name().c_str(), out);
}
}

View File

@ -19,19 +19,20 @@ struct Extension : public ProgramElement {
static constexpr Kind kProgramElementKind = Kind::kExtension;
Extension(int offset, String name)
: INHERITED(offset, kProgramElementKind)
, fName(std::move(name)) {}
: INHERITED(offset, kProgramElementKind, name) {}
const String& name() const {
return this->stringData();
}
std::unique_ptr<ProgramElement> clone() const override {
return std::unique_ptr<ProgramElement>(new Extension(fOffset, fName));
return std::unique_ptr<ProgramElement>(new Extension(fOffset, this->name()));
}
String description() const override {
return "#extension " + fName + " : enable";
return "#extension " + this->name() + " : enable";
}
const String fName;
using INHERITED = ProgramElement;
};

View File

@ -38,6 +38,11 @@ IRNode::IRNode(int offset, int kind, const FloatLiteralData& data)
, fKind(kind)
, fData(data) {}
IRNode::IRNode(int offset, int kind, const String& data)
: fOffset(offset)
, fKind(kind)
, fData(data) {}
IRNode::IRNode(int offset, int kind, const Type* data)
: fOffset(offset)
, fKind(kind)

View File

@ -107,6 +107,7 @@ protected:
kEnum,
kFloatLiteral,
kIntLiteral,
kString,
kType,
kTypeToken,
} fKind = Kind::kType;
@ -118,6 +119,7 @@ protected:
EnumData fEnum;
FloatLiteralData fFloatLiteral;
IntLiteralData fIntLiteral;
String fString;
const Type* fType;
TypeTokenData fTypeToken;
@ -151,6 +153,11 @@ protected:
*(new(&fContents) IntLiteralData) = data;
}
NodeData(const String& data)
: fKind(Kind::kString) {
*(new(&fContents) String) = data;
}
NodeData(const Type* data)
: fKind(Kind::kType) {
*(new(&fContents) const Type*) = data;
@ -184,6 +191,9 @@ protected:
case Kind::kIntLiteral:
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
break;
case Kind::kString:
*(new(&fContents) String) = other.fContents.fString;
break;
case Kind::kType:
*(new(&fContents) const Type*) = other.fContents.fType;
break;
@ -216,6 +226,9 @@ protected:
case Kind::kIntLiteral:
fContents.fIntLiteral.~IntLiteralData();
break;
case Kind::kString:
fContents.fString.~String();
break;
case Kind::kType:
break;
case Kind::kTypeToken:
@ -236,6 +249,8 @@ protected:
IRNode(int offset, int kind, const FloatLiteralData& data);
IRNode(int offset, int kind, const String& data);
IRNode(int offset, int kind, const Type* data = nullptr);
IRNode(int offset, int kind, const TypeTokenData& data);
@ -311,6 +326,11 @@ protected:
return fData.fContents.fIntLiteral;
}
const String& stringData() const {
SkASSERT(fData.fKind == NodeData::Kind::kString);
return fData.fContents.fString;
}
const Type* typeData() const {
SkASSERT(fData.fKind == NodeData::Kind::kType);
return fData.fContents.fType;

View File

@ -39,6 +39,11 @@ struct ProgramElement : public IRNode {
ProgramElement(int offset, const EnumData& enumData)
: INHERITED(offset, (int) Kind::kEnum, enumData) {}
ProgramElement(int offset, Kind kind, const String& data)
: INHERITED(offset, (int) kind, data) {
SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);
}
Kind kind() const {
return (Kind) fKind;
}