2022-02-11 12:53:21 +00:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/* TODO(sergey): The integrator folder might not be the best. Is easy to move files around if the
|
|
|
|
* better place is figured out. */
|
|
|
|
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "device/denoise.h"
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
#include "device/device.h"
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "util/function.h"
|
|
|
|
#include "util/unique_ptr.h"
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class BufferParams;
|
|
|
|
class Device;
|
|
|
|
class RenderBuffers;
|
|
|
|
class Progress;
|
|
|
|
|
|
|
|
/* Implementation of a specific denoising algorithm.
|
|
|
|
*
|
2021-09-22 04:48:01 +00:00
|
|
|
* This class takes care of breaking down denoising algorithm into a series of device calls or to
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
* calls of an external API to denoise given input.
|
|
|
|
*
|
|
|
|
* TODO(sergey): Are we better with device or a queue here? */
|
|
|
|
class Denoiser {
|
|
|
|
public:
|
|
|
|
/* Create denoiser for the given path trace device.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* - The denoiser must be configured. This means that `params.use` must be true.
|
|
|
|
* This is checked in debug builds.
|
|
|
|
* - The device might be MultiDevice. */
|
|
|
|
static unique_ptr<Denoiser> create(Device *path_trace_device, const DenoiseParams ¶ms);
|
|
|
|
|
|
|
|
virtual ~Denoiser() = default;
|
|
|
|
|
|
|
|
void set_params(const DenoiseParams ¶ms);
|
|
|
|
const DenoiseParams &get_params() const;
|
|
|
|
|
|
|
|
/* Create devices and load kernels needed for denoising.
|
2021-09-22 04:48:01 +00:00
|
|
|
* The progress is used to communicate state when kernels actually needs to be loaded.
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
*
|
|
|
|
* NOTE: The `progress` is an optional argument, can be nullptr. */
|
|
|
|
virtual bool load_kernels(Progress *progress);
|
|
|
|
|
|
|
|
/* Denoise the entire buffer.
|
|
|
|
*
|
|
|
|
* Buffer parameters denotes an effective parameters used during rendering. It could be
|
|
|
|
* a lower resolution render into a bigger allocated buffer, which is used in viewport during
|
|
|
|
* navigation and non-unit pixel size. Use that instead of render_buffers->params.
|
|
|
|
*
|
2021-09-22 04:48:01 +00:00
|
|
|
* The buffer might be coming from a "foreign" device from what this denoise is created for.
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
* This means that in general case the denoiser will make sure the input data is available on
|
|
|
|
* the denoiser device, perform denoising, and put data back to the device where the buffer
|
|
|
|
* came from.
|
|
|
|
*
|
|
|
|
* The `num_samples` corresponds to the number of samples in the render buffers. It is used
|
|
|
|
* to scale buffers down to the "final" value in algorithms which don't do automatic exposure,
|
|
|
|
* or which needs "final" value for data passes.
|
|
|
|
*
|
|
|
|
* The `allow_inplace_modification` means that the denoiser is allowed to do in-place
|
|
|
|
* modification of the input passes (scaling them down i.e.). This will lower the memory
|
|
|
|
* footprint of the denoiser but will make input passes "invalid" (from path tracer) point of
|
|
|
|
* view.
|
|
|
|
*
|
|
|
|
* Returns true when all passes are denoised. Will return false if there is a denoiser error (for
|
|
|
|
* example, caused by misconfigured denoiser) or when user requested to cancel rendering. */
|
|
|
|
virtual bool denoise_buffer(const BufferParams &buffer_params,
|
|
|
|
RenderBuffers *render_buffers,
|
|
|
|
const int num_samples,
|
|
|
|
bool allow_inplace_modification) = 0;
|
|
|
|
|
|
|
|
/* Get a device which is used to perform actual denoising.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
*
|
|
|
|
* - The device is lazily initialized via `load_kernels()`, so it will be nullptr until then,
|
|
|
|
*
|
|
|
|
* - The device can be different from the path tracing device. This happens, for example, when
|
|
|
|
* using OptiX denoiser and rendering on CPU.
|
|
|
|
*
|
|
|
|
* - No threading safety is ensured in this call. This means, that it is up to caller to ensure
|
2021-09-22 04:48:01 +00:00
|
|
|
* that there is no threading-conflict between denoising task lazily initializing the device
|
|
|
|
* and access to this device happen. */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
Device *get_denoiser_device() const;
|
|
|
|
|
|
|
|
function<bool(void)> is_cancelled_cb;
|
|
|
|
|
|
|
|
bool is_cancelled() const
|
|
|
|
{
|
|
|
|
if (!is_cancelled_cb) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return is_cancelled_cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Denoiser(Device *path_trace_device, const DenoiseParams ¶ms);
|
|
|
|
|
|
|
|
/* Make sure denoising device is initialized. */
|
|
|
|
virtual Device *ensure_denoiser_device(Progress *progress);
|
|
|
|
|
|
|
|
/* Get device type mask which is used to filter available devices when new device needs to be
|
|
|
|
* created. */
|
|
|
|
virtual uint get_device_type_mask() const = 0;
|
|
|
|
|
|
|
|
Device *path_trace_device_;
|
|
|
|
DenoiseParams params_;
|
|
|
|
|
|
|
|
/* Cached pointer to the device on which denoising will happen.
|
|
|
|
* Used to avoid lookup of a device for every denoising request. */
|
|
|
|
Device *denoiser_device_ = nullptr;
|
|
|
|
|
|
|
|
/* Denoiser device which was created to perform denoising in the case the none of the rendering
|
|
|
|
* devices are capable of denoising. */
|
|
|
|
unique_ptr<Device> local_denoiser_device_;
|
|
|
|
bool device_creation_attempted_ = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|