Stack size calculation for ProgramGroups (RG, EX, MS, HG) with optixUtilAccumulateStackSizes

Hi, I am new to Optix and currently using OptiX 9 for ray tracing development, starting with simple case. Below is the code lines to calculate the stack sizes for the ProgramGroups.

    // Stack size calculation
    OptixStackSizes stack_sizes = {};
    //for (auto& prog_group : _programGroups) {
    //    OPTIX_CHECK(optixUtilAccumulateStackSizes(
    //        prog_group, &stack_sizes, _pipeline));
    //}
    OPTIX_CHECK(optixUtilAccumulateStackSizes(
        pg_rg_firstIllumination,
        &stack_sizes,
        _pipeline
    ));
    OPTIX_CHECK(optixUtilAccumulateStackSizes(
        pg_exception,
        &stack_sizes,
        _pipeline
    ));
    OPTIX_CHECK(optixUtilAccumulateStackSizes(
        pg_miss_shadow,
        &stack_sizes,
        _pipeline
    ));
    OPTIX_CHECK(optixUtilAccumulateStackSizes(
        pg_hitgroup_default,
        &stack_sizes,
        _pipeline
    ));

When I debug, the stack size for RG has value and the rest are zeros as per below.

When I call optixUtilComputeStackSizes with those values of stack_size, I get as below.

image

Is there anything wrong since I also have EX, MS and HG programs but only counted for RG? If so, please assist how to correct it.

Is it a reason my code, not reaching to miss or anyhit or closesthit even though the condition is met (I think), when optixTrace is called from raygen? That is my main issue encountered now.

Thank you. Appreciated for your kind response and advice.

Hi @zawzawoo.ko, welcome!

It’s normal to have zeroes in your stack sizes sometimes. As long as you’ve accounted for all the program groups in your pipeline, what you’re doing so far looks correct to me.

If you have programs that are not getting called, that sounds potentially like an issue with the Shader Binding Table. If you have multiple entries in your SBT, it might be worth simplifying down to 1 entry for debugging/testing and make sure that works before adding multiple ray types and multiple materials, etc.


David.

Hi David,

Thank you for your kind reply. Let me check the SBT records and update my issue later.

Hi David,

I simplified the SBT to one entry for RG, MS, HG (anyhit & closesthit). The ray checking is called from raygen as below.

setPayloadPtr(&ray_prd, p0, p1);

optixTrace(params.traversable,
    triCtr, dir,
    tmin, tmax, 0.f, 255 /*ray.visibilityMask*/, flags,
    params.sbtOffset, params.sbtStride, params.shadowMissIndex,
    p0, p1);

where,

const unsigned int flags = OPTIX_RAY_FLAG_TERMINATE_ON_FIRST_HIT;    
params.sbtOffset = 0;      
params.sbtStride = 1;
params.shadowMissIndex = 0;

It seems like the optixTrace does not reach either MS or HG since I put printf in miss anyhit closesthit programs and nothing print to screen.

Then, applying different angles of the incident ray, then I get the following error.

Could you please advise what possible mistake I made?

Thanks again.