Skip to content

Commit 76972af

Browse files
committed
feat: add more shader group diagnostics to compile_report
When compile_report >= 1, report three new post-optimization stats for the shader group: - Number of active (non-unused) layers - Maximum connection depth of the shader network (node count along the longest layer-to-layer chain, so a single unconnected node = 1 and a chain A->B->C = 3) - Number of texture ops (texture, environment, gettextureinfo, texture3d) Coded via pair programming with Claude Code, using the Claue Sonnet 4.6 model. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 344fded commit 76972af

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/liboslexec/runtimeoptimize.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3278,11 +3278,14 @@ RuntimeOptimizer::run()
32783278
m_userdata_needed.clear();
32793279
m_attributes_needed.clear();
32803280
bool does_nothing = true;
3281+
int active_layers = 0;
3282+
int n_texture_ops = 0;
32813283
std::vector<uint8_t> interactive_data;
32823284
for (int layer = 0; layer < nlayers; ++layer) {
32833285
set_inst(layer);
32843286
if (inst()->unused())
32853287
continue; // no need to print or gather stats for unused layers
3288+
++active_layers;
32863289
FOREACH_SYM(Symbol & s, inst())
32873290
{
32883291
// set the layer numbers
@@ -3355,6 +3358,7 @@ RuntimeOptimizer::run()
33553358
}
33563359
}
33573360
if (opd->flags & OpDescriptor::Tex) {
3361+
++n_texture_ops;
33583362
// for all the texture ops, arg 1 is the texture name
33593363
Symbol* sym = opargsym(op, 1);
33603364
OSL_DASSERT(sym && sym->typespec().is_string());
@@ -3445,6 +3449,23 @@ RuntimeOptimizer::run()
34453449
group().does_nothing(does_nothing);
34463450
group().setup_interactive_arena(interactive_data);
34473451

3452+
// Compute the maximum depth of the shader network: the length of the
3453+
// longest chain of layer-to-layer connections. Layers are already in
3454+
// topological order, so a single forward pass suffices.
3455+
std::vector<int> layer_depth(nlayers, 0);
3456+
int max_network_depth = 0;
3457+
for (int layer = 0; layer < nlayers; ++layer) {
3458+
if (group()[layer]->unused())
3459+
continue;
3460+
layer_depth[layer] = 1;
3461+
for (auto&& c : group()[layer]->connections()) {
3462+
if (!group()[c.srclayer]->unused())
3463+
layer_depth[layer] = std::max(layer_depth[layer],
3464+
layer_depth[c.srclayer] + 1);
3465+
}
3466+
max_network_depth = std::max(max_network_depth, layer_depth[layer]);
3467+
}
3468+
34483469
m_stat_specialization_time = rop_timer();
34493470
{
34503471
// adjust memory stats
@@ -3468,26 +3489,30 @@ RuntimeOptimizer::run()
34683489
new_nops, old_nops,
34693490
100.0 * double((long long)new_nops - (long long)old_nops)
34703491
/ double(old_nops));
3492+
shadingcontext()->infofmt(" Group active layers: {}", active_layers);
3493+
shadingcontext()->infofmt(" Group network connection depth: {}",
3494+
max_network_depth);
3495+
shadingcontext()->infofmt(" Group texture ops: {}", n_texture_ops);
34713496
}
34723497
if (shadingsys().m_compile_report > 1) {
34733498
if (does_nothing)
3474-
shadingcontext()->infofmt("Group does nothing");
3499+
shadingcontext()->infofmt(" Group does nothing");
34753500
if (m_textures_needed.size()) {
3476-
shadingcontext()->infofmt("Group needs textures:");
3501+
shadingcontext()->infofmt(" Group needs textures:");
34773502
for (auto&& f : m_textures_needed)
34783503
shadingcontext()->infofmt(" {}", f);
34793504
if (m_unknown_textures_needed)
34803505
shadingcontext()->infofmt(
34813506
" Also may construct texture names on the fly.");
34823507
}
34833508
if (m_userdata_needed.size()) {
3484-
shadingcontext()->infofmt("Group potentially needs userdata:");
3509+
shadingcontext()->infofmt(" Group potentially needs userdata:");
34853510
for (auto&& f : m_userdata_needed)
34863511
shadingcontext()->infofmt(" {} {} {}", f.name, f.type,
34873512
f.derivs ? "(derivs)" : "");
34883513
}
34893514
if (m_attributes_needed.size()) {
3490-
shadingcontext()->infofmt("Group needs attributes:");
3515+
shadingcontext()->infofmt(" Group needs attributes:");
34913516
for (auto&& f : m_attributes_needed)
34923517
shadingcontext()->infofmt(" {} {} {}", f.name, f.scope,
34933518
f.type);

0 commit comments

Comments
 (0)