[Bf-blender-cvs] [013d758cb7c] cycles_path_guiding: Fix broken training, train_guiding was not propagated to CPU threads
Brecht Van Lommel
noreply at git.blender.org
Tue Sep 20 21:00:36 CEST 2022
Commit: 013d758cb7c0394a298e6566e964aaaa01864c22
Author: Brecht Van Lommel
Date: Mon Sep 19 20:52:52 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rB013d758cb7c0394a298e6566e964aaaa01864c22
Fix broken training, train_guiding was not propagated to CPU threads
===================================================================
M intern/cycles/integrator/path_trace.cpp
M intern/cycles/integrator/path_trace_work.h
M intern/cycles/integrator/path_trace_work_cpu.cpp
M intern/cycles/integrator/path_trace_work_cpu.h
===================================================================
diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp
index 5021a3e18ba..985287bad51 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -1318,23 +1318,23 @@ void PathTrace::set_guiding_params(const GuidingParams &guiding_params, const bo
void PathTrace::guiding_prepare_structures()
{
#ifdef WITH_PATH_GUIDING
+ const bool train = (guiding_params_.training_iterations == -1) ||
+ (guiding_field_->GetIteration() < guiding_params_.training_iterations);
+
for (auto &&path_trace_work : path_trace_works_) {
- path_trace_work->guiding_init_kernel_globals(guiding_field_.get(),
- guiding_sample_data_storage_.get());
+ path_trace_work->guiding_init_kernel_globals(
+ guiding_field_.get(), guiding_sample_data_storage_.get(), train);
}
- if ((guiding_params_.training_iterations == -1) ||
- (guiding_field_->GetIteration() < guiding_params_.training_iterations)) {
+ if (train) {
/* 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_samples_per_update(4);
}
else {
- device_scene_->data.integrator.train_guiding = false;
render_scheduler_.set_limit_samples_per_update(0);
}
#endif
diff --git a/intern/cycles/integrator/path_trace_work.h b/intern/cycles/integrator/path_trace_work.h
index db419330255..2ffebc14a25 100644
--- a/intern/cycles/integrator/path_trace_work.h
+++ b/intern/cycles/integrator/path_trace_work.h
@@ -145,7 +145,7 @@ class PathTraceWork {
* global guiding field and the sample data storage as well es initializes the per-thread
* guided sampling distrubtions (e.g., SurfaceSamplingDistribution and
* VolumeSamplingDistribution). */
- virtual void guiding_init_kernel_globals(void *, void *)
+ virtual void guiding_init_kernel_globals(void *, void *, const bool)
{
}
#endif
diff --git a/intern/cycles/integrator/path_trace_work_cpu.cpp b/intern/cycles/integrator/path_trace_work_cpu.cpp
index e212595394c..db697034576 100644
--- a/intern/cycles/integrator/path_trace_work_cpu.cpp
+++ b/intern/cycles/integrator/path_trace_work_cpu.cpp
@@ -57,10 +57,12 @@ void PathTraceWorkCPU::init_execution()
device_->get_cpu_kernel_thread_globals(kernel_thread_globals_);
}
-#if defined(WITH_PATH_GUIDING)
+#ifdef WITH_PATH_GUIDING
/* Note: It seems that this is called before every rendering iteration/progression and not once per
* rendering. May be we find a way to call it only once per rendering. */
-void PathTraceWorkCPU::guiding_init_kernel_globals(void *guiding_field, void *sample_data_storage)
+void PathTraceWorkCPU::guiding_init_kernel_globals(void *guiding_field,
+ void *sample_data_storage,
+ const bool train)
{
/* Linking the global guiding structures (e.g., Field and SampleStorage) to the per-thread
* kernel globals. */
@@ -69,30 +71,29 @@ void PathTraceWorkCPU::guiding_init_kernel_globals(void *guiding_field, void *sa
# endif
for (int thread_index = 0; thread_index < kernel_thread_globals_.size(); thread_index++) {
# if PATH_GUIDING_LEVEL >= 3
+ CPUKernelThreadGlobals &kg = kernel_thread_globals_[thread_index];
- kernel_thread_globals_[thread_index].opgl_sample_data_storage = (openpgl::cpp::SampleStorage *)
- sample_data_storage;
+ kg.opgl_sample_data_storage = (openpgl::cpp::SampleStorage *)sample_data_storage;
# endif
# if PATH_GUIDING_LEVEL >= 4
if (field) {
- kernel_thread_globals_[thread_index].opgl_guiding_field = field;
- if (kernel_thread_globals_[thread_index].opgl_surface_sampling_distribution)
- delete kernel_thread_globals_[thread_index].opgl_surface_sampling_distribution;
- kernel_thread_globals_[thread_index].opgl_surface_sampling_distribution =
- new openpgl::cpp::SurfaceSamplingDistribution(field);
- if (kernel_thread_globals_[thread_index].opgl_volume_sampling_distribution)
- delete kernel_thread_globals_[thread_index].opgl_volume_sampling_distribution;
- kernel_thread_globals_[thread_index].opgl_volume_sampling_distribution =
- new openpgl::cpp::VolumeSamplingDistribution(field);
+ kg.opgl_guiding_field = field;
+ if (kg.opgl_surface_sampling_distribution)
+ delete kg.opgl_surface_sampling_distribution;
+ kg.opgl_surface_sampling_distribution = new openpgl::cpp::SurfaceSamplingDistribution(field);
+ if (kg.opgl_volume_sampling_distribution)
+ delete kg.opgl_volume_sampling_distribution;
+ kg.opgl_volume_sampling_distribution = new openpgl::cpp::VolumeSamplingDistribution(field);
}
else {
- kernel_thread_globals_[thread_index].opgl_guiding_field = nullptr;
- kernel_thread_globals_[thread_index].opgl_surface_sampling_distribution = nullptr;
- kernel_thread_globals_[thread_index].opgl_volume_sampling_distribution = nullptr;
+ kg.opgl_guiding_field = nullptr;
+ kg.opgl_surface_sampling_distribution = nullptr;
+ kg.opgl_volume_sampling_distribution = nullptr;
}
-
# endif
+
+ kg.data.integrator.train_guiding = train;
}
}
#endif
diff --git a/intern/cycles/integrator/path_trace_work_cpu.h b/intern/cycles/integrator/path_trace_work_cpu.h
index 93d14364a4f..5004d2f6a85 100644
--- a/intern/cycles/integrator/path_trace_work_cpu.h
+++ b/intern/cycles/integrator/path_trace_work_cpu.h
@@ -66,7 +66,9 @@ class PathTraceWorkCPU : public PathTraceWork {
* global guiding field and the sample data storage as well es initializes the per-thread
* guided sampling distrubtions (e.g., SurfaceSamplingDistribution and
* VolumeSamplingDistribution). */
- void guiding_init_kernel_globals(void *guiding_field, void *sample_data_storage) override;
+ void guiding_init_kernel_globals(void *guiding_field,
+ void *sample_data_storage,
+ const bool train) override;
#endif
protected:
More information about the Bf-blender-cvs
mailing list