From 15f94707487395bb40ba71e1bb9b2e11ed04b9c9 Mon Sep 17 00:00:00 2001 From: Sebastien Speierer Date: Thu, 15 Feb 2024 09:47:49 +0100 Subject: [PATCH] Fix reference counting of OptiX shader binding table (This commit is a backport of 40ae0b89eea9d09bf99138642a20df84335a20eb) --- src/render/scene_optix.inl | 20 +++++++++----------- tutorials | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/render/scene_optix.inl b/src/render/scene_optix.inl index 5eab71990..0ee87ed32 100644 --- a/src/render/scene_optix.inl +++ b/src/render/scene_optix.inl @@ -30,12 +30,11 @@ struct OptixSceneState { OptixAccelData accel; OptixTraversableHandle ias_handle = 0ull; struct InstanceData { - void* buffer = nullptr; // Device-visible storage for IAS - void* inputs = nullptr; // Device-visible storage for OptixInstance array + void* buffer = nullptr; // Device-visible storage for IAS + void* inputs = nullptr; // Device-visible storage for OptixInstance array } ias_data; size_t config_index; uint32_t sbt_jit_index; - bool own_sbt; }; /** @@ -357,9 +356,11 @@ MI_VARIANT void Scene::accel_init_gpu(const Properties &props) jit_optix_update_sbt(s2.sbt_jit_index, &s2.sbt); memcpy(&s.sbt, &s2.sbt, sizeof(OptixShaderBindingTable)); + s.sbt_jit_index = s2.sbt_jit_index; + jit_var_inc_ref(s.sbt_jit_index); + s.config_index = s2.config_index; - s.own_sbt = false; } else { // ===================================================== // Initialize OptiX configuration @@ -425,7 +426,6 @@ MI_VARIANT void Scene::accel_init_gpu(const Properties &props) jit_malloc_migrate(s.sbt.hitgroupRecordBase, AllocType::Device, 1); s.sbt_jit_index = jit_optix_configure_sbt(&s.sbt, config.pipeline_jit_index); - s.own_sbt = true; } // ===================================================== @@ -555,12 +555,10 @@ MI_VARIANT void Scene::accel_release_gpu() { OptixSceneState *s = (OptixSceneState *) m_accel; - if (s->own_sbt) { - /* This will decrease the reference count of the shader binding table - JIT variable which might trigger the release of the OptiX SBT if - no ray tracing calls are pending. */ - (void) UInt32::steal(s->sbt_jit_index); - } + /* This will decrease the reference count of the shader binding table + JIT variable which might trigger the release of the OptiX SBT if + no ray tracing calls are pending. */ + (void) UInt32::steal(s->sbt_jit_index); /* Decrease the reference count of the IAS handle variable. This will trigger the release of the OptiX acceleration data structure if no diff --git a/tutorials b/tutorials index 42fffc6d8..e5dd59d74 160000 --- a/tutorials +++ b/tutorials @@ -1 +1 @@ -Subproject commit 42fffc6d85bb8b2423baca26b811b7662444ffe7 +Subproject commit e5dd59d743ba24a14516041c6db050ed73445b2c