[Bf-blender-cvs] [cf028a8f680] cycles-x: Cycles X: Avoid device copy for every pass

Sergey Sharybin noreply at git.blender.org
Tue Jun 29 20:03:21 CEST 2021


Commit: cf028a8f680650a0d33ce8dd288523b494b0fa00
Author: Sergey Sharybin
Date:   Tue Jun 29 13:03:51 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBcf028a8f680650a0d33ce8dd288523b494b0fa00

Cycles X: Avoid device copy for every pass

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

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

M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/integrator/path_trace.cpp
M	intern/cycles/integrator/path_trace.h
M	intern/cycles/integrator/path_trace_work.cpp
M	intern/cycles/integrator/path_trace_work.h
M	intern/cycles/render/session.cpp
M	intern/cycles/render/session.h

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

diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index 61f20b018af..373cc821401 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -683,6 +683,10 @@ void BlenderSession::bake(BL::Depsgraph &b_depsgraph_,
 
 void BlenderSession::write_render_result(BL::RenderLayer &b_rlay)
 {
+  if (!session->copy_render_tile_from_device()) {
+    return;
+  }
+
   const int2 tile_size = session->get_render_tile_size();
   vector<float> pixels(tile_size.x * tile_size.y * 4);
 
@@ -698,6 +702,10 @@ void BlenderSession::write_render_result(BL::RenderLayer &b_rlay)
 
 void BlenderSession::update_render_result(BL::RenderLayer &b_rlay)
 {
+  if (!session->copy_render_tile_from_device()) {
+    return;
+  }
+
   const int2 tile_size = session->get_render_tile_size();
   vector<float> pixels(tile_size.x * tile_size.y * 4);
 
diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp
index 09aa4e8a8da..ffbd7b19db6 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -578,6 +578,22 @@ void PathTrace::copy_from_render_buffers(RenderBuffers *render_buffers)
                          });
 }
 
+bool PathTrace::copy_render_tile_from_device()
+{
+  bool success = true;
+
+  tbb::parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
+    if (!success) {
+      return;
+    }
+    if (!path_trace_work->copy_render_tile_from_device()) {
+      success = false;
+    }
+  });
+
+  return success;
+}
+
 bool PathTrace::get_render_tile_pixels(const PassAccessor &pass_accessor,
                                        const PassAccessor::Destination &destination)
 {
diff --git a/intern/cycles/integrator/path_trace.h b/intern/cycles/integrator/path_trace.h
index 4985aa62d12..57f9ae885ca 100644
--- a/intern/cycles/integrator/path_trace.h
+++ b/intern/cycles/integrator/path_trace.h
@@ -107,9 +107,15 @@ class PathTrace {
    * buffers and will be copied to all devices of the path trace. */
   void copy_from_render_buffers(RenderBuffers *render_buffers);
 
+  /* Copy render buffers of the big tile from the device to hsot.
+   * Return true if all copies are successful. */
+  bool copy_render_tile_from_device();
+
   /* Get pass data of the entire big tile.
    * This call puts pass render result from all devices into the final pixels storage.
    *
+   * NOTE: Expects buffers to be copied to the host using `copy_render_tile_from_device()`.
+   *
    * Returns false if any of the accessor's `get_render_tile_pixels()` returned false. */
   bool get_render_tile_pixels(const PassAccessor &pass_accessor,
                               const PassAccessor::Destination &destination);
diff --git a/intern/cycles/integrator/path_trace_work.cpp b/intern/cycles/integrator/path_trace_work.cpp
index 54446f25f83..c7e0c06145c 100644
--- a/intern/cycles/integrator/path_trace_work.cpp
+++ b/intern/cycles/integrator/path_trace_work.cpp
@@ -112,13 +112,14 @@ void PathTraceWork::copy_from_render_buffers(const RenderBuffers *render_buffers
   buffers_->copy_to_device();
 }
 
+bool PathTraceWork::copy_render_tile_from_device()
+{
+  return buffers_->copy_from_device();
+}
+
 bool PathTraceWork::get_render_tile_pixels(const PassAccessor &pass_accessor,
                                            const PassAccessor::Destination &destination)
 {
-  if (!buffers_->copy_from_device()) {
-    return false;
-  }
-
   const int offset_y = effective_buffer_params_.full_y - effective_big_tile_params_.full_y;
   const int width = effective_buffer_params_.width;
 
diff --git a/intern/cycles/integrator/path_trace_work.h b/intern/cycles/integrator/path_trace_work.h
index d588528d086..3cc9abacc00 100644
--- a/intern/cycles/integrator/path_trace_work.h
+++ b/intern/cycles/integrator/path_trace_work.h
@@ -91,8 +91,13 @@ class PathTraceWork {
    * - Copies work's render buffer to its device. */
   void copy_from_render_buffers(const RenderBuffers *render_buffers);
 
+  bool copy_render_tile_from_device();
+
   /* Access pixels rendered by this work and copy them to the coresponding location in the
-   * destination. */
+   * destination.
+   *
+   * NOTE: Does not perform copy of buffers from the device. Use `copy_render_tile_from_device()`
+   * to update host-side data. */
   bool get_render_tile_pixels(const PassAccessor &pass_accessor,
                               const PassAccessor::Destination &destination);
 
diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp
index b2fe670a7db..bc6dfc6ce47 100644
--- a/intern/cycles/render/session.cpp
+++ b/intern/cycles/render/session.cpp
@@ -574,6 +574,11 @@ int2 Session::get_render_tile_offset() const
   return make_int2(tile.x - tile.full_x, tile.y - tile.full_y);
 }
 
+bool Session::copy_render_tile_from_device()
+{
+  return path_trace_->copy_render_tile_from_device();
+}
+
 bool Session::get_render_tile_pixels(const string &pass_name, int num_components, float *pixels)
 {
   const Pass *pass = Pass::find(scene->passes, pass_name);
diff --git a/intern/cycles/render/session.h b/intern/cycles/render/session.h
index 6969c1d7dbf..e3ae91ce2fc 100644
--- a/intern/cycles/render/session.h
+++ b/intern/cycles/render/session.h
@@ -150,6 +150,8 @@ class Session {
   int2 get_render_tile_size() const;
   int2 get_render_tile_offset() const;
 
+  bool copy_render_tile_from_device();
+
   bool get_render_tile_pixels(const string &pass_name, int num_components, float *pixels);
   bool set_render_tile_pixels(const string &pass_name, int num_components, const float *pixels);



More information about the Bf-blender-cvs mailing list