56 path_trace_device, film, device_scene, &
render_cancel_.is_requested);
79 display_->graphics_interop_activate();
85 display_->graphics_interop_deactivate();
93 path_trace_work->alloc_work_memory();
123 const bool reset_rendering)
136 display_->reset(big_tile_params, reset_rendering);
152 path_trace_work->get_render_buffers()->reset(empty_params);
214 const uint limit =
next_power_of_two(num_rendered_samples) - num_rendered_samples;
226 if (use_guiding && train_guiding) {
261 path_trace_work->init_execution();
268 path_trace_work->deinit_execution();
274 const int window_height,
275 const int scaled_window_height,
276 const float resolution_divider)
278 if (window_y >= window_height) {
279 return scaled_window_height;
282 return min(
int(window_y / resolution_divider), scaled_window_height);
295 const float resolution_divider,
296 const int full_res_window_height,
301 const int num_works = work_balance_infos.size();
304 int full_res_window_y = 0;
305 int full_res_window_end_y = 0;
307 for (
int i = 0; i <=
index; i++) {
308 full_res_window_y = full_res_window_end_y;
310 const double weight = work_balance_infos[i].weight;
311 const int slice_window_height =
max(lround(full_res_window_height * weight), 1);
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);
322 full_res_window_y, full_res_window_height, buffer_params.
window_height, resolution_divider);
324 full_res_window_height,
328 const int slice_window_full_y = buffer_params.
full_y + buffer_params.
window_y + window_y;
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;
350 for (
int i = 0; i < num_works; ++i) {
355 buffers->
reset(slice_params);
369 scaled_params.
width =
max(
int(params.
width / resolution_divider),
374 scaled_params.
full_x = int(params.
full_x / resolution_divider);
375 scaled_params.
full_y = int(params.
full_y / resolution_divider);
381 return scaled_params;
387 const float resolution_divider = render_work.
resolution_divider / denoised_resolution_divider;
390 denoised_resolution_divider);
395 const int scaled_overscan = int(overscan / resolution_divider);
399 for (
int i = 0; i < num_works; ++i) {
401 denoised_resolution_divider,
402 full_res_window_height,
409 full_res_window_height,
415 scaled_big_tile_params, slice_params, denoised_big_tile_params, denoised_slice_params);
418 render_state_.effective_big_tile_params = scaled_big_tile_params;
419 render_state_.effective_denoised_big_tile_params = denoised_big_tile_params;
445 path_trace_work->zero_render_buffers();
461 const double start_time =
time_dt();
465 thread_capture_fp_settings();
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;
484 const double work_time =
time_dt() - work_start_time;
488 LOG_INFO <<
"Rendered " << num_samples <<
" samples in " << work_time <<
" seconds ("
489 << work_time / num_samples
490 <<
" seconds per sample), occupancy: " << statistics.
occupancy;
493 float occupancy_accum = 0.0f;
495 occupancy_accum += balance_info.occupancy;
497 const float occupancy = occupancy_accum / num_works;
510 bool did_reschedule_on_idle =
false;
513 LOG_DEBUG <<
"Will filter adaptive stopping buffer, threshold "
516 LOG_DEBUG <<
"Will re-calculate convergency flag for currently converged pixels.";
519 const double start_time =
time_dt();
521 uint num_active_pixels = 0;
523 const uint num_active_pixels_in_work =
524 path_trace_work->adaptive_sampling_converge_filter_count_active(
526 if (num_active_pixels_in_work) {
534 if (num_active_pixels == 0) {
539 LOG_DEBUG <<
"Continuing with lower threshold.";
541 else if (did_reschedule_on_idle) {
544 else if (num_active_pixels < 128 * 128) {
551 LOG_DEBUG <<
"Rescheduling is not possible: final threshold is reached.";
554 LOG_DEBUG <<
"Rescheduling lower threshold.";
555 did_reschedule_on_idle =
true;
573 interop_device =
display_->graphics_interop_get_device();
576 Device *effective_denoise_device;
579 denoise_device_, cpu_fallback_device, params, interop_device, effective_denoise_device);
581 bool need_to_recreate_denoiser =
false;
586 old_denoiser_params.
use_gpu ==
false;
587 const bool always_gpu_denoising = effective_denoise_params.
type ==
DENOISER_DLSS ||
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 &&
602 const bool is_same_denoising_device_type = old_denoiser_params.
use_gpu ==
603 effective_denoise_params.
use_gpu;
606 if (old_denoiser_params.
type == effective_denoise_params.
type &&
607 (is_same_denoising_device_type || always_gpu_denoising))
609 denoiser_->set_params(effective_denoise_params);
612 need_to_recreate_denoiser =
true;
617 need_to_recreate_denoiser =
true;
620 if (need_to_recreate_denoiser) {
622 effective_denoise_device, cpu_fallback_device, effective_denoise_params, interop_device);
651 LOG_DEBUG <<
"Perform cryptomatte work.";
654 path_trace_work->cryptomatte_postproces();
660 if (!render_work.
tile.denoise) {
671 const double start_time =
time_dt();
674 bool allow_inplace_modification =
false;
693 allow_inplace_modification =
true;
705 allow_inplace_modification,
715 const bool has_volume)
721 LOG_DEBUG <<
"Denoise volume guiding buffers.";
723 const double start_time =
time_dt();
728 path_trace_work->denoise_volume_guiding_buffers();
747 display_ = make_unique<PathTraceDisplay>(std::move(driver));
781 if (!render_work.
display.update) {
791 LOG_DEBUG <<
"Skipping PathTraceDisplay update due to 0 size of the render buffer.";
795 const double start_time =
time_dt();
798 LOG_DEBUG <<
"Invoke buffer update callback.";
805 LOG_DEBUG <<
"Perform copy to GPUDisplay work.";
808 const bool show_denoised =
813 const int texture_width = show_denoised ?
814 render_state_.effective_denoised_big_tile_params.window_width :
816 const int texture_height = show_denoised ?
817 render_state_.effective_denoised_big_tile_params.window_height :
819 if (!
display_->update_begin(texture_width, texture_height)) {
820 LOG_ERROR <<
"Error beginning GPUDisplay update.";
834 path_trace_work->copy_to_display(
display_.get(), pass_mode, num_samples);
852 if (num_works == 1) {
853 LOG_DEBUG <<
"Ignoring rebalance work due to single device render.";
857 const double start_time =
time_dt();
861 LOG_DEBUG <<
"Per-device path tracing time (seconds):";
862 for (
int i = 0; i < num_works; ++i) {
871 LOG_DEBUG <<
"Calculated per-device weights for works:";
872 for (
int i = 0; i < num_works; ++i) {
878 if (!did_rebalance) {
879 LOG_DEBUG <<
"Balance in path trace works did not change.";
899 if (!render_work.
tile.write) {
916 if (!has_multiple_tiles) {
917 LOG_DEBUG <<
"Write tile result via buffer write callback.";
923 LOG_DEBUG <<
"Write tile result to disk.";
930 if (!render_work.
full.write) {
934 LOG_DEBUG <<
"Handle full-frame render buffer work.";
1014 path_trace_work->copy_render_buffers_from_device();
1022 path_trace_work->copy_render_buffers_to_device();
1034 if (num_rendered_samples == 0) {
1051 buffers = &big_tile_cpu_buffers;
1085 path_trace_work->copy_to_render_buffers(render_buffers);
1095 path_trace_work->copy_from_render_buffers(render_buffers);
1110 bool success =
true;
1116 if (!path_trace_work->copy_render_buffers_from_device()) {
1133 if (!result.empty()) {
1144 LOG_DEBUG <<
"Processing full frame buffer file " << filename;
1152 const string error_message =
"Error reading tiles from file";
1183 full_frame_buffers.
params, full_frame_buffers.
params, &full_frame_buffers, 0,
false);
1224 bool success =
true;
1230 if (!path_trace_work->get_render_tile_pixels(pass_accessor, destination)) {
1241 bool success =
true;
1247 if (!path_trace_work->set_render_tile_pixels(pass_accessor, source)) {
1302 path_trace_work->destroy_gpu_resources(
display_.get());
1348 string full_description = device_info.
description;
1353 full_description +=
" (display)";
1360 full_description +=
" [" + device_info.
id +
"]";
1362 return full_description;
1380 const bool show_hardware_raytracing)
1382 string result =
"\n" + message +
": ";
1383 const string pad(message.length() + 2,
' ');
1387 if (show_hardware_raytracing) {
1395 bool is_first =
true;
1402 if (show_hardware_raytracing) {
1403 result +=
pad +
" Hardware Ray-Tracing: " +
1418 for (
auto &&path_trace_work : path_trace_works) {
1419 device_info.
multi_devices.push_back(path_trace_work->get_device()->info);
1436 if (!denoiser_device) {
1445 string result =
"Full path tracing report:\n";
1461#if defined(WITH_PATH_GUIDING)
1462 if (guiding_params_.modified(guiding_params)) {
1463 guiding_params_ = guiding_params;
1465# if !(OPENPGL_VERSION_MAJOR == 0 && OPENPGL_VERSION_MINOR <= 5)
1466# define OPENPGL_USE_FIELD_CONFIG
1469 if (guiding_params_.use) {
1470# ifdef OPENPGL_USE_FIELD_CONFIG
1471 openpgl::cpp::FieldConfig field_config;
1473 PGLFieldArguments field_args;
1475 switch (guiding_params_.type) {
1479# ifdef OPENPGL_USE_FIELD_CONFIG
1481 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1482 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_PARALLAX_AWARE_VMM,
1485 pglFieldArgumentsSetDefaults(
1487 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1488 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_PARALLAX_AWARE_VMM);
1494# ifdef OPENPGL_USE_FIELD_CONFIG
1496 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1497 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_QUADTREE,
1500 pglFieldArgumentsSetDefaults(
1502 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1503 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_QUADTREE);
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,
1514 pglFieldArgumentsSetDefaults(
1516 PGL_SPATIAL_STRUCTURE_TYPE::PGL_SPATIAL_STRUCTURE_KDTREE,
1517 PGL_DIRECTIONAL_DISTRIBUTION_TYPE::PGL_DIRECTIONAL_DISTRIBUTION_VMM);
1522# ifdef OPENPGL_USE_FIELD_CONFIG
1523 field_config.SetSpatialStructureArgMaxDepth(16);
1526 reinterpret_cast<PGLKDTreeArguments *
>(field_args.spatialSturctureArguments)->maxDepth = 16;
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);
1535 guiding_field_ = make_unique<openpgl::cpp::Field>(guiding_device, field_args);
1539 guiding_sample_data_storage_ =
nullptr;
1540 guiding_field_ =
nullptr;
1544 guiding_sample_data_storage_ =
nullptr;
1545 guiding_field_ =
nullptr;
1549 if (guiding_field_) {
1550 guiding_field_->Reset();
1554 (void)guiding_params;
1561#if defined(WITH_PATH_GUIDING)
1562 const bool train = (guiding_params_.training_samples == 0) ||
1563 (guiding_field_->GetIteration() < guiding_params_.training_samples);
1566 path_trace_work->guiding_init_kernel_globals(
1567 guiding_field_.get(), guiding_sample_data_storage_.get(), train);
1586#if defined(WITH_PATH_GUIDING)
1587 LOG_DEBUG <<
"Update path guiding structures";
1589 LOG_TRACE <<
"Number of surface samples: " << guiding_sample_data_storage_->GetSizeSurface();
1590 LOG_TRACE <<
"Number of volume samples: " << guiding_sample_data_storage_->GetSizeVolume();
1592 const size_t num_valid_samples = guiding_sample_data_storage_->GetSizeSurface() +
1593 guiding_sample_data_storage_->GetSizeVolume();
1596 if (num_valid_samples >= 1024) {
1597 guiding_field_->Update(*guiding_sample_data_storage_);
1598 guiding_update_count++;
1600 LOG_TRACE <<
"Path guiding field valid: " << guiding_field_->Validate();
1602 guiding_sample_data_storage_->Clear();
ATOMIC_INLINE unsigned int atomic_add_and_fetch_u(unsigned int *p, unsigned int x)
int pad[32 - sizeof(int)]
unsigned long long int uint64_t
int get_pass_offset(PassType type, PassMode mode=PassMode::NOISY) const
void update_offset_stride()
bool modified(const BufferParams &other) const
static unique_ptr< Denoiser > create(Device *denoiser_device, Device *cpu_fallback_device, const DenoiseParams ¶ms, const GraphicsInteropDevice &interop_device)
Device * get_denoiser_device() const
const DenoiseParams & get_params() const
vector< DeviceInfo > multi_devices
bool use_hardware_raytracing
virtual void * get_guiding_device() const
virtual void set_error(const string &error)
virtual void foreach_device(const std::function< void(Device *)> &callback)
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 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
void process_full_buffer_from_disk(string_view filename)
unique_ptr< Denoiser > denoiser_
void update_effective_work_buffer_params(const RenderWork &render_work)
BufferParams full_params_
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_
void copy_from_render_buffers(RenderBuffers *render_buffers)
void set_denoiser_params(const DenoiseParams ¶ms)
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_
bool get_render_tile_pixels(const PassAccessor &pass_accessor, const PassAccessor::Destination &destination)
void guiding_update_structures()
PathTrace(Device *device, Device *denoise_device, Film *film, DeviceScene *device_scene, RenderScheduler &render_scheduler, TileManager &tile_manager)
void guiding_prepare_structures()
int2 get_render_tile_offset() const
unique_ptr< Device > cpu_device_
void denoise_volume_guiding_buffers(const RenderWork &render_work, const bool has_volume)
void set_guiding_params(const GuidingParams ¶ms, 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_
unique_ptr< PathTraceDisplay > display_
vector< WorkBalanceInfo > work_balance_infos_
bool copy_render_tile_from_device()
struct PathTrace::@173325273166301271234167061230356352223360370066 render_state_
bool did_draw_after_reset_
void render_init_kernel_execution()
int2 get_render_size() const
TileManager & tile_manager_
unique_ptr< PathTraceWork > big_tile_denoise_work_
void update_work_buffer_params_if_needed(const RenderWork &render_work)
BufferParams big_tile_params_
void write_tile_buffer(const RenderWork &render_work)
bool set_render_tile_pixels(PassAccessor &pass_accessor, const PassAccessor::Source &source)
void render(const RenderWork &render_work)
string full_report() const
void adaptive_sample(RenderWork &render_work)
const BufferParams & get_render_tile_params() const
struct PathTrace::@031215327331345151264042216111247320217046075201 render_cancel_
int get_num_render_tile_samples() const
RenderScheduler & render_scheduler_
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_)
void set_status(const string &status_, const string &substatus_="")
void add_samples(const uint64_t pixel_samples_, int tile_sample)
void set_error(const string &error_message_)
void reset(const BufferParams ¶ms)
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 ¶ms)
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)
bool volume_guiding_denoise
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
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_OPENIMAGEDENOISE
DenoiseParams get_effective_denoise_params(Device *denoiser_device, Device *cpu_fallback_device, const DenoiseParams ¶ms, const GraphicsInteropDevice &interop_device, Device *&single_denoiser_device)
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 CCL_NAMESPACE_END
const ccl_global KernelWorkTile * tile
@ GUIDING_TYPE_DIRECTIONAL_QUAD_TREE
@ GUIDING_TYPE_PARALLAX_AWARE_VMM
#define DCHECK(expression)
ccl_device_inline uint next_power_of_two(const uint x)
bool is_volume_guiding_pass(const PassType pass_type)
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 ¶ms, 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)
string to_string(const char *str)
std::unique_lock< std::mutex > thread_scoped_lock
CCL_NAMESPACE_BEGIN double time_dt()
CCL_NAMESPACE_BEGIN void work_balance_do_initial(vector< WorkBalanceInfo > &work_balance_infos)
bool work_balance_do_rebalance(vector< WorkBalanceInfo > &work_balance_infos)