Continuation stack size in optixUtilComputeStackSizes()

Hi, I have a question in stack size calculation for continuation callable.
optixUtilComputeStackSizes computes the size for continuation stack as:

*continuationStackSize
    = cssRG + cssCCTree
    + ( std::max( maxTraceDepth, 1u ) - 1 ) * cssCHOrMSPlusCCTree
    + std::min( maxTraceDepth, 1u ) * std::max( cssCHOrMSPlusCCTree, cssIS + cssAH );

For simplicity, assume we have maxTraceDepth = 1, then we get:

*continuationStackSize
    = cssRG + cssCCTree
    + std::max( cssCHOrMSPlusCCTree, cssIS + cssAH );

I don’t understand why cssCCTree appears twice (the first is cssCCTree as-is, the second is in cssCHOrMSPlusCCTree).
Possible call tree I think is the below (if I assume maxCCDepth = 1:

1. RG - CH - CC
2. RG - MS - CC
3. RG - IS/AH
4. RG - CC - CH // trace call from a CC, user cannot call a CC from CH/MS
5. RG - CC - MS // because maxCCDepth = 1 here.
6. RG - CC - IS/AH

Doesn’t optixUtilComputeStackSizes assume that the user manages oneself not to call a CC in the paths 4/5?

Thanks.

There is a specific chapter about calculating the stack size inside the OptiX 7 programming guide.
They are described in increasing order of optimizations.
Please check if this answers your question:
https://raytracing-docs.nvidia.com/optix7/guide/index.html#program_pipeline_creation#pipeline-stack-size

Here’s how I calculate it. (That’s code from before there were helper functions.)
OptiX Stack Sizes

Yes, I know.
It says at the first naive calculation:
Upper bound on continuation stack used by CH or MS programs including the call tree of continuation callables

I want to know how the stack size piled up.
If we assume any CC is not called from RG, can we optimize the calculation as:

*continuationStackSize
    = cssRG /*+ cssCCTree*/ There is no path like RG - CC - MS - CC
    + std::max( cssCHOrMSPlusCCTree, cssIS + cssAH );

?

My confusion comes from that optixUtilComputeStackSizes takes an argument named maxCCDepth but it seems to consider the possibility where it takes call path like RG - CC - MS - CC (maxCCDepth = 1 case).
This path seems CC depth = 2.