Commit: 767d501e2859c3acd854716ddd7f330d99be1479
Author: Sergey Sharybin
Date:   Thu Jun 10 18:04:31 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB767d501e2859c3acd854716ddd7f330d99be1479

Cycles X: De-duplicate shadow pass accessor kernel

The downside is that there is one extra if statement per pixel, but it
is probably unmeasurable because of other calculations involved. Could
not run actual numbers because it is not a function which is run often.

The upside is that it opens possibilities for ease support of passes
with optional alpha channel. For example, it will become useful for
shadow catcher pass denoising.

We can also now implement passes with divider for both RGB and RGBA
destinations and get rid of an exception in the pass Destination
constructor.

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

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

M       intern/cycles/device/device_kernel.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/kernel/device/cuda/kernel.cu
M       intern/cycles/kernel/kernel_film.h
M       intern/cycles/kernel/kernel_types.h

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

diff --git a/intern/cycles/device/device_kernel.cpp 
b/intern/cycles/device/device_kernel.cpp
index 345d0befc0e..08945b56fa1 100644
--- a/intern/cycles/device/device_kernel.cpp
+++ b/intern/cycles/device/device_kernel.cpp
@@ -80,14 +80,12 @@ const char *device_kernel_as_string(DeviceKernel kernel)
       return "film_convert_sample_count_half_rgba";
     case DEVICE_KERNEL_FILM_CONVERT_FLOAT_HALF_RGBA:
       return "film_convert_float_half_rgba";
-    case DEVICE_KERNEL_FILM_CONVERT_SHADOW3_HALF_RGBA:
-      return "film_convert_shadow3_half_rgba";
+    case DEVICE_KERNEL_FILM_CONVERT_SHADOW_HALF_RGBA:
+      return "film_convert_shadow_half_rgba";
     case DEVICE_KERNEL_FILM_CONVERT_DIVIDE_EVEN_COLOR_HALF_RGBA:
       return "film_convert_divide_even_color_half_rgba";
     case DEVICE_KERNEL_FILM_CONVERT_FLOAT3_HALF_RGBA:
       return "film_convert_float3_half_rgba";
-    case DEVICE_KERNEL_FILM_CONVERT_SHADOW4_HALF_RGBA:
-      return "film_convert_shadow4_half_rgba";
     case DEVICE_KERNEL_FILM_CONVERT_MOTION_HALF_RGBA:
       return "film_convert_motion_half_rgba";
     case DEVICE_KERNEL_FILM_CONVERT_CRYPTOMATTE_HALF_RGBA:
diff --git a/intern/cycles/integrator/pass_accessor.cpp 
b/intern/cycles/integrator/pass_accessor.cpp
index 803792524f0..65eea6c1609 100644
--- a/intern/cycles/integrator/pass_accessor.cpp
+++ b/intern/cycles/integrator/pass_accessor.cpp
@@ -186,7 +186,7 @@ bool PassAccessor::get_render_tile_pixels(const 
RenderBuffers *render_buffers,
 
     /* RGBA */
     if (type == PASS_SHADOW) {
-      get_pass_shadow3(render_buffers, buffer_params, destination);
+      get_pass_shadow(render_buffers, buffer_params, destination);
     }
     else if (pass_info.divide_type != PASS_NONE) {
       /* RGB lighting passes that need to divide out color */
@@ -208,7 +208,7 @@ bool PassAccessor::get_render_tile_pixels(const 
RenderBuffers *render_buffers,
 
       /* RGBA */
       if (type == PASS_SHADOW) {
-        get_pass_shadow4(render_buffers, buffer_params, destination);
+        get_pass_shadow(render_buffers, buffer_params, destination);
       }
       else if (type == PASS_MOTION) {
         get_pass_motion(render_buffers, buffer_params, destination);
@@ -282,7 +282,8 @@ bool PassAccessor::set_pass_rect(PassType type, int 
components, float *pixels, i
 #endif
 
 void PassAccessor::init_kernel_film_convert(KernelFilmConvert *kfilm_convert,
-                                            const BufferParams &buffer_params) 
const
+                                            const BufferParams &buffer_params,
+                                            const Destination &destination) 
const
 {
   const PassInfo &pass_info = Pass::get_info(pass_access_info_.type);
 
@@ -321,6 +322,8 @@ void 
PassAccessor::init_kernel_film_convert(KernelFilmConvert *kfilm_convert,
 
   kfilm_convert->use_approximate_shadow_catcher = 
pass_access_info_.use_approximate_shadow_catcher;
   kfilm_convert->show_active_pixels = pass_access_info_.show_active_pixels;
+
+  kfilm_convert->num_components = destination.num_components;
 }
 
 bool PassAccessor::set_render_tile_pixels(RenderBuffers *render_buffers, const 
Source &source)
diff --git a/intern/cycles/integrator/pass_accessor.h 
b/intern/cycles/integrator/pass_accessor.h
index 69046533c64..78de0fb28c1 100644
--- a/intern/cycles/integrator/pass_accessor.h
+++ b/intern/cycles/integrator/pass_accessor.h
@@ -101,7 +101,8 @@ class PassAccessor {
 
  protected:
   virtual void init_kernel_film_convert(KernelFilmConvert *kfilm_convert,
-                                        const BufferParams &buffer_params) 
const;
+                                        const BufferParams &buffer_params,
+                                        const Destination &destination) const;
 
 #define DECLARE_PASS_ACCESSOR(pass) \
   virtual void get_pass_##pass(const RenderBuffers *render_buffers, \
@@ -115,12 +116,10 @@ class PassAccessor {
   DECLARE_PASS_ACCESSOR(float)
 
   /* Float3 passes. */
-  DECLARE_PASS_ACCESSOR(shadow3)
   DECLARE_PASS_ACCESSOR(divide_even_color)
   DECLARE_PASS_ACCESSOR(float3)
 
   /* Float4 passes. */
-  DECLARE_PASS_ACCESSOR(shadow4)
   DECLARE_PASS_ACCESSOR(motion)
   DECLARE_PASS_ACCESSOR(cryptomatte)
   DECLARE_PASS_ACCESSOR(denoising_color)
@@ -128,6 +127,9 @@ class PassAccessor {
   DECLARE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow)
   DECLARE_PASS_ACCESSOR(float4)
 
+  /* Float3 or Float4 passes. */
+  DECLARE_PASS_ACCESSOR(shadow)
+
 #undef DECLARE_PASS_ACCESSOR
 
   PassAccessInfo pass_access_info_;
diff --git a/intern/cycles/integrator/pass_accessor_cpu.cpp 
b/intern/cycles/integrator/pass_accessor_cpu.cpp
index 1e45f8ce2c0..7a2b49de74a 100644
--- a/intern/cycles/integrator/pass_accessor_cpu.cpp
+++ b/intern/cycles/integrator/pass_accessor_cpu.cpp
@@ -40,7 +40,7 @@ inline void 
PassAccessorCPU::run_get_pass_kernel_processor(const RenderBuffers *
                                                            const Processor 
&processor) const
 {
   KernelFilmConvert kfilm_convert;
-  init_kernel_film_convert(&kfilm_convert, buffer_params);
+  init_kernel_film_convert(&kfilm_convert, buffer_params, destination);
 
   if (destination.pixels) {
     /* NOTE: No overlays are applied since they are not used for final renders.
@@ -158,12 +158,10 @@ DEFINE_PASS_ACCESSOR(sample_count)
 DEFINE_PASS_ACCESSOR(float)
 
 /* Float3 passes. */
-DEFINE_PASS_ACCESSOR(shadow3)
 DEFINE_PASS_ACCESSOR(divide_even_color)
 DEFINE_PASS_ACCESSOR(float3)
 
 /* Float4 passes. */
-DEFINE_PASS_ACCESSOR(shadow4)
 DEFINE_PASS_ACCESSOR(motion)
 DEFINE_PASS_ACCESSOR(cryptomatte)
 DEFINE_PASS_ACCESSOR(denoising_color)
@@ -171,6 +169,9 @@ DEFINE_PASS_ACCESSOR(shadow_catcher)
 DEFINE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow)
 DEFINE_PASS_ACCESSOR(float4)
 
+/* Float3 or Float4 passes. */
+DEFINE_PASS_ACCESSOR(shadow)
+
 #undef DEFINE_PASS_ACCESSOR
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/integrator/pass_accessor_cpu.h 
b/intern/cycles/integrator/pass_accessor_cpu.h
index 61841d894cd..32f0e5156f1 100644
--- a/intern/cycles/integrator/pass_accessor_cpu.h
+++ b/intern/cycles/integrator/pass_accessor_cpu.h
@@ -60,12 +60,10 @@ class PassAccessorCPU : public PassAccessor {
   DECLARE_PASS_ACCESSOR(float)
 
   /* Float3 passes. */
-  DECLARE_PASS_ACCESSOR(shadow3)
   DECLARE_PASS_ACCESSOR(divide_even_color)
   DECLARE_PASS_ACCESSOR(float3)
 
   /* Float4 passes. */
-  DECLARE_PASS_ACCESSOR(shadow4)
   DECLARE_PASS_ACCESSOR(motion)
   DECLARE_PASS_ACCESSOR(cryptomatte)
   DECLARE_PASS_ACCESSOR(denoising_color)
@@ -73,6 +71,9 @@ class PassAccessorCPU : public PassAccessor {
   DECLARE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow)
   DECLARE_PASS_ACCESSOR(float4)
 
+  /* Float3 or Float4 passes. */
+  DECLARE_PASS_ACCESSOR(shadow)
+
 #undef DECLARE_PASS_ACCESSOR
 };
 
diff --git a/intern/cycles/integrator/pass_accessor_gpu.cpp 
b/intern/cycles/integrator/pass_accessor_gpu.cpp
index e2d2a1c27d8..e5fe2fa94fb 100644
--- a/intern/cycles/integrator/pass_accessor_gpu.cpp
+++ b/intern/cycles/integrator/pass_accessor_gpu.cpp
@@ -41,7 +41,7 @@ void PassAccessorGPU::run_film_convert_kernels(DeviceKernel 
kernel,
                                                const Destination &destination) 
const
 {
   KernelFilmConvert kfilm_convert;
-  init_kernel_film_convert(&kfilm_convert, buffer_params);
+  init_kernel_film_convert(&kfilm_convert, buffer_params, destination);
 
   const int work_size = buffer_params.width * buffer_params.height;
 
@@ -81,12 +81,10 @@ DEFINE_PASS_ACCESSOR(sample_count, SAMPLE_COUNT);
 DEFINE_PASS_ACCESSOR(float, FLOAT);
 
 /* Float3 passes. */
-DEFINE_PASS_ACCESSOR(shadow3, SHADOW3);
 DEFINE_PASS_ACCESSOR(divide_even_color, DIVIDE_EVEN_COLOR);
 DEFINE_PASS_ACCESSOR(float3, FLOAT3);
 
 /* Float4 passes. */
-DEFINE_PASS_ACCESSOR(shadow4, SHADOW4);
 DEFINE_PASS_ACCESSOR(motion, MOTION);
 DEFINE_PASS_ACCESSOR(cryptomatte, CRYPTOMATTE);
 DEFINE_PASS_ACCESSOR(denoising_color, DENOISING_COLOR);
@@ -94,6 +92,9 @@ DEFINE_PASS_ACCESSOR(shadow_catcher, SHADOW_CATCHER);
 DEFINE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow, 
SHADOW_CATCHER_MATTE_WITH_SHADOW);
 DEFINE_PASS_ACCESSOR(float4, FLOAT4);
 
+/* Float3 or Float4 passes. */
+DEFINE_PASS_ACCESSOR(shadow, SHADOW);
+
 #undef DEFINE_PASS_ACCESSOR
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/integrator/pass_accessor_gpu.h 
b/intern/cycles/integrator/pass_accessor_gpu.h
index 90a7c9cbb4c..69f3b287fe6 100644
--- a/intern/cycles/integrator/pass_accessor_gpu.h
+++ b/intern/cycles/integrator/pass_accessor_gpu.h
@@ -49,12 +49,10 @@ class PassAccessorGPU : public PassAccessor {
   DECLARE_PASS_ACCESSOR(float);
 
   /* Float3 passes. */
-  DECLARE_PASS_ACCESSOR(shadow3);
   DECLARE_PASS_ACCESSOR(divide_even_color);
   DECLARE_PASS_ACCESSOR(float3);
 
   /* Float4 passes. */
-  DECLARE_PASS_ACCESSOR(shadow4);
   DECLARE_PASS_ACCESSOR(motion);
   DECLARE_PASS_ACCESSOR(cryptomatte);
   DECLARE_PASS_ACCESSOR(denoising_color);
@@ -62,6 +60,9 @@ class PassAccessorGPU : public PassAccessor {
   DECLARE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow);
   DECLARE_PASS_ACCESSOR(float4);
 
+  /* Float3 or Float4 passes. */
+  DECLARE_PASS_ACCESSOR(shadow);
+
 #undef DECLARE_PASS_ACCESSOR
 
   DeviceQueue *queue_;
diff --git a/intern/cycles/kernel/device/cuda/kernel.cu 
b/intern/cycles/kernel/device/cuda/kernel.cu
index 852ce100c9f..ea82e3edfb3 100644
--- a/intern/cycles/kernel/device/cuda/kernel.cu
+++ b/intern/cycles/kernel/device/cuda/kernel.cu
@@ -556,11 +556,9 @@ KERNEL_FILM_CONVERT_DEFINE(mist, value)
 KERNEL_FILM_CONVERT_DEFINE(sample_count, value)
 KERNEL_FILM_CONVERT_DEFINE(float, value)
 
-KERNEL_FILM_CONVERT_DEFINE(shadow3, rgb)
 KERNEL_FILM_CONVERT_DEFINE(divide_even_color, rgb)
 KERNEL_FILM_CONVERT_DEFINE(float3, rgb)
 
-KERNEL_FILM_CONVERT_DEFINE(shadow4, rgba)
 KERNEL_FILM_CONVERT_DEFINE(motion, rgba)
 KERNEL_FILM_CONVERT_DEFINE(cryptomatte, rgba)
 KERNEL_FILM_CONVERT_DEFINE(denoising_color, rgba)
@@ -568,6 +566,8 @@ KERNEL_FILM_CONVERT_DEFINE(shadow_catcher, rgba)
 KERNEL_FILM_CONVERT_DEFINE(shadow_catcher_matte_with_shadow, rgba)
 KERNEL_FILM_CONVERT_DEFINE(float4, rgba)
 
+KERNEL_FILM_CONVERT_DEFINE(shadow, rgb)
+
 #  undef KERNEL_FILM_CONVERT_DEFINE
 #  undef KERNEL_FILM_CONVERT_HA

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to