[Bf-blender-cvs] [f3048b244d5] cycles-x: Cycles X: Reduce OPtiX memory usage on multi-device

Sergey Sharybin noreply at git.blender.org
Fri Jul 9 17:32:19 CEST 2021


Commit: f3048b244d580ef0c7abf627bb191a0930bcf7d4
Author: Sergey Sharybin
Date:   Fri Jul 9 14:54:54 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBf3048b244d580ef0c7abf627bb191a0930bcf7d4

Cycles X: Reduce OPtiX memory usage on multi-device

The idea is to allow OptiX denoiser to modify input render buffers
when it is known it will not conflict with the path tracer.

Can be extended to the CPU rendering and OptiX denoising, but this
will need some generic way of copying denoised passes only between
render buffers.

Differential Revision: https://developer.blender.org/D11865

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

M	intern/cycles/device/device_denoise.h
M	intern/cycles/device/optix/device_impl.cpp
M	intern/cycles/integrator/denoiser_device.cpp

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

diff --git a/intern/cycles/device/device_denoise.h b/intern/cycles/device/device_denoise.h
index 25263d14cac..a1f88df3c34 100644
--- a/intern/cycles/device/device_denoise.h
+++ b/intern/cycles/device/device_denoise.h
@@ -89,6 +89,11 @@ class DeviceDenoiseTask {
 
   RenderBuffers *render_buffers;
   BufferParams buffer_params;
+
+  /* Allow to do in-place modification of the input passes (scaling them down i.e.). This will
+   * lower the memory footprint of the denoiser but will make input passes "invalid" (from path
+   * tracer) point of view. */
+  bool allow_inplace_modification;
 };
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp
index 9bda428c462..e265bbba726 100644
--- a/intern/cycles/device/optix/device_impl.cpp
+++ b/intern/cycles/device/optix/device_impl.cpp
@@ -549,21 +549,32 @@ class OptiXDevice::DenoiseContext {
     const int num_guiding_passes = num_input_passes - 1;
 
     if (num_guiding_passes) {
-      guiding_params.pass_stride = 0;
-      if (use_pass_albedo) {
-        guiding_params.pass_albedo = guiding_params.pass_stride;
-        guiding_params.pass_stride += 3;
-      }
-      if (use_pass_normal) {
-        guiding_params.pass_normal = guiding_params.pass_stride;
-        guiding_params.pass_stride += 3;
+      if (task.allow_inplace_modification) {
+        guiding_params.device_pointer = render_buffers->buffer.device_pointer;
+
+        guiding_params.pass_albedo = pass_denoising_albedo;
+        guiding_params.pass_normal = pass_denoising_normal;
+
+        guiding_params.stride = buffer_params.stride;
+        guiding_params.pass_stride = buffer_params.pass_stride;
       }
+      else {
+        guiding_params.pass_stride = 0;
+        if (use_pass_albedo) {
+          guiding_params.pass_albedo = guiding_params.pass_stride;
+          guiding_params.pass_stride += 3;
+        }
+        if (use_pass_normal) {
+          guiding_params.pass_normal = guiding_params.pass_stride;
+          guiding_params.pass_stride += 3;
+        }
 
-      guiding_params.stride = buffer_params.width;
+        guiding_params.stride = buffer_params.width;
 
-      guiding_buffer.alloc_to_device(buffer_params.width * buffer_params.height *
-                                     guiding_params.pass_stride);
-      guiding_params.device_pointer = guiding_buffer.device_pointer;
+        guiding_buffer.alloc_to_device(buffer_params.width * buffer_params.height *
+                                       guiding_params.pass_stride);
+        guiding_params.device_pointer = guiding_buffer.device_pointer;
+      }
     }
 
     pass_sample_count = buffer_params.get_pass_offset(PASS_SAMPLE_COUNT);
diff --git a/intern/cycles/integrator/denoiser_device.cpp b/intern/cycles/integrator/denoiser_device.cpp
index 6d472f9883e..05cc400f02a 100644
--- a/intern/cycles/integrator/denoiser_device.cpp
+++ b/intern/cycles/integrator/denoiser_device.cpp
@@ -41,9 +41,6 @@ void DeviceDenoiser::denoise_buffer(const BufferParams &buffer_params,
                                     const int num_samples,
                                     bool allow_inplace_modification)
 {
-  /* TODO(sergey): Support in-place modification to lower memory footprint. */
-  (void)allow_inplace_modification;
-
   Device *denoiser_device = get_denoiser_device();
   if (!denoiser_device) {
     return;
@@ -53,6 +50,7 @@ void DeviceDenoiser::denoise_buffer(const BufferParams &buffer_params,
   task.params = params_;
   task.num_samples = num_samples;
   task.buffer_params = buffer_params;
+  task.allow_inplace_modification = allow_inplace_modification;
 
   RenderBuffers local_render_buffers(denoiser_device);
   bool local_buffer_used = false;
@@ -93,7 +91,8 @@ void DeviceDenoiser::denoise_buffer(const BufferParams &buffer_params,
   denoiser_device->denoise_buffer(task);
 
   if (local_buffer_used) {
-    /* TODO(sergey): Only copy denoised passes. */
+    /* TODO(sergey): Only copy denoised passes. This will also allow to reduce memory usage by
+     * allowing in-place modification of the temporary render buffer. */
     local_render_buffers.copy_from_device();
     memcpy(render_buffers->buffer.data(),
            local_render_buffers.buffer.data(),



More information about the Bf-blender-cvs mailing list