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:
parent
4c1fcdb4e8
commit
efb09e2caf
@ -1495,7 +1495,7 @@ void GLSLCodeGenerator::writeHeader() {
|
|||||||
void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) {
|
void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) {
|
||||||
switch (e.kind()) {
|
switch (e.kind()) {
|
||||||
case ProgramElement::Kind::kExtension:
|
case ProgramElement::Kind::kExtension:
|
||||||
this->writeExtension(e.as<Extension>().fName);
|
this->writeExtension(e.as<Extension>().name());
|
||||||
break;
|
break;
|
||||||
case ProgramElement::Kind::kVar: {
|
case ProgramElement::Kind::kVar: {
|
||||||
const VarDeclarations& decl = e.as<VarDeclarations>();
|
const VarDeclarations& decl = e.as<VarDeclarations>();
|
||||||
|
@ -73,7 +73,7 @@ void MetalCodeGenerator::writeLine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MetalCodeGenerator::writeExtension(const Extension& ext) {
|
void MetalCodeGenerator::writeExtension(const Extension& ext) {
|
||||||
this->writeLine("#extension " + ext.fName + " : enable");
|
this->writeLine("#extension " + ext.name() + " : enable");
|
||||||
}
|
}
|
||||||
|
|
||||||
String MetalCodeGenerator::typeName(const Type& type) {
|
String MetalCodeGenerator::typeName(const Type& type) {
|
||||||
|
@ -3272,7 +3272,7 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream&
|
|||||||
}
|
}
|
||||||
for (const auto& e : program) {
|
for (const auto& e : program) {
|
||||||
if (e.kind() == ProgramElement::Kind::kExtension) {
|
if (e.kind() == ProgramElement::Kind::kExtension) {
|
||||||
this->writeInstruction(SpvOpSourceExtension, ((Extension&) e).fName.c_str(), out);
|
this->writeInstruction(SpvOpSourceExtension, ((Extension&) e).name().c_str(), out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,19 +19,20 @@ struct Extension : public ProgramElement {
|
|||||||
static constexpr Kind kProgramElementKind = Kind::kExtension;
|
static constexpr Kind kProgramElementKind = Kind::kExtension;
|
||||||
|
|
||||||
Extension(int offset, String name)
|
Extension(int offset, String name)
|
||||||
: INHERITED(offset, kProgramElementKind)
|
: INHERITED(offset, kProgramElementKind, name) {}
|
||||||
, fName(std::move(name)) {}
|
|
||||||
|
const String& name() const {
|
||||||
|
return this->stringData();
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<ProgramElement> clone() const override {
|
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 {
|
String description() const override {
|
||||||
return "#extension " + fName + " : enable";
|
return "#extension " + this->name() + " : enable";
|
||||||
}
|
}
|
||||||
|
|
||||||
const String fName;
|
|
||||||
|
|
||||||
using INHERITED = ProgramElement;
|
using INHERITED = ProgramElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,6 +38,11 @@ IRNode::IRNode(int offset, int kind, const FloatLiteralData& data)
|
|||||||
, fKind(kind)
|
, fKind(kind)
|
||||||
, fData(data) {}
|
, 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)
|
IRNode::IRNode(int offset, int kind, const Type* data)
|
||||||
: fOffset(offset)
|
: fOffset(offset)
|
||||||
, fKind(kind)
|
, fKind(kind)
|
||||||
|
@ -107,6 +107,7 @@ protected:
|
|||||||
kEnum,
|
kEnum,
|
||||||
kFloatLiteral,
|
kFloatLiteral,
|
||||||
kIntLiteral,
|
kIntLiteral,
|
||||||
|
kString,
|
||||||
kType,
|
kType,
|
||||||
kTypeToken,
|
kTypeToken,
|
||||||
} fKind = Kind::kType;
|
} fKind = Kind::kType;
|
||||||
@ -118,6 +119,7 @@ protected:
|
|||||||
EnumData fEnum;
|
EnumData fEnum;
|
||||||
FloatLiteralData fFloatLiteral;
|
FloatLiteralData fFloatLiteral;
|
||||||
IntLiteralData fIntLiteral;
|
IntLiteralData fIntLiteral;
|
||||||
|
String fString;
|
||||||
const Type* fType;
|
const Type* fType;
|
||||||
TypeTokenData fTypeToken;
|
TypeTokenData fTypeToken;
|
||||||
|
|
||||||
@ -151,6 +153,11 @@ protected:
|
|||||||
*(new(&fContents) IntLiteralData) = data;
|
*(new(&fContents) IntLiteralData) = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeData(const String& data)
|
||||||
|
: fKind(Kind::kString) {
|
||||||
|
*(new(&fContents) String) = data;
|
||||||
|
}
|
||||||
|
|
||||||
NodeData(const Type* data)
|
NodeData(const Type* data)
|
||||||
: fKind(Kind::kType) {
|
: fKind(Kind::kType) {
|
||||||
*(new(&fContents) const Type*) = data;
|
*(new(&fContents) const Type*) = data;
|
||||||
@ -184,6 +191,9 @@ protected:
|
|||||||
case Kind::kIntLiteral:
|
case Kind::kIntLiteral:
|
||||||
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
|
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
|
||||||
break;
|
break;
|
||||||
|
case Kind::kString:
|
||||||
|
*(new(&fContents) String) = other.fContents.fString;
|
||||||
|
break;
|
||||||
case Kind::kType:
|
case Kind::kType:
|
||||||
*(new(&fContents) const Type*) = other.fContents.fType;
|
*(new(&fContents) const Type*) = other.fContents.fType;
|
||||||
break;
|
break;
|
||||||
@ -216,6 +226,9 @@ protected:
|
|||||||
case Kind::kIntLiteral:
|
case Kind::kIntLiteral:
|
||||||
fContents.fIntLiteral.~IntLiteralData();
|
fContents.fIntLiteral.~IntLiteralData();
|
||||||
break;
|
break;
|
||||||
|
case Kind::kString:
|
||||||
|
fContents.fString.~String();
|
||||||
|
break;
|
||||||
case Kind::kType:
|
case Kind::kType:
|
||||||
break;
|
break;
|
||||||
case Kind::kTypeToken:
|
case Kind::kTypeToken:
|
||||||
@ -236,6 +249,8 @@ protected:
|
|||||||
|
|
||||||
IRNode(int offset, int kind, const FloatLiteralData& data);
|
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 Type* data = nullptr);
|
||||||
|
|
||||||
IRNode(int offset, int kind, const TypeTokenData& data);
|
IRNode(int offset, int kind, const TypeTokenData& data);
|
||||||
@ -311,6 +326,11 @@ protected:
|
|||||||
return fData.fContents.fIntLiteral;
|
return fData.fContents.fIntLiteral;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const String& stringData() const {
|
||||||
|
SkASSERT(fData.fKind == NodeData::Kind::kString);
|
||||||
|
return fData.fContents.fString;
|
||||||
|
}
|
||||||
|
|
||||||
const Type* typeData() const {
|
const Type* typeData() const {
|
||||||
SkASSERT(fData.fKind == NodeData::Kind::kType);
|
SkASSERT(fData.fKind == NodeData::Kind::kType);
|
||||||
return fData.fContents.fType;
|
return fData.fContents.fType;
|
||||||
|
@ -39,6 +39,11 @@ struct ProgramElement : public IRNode {
|
|||||||
ProgramElement(int offset, const EnumData& enumData)
|
ProgramElement(int offset, const EnumData& enumData)
|
||||||
: INHERITED(offset, (int) Kind::kEnum, 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 {
|
Kind kind() const {
|
||||||
return (Kind) fKind;
|
return (Kind) fKind;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user