Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/session/denoising.h
| Show All 11 Lines | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef __DENOISING_H__ | #ifndef __DENOISING_H__ | ||||
| #define __DENOISING_H__ | #define __DENOISING_H__ | ||||
| #if 0 | |||||
| /* TODO(sergey): Make it explicit and clear when something is a denoiser, its pipeline or | /* TODO(sergey): Make it explicit and clear when something is a denoiser, its pipeline or | ||||
| * parameters. Currently it is an annoying mixture of terms used interchangeably. */ | * parameters. Currently it is an annoying mixture of terms used interchangeably. */ | ||||
| # include "device/device.h" | #include "device/device.h" | ||||
| #include "integrator/denoiser.h" | |||||
| # include "render/buffers.h" | #include "util/string.h" | ||||
| #include "util/unique_ptr.h" | |||||
| # include "util/util_string.h" | #include "util/vector.h" | ||||
| # include "util/util_unique_ptr.h" | |||||
| # include "util/util_vector.h" | |||||
| # include <OpenImageIO/imageio.h> | #include <OpenImageIO/imageio.h> | ||||
| OIIO_NAMESPACE_USING | OIIO_NAMESPACE_USING | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| /* Denoiser pipeline */ | /* Denoiser pipeline */ | ||||
| class DenoiserPipeline { | class DenoiserPipeline { | ||||
| public: | public: | ||||
| DenoiserPipeline(DeviceInfo &device_info); | DenoiserPipeline(DeviceInfo &device_info, const DenoiseParams ¶ms); | ||||
| ~DenoiserPipeline(); | ~DenoiserPipeline(); | ||||
| bool run(); | bool run(); | ||||
| /* Error message after running, in case of failure. */ | /* Error message after running, in case of failure. */ | ||||
| string error; | string error; | ||||
| /* Sequential list of frame filepaths to denoise. */ | /* Sequential list of frame filepaths to denoise. */ | ||||
| vector<string> input; | vector<string> input; | ||||
| /* Sequential list of frame filepaths to write result to. Empty entries | /* Sequential list of frame filepaths to write result to. Empty entries | ||||
| * are skipped, so only a subset of the sequence can be denoised while | * are skipped, so only a subset of the sequence can be denoised while | ||||
| * taking into account all input frames. */ | * taking into account all input frames. */ | ||||
| vector<string> output; | vector<string> output; | ||||
| /* Sample number override, takes precedence over values from input frames. */ | |||||
| int samples_override; | |||||
| /* Tile size for processing on device. */ | |||||
| int2 tile_size; | |||||
| /* Equivalent to the settings in the regular denoiser. */ | |||||
| DenoiseParams params; | |||||
| protected: | protected: | ||||
| friend class DenoiseTask; | friend class DenoiseTask; | ||||
| Stats stats; | Stats stats; | ||||
| Profiler profiler; | Profiler profiler; | ||||
| Device *device; | Device *device; | ||||
| std::unique_ptr<Denoiser> denoiser; | |||||
| int num_frames; | |||||
| }; | }; | ||||
| /* Denoise Image Layer */ | /* Denoise Image Layer */ | ||||
| struct DenoiseImageLayer { | struct DenoiseImageLayer { | ||||
| string name; | string name; | ||||
| /* All channels belonging to this DenoiseImageLayer. */ | /* All channels belonging to this DenoiseImageLayer. */ | ||||
| vector<string> channels; | vector<string> channels; | ||||
| /* Layer to image channel mapping. */ | /* Layer to image channel mapping. */ | ||||
| vector<int> layer_to_image_channel; | vector<int> layer_to_image_channel; | ||||
| /* Sample amount that was used for rendering this layer. */ | /* Sample amount that was used for rendering this layer. */ | ||||
| int samples; | int samples; | ||||
| /* Device input channel will be copied from image channel input_to_image_channel[i]. */ | /* Device input channel will be copied from image channel input_to_image_channel[i]. */ | ||||
| vector<int> input_to_image_channel; | vector<int> input_to_image_channel; | ||||
| /* input_to_image_channel of the secondary frames, if any are used. */ | |||||
| vector<vector<int>> neighbor_input_to_image_channel; | |||||
| /* Write i-th channel of the processing output to output_to_image_channel[i]-th channel of the | /* Write i-th channel of the processing output to output_to_image_channel[i]-th channel of the | ||||
| * file. */ | * file. */ | ||||
| vector<int> output_to_image_channel; | vector<int> output_to_image_channel; | ||||
| /* output_to_image_channel of the previous frame, if used. */ | |||||
| vector<int> previous_output_to_image_channel; | |||||
| /* Detect whether this layer contains a full set of channels and set up the offsets accordingly. | /* Detect whether this layer contains a full set of channels and set up the offsets accordingly. | ||||
| */ | */ | ||||
| bool detect_denoising_channels(); | bool detect_denoising_channels(); | ||||
| /* Map the channels of a secondary frame to the channels that are required for processing, | /* Map the channels of a secondary frame to the channels that are required for processing, | ||||
| * fill neighbor_input_to_image_channel if all are present or return false if a channel are | * fill neighbor_input_to_image_channel if all are present or return false if a channel are | ||||
| * missing. */ | * missing. */ | ||||
| bool match_channels(int neighbor, | bool match_channels(const std::vector<string> &channelnames, | ||||
| const std::vector<string> &channelnames, | |||||
| const std::vector<string> &neighbor_channelnames); | const std::vector<string> &neighbor_channelnames); | ||||
| }; | }; | ||||
| /* Denoise Image Data */ | /* Denoise Image Data */ | ||||
| class DenoiseImage { | class DenoiseImage { | ||||
| public: | public: | ||||
| DenoiseImage(); | DenoiseImage(); | ||||
| ~DenoiseImage(); | ~DenoiseImage(); | ||||
| /* Dimensions */ | /* Dimensions */ | ||||
| int width, height, num_channels; | int width, height, num_channels; | ||||
| /* Samples */ | /* Samples */ | ||||
| int samples; | int samples; | ||||
| /* Pixel buffer with interleaved channels. */ | /* Pixel buffer with interleaved channels. */ | ||||
| array<float> pixels; | array<float> pixels; | ||||
| /* Image file handles */ | /* Image file handles */ | ||||
| ImageSpec in_spec; | ImageSpec in_spec; | ||||
| vector<unique_ptr<ImageInput>> in_neighbors; | unique_ptr<ImageInput> in_previous; | ||||
| /* Render layers */ | /* Render layers */ | ||||
| vector<DenoiseImageLayer> layers; | vector<DenoiseImageLayer> layers; | ||||
| void free(); | void free(); | ||||
| /* Open the input image, parse its channels, open the output image and allocate the output | /* Open the input image, parse its channels, open the output image and allocate the output | ||||
| * buffer. */ | * buffer. */ | ||||
| bool load(const string &in_filepath, string &error); | bool load(const string &in_filepath, string &error); | ||||
| /* Load neighboring frames. */ | /* Load neighboring frames. */ | ||||
| bool load_neighbors(const vector<string> &filepaths, const vector<int> &frames, string &error); | bool load_previous(const string &in_filepath, string &error); | ||||
| /* Load subset of pixels from file buffer into input buffer, as needed for denoising | /* Load subset of pixels from file buffer into input buffer, as needed for denoising | ||||
| * on the device. Channels are reshuffled following the provided mapping. */ | * on the device. Channels are reshuffled following the provided mapping. */ | ||||
| void read_pixels(const DenoiseImageLayer &layer, float *input_pixels); | void read_pixels(const DenoiseImageLayer &layer, | ||||
| bool read_neighbor_pixels(int neighbor, const DenoiseImageLayer &layer, float *input_pixels); | const BufferParams ¶ms, | ||||
| float *input_pixels); | |||||
| bool read_previous_pixels(const DenoiseImageLayer &layer, | |||||
| const BufferParams ¶ms, | |||||
| float *input_pixels); | |||||
| bool save_output(const string &out_filepath, string &error); | bool save_output(const string &out_filepath, string &error); | ||||
| protected: | protected: | ||||
| /* Parse input file channels, separate them into DenoiseImageLayers, | /* Parse input file channels, separate them into DenoiseImageLayers, | ||||
| * detect DenoiseImageLayers with full channel sets, | * detect DenoiseImageLayers with full channel sets, | ||||
| * fill layers and set up the output channels and passthrough map. */ | * fill layers and set up the output channels and passthrough map. */ | ||||
| bool parse_channels(const ImageSpec &in_spec, string &error); | bool parse_channels(const ImageSpec &in_spec, string &error); | ||||
| void close_input(); | void close_input(); | ||||
| }; | }; | ||||
| /* Denoise Task */ | /* Denoise Task */ | ||||
| class DenoiseTask { | class DenoiseTask { | ||||
| public: | public: | ||||
| DenoiseTask(Device *device, | DenoiseTask(Device *device, DenoiserPipeline *denoiser, int frame); | ||||
| DenoiserPipeline *denoiser, | |||||
| int frame, | |||||
| const vector<int> &neighbor_frames); | |||||
| ~DenoiseTask(); | ~DenoiseTask(); | ||||
| /* Task stages */ | /* Task stages */ | ||||
| bool load(); | bool load(); | ||||
| bool exec(); | bool exec(); | ||||
| bool save(); | bool save(); | ||||
| void free(); | void free(); | ||||
| string error; | string error; | ||||
| protected: | protected: | ||||
| /* Denoiser parameters and device */ | /* Denoiser parameters and device */ | ||||
| DenoiserPipeline *denoiser; | DenoiserPipeline *denoiser; | ||||
| Device *device; | Device *device; | ||||
| /* Frame number to be denoised */ | /* Frame number to be denoised */ | ||||
| int frame; | int frame; | ||||
| vector<int> neighbor_frames; | |||||
| /* Image file data */ | /* Image file data */ | ||||
| DenoiseImage image; | DenoiseImage image; | ||||
| int current_layer; | int current_layer; | ||||
| /* Device input buffer */ | RenderBuffers buffers; | ||||
| device_vector<float> input_pixels; | |||||
| /* Tiles */ | |||||
| thread_mutex tiles_mutex; | |||||
| list<RenderTile> tiles; | |||||
| int num_tiles; | |||||
| thread_mutex output_mutex; | |||||
| map<int, device_vector<float> *> output_pixels; | |||||
| /* Task handling */ | /* Task handling */ | ||||
| bool load_input_pixels(int layer); | bool load_input_pixels(int layer); | ||||
| void create_task(DeviceTask &task); | |||||
| /* Device task callbacks */ | |||||
| bool acquire_tile(Device *device, Device *tile_device, RenderTile &tile); | |||||
| void map_neighboring_tiles(RenderTileNeighbors &neighbors, Device *tile_device); | |||||
| void unmap_neighboring_tiles(RenderTileNeighbors &neighbors); | |||||
| void release_tile(); | |||||
| bool get_cancel(); | |||||
| }; | }; | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| #endif | |||||
| #endif /* __DENOISING_H__ */ | #endif /* __DENOISING_H__ */ | ||||