Some grammar questions


A very quick and simple problem but bothers me for a while.

So I am learning the sample code of the optix, which is cool, then I found this:

When the function is creating the context.

void createContext( bool use_pbo )
// Set up context
context = Context::create();

context->setRayTypeCount( 1 );
context->setEntryPointCount( 1 );
context->setStackSize( 800 );

// Note: high max depth for reflection and refraction through glass
[b]context["max_depth"]->setInt( 10 );
context["cutoff_color"]->setFloat( 0.2f, 0.2f, 0.2f );
context["frame"]->setUint( 0u );
context["scene_epsilon"]->setFloat( 1.e-3f );[/b]

Buffer buffer = sutil::createOutputBuffer( context, RT_FORMAT_UNSIGNED_BYTE4, WIDTH, HEIGHT, use_pbo );
context["output_buffer"]->set( buffer );

// Accumulation buffer
Buffer accum_buffer = context->createBuffer( RT_BUFFER_INPUT_OUTPUT | RT_BUFFER_GPU_LOCAL,
context["accum_buffer"]->set( accum_buffer );

// Ray generation program
std::string ptx_path( ptxPath( "" ) );
Program ray_gen_program = context->createProgramFromPTXFile( ptx_path, "pinhole_camera" );
// Specifies the ray generation program for a given context entry point.
[b]context->setRayGenerationProgram( 0, ray_gen_program );[/b]



so first question is the context set the value of max_depth or frame or cutoff_color at the very beginning,
i know these parameters are decalred in the ptx file or cu file as a “shader” in my mind.

But it was after that the program is linked to the context.

So how is the optix context know the parameters before the program is been set to it?

Do I miss something here?

Another question is very simple, so is this context[“XXXX”] usage a optix grammar or a new C++ feature,

I am sorry I am new at this.

Thanks a lot.

The syntax context[“XXXX”] is just using operator overloading to call context functions. If you want, you can see the declaration of this operator in the optixpp_namespace.h header file.

For the variables, when you use the bracket operator, the variable is created at that time. When you attach a program later, the variable in the .cu file are bound to the variables in the context, so it’s okay to set values on the context before you attach your programs.

Does that make sense?


Perfect, this totally make sense to me now!

Thanks a lot!