File indexing completed on 2026-04-09 07:49:01
0001
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <cstdlib>
0005
0006 #include "Ctx.h"
0007
0008 #include <optix.h>
0009 #include <optix_stubs.h>
0010 #include <optix_function_table_definition.h>
0011 #include <cuda_runtime.h>
0012
0013 #include "CUDA_CHECK.h"
0014 #include "OPTIX_CHECK.h"
0015 #include "Properties.h"
0016
0017 #include "ssys.h"
0018 #include "SLOG.hh"
0019
0020 const plog::Severity Ctx::LEVEL = SLOG::EnvLevel("Ctx", "DEBUG") ;
0021
0022 std::vector<std::string> Ctx::LOGLINES = {} ;
0023
0024 std::string Ctx::GetLOG()
0025 {
0026 std::stringstream ss ;
0027 ss << "[Ctx::GetLOG" << std::endl ;
0028 for(int i=0 ; i < int(LOGLINES.size()) ; i++) ss << LOGLINES[i] << std::endl ;
0029 ss << "]Ctx::GetLOG" << std::endl ;
0030 std::string str = ss.str();
0031 return str ;
0032 }
0033
0034
0035 OptixDeviceContext Ctx::context = nullptr ;
0036
0037 void Ctx::log_cb( unsigned int level, const char* tag, const char* message, void* )
0038 {
0039 std::stringstream ss ;
0040 ss << "[" << std::setw(2) << level << "][" << std::setw( 12 ) << tag << "]: " << message ;
0041 std::string line = ss.str() ;
0042 LOGLINES.push_back(line);
0043 LOG(LEVEL) << line ;
0044 }
0045
0046 Ctx::Ctx()
0047 :
0048 props(nullptr)
0049 {
0050
0051 CUDA_CHECK(cudaFree( 0 ) );
0052
0053 CUcontext cuCtx = 0;
0054 OPTIX_CHECK( optixInit() );
0055 OptixDeviceContextOptions options = {};
0056 options.logCallbackFunction = &Ctx::log_cb;
0057 options.logCallbackLevel = 4;
0058
0059
0060 OPTIX_CHECK( optixDeviceContextCreate( cuCtx, &options, &context ) );
0061
0062 props = new Properties ;
0063 }
0064
0065
0066 std::string Ctx::desc() const
0067 {
0068 std::stringstream ss ;
0069 ss
0070 << "Ctx::desc" << std::endl
0071 << props->desc()
0072 ;
0073
0074 std::string str = ss.str();
0075 return str ;
0076 }
0077
0078
0079
0080