aboutsummaryrefslogtreecommitdiff
path: root/src/sksl/ir/SkSLFunctionDefinition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sksl/ir/SkSLFunctionDefinition.cpp')
-rw-r--r--src/sksl/ir/SkSLFunctionDefinition.cpp41
1 files changed, 16 insertions, 25 deletions
diff --git a/src/sksl/ir/SkSLFunctionDefinition.cpp b/src/sksl/ir/SkSLFunctionDefinition.cpp
index 5daee59cc0..3c7c3d182e 100644
--- a/src/sksl/ir/SkSLFunctionDefinition.cpp
+++ b/src/sksl/ir/SkSLFunctionDefinition.cpp
@@ -21,8 +21,6 @@
#include "src/sksl/transform/SkSLProgramWriter.h"
#include <forward_list>
-#include <string_view>
-#include <vector>
namespace SkSL {
@@ -82,27 +80,7 @@ std::unique_ptr<FunctionDefinition> FunctionDefinition::Convert(const Context& c
FunctionSet* referencedBuiltinFunctions)
: fContext(context)
, fFunction(function)
- , 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");
- }
- }
+ , fReferencedBuiltinFunctions(referencedBuiltinFunctions) {}
~Finalizer() override {
SkASSERT(fBreakableLevel == 0);
@@ -166,8 +144,21 @@ std::unique_ptr<FunctionDefinition> FunctionDefinition::Convert(const Context& c
bool visitStatement(Statement& stmt) override {
switch (stmt.kind()) {
case Statement::Kind::kVarDeclaration: {
- const Variable* var = &stmt.as<VarDeclaration>().var();
- this->addLocalVariable(var, stmt.fLine);
+ // 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");
+ }
break;
}
case Statement::Kind::kReturn: {