rtPayload size fixed? Crashes when changing payload size

I’ve been playing around with some constructive solid geometry recently, and as a result I have had to add a couple of new fields to PerRayData_radiance.

This doesn’t seem to work (crashes, graphical artifacts) unless I remove existing fields though - I have to keep the size of this structure constant for some reason.

This is the existing structure:

struct PerRayData_radiance {
float3 result;
float importance;
int depth;
};

It gets referenced in the shader like so:
rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, );

I was under the impression ray payloads were fully programmable - is there something special I need to do in order to make a large structure work? I’m looking for something like:

struct PerRayData_radiance {
float3 result;
float importance;
int depth;
int inside_sphere;
int inside_box;
};

I’ve checked the forums and the documentation, but neither seem to mention any sort of special size required for this struct - in fact the rtPayload is supposed to be customizable. I can’t find any relevant buffer allocations either, and all the SDK examples use the exactly the same structure with no added fields.

For my purposes, I can get away with using depth as a bitfield - but I would prefer not to.

I’ve had no problem adding an arbitrary number of fields to existing ray payload structures or creating new ray payload structures.

Can you make sure that PerRayData_radiance is defined only once in your project? It seems possible that some of your files might still be referring to an old definition with a different size structure.

Maybe you get some OptiX exceptions (stack overflow comes to mind), did you enable them?
Try raising the OptiX stack size and see if it affects your results.

I actually added an entirely new structure PerRayData_csg_radiance, and set it as a ray payload - double definitions shouldn’t be an issue.

I can up the stack size, but presumably this should have no effect since the same number of calls are being performed either way? I’ll try it though.

I should also mention that for some reason, this issue actually causes an OS crash (not just an Optix one). I can easily reproduce the effect just by trying to set a single field in the structure - a one line difference causes the crash (I can define an arbitrary number of fields, but changing values is what causes issues). Sometimes when it doesn’t crash, I get Optix timeouts.

I was having the same problem, when the ray payload contained more than a certain number of fields I would get an unexpected behavior and get a lot of exceptions. I don’t remember exactly the size of fields that I was using which was causing the issues, but as you said, more fields can be added and it won’t cause problems until you start modifying the values of those fields. What I ended up doing was to perform the ray trace (rtTrace) more than once with the same origin and directions but with different ray types containing different payloads. I guess there is a limit on the size of the ray payload that Optix can handle.

By the way, the size of the structures of one of the payloads that I am using is larger than the one that you are trying to use and I don’t have any problems with it.
This is how my struct looks like:

struct RayData
{
    uint type;
    optix::float3 hitPoint;
    int geometryId;
    float importance;
    int depth;
    optix::uint2 indexId;
};

Some of my ray payloads are 76 bytes, and I have not had a problem. What are you using in terms of OS, bitness, CUDA and OptiX versions, GPUs, etc?

Would one of you retry your code that shows the bug with 3.7.0 beta 2? If it still fails, could you make us an OAC trace and send it to OptiX-Help@nvidia.com for us to fix?

This is my workable example: from 3.5.1. to 3.7.0 beta 2

struct PerRayData_radiance
  {
  short int    from_reflected;
  short int    depth, type;
  short int    break_depth;
  short int    nMed1, nMed2;
  float3 m;
  float3 m_from;
  float3 dir;
  float3 u, v, q, g, x, y;
  Matrix2x2 jj, Im_jj;
  };

Probably another reason brings an error. Every time I thought that rtPayload worked wrong I was wrong.
My platforms:
Notebook: Intel® Core i7-3630QM @ 2.40GHz, Win 8.1, x64, VS2010, CUDA 6.0/6.5, OptiX 3.6.2./3.7.II, GeForce GT 650M.
Desktop: Intel® Core 2 Quad @ 2.50GHz, Win 8.1, x64, VS2010, CUDA 6.0/6.5, OptiX 3.6.2./3.7.II, GeForce GTX 560 Ti.

Happy New Year!
sudak