aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-autoroll <android-autoroll@skia-corp.google.com.iam.gserviceaccount.com>2023-04-13 20:56:45 +0000
committerandroid-autoroll <android-autoroll@skia-corp.google.com.iam.gserviceaccount.com>2023-04-13 20:56:45 +0000
commit3ace9b2024d5b55a081f8b7ae6df909f8b241fbb (patch)
treef4482a145a60bf0d4c3b92e64e149719a94ad61b
parentaf7314072e3b95bd294ad19a06063e79488d3fcc (diff)
parent0506208ca0e5cf36f0200b75087f62cc7e91c543 (diff)
downloadskia-3ace9b2024d5b55a081f8b7ae6df909f8b241fbb.tar.gz
RESTRICT AUTOMERGE Roll Skia from e89ff8d45849 to 0506208ca0e5 (1 revision)
https://skia.googlesource.com/skia.git/+log/e89ff8d45849..0506208ca0e5 If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://skia-autoroll.corp.goog/r/android-u-release-autoroll Please CC nscobie@google.com,rmistry@google.com,scroggo@google.com on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md Test: Presubmit checks will test this change. Exempt-From-Owner-Approval: The autoroll bot does not require owner approval. Bug: b/186777432 Change-Id: I84d250c27ce407259c52d12e2e011c0c0a7ae3b0
-rw-r--r--gn/sksl_tests.gni1
-rw-r--r--resources/sksl/BUILD.bazel1
-rw-r--r--resources/sksl/errors/ProgramTooLarge_Parameters.rts14
-rw-r--r--src/sksl/ir/SkSLFunctionDefinition.cpp43
-rw-r--r--tests/sksl/errors/ProgramTooLarge_Parameters.glsl6
5 files changed, 48 insertions, 17 deletions
diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni
index 2ac52e543d..19ce61663b 100644
--- a/gn/sksl_tests.gni
+++ b/gn/sksl_tests.gni
@@ -199,6 +199,7 @@ sksl_error_tests = [
"errors/PrivateTypes.rts",
"errors/PrivateVariables.rts",
"errors/ProgramTooLarge_Globals.rts",
+ "errors/ProgramTooLarge_Parameters.rts",
"errors/ProgramTooLarge_Stack.rts",
"errors/PrototypeInFuncBody.rts",
"errors/RTAdjustType.sksl",
diff --git a/resources/sksl/BUILD.bazel b/resources/sksl/BUILD.bazel
index 2ed2f2b2be..6c21edc6d7 100644
--- a/resources/sksl/BUILD.bazel
+++ b/resources/sksl/BUILD.bazel
@@ -350,6 +350,7 @@ skia_filegroup(
"errors/PrivateTypes.rts",
"errors/PrivateVariables.rts",
"errors/ProgramTooLarge_Globals.rts",
+ "errors/ProgramTooLarge_Parameters.rts",
"errors/ProgramTooLarge_Stack.rts",
"errors/PrototypeInFuncBody.rts",
"errors/RTAdjustType.sksl",
diff --git a/resources/sksl/errors/ProgramTooLarge_Parameters.rts b/resources/sksl/errors/ProgramTooLarge_Parameters.rts
new file mode 100644
index 0000000000..cced977be4
--- /dev/null
+++ b/resources/sksl/errors/ProgramTooLarge_Parameters.rts
@@ -0,0 +1,14 @@
+struct S {
+ half4 ah4[1];
+ half ah[99999];
+ half4 h4;
+ half h;
+};
+
+void func(int small,
+ S big_chungus,
+ S no_report /*we don't need to report overflows past the first*/) {}
+
+/*%%*
+variable 'big_chungus' exceeds the stack size limit
+*%%*/
diff --git a/src/sksl/ir/SkSLFunctionDefinition.cpp b/src/sksl/ir/SkSLFunctionDefinition.cpp
index f5ff4f9411..b33a4352a6 100644
--- a/src/sksl/ir/SkSLFunctionDefinition.cpp
+++ b/src/sksl/ir/SkSLFunctionDefinition.cpp
@@ -37,6 +37,7 @@
#include <cstddef>
#include <forward_list>
#include <string_view>
+#include <vector>
namespace SkSL {
@@ -88,9 +89,29 @@ std::unique_ptr<FunctionDefinition> FunctionDefinition::Convert(const Context& c
bool builtin) {
class Finalizer : public ProgramWriter {
public:
- Finalizer(const Context& context, const FunctionDeclaration& function)
+ Finalizer(const Context& context, const FunctionDeclaration& function, Position pos)
: fContext(context)
- , fFunction(function) {}
+ , fFunction(function) {
+ // Function parameters count as local variables.
+ for (const Variable* var : function.parameters()) {
+ this->addLocalVariable(var, pos);
+ }
+ }
+
+ void addLocalVariable(const Variable* var, Position pos) {
+ // We count the number of slots used, but don't consider the precision of the base type.
+ // In practice, this reflects what GPUs actually do pretty well. (i.e., RelaxedPrecision
+ // math doesn't mean your variable takes less space.) We also don't attempt to reclaim
+ // slots at the end of a Block.
+ size_t prevSlotsUsed = fSlotsUsed;
+ fSlotsUsed = SkSafeMath::Add(fSlotsUsed, var->type().slotCount());
+ // To avoid overzealous error reporting, only trigger the error at the first
+ // place where the stack limit is exceeded.
+ if (prevSlotsUsed < kVariableSlotLimit && fSlotsUsed >= kVariableSlotLimit) {
+ fContext.fErrors->error(pos, "variable '" + std::string(var->name()) +
+ "' exceeds the stack size limit");
+ }
+ }
~Finalizer() override {
SkASSERT(fBreakableLevel == 0);
@@ -109,24 +130,12 @@ std::unique_ptr<FunctionDefinition> FunctionDefinition::Convert(const Context& c
bool visitStatement(Statement& stmt) override {
switch (stmt.kind()) {
case Statement::Kind::kVarDeclaration: {
- // We count the number of slots used, but don't consider the precision of the
- // base type. In practice, this reflects what GPUs really do pretty well.
- // (i.e., RelaxedPrecision math doesn't mean your variable takes less space.)
- // We also don't attempt to reclaim slots at the end of a Block.
- size_t prevSlotsUsed = fSlotsUsed;
const Variable* var = stmt.as<VarDeclaration>().var();
if (var->type().isOrContainsUnsizedArray()) {
fContext.fErrors->error(stmt.fPosition,
"unsized arrays are not permitted here");
- break;
- }
- fSlotsUsed = SkSafeMath::Add(fSlotsUsed, var->type().slotCount());
- // To avoid overzealous error reporting, only trigger the error at the first
- // place where the stack limit is exceeded.
- if (prevSlotsUsed < kVariableSlotLimit && fSlotsUsed >= kVariableSlotLimit) {
- fContext.fErrors->error(stmt.fPosition,
- "variable '" + std::string(var->name()) +
- "' exceeds the stack size limit");
+ } else {
+ this->addLocalVariable(var, stmt.fPosition);
}
break;
}
@@ -219,7 +228,7 @@ std::unique_ptr<FunctionDefinition> FunctionDefinition::Convert(const Context& c
using INHERITED = ProgramWriter;
};
- Finalizer(context, function).visitStatement(*body);
+ Finalizer(context, function, pos).visitStatement(*body);
if (function.isMain() && ProgramConfig::IsVertex(context.fConfig->fKind)) {
append_rtadjust_fixup_to_vertex_main(context, function, body->as<Block>());
}
diff --git a/tests/sksl/errors/ProgramTooLarge_Parameters.glsl b/tests/sksl/errors/ProgramTooLarge_Parameters.glsl
new file mode 100644
index 0000000000..d92c3256e8
--- /dev/null
+++ b/tests/sksl/errors/ProgramTooLarge_Parameters.glsl
@@ -0,0 +1,6 @@
+### Compilation failed:
+
+error: 10: variable 'big_chungus' exceeds the stack size limit
+ S no_report /*we don't need to report overflows past the first*/) {}
+ ^^
+1 error