[Bf-blender-cvs] [b0c4590130b] cycles_path_guiding: Cleanup: tweak limit samples per update code, remove outdated TODO

Brecht Van Lommel noreply at git.blender.org
Tue Sep 20 21:00:36 CEST 2022


Commit: b0c4590130b3d53efbcd9ca0d2cf65f789679fc8
Author: Brecht Van Lommel
Date:   Mon Sep 19 20:05:44 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rBb0c4590130b3d53efbcd9ca0d2cf65f789679fc8

Cleanup: tweak limit samples per update code, remove outdated TODO

===================================================================

M	intern/cycles/integrator/path_trace.cpp
M	intern/cycles/integrator/render_scheduler.cpp
M	intern/cycles/integrator/render_scheduler.h

===================================================================

diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp
index 673f2b39076..5021a3e18ba 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -1322,14 +1322,20 @@ void PathTrace::guiding_prepare_structures()
     path_trace_work->guiding_init_kernel_globals(guiding_field_.get(),
                                                  guiding_sample_data_storage_.get());
   }
+
   if ((guiding_params_.training_iterations == -1) ||
       (guiding_field_->GetIteration() < guiding_params_.training_iterations)) {
+    /* For training the guiding distribution we need to force the number of samples
+     * per update to be limited, for reproducible results and reasonable training size.
+     *
+     * Idea: we could stochastically discard samples with a probability of 1/num_samples_per_update
+     * we can then update only after the num_samples_per_update iterations are rendered.  */
     device_scene_->data.integrator.train_guiding = true;
-    render_scheduler_.set_limit_spp_for_guiding(true);
+    render_scheduler_.set_limit_samples_per_update(4);
   }
   else {
     device_scene_->data.integrator.train_guiding = false;
-    render_scheduler_.set_limit_spp_for_guiding(false);
+    render_scheduler_.set_limit_samples_per_update(0);
   }
 #endif
 }
diff --git a/intern/cycles/integrator/render_scheduler.cpp b/intern/cycles/integrator/render_scheduler.cpp
index 438b2fabf37..2e05dbbaf6e 100644
--- a/intern/cycles/integrator/render_scheduler.cpp
+++ b/intern/cycles/integrator/render_scheduler.cpp
@@ -45,9 +45,9 @@ void RenderScheduler::set_denoiser_params(const DenoiseParams &params)
   denoiser_params_ = params;
 }
 
-void RenderScheduler::set_limit_spp_for_guiding(const bool limit_spp)
+void RenderScheduler::set_limit_samples_per_update(const int limit_samples)
 {
-  limit_spp_for_guiding_ = limit_spp;
+  limit_samples_per_update_ = limit_samples;
 }
 
 void RenderScheduler::set_adaptive_sampling(const AdaptiveSampling &adaptive_sampling)
@@ -765,7 +765,13 @@ int RenderScheduler::calculate_num_samples_per_update() const
 
   const double update_interval_in_seconds = guess_display_update_interval_in_seconds();
 
-  return max(int(num_samples_in_second * update_interval_in_seconds), 1);
+  int num_samples_per_update = max(int(num_samples_in_second * update_interval_in_seconds), 1);
+
+  if (limit_samples_per_update_) {
+    num_samples_per_update = min(limit_samples_per_update_, num_samples_per_update);
+  }
+
+  return num_samples_per_update;
 }
 
 int RenderScheduler::get_start_sample_to_path_trace() const
@@ -814,20 +820,6 @@ int RenderScheduler::get_num_samples_to_path_trace() const
   }
 
   int num_samples_per_update = calculate_num_samples_per_update();
-#ifdef WITH_PATH_GUIDING
-  /*
-   * Note: For training the guiding distribution we
-   *       might need to force the num_samples_per_update to one
-   * Idea: we could stochastically discard samples with a
-   *       prob of 1/num_samples_per_update
-   *       we can then updated only after the num_samples_per_update
-   *       iterations are rendered
-   * TODO: only do this when path guiding is enabled.
-   */
-  if (limit_spp_for_guiding_) {
-    num_samples_per_update = std::min(4, num_samples_per_update);
-  }
-#endif
   const int path_trace_start_sample = get_start_sample_to_path_trace();
 
   /* Round number of samples to a power of two, so that division of path states into tiles goes in
diff --git a/intern/cycles/integrator/render_scheduler.h b/intern/cycles/integrator/render_scheduler.h
index fba1d200e9d..a0ab17b3794 100644
--- a/intern/cycles/integrator/render_scheduler.h
+++ b/intern/cycles/integrator/render_scheduler.h
@@ -187,7 +187,7 @@ class RenderScheduler {
    * times, and so on. */
   string full_report() const;
 
-  void set_limit_spp_for_guiding(const bool limit_spp);
+  void set_limit_samples_per_update(const int limit_samples);
 
  protected:
   /* Check whether all work has been scheduled and time limit was not exceeded.
@@ -455,7 +455,7 @@ class RenderScheduler {
 
   /* If the number of samples per rendering progression should be limited because of path guiding
    * being activated or is still inside its training phase */
-  bool limit_spp_for_guiding_ = false;
+  int limit_samples_per_update_ = 0;
 };
 
 int calculate_resolution_divider_for_resolution(int width, int height, int resolution);



More information about the Bf-blender-cvs mailing list