@@ -1605,6 +1605,7 @@ ShadingSystemImpl::attribute(string_view name, TypeDesc type, const void* val)
16051605
16061606 lock_guard guard (m_mutex); // Thread safety
16071607 ATTR_SET (" statistics:level" , int , m_statslevel);
1608+ ATTR_SET (" stat:rank_groups" , int , m_stat_rank_groups);
16081609 ATTR_SET (" debug" , int , m_debug);
16091610 ATTR_SET (" lazylayers" , int , m_lazylayers);
16101611 ATTR_SET (" lazyglobals" , int , m_lazyglobals);
@@ -1797,6 +1798,7 @@ ShadingSystemImpl::getattribute(string_view name, TypeDesc type, void* val)
17971798 ATTR_DECODE_STRING (" searchpath:shader" , m_searchpath);
17981799 ATTR_DECODE_STRING (" searchpath:library" , m_library_searchpath);
17991800 ATTR_DECODE (" statistics:level" , int , m_statslevel);
1801+ ATTR_DECODE (" stat:rank_groups" , int , m_stat_rank_groups);
18001802 ATTR_DECODE (" lazylayers" , int , m_lazylayers);
18011803 ATTR_DECODE (" lazyglobals" , int , m_lazyglobals);
18021804 ATTR_DECODE (" lazyunconnected" , int , m_lazyunconnected);
@@ -2168,6 +2170,22 @@ ShadingSystemImpl::getattribute(ShaderGroup* group, string_view name,
21682170 *(int *)val = group->m_exec_repeat ;
21692171 return true ;
21702172 }
2173+ if (name == " stat:compiled_active_layers" && type == TypeInt) {
2174+ *(int *)val = group->stat_active_layers ();
2175+ return true ;
2176+ }
2177+ if (name == " stat:compiled_network_depth" && type == TypeInt) {
2178+ *(int *)val = group->stat_network_depth ();
2179+ return true ;
2180+ }
2181+ if (name == " stat:compiled_texture_ops" && type == TypeInt) {
2182+ *(int *)val = group->stat_texture_ops ();
2183+ return true ;
2184+ }
2185+ if (name == " stat:compiled_noise_ops" && type == TypeInt) {
2186+ *(int *)val = group->stat_noise_ops ();
2187+ return true ;
2188+ }
21712189 if (name == " ptx_compiled_version" && type.basetype == TypeDesc::PTR ) {
21722190 bool exists = !group->m_llvm_ptx_compiled_version .empty ();
21732191 *(std::string*)val = exists ? group->m_llvm_ptx_compiled_version : " " ;
@@ -2714,6 +2732,70 @@ ShadingSystemImpl::getstats(int level) const
27142732 }
27152733 }
27162734
2735+ // Ranked shader groups by compile-time complexity metrics
2736+ if (m_stat_groups_compiled > 0 ) {
2737+ // Collect a snapshot of all still-live compiled (optimized) groups.
2738+ std::vector<ShaderGroupRef> groups;
2739+ {
2740+ spin_lock lock (m_all_shader_groups_mutex);
2741+ for (auto && w : m_all_shader_groups)
2742+ if (ShaderGroupRef g = w.lock ())
2743+ if (g->optimized ())
2744+ groups.push_back (g);
2745+ }
2746+ using StatVal = std::pair<int , ustring>;
2747+ print (out, " Shader compilation stats, post-optimized:\n " );
2748+ auto emit_ranked_groups =
2749+ [&](string_view label, string_view unit,
2750+ std::function<int (const ShaderGroup&)> getter) {
2751+ if (groups.empty ())
2752+ return ;
2753+ // Gather values from all compiled groups for aggregate stats.
2754+ std::vector<int > vals;
2755+ vals.reserve (groups.size ());
2756+ for (auto && g : groups)
2757+ vals.push_back (getter (*g));
2758+ std::sort (vals.begin (), vals.end ());
2759+ int vmin = vals.front ();
2760+ int vmax = vals.back ();
2761+ int vmedian = vals[vals.size () / 2 ];
2762+ print (out, " {}: min={} max={} median={}\n " , label, vmin,
2763+ vmax, vmedian);
2764+ // Ranked list: exclude groups with value 0.
2765+ std::vector<StatVal> ranked;
2766+ for (auto && g : groups) {
2767+ int v = getter (*g);
2768+ if (v > 0 )
2769+ ranked.emplace_back (v, g->name ());
2770+ }
2771+ if (ranked.empty ())
2772+ return ;
2773+ std::sort (ranked.begin (), ranked.end (),
2774+ [](const StatVal& a, const StatVal& b) {
2775+ return a.first != b.first ? a.first > b.first
2776+ : a.second < b.second ;
2777+ });
2778+ if ((int )ranked.size () > m_stat_rank_groups)
2779+ ranked.resize (m_stat_rank_groups);
2780+ print (out, " Top shader groups:\n " );
2781+ for (auto && [v, name] : ranked)
2782+ print (out, " {:>6} {} \" {}\"\n " , v, unit,
2783+ name.size () ? name.c_str () : " <unnamed>" );
2784+ };
2785+ emit_ranked_groups (" Active layers" , " layers" , [](const ShaderGroup& g) {
2786+ return g.stat_active_layers ();
2787+ });
2788+ emit_ranked_groups (" Network depth" , " depth" , [](const ShaderGroup& g) {
2789+ return g.stat_network_depth ();
2790+ });
2791+ emit_ranked_groups (" Texture ops" , " ops" , [](const ShaderGroup& g) {
2792+ return g.stat_texture_ops ();
2793+ });
2794+ emit_ranked_groups (" Noise ops" , " ops" , [](const ShaderGroup& g) {
2795+ return g.stat_noise_ops ();
2796+ });
2797+ }
2798+
27172799 return out.str ();
27182800}
27192801
0 commit comments