@@ -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,50 @@ 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.optix_cache_key ();
3830+ group.hash_key (cache_key);
3831+
3832+ std::string cache_value;
3833+ if (renderer ()->optix_cache_get (cache_key, cache_value)) {
3834+ cached = true ;
3835+ optix_cache_unwrap (cache_value,
3836+ group.m_llvm_ptx_compiled_version ,
3837+ group.m_llvm_groupdata_size );
3838+ }
38413839 }
38423840
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 );
3841+ if (!cached) {
3842+ BackendLLVM lljitter (*this , group, ctx);
3843+ lljitter.run ();
3844+
3845+ // NOTE: it is now possible to optimize and not JIT
3846+ // which would leave the cleanup to happen
3847+ // when the ShadingSystem is destroyed
3848+
3849+ // Only cleanup when are not batching or if
3850+ // the batch jit has already happened,
3851+ // as it requires the ops so we can't delete them yet!
3852+ if (((renderer ()->batched (WidthOf<16 >()) == nullptr )
3853+ && (renderer ()->batched (WidthOf<8 >()) == nullptr )
3854+ && (renderer ()->batched (WidthOf<4 >()) == nullptr ))
3855+ || group.batch_jitted ()) {
3856+ group_post_jit_cleanup (group);
3857+ }
3858+
3859+ group.m_jitted = true ;
3860+ spin_lock stat_lock (m_stat_mutex);
3861+ m_stat_opt_locking_time += locking_time;
3862+ m_stat_optimization_time += timer ();
3863+ m_stat_total_llvm_time += lljitter.m_stat_total_llvm_time ;
3864+ m_stat_llvm_setup_time += lljitter.m_stat_llvm_setup_time ;
3865+ m_stat_llvm_irgen_time += lljitter.m_stat_llvm_irgen_time ;
3866+ m_stat_llvm_opt_time += lljitter.m_stat_llvm_opt_time ;
3867+ m_stat_llvm_jit_time += lljitter.m_stat_llvm_jit_time ;
3868+ m_stat_max_llvm_local_mem = std::max (m_stat_max_llvm_local_mem,
3869+ lljitter.m_llvm_local_mem );
3870+ }
38543871 }
38553872
38563873 if (ctx_allocated) {
0 commit comments