diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-29 03:10:08 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-29 03:10:08 +0000 |
commit | 9c617e1bcd1da17431fcea6ccb2eadb1934eaa6e (patch) | |
tree | 484a1a970bd17c8924c004b2ec56984015b6372f | |
parent | 90150eb648ed7c18fced7dc4a58b7eb7c8235a0b (diff) | |
parent | e8f461729bcd4ec9a27a8b27c313972e1b3d1e76 (diff) | |
download | skia-android13-qpr3-c-s12-release.tar.gz |
Merge cherrypicks of ['googleplex-android-review.googlesource.com/22896125'] into tm-qpr3-c-release.android-13.0.0_r82android-13.0.0_r81android-13.0.0_r80android-13.0.0_r74android-13.0.0_r73android-13.0.0_r72android-13.0.0_r66android-13.0.0_r65android-13.0.0_r64android13-qpr3-c-s8-releaseandroid13-qpr3-c-s7-releaseandroid13-qpr3-c-s6-releaseandroid13-qpr3-c-s5-releaseandroid13-qpr3-c-s4-releaseandroid13-qpr3-c-s12-releaseandroid13-qpr3-c-s11-releaseandroid13-qpr3-c-s10-release
Change-Id: I11628b86f62a56bd99b8979ac77d9b137aedb6ba
-rw-r--r-- | gn/sksl_tests.gni | 1 | ||||
-rw-r--r-- | resources/sksl/errors/ProgramTooLarge_Parameters.rts | 14 | ||||
-rw-r--r-- | src/sksl/ir/SkSLFunctionDefinition.cpp | 41 | ||||
-rw-r--r-- | tests/sksl/errors/ProgramTooLarge_Parameters.glsl | 6 |
4 files changed, 46 insertions, 16 deletions
diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni index d4c4ad4958..fdb0b91aee 100644 --- a/gn/sksl_tests.gni +++ b/gn/sksl_tests.gni @@ -146,6 +146,7 @@ sksl_error_tests = [ "/sksl/errors/PrivateTypes.rts", "/sksl/errors/PrivateVariables.rts", "/sksl/errors/ProgramTooLarge_Globals.rts", + "/sksl/errors/ProgramTooLarge_Parameters.rts", "/sksl/errors/ProgramTooLarge_Stack.rts", "/sksl/errors/PrototypeInFuncBody.rts", "/sksl/errors/RedeclareBasicType.rts", 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 3c7c3d182e..5daee59cc0 100644 --- a/src/sksl/ir/SkSLFunctionDefinition.cpp +++ b/src/sksl/ir/SkSLFunctionDefinition.cpp @@ -21,6 +21,8 @@ #include "src/sksl/transform/SkSLProgramWriter.h" #include <forward_list> +#include <string_view> +#include <vector> namespace SkSL { @@ -80,7 +82,27 @@ std::unique_ptr<FunctionDefinition> FunctionDefinition::Convert(const Context& c FunctionSet* referencedBuiltinFunctions) : fContext(context) , fFunction(function) - , fReferencedBuiltinFunctions(referencedBuiltinFunctions) {} + , fReferencedBuiltinFunctions(referencedBuiltinFunctions) { + // Function parameters count as local variables. + for (const Variable* var : function.parameters()) { + this->addLocalVariable(var, function.fLine); + } + } + + void addLocalVariable(const Variable* var, int line) { + // 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(line, "variable '" + std::string(var->name()) + + "' exceeds the stack size limit"); + } + } ~Finalizer() override { SkASSERT(fBreakableLevel == 0); @@ -144,21 +166,8 @@ 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; - fSlotsUsed = SkSafeMath::Add( - fSlotsUsed, stmt.as<VarDeclaration>().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.fLine, - "variable '" + std::string(stmt.as<VarDeclaration>().var().name()) + - "' exceeds the stack size limit"); - } + const Variable* var = &stmt.as<VarDeclaration>().var(); + this->addLocalVariable(var, stmt.fLine); break; } case Statement::Kind::kReturn: { 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 |