Attributes on g_optixFunctionTable

Hi,

Context:
I am working on a project where I have a “core” library compiled as a shared object (.so/.dll), and multiple executables and libraries that link against that core library.
I would like to define the g_optixFunctionTable in the core library, which is also responsible for creating the OptiX device context, and access the OptiX API in the executables and other libraries as well.
I would prefer to avoid calling optixInit() everywhere and having possibly rendundant includes of optix_function_table_definition.h, just to be sure that g_optixFunctionTable exists and is initialized.

Question:
Can we get a way to specify attributes on the g_optixFunctionTable declaration in optix_stubs.h via some macro defines?
This way I can declare this variable to be exported by my core library and have it visible in my other executables and libraries.

// optix_stubs.h
// ...
// Simulate old/current behaviour if OPTIX_STUBS_API is not defined
#ifndef OPTIX_STUBS_API
#define OPTIX_STUBS_API
#endif
// The function table needs to be defined in exactly one translation unit. This can be
// achieved by including optix_function_table_definition.h in that translation unit.
OPTIX_STUBS_API extern OptixFunctionTable g_optixFunctionTable;
// ...

Regards,
Tom

That optix_stubs.h header just loads the OptiX entry point functions and makes them available in the global namespace via wrappers. If you’d like to initialize and export the OptiX 7 entry point functions in a different way, you can do that. There is no need to use the optix_stubs.h inside your own applications.

The only complicated part in that is just how to locate the proper Windows display driver component with the OptiX entry point functions, means the code which is searching the registry to find the nvoptix.dll.
Everything else is your choice how you want to expose the OptixFunctionTable entry points.
Means you could just export the necessary wrapper functions from your core DLL which holds the OptixFunctionTable.

I’m not using the optix_stubs.h in my OptiX 7 examples but handle an OptixFunctionTable per active device:
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/nvlink_shared/src/Device.cpp#L513

Thanks for the quick response!
I guess not relying on the optix_stubs.h at all and doing the work in my code is also a viable solution.

I just thought it might be useful to have the option to specify attributes for the function table since it would reduce the code that I have to write in my applications while only adding very little “overhead” to the provided optix_stubs.h.