diff --git a/src/sksl/SkSLDehydrator.cpp b/src/sksl/SkSLDehydrator.cpp index 2b81eaae3a..22071cc2e0 100644 --- a/src/sksl/SkSLDehydrator.cpp +++ b/src/sksl/SkSLDehydrator.cpp @@ -545,7 +545,7 @@ void Dehydrator::write(const ProgramElement& e) { case ProgramElement::Kind::kInterfaceBlock: { const InterfaceBlock& i = e.as(); this->writeU8(Rehydrator::kInterfaceBlock_Command); - this->write(i.fVariable); + this->write(*i.fVariable); this->write(i.fTypeName); this->write(i.fInstanceName); this->writeU8(i.fSizes.size()); diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp index 8eef94241e..e3a5089503 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.cpp +++ b/src/sksl/SkSLGLSLCodeGenerator.cpp @@ -1177,10 +1177,10 @@ void GLSLCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) { if (intf.fTypeName == "sk_PerVertex") { return; } - this->writeModifiers(intf.fVariable.modifiers(), true); + this->writeModifiers(intf.fVariable->modifiers(), true); this->writeLine(intf.fTypeName + " {"); fIndentation++; - const Type* structType = &intf.fVariable.type(); + const Type* structType = &intf.fVariable->type(); while (structType->typeKind() == Type::TypeKind::kArray) { structType = &structType->componentType(); } diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 78472dcbf4..b5599e4169 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -186,9 +186,9 @@ void IRGenerator::start(const Program::Settings* settings, for (const auto& e : *inherited) { if (e->kind() == ProgramElement::Kind::kInterfaceBlock) { InterfaceBlock& intf = e->as(); - if (intf.fVariable.name() == Compiler::PERVERTEX_NAME) { + if (intf.fVariable->name() == Compiler::PERVERTEX_NAME) { SkASSERT(!fSkPerVertex); - fSkPerVertex = &intf.fVariable; + fSkPerVertex = intf.fVariable; } } } @@ -1433,12 +1433,11 @@ std::unique_ptr IRGenerator::convertIdentifier(const ASTNode& identi } case Symbol::Kind::kField: { const Field* field = &result->as(); - VariableReference* base = new VariableReference(identifier.fOffset, &field->owner(), + auto base = std::make_unique(identifier.fOffset, &field->owner(), VariableReference::kRead_RefKind); - return std::unique_ptr(new FieldAccess( - std::unique_ptr(base), - field->fieldIndex(), - FieldAccess::kAnonymousInterfaceBlock_OwnerKind)); + return std::make_unique(std::move(base), + field->fieldIndex(), + FieldAccess::kAnonymousInterfaceBlock_OwnerKind); } case Symbol::Kind::kType: { const Type* t = &result->as(); diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp index 980d499b87..86a4bc2b59 100644 --- a/src/sksl/SkSLMetalCodeGenerator.cpp +++ b/src/sksl/SkSLMetalCodeGenerator.cpp @@ -983,11 +983,11 @@ void MetalCodeGenerator::writeFunction(const FunctionDefinition& f) { continue; } this->write(", constant "); - this->writeType(intf.fVariable.type()); + this->writeType(intf.fVariable->type()); this->write("& " ); this->write(fInterfaceBlockNameMap[&intf]); this->write(" [[buffer("); - this->write(to_string(intf.fVariable.modifiers().fLayout.fBinding)); + this->write(to_string(intf.fVariable->modifiers().fLayout.fBinding)); this->write(")]]"); } } @@ -1113,10 +1113,10 @@ void MetalCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) { if ("sk_PerVertex" == intf.fTypeName) { return; } - this->writeModifiers(intf.fVariable.modifiers(), true); + this->writeModifiers(intf.fVariable->modifiers(), true); this->write("struct "); this->writeLine(intf.fTypeName + " {"); - const Type* structType = &intf.fVariable.type(); + const Type* structType = &intf.fVariable->type(); fWrittenStructs.push_back(structType); while (structType->typeKind() == Type::TypeKind::kArray) { structType = &structType->componentType(); diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index 63a354338a..32d110820c 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -2693,14 +2693,14 @@ static void update_sk_in_count(const Modifiers& m, int* outSkInCount) { } SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool appendRTHeight) { - bool isBuffer = (0 != (intf.fVariable.modifiers().fFlags & Modifiers::kBuffer_Flag)); - bool pushConstant = (0 != (intf.fVariable.modifiers().fLayout.fFlags & + bool isBuffer = (0 != (intf.fVariable->modifiers().fFlags & Modifiers::kBuffer_Flag)); + bool pushConstant = (0 != (intf.fVariable->modifiers().fLayout.fFlags & Layout::kPushConstant_Flag)); MemoryLayout memoryLayout = (pushConstant || isBuffer) ? MemoryLayout(MemoryLayout::k430_Standard) : fDefaultLayout; SpvId result = this->nextId(); - const Type* type = &intf.fVariable.type(); + const Type* type = &intf.fVariable->type(); if (fProgram.fInputs.fRTHeight && appendRTHeight) { SkASSERT(fRTHeightStructId == (SpvId) -1); SkASSERT(fRTHeightFieldIndex == (SpvId) -1); @@ -2711,7 +2711,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a type = new Type(type->fOffset, type->name(), fields); } SpvId typeId; - Modifiers intfModifiers = intf.fVariable.modifiers(); + Modifiers intfModifiers = intf.fVariable->modifiers(); if (intfModifiers.fLayout.fBuiltin == SK_IN_BUILTIN) { for (const auto& e : fProgram) { if (e.kind() == ProgramElement::Kind::kModifiers) { @@ -2720,7 +2720,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a } } typeId = this->getType(Type("sk_in", Type::TypeKind::kArray, - intf.fVariable.type().componentType(), + intf.fVariable->type().componentType(), fSkInCount), memoryLayout); } else { @@ -2740,7 +2740,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a layout.fSet = 0; } this->writeLayout(layout, result); - fVariableMap[&intf.fVariable] = result; + fVariableMap[intf.fVariable] = result; if (fProgram.fInputs.fRTHeight && appendRTHeight) { delete type; } @@ -3194,7 +3194,7 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream& for (const auto& e : program) { if (e.kind() == ProgramElement::Kind::kInterfaceBlock) { InterfaceBlock& intf = (InterfaceBlock&) e; - const Modifiers& modifiers = intf.fVariable.modifiers(); + const Modifiers& modifiers = intf.fVariable->modifiers(); if (SK_IN_BUILTIN == modifiers.fLayout.fBuiltin) { SkASSERT(skInSize != -1); intf.fSizes.emplace_back(new IntLiteral(fContext, -1, skInSize)); @@ -3203,7 +3203,7 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream& if (((modifiers.fFlags & Modifiers::kIn_Flag) || (modifiers.fFlags & Modifiers::kOut_Flag)) && modifiers.fLayout.fBuiltin == -1 && - !is_dead(intf.fVariable)) { + !is_dead(*intf.fVariable)) { interfaceVars.insert(id); } } diff --git a/src/sksl/ir/SkSLInterfaceBlock.h b/src/sksl/ir/SkSLInterfaceBlock.h index cee0a22d61..532a9afdab 100644 --- a/src/sksl/ir/SkSLInterfaceBlock.h +++ b/src/sksl/ir/SkSLInterfaceBlock.h @@ -31,7 +31,7 @@ struct InterfaceBlock : public ProgramElement { std::vector> sizes, std::shared_ptr typeOwner) : INHERITED(offset, kProgramElementKind) - , fVariable(*var) + , fVariable(var) , fTypeName(std::move(typeName)) , fInstanceName(std::move(instanceName)) , fSizes(std::move(sizes)) @@ -39,18 +39,19 @@ struct InterfaceBlock : public ProgramElement { std::unique_ptr clone() const override { std::vector> sizesClone; + sizesClone.reserve(fSizes.size()); for (const auto& s : fSizes) { sizesClone.push_back(s ? s->clone() : nullptr); } - return std::unique_ptr(new InterfaceBlock(fOffset, &fVariable, fTypeName, + return std::unique_ptr(new InterfaceBlock(fOffset, fVariable, fTypeName, fInstanceName, std::move(sizesClone), fTypeOwner)); } String description() const override { - String result = fVariable.modifiers().description() + fTypeName + " {\n"; - const Type* structType = &fVariable.type(); + String result = fVariable->modifiers().description() + fTypeName + " {\n"; + const Type* structType = &fVariable->type(); while (structType->typeKind() == Type::TypeKind::kArray) { structType = &structType->componentType(); } @@ -71,7 +72,7 @@ struct InterfaceBlock : public ProgramElement { return result + ";"; } - const Variable& fVariable; + const Variable* fVariable; const String fTypeName; const String fInstanceName; std::vector> fSizes;