From 7335009e18ecbf53ad9f59d64eed2ed5abbe7b8b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 10 Mar 2021 13:14:48 +0200 Subject: [PATCH] Some rearranging and comments --- source/glsl/compiler.h | 2 ++ source/glsl/generate.cpp | 3 +++ source/glsl/optimize.cpp | 46 ++++++++++++++++++++-------------------- source/glsl/optimize.h | 4 ++-- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/source/glsl/compiler.h b/source/glsl/compiler.h index 51043888..a515a326 100644 --- a/source/glsl/compiler.h +++ b/source/glsl/compiler.h @@ -131,6 +131,8 @@ private: aspects as necessary. */ void resolve(Stage &, unsigned = RESOLVE_ALL); + /** Checks the validity of the module. If the return value is false, the + module's diagnostics list will contain additional information of errors. */ bool validate(Stage &); static bool diagnostic_line_order(const Diagnostic &, const Diagnostic &); diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 09a776af..158bb4cc 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -191,6 +191,9 @@ void TypeResolver::visit(BasicTypeDeclaration &type) if(basic_base->kind==BasicTypeDeclaration::VECTOR) { type.kind = BasicTypeDeclaration::MATRIX; + /* A matrix's base type is its column vector type. This will put + the column vector's size, i.e. the matrix's row count, in the high + half of the size. */ type.size |= basic_base->size<<16; } diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 441a73a0..9ab8ef70 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -809,29 +809,6 @@ void UnusedVariableRemover::visit(InterfaceBlock &iface) } } -void UnusedVariableRemover::visit(FunctionDeclaration &func) -{ - if(func.body.body.empty()) - return; - - BlockVariableMap saved_vars = variables; - // Assignments from other functions should not be visible. - for(BlockVariableMap::iterator i=variables.begin(); i!=variables.end(); ++i) - i->second.assignments.resize(i->second.initialized); - TraversingVisitor::visit(func); - swap(variables, saved_vars); - merge_variables(saved_vars); - - /* Always treat function parameters as referenced. Removing unused - parameters is not currently supported. */ - for(NodeArray::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i) - { - BlockVariableMap::iterator j = variables.find(i->get()); - if(j!=variables.end()) - j->second.referenced = true; - } -} - void UnusedVariableRemover::merge_variables(const BlockVariableMap &other_vars) { for(BlockVariableMap::const_iterator i=other_vars.begin(); i!=other_vars.end(); ++i) @@ -855,6 +832,29 @@ void UnusedVariableRemover::merge_variables(const BlockVariableMap &other_vars) } } +void UnusedVariableRemover::visit(FunctionDeclaration &func) +{ + if(func.body.body.empty()) + return; + + BlockVariableMap saved_vars = variables; + // Assignments from other functions should not be visible. + for(BlockVariableMap::iterator i=variables.begin(); i!=variables.end(); ++i) + i->second.assignments.resize(i->second.initialized); + TraversingVisitor::visit(func); + swap(variables, saved_vars); + merge_variables(saved_vars); + + /* Always treat function parameters as referenced. Removing unused + parameters is not currently supported. */ + for(NodeArray::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i) + { + BlockVariableMap::iterator j = variables.find(i->get()); + if(j!=variables.end()) + j->second.referenced = true; + } +} + void UnusedVariableRemover::visit(Conditional &cond) { cond.condition->visit(*this); diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 5448ea7c..34c0b245 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -227,15 +227,15 @@ private: virtual void visit(UnaryExpression &); virtual void visit(BinaryExpression &); virtual void visit(Assignment &); - void record_assignment(const Assignment::Target &, Node &); virtual void visit(FunctionCall &); + void record_assignment(const Assignment::Target &, Node &); virtual void visit(ExpressionStatement &); // Ignore structs because their members can't be accessed directly. virtual void visit(StructDeclaration &) { } virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); - virtual void visit(FunctionDeclaration &); void merge_variables(const BlockVariableMap &); + virtual void visit(FunctionDeclaration &); virtual void visit(Conditional &); virtual void visit(Iteration &); }; -- 2.43.0