Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d39aec0

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Simplify InterfaceBlock by removing multi-dimensional array support.
Maintaining an array of Expression-based sizes is not necessary as GLSL only supports a single dimension, and doesn't allow any expression other than a constant integer or nothing (meaning "unsized"). Change-Id: Id58404c5c8d48786e02585d2a6391b2f3e5393e8 Bug: skia:11026 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/340456 Reviewed-by: Brian Osman <[email protected]> Commit-Queue: John Stiles <[email protected]> Auto-Submit: John Stiles <[email protected]>
1 parent 2833ec6 commit d39aec0

9 files changed

+40
-76
lines changed

src/sksl/SkSLAnalysis.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ bool TProgramVisitor<PROG, EXPR, STMT, ELEM>::visitProgramElement(ELEM pe) {
629629
case ProgramElement::Kind::kEnum:
630630
case ProgramElement::Kind::kExtension:
631631
case ProgramElement::Kind::kFunctionPrototype:
632+
case ProgramElement::Kind::kInterfaceBlock:
632633
case ProgramElement::Kind::kModifiers:
633634
case ProgramElement::Kind::kSection:
634635
case ProgramElement::Kind::kStructDefinition:
@@ -638,14 +639,6 @@ bool TProgramVisitor<PROG, EXPR, STMT, ELEM>::visitProgramElement(ELEM pe) {
638639
case ProgramElement::Kind::kFunction:
639640
return this->visitStatement(*pe.template as<FunctionDefinition>().body());
640641

641-
case ProgramElement::Kind::kInterfaceBlock:
642-
for (auto& e : pe.template as<InterfaceBlock>().sizes()) {
643-
if (e && this->visitExpression(*e)) {
644-
return true;
645-
}
646-
}
647-
return false;
648-
649642
case ProgramElement::Kind::kGlobalVar:
650643
if (this->visitStatement(*pe.template as<GlobalVarDeclaration>().declaration())) {
651644
return true;

src/sksl/SkSLDehydrator.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,7 @@ void Dehydrator::write(const ProgramElement& e) {
553553
this->write(i.variable());
554554
this->write(i.typeName());
555555
this->write(i.instanceName());
556-
this->writeU8(i.sizes().count());
557-
for (const auto& s : i.sizes()) {
558-
this->write(s.get());
559-
}
556+
this->writeS8(i.arraySize());
560557
break;
561558
}
562559
case ProgramElement::Kind::kModifiers:

src/sksl/SkSLGLSLCodeGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,12 +1218,12 @@ void GLSLCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
12181218
if (intf.instanceName().size()) {
12191219
this->write(" ");
12201220
this->write(intf.instanceName());
1221-
for (const auto& size : intf.sizes()) {
1221+
if (intf.arraySize() > 0) {
12221222
this->write("[");
1223-
if (size) {
1224-
this->writeExpression(*size, kTopLevel_Precedence);
1225-
}
1223+
this->write(to_string(intf.arraySize()));
12261224
this->write("]");
1225+
} else if (intf.arraySize() == Type::kUnsizedArray){
1226+
this->write("[]");
12271227
}
12281228
}
12291229
this->writeLine(";");

src/sksl/SkSLIRGenerator.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,39 +1146,30 @@ std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTNode
11461146
}
11471147
}
11481148
}
1149-
const Type* type =
1150-
old->takeOwnershipOfSymbol(std::make_unique<Type>(intf.fOffset, id.fTypeName, fields));
1151-
ExpressionArray sizes;
1152-
sizes.reserve_back(id.fSizeCount);
1153-
for (size_t i = 0; i < id.fSizeCount; ++i) {
1149+
const Type* type = old->takeOwnershipOfSymbol(std::make_unique<Type>(intf.fOffset, id.fTypeName,
1150+
fields));
1151+
int arraySize = 0;
1152+
if (id.fSizeCount > 0) {
1153+
SkASSERT(id.fSizeCount == 1); // multi-dimensional arrays are not supported
11541154
const ASTNode& size = *(iter++);
11551155
if (size) {
11561156
std::unique_ptr<Expression> converted = this->convertExpression(size);
11571157
if (!converted) {
11581158
return nullptr;
11591159
}
1160-
String name = type->name();
1161-
int64_t count;
1162-
if (converted->kind() == Expression::Kind::kIntLiteral) {
1163-
count = converted->as<IntLiteral>().value();
1164-
if (count <= 0) {
1165-
fErrors.error(converted->fOffset, "array size must be positive");
1166-
return nullptr;
1167-
}
1168-
name += "[" + to_string(count) + "]";
1169-
} else {
1160+
if (!converted->is<IntLiteral>()) {
11701161
fErrors.error(intf.fOffset, "array size must be specified");
11711162
return nullptr;
11721163
}
1173-
type = symbols->takeOwnershipOfSymbol(
1174-
std::make_unique<Type>(name, Type::TypeKind::kArray, *type, (int)count));
1175-
sizes.push_back(std::move(converted));
1164+
arraySize = converted->as<IntLiteral>().value();
1165+
if (arraySize <= 0) {
1166+
fErrors.error(converted->fOffset, "array size must be positive");
1167+
return nullptr;
1168+
}
11761169
} else {
1177-
String name = String(type->name()) + "[]";
1178-
type = symbols->takeOwnershipOfSymbol(std::make_unique<Type>(
1179-
name, Type::TypeKind::kArray, *type, Type::kUnsizedArray));
1180-
sizes.push_back(nullptr);
1170+
arraySize = Type::kUnsizedArray;
11811171
}
1172+
type = symbols->addArrayDimensions(type, {arraySize});
11821173
}
11831174
const Variable* var = old->takeOwnershipOfSymbol(
11841175
std::make_unique<Variable>(intf.fOffset,
@@ -1201,7 +1192,7 @@ std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTNode
12011192
var,
12021193
id.fTypeName,
12031194
id.fInstanceName,
1204-
std::move(sizes),
1195+
arraySize,
12051196
symbols);
12061197
}
12071198

src/sksl/SkSLMetalCodeGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,12 +1260,12 @@ void MetalCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
12601260
if (intf.instanceName().size()) {
12611261
this->write(" ");
12621262
this->write(intf.instanceName());
1263-
for (const auto& size : intf.sizes()) {
1263+
if (intf.arraySize() > 0) {
12641264
this->write("[");
1265-
if (size) {
1266-
this->writeExpression(*size, kTopLevel_Precedence);
1267-
}
1265+
this->write(to_string(intf.arraySize()));
12681266
this->write("]");
1267+
} else if (intf.arraySize() == Type::kUnsizedArray){
1268+
this->write("[]");
12691269
}
12701270
fInterfaceBlockNameMap[&intf] = intf.instanceName();
12711271
} else {

src/sksl/SkSLRehydrator.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,9 @@ std::unique_ptr<ProgramElement> Rehydrator::element() {
327327
SkASSERT(var && var->is<Variable>());
328328
StringFragment typeName = this->readString();
329329
StringFragment instanceName = this->readString();
330-
uint8_t sizeCount = this->readU8();
331-
ExpressionArray sizes;
332-
sizes.reserve_back(sizeCount);
333-
for (int i = 0; i < sizeCount; ++i) {
334-
sizes.push_back(this->expression());
335-
}
330+
int arraySize = this->readS8();
336331
return std::make_unique<InterfaceBlock>(/*offset=*/-1, &var->as<Variable>(), typeName,
337-
instanceName, std::move(sizes), nullptr);
332+
instanceName, arraySize, nullptr);
338333
}
339334
case Rehydrator::kVarDeclarations_Command: {
340335
std::unique_ptr<Statement> decl = this->statement();

src/sksl/SkSLSPIRVCodeGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,8 +1907,8 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O
19071907
&intfStruct,
19081908
/*builtin=*/false,
19091909
Variable::Storage::kGlobal));
1910-
InterfaceBlock intf(/*offset=*/-1, intfVar, name, /*instanceName=*/"",
1911-
/*sizes=*/ExpressionArray(),
1910+
InterfaceBlock intf(/*offset=*/-1, intfVar, name,
1911+
/*instanceName=*/"", /*arraySize=*/0,
19121912
std::make_shared<SymbolTable>(&fErrors, /*builtin=*/false));
19131913

19141914
fRTHeightStructId = this->writeInterfaceBlock(intf, false);

src/sksl/generated/sksl_geom.dehydrated.sksl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ static uint8_t SKSL_INCLUDE_sksl_geom[] = {134,0,
7070
1,0,
7171
12,
7272
27,
73-
42,4,0,2,0,53,0,1,
74-
52,
73+
42,4,0,2,0,53,0,255,
7574
27,
7675
42,7,0,2,0,135,0,0,
7776
13,};

src/sksl/ir/SkSLInterfaceBlock.h

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class InterfaceBlock final : public ProgramElement {
3131
static constexpr Kind kProgramElementKind = Kind::kInterfaceBlock;
3232

3333
InterfaceBlock(int offset, const Variable* var, String typeName, String instanceName,
34-
ExpressionArray sizes, std::shared_ptr<SymbolTable> typeOwner)
34+
int arraySize, std::shared_ptr<SymbolTable> typeOwner)
3535
: INHERITED(offset, kProgramElementKind)
3636
, fVariable(var)
3737
, fTypeName(std::move(typeName))
3838
, fInstanceName(std::move(instanceName))
39-
, fSizes(std::move(sizes))
39+
, fArraySize(arraySize)
4040
, fTypeOwner(std::move(typeOwner)) {}
4141

4242
const Variable& variable() const {
@@ -59,22 +59,13 @@ class InterfaceBlock final : public ProgramElement {
5959
return fTypeOwner;
6060
}
6161

62-
ExpressionArray& sizes() {
63-
return fSizes;
64-
}
65-
66-
const ExpressionArray& sizes() const {
67-
return fSizes;
62+
int arraySize() const {
63+
return fArraySize;
6864
}
6965

7066
std::unique_ptr<ProgramElement> clone() const override {
71-
ExpressionArray sizesClone;
72-
sizesClone.reserve_back(this->sizes().size());
73-
for (const auto& size : this->sizes()) {
74-
sizesClone.push_back(size ? size->clone() : nullptr);
75-
}
7667
return std::make_unique<InterfaceBlock>(fOffset, &this->variable(), this->typeName(),
77-
this->instanceName(), std::move(sizesClone),
68+
this->instanceName(), this->arraySize(),
7869
SymbolTable::WrapIfBuiltin(this->typeOwner()));
7970
}
8071

@@ -88,14 +79,12 @@ class InterfaceBlock final : public ProgramElement {
8879
result += f.description() + "\n";
8980
}
9081
result += "}";
91-
if (this->instanceName().size()) {
82+
if (!this->instanceName().empty()) {
9283
result += " " + this->instanceName();
93-
for (const auto& size : this->sizes()) {
94-
result += "[";
95-
if (size) {
96-
result += size->description();
97-
}
98-
result += "]";
84+
if (this->arraySize() > 0) {
85+
result.appendf("[%d]", this->arraySize());
86+
} else if (this->arraySize() == Type::kUnsizedArray){
87+
result += "[]";
9988
}
10089
}
10190
return result + ";";
@@ -105,7 +94,7 @@ class InterfaceBlock final : public ProgramElement {
10594
const Variable* fVariable;
10695
String fTypeName;
10796
String fInstanceName;
108-
ExpressionArray fSizes;
97+
int fArraySize;
10998
std::shared_ptr<SymbolTable> fTypeOwner;
11099

111100
using INHERITED = ProgramElement;

0 commit comments

Comments
 (0)