Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:42

0001 #pragma once
0002 /**
0003 SOPTIX_Context.h : OptixDeviceContext + SOPTIX_Properties
0004 ==========================================================
0005 
0006 **/
0007 
0008 #include <optix.h>
0009 #include <optix_function_table_definition.h>
0010 #include <optix_stack_size.h>
0011 #include <optix_stubs.h>
0012 
0013 #define _xstr(s) _str(s)
0014 #define _str(s) #s
0015 
0016 #include "CUDA_CHECK.h"
0017 #include "OPTIX_CHECK.h"
0018 
0019 #include "SOPTIX_Properties.h"
0020 #include "SOPTIX_Options.h"
0021 
0022 
0023 struct SOPTIX_Context
0024 {  
0025     static int Initialize(); 
0026     static void LogCB( unsigned int level, const char* tag, const char* message, void* /*cbdata */) ;     
0027 
0028     int irc ; 
0029     const char* VERSION ; 
0030     OptixDeviceContext context ; 
0031     SOPTIX_Properties* props ; 
0032 
0033     std::string desc() const ;
0034 
0035     SOPTIX_Context(); 
0036     void init(); 
0037 };
0038 
0039 
0040 inline int SOPTIX_Context::Initialize()
0041 {
0042     if(SOPTIX_Options::Level()>0) std::cout << "-SOPTIX_Context::Initialize\n" ; 
0043     return 0 ;     
0044 }
0045 
0046 inline void SOPTIX_Context::LogCB( unsigned int level, const char* tag, const char* message, void* /*cbdata */)  // static 
0047 {   
0048     std::stringstream ss ; 
0049     ss << "[" << std::setw(2) << level << "][" << std::setw( 12 ) << tag << "]: " << message << std::endl ;
0050     std::string line = ss.str() ;
0051     std::cout << line ;
0052 }
0053 
0054 inline std::string SOPTIX_Context::desc() const
0055 {
0056     std::stringstream ss ; 
0057     ss << "[ SOPTIX_Context::desc \n" ; 
0058     ss << " OPTIX_VERSION " << OPTIX_VERSION << "\n" ;
0059     ss << props->desc() ; 
0060     ss << "] SOPTIX_Context::desc \n" ; 
0061     std::string str = ss.str(); 
0062     return str ; 
0063 }
0064 
0065 inline SOPTIX_Context::SOPTIX_Context()
0066     :
0067     irc(Initialize()),
0068     VERSION(_xstr(OPTIX_VERSION)),
0069     context(nullptr),
0070     props(nullptr)
0071 {
0072     init();
0073 }
0074 
0075 /**
0076 SOPTIX_Context::init
0077 ---------------------
0078 
0079 Initialize CUDA and create OptiX context
0080 
0081 **/
0082 
0083 inline void SOPTIX_Context::init()
0084 {
0085     if(SOPTIX_Options::Level()>0) std::cout << "[SOPTIX_Context::init\n" ; 
0086     CUDA_CHECK(cudaFree( 0 ) );
0087 
0088     OPTIX_CHECK( optixInit() );
0089 
0090     OptixDeviceContextOptions options = {};
0091     options.logCallbackFunction       = &SOPTIX_Context::LogCB ;
0092     options.logCallbackLevel          = 4;
0093     options.validationMode = OPTIX_DEVICE_CONTEXT_VALIDATION_MODE_ALL ; 
0094 
0095     CUcontext cuCtx = 0;  // zero means take the current context
0096 
0097     OPTIX_CHECK( optixDeviceContextCreate( cuCtx, &options, &context ) );
0098 
0099     props = new SOPTIX_Properties(context); 
0100     if(SOPTIX_Options::Level()>0) std::cout << "]SOPTIX_Context::init\n" ; 
0101 }
0102 
0103 
0104 
0105