@@ -3774,6 +3774,7 @@ ShadingSystemImpl::optimize_group(ShaderGroup& group, ShadingContext* ctx,
37743774 ctx = get_context (thread_info);
37753775 ctx_allocated = true ;
37763776 }
3777+
37773778 if (!group.optimized ()) {
37783779 RuntimeOptimizer rop (*this , group, ctx);
37793780 rop.run ();
@@ -3823,34 +3824,49 @@ ShadingSystemImpl::optimize_group(ShaderGroup& group, ShadingContext* ctx,
38233824 }
38243825
38253826 if (need_jit) {
3826- BackendLLVM lljitter (*this , group, ctx);
3827- lljitter.run ();
3828-
3829- // NOTE: it is now possible to optimize and not JIT
3830- // which would leave the cleanup to happen
3831- // when the ShadingSystem is destroyed
3832-
3833- // Only cleanup when are not batching or if
3834- // the batch jit has already happened,
3835- // as it requires the ops so we can't delete them yet!
3836- if (((renderer ()->batched (WidthOf<16 >()) == nullptr )
3837- && (renderer ()->batched (WidthOf<8 >()) == nullptr )
3838- && (renderer ()->batched (WidthOf<4 >()) == nullptr ))
3839- || group.batch_jitted ()) {
3840- group_post_jit_cleanup (group);
3827+ bool cached = false ;
3828+ if (use_optix () && renderer ()->optix_cache_enabled ()) {
3829+ std::string cache_key = group.generate_optix_cache_key ();
3830+
3831+ std::string cache_value;
3832+ if (renderer ()->optix_cache_get (cache_key, cache_value)) {
3833+ cached = true ;
3834+ optix_cache_unwrap (cache_value,
3835+ group.m_llvm_ptx_compiled_version ,
3836+ group.m_llvm_groupdata_size );
3837+ }
38413838 }
38423839
3843- group.m_jitted = true ;
3844- spin_lock stat_lock (m_stat_mutex);
3845- m_stat_opt_locking_time += locking_time;
3846- m_stat_optimization_time += timer ();
3847- m_stat_total_llvm_time += lljitter.m_stat_total_llvm_time ;
3848- m_stat_llvm_setup_time += lljitter.m_stat_llvm_setup_time ;
3849- m_stat_llvm_irgen_time += lljitter.m_stat_llvm_irgen_time ;
3850- m_stat_llvm_opt_time += lljitter.m_stat_llvm_opt_time ;
3851- m_stat_llvm_jit_time += lljitter.m_stat_llvm_jit_time ;
3852- m_stat_max_llvm_local_mem = std::max (m_stat_max_llvm_local_mem,
3853- lljitter.m_llvm_local_mem );
3840+ if (!cached) {
3841+ BackendLLVM lljitter (*this , group, ctx);
3842+ lljitter.run ();
3843+
3844+ // NOTE: it is now possible to optimize and not JIT
3845+ // which would leave the cleanup to happen
3846+ // when the ShadingSystem is destroyed
3847+
3848+ // Only cleanup when are not batching or if
3849+ // the batch jit has already happened,
3850+ // as it requires the ops so we can't delete them yet!
3851+ if (((renderer ()->batched (WidthOf<16 >()) == nullptr )
3852+ && (renderer ()->batched (WidthOf<8 >()) == nullptr )
3853+ && (renderer ()->batched (WidthOf<4 >()) == nullptr ))
3854+ || group.batch_jitted ()) {
3855+ group_post_jit_cleanup (group);
3856+ }
3857+
3858+ group.m_jitted = true ;
3859+ spin_lock stat_lock (m_stat_mutex);
3860+ m_stat_opt_locking_time += locking_time;
3861+ m_stat_optimization_time += timer ();
3862+ m_stat_total_llvm_time += lljitter.m_stat_total_llvm_time ;
3863+ m_stat_llvm_setup_time += lljitter.m_stat_llvm_setup_time ;
3864+ m_stat_llvm_irgen_time += lljitter.m_stat_llvm_irgen_time ;
3865+ m_stat_llvm_opt_time += lljitter.m_stat_llvm_opt_time ;
3866+ m_stat_llvm_jit_time += lljitter.m_stat_llvm_jit_time ;
3867+ m_stat_max_llvm_local_mem = std::max (m_stat_max_llvm_local_mem,
3868+ lljitter.m_llvm_local_mem );
3869+ }
38543870 }
38553871
38563872 if (ctx_allocated) {
0 commit comments