/* * Copyright 2011-2017 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. */ #ifndef __DEVICE_DENOISING_H__ #define __DEVICE_DENOISING_H__ #include "device/device.h" #include "render/buffers.h" #include "kernel/filter/filter_defines.h" #include "util/util_profiling.h" CCL_NAMESPACE_BEGIN class DenoisingTask { public: /* Parameters of the denoising algorithm. */ int radius; float nlm_k_2; float pca_threshold; /* Parameters of the RenderBuffers. */ struct RenderBuffers { int offset; int pass_stride; int frame_stride; int samples; } render_buffer; /* Pointer and parameters of the target buffer. */ struct TargetBuffer { int offset; int stride; int pass_stride; int denoising_clean_offset; int denoising_output_offset; device_ptr ptr; } target_buffer; TileInfo *tile_info; device_vector tile_info_mem; ProfilingState *profiler; int4 rect; int4 filter_area; bool do_prefilter; bool do_filter; struct DeviceFunctions { function non_local_means; function accumulate; function solve; function construct_transform; function combine_halves; function divide_shadow; function get_feature; function detect_outliers; function write_feature; function map_neighbor_tiles; function unmap_neighbor_tiles; } functions; /* Stores state of the current Reconstruction operation, * which is accessed by the device in order to perform the operation. */ struct ReconstructionState { int4 filter_window; int4 buffer_params; int source_w; int source_h; } reconstruction_state; /* Stores state of the current NLM operation, * which is accessed by the device in order to perform the operation. */ struct NLMState { int r; /* Search radius of the filter. */ int f; /* Patch size of the filter. */ float a; /* Variance compensation factor in the MSE estimation. */ float k_2; /* Squared value of the k parameter of the filter. */ bool is_color; void set_parameters(int r_, int f_, float a_, float k_2_, bool is_color_) { r = r_; f = f_; a = a_, k_2 = k_2_; is_color = is_color_; } } nlm_state; struct Storage { device_only_memory transform; device_only_memory rank; device_only_memory XtWX; device_only_memory XtWY; int w; int h; Storage(Device *device) : transform(device, "denoising transform"), rank(device, "denoising rank"), XtWX(device, "denoising XtWX"), XtWY(device, "denoising XtWY") { } } storage; DenoisingTask(Device *device, const DeviceTask &task); ~DenoisingTask(); void run_denoising(RenderTile &tile); struct DenoiseBuffers { int pass_stride; int passes; int stride; int h; int width; int frame_stride; device_only_memory mem; device_only_memory temporary_mem; bool use_time; bool use_intensity; bool gpu_temporary_mem; DenoiseBuffers(Device *device) : mem(device, "denoising pixel buffer"), temporary_mem(device, "denoising temporary mem") { } } buffer; protected: Device *device; void set_render_buffer(RenderTileNeighbors &neighbors); void setup_denoising_buffer(); void prefilter_shadowing(); void prefilter_features(); void prefilter_color(); void construct_transform(); void reconstruct(); void load_buffer(); void write_buffer(); }; CCL_NAMESPACE_END #endif /* __DEVICE_DENOISING_H__ */