2023-06-14 06:52:36 +00:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
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 "integrator/tile.h"
|
|
|
|
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "util/log.h"
|
|
|
|
#include "util/math.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
|
|
|
|
2023-09-29 14:58:57 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
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
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const TileSize &tile_size)
|
|
|
|
{
|
|
|
|
os << "size: (" << tile_size.width << ", " << tile_size.height << ")";
|
|
|
|
os << ", num_samples: " << tile_size.num_samples;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline uint round_down_to_power_of_two(uint x)
|
|
|
|
{
|
|
|
|
if (is_power_of_two(x)) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prev_power_of_two(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_inline uint round_up_to_power_of_two(uint x)
|
|
|
|
{
|
|
|
|
if (is_power_of_two(x)) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next_power_of_two(x);
|
|
|
|
}
|
|
|
|
|
2021-11-25 08:20:28 +00:00
|
|
|
TileSize tile_calculate_best_size(const bool accel_rt,
|
|
|
|
const int2 &image_size,
|
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
|
|
|
const int num_samples,
|
2021-10-26 06:30:15 +00:00
|
|
|
const int max_num_path_states,
|
|
|
|
const float scrambling_distance)
|
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
|
|
|
{
|
|
|
|
if (max_num_path_states == 1) {
|
|
|
|
/* Simple case: avoid any calculation, which could cause rounding issues. */
|
|
|
|
return TileSize(1, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int64_t num_pixels = image_size.x * image_size.y;
|
|
|
|
const int64_t num_pixel_samples = num_pixels * num_samples;
|
|
|
|
|
|
|
|
if (max_num_path_states >= num_pixel_samples) {
|
|
|
|
/* Image fully fits into the state (could be border render, for example). */
|
|
|
|
return TileSize(image_size.x, image_size.y, num_samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The idea here is to keep number of samples per tile as much as possible to improve coherency
|
|
|
|
* across threads.
|
|
|
|
*
|
|
|
|
* Some general ideas:
|
|
|
|
* - Prefer smaller tiles with more samples, which improves spatial coherency of paths.
|
|
|
|
* - Keep values a power of two, for more integer fit into the maximum number of paths. */
|
|
|
|
|
|
|
|
TileSize tile_size;
|
|
|
|
const int num_path_states_per_sample = max_num_path_states / num_samples;
|
2021-11-25 08:20:28 +00:00
|
|
|
if (scrambling_distance < 0.9f && accel_rt) {
|
2021-10-27 12:14:43 +00:00
|
|
|
/* Prefer large tiles for scrambling distance, bounded by max num path states. */
|
|
|
|
tile_size.width = min(image_size.x, max_num_path_states);
|
|
|
|
tile_size.height = min(image_size.y, max(max_num_path_states / tile_size.width, 1));
|
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
|
|
|
}
|
|
|
|
else {
|
2021-10-26 06:30:15 +00:00
|
|
|
/* Calculate tile size as if it is the most possible one to fit an entire range of samples.
|
|
|
|
* The idea here is to keep tiles as small as possible, and keep device occupied by scheduling
|
|
|
|
* multiple tiles with the same coordinates rendering different samples. */
|
|
|
|
|
|
|
|
if (num_path_states_per_sample != 0) {
|
|
|
|
tile_size.width = round_down_to_power_of_two(lround(sqrt(num_path_states_per_sample)));
|
|
|
|
tile_size.height = tile_size.width;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tile_size.width = tile_size.height = 1;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (num_samples == 1) {
|
|
|
|
tile_size.num_samples = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Heuristic here is to have more uniform division of the sample range: for example prefer
|
|
|
|
* [32 <38 times>, 8] over [1024, 200]. This allows to greedily add more tiles early on. */
|
|
|
|
tile_size.num_samples = min(round_up_to_power_of_two(lround(sqrt(num_samples / 2))),
|
|
|
|
static_cast<uint>(num_samples));
|
|
|
|
|
2021-10-26 06:30:15 +00:00
|
|
|
const int tile_area = tile_size.width * tile_size.height;
|
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
|
|
|
tile_size.num_samples = min(tile_size.num_samples, max_num_path_states / tile_area);
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK_GE(tile_size.width, 1);
|
|
|
|
DCHECK_GE(tile_size.height, 1);
|
|
|
|
DCHECK_GE(tile_size.num_samples, 1);
|
|
|
|
DCHECK_LE(tile_size.width * tile_size.height * tile_size.num_samples, max_num_path_states);
|
|
|
|
|
|
|
|
return tile_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|