[Bf-blender-cvs] [81634e83794] cycles-x: Cycles X: Refactor noisy/denoised passes access

Sergey Sharybin noreply at git.blender.org
Fri Jun 11 16:56:38 CEST 2021


Commit: 81634e83794ccbc29ca23c886917d4287d1f81fb
Author: Sergey Sharybin
Date:   Thu Jun 10 18:22:02 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB81634e83794ccbc29ca23c886917d4287d1f81fb

Cycles X: Refactor noisy/denoised passes access

The goal is to make it easily to extend denoising support for passes
like light passes and shadow catcher, without need to double-write in
the kernel, and without duplicating pass type for every noisy/denoised
combination.

Avoid double-write of noisy pass in the kernel, introducing an explicit
separation of noisy pass written by the kernel and denoised pass written
by a denoiser.

The idea is to allow marking pass as "please read denoised result of the
type when available". If there is no denoiser configured, then the pass
will access its noisy data (and no data will be allocated for the pass
which is requesting to return denoised result).

It is possible to simplify some of the pass accessing in the denoisers,
as well as possibly avoiding memory allocation. Will look into this as
a followup development related on making denoiser able to denoise any
input.

The positive side is that now there is no need in the denoised pass
film convert kernel.

Should be no functional changes.

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

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

M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/device/device_kernel.cpp
M	intern/cycles/device/optix/device_impl.cpp
M	intern/cycles/integrator/denoiser_oidn.cpp
M	intern/cycles/integrator/pass_accessor.cpp
M	intern/cycles/integrator/pass_accessor.h
M	intern/cycles/integrator/pass_accessor_cpu.cpp
M	intern/cycles/integrator/pass_accessor_cpu.h
M	intern/cycles/integrator/pass_accessor_gpu.cpp
M	intern/cycles/integrator/pass_accessor_gpu.h
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/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
M	intern/cycles/kernel/device/cuda/kernel.cu
M	intern/cycles/kernel/kernel_accumulate.h
M	intern/cycles/kernel/kernel_film.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/bake.cpp
M	intern/cycles/render/buffers.cpp
M	intern/cycles/render/buffers.h
M	intern/cycles/render/film.cpp
M	intern/cycles/render/film.h
M	intern/cycles/render/pass.cpp
M	intern/cycles/render/pass.h
M	intern/cycles/render/scene.cpp
M	intern/cycles/render/session.cpp

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

diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index 0b5c171b0cb..69d1e3003dd 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -631,7 +631,7 @@ void BlenderSession::bake(BL::Depsgraph &b_depsgraph_,
   /* Add render pass that we want to bake, and name it Combined so that it is
    * used as that on the Blender side. */
   const PassType pass_type = bake_type_to_pass(bake_type, bake_filter);
-  Pass::add(pass_type, scene->passes, "Combined");
+  Pass::add(scene->passes, pass_type, "Combined");
 
   session->read_render_tile_cb = [&]() { read_render_tile(); };
   session->write_render_tile_cb = [&]() { write_render_tile(); };
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index 3d1a4eaac60..240f5c3b079 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -496,16 +496,32 @@ void BlenderSync::sync_images()
 }
 
 /* Passes */
-static PassType get_pass_type(BL::RenderPass &b_pass)
+
+class BlenderPassInfo {
+ public:
+  explicit BlenderPassInfo(PassType type = PASS_NONE, PassMode mode = PassMode::NOISY)
+      : type(type), mode(mode)
+  {
+  }
+
+  PassType type = PASS_NONE;
+  PassMode mode = PassMode::NOISY;
+};
+
+static BlenderPassInfo get_blender_pass_info(BL::RenderPass &b_pass)
 {
   string name = b_pass.name();
-#define MAP_PASS(passname, passtype) \
+#define MAP_PASS(passname, ...) \
   if (name == passname) { \
-    return passtype; \
+    return BlenderPassInfo(__VA_ARGS__); \
   } \
   ((void)0)
+
   /* NOTE: Keep in sync with defined names from DNA_scene_types.h */
-  MAP_PASS("Combined", PASS_COMBINED);
+
+  MAP_PASS("Combined", PASS_COMBINED, PassMode::DENOISED);
+  MAP_PASS("Noisy Image", PASS_COMBINED);
+
   MAP_PASS("Depth", PASS_DEPTH);
   MAP_PASS("Mist", PASS_MIST);
   MAP_PASS("Normal", PASS_NORMAL);
@@ -536,7 +552,6 @@ static PassType get_pass_type(BL::RenderPass &b_pass)
   MAP_PASS("BakePrimitive", PASS_BAKE_PRIMITIVE);
   MAP_PASS("BakeDifferential", PASS_BAKE_DIFFERENTIAL);
 
-  MAP_PASS("Noisy Image", PASS_DENOISING_COLOR);
   MAP_PASS("Denoising Normal", PASS_DENOISING_NORMAL);
   MAP_PASS("Denoising Albedo", PASS_DENOISING_ALBEDO);
 
@@ -548,12 +563,12 @@ static PassType get_pass_type(BL::RenderPass &b_pass)
   MAP_PASS("Debug Sample Count", PASS_SAMPLE_COUNT);
 
   if (string_startswith(name, cryptomatte_prefix)) {
-    return PASS_CRYPTOMATTE;
+    return BlenderPassInfo(PASS_CRYPTOMATTE);
   }
 
 #undef MAP_PASS
 
-  return PASS_NONE;
+  return BlenderPassInfo(PASS_NONE);
 }
 
 void BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_view_layer)
@@ -564,51 +579,62 @@ void BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_v
 
   /* loop over passes */
   for (BL::RenderPass &b_pass : b_rlay.passes) {
-    PassType pass_type = get_pass_type(b_pass);
+    const BlenderPassInfo pass_info = get_blender_pass_info(b_pass);
 
-    if (pass_type == PASS_MOTION && b_scene.render().use_motion_blur())
+    if (pass_info.type == PASS_NONE) {
+      LOG(ERROR) << "Unknown pass " << b_pass.name();
       continue;
-    if (pass_type != PASS_NONE)
-      Pass::add(pass_type, passes, b_pass.name().c_str());
+    }
+
+    if (pass_info.type == PASS_MOTION && b_scene.render().use_motion_blur()) {
+      continue;
+    }
+
+    if (pass_info.mode == PassMode::DENOISED) {
+      Pass::add_denoising_read(passes, pass_info.type, b_pass.name().c_str());
+    }
+    else {
+      Pass::add(passes, pass_info.type, b_pass.name().c_str());
+    }
   }
 
   PointerRNA crl = RNA_pointer_get(&b_view_layer.ptr, "cycles");
 
   if (get_boolean(crl, "denoising_store_passes")) {
     b_engine.add_pass("Noisy Image", 4, "RGBA", b_view_layer.name().c_str());
-    Pass::add(PASS_DENOISING_COLOR, passes, "Noisy Image");
+    Pass::add(passes, PASS_COMBINED, "Noisy Image");
 
     b_engine.add_pass("Denoising Normal", 3, "XYZ", b_view_layer.name().c_str());
-    Pass::add(PASS_DENOISING_NORMAL, passes, "Denoising Normal");
+    Pass::add(passes, PASS_DENOISING_NORMAL, "Denoising Normal");
 
     b_engine.add_pass("Denoising Albedo", 3, "RGB", b_view_layer.name().c_str());
-    Pass::add(PASS_DENOISING_ALBEDO, passes, "Denoising Albedo");
+    Pass::add(passes, PASS_DENOISING_ALBEDO, "Denoising Albedo");
   }
   else if (get_boolean(cscene, "use_denoising")) {
     b_engine.add_pass("Noisy Image", 4, "RGBA", b_view_layer.name().c_str());
-    Pass::add(PASS_DENOISING_COLOR, passes, "Noisy Image");
+    Pass::add(passes, PASS_COMBINED, "Noisy Image");
   }
 
   if (get_boolean(crl, "pass_debug_render_time")) {
     b_engine.add_pass("Debug Render Time", 1, "X", b_view_layer.name().c_str());
-    Pass::add(PASS_RENDER_TIME, passes, "Debug Render Time");
+    Pass::add(passes, PASS_RENDER_TIME, "Debug Render Time");
   }
   if (get_boolean(crl, "pass_debug_sample_count")) {
     b_engine.add_pass("Debug Sample Count", 1, "X", b_view_layer.name().c_str());
-    Pass::add(PASS_SAMPLE_COUNT, passes, "Debug Sample Count");
+    Pass::add(passes, PASS_SAMPLE_COUNT, "Debug Sample Count");
   }
   if (get_boolean(crl, "use_pass_volume_direct")) {
     b_engine.add_pass("VolumeDir", 3, "RGB", b_view_layer.name().c_str());
-    Pass::add(PASS_VOLUME_DIRECT, passes, "VolumeDir");
+    Pass::add(passes, PASS_VOLUME_DIRECT, "VolumeDir");
   }
   if (get_boolean(crl, "use_pass_volume_indirect")) {
     b_engine.add_pass("VolumeInd", 3, "RGB", b_view_layer.name().c_str());
-    Pass::add(PASS_VOLUME_INDIRECT, passes, "VolumeInd");
+    Pass::add(passes, PASS_VOLUME_INDIRECT, "VolumeInd");
   }
 
   if (get_boolean(crl, "use_pass_shadow_catcher")) {
     b_engine.add_pass("Shadow Catcher", 4, "RGBA", b_view_layer.name().c_str());
-    Pass::add(PASS_SHADOW_CATCHER, passes, "Shadow Catcher");
+    Pass::add(passes, PASS_SHADOW_CATCHER, "Shadow Catcher");
   }
 
   /* Cryptomatte stores two ID/weight pairs per RGBA layer.
@@ -620,7 +646,7 @@ void BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_v
     for (int i = 0; i < crypto_depth; i++) {
       string passname = cryptomatte_prefix + string_printf("Object%02d", i);
       b_engine.add_pass(passname.c_str(), 4, "RGBA", b_view_layer.name().c_str());
-      Pass::add(PASS_CRYPTOMATTE, passes, passname.c_str());
+      Pass::add(passes, PASS_CRYPTOMATTE, passname.c_str());
     }
     cryptomatte_passes = (CryptomatteType)(cryptomatte_passes | CRYPT_OBJECT);
   }
@@ -628,7 +654,7 @@ void BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_v
     for (int i = 0; i < crypto_depth; i++) {
       string passname = cryptomatte_prefix + string_printf("Material%02d", i);
       b_engine.add_pass(passname.c_str(), 4, "RGBA", b_view_layer.name().c_str());
-      Pass::add(PASS_CRYPTOMATTE, passes, passname.c_str());
+      Pass::add(passes, PASS_CRYPTOMATTE, passname.c_str());
     }
     cryptomatte_passes = (CryptomatteType)(cryptomatte_passes | CRYPT_MATERIAL);
   }
@@ -636,7 +662,7 @@ void BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_v
     for (int i = 0; i < crypto_depth; i++) {
       string passname = cryptomatte_prefix + string_printf("Asset%02d", i);
       b_engine.add_pass(passname.c_str(), 4, "RGBA", b_view_layer.name().c_str());
-      Pass::add(PASS_CRYPTOMATTE, passes, passname.c_str());
+      Pass::add(passes, PASS_CRYPTOMATTE, passname.c_str());
     }
     cryptomatte_passes = (CryptomatteType)(cryptomatte_passes | CRYPT_ASSET);
   }
@@ -657,11 +683,11 @@ void BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_v
 
     if (is_color) {
       b_engine.add_pass(name.c_str(), 4, "RGBA", b_view_layer.name().c_str());
-      Pass::add(PASS_AOV_COLOR, passes, name.c_str());
+      Pass::add(passes, PASS_AOV_COLOR, name.c_str());
     }
     else {
       b_engine.add_pass(name.c_str(), 1, "X", b_view_layer.name().c_str());
-      Pass::add(PASS_AOV_VALUE, passes, name.c_str());
+      Pass::add(passes, PASS_AOV_VALUE, name.c_str());
     }
   }
 
diff --git a/intern/cycles/device/device_kernel.cpp b/intern/cycles/device/device_kernel.cpp
index 08945b56fa1..45e73710530 100644
--- a/intern/cycles/device/device_kernel.cpp
+++ b/intern/cycles/device/device_kernel.cpp
@@ -90,8 +90,6 @@ const char *device_kernel_as_string(DeviceKernel kernel)
       return "film_convert_motion_half_rgba";
     case DEVICE_KERNEL_FILM_CONVERT_CRYPTOMATTE_HALF_RGBA:
       return "film_convert_cryptomatte_half_rgba";
-    case DEVICE_KERNEL_FILM_CONVERT_DENOISING_COLOR_HALF_RGBA:
-      return "film_convert_denoising_color_half_rgba";
     case DEVICE_KERNEL_FILM_CONVERT_SHADOW_CATCHER_HALF_RGBA:
       return "film_convert_shadow_catcher_half_rgba";
     case DEVICE_KERNEL_FILM_CONVERT_SHADOW_CATCHER_MATTE_WITH_SHADOW_HALF_RGBA:
diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp
index c026daaf287..b9f624f0ba0 100644
--- a/intern/cycles/device/optix/device_impl.cpp
+++ b/intern/cycles/device/optix/device_impl.cpp
@@ -585,7 +585,7 @@ bool OptiXDevice::denoise_filter_convert_to_rgb(OptiXDeviceQueue *queue,
 {
   const int work_size = task.buffer_params.width * task.buffer_params.height;
 
-  const int pass_offset[3] = {task.buffer_params.get_pass_offset(PASS_DENOISING_COLOR),
+  const int pass_offset[3] = {task.buffer_params.get_pass_offset(PASS_COMBINED),
                               task.buffer_params.get_pass_offset(PASS_DENOISING_ALBEDO),
                               task.buffer_params.get_pass_offset(PASS_DENOISING_NORMAL)};
 
@@ -616,6 +616,8 @@ bool OptiXDevice::denoise_filter_convert_from_rgb(OptiXDeviceQueue *queue,
 {
   const int work_size = task.buffer_params.width * task.buffer_params.height;
 
+  const int pass_combined_denoised = task.buffer_params.get_pass_offset(PASS_COMBINED,
+                                                                        PassMode::DENOISED);
   const int pass_sample_count = task.buffer_params.get_pass_offset(PASS_SAMPLE_COUNT);
 
   void *args[] = {const_cast<device_ptr *>(&d_input_rgb),
@@ -628,6 +630,7 @@ bool

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list