File indexing completed on 2026-04-09 07:49:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "ssys.h"
0027 #include "spath.h"
0028 #include "scuda.h"
0029 #include "sppm.h"
0030
0031 #include "SGLM.h"
0032 #include "SScene.h"
0033
0034 #include "SOPTIX_Context.h"
0035 #include "SOPTIX_Desc.h"
0036 #include "SOPTIX_MeshGroup.h"
0037 #include "SOPTIX_Scene.h"
0038 #include "SOPTIX_Module.h"
0039 #include "SOPTIX_Pipeline.h"
0040 #include "SOPTIX_SBT.h"
0041 #include "SOPTIX_Params.h"
0042
0043 int main()
0044 {
0045 bool dump = false ;
0046
0047
0048 SScene* _scn = SScene::Load("$SCENE_FOLD") ;
0049 if(dump) std::cout << _scn->desc() ;
0050
0051 int FRAME = ssys::getenvint("FRAME", -1) ;
0052 std::cout << "FRAME=" << FRAME << " ~/o/sysrap/tests/SOPTIX_Scene_test.sh run \n" ;
0053 sfr fr = _scn->getFrame(FRAME) ;
0054
0055 SGLM gm ;
0056 gm.set_frame(fr);
0057 std::cout << gm.desc() ;
0058
0059
0060
0061
0062
0063 SOPTIX_Context ctx ;
0064 if(dump) std::cout << ctx.desc() ;
0065
0066 SOPTIX_Options opt ;
0067 if(dump) std::cout << opt.desc() ;
0068
0069 SOPTIX_Module mod(ctx.context, opt, "$SOPTIX_PTX" );
0070 if(dump) std::cout << mod.desc() ;
0071
0072 SOPTIX_Pipeline pip(ctx.context, mod.module, opt );
0073 if(dump) std::cout << pip.desc() ;
0074
0075 SOPTIX_Scene scn(&ctx, _scn );
0076 if(dump) std::cout << scn.desc() ;
0077
0078 SOPTIX_SBT sbt(pip, scn );
0079 if(dump) std::cout << sbt.desc() ;
0080
0081
0082 int HANDLE = ssys::getenvint("HANDLE", -1) ;
0083 OptixTraversableHandle handle = scn.getHandle(HANDLE) ;
0084
0085
0086
0087 uchar4* d_pixels = nullptr ;
0088 size_t num_pixel = gm.Width()*gm.Height();
0089 size_t pixel_bytes = num_pixel*sizeof(uchar4) ;
0090 CUDA_CHECK( cudaMalloc(reinterpret_cast<void**>( &d_pixels ), pixel_bytes ));
0091 uchar4* pixels = new uchar4[num_pixel] ;
0092
0093
0094 SOPTIX_Params* d_param = SOPTIX_Params::DeviceAlloc();
0095 SOPTIX_Params par ; ;
0096
0097 par.width = gm.Width() ;
0098 par.height = gm.Height() ;
0099 par.pixels = d_pixels ;
0100 par.tmin = gm.get_near_abs() ;
0101 par.tmax = gm.get_far_abs() ;
0102 par.cameratype = gm.cam ;
0103 par.visibilityMask = gm.vizmask ;
0104
0105 SGLM::Copy(&par.eye.x, gm.e );
0106 SGLM::Copy(&par.U.x , gm.u );
0107 SGLM::Copy(&par.V.x , gm.v );
0108 SGLM::Copy(&par.W.x , gm.w );
0109
0110 par.handle = handle ;
0111
0112 par.upload(d_param);
0113
0114 CUstream stream = 0 ;
0115 unsigned depth = 1 ;
0116
0117 OPTIX_CHECK( optixLaunch(
0118 pip.pipeline,
0119 stream,
0120 (CUdeviceptr)d_param,
0121 sizeof( SOPTIX_Params ),
0122 &(sbt.sbt),
0123 gm.Width(),
0124 gm.Height(),
0125 depth
0126 ) );
0127
0128 CUDA_SYNC_CHECK();
0129 CUDA_CHECK( cudaMemcpy( pixels, reinterpret_cast<void*>(d_pixels), pixel_bytes, cudaMemcpyDeviceToHost ));
0130
0131 const char* ppm_path = getenv("PPM_PATH") ;
0132 bool yflip = true ;
0133 int ncomp = 4 ;
0134 sppm::Write(ppm_path, gm.Width(), gm.Height(), ncomp, (unsigned char*)pixels, yflip );
0135
0136
0137 return 0 ;
0138 }