X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.cpp;h=414cf38754191a85d8b6643811c3dc5c4764f4b4;hb=f526938b407e061c7424adedc34af4d1ff687f90;hp=f938314814ea9cd4211279d5e94ff817c2a92fcc;hpb=cb8ee1f5ea24a5f7b561fc88d4ff5af3ae364038;p=libs%2Fgl.git diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index f9383148..414cf387 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -232,6 +232,11 @@ void FunctionInliner::visit(MemberAccess &memacc) visit_and_inline(memacc.left); } +void FunctionInliner::visit(Swizzle &swizzle) +{ + visit_and_inline(swizzle.left); +} + void FunctionInliner::visit(FunctionCall &call) { for(NodeArray::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i) @@ -439,6 +444,13 @@ void ExpressionInliner::visit(MemberAccess &memacc) r_trivial = false; } +void ExpressionInliner::visit(Swizzle &swizzle) +{ + visit_and_record(swizzle.left, swizzle.oper, false); + r_oper = swizzle.oper; + r_trivial = false; +} + void ExpressionInliner::visit(UnaryExpression &unary) { SetFlag set_target(mutating, mutating || unary.oper->token[1]=='+' || unary.oper->token[1]=='-'); @@ -668,6 +680,11 @@ void UnusedTypeRemover::visit(VariableDeclaration &var) unused_nodes.erase(var.type_declaration); } +void UnusedTypeRemover::visit(InterfaceBlock &iface) +{ + unused_nodes.erase(iface.type_declaration); +} + void UnusedTypeRemover::visit(FunctionDeclaration &func) { unused_nodes.erase(func.return_type_declaration); @@ -690,9 +707,19 @@ bool UnusedVariableRemover::apply(Stage &stage) BlockVariableMap &global_variables = variables.back(); for(BlockVariableMap::iterator i=global_variables.begin(); i!=global_variables.end(); ++i) { + string interface = i->first->interface; + bool linked = i->first->linked_declaration; + map::iterator j = aggregates.find(i->first); + if(j!=aggregates.end()) + if(InterfaceBlock *iface = dynamic_cast(j->second)) + { + interface = iface->interface; + linked = iface->linked_block; + } + /* Don't remove output variables which are used by the next stage or the graphics API. */ - if(i->first->interface=="out" && (stage.type==Stage::FRAGMENT || i->first->linked_declaration || !i->first->name.compare(0, 3, "gl_"))) + if(interface=="out" && (stage.type==Stage::FRAGMENT || linked || !i->first->name.compare(0, 3, "gl_"))) continue; // Mark other unreferenced global variables as unused. @@ -737,6 +764,13 @@ void UnusedVariableRemover::visit(MemberAccess &memacc) unused_nodes.erase(memacc.declaration); } +void UnusedVariableRemover::visit(Swizzle &swizzle) +{ + if(assignment_target) + r_assign_to_subfield = true; + TraversingVisitor::visit(swizzle); +} + void UnusedVariableRemover::visit(UnaryExpression &unary) { TraversingVisitor::visit(unary); @@ -833,7 +867,7 @@ void UnusedVariableRemover::visit(InterfaceBlock &iface) { SetForScope set(aggregate, &iface); unused_nodes.insert(&iface); - TraversingVisitor::visit(iface); + iface.struct_declaration->members.visit(*this); } void UnusedVariableRemover::visit(FunctionDeclaration &func)