2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sstream>
|
2020-03-19 08:33:03 +00:00
|
|
|
#include <stdlib.h>
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-12-10 13:18:25 +00:00
|
|
|
#include "bvh/bvh_multi.h"
|
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "device/device.h"
|
|
|
|
#include "device/device_intern.h"
|
|
|
|
#include "device/device_network.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "render/buffers.h"
|
2020-12-10 13:18:25 +00:00
|
|
|
#include "render/geometry.h"
|
2012-09-04 13:29:07 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_list.h"
|
|
|
|
#include "util/util_logging.h"
|
|
|
|
#include "util/util_map.h"
|
|
|
|
#include "util/util_time.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class MultiDevice : public Device {
|
|
|
|
public:
|
|
|
|
struct SubDevice {
|
2020-06-08 15:16:10 +00:00
|
|
|
Stats stats;
|
2011-04-27 11:58:34 +00:00
|
|
|
Device *device;
|
|
|
|
map<device_ptr, device_ptr> ptr_map;
|
2020-06-08 15:16:10 +00:00
|
|
|
int peer_island_index = -1;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-11 15:30:01 +00:00
|
|
|
list<SubDevice> devices, denoising_devices;
|
2017-10-20 23:09:59 +00:00
|
|
|
device_ptr unique_key;
|
2020-06-08 15:16:10 +00:00
|
|
|
vector<vector<SubDevice *>> peer_islands;
|
2021-03-30 10:59:03 +00:00
|
|
|
bool use_denoising;
|
2020-06-09 17:46:16 +00:00
|
|
|
bool matching_rendering_and_denoising_devices;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-11-29 22:30:17 +00:00
|
|
|
MultiDevice(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background_)
|
2021-03-30 10:59:03 +00:00
|
|
|
: Device(info, stats, profiler, background_),
|
|
|
|
unique_key(1),
|
|
|
|
use_denoising(!info.denoising_devices.empty())
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-01-04 18:06:32 +00:00
|
|
|
foreach (DeviceInfo &subinfo, info.multi_devices) {
|
2017-11-03 23:33:38 +00:00
|
|
|
/* Always add CPU devices at the back since GPU devices can change
|
|
|
|
* host memory pointers, which CPU uses as device pointer. */
|
2020-06-08 15:16:10 +00:00
|
|
|
SubDevice *sub;
|
2017-11-03 23:33:38 +00:00
|
|
|
if (subinfo.type == DEVICE_CPU) {
|
2020-06-08 15:16:10 +00:00
|
|
|
devices.emplace_back();
|
|
|
|
sub = &devices.back();
|
2017-11-03 23:33:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-06-08 15:16:10 +00:00
|
|
|
devices.emplace_front();
|
|
|
|
sub = &devices.front();
|
2017-11-03 23:33:38 +00:00
|
|
|
}
|
2020-06-08 15:16:10 +00:00
|
|
|
|
|
|
|
/* The pointer to 'sub->stats' will stay valid even after new devices
|
|
|
|
* are added, since 'devices' is a linked list. */
|
|
|
|
sub->device = Device::create(subinfo, sub->stats, profiler, background);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (DeviceInfo &subinfo, info.denoising_devices) {
|
2020-06-09 17:46:16 +00:00
|
|
|
denoising_devices.emplace_front();
|
|
|
|
SubDevice *sub = &denoising_devices.front();
|
2020-06-08 15:16:10 +00:00
|
|
|
|
|
|
|
sub->device = Device::create(subinfo, sub->stats, profiler, background);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build a list of peer islands for the available render devices */
|
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
/* First ensure that every device is in at least once peer island */
|
|
|
|
if (sub.peer_island_index < 0) {
|
|
|
|
peer_islands.emplace_back();
|
|
|
|
sub.peer_island_index = (int)peer_islands.size() - 1;
|
|
|
|
peer_islands[sub.peer_island_index].push_back(&sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!info.has_peer_memory) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
/* Second check peer access between devices and fill up the islands accordingly */
|
|
|
|
foreach (SubDevice &peer_sub, devices) {
|
|
|
|
if (peer_sub.peer_island_index < 0 &&
|
|
|
|
peer_sub.device->info.type == sub.device->info.type &&
|
|
|
|
peer_sub.device->check_peer_access(sub.device)) {
|
|
|
|
peer_sub.peer_island_index = sub.peer_island_index;
|
|
|
|
peer_islands[sub.peer_island_index].push_back(&peer_sub);
|
|
|
|
}
|
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 17:46:16 +00:00
|
|
|
/* Try to re-use memory when denoising and render devices use the same physical devices
|
|
|
|
* (e.g. OptiX denoising and CUDA rendering device pointing to the same GPU).
|
|
|
|
* Ordering has to match as well, so that 'DeviceTask::split' behaves consistent. */
|
|
|
|
matching_rendering_and_denoising_devices = denoising_devices.empty() ||
|
|
|
|
(devices.size() == denoising_devices.size());
|
|
|
|
if (matching_rendering_and_denoising_devices) {
|
|
|
|
for (list<SubDevice>::iterator device_it = devices.begin(),
|
|
|
|
denoising_device_it = denoising_devices.begin();
|
|
|
|
device_it != devices.end() && denoising_device_it != denoising_devices.end();
|
|
|
|
++device_it, ++denoising_device_it) {
|
|
|
|
const DeviceInfo &info = device_it->device->info;
|
|
|
|
const DeviceInfo &denoising_info = denoising_device_it->device->info;
|
|
|
|
if ((info.type != DEVICE_CUDA && info.type != DEVICE_OPTIX) ||
|
|
|
|
(denoising_info.type != DEVICE_CUDA && denoising_info.type != DEVICE_OPTIX) ||
|
|
|
|
info.num != denoising_info.num) {
|
|
|
|
matching_rendering_and_denoising_devices = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
#ifdef WITH_NETWORK
|
2011-04-27 11:58:34 +00:00
|
|
|
/* try to add network devices */
|
|
|
|
ServerDiscovery discovery(true);
|
|
|
|
time_sleep(1.0);
|
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
vector<string> servers = discovery.get_server_list();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
foreach (string &server, servers) {
|
2018-11-29 22:30:17 +00:00
|
|
|
Device *device = device_network_create(info, stats, profiler, server.c_str());
|
2011-04-27 11:58:34 +00:00
|
|
|
if (device)
|
|
|
|
devices.push_back(SubDevice(device));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
~MultiDevice()
|
|
|
|
{
|
|
|
|
foreach (SubDevice &sub, devices)
|
|
|
|
delete sub.device;
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (SubDevice &sub, denoising_devices)
|
|
|
|
delete sub.device;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
const string &error_message() override
|
2012-01-04 18:06:32 +00:00
|
|
|
{
|
2020-02-11 15:30:01 +00:00
|
|
|
error_msg.clear();
|
|
|
|
|
|
|
|
foreach (SubDevice &sub, devices)
|
|
|
|
error_msg += sub.device->error_message();
|
|
|
|
foreach (SubDevice &sub, denoising_devices)
|
|
|
|
error_msg += sub.device->error_message();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
return error_msg;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
virtual bool show_samples() const override
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 03:22:34 +00:00
|
|
|
{
|
|
|
|
if (devices.size() > 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return devices.front().device->show_samples();
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
virtual BVHLayoutMask get_bvh_layout_mask() const override
|
2018-10-31 10:46:52 +00:00
|
|
|
{
|
|
|
|
BVHLayoutMask bvh_layout_mask = BVH_LAYOUT_ALL;
|
2020-12-10 13:18:25 +00:00
|
|
|
BVHLayoutMask bvh_layout_mask_all = BVH_LAYOUT_NONE;
|
2018-10-31 10:46:52 +00:00
|
|
|
foreach (const SubDevice &sub_device, devices) {
|
2020-12-10 13:18:25 +00:00
|
|
|
BVHLayoutMask device_bvh_layout_mask = sub_device.device->get_bvh_layout_mask();
|
|
|
|
bvh_layout_mask &= device_bvh_layout_mask;
|
|
|
|
bvh_layout_mask_all |= device_bvh_layout_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* With multiple OptiX devices, every device needs its own acceleration structure */
|
|
|
|
if (bvh_layout_mask == BVH_LAYOUT_OPTIX) {
|
|
|
|
return BVH_LAYOUT_MULTI_OPTIX;
|
2018-10-31 10:46:52 +00:00
|
|
|
}
|
2020-12-10 13:18:25 +00:00
|
|
|
|
|
|
|
/* When devices do not share a common BVH layout, fall back to creating one for each */
|
|
|
|
const BVHLayoutMask BVH_LAYOUT_OPTIX_EMBREE = (BVH_LAYOUT_OPTIX | BVH_LAYOUT_EMBREE);
|
|
|
|
if ((bvh_layout_mask_all & BVH_LAYOUT_OPTIX_EMBREE) == BVH_LAYOUT_OPTIX_EMBREE) {
|
|
|
|
return BVH_LAYOUT_MULTI_OPTIX_EMBREE;
|
|
|
|
}
|
|
|
|
|
2018-10-31 10:46:52 +00:00
|
|
|
return bvh_layout_mask;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
bool load_kernels(const DeviceRequestedFeatures &requested_features) override
|
2011-09-12 13:13:56 +00:00
|
|
|
{
|
|
|
|
foreach (SubDevice &sub, devices)
|
2015-05-09 14:05:49 +00:00
|
|
|
if (!sub.device->load_kernels(requested_features))
|
2011-09-12 13:13:56 +00:00
|
|
|
return false;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2021-03-30 10:59:03 +00:00
|
|
|
use_denoising = requested_features.use_denoising;
|
2020-02-11 15:30:01 +00:00
|
|
|
if (requested_features.use_denoising) {
|
2020-07-06 15:32:32 +00:00
|
|
|
/* Only need denoising feature, everything else is unused. */
|
|
|
|
DeviceRequestedFeatures denoising_features;
|
|
|
|
denoising_features.use_denoising = true;
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (SubDevice &sub, denoising_devices)
|
2020-07-06 15:32:32 +00:00
|
|
|
if (!sub.device->load_kernels(denoising_features))
|
2020-02-11 15:30:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
bool wait_for_availability(const DeviceRequestedFeatures &requested_features) override
|
2019-03-13 11:31:48 +00:00
|
|
|
{
|
|
|
|
foreach (SubDevice &sub, devices)
|
|
|
|
if (!sub.device->wait_for_availability(requested_features))
|
|
|
|
return false;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-11 15:30:01 +00:00
|
|
|
if (requested_features.use_denoising) {
|
|
|
|
foreach (SubDevice &sub, denoising_devices)
|
|
|
|
if (!sub.device->wait_for_availability(requested_features))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-13 11:31:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
DeviceKernelStatus get_active_kernel_switch_state() override
|
2019-03-13 11:31:48 +00:00
|
|
|
{
|
|
|
|
DeviceKernelStatus result = DEVICE_KERNEL_USING_FEATURE_KERNEL;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-03-13 11:31:48 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
DeviceKernelStatus subresult = sub.device->get_active_kernel_switch_state();
|
|
|
|
switch (subresult) {
|
|
|
|
case DEVICE_KERNEL_WAITING_FOR_FEATURE_KERNEL:
|
|
|
|
result = subresult;
|
|
|
|
break;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-03-13 11:31:48 +00:00
|
|
|
case DEVICE_KERNEL_FEATURE_KERNEL_INVALID:
|
|
|
|
case DEVICE_KERNEL_FEATURE_KERNEL_AVAILABLE:
|
|
|
|
return subresult;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-03-13 11:31:48 +00:00
|
|
|
case DEVICE_KERNEL_USING_FEATURE_KERNEL:
|
2019-03-16 18:48:28 +00:00
|
|
|
case DEVICE_KERNEL_UNKNOWN:
|
2019-03-13 11:31:48 +00:00
|
|
|
break;
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
2019-03-13 11:31:48 +00:00
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2019-03-13 11:31:48 +00:00
|
|
|
return result;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-10 13:18:25 +00:00
|
|
|
void build_bvh(BVH *bvh, Progress &progress, bool refit) override
|
2019-09-12 12:50:06 +00:00
|
|
|
{
|
2020-12-10 13:18:25 +00:00
|
|
|
/* Try to build and share a single acceleration structure, if possible */
|
2021-01-05 17:37:31 +00:00
|
|
|
if (bvh->params.bvh_layout == BVH_LAYOUT_BVH2 || bvh->params.bvh_layout == BVH_LAYOUT_EMBREE) {
|
2020-12-10 13:18:25 +00:00
|
|
|
devices.back().device->build_bvh(bvh, progress, refit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-05 17:37:31 +00:00
|
|
|
assert(bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX ||
|
|
|
|
bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE);
|
|
|
|
|
2020-12-10 13:18:25 +00:00
|
|
|
BVHMulti *const bvh_multi = static_cast<BVHMulti *>(bvh);
|
|
|
|
bvh_multi->sub_bvhs.resize(devices.size());
|
|
|
|
|
|
|
|
vector<BVHMulti *> geom_bvhs;
|
|
|
|
geom_bvhs.reserve(bvh->geometry.size());
|
|
|
|
foreach (Geometry *geom, bvh->geometry) {
|
|
|
|
geom_bvhs.push_back(static_cast<BVHMulti *>(geom->bvh));
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
/* Broadcast acceleration structure build to all render devices */
|
2020-12-10 13:18:25 +00:00
|
|
|
size_t i = 0;
|
2020-06-08 15:16:10 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
2020-12-10 13:18:25 +00:00
|
|
|
/* Change geometry BVH pointers to the sub BVH */
|
|
|
|
for (size_t k = 0; k < bvh->geometry.size(); ++k) {
|
|
|
|
bvh->geometry[k]->bvh = geom_bvhs[k]->sub_bvhs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bvh_multi->sub_bvhs[i]) {
|
|
|
|
BVHParams params = bvh->params;
|
|
|
|
if (bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX)
|
|
|
|
params.bvh_layout = BVH_LAYOUT_OPTIX;
|
|
|
|
else if (bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE)
|
|
|
|
params.bvh_layout = sub.device->info.type == DEVICE_OPTIX ? BVH_LAYOUT_OPTIX :
|
|
|
|
BVH_LAYOUT_EMBREE;
|
|
|
|
|
|
|
|
/* Skip building a bottom level acceleration structure for non-instanced geometry on Embree
|
|
|
|
* (since they are put into the top level directly, see bvh_embree.cpp) */
|
|
|
|
if (!params.top_level && params.bvh_layout == BVH_LAYOUT_EMBREE &&
|
|
|
|
!bvh->geometry[0]->is_instanced()) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bvh_multi->sub_bvhs[i] = BVH::create(params, bvh->geometry, bvh->objects, sub.device);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub.device->build_bvh(bvh_multi->sub_bvhs[i], progress, refit);
|
|
|
|
i++;
|
2020-06-08 15:16:10 +00:00
|
|
|
}
|
2019-09-12 12:50:06 +00:00
|
|
|
|
2021-02-05 05:23:34 +00:00
|
|
|
/* Change geometry BVH pointers back to the multi BVH. */
|
2020-12-10 13:18:25 +00:00
|
|
|
for (size_t k = 0; k < bvh->geometry.size(); ++k) {
|
|
|
|
bvh->geometry[k]->bvh = geom_bvhs[k];
|
|
|
|
}
|
2020-09-15 12:57:49 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
virtual void *osl_memory() override
|
2020-03-05 15:28:31 +00:00
|
|
|
{
|
|
|
|
if (devices.size() > 1) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return devices.front().device->osl_memory();
|
|
|
|
}
|
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
bool is_resident(device_ptr key, Device *sub_device) override
|
2020-06-08 15:16:10 +00:00
|
|
|
{
|
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
if (sub.device == sub_device) {
|
|
|
|
return find_matching_mem_device(key, sub)->device == sub_device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubDevice *find_matching_mem_device(device_ptr key, SubDevice &sub)
|
|
|
|
{
|
2020-06-09 17:46:16 +00:00
|
|
|
assert(key != 0 && (sub.peer_island_index >= 0 || sub.ptr_map.find(key) != sub.ptr_map.end()));
|
2020-06-08 15:16:10 +00:00
|
|
|
|
|
|
|
/* Get the memory owner of this key (first try current device, then peer devices) */
|
|
|
|
SubDevice *owner_sub = ⊂
|
|
|
|
if (owner_sub->ptr_map.find(key) == owner_sub->ptr_map.end()) {
|
|
|
|
foreach (SubDevice *island_sub, peer_islands[sub.peer_island_index]) {
|
|
|
|
if (island_sub != owner_sub &&
|
|
|
|
island_sub->ptr_map.find(key) != island_sub->ptr_map.end()) {
|
|
|
|
owner_sub = island_sub;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return owner_sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubDevice *find_suitable_mem_device(device_ptr key, const vector<SubDevice *> &island)
|
|
|
|
{
|
|
|
|
assert(!island.empty());
|
|
|
|
|
|
|
|
/* Get the memory owner of this key or the device with the lowest memory usage when new */
|
|
|
|
SubDevice *owner_sub = island.front();
|
|
|
|
foreach (SubDevice *island_sub, island) {
|
|
|
|
if (key ? (island_sub->ptr_map.find(key) != island_sub->ptr_map.end()) :
|
|
|
|
(island_sub->device->stats.mem_used < owner_sub->device->stats.mem_used)) {
|
|
|
|
owner_sub = island_sub;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return owner_sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline device_ptr find_matching_mem(device_ptr key, SubDevice &sub)
|
|
|
|
{
|
|
|
|
return find_matching_mem_device(key, sub)->ptr_map[key];
|
|
|
|
}
|
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void mem_alloc(device_memory &mem) override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
device_ptr key = unique_key++;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
if (mem.type == MEM_PIXELS) {
|
|
|
|
/* Always allocate pixels memory on all devices
|
|
|
|
* This is necessary to ensure PBOs are registered everywhere, which FILM_CONVERT uses */
|
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
mem.device = sub.device;
|
|
|
|
mem.device_pointer = 0;
|
|
|
|
mem.device_size = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
sub.device->mem_alloc(mem);
|
|
|
|
sub.ptr_map[key] = mem.device_pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(mem.type == MEM_READ_ONLY || mem.type == MEM_READ_WRITE ||
|
|
|
|
mem.type == MEM_DEVICE_ONLY);
|
|
|
|
/* The remaining memory types can be distributed across devices */
|
|
|
|
foreach (const vector<SubDevice *> &island, peer_islands) {
|
|
|
|
SubDevice *owner_sub = find_suitable_mem_device(key, island);
|
|
|
|
mem.device = owner_sub->device;
|
|
|
|
mem.device_pointer = 0;
|
|
|
|
mem.device_size = 0;
|
|
|
|
|
|
|
|
owner_sub->device->mem_alloc(mem);
|
|
|
|
owner_sub->ptr_map[key] = mem.device_pointer;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
mem.device = this;
|
|
|
|
mem.device_pointer = key;
|
2017-10-24 14:59:17 +00:00
|
|
|
stats.mem_alloc(mem.device_size);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void mem_copy_to(device_memory &mem) override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
device_ptr existing_key = mem.device_pointer;
|
|
|
|
device_ptr key = (existing_key) ? existing_key : unique_key++;
|
2017-10-24 14:59:17 +00:00
|
|
|
size_t existing_size = mem.device_size;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
/* The tile buffers are allocated on each device (see below), so copy to all of them */
|
2021-03-30 10:59:03 +00:00
|
|
|
if (strcmp(mem.name, "RenderBuffers") == 0 && use_denoising) {
|
2020-06-08 15:16:10 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
mem.device = sub.device;
|
|
|
|
mem.device_pointer = (existing_key) ? sub.ptr_map[existing_key] : 0;
|
|
|
|
mem.device_size = existing_size;
|
|
|
|
|
|
|
|
sub.device->mem_copy_to(mem);
|
|
|
|
sub.ptr_map[key] = mem.device_pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach (const vector<SubDevice *> &island, peer_islands) {
|
|
|
|
SubDevice *owner_sub = find_suitable_mem_device(existing_key, island);
|
|
|
|
mem.device = owner_sub->device;
|
|
|
|
mem.device_pointer = (existing_key) ? owner_sub->ptr_map[existing_key] : 0;
|
|
|
|
mem.device_size = existing_size;
|
|
|
|
|
|
|
|
owner_sub->device->mem_copy_to(mem);
|
|
|
|
owner_sub->ptr_map[key] = mem.device_pointer;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
if (mem.type == MEM_GLOBAL || mem.type == MEM_TEXTURE) {
|
|
|
|
/* Need to create texture objects and update pointer in kernel globals on all devices */
|
|
|
|
foreach (SubDevice *island_sub, island) {
|
|
|
|
if (island_sub != owner_sub) {
|
|
|
|
island_sub->device->mem_copy_to(mem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
mem.device = this;
|
|
|
|
mem.device_pointer = key;
|
2017-10-24 14:59:17 +00:00
|
|
|
stats.mem_alloc(mem.device_size - existing_size);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void mem_copy_from(device_memory &mem, int y, int w, int h, int elem) override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
device_ptr key = mem.device_pointer;
|
2012-01-09 16:58:01 +00:00
|
|
|
int i = 0, sub_h = h / devices.size();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
2012-01-09 16:58:01 +00:00
|
|
|
int sy = y + i * sub_h;
|
|
|
|
int sh = (i == (int)devices.size() - 1) ? h - sub_h * i : sub_h;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
SubDevice *owner_sub = find_matching_mem_device(key, sub);
|
|
|
|
mem.device = owner_sub->device;
|
|
|
|
mem.device_pointer = owner_sub->ptr_map[key];
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
owner_sub->device->mem_copy_from(mem, sy, w, sh, elem);
|
2012-01-09 16:58:01 +00:00
|
|
|
i++;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
mem.device = this;
|
|
|
|
mem.device_pointer = key;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void mem_zero(device_memory &mem) override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
device_ptr existing_key = mem.device_pointer;
|
|
|
|
device_ptr key = (existing_key) ? existing_key : unique_key++;
|
2017-10-24 14:59:17 +00:00
|
|
|
size_t existing_size = mem.device_size;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
/* This is a hack to only allocate the tile buffers on denoising devices
|
2020-06-25 13:13:02 +00:00
|
|
|
* Similarly the tile buffers also need to be allocated separately on all devices so any
|
|
|
|
* overlap rendered for denoising does not interfere with each other */
|
2021-03-30 10:59:03 +00:00
|
|
|
if (strcmp(mem.name, "RenderBuffers") == 0 && use_denoising) {
|
2020-06-09 17:46:16 +00:00
|
|
|
vector<device_ptr> device_pointers;
|
|
|
|
device_pointers.reserve(devices.size());
|
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
mem.device = sub.device;
|
|
|
|
mem.device_pointer = (existing_key) ? sub.ptr_map[existing_key] : 0;
|
|
|
|
mem.device_size = existing_size;
|
|
|
|
|
|
|
|
sub.device->mem_zero(mem);
|
|
|
|
sub.ptr_map[key] = mem.device_pointer;
|
2020-06-09 17:46:16 +00:00
|
|
|
|
|
|
|
device_pointers.push_back(mem.device_pointer);
|
2020-06-08 15:16:10 +00:00
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (SubDevice &sub, denoising_devices) {
|
2020-06-09 17:46:16 +00:00
|
|
|
if (matching_rendering_and_denoising_devices) {
|
|
|
|
sub.ptr_map[key] = device_pointers.front();
|
|
|
|
device_pointers.erase(device_pointers.begin());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mem.device = sub.device;
|
|
|
|
mem.device_pointer = (existing_key) ? sub.ptr_map[existing_key] : 0;
|
|
|
|
mem.device_size = existing_size;
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2020-06-09 17:46:16 +00:00
|
|
|
sub.device->mem_zero(mem);
|
|
|
|
sub.ptr_map[key] = mem.device_pointer;
|
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-08 15:16:10 +00:00
|
|
|
else {
|
|
|
|
foreach (const vector<SubDevice *> &island, peer_islands) {
|
|
|
|
SubDevice *owner_sub = find_suitable_mem_device(existing_key, island);
|
|
|
|
mem.device = owner_sub->device;
|
|
|
|
mem.device_pointer = (existing_key) ? owner_sub->ptr_map[existing_key] : 0;
|
|
|
|
mem.device_size = existing_size;
|
|
|
|
|
|
|
|
owner_sub->device->mem_zero(mem);
|
|
|
|
owner_sub->ptr_map[key] = mem.device_pointer;
|
|
|
|
}
|
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
mem.device = this;
|
|
|
|
mem.device_pointer = key;
|
2017-10-24 14:59:17 +00:00
|
|
|
stats.mem_alloc(mem.device_size - existing_size);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void mem_free(device_memory &mem) override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
device_ptr key = mem.device_pointer;
|
2017-10-24 14:59:17 +00:00
|
|
|
size_t existing_size = mem.device_size;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
/* Free memory that was allocated for all devices (see above) on each device */
|
2021-03-30 10:59:03 +00:00
|
|
|
if (mem.type == MEM_PIXELS || (strcmp(mem.name, "RenderBuffers") == 0 && use_denoising)) {
|
2020-06-08 15:16:10 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
mem.device = sub.device;
|
|
|
|
mem.device_pointer = sub.ptr_map[key];
|
|
|
|
mem.device_size = existing_size;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
sub.device->mem_free(mem);
|
|
|
|
sub.ptr_map.erase(sub.ptr_map.find(key));
|
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (SubDevice &sub, denoising_devices) {
|
2020-06-09 17:46:16 +00:00
|
|
|
if (matching_rendering_and_denoising_devices) {
|
|
|
|
sub.ptr_map.erase(key);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mem.device = sub.device;
|
|
|
|
mem.device_pointer = sub.ptr_map[key];
|
|
|
|
mem.device_size = existing_size;
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2020-06-09 17:46:16 +00:00
|
|
|
sub.device->mem_free(mem);
|
|
|
|
sub.ptr_map.erase(sub.ptr_map.find(key));
|
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-08 15:16:10 +00:00
|
|
|
else {
|
|
|
|
foreach (const vector<SubDevice *> &island, peer_islands) {
|
|
|
|
SubDevice *owner_sub = find_matching_mem_device(key, *island.front());
|
|
|
|
mem.device = owner_sub->device;
|
|
|
|
mem.device_pointer = owner_sub->ptr_map[key];
|
|
|
|
mem.device_size = existing_size;
|
|
|
|
|
|
|
|
owner_sub->device->mem_free(mem);
|
|
|
|
owner_sub->ptr_map.erase(owner_sub->ptr_map.find(key));
|
|
|
|
|
|
|
|
if (mem.type == MEM_TEXTURE) {
|
|
|
|
/* Free texture objects on all devices */
|
|
|
|
foreach (SubDevice *island_sub, island) {
|
|
|
|
if (island_sub != owner_sub) {
|
|
|
|
island_sub->device->mem_free(mem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
mem.device = this;
|
2011-04-27 11:58:34 +00:00
|
|
|
mem.device_pointer = 0;
|
2017-10-24 14:59:17 +00:00
|
|
|
mem.device_size = 0;
|
|
|
|
stats.mem_free(existing_size);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void const_copy_to(const char *name, void *host, size_t size) override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
foreach (SubDevice &sub, devices)
|
|
|
|
sub.device->const_copy_to(name, host, size);
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
void draw_pixels(device_memory &rgba,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int dx,
|
|
|
|
int dy,
|
|
|
|
int dw,
|
|
|
|
int dh,
|
|
|
|
bool transparent,
|
2020-12-11 16:12:19 +00:00
|
|
|
const DeviceDrawParams &draw_params) override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-06-08 15:16:10 +00:00
|
|
|
assert(rgba.type == MEM_PIXELS);
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
device_ptr key = rgba.device_pointer;
|
2011-04-27 11:58:34 +00:00
|
|
|
int i = 0, sub_h = h / devices.size();
|
2011-09-12 13:13:56 +00:00
|
|
|
int sub_height = height / devices.size();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
int sy = y + i * sub_h;
|
|
|
|
int sh = (i == (int)devices.size() - 1) ? h - sub_h * i : sub_h;
|
2011-09-12 13:13:56 +00:00
|
|
|
int sheight = (i == (int)devices.size() - 1) ? height - sub_height * i : sub_height;
|
2012-01-04 18:06:32 +00:00
|
|
|
int sdy = dy + i * sub_height;
|
2011-04-27 11:58:34 +00:00
|
|
|
/* adjust math for w/width */
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
rgba.device_pointer = sub.ptr_map[key];
|
2017-04-28 17:25:57 +00:00
|
|
|
sub.device->draw_pixels(
|
|
|
|
rgba, sy, w, sh, width, sheight, dx, sdy, dw, dh, transparent, draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
i++;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
rgba.device_pointer = key;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void map_tile(Device *sub_device, RenderTile &tile) override
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2020-02-11 15:30:01 +00:00
|
|
|
if (!tile.buffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
if (sub.device == sub_device) {
|
2020-06-08 15:16:10 +00:00
|
|
|
tile.buffer = find_matching_mem(tile.buffer, sub);
|
2020-02-11 15:30:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (SubDevice &sub, denoising_devices) {
|
|
|
|
if (sub.device == sub_device) {
|
|
|
|
tile.buffer = sub.ptr_map[tile.buffer];
|
|
|
|
return;
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
int device_number(Device *sub_device) override
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
if (sub.device == sub_device)
|
|
|
|
return i;
|
|
|
|
i++;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (SubDevice &sub, denoising_devices) {
|
|
|
|
if (sub.device == sub_device)
|
|
|
|
return i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void map_neighbor_tiles(Device *sub_device, RenderTileNeighbors &neighbors) override
|
2017-05-07 12:40:58 +00:00
|
|
|
{
|
2020-07-09 18:01:22 +00:00
|
|
|
for (int i = 0; i < RenderTileNeighbors::SIZE; i++) {
|
|
|
|
RenderTile &tile = neighbors.tiles[i];
|
|
|
|
|
|
|
|
if (!tile.buffers) {
|
2017-05-07 12:40:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-07-09 18:01:22 +00:00
|
|
|
device_vector<float> &mem = tile.buffers->buffer;
|
|
|
|
tile.buffer = mem.device_pointer;
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2020-06-09 17:46:16 +00:00
|
|
|
if (mem.device == this && matching_rendering_and_denoising_devices) {
|
2020-02-11 15:30:01 +00:00
|
|
|
/* Skip unnecessary copies in viewport mode (buffer covers the
|
2020-02-13 03:01:52 +00:00
|
|
|
* whole image), but still need to fix up the tile device pointer. */
|
2020-07-09 18:01:22 +00:00
|
|
|
map_tile(sub_device, tile);
|
2020-02-11 15:30:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
/* If the tile was rendered on another device, copy its memory to
|
|
|
|
* to the current device now, for the duration of the denoising task.
|
|
|
|
* Note that this temporarily modifies the RenderBuffers and calls
|
|
|
|
* the device, so this function is not thread safe. */
|
2017-10-20 23:09:59 +00:00
|
|
|
if (mem.device != sub_device) {
|
2017-10-24 02:07:24 +00:00
|
|
|
/* Only copy from device to host once. This is faster, but
|
|
|
|
* also required for the case where a CPU thread is denoising
|
|
|
|
* a tile rendered on the GPU. In that case we have to avoid
|
2020-02-13 03:01:52 +00:00
|
|
|
* overwriting the buffer being de-noised by the CPU thread. */
|
2020-07-09 18:01:22 +00:00
|
|
|
if (!tile.buffers->map_neighbor_copied) {
|
|
|
|
tile.buffers->map_neighbor_copied = true;
|
2020-02-11 15:30:01 +00:00
|
|
|
mem.copy_from_device();
|
2017-10-24 02:07:24 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-11 15:30:01 +00:00
|
|
|
if (mem.device == this) {
|
|
|
|
/* Can re-use memory if tile is already allocated on the sub device. */
|
2020-07-09 18:01:22 +00:00
|
|
|
map_tile(sub_device, tile);
|
|
|
|
mem.swap_device(sub_device, mem.device_size, tile.buffer);
|
2020-02-11 15:30:01 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mem.swap_device(sub_device, 0, 0);
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-24 02:07:24 +00:00
|
|
|
mem.copy_to_device();
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2020-07-09 18:01:22 +00:00
|
|
|
tile.buffer = mem.device_pointer;
|
|
|
|
tile.device_size = mem.device_size;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-07-04 11:19:12 +00:00
|
|
|
mem.restore_device();
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
2017-05-07 12:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void unmap_neighbor_tiles(Device *sub_device, RenderTileNeighbors &neighbors) override
|
2017-05-07 12:40:58 +00:00
|
|
|
{
|
2020-07-09 18:01:22 +00:00
|
|
|
RenderTile &target_tile = neighbors.target;
|
|
|
|
device_vector<float> &mem = target_tile.buffers->buffer;
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2020-06-09 17:46:16 +00:00
|
|
|
if (mem.device == this && matching_rendering_and_denoising_devices) {
|
2020-02-11 15:30:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy denoised result back to the host. */
|
2020-07-09 18:01:22 +00:00
|
|
|
mem.swap_device(sub_device, target_tile.device_size, target_tile.buffer);
|
2020-02-11 15:30:01 +00:00
|
|
|
mem.copy_from_device();
|
2018-07-04 11:19:12 +00:00
|
|
|
mem.restore_device();
|
2020-02-11 15:30:01 +00:00
|
|
|
|
2018-07-04 11:19:12 +00:00
|
|
|
/* Copy denoised result to the original device. */
|
|
|
|
mem.copy_to_device();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-07-09 18:01:22 +00:00
|
|
|
for (int i = 0; i < RenderTileNeighbors::SIZE; i++) {
|
|
|
|
RenderTile &tile = neighbors.tiles[i];
|
|
|
|
if (!tile.buffers) {
|
2017-05-07 12:40:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-07-09 18:01:22 +00:00
|
|
|
device_vector<float> &mem = tile.buffers->buffer;
|
2020-02-11 15:30:01 +00:00
|
|
|
|
|
|
|
if (mem.device != sub_device && mem.device != this) {
|
|
|
|
/* Free up memory again if it was allocated for the copy above. */
|
2020-07-09 18:01:22 +00:00
|
|
|
mem.swap_device(sub_device, tile.device_size, tile.buffer);
|
2017-05-07 12:40:58 +00:00
|
|
|
sub_device->mem_free(mem);
|
2018-07-04 11:19:12 +00:00
|
|
|
mem.restore_device();
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-07 12:40:58 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
int get_split_task_count(DeviceTask &task) override
|
2014-07-22 21:41:01 +00:00
|
|
|
{
|
2014-08-05 16:50:50 +00:00
|
|
|
int total_tasks = 0;
|
|
|
|
list<DeviceTask> tasks;
|
|
|
|
task.split(tasks, devices.size());
|
|
|
|
foreach (SubDevice &sub, devices) {
|
|
|
|
if (!tasks.empty()) {
|
|
|
|
DeviceTask subtask = tasks.front();
|
|
|
|
tasks.pop_front();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2014-08-05 16:50:50 +00:00
|
|
|
total_tasks += sub.device->get_split_task_count(subtask);
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
2014-08-05 16:50:50 +00:00
|
|
|
}
|
|
|
|
return total_tasks;
|
2014-07-22 21:41:01 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void task_add(DeviceTask &task) override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-02-26 15:30:42 +00:00
|
|
|
list<SubDevice> task_devices = devices;
|
|
|
|
if (!denoising_devices.empty()) {
|
|
|
|
if (task.type == DeviceTask::DENOISE_BUFFER) {
|
|
|
|
/* Denoising tasks should be redirected to the denoising devices entirely. */
|
|
|
|
task_devices = denoising_devices;
|
|
|
|
}
|
|
|
|
else if (task.type == DeviceTask::RENDER && (task.tile_types & RenderTile::DENOISE)) {
|
|
|
|
const uint tile_types = task.tile_types;
|
|
|
|
/* For normal rendering tasks only redirect the denoising part to the denoising devices.
|
|
|
|
* Do not need to split the task here, since they all run through 'acquire_tile'. */
|
|
|
|
task.tile_types = RenderTile::DENOISE;
|
|
|
|
foreach (SubDevice &sub, denoising_devices) {
|
|
|
|
sub.device->task_add(task);
|
|
|
|
}
|
|
|
|
/* Rendering itself should still be executed on the rendering devices. */
|
|
|
|
task.tile_types = tile_types ^ RenderTile::DENOISE;
|
|
|
|
}
|
|
|
|
}
|
2020-02-11 15:30:01 +00:00
|
|
|
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
list<DeviceTask> tasks;
|
2020-02-11 15:30:01 +00:00
|
|
|
task.split(tasks, task_devices.size());
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (SubDevice &sub, task_devices) {
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
if (!tasks.empty()) {
|
|
|
|
DeviceTask subtask = tasks.front();
|
|
|
|
tasks.pop_front();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-09 17:46:16 +00:00
|
|
|
if (task.buffer)
|
|
|
|
subtask.buffer = find_matching_mem(task.buffer, sub);
|
|
|
|
if (task.rgba_byte)
|
|
|
|
subtask.rgba_byte = sub.ptr_map[task.rgba_byte];
|
|
|
|
if (task.rgba_half)
|
|
|
|
subtask.rgba_half = sub.ptr_map[task.rgba_half];
|
|
|
|
if (task.shader_input)
|
|
|
|
subtask.shader_input = find_matching_mem(task.shader_input, sub);
|
|
|
|
if (task.shader_output)
|
|
|
|
subtask.shader_output = find_matching_mem(task.shader_output, sub);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
sub.device->task_add(subtask);
|
2020-06-09 17:46:16 +00:00
|
|
|
|
|
|
|
if (task.buffers && task.buffers->buffer.device == this) {
|
|
|
|
/* Synchronize access to RenderBuffers, since 'map_neighbor_tiles' is not thread-safe. */
|
|
|
|
sub.device->task_wait();
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void task_wait() override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
foreach (SubDevice &sub, devices)
|
|
|
|
sub.device->task_wait();
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (SubDevice &sub, denoising_devices)
|
|
|
|
sub.device->task_wait();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-11 16:12:19 +00:00
|
|
|
void task_cancel() override
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
foreach (SubDevice &sub, devices)
|
|
|
|
sub.device->task_cancel();
|
2020-02-11 15:30:01 +00:00
|
|
|
foreach (SubDevice &sub, denoising_devices)
|
|
|
|
sub.device->task_cancel();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-29 22:30:17 +00:00
|
|
|
Device *device_multi_create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background)
|
2012-01-04 18:06:32 +00:00
|
|
|
{
|
2018-11-29 22:30:17 +00:00
|
|
|
return new MultiDevice(info, stats, profiler, background);
|
2012-01-04 18:06:32 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|