[Bf-blender-cvs] [048a515ef42] cycles-x: Cycles X: Ensure buffers zero/copy happens in a desired order
Sergey Sharybin
noreply at git.blender.org
Mon Jul 5 17:24:34 CEST 2021
Commit: 048a515ef42853974b5e80d0f3a6c6eee64399f4
Author: Sergey Sharybin
Date: Mon Jul 5 14:14:02 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB048a515ef42853974b5e80d0f3a6c6eee64399f4
Cycles X: Ensure buffers zero/copy happens in a desired order
Use GPU queue to perform buffers copy form/to and zero operations,
so that things happens in proper order with the `render_samples()`.
Seems to solve artifacts when using OptiX denoiser in viewport and
dual GPU rendering.
Differential Revision: https://developer.blender.org/D11809
===================================================================
M intern/cycles/integrator/path_trace.cpp
M intern/cycles/integrator/path_trace_work.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
M intern/cycles/integrator/path_trace_work_gpu.cpp
M intern/cycles/integrator/path_trace_work_gpu.h
===================================================================
diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp
index 3d434c5beda..b0581503641 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -285,8 +285,7 @@ void PathTrace::init_render_buffers(const RenderWork &render_work)
/* Handle initialization scheduled by the render scheduler. */
if (render_work.init_render_buffers) {
tbb::parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
- RenderBuffers *buffers = path_trace_work->get_render_buffers();
- buffers->zero();
+ path_trace_work->zero_render_buffers();
});
buffer_read();
@@ -618,8 +617,7 @@ void PathTrace::buffer_read()
if (buffer_read_cb()) {
tbb::parallel_for_each(path_trace_works_, [](unique_ptr<PathTraceWork> &path_trace_work) {
- RenderBuffers *buffers = path_trace_work->get_render_buffers();
- buffers->copy_to_device();
+ path_trace_work->copy_render_buffers_to_device();
});
}
}
@@ -661,7 +659,7 @@ bool PathTrace::copy_render_tile_from_device()
if (!success) {
return;
}
- if (!path_trace_work->copy_render_tile_from_device()) {
+ if (!path_trace_work->copy_render_buffers_from_device()) {
success = false;
}
});
diff --git a/intern/cycles/integrator/path_trace_work.cpp b/intern/cycles/integrator/path_trace_work.cpp
index c7e0c06145c..90ff2f86d3f 100644
--- a/intern/cycles/integrator/path_trace_work.cpp
+++ b/intern/cycles/integrator/path_trace_work.cpp
@@ -76,7 +76,7 @@ bool PathTraceWork::has_multiple_works() const
void PathTraceWork::copy_to_render_buffers(RenderBuffers *render_buffers)
{
- buffers_->copy_from_device();
+ copy_render_buffers_from_device();
const int64_t width = effective_buffer_params_.width;
const int64_t height = effective_buffer_params_.height;
@@ -109,12 +109,7 @@ void PathTraceWork::copy_from_render_buffers(const RenderBuffers *render_buffers
memcpy(dst, src, data_size);
- buffers_->copy_to_device();
-}
-
-bool PathTraceWork::copy_render_tile_from_device()
-{
- return buffers_->copy_from_device();
+ copy_render_buffers_to_device();
}
bool PathTraceWork::get_render_tile_pixels(const PassAccessor &pass_accessor,
diff --git a/intern/cycles/integrator/path_trace_work.h b/intern/cycles/integrator/path_trace_work.h
index 3cc9abacc00..b69694c20f0 100644
--- a/intern/cycles/integrator/path_trace_work.h
+++ b/intern/cycles/integrator/path_trace_work.h
@@ -91,7 +91,14 @@ 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();
+ /* Copy render buffers to/from device using an appropriate device queue when needed so that
+ * things are executed in order with the `render_samples()`. */
+ virtual bool copy_render_buffers_from_device() = 0;
+ virtual bool copy_render_buffers_to_device() = 0;
+
+ /* Zero render buffers to/from device using an appropriate device queue when needed so that
+ * things are executed in order with the `render_samples()`. */
+ virtual bool zero_render_buffers() = 0;
/* Access pixels rendered by this work and copy them to the coresponding location in the
* destination.
diff --git a/intern/cycles/integrator/path_trace_work_cpu.cpp b/intern/cycles/integrator/path_trace_work_cpu.cpp
index a66492f0f03..5f4ef5a9dbc 100644
--- a/intern/cycles/integrator/path_trace_work_cpu.cpp
+++ b/intern/cycles/integrator/path_trace_work_cpu.cpp
@@ -173,6 +173,23 @@ void PathTraceWorkCPU::copy_to_gpu_display(GPUDisplay *gpu_display,
gpu_display->unmap_texture_buffer();
}
+bool PathTraceWorkCPU::copy_render_buffers_from_device()
+{
+ return buffers_->copy_from_device();
+}
+
+bool PathTraceWorkCPU::copy_render_buffers_to_device()
+{
+ buffers_->buffer.copy_to_device();
+ return true;
+}
+
+bool PathTraceWorkCPU::zero_render_buffers()
+{
+ buffers_->zero();
+ return true;
+}
+
int PathTraceWorkCPU::adaptive_sampling_converge_filter_count_active(float threshold, bool reset)
{
const int full_x = effective_buffer_params_.full_x;
diff --git a/intern/cycles/integrator/path_trace_work_cpu.h b/intern/cycles/integrator/path_trace_work_cpu.h
index 09b24b55e35..80d43c1c082 100644
--- a/intern/cycles/integrator/path_trace_work_cpu.h
+++ b/intern/cycles/integrator/path_trace_work_cpu.h
@@ -49,6 +49,10 @@ class PathTraceWorkCPU : public PathTraceWork {
PassMode pass_mode,
int num_samples) override;
+ virtual bool copy_render_buffers_from_device() override;
+ virtual bool copy_render_buffers_to_device() override;
+ virtual bool zero_render_buffers() override;
+
virtual int adaptive_sampling_converge_filter_count_active(float threshold, bool reset) override;
protected:
diff --git a/intern/cycles/integrator/path_trace_work_gpu.cpp b/intern/cycles/integrator/path_trace_work_gpu.cpp
index 8303e33abfb..a152d987f41 100644
--- a/intern/cycles/integrator/path_trace_work_gpu.cpp
+++ b/intern/cycles/integrator/path_trace_work_gpu.cpp
@@ -829,6 +829,32 @@ void PathTraceWorkGPU::enqueue_adaptive_sampling_filter_y()
queue_->enqueue(DEVICE_KERNEL_ADAPTIVE_SAMPLING_CONVERGENCE_FILTER_Y, work_size, args);
}
+bool PathTraceWorkGPU::copy_render_buffers_from_device()
+{
+ queue_->copy_from_device(buffers_->buffer);
+
+ /* Synchronize so that the CPU-side buffer is available at the exit of this function. */
+ return queue_->synchronize();
+}
+
+bool PathTraceWorkGPU::copy_render_buffers_to_device()
+{
+ queue_->copy_to_device(buffers_->buffer);
+
+ /* NOTE: The direct device access to the buffers only happens within this path trace work. The
+ * rest of communication happens via API calls which involves `copy_render_buffers_from_device()`
+ * which will perform synchronization as needed. */
+
+ return true;
+}
+
+bool PathTraceWorkGPU::zero_render_buffers()
+{
+ queue_->zero_to_device(buffers_->buffer);
+
+ return true;
+}
+
bool PathTraceWorkGPU::has_shadow_catcher() const
{
return device_scene_->data.integrator.has_shadow_catcher;
diff --git a/intern/cycles/integrator/path_trace_work_gpu.h b/intern/cycles/integrator/path_trace_work_gpu.h
index e163d9690af..69475ed0a1b 100644
--- a/intern/cycles/integrator/path_trace_work_gpu.h
+++ b/intern/cycles/integrator/path_trace_work_gpu.h
@@ -46,6 +46,10 @@ class PathTraceWorkGPU : public PathTraceWork {
PassMode pass_mode,
int num_samples) override;
+ virtual bool copy_render_buffers_from_device() override;
+ virtual bool copy_render_buffers_to_device() override;
+ virtual bool zero_render_buffers() override;
+
virtual int adaptive_sampling_converge_filter_count_active(float threshold, bool reset) override;
protected:
More information about the Bf-blender-cvs
mailing list