[Bf-blender-cvs] [379a5cb79c2] cycles-x: Cycles X: Use pass accessor for viewport on CPU

Sergey Sharybin noreply at git.blender.org
Thu Jun 3 16:11:42 CEST 2021


Commit: 379a5cb79c291e26a3e8bd9fb6c59eb7f908bcd5
Author: Sergey Sharybin
Date:   Wed Jun 2 16:44:49 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB379a5cb79c291e26a3e8bd9fb6c59eb7f908bcd5

Cycles X: Use pass accessor for viewport on CPU

No functional changes, no measurable time difference.

Quite boring on itself, but it opens doors for support of shadow
catcher pass in the viewport.

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

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

M	intern/cycles/device/cpu/kernel.cpp
M	intern/cycles/device/cpu/kernel.h
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/path_trace.cpp
M	intern/cycles/integrator/path_trace.h
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/cpu/kernel_arch.h
M	intern/cycles/kernel/device/cpu/kernel_arch_impl.h
M	intern/cycles/kernel/kernel_film.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/film.cpp
M	intern/cycles/render/session.cpp

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

diff --git a/intern/cycles/device/cpu/kernel.cpp b/intern/cycles/device/cpu/kernel.cpp
index fd3614205db..59daf836560 100644
--- a/intern/cycles/device/cpu/kernel.cpp
+++ b/intern/cycles/device/cpu/kernel.cpp
@@ -39,8 +39,6 @@ CPUKernels::CPUKernels()
       REGISTER_KERNEL(integrator_shade_surface),
       REGISTER_KERNEL(integrator_shade_volume),
       REGISTER_KERNEL(integrator_megakernel),
-      /* Film. */
-      REGISTER_KERNEL(convert_to_half_float),
       /* Shader evaluation. */
       REGISTER_KERNEL(shader_eval_displace),
       REGISTER_KERNEL(shader_eval_background),
diff --git a/intern/cycles/device/cpu/kernel.h b/intern/cycles/device/cpu/kernel.h
index f3990f3f2f2..b691061b2a3 100644
--- a/intern/cycles/device/cpu/kernel.h
+++ b/intern/cycles/device/cpu/kernel.h
@@ -49,19 +49,6 @@ class CPUKernels {
   IntegratorShadeFunction integrator_shade_volume;
   IntegratorShadeFunction integrator_megakernel;
 
-  /* Film. */
-
-  using ConvertToHalfFloatFunction = CPUKernelFunction<void (*)(const KernelGlobals *kg,
-                                                                uchar4 *rgba,
-                                                                float *buffer,
-                                                                float sample_scale,
-                                                                int x,
-                                                                int y,
-                                                                int offset,
-                                                                int stride)>;
-
-  ConvertToHalfFloatFunction convert_to_half_float;
-
   /* Shader evaluation. */
 
   using ShaderEvalFunction = CPUKernelFunction<void (*)(
diff --git a/intern/cycles/integrator/pass_accessor.cpp b/intern/cycles/integrator/pass_accessor.cpp
index 0a9f3243cc8..e46b202e684 100644
--- a/intern/cycles/integrator/pass_accessor.cpp
+++ b/intern/cycles/integrator/pass_accessor.cpp
@@ -21,6 +21,10 @@
 
 CCL_NAMESPACE_BEGIN
 
+/* --------------------------------------------------------------------
+ * Pass input information.
+ */
+
 PassAccessor::PassAccessInfo::PassAccessInfo(const Pass &pass,
                                              const Film &film,
                                              const vector<Pass> &passes)
@@ -30,28 +34,65 @@ PassAccessor::PassAccessInfo::PassAccessInfo(const Pass &pass,
 {
 }
 
-PassAccessor::PassAccessor(const PassAccessInfo &pass_access_info,
-                           int num_components,
-                           float exposure,
-                           int num_samples)
-    : pass_access_info_(pass_access_info),
-      num_components_(num_components),
-      exposure_(exposure),
-      num_samples_(num_samples)
+/* --------------------------------------------------------------------
+ * Pass destination.
+ */
+
+PassAccessor::Destination::Destination(float *pixels, int num_components)
+    : pixels(pixels), num_components(num_components)
+{
+}
+
+PassAccessor::Destination::Destination(const PassType pass_type, half4 *pixels)
+    : pixels_half_rgba(pixels)
+{
+  const PassInfo pass_info = Pass::get_info(pass_type);
+
+  if (pass_info.divide_type != PASS_NONE) {
+    /* Divide is used for colors, which has 3 destination components.
+     * The passes which use division are stored as aligned float4 internally, and there is no
+     * implementation of divide_even_color for float4. So we force it here.
+     * The rest of the aligned float3 passes should be fine, because they have float4
+     * implementation. */
+    num_components = 3;
+  }
+  else {
+    num_components = pass_info.num_components;
+  }
+}
+
+/* --------------------------------------------------------------------
+ * Pass accessor.
+ */
+
+PassAccessor::PassAccessor(const PassAccessInfo &pass_access_info, float exposure, int num_samples)
+    : pass_access_info_(pass_access_info), exposure_(exposure), num_samples_(num_samples)
+{
+}
+
+bool PassAccessor::get_render_tile_pixels(const RenderBuffers *render_buffers,
+                                          const Destination &destination) const
 {
+  if (render_buffers == nullptr || render_buffers->buffer.data() == nullptr) {
+    return false;
+  }
+
+  return get_render_tile_pixels(render_buffers, render_buffers->params, destination);
 }
 
-bool PassAccessor::get_render_tile_pixels(const RenderBuffers *render_buffers, float *pixels) const
+bool PassAccessor::get_render_tile_pixels(const RenderBuffers *render_buffers,
+                                          const BufferParams &buffer_params,
+                                          const Destination &destination) const
 {
-  if (render_buffers->buffer.data() == nullptr) {
+  if (render_buffers == nullptr || render_buffers->buffer.data() == nullptr) {
     return false;
   }
 
   const PassType type = pass_access_info_.type;
   const PassInfo pass_info = Pass::get_info(type);
 
-  if (num_components_ == 1) {
-    DCHECK_EQ(pass_info.num_components, num_components_)
+  if (destination.num_components == 1) {
+    DCHECK_EQ(pass_info.num_components, destination.num_components)
         << "Number of components mismatch for pass type " << pass_info.type;
 
     /* Scalar */
@@ -59,19 +100,19 @@ bool PassAccessor::get_render_tile_pixels(const RenderBuffers *render_buffers, f
       /* TODO(sergey): Needs implementation. */
     }
     else if (type == PASS_DEPTH) {
-      get_pass_depth(render_buffers, pixels);
+      get_pass_depth(render_buffers, buffer_params, destination);
     }
     else if (type == PASS_MIST) {
-      get_pass_mist(render_buffers, pixels);
+      get_pass_mist(render_buffers, buffer_params, destination);
     }
     else if (type == PASS_SAMPLE_COUNT) {
-      get_pass_sample_count(render_buffers, pixels);
+      get_pass_sample_count(render_buffers, buffer_params, destination);
     }
     else {
-      get_pass_float(render_buffers, pixels);
+      get_pass_float(render_buffers, buffer_params, destination);
     }
   }
-  else if (num_components_ == 3) {
+  else if (destination.num_components == 3) {
     if (pass_info.is_unaligned) {
       DCHECK_EQ(pass_info.num_components, 3)
           << "Number of components mismatch for pass type " << pass_info.type;
@@ -83,43 +124,43 @@ bool PassAccessor::get_render_tile_pixels(const RenderBuffers *render_buffers, f
 
     /* RGBA */
     if (type == PASS_SHADOW) {
-      get_pass_shadow3(render_buffers, pixels);
+      get_pass_shadow3(render_buffers, buffer_params, destination);
     }
     else if (pass_info.divide_type != PASS_NONE) {
       /* RGB lighting passes that need to divide out color */
-      get_pass_divide_even_color(render_buffers, pixels);
+      get_pass_divide_even_color(render_buffers, buffer_params, destination);
     }
     else {
       /* RGB/vector */
-      get_pass_float3(render_buffers, pixels);
+      get_pass_float3(render_buffers, buffer_params, destination);
     }
   }
-  else if (num_components_ == 4) {
+  else if (destination.num_components == 4) {
     DCHECK_EQ(pass_info.num_components, 4)
         << "Number of components mismatch for pass type " << pass_info.type;
 
     /* RGBA */
     if (type == PASS_SHADOW) {
-      get_pass_shadow4(render_buffers, pixels);
+      get_pass_shadow4(render_buffers, buffer_params, destination);
     }
     else if (type == PASS_MOTION) {
-      get_pass_motion(render_buffers, pixels);
+      get_pass_motion(render_buffers, buffer_params, destination);
     }
     else if (type == PASS_CRYPTOMATTE) {
-      get_pass_cryptomatte(render_buffers, pixels);
+      get_pass_cryptomatte(render_buffers, buffer_params, destination);
     }
     else if (type == PASS_DENOISING_COLOR) {
-      get_pass_denoising_color(render_buffers, pixels);
+      get_pass_denoising_color(render_buffers, buffer_params, destination);
     }
     else if (type == PASS_SHADOW_CATCHER) {
-      get_pass_shadow_catcher(render_buffers, pixels);
+      get_pass_shadow_catcher(render_buffers, buffer_params, destination);
     }
     else if (type == PASS_SHADOW_CATCHER_MATTE &&
              pass_access_info_.use_approximate_shadow_catcher) {
-      get_pass_shadow_catcher_matte_with_shadow(render_buffers, pixels);
+      get_pass_shadow_catcher_matte_with_shadow(render_buffers, buffer_params, destination);
     }
     else {
-      get_pass_float4(render_buffers, pixels);
+      get_pass_float4(render_buffers, buffer_params, destination);
     }
   }
 
diff --git a/intern/cycles/integrator/pass_accessor.h b/intern/cycles/integrator/pass_accessor.h
index 5a164979aaf..d478e9a9918 100644
--- a/intern/cycles/integrator/pass_accessor.h
+++ b/intern/cycles/integrator/pass_accessor.h
@@ -17,6 +17,7 @@
 #pragma once
 
 #include "render/pass.h"
+#include "util/util_half.h"
 #include "util/util_string.h"
 #include "util/util_vector.h"
 
@@ -24,6 +25,7 @@ CCL_NAMESPACE_BEGIN
 
 class Film;
 class RenderBuffers;
+class BufferParams;
 
 /* Helper class which allows to access pass data.
  * Is designed in a way that it is created once when the pass data is known, and then pixels gets
@@ -42,19 +44,34 @@ class PassAccessor {
      * matte pass, so that both artificial objects and shadows can be alpha-overed onto a backdrop.
      */
     bool use_approximate_shadow_catcher = false;
+
+    bool show_active_pixels = false;
   };
 
-  PassAccessor(const PassAccessInfo &pass_access_info,
-               int num_pixel_components,
-               float exposure,
-               int num_samples);
+  class Destination {
+   public:
+    Destination() = default;
+    Destination(float *pixels, int num_components);
+    Destination(const PassType pass_type, half4 *pixels);
+
+    float *pixels = nullptr;
+    half4 *pixels_half_rgba = nullptr;
+
+    int num_components = 0;
+  };
+
+  PassAccessor(const PassAccessInfo &pass_access_info, float exposure, int num_samples);
 
   virtual ~PassAccessor() = default;
 
   /* Get pass data from the given render buffers, perform needed filtering, and store result into
    * the pixels.
    * The result is stored sequentially starting from the very beginning of the pixels memory. */
-  bool get_render_tile_pixels(const RenderBuffers *render_buffers, float *

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list