Skip to content

Commit

Permalink
Fix reference counting of OptiX shader binding table
Browse files Browse the repository at this point in the history
(This commit is a backport of 40ae0b8)
  • Loading branch information
Speierers authored and njroussel committed Jun 10, 2024
1 parent 1288136 commit 15f9470
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/render/scene_optix.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down Expand Up @@ -357,9 +356,11 @@ MI_VARIANT void Scene<Float, Spectrum>::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
Expand Down Expand Up @@ -425,7 +426,6 @@ MI_VARIANT void Scene<Float, Spectrum>::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;
}

// =====================================================
Expand Down Expand Up @@ -555,12 +555,10 @@ MI_VARIANT void Scene<Float, Spectrum>::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
Expand Down
2 changes: 1 addition & 1 deletion tutorials

0 comments on commit 15f9470

Please sign in to comment.