Unfortunately I ran into another problem. When I try to built my c-module, which runs my optix code from a static library, it can’t find sutil functions. I always get the error:
/home/user/cuda-workspace/c-Modul/lib/libmyoptix.a(foo.o): In function MyOptiXClass::createContext()': /home/user/cuda-workspace/Optix-Project/Debug/../src/optix.cpp:91: undefined reference to
sutil::createOutputBuffer(optix::Handleoptix::ContextObj, RTformat, unsigned int, unsigned int, bool)’
This error message includes all functions related to sutil. I already tried to use namespace sutil explicit but this doesn’t help. I checked the linker to the libraries and the sutil library can be found.
What can I do to get the sutil functions found?
Is it right, that my c-code can actually know what c++ code is missing?
EDIT: I now solved this problem with linking to sutil_sdk instead of sutil. But my program now gets always terminated a the point context->setRayTypeCount() with an segmentation fault.
This is how my c-function looks like, for creating the optix scene:
void* createScene( double* inputArray, double* outputArray, int argc, char** argv ){
OptixScene* scene = new OptixScene();
scene->routeInput(inputArray);
scene->routeOutput(outputArray);
scene->createContext(); // in this function it gets terminated!
scene->loadMeshes();
scene->setupCamera();
scene->setupLights();
scene->validateContext();
std::thread display_thread(&OptixScene::displayScene, scene, argc, argv);
display_thread.detach();
return (void *)sensor;
}
createContext():
void OptixScene::createContext()
{
// Set up context
my_context -> create();
my_context -> setRayTypeCount( 2 ); // terminates here!
my_context -> setEntryPointCount( 1 );
my_context -> setStackSize( 4096 );
my_context[ "radiance_ray_type" ] ->setUint ( 0u );
my_context[ "shadow_ray_type" ] ->setUint ( 1u );
my_context[ "scene_epsilon" ] ->setFloat( 1.e-4f );
my_context[ "max_depth" ] ->setInt ( 2 );
my_context[ "importance_cutoff" ] ->setFloat( 0.1f );
my_context[ "ambient_light_color" ]->setFloat( 1.0f, 1.0f, 1.0f );
// Output buffer
Buffer buffer = sutil::createOutputBuffer( my_context, RT_FORMAT_UNSIGNED_BYTE4, m_width, m_height, m_use_pbo );
my_context["output_buffer"]->set( buffer );
m_obj_id_buffer = my_context->createBuffer(RT_BUFFER_OUTPUT);
m_obj_id_buffer -> setFormat(RT_FORMAT_USER);
m_obj_id_buffer -> setElementSize(sizeof(float));
m_obj_id_buffer -> setSize(m_width, m_height);
my_context["Obj_ID_Buffer"] -> set(m_obj_id_buffer);
// Ray generation program
Program ray_gen_program = my_context->createProgramFromPTXFile( m_ptxPath + "scene.ptx", "pinhole_camera" );
my_context->setRayGenerationProgram( 0, ray_gen_program );
// Exception program
Program exception_program = my_context->createProgramFromPTXFile( m_ptxPath + "scene.ptx", "exception" );
my_context->setExceptionProgram( 0, exception_program );
my_context[ "bad_color" ]->setFloat( 1.0f, 0.0f, 1.0f );
// Miss program
Program miss_program = my_context->createProgramFromPTXFile( m_ptxPath + "scene.ptx", "miss" );
my_context->setMissProgram( 0, miss_program );
my_context[ "bg_color" ]->setFloat( 0.0f, 0.0f, 0.0f );
#ifdef USE_DEBUG_EXCEPTIONS
// Enable printing (for debugging only!)
my_context->setPrintEnabled( true );
my_context->setExceptionEnabled(RT_EXCEPTION_ALL, true);
my_context->setPrintBufferSize( 2048 );
#endif
}