X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Foptimize.cpp;h=6e4b56771fa3222ce778a53d37b828b5d34554cf;hp=ea0f96f0e60920cba9dd23523e83c37a07133ffb;hb=HEAD;hpb=1420854eb3827b8229bae2c2c6cebdd34a320f13 diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index ea0f96f0..a35e2cd2 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -115,12 +115,16 @@ string InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_fu /* Populate referenced_names from the target function so we can rename variables from the inlined function that would conflict. Only consider - names which declared in blocks linearly related to the target block. */ + names declared in blocks linearly related to the target block. */ pass = REFERENCED; tgt_blk.visit(*this); for(const Block *b=&tgt_blk; b; b=b->parent) for(const auto &kvp: b->variables) referenced_names.insert(kvp.first); + for(const auto &kvp: stage.interface_blocks) + if(kvp.second->name.find(' ')!=string::npos) + for(const auto &kvp2: kvp.second->block_declaration->members.variables) + referenced_names.insert(kvp2.first); /* Inline and rename passes must be interleaved so used variable names are known when inlining the return statement. */ @@ -191,12 +195,6 @@ void InlineContentInjector::visit(VariableReference &var) referenced_names.insert(var.name); } -void InlineContentInjector::visit(InterfaceBlockReference &iface) -{ - if(pass==REFERENCED) - referenced_names.insert(iface.name); -} - void InlineContentInjector::visit(FunctionCall &call) { if(pass==REFERENCED) @@ -449,7 +447,7 @@ void ExpressionInliner::visit(Assignment &assign) if(targets_overlap(i->first, assign.target)) i->second->blocked = true; - expressions.push_back(ExpressionInfo()); + expressions.emplace_back(); ExpressionInfo &info = expressions.back(); info.target = assign.target; // Self-referencing assignments can't be inlined without additional work. @@ -496,7 +494,7 @@ void ExpressionInliner::visit(VariableDeclaration &var) analyze and non-trivial expressions could be expensive to inline. */ if((current_block->parent || (constant && r_trivial)) && var.interface.empty()) { - expressions.push_back(ExpressionInfo()); + expressions.emplace_back(); ExpressionInfo &info = expressions.back(); info.target = &var; /* Assume variables declared in an iteration initialization statement @@ -1231,6 +1229,8 @@ void UnusedTypeRemover::visit(ImageTypeDeclaration &type) { if(type.base_type) unused_nodes.erase(type.base_type); + if(type.base_image) + unused_nodes.erase(type.base_image); unused_nodes.insert(&type); } @@ -1246,11 +1246,6 @@ void UnusedTypeRemover::visit(VariableDeclaration &var) TraversingVisitor::visit(var); } -void UnusedTypeRemover::visit(InterfaceBlock &iface) -{ - unused_nodes.erase(iface.type_declaration); -} - void UnusedTypeRemover::visit(FunctionDeclaration &func) { unused_nodes.erase(func.return_type_declaration); @@ -1313,14 +1308,6 @@ void UnusedVariableRemover::visit(VariableReference &var) referenced(var.declaration, var); } -void UnusedVariableRemover::visit(InterfaceBlockReference &iface) -{ - if(composite_reference) - r_reference.declaration = iface.declaration; - else if(iface.declaration) - referenced(iface.declaration, iface); -} - void UnusedVariableRemover::visit_composite(Expression &expr) { if(!composite_reference) @@ -1420,7 +1407,7 @@ void UnusedVariableRemover::visit(FunctionCall &call) void UnusedVariableRemover::record_assignment(const Assignment::Target &target, Node &node) { - assignments.push_back(AssignmentInfo()); + assignments.emplace_back(); AssignmentInfo &assign_info = assignments.back(); assign_info.node = &node; assign_info.target = target; @@ -1474,7 +1461,8 @@ void UnusedVariableRemover::visit(VariableDeclaration &var) /* Mark variables as output if they're used by the next stage or the graphics API. */ - var_info.output = (var.interface=="out" && (stage->type==Stage::FRAGMENT || var.linked_declaration || !var.name.compare(0, 3, "gl_"))); + bool builtin = (!var.name.compare(0, 3, "gl_") || (var.block_declaration && !var.block_declaration->block_name.compare(0, 3, "gl_"))); + var_info.output = (var.interface=="out" && (stage->type==Stage::FRAGMENT || var.linked_declaration || builtin)); // Linked outputs are automatically referenced. if(var_info.output && var.linked_declaration) @@ -1487,12 +1475,6 @@ void UnusedVariableRemover::visit(VariableDeclaration &var) } } -void UnusedVariableRemover::visit(InterfaceBlock &iface) -{ - VariableInfo &var_info = variables[&iface]; - var_info.output = (iface.interface=="out" && (iface.linked_block || !iface.block_name.compare(0, 3, "gl_"))); -} - void UnusedVariableRemover::merge_variables(const BlockVariableMap &other_vars) { for(const auto &kvp: other_vars)