blender/intern/cycles/integrator/denoiser_oidn_base.h
Stefan Werner daf837ca21 Cycles: Closer alignment of CPU and GPU OIDN integration
Introduce OIDNDenoiserBase composition helper to eliminate code
duplication between CPU and GPU OIDN implementations:
- Move shared device, filter, and quality management to base class
- Consolidate custom weights loading and common filter parameter setup
- Both CPU and GPU denoisers access OIDN state through base_ member
- Lazy device initialization moved to denoise_create_if_needed()
- Filter lifecycle unified across both implementations

Pull Request: https://projects.blender.org/blender/blender/pulls/152637
2026-01-20 10:28:24 +01:00

50 lines
1.3 KiB
C++

/* SPDX-FileCopyrightText: 2011-2026 Blender Foundation
*
* SPDX-License-Identifier: Apache-2.0 */
#pragma once
#ifdef WITH_OPENIMAGEDENOISE
# include "integrator/denoiser.h"
# include "util/openimagedenoise.h"
# include "util/vector.h"
CCL_NAMESPACE_BEGIN
/* Shared OIDN denoiser functionality for both CPU and GPU implementations.
* Uses composition pattern to avoid multiple inheritance. */
class OIDNDenoiserBase {
public:
explicit OIDNDenoiserBase(Denoiser *denoiser);
~OIDNDenoiserBase()
{
release_all_resources();
}
/* OIDN handles and state. */
OIDNDevice oidn_device_ = nullptr;
OIDNFilter oidn_filter_ = nullptr;
OIDNFilter albedo_filter_ = nullptr;
OIDNFilter normal_filter_ = nullptr;
DenoiserQuality quality_ = DENOISER_QUALITY_HIGH;
bool is_configured_ = false;
int2 configured_size_ = make_int2(0, 0);
vector<uint8_t> custom_weights_;
bool use_pass_albedo_ = false;
bool use_pass_normal_ = false;
/* Shared methods. */
bool create_filters(DenoiserQuality quality, bool denoise_abledo, bool denoise_normal);
void load_custom_weights();
void release_all_resources();
bool denoise_configure_if_needed(int width, int height);
private:
OIDNFilter new_filter();
Denoiser *denoiser_; /* Back-pointer for error reporting. */
};
CCL_NAMESPACE_END
#endif /* WITH_OPENIMAGEDENOISE */