Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/integrator/denoiser_oidn.cpp
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| #ifdef WITH_OPENIMAGEDENOISE | #ifdef WITH_OPENIMAGEDENOISE | ||||
| static bool oidn_progress_monitor_function(void *user_ptr, double /*n*/) | static bool oidn_progress_monitor_function(void *user_ptr, double /*n*/) | ||||
| { | { | ||||
| OIDNDenoiser *oidn_denoiser = reinterpret_cast<OIDNDenoiser *>(user_ptr); | OIDNDenoiser *oidn_denoiser = reinterpret_cast<OIDNDenoiser *>(user_ptr); | ||||
| return !oidn_denoiser->is_cancelled(); | return !oidn_denoiser->is_cancelled(); | ||||
| } | } | ||||
| #endif | |||||
| #ifdef WITH_OPENIMAGEDENOISE | |||||
| class OIDNPass { | class OIDNPass { | ||||
| public: | public: | ||||
| OIDNPass() = default; | OIDNPass() = default; | ||||
| OIDNPass(const BufferParams &buffer_params, | OIDNPass(const BufferParams &buffer_params, | ||||
| const char *name, | const char *name, | ||||
| PassType type, | PassType type, | ||||
| ▲ Show 20 Lines • Show All 481 Lines • ▼ Show 20 Lines | protected: | ||||
| OIDNPass oidn_albedo_pass_; | OIDNPass oidn_albedo_pass_; | ||||
| OIDNPass oidn_normal_pass_; | OIDNPass oidn_normal_pass_; | ||||
| /* For passes which don't need albedo channel for denoising we replace the actual albedo with | /* For passes which don't need albedo channel for denoising we replace the actual albedo with | ||||
| * the (0.5, 0.5, 0.5). This flag indicates that the real albedo pass has been replaced with | * the (0.5, 0.5, 0.5). This flag indicates that the real albedo pass has been replaced with | ||||
| * the fake values and denoising of passes which do need albedo can no longer happen. */ | * the fake values and denoising of passes which do need albedo can no longer happen. */ | ||||
| bool albedo_replaced_with_fake_ = false; | bool albedo_replaced_with_fake_ = false; | ||||
| }; | }; | ||||
| #endif | |||||
| static unique_ptr<DeviceQueue> create_device_queue(const RenderBuffers *render_buffers) | static unique_ptr<DeviceQueue> create_device_queue(const RenderBuffers *render_buffers) | ||||
| { | { | ||||
| Device *device = render_buffers->buffer.device; | Device *device = render_buffers->buffer.device; | ||||
| if (device->info.has_gpu_queue) { | if (device->info.has_gpu_queue) { | ||||
| return device->gpu_queue_create(); | return device->gpu_queue_create(); | ||||
| } | } | ||||
| return nullptr; | return nullptr; | ||||
| Show All 18 Lines | if (queue) { | ||||
| queue->copy_to_device(render_buffers->buffer); | queue->copy_to_device(render_buffers->buffer); | ||||
| queue->synchronize(); | queue->synchronize(); | ||||
| } | } | ||||
| else { | else { | ||||
| render_buffers->copy_to_device(); | render_buffers->copy_to_device(); | ||||
| } | } | ||||
| } | } | ||||
| #endif | |||||
| bool OIDNDenoiser::denoise_buffer(const BufferParams &buffer_params, | bool OIDNDenoiser::denoise_buffer(const BufferParams &buffer_params, | ||||
| RenderBuffers *render_buffers, | RenderBuffers *render_buffers, | ||||
| const int num_samples, | const int num_samples, | ||||
| bool allow_inplace_modification) | bool allow_inplace_modification) | ||||
| { | { | ||||
| #ifdef WITH_OPENIMAGEDENOISE | |||||
| thread_scoped_lock lock(mutex_); | thread_scoped_lock lock(mutex_); | ||||
| /* Make sure the host-side data is available for denoising. */ | /* Make sure the host-side data is available for denoising. */ | ||||
| unique_ptr<DeviceQueue> queue = create_device_queue(render_buffers); | unique_ptr<DeviceQueue> queue = create_device_queue(render_buffers); | ||||
| copy_render_buffers_from_device(queue, render_buffers); | copy_render_buffers_from_device(queue, render_buffers); | ||||
| #ifdef WITH_OPENIMAGEDENOISE | |||||
| OIDNDenoiseContext context( | OIDNDenoiseContext context( | ||||
| this, params_, buffer_params, render_buffers, num_samples, allow_inplace_modification); | this, params_, buffer_params, render_buffers, num_samples, allow_inplace_modification); | ||||
| if (context.need_denoising()) { | if (context.need_denoising()) { | ||||
| context.read_guiding_passes(); | context.read_guiding_passes(); | ||||
| const std::array<PassType, 3> passes = { | const std::array<PassType, 3> passes = { | ||||
| {/* Passes which will use real albedo when it is available. */ | {/* Passes which will use real albedo when it is available. */ | ||||
| Show All 10 Lines | for (const PassType pass_type : passes) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| /* TODO: It may be possible to avoid this copy, but we have to ensure that when other code | /* TODO: It may be possible to avoid this copy, but we have to ensure that when other code | ||||
| * copies data from the device it doesn't overwrite the denoiser buffers. */ | * copies data from the device it doesn't overwrite the denoiser buffers. */ | ||||
| copy_render_buffers_to_device(queue, render_buffers); | copy_render_buffers_to_device(queue, render_buffers); | ||||
| } | } | ||||
| #else | |||||
| (void)buffer_params; | |||||
| (void)render_buffers; | |||||
| (void)num_samples; | |||||
| (void)allow_inplace_modification; | |||||
| #endif | #endif | ||||
| /* This code is not supposed to run when compiled without OIDN support, so can assume if we made | /* This code is not supposed to run when compiled without OIDN support, so can assume if we made | ||||
| * it up here all passes are properly denoised. */ | * it up here all passes are properly denoised. */ | ||||
| return true; | return true; | ||||
| } | } | ||||
| uint OIDNDenoiser::get_device_type_mask() const | uint OIDNDenoiser::get_device_type_mask() const | ||||
| { | { | ||||
| return DEVICE_MASK_CPU; | return DEVICE_MASK_CPU; | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||