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/resources/sksl/errors/ArrayIndexOutOfRange.sksl b/resources/sksl/errors/ArrayIndexOutOfRange.sksl
index 3ad9dfb..72a9a37 100644
--- a/resources/sksl/errors/ArrayIndexOutOfRange.sksl
+++ b/resources/sksl/errors/ArrayIndexOutOfRange.sksl
@@ -1,5 +1,3 @@
-in Block { int x; } unsizedArray[];
-
void array_neg1 () { int a[123]; int v = a[-1]; }
void array_0 () { float a[123]; float v = a[0]; }
void array_122 () { bool2 a[123]; bool2 v = a[122]; }
@@ -8,12 +6,6 @@
void array_overflow () { half3 a[123]; half3 v = a[3000000000]; }
void array_no_index () { int a[123]; int v = a[]; }
-void unsized_array_neg1 () { int v = unsizedArray[-1].x; }
-void unsized_array_0 () { int v = unsizedArray[0].x; }
-void unsized_array_huge () { int v = unsizedArray[1000000000].x; }
-void unsized_array_overflow () { int v = unsizedArray[3000000000].x; }
-void unsized_array_no_index () { int v = unsizedArray[].x; }
-
void half4_neg1() { half4 h; half v = h[-1]; }
void half4_0() { half4 h; half v = h[0]; }
void half4_1() { half4 h; half v = h[1]; }
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;
diff --git a/tests/sksl/errors/ArrayIndexOutOfRange.glsl b/tests/sksl/errors/ArrayIndexOutOfRange.glsl
index 64909e4..d8e2853 100644
--- a/tests/sksl/errors/ArrayIndexOutOfRange.glsl
+++ b/tests/sksl/errors/ArrayIndexOutOfRange.glsl
@@ -1,44 +1,41 @@
### Compilation failed:
-error: 3: index -1 out of range for 'int[123]'
-error: 6: index 123 out of range for 'half4x4[123]'
-error: 7: index 1000000000 out of range for 'int4[123]'
-error: 8: index 3000000000 out of range for 'half3[123]'
-error: 9: missing index in '[]'
-error: 11: index -1 out of range for 'Block[]'
-error: 14: index 3000000000 out of range for 'Block[]'
-error: 15: missing index in '[]'
-error: 17: index -1 out of range for 'half4'
-error: 22: index 4 out of range for 'half4'
-error: 23: index 1000000000 out of range for 'half4'
-error: 25: index -1 out of range for 'half3'
-error: 29: index 3 out of range for 'half3'
-error: 30: index 4 out of range for 'half3'
-error: 31: index 1000000000 out of range for 'half3'
-error: 33: index -1 out of range for 'half2'
-error: 36: index 2 out of range for 'half2'
-error: 37: index 3 out of range for 'half2'
-error: 38: index 4 out of range for 'half2'
-error: 39: index 1000000000 out of range for 'half2'
-error: 41: index -1 out of range for 'half2x4'
-error: 44: index 2 out of range for 'half2x4'
-error: 45: index 3 out of range for 'half2x4'
-error: 46: index 4 out of range for 'half2x4'
-error: 47: index 1000000000 out of range for 'half2x4'
-error: 49: index -1 out of range for 'half3x3'
-error: 53: index 3 out of range for 'half3x3'
-error: 54: index 4 out of range for 'half3x3'
-error: 55: index 1000000000 out of range for 'half3x3'
-error: 57: index -1 out of range for 'half4x2'
-error: 62: index 4 out of range for 'half4x2'
-error: 63: index 1000000000 out of range for 'half4x2'
-error: 65: index -1 out of range for 'half2'
-error: 68: index 2 out of range for 'half2'
-error: 69: index 1000000000 out of range for 'half2'
-error: 71: index -1 out of range for 'half3'
-error: 75: index 3 out of range for 'half3'
-error: 76: index 1000000000 out of range for 'half3'
-error: 78: index -1 out of range for 'half4'
-error: 83: index 4 out of range for 'half4'
-error: 84: index 1000000000 out of range for 'half4'
-41 errors
+error: 1: index -1 out of range for 'int[123]'
+error: 4: index 123 out of range for 'half4x4[123]'
+error: 5: index 1000000000 out of range for 'int4[123]'
+error: 6: index 3000000000 out of range for 'half3[123]'
+error: 7: missing index in '[]'
+error: 9: index -1 out of range for 'half4'
+error: 14: index 4 out of range for 'half4'
+error: 15: index 1000000000 out of range for 'half4'
+error: 17: index -1 out of range for 'half3'
+error: 21: index 3 out of range for 'half3'
+error: 22: index 4 out of range for 'half3'
+error: 23: index 1000000000 out of range for 'half3'
+error: 25: index -1 out of range for 'half2'
+error: 28: index 2 out of range for 'half2'
+error: 29: index 3 out of range for 'half2'
+error: 30: index 4 out of range for 'half2'
+error: 31: index 1000000000 out of range for 'half2'
+error: 33: index -1 out of range for 'half2x4'
+error: 36: index 2 out of range for 'half2x4'
+error: 37: index 3 out of range for 'half2x4'
+error: 38: index 4 out of range for 'half2x4'
+error: 39: index 1000000000 out of range for 'half2x4'
+error: 41: index -1 out of range for 'half3x3'
+error: 45: index 3 out of range for 'half3x3'
+error: 46: index 4 out of range for 'half3x3'
+error: 47: index 1000000000 out of range for 'half3x3'
+error: 49: index -1 out of range for 'half4x2'
+error: 54: index 4 out of range for 'half4x2'
+error: 55: index 1000000000 out of range for 'half4x2'
+error: 57: index -1 out of range for 'half2'
+error: 60: index 2 out of range for 'half2'
+error: 61: index 1000000000 out of range for 'half2'
+error: 63: index -1 out of range for 'half3'
+error: 67: index 3 out of range for 'half3'
+error: 68: index 1000000000 out of range for 'half3'
+error: 70: index -1 out of range for 'half4'
+error: 75: index 4 out of range for 'half4'
+error: 76: index 1000000000 out of range for 'half4'
+38 errors
diff --git a/tests/sksl/errors/Ossfuzz36850.asm.frag b/tests/sksl/errors/Ossfuzz36850.asm.frag
index 994061e..f0c29c1 100644
--- a/tests/sksl/errors/Ossfuzz36850.asm.frag
+++ b/tests/sksl/errors/Ossfuzz36850.asm.frag
@@ -1,4 +1,4 @@
### Compilation failed:
-error: runtime-sized arrays are not supported in SPIR-V
+error: array must have a size
1 error
diff --git a/tests/sksl/errors/Ossfuzz37469.asm.frag b/tests/sksl/errors/Ossfuzz37469.asm.frag
index 994061e..f0c29c1 100644
--- a/tests/sksl/errors/Ossfuzz37469.asm.frag
+++ b/tests/sksl/errors/Ossfuzz37469.asm.frag
@@ -1,4 +1,4 @@
### Compilation failed:
-error: runtime-sized arrays are not supported in SPIR-V
+error: array must have a size
1 error