Change interface block's fVariable from ref to pointer
The next pre-include refactor will require cloning InterfaceBlocks, and re-targeting the variable. Change-Id: Iccfc1f39789fcd572199682386cd612500334061 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323890 Commit-Queue: Brian Osman <brianosman@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
dd21816b00
commit
6a204db32c
@ -545,7 +545,7 @@ void Dehydrator::write(const ProgramElement& e) {
|
||||
case ProgramElement::Kind::kInterfaceBlock: {
|
||||
const InterfaceBlock& i = e.as<InterfaceBlock>();
|
||||
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());
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<InterfaceBlock>();
|
||||
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<Expression> IRGenerator::convertIdentifier(const ASTNode& identi
|
||||
}
|
||||
case Symbol::Kind::kField: {
|
||||
const Field* field = &result->as<Field>();
|
||||
VariableReference* base = new VariableReference(identifier.fOffset, &field->owner(),
|
||||
auto base = std::make_unique<VariableReference>(identifier.fOffset, &field->owner(),
|
||||
VariableReference::kRead_RefKind);
|
||||
return std::unique_ptr<Expression>(new FieldAccess(
|
||||
std::unique_ptr<Expression>(base),
|
||||
field->fieldIndex(),
|
||||
FieldAccess::kAnonymousInterfaceBlock_OwnerKind));
|
||||
return std::make_unique<FieldAccess>(std::move(base),
|
||||
field->fieldIndex(),
|
||||
FieldAccess::kAnonymousInterfaceBlock_OwnerKind);
|
||||
}
|
||||
case Symbol::Kind::kType: {
|
||||
const Type* t = &result->as<Type>();
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ struct InterfaceBlock : public ProgramElement {
|
||||
std::vector<std::unique_ptr<Expression>> sizes,
|
||||
std::shared_ptr<SymbolTable> 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<ProgramElement> clone() const override {
|
||||
std::vector<std::unique_ptr<Expression>> sizesClone;
|
||||
sizesClone.reserve(fSizes.size());
|
||||
for (const auto& s : fSizes) {
|
||||
sizesClone.push_back(s ? s->clone() : nullptr);
|
||||
}
|
||||
return std::unique_ptr<ProgramElement>(new InterfaceBlock(fOffset, &fVariable, fTypeName,
|
||||
return std::unique_ptr<ProgramElement>(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<std::unique_ptr<Expression>> fSizes;
|
||||
|
Loading…
Reference in New Issue
Block a user