[Bf-blender-cvs] [2ba7c3aa650] master: Cleanup: refactor to make number of channels for shader evaluation variable

Brecht Van Lommel noreply at git.blender.org
Fri Oct 15 15:59:42 CEST 2021


Commit: 2ba7c3aa650c3c795d903a24998204f67c75b017
Author: Brecht Van Lommel
Date:   Wed Oct 13 19:13:35 2021 +0200
Branches: master
https://developer.blender.org/rB2ba7c3aa650c3c795d903a24998204f67c75b017

Cleanup: refactor to make number of channels for shader evaluation variable

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

M	intern/cycles/device/cpu/kernel.h
M	intern/cycles/integrator/shader_eval.cpp
M	intern/cycles/integrator/shader_eval.h
M	intern/cycles/kernel/device/cpu/kernel_arch.h
M	intern/cycles/kernel/device/cpu/kernel_arch_impl.h
M	intern/cycles/kernel/device/gpu/kernel.h
M	intern/cycles/kernel/integrator/integrator_intersect_shadow.h
M	intern/cycles/kernel/kernel_bake.h
M	intern/cycles/render/light.cpp
M	intern/cycles/render/mesh_displace.cpp

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

diff --git a/intern/cycles/device/cpu/kernel.h b/intern/cycles/device/cpu/kernel.h
index 54b18308544..b5f0d873f30 100644
--- a/intern/cycles/device/cpu/kernel.h
+++ b/intern/cycles/device/cpu/kernel.h
@@ -54,7 +54,7 @@ class CPUKernels {
   /* Shader evaluation. */
 
   using ShaderEvalFunction = CPUKernelFunction<void (*)(
-      const KernelGlobals *kg, const KernelShaderEvalInput *, float4 *, const int)>;
+      const KernelGlobals *kg, const KernelShaderEvalInput *, float *, const int)>;
 
   ShaderEvalFunction shader_eval_displace;
   ShaderEvalFunction shader_eval_background;
diff --git a/intern/cycles/integrator/shader_eval.cpp b/intern/cycles/integrator/shader_eval.cpp
index a14e41ec5be..53546c03872 100644
--- a/intern/cycles/integrator/shader_eval.cpp
+++ b/intern/cycles/integrator/shader_eval.cpp
@@ -34,9 +34,10 @@ ShaderEval::ShaderEval(Device *device, Progress &progress) : device_(device), pr
 }
 
 bool ShaderEval::eval(const ShaderEvalType type,
-                      const int max_num_points,
+                      const int max_num_inputs,
+                      const int num_channels,
                       const function<int(device_vector<KernelShaderEvalInput> &)> &fill_input,
-                      const function<void(device_vector<float4> &)> &read_output)
+                      const function<void(device_vector<float> &)> &read_output)
 {
   bool first_device = true;
   bool success = true;
@@ -50,26 +51,27 @@ bool ShaderEval::eval(const ShaderEvalType type,
     first_device = false;
 
     device_vector<KernelShaderEvalInput> input(device, "ShaderEval input", MEM_READ_ONLY);
-    device_vector<float4> output(device, "ShaderEval output", MEM_READ_WRITE);
+    device_vector<float> output(device, "ShaderEval output", MEM_READ_WRITE);
 
     /* Allocate and copy device buffers. */
     DCHECK_EQ(input.device, device);
     DCHECK_EQ(output.device, device);
     DCHECK_LE(output.size(), input.size());
 
-    input.alloc(max_num_points);
+    input.alloc(max_num_inputs);
     int num_points = fill_input(input);
     if (num_points == 0) {
       return;
     }
 
     input.copy_to_device();
-    output.alloc(num_points);
+    output.alloc(num_points * num_channels);
     output.zero_to_device();
 
     /* Evaluate on CPU or GPU. */
-    success = (device->info.type == DEVICE_CPU) ? eval_cpu(device, type, input, output) :
-                                                  eval_gpu(device, type, input, output);
+    success = (device->info.type == DEVICE_CPU) ?
+                  eval_cpu(device, type, input, output, num_points) :
+                  eval_gpu(device, type, input, output, num_points);
 
     /* Copy data back from device if not canceled. */
     if (success) {
@@ -87,7 +89,8 @@ bool ShaderEval::eval(const ShaderEvalType type,
 bool ShaderEval::eval_cpu(Device *device,
                           const ShaderEvalType type,
                           device_vector<KernelShaderEvalInput> &input,
-                          device_vector<float4> &output)
+                          device_vector<float> &output,
+                          const int64_t work_size)
 {
   vector<CPUKernelThreadGlobals> kernel_thread_globals;
   device->get_cpu_kernel_thread_globals(kernel_thread_globals);
@@ -96,9 +99,8 @@ bool ShaderEval::eval_cpu(Device *device,
   const CPUKernels &kernels = *(device->get_cpu_kernels());
 
   /* Simple parallel_for over all work items. */
-  const int64_t work_size = output.size();
   KernelShaderEvalInput *input_data = input.data();
-  float4 *output_data = output.data();
+  float *output_data = output.data();
   bool success = true;
 
   tbb::task_arena local_arena(device->info.cpu_threads);
@@ -130,7 +132,8 @@ bool ShaderEval::eval_cpu(Device *device,
 bool ShaderEval::eval_gpu(Device *device,
                           const ShaderEvalType type,
                           device_vector<KernelShaderEvalInput> &input,
-                          device_vector<float4> &output)
+                          device_vector<float> &output,
+                          const int64_t work_size)
 {
   /* Find required kernel function. */
   DeviceKernel kernel;
@@ -151,7 +154,6 @@ bool ShaderEval::eval_gpu(Device *device,
    * TODO : query appropriate size from device.*/
   const int64_t chunk_size = 65536;
 
-  const int64_t work_size = output.size();
   void *d_input = (void *)input.device_pointer;
   void *d_output = (void *)output.device_pointer;
 
diff --git a/intern/cycles/integrator/shader_eval.h b/intern/cycles/integrator/shader_eval.h
index 7dbf334b8d7..013fad17d4f 100644
--- a/intern/cycles/integrator/shader_eval.h
+++ b/intern/cycles/integrator/shader_eval.h
@@ -40,19 +40,22 @@ class ShaderEval {
   /* Evaluate shader at points specified by KernelShaderEvalInput and write out
    * RGBA colors to output. */
   bool eval(const ShaderEvalType type,
-            const int max_num_points,
+            const int max_num_inputs,
+            const int num_channels,
             const function<int(device_vector<KernelShaderEvalInput> &)> &fill_input,
-            const function<void(device_vector<float4> &)> &read_output);
+            const function<void(device_vector<float> &)> &read_output);
 
  protected:
   bool eval_cpu(Device *device,
                 const ShaderEvalType type,
                 device_vector<KernelShaderEvalInput> &input,
-                device_vector<float4> &output);
+                device_vector<float> &output,
+                const int64_t work_size);
   bool eval_gpu(Device *device,
                 const ShaderEvalType type,
                 device_vector<KernelShaderEvalInput> &input,
-                device_vector<float4> &output);
+                device_vector<float> &output,
+                const int64_t work_size);
 
   Device *device_;
   Progress &progress_;
diff --git a/intern/cycles/kernel/device/cpu/kernel_arch.h b/intern/cycles/kernel/device/cpu/kernel_arch.h
index 81f328c710b..8b7b0ec0548 100644
--- a/intern/cycles/kernel/device/cpu/kernel_arch.h
+++ b/intern/cycles/kernel/device/cpu/kernel_arch.h
@@ -58,11 +58,11 @@ KERNEL_INTEGRATOR_SHADE_FUNCTION(megakernel);
 
 void KERNEL_FUNCTION_FULL_NAME(shader_eval_background)(const KernelGlobals *kg,
                                                        const KernelShaderEvalInput *input,
-                                                       float4 *output,
+                                                       float *output,
                                                        const int offset);
 void KERNEL_FUNCTION_FULL_NAME(shader_eval_displace)(const KernelGlobals *kg,
                                                      const KernelShaderEvalInput *input,
-                                                     float4 *output,
+                                                     float *output,
                                                      const int offset);
 
 /* --------------------------------------------------------------------
diff --git a/intern/cycles/kernel/device/cpu/kernel_arch_impl.h b/intern/cycles/kernel/device/cpu/kernel_arch_impl.h
index 1432abfd330..23e371f165f 100644
--- a/intern/cycles/kernel/device/cpu/kernel_arch_impl.h
+++ b/intern/cycles/kernel/device/cpu/kernel_arch_impl.h
@@ -114,7 +114,7 @@ DEFINE_INTEGRATOR_SHADE_KERNEL(megakernel)
 
 void KERNEL_FUNCTION_FULL_NAME(shader_eval_displace)(const KernelGlobals *kg,
                                                      const KernelShaderEvalInput *input,
-                                                     float4 *output,
+                                                     float *output,
                                                      const int offset)
 {
 #ifdef KERNEL_STUB
@@ -126,7 +126,7 @@ void KERNEL_FUNCTION_FULL_NAME(shader_eval_displace)(const KernelGlobals *kg,
 
 void KERNEL_FUNCTION_FULL_NAME(shader_eval_background)(const KernelGlobals *kg,
                                                        const KernelShaderEvalInput *input,
-                                                       float4 *output,
+                                                       float *output,
                                                        const int offset)
 {
 #ifdef KERNEL_STUB
diff --git a/intern/cycles/kernel/device/gpu/kernel.h b/intern/cycles/kernel/device/gpu/kernel.h
index 3379114fc62..21901215757 100644
--- a/intern/cycles/kernel/device/gpu/kernel.h
+++ b/intern/cycles/kernel/device/gpu/kernel.h
@@ -615,7 +615,7 @@ KERNEL_FILM_CONVERT_DEFINE(float4, rgba)
 
 ccl_gpu_kernel(GPU_KERNEL_BLOCK_NUM_THREADS, GPU_KERNEL_MAX_REGISTERS)
     kernel_gpu_shader_eval_displace(KernelShaderEvalInput *input,
-                                    float4 *output,
+                                    float *output,
                                     const int offset,
                                     const int work_size)
 {
@@ -629,7 +629,7 @@ ccl_gpu_kernel(GPU_KERNEL_BLOCK_NUM_THREADS, GPU_KERNEL_MAX_REGISTERS)
 
 ccl_gpu_kernel(GPU_KERNEL_BLOCK_NUM_THREADS, GPU_KERNEL_MAX_REGISTERS)
     kernel_gpu_shader_eval_background(KernelShaderEvalInput *input,
-                                      float4 *output,
+                                      float *output,
                                       const int offset,
                                       const int work_size)
 {
diff --git a/intern/cycles/kernel/integrator/integrator_intersect_shadow.h b/intern/cycles/kernel/integrator/integrator_intersect_shadow.h
index 00d44f0e5ed..3ebd21e4651 100644
--- a/intern/cycles/kernel/integrator/integrator_intersect_shadow.h
+++ b/intern/cycles/kernel/integrator/integrator_intersect_shadow.h
@@ -85,7 +85,8 @@ ccl_device bool integrate_intersect_shadow_transparent(INTEGRATOR_STATE_ARGS,
     if (num_recorded_hits > 0) {
       sort_intersections(isect, num_recorded_hits);
 
-      /* Write intersection result into global integrator state memory. */
+      /* Write intersection result into global integrator state memory.
+       * More efficient may be to do this directly from the intersection kernel. */
       for (int hit = 0; hit < num_recorded_hits; hit++) {
         integrator_state_write_shadow_isect(INTEGRATOR_STATE_PASS, &isect[hit]

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list