moved SkSL ModifiersDeclaration data into IRNode

Change-Id: Iebe59b32a965e383d2b032258d7731645e0bd1a4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325622
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
Ethan Nicholas 2020-10-13 10:30:20 -04:00 committed by Skia Commit-Bot
parent 4c412bce4c
commit 077050b019
8 changed files with 51 additions and 13 deletions

View File

@ -1515,7 +1515,7 @@ void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) {
this->writeFunction(e.as<FunctionDefinition>());
break;
case ProgramElement::Kind::kModifiers: {
const Modifiers& modifiers = e.as<ModifiersDeclaration>().fModifiers;
const Modifiers& modifiers = e.as<ModifiersDeclaration>().modifiers();
if (!fFoundGSInvocations && modifiers.fLayout.fInvocations >= 0) {
if (fProgram.fSettings.fCaps->gsInvocationsExtensionString()) {
this->writeExtension(fProgram.fSettings.fCaps->gsInvocationsExtensionString());

View File

@ -469,7 +469,7 @@ std::unique_ptr<ModifiersDeclaration> IRGenerator::convertModifiersDeclaration(c
!fSettings->fCaps->gsInvocationsSupport()) {
modifiers.fLayout.fMaxVertices *= fInvocations;
}
return std::make_unique<ModifiersDeclaration>(modifiers);
return std::make_unique<ModifiersDeclaration>(fModifiers->handle(modifiers));
}
std::unique_ptr<Statement> IRGenerator::convertIf(const ASTNode& n) {

View File

@ -1658,7 +1658,7 @@ void MetalCodeGenerator::writeProgramElement(const ProgramElement& e) {
this->writeFunction(e.as<FunctionDefinition>());
break;
case ProgramElement::Kind::kModifiers:
this->writeModifiers(e.as<ModifiersDeclaration>().fModifiers, true);
this->writeModifiers(e.as<ModifiersDeclaration>().modifiers(), true);
this->writeLine(";");
break;
default:

View File

@ -2717,7 +2717,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a
if (intfModifiers.fLayout.fBuiltin == SK_IN_BUILTIN) {
for (const auto& e : fProgram.elements()) {
if (e->is<ModifiersDeclaration>()) {
const Modifiers& m = e->as<ModifiersDeclaration>().fModifiers;
const Modifiers& m = e->as<ModifiersDeclaration>().modifiers();
update_sk_in_count(m, &fSkInCount);
}
}
@ -3094,7 +3094,7 @@ void SPIRVCodeGenerator::writeGeometryShaderExecutionMode(SpvId entryPoint, Outp
int invocations = 1;
for (const auto& e : fProgram.elements()) {
if (e->is<ModifiersDeclaration>()) {
const Modifiers& m = e->as<ModifiersDeclaration>().fModifiers;
const Modifiers& m = e->as<ModifiersDeclaration>().modifiers();
if (m.fFlags & Modifiers::kIn_Flag) {
if (m.fLayout.fInvocations != -1) {
invocations = m.fLayout.fInvocations;
@ -3169,7 +3169,7 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream&
break;
}
case ProgramElement::Kind::kModifiers: {
Modifiers& m = e->as<ModifiersDeclaration>().fModifiers;
const Modifiers& m = e->as<ModifiersDeclaration>().modifiers();
if (m.fFlags & Modifiers::kIn_Flag) {
switch (m.fLayout.fPrimitive) {
case Layout::kPoints_Primitive: // break

View File

@ -83,6 +83,11 @@ IRNode::IRNode(int offset, int kind, const IntLiteralData& data)
, fKind(kind)
, fData(data) {}
IRNode::IRNode(int offset, int kind, const ModifiersDeclarationData& data)
: fOffset(offset)
, fKind(kind)
, fData(data) {}
IRNode::IRNode(int offset, int kind, const SectionData& data)
: fOffset(offset)
, fKind(kind)

View File

@ -152,6 +152,10 @@ protected:
const FunctionDeclaration* fFunction;
};
struct ModifiersDeclarationData {
ModifiersPool::Handle fModifiersHandle;
};
struct SectionData {
String fName;
String fArgument;
@ -230,6 +234,7 @@ protected:
kIfStatement,
kInlineMarker,
kIntLiteral,
kModifiersDeclaration,
kSection,
kSetting,
kString,
@ -260,6 +265,7 @@ protected:
IfStatementData fIfStatement;
InlineMarkerData fInlineMarker;
IntLiteralData fIntLiteral;
ModifiersDeclarationData fModifiersDeclaration;
SectionData fSection;
SettingData fSetting;
String fString;
@ -348,6 +354,11 @@ protected:
*(new(&fContents) IntLiteralData) = data;
}
NodeData(ModifiersDeclarationData data)
: fKind(Kind::kModifiersDeclaration) {
*(new(&fContents) ModifiersDeclarationData) = data;
}
NodeData(const SectionData& data)
: fKind(Kind::kSection) {
*(new(&fContents) SectionData) = data;
@ -459,6 +470,10 @@ protected:
case Kind::kIntLiteral:
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
break;
case Kind::kModifiersDeclaration:
*(new(&fContents) ModifiersDeclarationData) =
other.fContents.fModifiersDeclaration;
break;
case Kind::kSection:
*(new(&fContents) SectionData) = other.fContents.fSection;
break;
@ -548,6 +563,9 @@ protected:
case Kind::kIntLiteral:
fContents.fIntLiteral.~IntLiteralData();
break;
case Kind::kModifiersDeclaration:
fContents.fModifiersDeclaration.~ModifiersDeclarationData();
break;
case Kind::kSection:
fContents.fSection.~SectionData();
break;
@ -616,6 +634,8 @@ protected:
IRNode(int offset, int kind, const IntLiteralData& data);
IRNode(int offset, int kind, const ModifiersDeclarationData& data);
IRNode(int offset, int kind, const SectionData& data);
IRNode(int offset, int kind, const SettingData& data);
@ -759,6 +779,11 @@ protected:
return fData.fContents.fIntLiteral;
}
const ModifiersDeclarationData& modifiersDeclarationData() const {
SkASSERT(fData.fKind == NodeData::Kind::kModifiersDeclaration);
return fData.fContents.fModifiersDeclaration;
}
const SectionData& sectionData() const {
SkASSERT(fData.fKind == NodeData::Kind::kSection);
return fData.fContents.fSection;

View File

@ -21,20 +21,25 @@ namespace SkSL {
struct ModifiersDeclaration : public ProgramElement {
static constexpr Kind kProgramElementKind = Kind::kModifiers;
ModifiersDeclaration(Modifiers modifiers)
: INHERITED(-1, kProgramElementKind)
, fModifiers(modifiers) {}
ModifiersDeclaration(ModifiersPool::Handle modifiers)
: INHERITED(-1, ModifiersDeclarationData{modifiers}) {}
const Modifiers& modifiers() const {
return *this->modifiersDeclarationData().fModifiersHandle;
}
const ModifiersPool::Handle& modifiersHandle() const {
return this->modifiersDeclarationData().fModifiersHandle;
}
std::unique_ptr<ProgramElement> clone() const override {
return std::unique_ptr<ProgramElement>(new ModifiersDeclaration(fModifiers));
return std::unique_ptr<ProgramElement>(new ModifiersDeclaration(this->modifiersHandle()));
}
String description() const override {
return fModifiers.description() + ";";
return this->modifiers().description() + ";";
}
Modifiers fModifiers;
using INHERITED = ProgramElement;
};

View File

@ -40,6 +40,9 @@ public:
ProgramElement(int offset, const EnumData& enumData)
: INHERITED(offset, (int) Kind::kEnum, enumData) {}
ProgramElement(int offset, const ModifiersDeclarationData& enumData)
: INHERITED(offset, (int) Kind::kModifiers, enumData) {}
ProgramElement(int offset, Kind kind, const String& data)
: INHERITED(offset, (int) kind, data) {
SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);