[Bf-blender-cvs] [dfef4de] soc-2016-cycles_denoising: Cycles: Add device code and kernel stubs for denoising
Lukas Stockner
noreply at git.blender.org
Sun Jun 19 18:22:00 CEST 2016
Commit: dfef4de5d0b5b4cc9499d5d8bd3db47a907f5d2b
Author: Lukas Stockner
Date: Sun Jun 19 17:59:23 2016 +0200
Branches: soc-2016-cycles_denoising
https://developer.blender.org/rBdfef4de5d0b5b4cc9499d5d8bd3db47a907f5d2b
Cycles: Add device code and kernel stubs for denoising
This commit implements stub kernels and the required host-side code to call them (CPU-only for now).
===================================================================
M intern/cycles/device/device_cpu.cpp
A intern/cycles/kernel/kernel_filter.h
M intern/cycles/kernel/kernel_types.h
M intern/cycles/kernel/kernels/cpu/kernel_cpu.h
M intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h
===================================================================
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index 512f8b2..0c4fed1 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -222,39 +222,53 @@ public:
RenderTile tile;
void(*path_trace_kernel)(KernelGlobals*, float*, unsigned int*, int, int, int, int, int);
+ void(*filter_estimate_params_kernel)(KernelGlobals*, int, float**, int, int, int*, int*, int*, int*, void*);
+ void(*filter_final_pass_kernel)(KernelGlobals*, int, float**, int, int, int*, int*, int*, int*, void*);
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
if(system_cpu_support_avx2()) {
path_trace_kernel = kernel_cpu_avx2_path_trace;
+ filter_estimate_params_kernel = kernel_cpu_avx2_filter_estimate_params;
+ filter_final_pass_kernel = kernel_cpu_avx2_filter_final_pass;
}
else
#endif
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
if(system_cpu_support_avx()) {
path_trace_kernel = kernel_cpu_avx_path_trace;
+ filter_estimate_params_kernel = kernel_cpu_avx_filter_estimate_params;
+ filter_final_pass_kernel = kernel_cpu_avx_filter_final_pass;
}
else
#endif
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
if(system_cpu_support_sse41()) {
path_trace_kernel = kernel_cpu_sse41_path_trace;
+ filter_estimate_params_kernel = kernel_cpu_sse41_filter_estimate_params;
+ filter_final_pass_kernel = kernel_cpu_sse41_filter_final_pass;
}
else
#endif
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
if(system_cpu_support_sse3()) {
path_trace_kernel = kernel_cpu_sse3_path_trace;
+ filter_estimate_params_kernel = kernel_cpu_sse3_filter_estimate_params;
+ filter_final_pass_kernel = kernel_cpu_sse3_filter_final_pass;
}
else
#endif
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
if(system_cpu_support_sse2()) {
path_trace_kernel = kernel_cpu_sse2_path_trace;
+ filter_estimate_params_kernel = kernel_cpu_sse2_filter_estimate_params;
+ filter_final_pass_kernel = kernel_cpu_sse2_filter_final_pass;
}
else
#endif
{
path_trace_kernel = kernel_cpu_path_trace;
+ filter_estimate_params_kernel = kernel_cpu_filter_estimate_params;
+ filter_final_pass_kernel = kernel_cpu_filter_final_pass;
}
while(task.acquire_tile(this, tile)) {
@@ -284,14 +298,30 @@ public:
}
}
else if(tile.task == RenderTile::DENOISE) {
- printf("TODO: Implement Denoising kernel, was called for tile at (%d, %d) with size %dx%d!\n", tile.x, tile.y, tile.w, tile.h);
- /* Small brightness increase to have visual feedback in the UI which parts have been "denoised" already, will of course be removed once proper denoising works. */
+ int sample = tile.start_sample + tile.num_samples;
+
+ RenderTile rtiles[9];
+ rtiles[4] = tile;
+ task.get_neighbor_tiles(rtiles);
+ float *buffers[9];
+ int offsets[9], strides[9];
+ for(int i = 0; i < 9; i++) {
+ buffers[i] = (float*) rtiles[i].buffer;
+ offsets[i] = rtiles[i].offset;
+ strides[i] = rtiles[i].stride;
+ }
+ int tile_x[4] = {rtiles[0].x, rtiles[1].x, rtiles[2].x, rtiles[2].x+rtiles[2].w};
+ int tile_y[4] = {rtiles[0].y, rtiles[3].y, rtiles[6].y, rtiles[6].y+rtiles[6].h};
+ FilterStorage *storages = new FilterStorage[tile.w*tile.h];
+
+ for(int y = tile.y; y < tile.y + tile.h; y++) {
+ for(int x = tile.x; x < tile.x + tile.w; x++) {
+ filter_estimate_params_kernel(&kg, sample, buffers, x, y, tile_x, tile_y, offsets, strides, storages);
+ }
+ }
for(int y = tile.y; y < tile.y + tile.h; y++) {
for(int x = tile.x; x < tile.x + tile.w; x++) {
- float4 *pix = (float4*) (render_buffer + (tile.offset + y*tile.stride + x)*kg.__data.film.pass_stride);
- pix->x *= 2;
- pix->y *= 2;
- pix->z *= 2;
+ filter_final_pass_kernel(&kg, sample, buffers, x, y, tile_x, tile_y, offsets, strides, storages);
}
}
}
diff --git a/intern/cycles/kernel/kernel_filter.h b/intern/cycles/kernel/kernel_filter.h
new file mode 100644
index 0000000..6ef4c8c
--- /dev/null
+++ b/intern/cycles/kernel/kernel_filter.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2011-2016 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+CCL_NAMESPACE_BEGIN
+
+/* Since the filtering may be performed across tile edged, all the neighboring tiles have to be passed along as well.
+ * tile_x/y contain the x/y positions of the tile grid, 4 entries each:
+ * - Start of the lower/left neighbor
+ * - Start of the own tile
+ * - Start of the upper/right neighbor
+ * - Start of the next upper/right neighbor (not accessed)
+ * buffers contains the nine buffer pointers (y-major ordering, starting with the lower left tile), offset and stride the respective parameters of the tile.
+ */
+ccl_device void kernel_filter_estimate_params(KernelGlobals *kg, int sample, float **buffers, int x, int y, int *tile_x, int *tile_y, int *offset, int *stride, FilterStorage *storage)
+{
+ /* TODO(lukas): Implement filter. */
+}
+
+
+
+
+ccl_device void kernel_filter_final_pass(KernelGlobals *kg, int sample, float **buffers, int x, int y, int *tile_x, int *tile_y, int *offset, int *stride, FilterStorage *storage)
+{
+ /* TODO(lukas): Implement filter. */
+}
+
+CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 4f4998f..21d1671 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -1270,6 +1270,15 @@ enum RayState {
#define REMOVE_RAY_FLAG(ray_state, ray_index, flag) (ray_state[ray_index] = (ray_state[ray_index] & (~flag)))
#define IS_FLAG(ray_state, ray_index, flag) (ray_state[ray_index] & flag)
+#define DENOISE_FEATURES 9 /* The amount of denoising features: Normal, Albedo, Depth and screen position (x, y)*/
+
+typedef struct FilterStorage {
+ float transform[DENOISE_FEATURES*DENOISE_FEATURES];
+ float bandwidth[DENOISE_FEATURES];
+ int rank;
+ float global_bandwidth;
+} FilterStorage;
+
CCL_NAMESPACE_END
#endif /* __KERNEL_TYPES_H__ */
diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu.h
index 1a07c70..b719a79 100644
--- a/intern/cycles/kernel/kernels/cpu/kernel_cpu.h
+++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu.h
@@ -49,4 +49,26 @@ void KERNEL_FUNCTION_FULL_NAME(shader)(KernelGlobals *kg,
int offset,
int sample);
+void KERNEL_FUNCTION_FULL_NAME(filter_estimate_params)(KernelGlobals *kg,
+ int sample,
+ float** buffers,
+ int x,
+ int y,
+ int *tile_x,
+ int *tile_y,
+ int *offset,
+ int *stride,
+ void *storage);
+
+void KERNEL_FUNCTION_FULL_NAME(filter_final_pass)(KernelGlobals *kg,
+ int sample,
+ float** buffers,
+ int x,
+ int y,
+ int *tile_x,
+ int *tile_y,
+ int *offset,
+ int *stride,
+ void *storage);
+
#undef KERNEL_ARCH
diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h
index 1454f92..9e468b4 100644
--- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h
+++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_impl.h
@@ -28,6 +28,7 @@
#include "kernel_path.h"
#include "kernel_path_branched.h"
#include "kernel_bake.h"
+#include "kernel_filter.h"
CCL_NAMESPACE_BEGIN
@@ -128,4 +129,34 @@ void KERNEL_FUNCTION_FULL_NAME(shader)(KernelGlobals *kg,
}
}
+/* Denoise filter */
+
+void KERNEL_FUNCTION_FULL_NAME(filter_estimate_params)(KernelGlobals *kg,
+ int sample,
+ float** buffers,
+ int x,
+ int y,
+ int *tile_x,
+ int *tile_y,
+ int *offset,
+ int *stride,
+ void *storage)
+{
+ kernel_filter_estimate_params(kg, sample, buffers, x, y, tile_x, tile_y, offset, stride, (FilterStorage*) storage);
+}
+
+void KERNEL_FUNCTION_FULL_NAME(filter_final_pass)(KernelGlobals *kg,
+ int sample,
+ float** buffers,
+ int x,
+ int y,
+ int *tile_x,
+ int *tile_y,
+ int *offset,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list