@@ -3823,34 +3823,49 @@ ShadingSystemImpl::optimize_group(ShaderGroup& group, ShadingContext* ctx,
38233823 }
38243824
38253825 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);
3826+ bool cached = false ;
3827+ if (use_optix () && renderer ()->supports (" optix_ptx_cache" )) {
3828+ std::string cache_key = group.generate_optix_cache_key ();
3829+
3830+ std::string cache_value;
3831+ if (renderer ()->cache_get (" optix_ptx" , cache_key, cache_value)) {
3832+ cached = true ;
3833+ optix_cache_unwrap (cache_value,
3834+ group.m_llvm_ptx_compiled_version ,
3835+ group.m_llvm_groupdata_size );
3836+ }
38413837 }
38423838
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 );
3839+ if (!cached) {
3840+ BackendLLVM lljitter (*this , group, ctx);
3841+ lljitter.run ();
3842+
3843+ // NOTE: it is now possible to optimize and not JIT
3844+ // which would leave the cleanup to happen
3845+ // when the ShadingSystem is destroyed
3846+
3847+ // Only cleanup when are not batching or if
3848+ // the batch jit has already happened,
3849+ // as it requires the ops so we can't delete them yet!
3850+ if (((renderer ()->batched (WidthOf<16 >()) == nullptr )
3851+ && (renderer ()->batched (WidthOf<8 >()) == nullptr )
3852+ && (renderer ()->batched (WidthOf<4 >()) == nullptr ))
3853+ || group.batch_jitted ()) {
3854+ group_post_jit_cleanup (group);
3855+ }
3856+
3857+ group.m_jitted = true ;
3858+ spin_lock stat_lock (m_stat_mutex);
3859+ m_stat_opt_locking_time += locking_time;
3860+ m_stat_optimization_time += timer ();
3861+ m_stat_total_llvm_time += lljitter.m_stat_total_llvm_time ;
3862+ m_stat_llvm_setup_time += lljitter.m_stat_llvm_setup_time ;
3863+ m_stat_llvm_irgen_time += lljitter.m_stat_llvm_irgen_time ;
3864+ m_stat_llvm_opt_time += lljitter.m_stat_llvm_opt_time ;
3865+ m_stat_llvm_jit_time += lljitter.m_stat_llvm_jit_time ;
3866+ m_stat_max_llvm_local_mem = std::max (m_stat_max_llvm_local_mem,
3867+ lljitter.m_llvm_local_mem );
3868+ }
38543869 }
38553870
38563871 if (ctx_allocated) {
0 commit comments