Skip to content

Commit

Permalink
Improve Optix cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Jun 20, 2024
1 parent 353b674 commit 384e45a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
56 changes: 24 additions & 32 deletions zenovis/xinxinoptix/optixPathTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1507,20 +1507,6 @@ static void cleanupState( PathTracerState& state )
OPTIX_CHECK(optixModuleDestroy(OptixUtil::ray_module));
OPTIX_CHECK(optixModuleDestroy(OptixUtil::sphere_module));

cleanupSpheresGPU();
lightsWrapper.reset();

for (auto& ele : list_volume) {
cleanupVolume(*ele);
}
list_volume.clear();

for (auto const& [key, val] : OptixUtil::g_vdb_cached_map) {
cleanupVolume(*val);
}
OptixUtil::g_vdb_cached_map.clear();
OptixUtil::g_ies.clear();

std::cout << "optix cleanup" << std::endl;
}

Expand Down Expand Up @@ -3984,31 +3970,42 @@ void optixCleanup() {
}

OptixUtil::sky_tex = OptixUtil::default_sky_tex;

cleanupSpheresGPU();
lightsWrapper.reset();

for (auto& ele : list_volume) {
cleanupVolume(*ele);
}
list_volume.clear();

for (auto const& [key, val] : OptixUtil::g_vdb_cached_map) {
cleanupVolume(*val);
}
OptixUtil::g_vdb_cached_map.clear();
OptixUtil::g_ies.clear();

g_StaticMeshPieces.clear();
g_meshPieces.clear();
}

void optixDestroy() {
using namespace OptixUtil;
try {
CUDA_SYNC_CHECK();
optixCleanup();
cleanupState( state );
rtMaterialShaders.clear();

OptixUtil::shaderCoreLUT.clear();

OPTIX_CHECK(optixPipelineDestroy(state.pipeline));
OPTIX_CHECK(optixDeviceContextDestroy(state.context));
}
catch (sutil::Exception const& e) {
std::cout << "OptixCleanupError: " << e.what() << std::endl;
}
//// state.d_vertices.reset();
//// state.d_clr.reset();
//// state.d_mat_indices.reset();
//// state.d_nrm.reset();
//// state.d_tan.reset();
//// state.d_uv.reset();
// std::memset((void *)&state, 0, sizeof(state));
// //std::memset((void *)&rtMaterialShaders[0], 0, sizeof(rtMaterialShaders[0]) * rtMaterialShaders.size());
//
//

context .handle=0;
pipeline .handle=0;
ray_module .handle=0;
Expand All @@ -4017,22 +4014,17 @@ void optixDestroy() {
radiance_miss_group .handle=0;
occlusion_miss_group .handle=0;

OptixUtil::shaderCoreLUT.clear();

output_buffer_o .reset();
output_buffer_diffuse .reset();
output_buffer_specular .reset();
output_buffer_transmit .reset();
output_buffer_background .reset();
output_buffer_mask .reset();
g_StaticMeshPieces .clear();
g_meshPieces .clear();
state = {};
isPipelineCreated = false;



state = {};
isPipelineCreated = false;
}

#if 0
if( outfile.empty() )
{
Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/xinxinoptixapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace xinxinoptix {
std::set<std::string> uniqueMatsForMesh();

void optixCleanup();

void optixDestroy();

void optixrender(int fbo = 0, int samples = 1, bool denoise = false, bool simpleRender = false);
void *optixgetimg(int &w, int &h);
void optixinit(int argc, char* argv[]);
Expand Down

0 comments on commit 384e45a

Please sign in to comment.