MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenShadingLanguage / run

Method run

src/liboslexec/runtimeoptimize.cpp:3014–3268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3012
3013
3014void
3015RuntimeOptimizer::run ()
3016{
3017 Timer rop_timer;
3018 int nlayers = (int) group().nlayers ();
3019 if (debug())
3020 shadingcontext()->info ("About to optimize shader group %s (%d layers):",
3021 group().name(), nlayers);
3022 if (debug())
3023 std::cout << "About to optimize shader group " << group().name() << "\n";
3024
3025 for (int layer = 0; layer < nlayers; ++layer) {
3026 set_inst (layer);
3027 // These need to happen before merge_instances
3028 inst()->copy_code_from_master (group());
3029 mark_outgoing_connections();
3030 }
3031
3032 // Inventory the network and print pre-optimized debug info
3033 size_t old_nsyms = 0, old_nops = 0;
3034 for (int layer = 0; layer < nlayers; ++layer) {
3035 set_inst (layer);
3036 if (debug() /* && optimize() >= 1*/) {
3037 find_basic_blocks ();
3038 std::cout.flush ();
3039 std::cout << "Before optimizing layer " << layer << " \""
3040 << inst()->layername() << "\" (ID " << inst()->id() << ") :\n";
3041 printinst (std::cout);
3042 std::cout << "\n--------------------------------\n" << std::endl;
3043 }
3044 old_nsyms += inst()->symbols().size();
3045 old_nops += inst()->ops().size();
3046 }
3047
3048 if (shadingsys().m_opt_merge_instances == 1)
3049 shadingsys().merge_instances (group());
3050
3051 m_params_holding_globals.resize (nlayers);
3052
3053 // Optimize each layer, from first to last
3054 for (int layer = 0; layer < nlayers; ++layer) {
3055 set_inst (layer);
3056 if (inst()->unused())
3057 continue;
3058 // N.B. we need to resolve isconnected() calls before the instance
3059 // is otherwise optimized, or else isconnected() may not reflect
3060 // the original connectivity after substitutions are made.
3061 resolve_isconnected ();
3062 optimize_instance ();
3063 }
3064
3065 // Optimize each layer again, from last to first (because some
3066 // optimizations are only apparent when the subsequent shaders have
3067 // been simplified).
3068 for (int layer = nlayers-1; layer >= 0; --layer) {
3069 set_inst (layer);
3070 if (! inst()->unused())
3071 optimize_instance ();

Callers

nothing calls this directly

Calls 15

groupFunction · 0.85
debugFunction · 0.85
AttributeNeededClass · 0.85
nlayersMethod · 0.80
infoMethod · 0.80
copy_code_from_masterMethod · 0.80
flushMethod · 0.80
layernameMethod · 0.80
unusedMethod · 0.80
has_derivsMethod · 0.80
is_closure_basedMethod · 0.80
is_floatbasedMethod · 0.80

Tested by

no test coverage detected