moved SkSL Section data into IRNode
Change-Id: I255eb58fc4e6e3b08dfd8e962ee8fe22144d4c36 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325859 Reviewed-by: John Stiles <johnstiles@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
parent
fa88911640
commit
48b6df4bc0
@ -648,7 +648,7 @@ void CPPCodeGenerator::writeSetting(const Setting& s) {
|
||||
bool CPPCodeGenerator::writeSection(const char* name, const char* prefix) {
|
||||
const Section* s = fSectionAndParameterHelper.getSection(name);
|
||||
if (s) {
|
||||
this->writef("%s%s", prefix, s->fText.c_str());
|
||||
this->writef("%s%s", prefix, s->text().c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -994,7 +994,7 @@ bool CPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) {
|
||||
void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
|
||||
const char* fullName = fFullName.c_str();
|
||||
const Section* section = fSectionAndParameterHelper.getSection(kSetDataSection);
|
||||
const char* pdman = section ? section->fArgument.c_str() : "pdman";
|
||||
const char* pdman = section ? section->argument().c_str() : "pdman";
|
||||
this->writef(" void onSetData(const GrGLSLProgramDataManager& %s, "
|
||||
"const GrFragmentProcessor& _proc) override {\n",
|
||||
pdman);
|
||||
@ -1231,7 +1231,7 @@ void CPPCodeGenerator::writeTest() {
|
||||
"std::unique_ptr<GrFragmentProcessor> %s::TestCreate(GrProcessorTestData* %s) {\n",
|
||||
fFullName.c_str(),
|
||||
fFullName.c_str(),
|
||||
test->fArgument.c_str());
|
||||
test->argument().c_str());
|
||||
this->writeSection(kTestCodeSection);
|
||||
this->write("}\n"
|
||||
"#endif\n");
|
||||
|
@ -134,7 +134,7 @@ void HCodeGenerator::writef(const char* s, ...) {
|
||||
bool HCodeGenerator::writeSection(const char* name, const char* prefix) {
|
||||
const Section* s = fSectionAndParameterHelper.getSection(name);
|
||||
if (s) {
|
||||
this->writef("%s%s", prefix, s->fText.c_str());
|
||||
this->writef("%s%s", prefix, s->text().c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -146,7 +146,7 @@ void HCodeGenerator::writeExtraConstructorParams(const char* separator) {
|
||||
// this with something more robust if the need arises.
|
||||
const Section* section = fSectionAndParameterHelper.getSection(kConstructorParamsSection);
|
||||
if (section) {
|
||||
const char* s = section->fText.c_str();
|
||||
const char* s = section->text().c_str();
|
||||
#define BUFFER_SIZE 64
|
||||
char lastIdentifier[BUFFER_SIZE];
|
||||
int lastIdentifierLength = 0;
|
||||
@ -254,8 +254,8 @@ void HCodeGenerator::writeConstructor() {
|
||||
this->writef("\n , %s(std::move(%s)", FieldName(name).c_str(), name);
|
||||
for (const Section* s : fSectionAndParameterHelper.getSections(
|
||||
kSamplerParamsSection)) {
|
||||
if (s->fArgument == name) {
|
||||
this->writef(", %s", s->fText.c_str());
|
||||
if (s->argument() == name) {
|
||||
this->writef(", %s", s->text().c_str());
|
||||
}
|
||||
}
|
||||
this->writef(")");
|
||||
|
@ -38,26 +38,28 @@ SectionAndParameterHelper::SectionAndParameterHelper(const Program* program, Err
|
||||
}
|
||||
case ProgramElement::Kind::kSection: {
|
||||
const Section& s = p->as<Section>();
|
||||
if (IsSupportedSection(s.fName.c_str())) {
|
||||
if (SectionRequiresArgument(s.fName.c_str()) && !s.fArgument.size()) {
|
||||
const String& name = s.name();
|
||||
const String& arg = s.argument();
|
||||
if (IsSupportedSection(name.c_str())) {
|
||||
if (SectionRequiresArgument(name.c_str()) && !arg.size()) {
|
||||
errors.error(s.fOffset,
|
||||
("section '@" + s.fName +
|
||||
("section '@" + name +
|
||||
"' requires one parameter").c_str());
|
||||
}
|
||||
if (!SectionAcceptsArgument(s.fName.c_str()) && s.fArgument.size()) {
|
||||
if (!SectionAcceptsArgument(name.c_str()) && arg.size()) {
|
||||
errors.error(s.fOffset,
|
||||
("section '@" + s.fName + "' has no parameters").c_str());
|
||||
("section '@" + name + "' has no parameters").c_str());
|
||||
}
|
||||
} else {
|
||||
errors.error(s.fOffset,
|
||||
("unsupported section '@" + s.fName + "'").c_str());
|
||||
("unsupported section '@" + name + "'").c_str());
|
||||
}
|
||||
if (!SectionPermitsDuplicates(s.fName.c_str()) &&
|
||||
fSections.find(s.fName) != fSections.end()) {
|
||||
if (!SectionPermitsDuplicates(name.c_str()) &&
|
||||
fSections.find(name) != fSections.end()) {
|
||||
errors.error(s.fOffset,
|
||||
("duplicate section '@" + s.fName + "'").c_str());
|
||||
("duplicate section '@" + name + "'").c_str());
|
||||
}
|
||||
fSections[s.fName].push_back(&s);
|
||||
fSections[name].push_back(&s);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -83,6 +83,11 @@ IRNode::IRNode(int offset, int kind, const IntLiteralData& data)
|
||||
, fKind(kind)
|
||||
, fData(data) {}
|
||||
|
||||
IRNode::IRNode(int offset, int kind, const SectionData& data)
|
||||
: fOffset(offset)
|
||||
, fKind(kind)
|
||||
, fData(data) {}
|
||||
|
||||
IRNode::IRNode(int offset, int kind, const SettingData& data)
|
||||
: fOffset(offset)
|
||||
, fKind(kind)
|
||||
|
@ -152,6 +152,12 @@ protected:
|
||||
const FunctionDeclaration* fFunction;
|
||||
};
|
||||
|
||||
struct SectionData {
|
||||
String fName;
|
||||
String fArgument;
|
||||
String fText;
|
||||
};
|
||||
|
||||
struct SettingData {
|
||||
String fName;
|
||||
const Type* fType;
|
||||
@ -224,6 +230,7 @@ protected:
|
||||
kIfStatement,
|
||||
kInlineMarker,
|
||||
kIntLiteral,
|
||||
kSection,
|
||||
kSetting,
|
||||
kString,
|
||||
kSwizzle,
|
||||
@ -253,6 +260,7 @@ protected:
|
||||
IfStatementData fIfStatement;
|
||||
InlineMarkerData fInlineMarker;
|
||||
IntLiteralData fIntLiteral;
|
||||
SectionData fSection;
|
||||
SettingData fSetting;
|
||||
String fString;
|
||||
SwizzleData fSwizzle;
|
||||
@ -340,6 +348,11 @@ protected:
|
||||
*(new(&fContents) IntLiteralData) = data;
|
||||
}
|
||||
|
||||
NodeData(const SectionData& data)
|
||||
: fKind(Kind::kSection) {
|
||||
*(new(&fContents) SectionData) = data;
|
||||
}
|
||||
|
||||
NodeData(const SettingData& data)
|
||||
: fKind(Kind::kSetting) {
|
||||
*(new(&fContents) SettingData) = data;
|
||||
@ -446,6 +459,9 @@ protected:
|
||||
case Kind::kIntLiteral:
|
||||
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
|
||||
break;
|
||||
case Kind::kSection:
|
||||
*(new(&fContents) SectionData) = other.fContents.fSection;
|
||||
break;
|
||||
case Kind::kSetting:
|
||||
*(new(&fContents) SettingData) = other.fContents.fSetting;
|
||||
break;
|
||||
@ -532,6 +548,9 @@ protected:
|
||||
case Kind::kIntLiteral:
|
||||
fContents.fIntLiteral.~IntLiteralData();
|
||||
break;
|
||||
case Kind::kSection:
|
||||
fContents.fSection.~SectionData();
|
||||
break;
|
||||
case Kind::kSetting:
|
||||
fContents.fSetting.~SettingData();
|
||||
break;
|
||||
@ -597,6 +616,8 @@ protected:
|
||||
|
||||
IRNode(int offset, int kind, const IntLiteralData& data);
|
||||
|
||||
IRNode(int offset, int kind, const SectionData& data);
|
||||
|
||||
IRNode(int offset, int kind, const SettingData& data);
|
||||
|
||||
IRNode(int offset, int kind, const String& data);
|
||||
@ -738,6 +759,11 @@ protected:
|
||||
return fData.fContents.fIntLiteral;
|
||||
}
|
||||
|
||||
const SectionData& sectionData() const {
|
||||
SkASSERT(fData.fKind == NodeData::Kind::kSection);
|
||||
return fData.fContents.fSection;
|
||||
}
|
||||
|
||||
const SettingData& settingData() const {
|
||||
SkASSERT(fData.fKind == NodeData::Kind::kSetting);
|
||||
return fData.fContents.fSetting;
|
||||
|
@ -45,6 +45,9 @@ public:
|
||||
SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);
|
||||
}
|
||||
|
||||
ProgramElement(int offset, const SectionData& sectionData)
|
||||
: INHERITED(offset, (int) Kind::kSection, sectionData) {}
|
||||
|
||||
Kind kind() const {
|
||||
return (Kind) fKind;
|
||||
}
|
||||
|
@ -19,28 +19,34 @@ struct Section : public ProgramElement {
|
||||
static constexpr Kind kProgramElementKind = Kind::kSection;
|
||||
|
||||
Section(int offset, String name, String arg, String text)
|
||||
: INHERITED(offset, kProgramElementKind)
|
||||
, fName(std::move(name))
|
||||
, fArgument(std::move(arg))
|
||||
, fText(std::move(text)) {}
|
||||
: INHERITED(offset, SectionData{std::move(name), std::move(arg), std::move(text)}) {}
|
||||
|
||||
const String& name() const {
|
||||
return this->sectionData().fName;
|
||||
}
|
||||
|
||||
const String& argument() const {
|
||||
return this->sectionData().fArgument;
|
||||
}
|
||||
|
||||
const String& text() const {
|
||||
return this->sectionData().fText;
|
||||
}
|
||||
|
||||
std::unique_ptr<ProgramElement> clone() const override {
|
||||
return std::unique_ptr<ProgramElement>(new Section(fOffset, fName, fArgument, fText));
|
||||
return std::unique_ptr<ProgramElement>(new Section(fOffset, this->name(), this->argument(),
|
||||
this->text()));
|
||||
}
|
||||
|
||||
String description() const override {
|
||||
String result = "@" + fName;
|
||||
if (fArgument.size()) {
|
||||
result += "(" + fArgument + ")";
|
||||
String result = "@" + this->name();
|
||||
if (this->argument().size()) {
|
||||
result += "(" + this->argument() + ")";
|
||||
}
|
||||
result += " { " + fText + " }";
|
||||
result += " { " + this->text() + " }";
|
||||
return result;
|
||||
}
|
||||
|
||||
const String fName;
|
||||
const String fArgument;
|
||||
const String fText;
|
||||
|
||||
using INHERITED = ProgramElement;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user