Remove support for unsized arrays
These only existed for geometry shader interface blocks.
Change-Id: Ie82252715fe5e6babb85e3b437c6edd811fab955
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/442695
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/gpu/GrSPIRVVaryingHandler.cpp b/src/gpu/GrSPIRVVaryingHandler.cpp
index a0c8ea9..064ce6d 100644
--- a/src/gpu/GrSPIRVVaryingHandler.cpp
+++ b/src/gpu/GrSPIRVVaryingHandler.cpp
@@ -96,10 +96,7 @@
int elementSize = grsltype_to_location_size(var.getType());
SkASSERT(elementSize > 0);
- int numElements = 1;
- if (var.isArray() && !var.isUnsizedArray()) {
- numElements = var.getArrayCount();
- }
+ int numElements = var.isArray() ? var.getArrayCount() : 1;
SkASSERT(numElements > 0);
locationIndex += elementSize * numElements;
}
diff --git a/src/gpu/GrShaderVar.cpp b/src/gpu/GrShaderVar.cpp
index 78c9331..accbe2c 100644
--- a/src/gpu/GrShaderVar.cpp
+++ b/src/gpu/GrShaderVar.cpp
@@ -32,15 +32,11 @@
}
GrSLType effectiveType = this->getType();
if (this->isArray()) {
- if (this->isUnsizedArray()) {
- out->appendf("%s %s[]", GrGLSLTypeString(effectiveType), this->getName().c_str());
- } else {
- SkASSERT(this->getArrayCount() > 0);
- out->appendf("%s %s[%d]",
- GrGLSLTypeString(effectiveType),
- this->getName().c_str(),
- this->getArrayCount());
- }
+ SkASSERT(this->getArrayCount() > 0);
+ out->appendf("%s %s[%d]",
+ GrGLSLTypeString(effectiveType),
+ this->getName().c_str(),
+ this->getArrayCount());
} else {
out->appendf("%s %s", GrGLSLTypeString(effectiveType), this->getName().c_str());
}
diff --git a/src/gpu/GrShaderVar.h b/src/gpu/GrShaderVar.h
index f4e8d4f..45bdce2 100644
--- a/src/gpu/GrShaderVar.h
+++ b/src/gpu/GrShaderVar.h
@@ -29,7 +29,6 @@
/** Values for array count that have special meaning. We allow 1-sized arrays. */
enum {
kNonArray = 0, // not an array
- kUnsizedArray = -1, // an unsized array (declared with [])
};
/** Defaults to a void with no type modifier or layout qualifier. */
@@ -85,9 +84,6 @@
/** Is the var an array. */
bool isArray() const { return kNonArray != fCount; }
- /** Is this an unsized array, (i.e. declared with []). */
- bool isUnsizedArray() const { return kUnsizedArray == fCount; }
-
/** Get the array length. */
int getArrayCount() const { return fCount; }
diff --git a/src/gpu/vk/GrVkVaryingHandler.cpp b/src/gpu/vk/GrVkVaryingHandler.cpp
index e6925ea..bf57012 100644
--- a/src/gpu/vk/GrVkVaryingHandler.cpp
+++ b/src/gpu/vk/GrVkVaryingHandler.cpp
@@ -90,10 +90,7 @@
int elementSize = grsltype_to_location_size(var.getType());
SkASSERT(elementSize > 0);
- int numElements = 1;
- if (var.isArray() && !var.isUnsizedArray()) {
- numElements = var.getArrayCount();
- }
+ int numElements = var.isArray() ? var.getArrayCount() : 1;
SkASSERT(numElements > 0);
locationIndex += elementSize * numElements;
}
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 429a52b..9471aa3 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -842,16 +842,9 @@
int arraySize = 0;
if (id.fIsArray) {
const ASTNode& size = *(iter++);
- if (size) {
- // convertArraySize rejects unsized arrays. This is the one place we allow those, but
- // we've already checked for that, so this is verifying the other aspects (constant,
- // positive, not too large).
- arraySize = this->convertArraySize(*type, size.fOffset, size);
- if (!arraySize) {
- return nullptr;
- }
- } else {
- arraySize = Type::kUnsizedArray;
+ arraySize = this->convertArraySize(*type, size.fOffset, size);
+ if (!arraySize) {
+ return nullptr;
}
type = symbols->addArrayDimension(type, arraySize);
}
diff --git a/src/sksl/codegen/SkSLGLSLCodeGenerator.cpp b/src/sksl/codegen/SkSLGLSLCodeGenerator.cpp
index 81087d9..7f3ba9b 100644
--- a/src/sksl/codegen/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLGLSLCodeGenerator.cpp
@@ -102,9 +102,7 @@
}
case Type::TypeKind::kArray: {
String baseTypeName = this->getTypeName(type.componentType());
- return (type.columns() == Type::kUnsizedArray)
- ? String::printf("%s[]", baseTypeName.c_str())
- : String::printf("%s[%d]", baseTypeName.c_str(), type.columns());
+ return String::printf("%s[%d]", baseTypeName.c_str(), type.columns());
}
case Type::TypeKind::kScalar: {
if (type == *fContext.fTypes.fHalf) {
@@ -1013,11 +1011,7 @@
this->writeType(*type);
this->write(" " + param->name());
for (int s : sizes) {
- if (s == Type::kUnsizedArray) {
- this->write("[]");
- } else {
- this->write("[" + to_string(s) + "]");
- }
+ this->write("[" + to_string(s) + "]");
}
}
this->write(")");
@@ -1120,8 +1114,6 @@
this->write("[");
this->write(to_string(intf.arraySize()));
this->write("]");
- } else if (intf.arraySize() == Type::kUnsizedArray){
- this->write("[]");
}
}
this->writeLine(";");
@@ -1175,8 +1167,6 @@
this->write("[");
this->write(to_string(var.arraySize()));
this->write("]");
- } else if (var.arraySize() == Type::kUnsizedArray){
- this->write("[]");
}
if (var.value()) {
this->write(" = ");
diff --git a/src/sksl/codegen/SkSLMetalCodeGenerator.cpp b/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
index af97607..bd5b2d0 100644
--- a/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
@@ -1886,8 +1886,6 @@
this->write("[");
this->write(to_string(intf.arraySize()));
this->write("]");
- } else if (intf.arraySize() == Type::kUnsizedArray){
- this->write("[]");
}
fInterfaceBlockNameMap[&intf] = intf.instanceName();
} else {
diff --git a/src/sksl/codegen/SkSLPipelineStageCodeGenerator.cpp b/src/sksl/codegen/SkSLPipelineStageCodeGenerator.cpp
index 094f52f..3182b392 100644
--- a/src/sksl/codegen/SkSLPipelineStageCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLPipelineStageCodeGenerator.cpp
@@ -409,9 +409,7 @@
// This is necessary so that name mangling on arrays-of-structs works properly.
String arrayName = this->typeName(type.componentType());
arrayName.push_back('[');
- if (type.columns() != Type::kUnsizedArray) {
- arrayName += to_string(type.columns());
- }
+ arrayName += to_string(type.columns());
arrayName.push_back(']');
return arrayName;
}
diff --git a/src/sksl/dsl/DSLType.cpp b/src/sksl/dsl/DSLType.cpp
index 4791b23..8e84881 100644
--- a/src/sksl/dsl/DSLType.cpp
+++ b/src/sksl/dsl/DSLType.cpp
@@ -205,6 +205,7 @@
DSLType Array(const DSLType& base, int count) {
if (count <= 0) {
DSLWriter::ReportError("array size must be positive");
+ return base;
}
if (base.isArray()) {
DSLWriter::ReportError("multidimensional arrays are not permitted");
diff --git a/src/sksl/ir/SkSLIndexExpression.cpp b/src/sksl/ir/SkSLIndexExpression.cpp
index d2f355c..7f31226 100644
--- a/src/sksl/ir/SkSLIndexExpression.cpp
+++ b/src/sksl/ir/SkSLIndexExpression.cpp
@@ -63,10 +63,7 @@
const Expression* indexExpr = ConstantFolder::GetConstantValueForVariable(*index);
if (indexExpr->is<IntLiteral>()) {
SKSL_INT indexValue = indexExpr->as<IntLiteral>().value();
- const int upperBound = (baseType.isArray() && baseType.columns() == Type::kUnsizedArray)
- ? INT_MAX
- : baseType.columns();
- if (indexValue < 0 || indexValue >= upperBound) {
+ if (indexValue < 0 || indexValue >= baseType.columns()) {
context.fErrors->error(base->fOffset, "index " + to_string(indexValue) +
" out of range for '" + baseType.displayName() +
"'");
diff --git a/src/sksl/ir/SkSLInterfaceBlock.h b/src/sksl/ir/SkSLInterfaceBlock.h
index b5ececd..0405e2e 100644
--- a/src/sksl/ir/SkSLInterfaceBlock.h
+++ b/src/sksl/ir/SkSLInterfaceBlock.h
@@ -85,8 +85,6 @@
result += " " + this->instanceName();
if (this->arraySize() > 0) {
result.appendf("[%d]", this->arraySize());
- } else if (this->arraySize() == Type::kUnsizedArray){
- result += "[]";
}
}
return result + ";";
diff --git a/src/sksl/ir/SkSLSymbolTable.h b/src/sksl/ir/SkSLSymbolTable.h
index 44d8c73..b0434e6 100644
--- a/src/sksl/ir/SkSLSymbolTable.h
+++ b/src/sksl/ir/SkSLSymbolTable.h
@@ -90,8 +90,8 @@
/**
* Given type = `float` and arraySize = 5, creates the array type `float[5]` in the symbol
- * table. The created array type is returned. `kUnsizedArray` can be passed as a `[]` dimension.
- * If zero is passed, the base type is returned unchanged.
+ * table. The created array type is returned. If zero is passed, the base type is returned
+ * unchanged.
*/
const Type* addArrayDimension(const Type* type, int arraySize);
diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp
index 160126e..40e8447 100644
--- a/src/sksl/ir/SkSLType.cpp
+++ b/src/sksl/ir/SkSLType.cpp
@@ -29,8 +29,8 @@
: INHERITED(name, abbrev, kTypeKind)
, fComponentType(componentType)
, fCount(count) {
- // Allow either explicitly-sized or unsized arrays.
- SkASSERT(count > 0 || count == kUnsizedArray);
+ // Only allow explicitly-sized arrays.
+ SkASSERT(count > 0);
// Disallow multi-dimensional arrays.
SkASSERT(!componentType.is<ArrayType>());
}
@@ -376,9 +376,7 @@
String Type::getArrayName(int arraySize) const {
skstd::string_view name = this->name();
- return (arraySize != kUnsizedArray)
- ? String::printf("%.*s[%d]", (int)name.size(), name.data(), arraySize)
- : String::printf("%.*s[]", (int)name.size(), name.data());
+ return String::printf("%.*s[%d]", (int)name.size(), name.data(), arraySize);
}
std::unique_ptr<Type> Type::MakeArrayType(skstd::string_view name, const Type& componentType,
diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h
index d3ec44a..a2f5a44 100644
--- a/src/sksl/ir/SkSLType.h
+++ b/src/sksl/ir/SkSLType.h
@@ -106,7 +106,6 @@
Type(const Type& other) = delete;
/** Creates an array type. */
- static constexpr int kUnsizedArray = -1;
static std::unique_ptr<Type> MakeArrayType(skstd::string_view name, const Type& componentType,
int columns);
diff --git a/src/sksl/ir/SkSLVarDeclarations.cpp b/src/sksl/ir/SkSLVarDeclarations.cpp
index 6cd96ca..725544c 100644
--- a/src/sksl/ir/SkSLVarDeclarations.cpp
+++ b/src/sksl/ir/SkSLVarDeclarations.cpp
@@ -24,8 +24,6 @@
this->var().name();
if (this->arraySize() > 0) {
result.appendf("[%d]", this->arraySize());
- } else if (this->arraySize() == Type::kUnsizedArray) {
- result += "[]";
}
if (this->value()) {
result += " = " + this->value()->description();
diff --git a/src/sksl/ir/SkSLVarDeclarations.h b/src/sksl/ir/SkSLVarDeclarations.h
index 8a2b7ca..52ce919 100644
--- a/src/sksl/ir/SkSLVarDeclarations.h
+++ b/src/sksl/ir/SkSLVarDeclarations.h
@@ -89,7 +89,7 @@
private:
const Variable* fVar;
const Type& fBaseType;
- int fArraySize; // zero means "not an array", Type::kUnsizedArray means var[]
+ int fArraySize; // zero means "not an array"
std::unique_ptr<Expression> fValue;
friend class IRGenerator;