How to rtPrint with Optix Context Wrapper

367 Views Asked by At

This question is meant to help beginners of NVIDIA OptiX (much like myself)


What's Happening

When working with the OptiX compiled examples (delivered with the installation of OptiX), I am trying to print to the console from one of the computer kernels and I keep getting these errors:

error: cannot convert ‘optix::Context {aka optix::Handle<optix::ContextObj>}’ to ‘RTcontext’ for argument ‘1’ to ‘RTresult rtContextSetPrintEnabled(RTcontext, int)’
error: cannot convert ‘optix::Context {aka optix::Handle<optix::ContextObj>}’ to ‘RTcontext’ for argument ‘1’ to ‘RTresult rtContextSetPrintBufferSize(RTcontext, RTsize)’

Attempted Solution

Inside the createContext() function, under where the context is created, I added lines of code to turn on debug printing. The lines of code I added are:

rtContextSetPrintEnabled(context, 1);
rtContextSetPrintBufferSize(context, 4096);

These are the two lines that produce the above error. I added these lines of code after the instantiation of the context object, provided by the code below - from the original nvidia example:

context = Context::create();
context->setRayTypeCount( 2 );
context->setEntryPointCount( 1 );
context->setStackSize( 2800 );

So, complete code that breaks looks like this:

// Set up context
context = Context::create();
context->setRayTypeCount( 2 );
context->setEntryPointCount( 1 );
context->setStackSize( 2800 );

// Setup debug printing
rtContextSetPrintEnabled(context, 1);
rtContextSetPrintBufferSize(context, 4096);

Some background information

I am trying to modify the optixWhitted project, working on a CentOS computer using the NSight edition of Eclipse.


Question

While using the optixWhitted code, and trying to maintain the code style and object usage already laid out... How do I solve this?

2

There are 2 best solutions below

0
On BEST ANSWER

After looking further at the error and the original instantiation of the context, it turns out that the optixWhitted example uses a wrapper class to handle the rtContext object. The two objects are different classes and in doing some digging around, I discovered that NVIDIA has included the ContextObj class as a convenience wrapper for the underlying rtContext. This ContextObj class has very similar functions to the rtContext and functions outlined in Chapter 3 of the OptiX 5.1 Programming Guide.

Looking through the ContextObj class, you will find analogous functions for setting the rtPrintf settings: OptiX ContextObj Wrapper Class.

Specifically you'll find these functions:

  • setPrintEnabled(bool)
  • setPrintBufferSize(uint)

Final Working Code

This is the final working code, that uses the ContextObj wrapper class already present and in use inside the optixWhitted tutorial.

// Set up context
context = Context::create();
context->setRayTypeCount( 2 );
context->setEntryPointCount( 1 );
context->setStackSize( 2800 );

// Set Output Debugging via rtPrintf
context->setPrintEnabled(1);
context->setPrintBufferSize(4096);
0
On

There are two basic ways to use the OptiX API. In your question, you instantiate your context using the OptiXpp api, hence the pointer to access methods and data. In this case, context is of type optix::Handle<optix::ContextObj> which is not the same as the type needed by the rt functions, in this case RTcontext *. You could have also used the get() method on the handle and mixed the APIs, but if you would have created your context using the other API, then things should have worked.

RTcontext context;
rtContextCreate( &context );
rtContextSetPrintEnabled(context, 1);
rtContextSetPrintBufferSize(context, 4096);

There are other benefits to using the OptiXpp API such as the bracket notation for variables. In short, to avoid confusion pick one and stick with it.