Exploring OptiX SDK path_tracer - Tex2D causes crash at start up


I’m exploring OptiX 3.9.0’s SDK with CUDA 7.5. I opened the SDK sample called ‘path_tracer’ and attempted to add textures to it. However, it crashes at start up after adding a few lines of code loading and sampling a texture.

The debug log reads some exceptions:
… [rethrow] at memory location …
… optix::shared::ValidationError at memory location …
… optix::Exception at memory location …

As far as I understand I have caused a memory leak, but I would not know how.

For a minimal working example I added four lines of code, for which I used the sample ‘cook’ as an example.
Two lines are added to path_tracer.cpp. To the top (line 36):

#include <ImageLoader.h>

And just after setting the floor material in line 303:

gis.back()["floor_texture"]->setTextureSampler(loadTexture(m_context, std::string(sutilSamplesDir()) + "/cook/data/cloth.ppm", make_float3(1, 1, 1)));

To path_tracer.cu I added a line to the variable declarations (line 7):

rtTextureSampler<float4, 2> floor_texture;

And a line sampling the texture to the top of the diffuse() material program (line 174):

tex2D(floor_texture, 0.0, 0.0);

I am curious to know what my mistake is. Thanks in advance to anyone trying to help me find it.

My first guess would be that you’ve attached the texture only to the floor GeometryInstance but changed the closest hit program implementation which is used for all objects. Means only the floor would be able to resolve that texture sampler variable scope, all other GeometryInstances would have an invalid sampler access.

If you declare the “floor_texture” sampler variable at the OptiX context scope it’ll be accessible everywhere.
I would recommend to move that variable from the GeometryInstance to the Material instead. Then you could build a scene with different materials for the floor and the other objects later.
See the OptiX Programming Guide Chapter 2.3 and 4.1.5 for how the variable scopes are resolved.

If you’re using OptiX 3.9.0 right now, it’s worth updating to OptiX 3.9.1.

Your first guess was completely correct. Thank you for the explanation and advice.

Also I have updated to OptiX 3.9.1. May I ask why it is that you didn’t advice 4.0.0?
I tested that too, but the precompiled samples wouldn’t start, reporting that no supported graphics card was found.

Because I could be sure that OptiX 3.9.1 would work if you’re running 3.9.0 successfully, and it’s faster and more robust than 3.9.0.
I assume you have a Fermi GPU architecture board if 4.0.0 doesn’t work, because that architecture isn’t supported in 4.0 anymore.