[Bf-blender-cvs] [e1b6b9702db] cycles-x: Cycles X: Allow adding samples to pixel

Sergey Sharybin noreply at git.blender.org
Wed May 12 16:10:45 CEST 2021


Commit: e1b6b9702db556853121dfec6c04a242969c83e7
Author: Sergey Sharybin
Date:   Thu Apr 22 16:21:10 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBe1b6b9702db556853121dfec6c04a242969c83e7

Cycles X: Allow adding samples to pixel

The idea is to be able to resume sampling pixel after it "skipped"
some of the scheduled tiles due to convergence.

This is a bit weak concept, but is the most straight forward to
implement. This will be needed for the progressive noise floor
feature.

The current implementation is relying on the fact that the maximum
number of samples will not exceed floating point precision: for
the range of 0 to 2^24 the worst prevision of the single floating
precision is 1. To be more robust for all possible GPUs which might
have precision issues this will be changed in the followup commit.

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

M	intern/cycles/kernel/integrator/integrator_init_from_camera.h
M	intern/cycles/kernel/kernel_accumulate.h

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

diff --git a/intern/cycles/kernel/integrator/integrator_init_from_camera.h b/intern/cycles/kernel/integrator/integrator_init_from_camera.h
index 4c075ea8740..751e6e6afac 100644
--- a/intern/cycles/kernel/integrator/integrator_init_from_camera.h
+++ b/intern/cycles/kernel/integrator/integrator_init_from_camera.h
@@ -68,7 +68,7 @@ ccl_device bool integrator_init_from_camera(INTEGRATOR_STATE_ARGS,
                                             ccl_global float *render_buffer,
                                             const int x,
                                             const int y,
-                                            const int sample)
+                                            const int scheduled_sample)
 {
   /* Initialize path state to give basic buffer access and allow early outputs. */
   path_state_init(INTEGRATOR_STATE_PASS, tile, x, y);
@@ -82,8 +82,12 @@ ccl_device bool integrator_init_from_camera(INTEGRATOR_STATE_ARGS,
     return false;
   }
 
-  /* Always count the sample, even if the camera sample will reject the ray. */
-  kernel_accum_sample(INTEGRATOR_STATE_PASS, render_buffer);
+  /* Count the sample and get an effective sample for this pixel.
+   *
+   * This logic allows to both count actual number of sampels per pixel, and to add samples to this
+   * pixel after it was converged and samples were added somewhere else (in which case the
+   * `scheduled_sample` will be different from actual number of samples in this pixel). */
+  const int sample = kernel_accum_sample(INTEGRATOR_STATE_PASS, render_buffer, scheduled_sample);
 
   /* Initialize random number seed for path. */
   const uint rng_hash = path_rng_hash_init(kg, sample, x, y);
diff --git a/intern/cycles/kernel/kernel_accumulate.h b/intern/cycles/kernel/kernel_accumulate.h
index dd78a436633..4d893ce57f8 100644
--- a/intern/cycles/kernel/kernel_accumulate.h
+++ b/intern/cycles/kernel/kernel_accumulate.h
@@ -321,17 +321,18 @@ ccl_device_forceinline ccl_global float *kernel_accum_pixel_render_buffer(
  * Adaptive sampling.
  */
 
-ccl_device_inline void kernel_accum_sample(INTEGRATOR_STATE_CONST_ARGS,
-                                           ccl_global float *ccl_restrict render_buffer)
+ccl_device_inline int kernel_accum_sample(INTEGRATOR_STATE_CONST_ARGS,
+                                          ccl_global float *ccl_restrict render_buffer,
+                                          int sample)
 {
   if (kernel_data.film.pass_sample_count == PASS_UNUSED) {
-    return;
+    return sample;
   }
 
   ccl_global float *buffer = kernel_accum_pixel_render_buffer(INTEGRATOR_STATE_PASS,
                                                               render_buffer);
 
-  kernel_write_pass_float(buffer + kernel_data.film.pass_sample_count, 1.0f);
+  return (int)atomic_add_and_fetch_float(buffer + kernel_data.film.pass_sample_count, 1.0f) - 1;
 }
 
 ccl_device void kernel_accum_adaptive_buffer(INTEGRATOR_STATE_CONST_ARGS,



More information about the Bf-blender-cvs mailing list