From 384e45a3c617c7e216e6d43a27cb0c8cb88e1447 Mon Sep 17 00:00:00 2001 From: iaomw Date: Thu, 20 Jun 2024 16:50:45 +0800 Subject: [PATCH 1/2] Improve Optix cleanup --- zenovis/xinxinoptix/optixPathTracer.cpp | 56 +++++++++++-------------- zenovis/xinxinoptix/xinxinoptixapi.h | 2 +- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/zenovis/xinxinoptix/optixPathTracer.cpp b/zenovis/xinxinoptix/optixPathTracer.cpp index b33f92b89f..172da61aa9 100644 --- a/zenovis/xinxinoptix/optixPathTracer.cpp +++ b/zenovis/xinxinoptix/optixPathTracer.cpp @@ -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; } @@ -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; @@ -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() ) { diff --git a/zenovis/xinxinoptix/xinxinoptixapi.h b/zenovis/xinxinoptix/xinxinoptixapi.h index 135cd460db..a75af3a313 100644 --- a/zenovis/xinxinoptix/xinxinoptixapi.h +++ b/zenovis/xinxinoptix/xinxinoptixapi.h @@ -34,8 +34,8 @@ namespace xinxinoptix { std::set 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[]); From cc75adf3f8997418c605a2d006ac6d661a90ac99 Mon Sep 17 00:00:00 2001 From: iaomw Date: Thu, 20 Jun 2024 16:52:17 +0800 Subject: [PATCH 2/2] dirty fix --- zenovis/xinxinoptix/optixPathTracer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zenovis/xinxinoptix/optixPathTracer.cpp b/zenovis/xinxinoptix/optixPathTracer.cpp index 172da61aa9..ad38fddad9 100644 --- a/zenovis/xinxinoptix/optixPathTracer.cpp +++ b/zenovis/xinxinoptix/optixPathTracer.cpp @@ -2108,7 +2108,10 @@ void using_hdr_sky(bool enable) { } void show_background(bool enable) { - state.params.show_background = enable; + if (enable != state.params.show_background) { + state.params.show_background = enable; + state.params.subframe_index = 0; + } } void updatePortalLights(const std::vector& portals) {