Blender V5.3
path_trace.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
6
7#include "device/cpu/device.h"
8#include "device/device.h"
9
14
15#include "scene/pass.h"
16#include "scene/scene.h"
17
19#include "session/tile.h"
20
21#include "util/log.h"
22#include "util/progress.h"
23#include "util/scoped_defer.h"
24#include "util/tbb.h"
25#include "util/time.h"
26
28
30 Device *denoise_device,
31 Film *film,
32 DeviceScene *device_scene,
33 RenderScheduler &render_scheduler,
34 TileManager &tile_manager)
35 : device_(device),
36 denoise_device_(denoise_device),
37 film_(film),
38 device_scene_(device_scene),
39 render_scheduler_(render_scheduler),
40 tile_manager_(tile_manager)
41{
42 DCHECK_NE(device_, nullptr);
43
44 {
45 vector<DeviceInfo> cpu_devices;
46 device_cpu_info(cpu_devices);
47
49 cpu_devices[0], device->stats, device->profiler, device_->headless);
50 }
51
52 /* Create path tracing work in advance, so that it can be reused by incremental sampling as much
53 * as possible. */
54 device_->foreach_device([&](Device *path_trace_device) {
56 path_trace_device, film, device_scene, &render_cancel_.is_requested);
57 if (work) {
58 path_trace_works_.emplace_back(std::move(work));
59 }
60 });
61
64
65 render_scheduler.set_need_schedule_rebalance(path_trace_works_.size() > 1);
66}
67
72
74{
75 if (denoiser_) {
76 /* Activate graphics interop while denoiser device is created, so that it can choose a device
77 * that supports interop for faster display updates. */
78 if (display_ && path_trace_works_.size() > 1) {
79 display_->graphics_interop_activate();
80 }
81
82 denoiser_->load_kernels(progress_);
83
84 if (display_ && path_trace_works_.size() > 1) {
85 display_->graphics_interop_deactivate();
86 }
87 }
88}
89
91{
92 for (auto &&path_trace_work : path_trace_works_) {
93 path_trace_work->alloc_work_memory();
94 }
95}
96
98{
99 /* The logic here is optimized for the best feedback in the viewport, which implies having a GPU
100 * display. Of there is no such display, the logic here will break. */
102
103 /* The logic here tries to provide behavior which feels the most interactive feel to artists.
104 * General idea is to be able to reset as quickly as possible, while still providing interactive
105 * feel.
106 *
107 * If the render result was ever drawn after previous reset, consider that reset is now possible.
108 * This way camera navigation gives the quickest feedback of rendered pixels, regardless of
109 * whether CPU or GPU drawing pipeline is used.
110 *
111 * Consider reset happening after redraw "slow" enough to not clog anything. This is a bit
112 * arbitrary, but seems to work very well with viewport navigation in Blender. */
113
115 return true;
116 }
117
118 return false;
119}
120
121void PathTrace::reset(const BufferParams &full_params,
122 const BufferParams &big_tile_params,
123 const bool reset_rendering)
124{
125 if (big_tile_params_.modified(big_tile_params)) {
126 big_tile_params_ = big_tile_params;
127 render_state_.need_reset_params = true;
128 }
129
130 full_params_ = full_params;
131
132 /* NOTE: GPU display checks for buffer modification and avoids unnecessary re-allocation.
133 * It is requires to inform about reset whenever it happens, so that the redraw state tracking is
134 * properly updated. */
135 if (display_) {
136 display_->reset(big_tile_params, reset_rendering);
137 }
138
139 render_state_.has_denoised_result = false;
140 render_state_.tile_written = false;
141
142 did_draw_after_reset_ = false;
143}
144
146{
147 /* Free render buffers used by the path trace work to reduce memory peak. */
148 BufferParams empty_params;
149 empty_params.pass_stride = 0;
150 empty_params.update_offset_stride();
151 for (auto &&path_trace_work : path_trace_works_) {
152 path_trace_work->get_render_buffers()->reset(empty_params);
153 }
154 render_state_.need_reset_params = true;
155}
156
158{
159 progress_ = progress;
160}
161
162void PathTrace::render(const RenderWork &render_work)
163{
164 /* Indicate that rendering has started and that it can be requested to cancel. */
165 {
167 if (render_cancel_.is_requested) {
168 return;
169 }
170 render_cancel_.is_rendering = true;
171 }
172
173 render_pipeline(render_work);
174
175 /* Indicate that rendering has finished, making it so thread which requested `cancel()` can carry
176 * on. */
177 {
179 render_cancel_.is_rendering = false;
180 render_cancel_.condition.notify_one();
181 }
182}
183
185{
186 /* NOTE: Only check for "instant" cancel here. The user-requested cancel via progress is
187 * checked in Session and the work in the event of cancel is to be finished here. */
188
190 0);
191
194
196
197 init_render_buffers(render_work);
198
199 rebalance(render_work);
200
201 /* Reset sample limit. */
203
204 /* Prepare all per-thread guiding structures before we start with the next rendering
205 * iteration/progression. */
206 const bool use_guiding = device_scene_->data.integrator.use_guiding;
207 if (use_guiding) {
209 }
210
211 const bool has_volume = device_scene_->data.integrator.use_volumes;
212 if (has_volume) {
213 const uint num_rendered_samples = render_scheduler_.get_num_rendered_samples();
214 const uint limit = next_power_of_two(num_rendered_samples) - num_rendered_samples;
216 }
217
218 path_trace(render_work);
219 if (render_cancel_.is_requested) {
220 return;
221 }
222
223 /* Update the guiding field using the training data/samples collected during the rendering
224 * iteration/progression. */
225 const bool train_guiding = device_scene_->data.integrator.train_guiding;
226 if (use_guiding && train_guiding) {
228 }
229
230 adaptive_sample(render_work);
231 if (render_cancel_.is_requested) {
232 return;
233 }
234
235 cryptomatte_postprocess(render_work);
236 if (render_cancel_.is_requested) {
237 return;
238 }
239
240 denoise(render_work);
241 if (render_cancel_.is_requested) {
242 return;
243 }
244
245 denoise_volume_guiding_buffers(render_work, has_volume);
246 if (render_cancel_.is_requested) {
247 return;
248 }
249
250 write_tile_buffer(render_work);
251 update_display(render_work);
252
253 progress_update_if_needed(render_work);
254
255 finalize_full_buffer_on_disk(render_work);
256}
257
259{
260 for (auto &&path_trace_work : path_trace_works_) {
261 path_trace_work->init_execution();
262 }
263}
264
266{
267 for (auto &&path_trace_work : path_trace_works_) {
268 path_trace_work->deinit_execution();
269 }
270}
271
272/* Scale down an Y coordinate for slicing the buffer. */
273static int scale_window_y(const int window_y,
274 const int window_height,
275 const int scaled_window_height,
276 const float resolution_divider)
277{
278 if (window_y >= window_height) {
279 return scaled_window_height;
280 }
281
282 return min(int(window_y / resolution_divider), scaled_window_height);
283}
284
285/*
286 * Get the parameters of the horizontal slice of the buffer, for a given work index and
287 * balancing weights. Note the result can be empty with many devices and small height.
288 *
289 * The split is computed at the full resolution, and then scaled down. This keeps the slices
290 * filling the window exactly at every resolution and keeps a slice that is empty at full
291 * resolution empty at the downscaled resolution. Slicing at different resolutions with
292 * float weights can lead to mismatches.
293 */
295 const float resolution_divider,
296 const int full_res_window_height,
297 const vector<WorkBalanceInfo> &work_balance_infos,
298 const int index,
299 const int overscan)
300{
301 const int num_works = work_balance_infos.size();
302
303 /* Find the Y coordinates at which the slice starts and ends, at the full resolution. */
304 int full_res_window_y = 0;
305 int full_res_window_end_y = 0;
306
307 for (int i = 0; i <= index; i++) {
308 full_res_window_y = full_res_window_end_y;
309
310 const double weight = work_balance_infos[i].weight;
311 const int slice_window_height = max(lround(full_res_window_height * weight), 1);
312
313 const int remaining_window_height = max(0, full_res_window_height - full_res_window_y);
314 full_res_window_end_y = full_res_window_y +
315 ((i < num_works - 1) ?
316 min(slice_window_height, remaining_window_height) :
317 remaining_window_height);
318 }
319
320 /* Scale the Y coordinates down to the resolution of the buffer. */
321 const int window_y = scale_window_y(
322 full_res_window_y, full_res_window_height, buffer_params.window_height, resolution_divider);
323 const int window_end_y = scale_window_y(full_res_window_end_y,
324 full_res_window_height,
325 buffer_params.window_height,
326 resolution_divider);
327
328 const int slice_window_full_y = buffer_params.full_y + buffer_params.window_y + window_y;
329
330 BufferParams slice_params = buffer_params;
331
332 slice_params.full_y = max(slice_window_full_y - overscan, buffer_params.full_y);
333 slice_params.window_y = slice_window_full_y - slice_params.full_y;
334 slice_params.window_height = window_end_y - window_y;
335
336 slice_params.height = slice_params.window_y + slice_params.window_height + overscan;
337 slice_params.height = min(slice_params.height,
338 buffer_params.height + buffer_params.full_y - slice_params.full_y);
339
340 slice_params.update_offset_stride();
341
342 return slice_params;
343}
344
346{
347 const int overscan = tile_manager_.get_tile_overscan();
348
349 const int num_works = path_trace_works_.size();
350 for (int i = 0; i < num_works; ++i) {
351 const BufferParams slice_params = slice_buffer_params(
353
354 RenderBuffers *buffers = path_trace_works_[i]->get_render_buffers();
355 buffers->reset(slice_params);
356 }
357}
358
359static BufferParams scale_buffer_params(const BufferParams &params, const float resolution_divider)
360{
361 BufferParams scaled_params = params;
362
363 scaled_params.window_x = int(params.window_x / resolution_divider);
364 scaled_params.window_y = int(params.window_y / resolution_divider);
365 scaled_params.window_width = max(1, int(params.window_width / resolution_divider));
366 scaled_params.window_height = max(1, int(params.window_height / resolution_divider));
367
368 /* Scaled down buffer size, but not smaller than the window that we need to write into. */
369 scaled_params.width = max(int(params.width / resolution_divider),
370 scaled_params.window_x + scaled_params.window_width);
371 scaled_params.height = max(int(params.height / resolution_divider),
372 scaled_params.window_y + scaled_params.window_height);
373
374 scaled_params.full_x = int(params.full_x / resolution_divider);
375 scaled_params.full_y = int(params.full_y / resolution_divider);
376 scaled_params.full_width = max(1, int(params.full_width / resolution_divider));
377 scaled_params.full_height = max(1, int(params.full_height / resolution_divider));
378
379 scaled_params.update_offset_stride();
380
381 return scaled_params;
382}
383
385{
386 const float denoised_resolution_divider = render_work.denoised_resolution_divider;
387 const float resolution_divider = render_work.resolution_divider / denoised_resolution_divider;
388
389 const BufferParams denoised_big_tile_params = scale_buffer_params(big_tile_params_,
390 denoised_resolution_divider);
391 const BufferParams scaled_big_tile_params = scale_buffer_params(denoised_big_tile_params,
392 resolution_divider);
393
394 const int overscan = tile_manager_.get_tile_overscan();
395 const int scaled_overscan = int(overscan / resolution_divider);
396 const int full_res_window_height = big_tile_params_.window_height;
397
398 const int num_works = path_trace_works_.size();
399 for (int i = 0; i < num_works; ++i) {
400 const BufferParams denoised_slice_params = slice_buffer_params(denoised_big_tile_params,
401 denoised_resolution_divider,
402 full_res_window_height,
404 i,
405 overscan);
406
407 const BufferParams slice_params = slice_buffer_params(scaled_big_tile_params,
408 render_work.resolution_divider,
409 full_res_window_height,
411 i,
412 scaled_overscan);
413
414 path_trace_works_[i]->set_effective_buffer_params(
415 scaled_big_tile_params, slice_params, denoised_big_tile_params, denoised_slice_params);
416 }
417
418 render_state_.effective_big_tile_params = scaled_big_tile_params;
419 render_state_.effective_denoised_big_tile_params = denoised_big_tile_params;
420}
421
423{
424 if (render_state_.need_reset_params) {
426 }
427
428 if (render_state_.need_reset_params ||
429 render_state_.resolution_divider != render_work.resolution_divider)
430 {
432 }
433
434 render_state_.resolution_divider = render_work.resolution_divider;
435 render_state_.need_reset_params = false;
436}
437
439{
441
442 /* Handle initialization scheduled by the render scheduler. */
443 if (render_work.init_render_buffers) {
444 parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
445 path_trace_work->zero_render_buffers();
446 });
447
449 }
450}
451
453{
454 if (!render_work.path_trace.num_samples) {
455 return;
456 }
457
458 LOG_DEBUG << "Will path trace " << render_work.path_trace.num_samples
459 << " samples at the resolution divider " << render_work.resolution_divider;
460
461 const double start_time = time_dt();
462
463 const int num_works = path_trace_works_.size();
464
465 thread_capture_fp_settings();
466
467 parallel_for(0, num_works, [&](int i) {
468 const double work_start_time = time_dt();
469 const int num_samples = render_work.path_trace.num_samples;
470
471 PathTraceWork *path_trace_work = path_trace_works_[i].get();
472 if (path_trace_work->get_device()->have_error()) {
473 return;
474 }
475
477 path_trace_work->render_samples(statistics,
478 render_work.path_trace.start_sample,
479 num_samples,
480 render_work.path_trace.sample_offset);
481
482 DCHECK(isfinite(statistics.occupancy));
483
484 const double work_time = time_dt() - work_start_time;
485 work_balance_infos_[i].time_spent += work_time;
486 work_balance_infos_[i].occupancy = statistics.occupancy;
487
488 LOG_INFO << "Rendered " << num_samples << " samples in " << work_time << " seconds ("
489 << work_time / num_samples
490 << " seconds per sample), occupancy: " << statistics.occupancy;
491 });
492
493 float occupancy_accum = 0.0f;
494 for (const WorkBalanceInfo &balance_info : work_balance_infos_) {
495 occupancy_accum += balance_info.occupancy;
496 }
497 const float occupancy = occupancy_accum / num_works;
499
501 render_work, time_dt() - start_time, is_cancel_requested());
502}
503
505{
506 if (!render_work.adaptive_sampling.filter) {
507 return;
508 }
509
510 bool did_reschedule_on_idle = false;
511
512 while (true) {
513 LOG_DEBUG << "Will filter adaptive stopping buffer, threshold "
514 << render_work.adaptive_sampling.threshold;
515 if (render_work.adaptive_sampling.reset) {
516 LOG_DEBUG << "Will re-calculate convergency flag for currently converged pixels.";
517 }
518
519 const double start_time = time_dt();
520
521 uint num_active_pixels = 0;
522 parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
523 const uint num_active_pixels_in_work =
524 path_trace_work->adaptive_sampling_converge_filter_count_active(
525 render_work.adaptive_sampling.threshold, render_work.adaptive_sampling.reset);
526 if (num_active_pixels_in_work) {
527 atomic_add_and_fetch_u(&num_active_pixels, num_active_pixels_in_work);
528 }
529 });
530
532 render_work, time_dt() - start_time, is_cancel_requested());
533
534 if (num_active_pixels == 0) {
535 LOG_DEBUG << "All pixels converged.";
537 break;
538 }
539 LOG_DEBUG << "Continuing with lower threshold.";
540 }
541 else if (did_reschedule_on_idle) {
542 break;
543 }
544 else if (num_active_pixels < 128 * 128) {
545 /* NOTE: The hardcoded value of 128^2 is more of an empirical value to keep GPU busy so that
546 * there is no performance loss from the progressive noise floor feature.
547 *
548 * A better heuristic is possible here: for example, use maximum of 128^2 and percentage of
549 * the final resolution. */
551 LOG_DEBUG << "Rescheduling is not possible: final threshold is reached.";
552 break;
553 }
554 LOG_DEBUG << "Rescheduling lower threshold.";
555 did_reschedule_on_idle = true;
556 }
557 else {
558 break;
559 }
560 }
561}
562
564{
565 if (!params.use) {
566 denoiser_.reset();
568 return;
569 }
570
571 GraphicsInteropDevice interop_device;
572 if (display_) {
573 interop_device = display_->graphics_interop_get_device();
574 }
575
576 Device *effective_denoise_device;
577 Device *cpu_fallback_device = cpu_device_.get();
578 const DenoiseParams effective_denoise_params = get_effective_denoise_params(
579 denoise_device_, cpu_fallback_device, params, interop_device, effective_denoise_device);
580
581 bool need_to_recreate_denoiser = false;
582 if (denoiser_) {
583 const DenoiseParams old_denoiser_params = denoiser_->get_params();
584
585 const bool is_cpu_denoising = old_denoiser_params.type == DENOISER_OPENIMAGEDENOISE &&
586 old_denoiser_params.use_gpu == false;
587 const bool always_gpu_denoising = effective_denoise_params.type == DENOISER_DLSS ||
588 effective_denoise_params.type == DENOISER_OPTIX;
589 const bool requested_gpu_denoising = always_gpu_denoising ||
590 (effective_denoise_params.type ==
592 effective_denoise_params.use_gpu == true);
593 if (requested_gpu_denoising && is_cpu_denoising &&
594 effective_denoise_device->info.type == DEVICE_CPU)
595 {
596 /* It won't be possible to use GPU denoising when according to user settings we have
597 * only CPU as available denoising device. So we just exiting early to avoid
598 * unnecessary denoiser recreation or parameters update. */
599 return;
600 }
601
602 const bool is_same_denoising_device_type = old_denoiser_params.use_gpu ==
603 effective_denoise_params.use_gpu;
604 /* Optix Denoiser is not supporting CPU devices, so use_gpu option is not
605 * shown in the UI and changes in the option value should not be checked. */
606 if (old_denoiser_params.type == effective_denoise_params.type &&
607 (is_same_denoising_device_type || always_gpu_denoising))
608 {
609 denoiser_->set_params(effective_denoise_params);
610 }
611 else {
612 need_to_recreate_denoiser = true;
613 }
614 }
615 else {
616 /* if there is no denoiser and param.use is true, then we need to create it. */
617 need_to_recreate_denoiser = true;
618 }
619
620 if (need_to_recreate_denoiser) {
622 effective_denoise_device, cpu_fallback_device, effective_denoise_params, interop_device);
623
624 if (denoiser_) {
625 /* Only take into account the "immediate" cancel to have interactive rendering responding to
626 * navigation as quickly as possible, but allow to run denoiser after user hit Escape key
627 * while doing offline rendering. */
628 denoiser_->is_cancelled_cb = [this]() { return render_cancel_.is_requested; };
629 }
630 }
631
632 /* Use actual parameters, if available */
633 if (denoise_device_ && denoiser_) {
635 }
636 else {
637 render_scheduler_.set_denoiser_params(effective_denoise_params);
638 }
639}
640
642{
643 render_scheduler_.set_adaptive_sampling(adaptive_sampling);
644}
645
647{
648 if (!render_work.cryptomatte.postprocess) {
649 return;
650 }
651 LOG_DEBUG << "Perform cryptomatte work.";
652
653 parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
654 path_trace_work->cryptomatte_postproces();
655 });
656}
657
658void PathTrace::denoise(const RenderWork &render_work)
659{
660 if (!render_work.tile.denoise) {
661 return;
662 }
663
664 if (!denoiser_) {
665 /* Denoiser was not configured, so nothing to do here. */
666 return;
667 }
668
669 LOG_DEBUG << "Perform denoising work.";
670
671 const double start_time = time_dt();
672
673 RenderBuffers *buffer_to_denoise = nullptr;
674 bool allow_inplace_modification = false;
675
676 Device *denoiser_device = denoiser_->get_denoiser_device();
677 if (path_trace_works_.size() > 1 && denoiser_device && !big_tile_denoise_work_) {
679 }
680
682 big_tile_denoise_work_->set_effective_buffer_params(
683 render_state_.effective_big_tile_params,
684 render_state_.effective_big_tile_params,
685 render_state_.effective_denoised_big_tile_params,
686 render_state_.effective_denoised_big_tile_params);
687
688 buffer_to_denoise = big_tile_denoise_work_->get_render_buffers();
689 buffer_to_denoise->reset(render_state_.effective_denoised_big_tile_params);
690
691 copy_to_render_buffers(buffer_to_denoise);
692
693 allow_inplace_modification = true;
694 }
695 else {
696 DCHECK_EQ(path_trace_works_.size(), 1);
697
698 buffer_to_denoise = path_trace_works_.front()->get_render_buffers();
699 }
700
701 if (denoiser_->denoise_buffer(render_state_.effective_big_tile_params,
702 render_state_.effective_denoised_big_tile_params,
703 buffer_to_denoise,
705 allow_inplace_modification,
706 device_scene_->data.integrator.pixel_jitter))
707 {
708 render_state_.has_denoised_result = true;
709 }
710
711 render_scheduler_.report_denoise_time(render_work, time_dt() - start_time);
712}
713
715 const bool has_volume)
716{
717 if (!has_volume || !render_work.volume_guiding_denoise) {
718 return;
719 }
720
721 LOG_DEBUG << "Denoise volume guiding buffers.";
722
723 const double start_time = time_dt();
724
725 /* TODO: in the multi-GPU case, we can denoise on one device and copy to the rest, instead of
726 * denoising on each device separately. */
727 parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
728 path_trace_work->denoise_volume_guiding_buffers();
729 });
730
732}
733
735{
736 output_driver_ = std::move(driver);
737}
738
740{
741 /* The display driver is the source of the drawing context which might be used by
742 * path trace works. Make sure there is no graphics interop using resources from
743 * the old display, as it might no longer be available after this call. */
745
746 if (driver) {
747 display_ = make_unique<PathTraceDisplay>(std::move(driver));
748 }
749 else {
750 display_ = nullptr;
751 }
752}
753
755{
756 if (display_) {
757 display_->zero();
758 }
759}
760
762{
763 if (!display_) {
764 return;
765 }
766
768}
769
771{
772 if (!display_) {
773 return;
774 }
775
776 display_->flush();
777}
778
779void PathTrace::update_display(const RenderWork &render_work)
780{
781 if (!render_work.display.update) {
782 return;
783 }
784
785 if (!display_ && !output_driver_) {
786 LOG_DEBUG << "Ignore display update.";
787 return;
788 }
789
790 if (full_params_.width == 0 || full_params_.height == 0) {
791 LOG_DEBUG << "Skipping PathTraceDisplay update due to 0 size of the render buffer.";
792 return;
793 }
794
795 const double start_time = time_dt();
796
797 if (output_driver_) {
798 LOG_DEBUG << "Invoke buffer update callback.";
799
800 const PathTraceTile tile(*this);
801 output_driver_->update_render_tile(tile);
802 }
803
804 if (display_) {
805 LOG_DEBUG << "Perform copy to GPUDisplay work.";
806
807 const PassType pass_type = film_->get_display_pass();
808 const bool show_denoised =
809 ((render_work.display.use_denoised_result && has_denoised_result() &&
811 is_volume_guiding_pass(pass_type));
812
813 const int texture_width = show_denoised ?
814 render_state_.effective_denoised_big_tile_params.window_width :
815 render_state_.effective_big_tile_params.window_width;
816 const int texture_height = show_denoised ?
817 render_state_.effective_denoised_big_tile_params.window_height :
818 render_state_.effective_big_tile_params.window_height;
819 if (!display_->update_begin(texture_width, texture_height)) {
820 LOG_ERROR << "Error beginning GPUDisplay update.";
821 return;
822 }
823
824 const PassMode pass_mode = show_denoised ? PassMode::DENOISED : PassMode::NOISY;
825
826 /* TODO(sergey): When using multi-device rendering map the GPUDisplay once and copy data from
827 * all works in parallel. */
828 const int num_samples = get_num_samples_in_buffer();
829 if (big_tile_denoise_work_ && render_state_.has_denoised_result) {
830 big_tile_denoise_work_->copy_to_display(display_.get(), pass_mode, num_samples);
831 }
832 else {
833 for (auto &&path_trace_work : path_trace_works_) {
834 path_trace_work->copy_to_display(display_.get(), pass_mode, num_samples);
835 }
836 }
837
838 display_->update_end();
839 }
840
841 render_scheduler_.report_display_update_time(render_work, time_dt() - start_time);
842}
843
844void PathTrace::rebalance(const RenderWork &render_work)
845{
846 if (!render_work.rebalance) {
847 return;
848 }
849
850 const int num_works = path_trace_works_.size();
851
852 if (num_works == 1) {
853 LOG_DEBUG << "Ignoring rebalance work due to single device render.";
854 return;
855 }
856
857 const double start_time = time_dt();
858
860 LOG_DEBUG << "Perform rebalance work.";
861 LOG_DEBUG << "Per-device path tracing time (seconds):";
862 for (int i = 0; i < num_works; ++i) {
863 LOG_DEBUG << path_trace_works_[i]->get_device()->info.description << ": "
864 << work_balance_infos_[i].time_spent;
865 }
866 }
867
868 const bool did_rebalance = work_balance_do_rebalance(work_balance_infos_);
869
871 LOG_DEBUG << "Calculated per-device weights for works:";
872 for (int i = 0; i < num_works; ++i) {
873 LOG_DEBUG << path_trace_works_[i]->get_device()->info.description << ": "
874 << work_balance_infos_[i].weight;
875 }
876 }
877
878 if (!did_rebalance) {
879 LOG_DEBUG << "Balance in path trace works did not change.";
880 render_scheduler_.report_rebalance_time(render_work, time_dt() - start_time, false);
881 return;
882 }
883
884 RenderBuffers big_tile_cpu_buffers(cpu_device_.get());
885 big_tile_cpu_buffers.reset(render_state_.effective_big_tile_params);
886
887 copy_to_render_buffers(&big_tile_cpu_buffers);
888
889 render_state_.need_reset_params = true;
891
892 copy_from_render_buffers(&big_tile_cpu_buffers);
893
894 render_scheduler_.report_rebalance_time(render_work, time_dt() - start_time, true);
895}
896
898{
899 if (!render_work.tile.write) {
900 return;
901 }
902
903 LOG_DEBUG << "Write tile result.";
904
905 render_state_.tile_written = true;
906
907 const bool has_multiple_tiles = tile_manager_.has_multiple_tiles();
908
909 /* Write render tile result, but only if not using tiled rendering.
910 *
911 * Tiles are written to a file during rendering, and written to the software at the end
912 * of rendering (wither when all tiles are finished, or when rendering was requested to be
913 * canceled).
914 *
915 * Important thing is: tile should be written to the software via callback only once. */
916 if (!has_multiple_tiles) {
917 LOG_DEBUG << "Write tile result via buffer write callback.";
919 }
920 /* Write tile to disk, so that the render work's render buffer can be re-used for the next tile.
921 */
922 else {
923 LOG_DEBUG << "Write tile result to disk.";
925 }
926}
927
929{
930 if (!render_work.full.write) {
931 return;
932 }
933
934 LOG_DEBUG << "Handle full-frame render buffer work.";
935
937 LOG_DEBUG << "No tiles on disk.";
938 return;
939 }
940
941 /* Make sure writing to the file is fully finished.
942 * This will include writing all possible missing tiles, ensuring validness of the file. */
944
945 /* NOTE: The rest of full-frame post-processing (such as full-frame denoising) will be done after
946 * all scenes and layers are rendered by the Session (which happens after freeing Session memory,
947 * so that we never hold scene and full-frame buffer in memory at the same time). */
948}
949
951{
953
954 /* With interactive denoisers like DLSS always render 1 complete sample,
955 * otherwise interactivity becomes bad. Otherwise cancel immediately so
956 * the main thread isn't blocked. */
958 render_cancel_.is_requested = true;
959 }
960
961 while (render_cancel_.is_rendering) {
962 render_cancel_.condition.wait(lock);
963 }
964
965 render_cancel_.is_requested = false;
966
967 if (display_) {
968 display_->reset();
969 }
970}
971
976
978{
979 if (render_cancel_.is_requested) {
980 return true;
981 }
982
983 if (progress_ != nullptr) {
984 if (progress_->get_cancel()) {
985 return true;
986 }
987 }
988
989 return false;
990}
991
993{
994 if (!output_driver_) {
995 return;
996 }
997
998 const PathTraceTile tile(*this);
999 output_driver_->write_render_tile(tile);
1000}
1001
1003{
1004 if (!device_scene_->data.bake.use) {
1005 return;
1006 }
1007
1008 if (!output_driver_) {
1009 return;
1010 }
1011
1012 /* Read buffers back from device. */
1013 parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
1014 path_trace_work->copy_render_buffers_from_device();
1015 });
1016
1017 /* Read (subset of) passes from output driver. */
1018 const PathTraceTile tile(*this);
1019 if (output_driver_->read_render_tile(tile)) {
1020 /* Copy buffers to device again. */
1021 parallel_for_each(path_trace_works_, [](unique_ptr<PathTraceWork> &path_trace_work) {
1022 path_trace_work->copy_render_buffers_to_device();
1023 });
1024 }
1025}
1026
1028{
1029 /* Sample count pass is required to support per-tile partial results stored in the file. */
1031
1032 const int num_rendered_samples = render_scheduler_.get_num_rendered_samples();
1033
1034 if (num_rendered_samples == 0) {
1035 /* The tile has zero samples, no need to write it. */
1036 return;
1037 }
1038
1039 /* Get access to the CPU-side render buffers of the current big tile. */
1040 RenderBuffers *buffers;
1041 RenderBuffers big_tile_cpu_buffers(cpu_device_.get());
1042
1043 if (path_trace_works_.size() == 1) {
1044 path_trace_works_[0]->copy_render_buffers_from_device();
1045 buffers = path_trace_works_[0]->get_render_buffers();
1046 }
1047 else {
1048 big_tile_cpu_buffers.reset(render_state_.effective_big_tile_params);
1049 copy_to_render_buffers(&big_tile_cpu_buffers);
1050
1051 buffers = &big_tile_cpu_buffers;
1052 }
1053
1054 if (!tile_manager_.write_tile(*buffers)) {
1055 device_->set_error("Error writing tile to file");
1056 }
1057}
1058
1060{
1061 if (progress_ != nullptr) {
1062 const int2 tile_size = get_render_tile_size();
1063 const uint64_t num_samples_added = uint64_t(tile_size.x) * tile_size.y *
1064 render_work.path_trace.num_samples;
1065 const int current_sample = render_scheduler_.get_total_rendered_samples();
1066 progress_->add_samples(num_samples_added, current_sample);
1067 }
1068
1069 if (progress_update_cb) {
1071 }
1072}
1073
1074void PathTrace::progress_set_status(const string &status, const string &substatus)
1075{
1076 if (progress_ != nullptr) {
1077 progress_->set_status(status, substatus);
1078 }
1079}
1080
1082{
1083 parallel_for_each(path_trace_works_,
1084 [&render_buffers](unique_ptr<PathTraceWork> &path_trace_work) {
1085 path_trace_work->copy_to_render_buffers(render_buffers);
1086 });
1087 render_buffers->copy_to_device();
1088}
1089
1091{
1092 render_buffers->copy_from_device();
1093 parallel_for_each(path_trace_works_,
1094 [&render_buffers](unique_ptr<PathTraceWork> &path_trace_work) {
1095 path_trace_work->copy_from_render_buffers(render_buffers);
1096 });
1097}
1098
1100{
1101 if (full_frame_state_.render_buffers) {
1102 /* Full-frame buffer is always allocated on CPU. */
1103 return true;
1104 }
1105
1106 if (big_tile_denoise_work_ && render_state_.has_denoised_result) {
1107 return big_tile_denoise_work_->copy_render_buffers_from_device();
1108 }
1109
1110 bool success = true;
1111
1112 parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
1113 if (!success) {
1114 return;
1115 }
1116 if (!path_trace_work->copy_render_buffers_from_device()) {
1117 success = false;
1118 }
1119 });
1120
1121 return success;
1122}
1123
1124static string get_layer_view_name(const RenderBuffers &buffers)
1125{
1126 string result;
1127
1128 if (!buffers.params.layer.empty()) {
1129 result += string(buffers.params.layer);
1130 }
1131
1132 if (!buffers.params.view.empty()) {
1133 if (!result.empty()) {
1134 result += ", ";
1135 }
1136 result += string(buffers.params.view);
1137 }
1138
1139 return result;
1140}
1141
1143{
1144 LOG_DEBUG << "Processing full frame buffer file " << filename;
1145
1146 progress_set_status("Reading full buffer from disk");
1147
1148 RenderBuffers full_frame_buffers(cpu_device_.get());
1149
1150 DenoiseParams denoise_params;
1151 if (!tile_manager_.read_full_buffer_from_disk(filename, &full_frame_buffers, &denoise_params)) {
1152 const string error_message = "Error reading tiles from file";
1153 if (progress_) {
1154 progress_->set_error(error_message);
1155 progress_->set_cancel(error_message);
1156 }
1157 else {
1158 LOG_ERROR << error_message;
1159 }
1160 return;
1161 }
1162
1163 const string layer_view_name = get_layer_view_name(full_frame_buffers);
1164
1165 render_state_.has_denoised_result = false;
1166
1167 if (denoise_params.use && denoiser_ && !progress_->get_cancel()) {
1168 progress_set_status(layer_view_name, "Denoising");
1169
1170 /* If GPU should be used is not based on file metadata. */
1172
1173 /* Re-use the denoiser as much as possible, avoiding possible device re-initialization.
1174 *
1175 * It will not conflict with the regular rendering as:
1176 * - Rendering is supposed to be finished here.
1177 * - The next rendering will go via Session's `run_update_for_next_iteration` which will
1178 * ensure proper denoiser is used. */
1179 set_denoiser_params(denoise_params);
1180
1181 /* Number of samples doesn't matter too much, since the samples count pass will be used. */
1182 denoiser_->denoise_buffer(
1183 full_frame_buffers.params, full_frame_buffers.params, &full_frame_buffers, 0, false);
1184
1185 render_state_.has_denoised_result = true;
1186 }
1187
1188 full_frame_state_.render_buffers = &full_frame_buffers;
1189
1190 progress_set_status(layer_view_name, "Finishing");
1191
1192 /* Write the full result pretending that there is a single tile.
1193 * Requires some state change, but allows to use same communication API with the software. */
1195
1196 full_frame_state_.render_buffers = nullptr;
1197}
1198
1200{
1201 if (full_frame_state_.render_buffers) {
1202 return full_frame_state_.render_buffers->params.samples;
1203 }
1204
1206}
1207
1209 const PassAccessor::Destination &destination)
1210{
1211 if (full_frame_state_.render_buffers) {
1212 return pass_accessor.get_render_tile_pixels(full_frame_state_.render_buffers, destination);
1213 }
1214
1215 if (big_tile_denoise_work_ && render_state_.has_denoised_result) {
1216 /* Only use the big tile denoised buffer to access the denoised passes.
1217 * The guiding passes are allowed to be modified in-place for the needs of the denoiser,
1218 * so copy those from the original devices buffers. */
1219 if (pass_accessor.get_pass_access_info().mode == PassMode::DENOISED) {
1220 return big_tile_denoise_work_->get_render_tile_pixels(pass_accessor, destination);
1221 }
1222 }
1223
1224 bool success = true;
1225
1226 parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
1227 if (!success) {
1228 return;
1229 }
1230 if (!path_trace_work->get_render_tile_pixels(pass_accessor, destination)) {
1231 success = false;
1232 }
1233 });
1234
1235 return success;
1236}
1237
1239 const PassAccessor::Source &source)
1240{
1241 bool success = true;
1242
1243 parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) {
1244 if (!success) {
1245 return;
1246 }
1247 if (!path_trace_work->set_render_tile_pixels(pass_accessor, source)) {
1248 success = false;
1249 }
1250 });
1251
1252 return success;
1253}
1254
1256{
1257 if (full_frame_state_.render_buffers) {
1258 return make_int2(full_frame_state_.render_buffers->params.window_width,
1259 full_frame_state_.render_buffers->params.window_height);
1260 }
1261
1263 return make_int2(tile.window_width, tile.window_height);
1264}
1265
1267{
1268 if (full_frame_state_.render_buffers) {
1269 return make_int2(0, 0);
1270 }
1271
1273 return make_int2(tile.x + tile.window_x, tile.y + tile.window_y);
1274}
1275
1277{
1278 return tile_manager_.get_size();
1279}
1280
1282{
1283 if (full_frame_state_.render_buffers) {
1284 return full_frame_state_.render_buffers->params;
1285 }
1286
1287 return big_tile_params_;
1288}
1289
1291{
1292 return render_state_.has_denoised_result;
1293}
1294
1296{
1297 /* Destroy any GPU resource which was used for graphics interop.
1298 * Need to have access to the PathTraceDisplay as it is the only source of drawing context which
1299 * is used for interop. */
1300 if (display_) {
1301 for (auto &&path_trace_work : path_trace_works_) {
1302 path_trace_work->destroy_gpu_resources(display_.get());
1303 }
1304
1306 big_tile_denoise_work_->destroy_gpu_resources(display_.get());
1307 }
1308 }
1309}
1310
1311/* --------------------------------------------------------------------
1312 * Report generation.
1313 */
1314
1315static const char *device_type_for_description(const DeviceType type)
1316{
1317 switch (type) {
1318 case DEVICE_NONE:
1319 return "None";
1320
1321 case DEVICE_CPU:
1322 return "CPU";
1323 case DEVICE_CUDA:
1324 return "CUDA";
1325 case DEVICE_OPTIX:
1326 return "OptiX";
1327 case DEVICE_HIP:
1328 return "HIP";
1329 case DEVICE_HIPRT:
1330 return "HIPRT";
1331 case DEVICE_ONEAPI:
1332 return "oneAPI";
1333 case DEVICE_DUMMY:
1334 return "Dummy";
1335 case DEVICE_MULTI:
1336 return "Multi";
1337 case DEVICE_METAL:
1338 return "Metal";
1339 }
1340
1341 return "UNKNOWN";
1342}
1343
1344/* Construct description of the device which will appear in the full report. */
1345/* TODO(sergey): Consider making it more reusable utility. */
1346static string full_device_info_description(const DeviceInfo &device_info)
1347{
1348 string full_description = device_info.description;
1349
1350 full_description += " (" + string(device_type_for_description(device_info.type)) + ")";
1351
1352 if (device_info.display_device) {
1353 full_description += " (display)";
1354 }
1355
1356 if (device_info.type == DEVICE_CPU) {
1357 full_description += " (" + to_string(device_info.cpu_threads) + " threads)";
1358 }
1359
1360 full_description += " [" + device_info.id + "]";
1361
1362 return full_description;
1363}
1364
1365/* Construct string which will contain information about devices, possibly multiple of the devices.
1366 *
1367 * In the simple case the result looks like:
1368 *
1369 * Message: Full Device Description
1370 *
1371 * If there are multiple devices then the result looks like:
1372 *
1373 * Message: Full First Device Description
1374 * Full Second Device Description
1375 *
1376 * Note that the newlines are placed in a way so that the result can be easily concatenated to the
1377 * full report. */
1378static string device_info_list_report(const string &message,
1379 const DeviceInfo &device_info,
1380 const bool show_hardware_raytracing)
1381{
1382 string result = "\n" + message + ": ";
1383 const string pad(message.length() + 2, ' ');
1384
1385 if (device_info.multi_devices.empty()) {
1386 result += full_device_info_description(device_info) + "\n";
1387 if (show_hardware_raytracing) {
1388 result += pad +
1389 " Hardware Ray-Tracing: " + (device_info.use_hardware_raytracing ? "On" : "Off") +
1390 "\n";
1391 }
1392 return result;
1393 }
1394
1395 bool is_first = true;
1396 for (const DeviceInfo &sub_device_info : device_info.multi_devices) {
1397 if (!is_first) {
1398 result += pad;
1399 }
1400
1401 result += full_device_info_description(sub_device_info) + "\n";
1402 if (show_hardware_raytracing) {
1403 result += pad + " Hardware Ray-Tracing: " +
1404 (sub_device_info.use_hardware_raytracing ? "On" : "Off") + "\n";
1405 }
1406
1407 is_first = false;
1408 }
1409
1410 return result;
1411}
1412
1413static string path_trace_devices_report(const vector<unique_ptr<PathTraceWork>> &path_trace_works)
1414{
1415 DeviceInfo device_info;
1416 device_info.type = DEVICE_MULTI;
1417
1418 for (auto &&path_trace_work : path_trace_works) {
1419 device_info.multi_devices.push_back(path_trace_work->get_device()->info);
1420 }
1421
1422 return device_info_list_report("Path tracing on", device_info, true);
1423}
1424
1425static string denoiser_device_report(const Denoiser *denoiser)
1426{
1427 if (!denoiser) {
1428 return "";
1429 }
1430
1431 if (!denoiser->get_params().use) {
1432 return "";
1433 }
1434
1435 const Device *denoiser_device = denoiser->get_denoiser_device();
1436 if (!denoiser_device) {
1437 return "";
1438 }
1439
1440 return device_info_list_report("Denoising on", denoiser_device->info, false);
1441}
1442
1444{
1445 string result = "Full path tracing report:\n";
1446
1448 result += denoiser_device_report(denoiser_.get());
1449
1450 /* Report from the render scheduler, which includes:
1451 * - Render mode (interactive, offline, headless)
1452 * - Adaptive sampling and denoiser parameters
1453 * - Breakdown of timing. */
1454 result += render_scheduler_.full_report();
1455
1456 return result;
1457}
1458
1459void PathTrace::set_guiding_params(const GuidingParams &guiding_params, const bool reset)
1460{
1461#if defined(WITH_PATH_GUIDING)
1462 if (guiding_params_.modified(guiding_params)) {
1463 guiding_params_ = guiding_params;
1464
1465# if !(OPENPGL_VERSION_MAJOR == 0 && OPENPGL_VERSION_MINOR <= 5)
1466# define OPENPGL_USE_FIELD_CONFIG
1467# endif
1468
1469 if (guiding_params_.use) {
1470# ifdef OPENPGL_USE_FIELD_CONFIG
1471 openpgl::cpp::FieldConfig field_config;
1472# else
1473 PGLFieldArguments field_args;
1474# endif
1475 switch (guiding_params_.type) {
1476 default:
1477 /* Parallax-aware von Mises-Fisher mixture models. */
1479# ifdef OPENPGL_USE_FIELD_CONFIG
1480 field_config.Init(
1481 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1482 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_PARALLAX_AWARE_VMM,
1483 guiding_params.deterministic);
1484# else
1485 pglFieldArgumentsSetDefaults(
1486 field_args,
1487 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1488 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_PARALLAX_AWARE_VMM);
1489# endif
1490 break;
1491 }
1492 /* Directional quad-trees. */
1494# ifdef OPENPGL_USE_FIELD_CONFIG
1495 field_config.Init(
1496 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1497 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_QUADTREE,
1498 guiding_params.deterministic);
1499# else
1500 pglFieldArgumentsSetDefaults(
1501 field_args,
1502 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1503 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_QUADTREE);
1504# endif
1505 break;
1506 }
1507 /* von Mises-Fisher mixture models. */
1508 case GUIDING_TYPE_VMM: {
1509# ifdef OPENPGL_USE_FIELD_CONFIG
1510 field_config.Init(PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1511 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_VMM,
1512 guiding_params.deterministic);
1513# else
1514 pglFieldArgumentsSetDefaults(
1515 field_args,
1516 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1517 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_VMM);
1518# endif
1519 break;
1520 }
1521 }
1522# ifdef OPENPGL_USE_FIELD_CONFIG
1523 field_config.SetSpatialStructureArgMaxDepth(16);
1524# else
1525 field_args.deterministic = guiding_params.deterministic;
1526 reinterpret_cast<PGLKDTreeArguments *>(field_args.spatialSturctureArguments)->maxDepth = 16;
1527# endif
1528 openpgl::cpp::Device *guiding_device = static_cast<openpgl::cpp::Device *>(
1530 if (guiding_device) {
1531 guiding_sample_data_storage_ = make_unique<openpgl::cpp::SampleStorage>();
1532# ifdef OPENPGL_USE_FIELD_CONFIG
1533 guiding_field_ = make_unique<openpgl::cpp::Field>(guiding_device, field_config);
1534# else
1535 guiding_field_ = make_unique<openpgl::cpp::Field>(guiding_device, field_args);
1536# endif
1537 }
1538 else {
1539 guiding_sample_data_storage_ = nullptr;
1540 guiding_field_ = nullptr;
1541 }
1542 }
1543 else {
1544 guiding_sample_data_storage_ = nullptr;
1545 guiding_field_ = nullptr;
1546 }
1547 }
1548 else if (reset) {
1549 if (guiding_field_) {
1550 guiding_field_->Reset();
1551 }
1552 }
1553#else
1554 (void)guiding_params;
1555 (void)reset;
1556#endif
1557}
1558
1560{
1561#if defined(WITH_PATH_GUIDING)
1562 const bool train = (guiding_params_.training_samples == 0) ||
1563 (guiding_field_->GetIteration() < guiding_params_.training_samples);
1564
1565 for (auto &&path_trace_work : path_trace_works_) {
1566 path_trace_work->guiding_init_kernel_globals(
1567 guiding_field_.get(), guiding_sample_data_storage_.get(), train);
1568 }
1569
1570 if (train) {
1571 /* For training the guiding distribution we need to force the number of samples
1572 * per update to be limited, for reproducible results and reasonable training size.
1573 *
1574 * Idea: we could stochastically discard samples with a probability of 1/num_samples_per_update
1575 * we can then update only after the num_samples_per_update iterations are rendered. */
1577 }
1578 else {
1580 }
1581#endif
1582}
1583
1585{
1586#if defined(WITH_PATH_GUIDING)
1587 LOG_DEBUG << "Update path guiding structures";
1588
1589 LOG_TRACE << "Number of surface samples: " << guiding_sample_data_storage_->GetSizeSurface();
1590 LOG_TRACE << "Number of volume samples: " << guiding_sample_data_storage_->GetSizeVolume();
1591
1592 const size_t num_valid_samples = guiding_sample_data_storage_->GetSizeSurface() +
1593 guiding_sample_data_storage_->GetSizeVolume();
1594
1595 /* we wait until we have at least 1024 samples */
1596 if (num_valid_samples >= 1024) {
1597 guiding_field_->Update(*guiding_sample_data_storage_);
1598 guiding_update_count++;
1599
1600 LOG_TRACE << "Path guiding field valid: " << guiding_field_->Validate();
1601
1602 guiding_sample_data_storage_->Clear();
1603 }
1604#endif
1605}
1606
ATOMIC_INLINE unsigned int atomic_add_and_fetch_u(unsigned int *p, unsigned int x)
int pad[32 - sizeof(int)]
volatile int lock
unsigned long long int uint64_t
btScalar max
ustring view
Definition buffers.h:97
int pass_stride
Definition buffers.h:92
ustring layer
Definition buffers.h:96
int full_width
Definition buffers.h:85
int get_pass_offset(PassType type, PassMode mode=PassMode::NOISY) const
Definition buffers.cpp:164
int window_y
Definition buffers.h:78
void update_offset_stride()
Definition buffers.cpp:218
bool modified(const BufferParams &other) const
Definition buffers.cpp:224
int full_height
Definition buffers.h:86
int window_height
Definition buffers.h:80
int window_width
Definition buffers.h:79
NODE_DECLARE int width
Definition buffers.h:70
int window_x
Definition buffers.h:77
DenoiserType type
Definition denoise.h:73
bool use_gpu
Definition denoise.h:86
NODE_DECLARE bool use
Definition denoise.h:70
static unique_ptr< Denoiser > create(Device *denoiser_device, Device *cpu_fallback_device, const DenoiseParams &params, const GraphicsInteropDevice &interop_device)
Definition denoiser.cpp:163
Device * get_denoiser_device() const
Definition denoiser.cpp:309
const DenoiseParams & get_params() const
Definition denoiser.cpp:271
vector< DeviceInfo > multi_devices
bool display_device
DeviceType type
string description
bool use_hardware_raytracing
KernelData data
virtual void * get_guiding_device() const
Profiler & profiler
Stats & stats
virtual void set_error(const string &error)
bool headless
DeviceInfo info
virtual void foreach_device(const std::function< void(Device *)> &callback)
bool have_error()
Definition film.h:29
bool get_render_tile_pixels(const RenderBuffers *render_buffers, const Destination &destination) const
const PassAccessInfo & get_pass_access_info() const
static unique_ptr< PathTraceWork > create(Device *device, Film *film, DeviceScene *device_scene, const bool *cancel_requested_flag)
virtual void render_samples(RenderStatistics &statistics, const int start_sample, const int samples_num, const int sample_offset)=0
Device * get_device() const
void device_free()
Progress * progress_
Definition path_trace.h:342
void render_deinit_kernel_execution()
void denoise(const RenderWork &render_work)
int2 get_render_tile_size() const
void finalize_full_buffer_on_disk(const RenderWork &render_work)
std::function< void(void)> progress_update_cb
Definition path_trace.h:187
void process_full_buffer_from_disk(string_view filename)
void tile_buffer_write()
Device * device_
Definition path_trace.h:260
unique_ptr< Denoiser > denoiser_
Definition path_trace.h:293
void update_effective_work_buffer_params(const RenderWork &render_work)
BufferParams full_params_
Definition path_trace.h:289
void rebalance(const RenderWork &render_work)
bool is_cancel_requested()
void init_render_buffers(const RenderWork &render_work)
void copy_to_render_buffers(RenderBuffers *render_buffers)
void destroy_gpu_resources()
struct PathTrace::@127322252215372354363353156034112366364350337004 full_frame_state_
bool has_denoised_result() const
void set_progress(Progress *progress)
vector< unique_ptr< PathTraceWork > > path_trace_works_
Definition path_trace.h:283
void copy_from_render_buffers(RenderBuffers *render_buffers)
Device * denoise_device_
Definition path_trace.h:264
void set_denoiser_params(const DenoiseParams &params)
void progress_update_if_needed(const RenderWork &render_work)
void update_display(const RenderWork &render_work)
void progress_set_status(const string &status, const string &substatus="")
void set_adaptive_sampling(const AdaptiveSampling &adaptive_sampling)
void set_output_driver(unique_ptr< OutputDriver > driver)
void reset(const BufferParams &full_params, const BufferParams &big_tile_params, bool reset_rendering)
DeviceScene * device_scene_
Definition path_trace.h:270
bool ready_to_reset()
bool get_render_tile_pixels(const PassAccessor &pass_accessor, const PassAccessor::Destination &destination)
void cancel()
void guiding_update_structures()
PathTrace(Device *device, Device *denoise_device, Film *film, DeviceScene *device_scene, RenderScheduler &render_scheduler, TileManager &tile_manager)
void zero_display()
void guiding_prepare_structures()
int2 get_render_tile_offset() const
unique_ptr< Device > cpu_device_
Definition path_trace.h:267
void denoise_volume_guiding_buffers(const RenderWork &render_work, const bool has_volume)
void set_guiding_params(const GuidingParams &params, const bool reset)
void tile_buffer_write_to_disk()
void set_display_driver(unique_ptr< DisplayDriver > driver)
void path_trace(RenderWork &render_work)
void render_pipeline(RenderWork render_work)
unique_ptr< OutputDriver > output_driver_
Definition path_trace.h:279
unique_ptr< PathTraceDisplay > display_
Definition path_trace.h:276
vector< WorkBalanceInfo > work_balance_infos_
Definition path_trace.h:286
bool copy_render_tile_from_device()
struct PathTrace::@173325273166301271234167061230356352223360370066 render_state_
bool did_draw_after_reset_
Definition path_trace.h:360
void render_init_kernel_execution()
int2 get_render_size() const
TileManager & tile_manager_
Definition path_trace.h:273
unique_ptr< PathTraceWork > big_tile_denoise_work_
Definition path_trace.h:296
void update_work_buffer_params_if_needed(const RenderWork &render_work)
void alloc_work_memory()
BufferParams big_tile_params_
Definition path_trace.h:290
void draw()
void write_tile_buffer(const RenderWork &render_work)
void tile_buffer_read()
bool set_render_tile_pixels(PassAccessor &pass_accessor, const PassAccessor::Source &source)
void render(const RenderWork &render_work)
Film * film_
Definition path_trace.h:269
string full_report() const
void adaptive_sample(RenderWork &render_work)
void load_kernels()
const BufferParams & get_render_tile_params() const
struct PathTrace::@031215327331345151264042216111247320217046075201 render_cancel_
int get_num_render_tile_samples() const
void flush_display()
RenderScheduler & render_scheduler_
Definition path_trace.h:272
int get_num_samples_in_buffer()
void cryptomatte_postprocess(const RenderWork &render_work)
void update_allocated_work_buffer_params()
void set_cancel(const string &cancel_message_)
Definition progress.h:70
bool get_cancel() const
Definition progress.h:77
void set_status(const string &status_, const string &substatus_="")
Definition progress.h:248
void add_samples(const uint64_t pixel_samples_, int tile_sample)
Definition progress.h:200
void set_error(const string &error_message_)
Definition progress.h:98
BufferParams params
Definition buffers.h:155
bool copy_from_device()
Definition buffers.cpp:286
void copy_to_device()
Definition buffers.cpp:299
void reset(const BufferParams &params)
Definition buffers.cpp:271
void report_path_trace_occupancy(const RenderWork &render_work, const float occupancy)
void report_adaptive_filter_time(const RenderWork &render_work, const double time, bool is_cancelled)
void set_need_schedule_rebalance(bool need_schedule_rebalance)
int get_num_rendered_samples() const
string full_report() const
void report_denoise_time(const RenderWork &render_work, const double time)
void set_denoiser_params(const DenoiseParams &params)
bool is_denoiser_interactive() const
int get_total_rendered_samples() const
bool render_work_reschedule_on_idle(RenderWork &render_work)
void report_display_update_time(const RenderWork &render_work, const double time)
bool is_denoiser_gpu_used() const
void report_path_trace_time(const RenderWork &render_work, const double time, bool is_cancelled)
void set_adaptive_sampling(const AdaptiveSampling &adaptive_sampling)
bool render_work_reschedule_on_converge(RenderWork &render_work)
void report_work_begin(const RenderWork &render_work)
void set_need_schedule_cryptomatte(bool need_schedule_cryptomatte)
void report_rebalance_time(const RenderWork &render_work, const double time, bool balance_changed)
void set_limit_samples_per_update(const int limit_samples)
void report_volume_guiding_denoise_time(const RenderWork &render_work, const double time)
float resolution_divider
bool volume_guiding_denoise
bool init_render_buffers
struct RenderWork::@062144024112073257370032340252251130221344035014 tile
struct RenderWork::@045110325327334210271225251376000202010073303033 adaptive_sampling
struct RenderWork::@103345022157251202112140335355011252273171271005 path_trace
struct RenderWork::@310313166116170111017300246342343006316141322247 display
struct RenderWork::@026114172320136364120000247117121135046160342264 cryptomatte
struct RenderWork::@075102241252202025353112266176333317356231366323 full
float denoised_resolution_divider
bool has_multiple_tiles() const
int2 get_size() const
bool has_written_tiles() const
const Tile & get_current_tile() const
bool write_tile(const RenderBuffers &tile_buffers)
bool read_full_buffer_from_disk(string_view filename, RenderBuffers *buffers, DenoiseParams *denoise_params)
void finish_write_tiles()
int get_tile_overscan() const
@ DENOISER_OPTIX
Definition denoise.h:12
@ DENOISER_OPENIMAGEDENOISE
Definition denoise.h:13
@ DENOISER_DLSS
Definition denoise.h:14
DenoiseParams get_effective_denoise_params(Device *denoiser_device, Device *cpu_fallback_device, const DenoiseParams &params, const GraphicsInteropDevice &interop_device, Device *&single_denoiser_device)
Definition denoiser.cpp:118
void device_cpu_info(vector< DeviceInfo > &devices)
CCL_NAMESPACE_BEGIN unique_ptr< Device > device_cpu_create(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless)
#define PASS_UNUSED
#define CCL_NAMESPACE_END
DeviceType
@ DEVICE_DUMMY
@ DEVICE_NONE
@ DEVICE_METAL
@ DEVICE_MULTI
@ DEVICE_CUDA
@ DEVICE_CPU
@ DEVICE_HIPRT
@ DEVICE_OPTIX
@ DEVICE_HIP
@ DEVICE_ONEAPI
ccl_device_forceinline int2 make_int2(const int x, const int y)
#define index(i)
const ccl_global KernelWorkTile * tile
PassType
@ PASS_SAMPLE_COUNT
@ GUIDING_TYPE_VMM
@ GUIDING_TYPE_DIRECTIONAL_QUAD_TREE
@ GUIDING_TYPE_PARALLAX_AWARE_VMM
#define DCHECK(expression)
Definition log.h:135
#define DCHECK_EQ(a, b)
Definition log.h:144
#define LOG_DEBUG
Definition log.h:107
#define LOG_IS_ON(level)
Definition log.h:113
@ LOG_LEVEL_DEBUG
Definition log.h:26
#define LOG_ERROR
Definition log.h:101
#define DCHECK_NE(a, b)
Definition log.h:143
#define LOG_INFO
Definition log.h:106
#define LOG_TRACE
Definition log.h:108
ccl_device_inline uint next_power_of_two(const uint x)
Definition math_base.h:832
bool is_volume_guiding_pass(const PassType pass_type)
Definition pass.cpp:478
PassMode
Definition pass.h:20
@ DENOISED
Definition pass.h:22
@ NOISY
Definition pass.h:21
static string device_info_list_report(const string &message, const DeviceInfo &device_info, const bool show_hardware_raytracing)
static string path_trace_devices_report(const vector< unique_ptr< PathTraceWork > > &path_trace_works)
static string full_device_info_description(const DeviceInfo &device_info)
static BufferParams slice_buffer_params(const BufferParams &buffer_params, const float resolution_divider, const int full_res_window_height, const vector< WorkBalanceInfo > &work_balance_infos, const int index, const int overscan)
static BufferParams scale_buffer_params(const BufferParams &params, const float resolution_divider)
static string get_layer_view_name(const RenderBuffers &buffers)
static const char * device_type_for_description(const DeviceType type)
static int scale_window_y(const int window_y, const int window_height, const int scaled_window_height, const float resolution_divider)
static string denoiser_device_report(const Denoiser *denoiser)
#define SCOPED_DEFER(code)
#define min(a, b)
Definition sort.cc:38
string to_string(const char *str)
Definition string.cpp:202
std::unique_lock< std::mutex > thread_scoped_lock
Definition thread.h:28
CCL_NAMESPACE_BEGIN double time_dt()
Definition time.cpp:31
CCL_NAMESPACE_BEGIN void work_balance_do_initial(vector< WorkBalanceInfo > &work_balance_infos)
bool work_balance_do_rebalance(vector< WorkBalanceInfo > &work_balance_infos)