Type mismatch of light buffer in context validation

Is there a new restriction to the size of light buffers in OptiX 4.0?

My light buffer hasn’t changed between 3.9.1 and 4.0 and now I can’t use my light buffer because it has to be 32 byte element size instead of my 68 byte large elements.

OptiX Error: 'Type mismatch (Details: Function "RTresult _rtContextValidate(RTcontext)" caught exception: Variable "lights" assigned type Buffer(1d, 68 byte element).  Should be Buffer(1d, 32 byte element)., file:/root/sw/wsapps/raytracing/rtsdk/rel4.0/src/Context/ValidationManager.cpp, line: 75)'

It looks like 4.0 is catching a mismatch error that 3.9 did not. It appears that on the host side you are creating a buffer with 68byte elements on the host side and your cuda code is expecting element size to be 32.

Is this the case?

Yes, it expects now 32 byte element size. Do you have any idea how to change the expected value or is it a fix value in the optix implementation?

EDIT: I tested now, whether one can use another context variable as light source, but it seems that the context only accepts the variable “lights” as light source and it has to be at most 32 byte large. Furthermore the context variable “lights” has defined areas where the postion and color of a light source are defined. If I replace the light color with a direction, it still changes the color of the light instead of the direction. So I will have to use other context variables to include a direction for a spotlight.

Not sure I follow. There is not a fixed 32-byte limit on buffer entries (or at least, there shouldn’t be). You specify the element size for user data at the time you create the buffer on the host side:

// host code
Buffer buffer = context->createBuffer( RT_BUFFER_INPUT );
buffer->setFormat( RT_FORMAT_USER );
buffer->setElementSize( sizeof(LightType) );  // (1) size here should match device program
...
context[ "lights" ]->set( buffer );
// device code
...
rtBuffer<LightType> lights;  // (2) LightType here should match host side.  
...

The OptiX validation error says that the two lines commented (1) and (2) do not agree on the size of LightType (or whatever the type is called in your program). You usually ensure the definitions match by including the same header defining LightType into both host and device code.

Is it possible this is what is going on? If you still think there’s a bug, could you please post a simple example or send it to optix-help?

Bumped into a similar issue today and solved it. To anyone having a similar issue:

OptiXMesh (in OptiX 4) defaults to the sutil Phong(.cu) material, which uses a “lights” variable of type BasicLight, which is 32 bytes in size.

So if you’re sure that your lights buffer uses the same header file both on the host and device side but you still get this error, make sure to check if you’ve correctly passed your closest hit program to your mesh.

Program closest_hit_program = context->createProgramFromPTXFile( your_ptx_path, "your_closest_hit_program" );
OptiXMesh mesh;
mesh.closest_hit = closest_hit_program;

Think it would be great for debugging if OptiX would report a mismatch in type and not only in byte size. (Don’t know how easy that would be technically however.)