2023-06-14 06:52:36 +00:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#ifndef __DEVICE_H__
|
|
|
|
#define __DEVICE_H__
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "bvh/params.h"
|
|
|
|
|
|
|
|
#include "device/denoise.h"
|
|
|
|
#include "device/memory.h"
|
|
|
|
|
|
|
|
#include "util/function.h"
|
|
|
|
#include "util/list.h"
|
|
|
|
#include "util/log.h"
|
|
|
|
#include "util/stats.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
#include "util/texture.h"
|
|
|
|
#include "util/thread.h"
|
|
|
|
#include "util/types.h"
|
|
|
|
#include "util/unique_ptr.h"
|
|
|
|
#include "util/vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2019-09-12 12:50:06 +00:00
|
|
|
class BVH;
|
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
|
|
|
class DeviceQueue;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Progress;
|
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
|
|
|
class CPUKernels;
|
|
|
|
class CPUKernelThreadGlobals;
|
2022-07-12 13:32:46 +00:00
|
|
|
class Scene;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
/* Device Types */
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
enum DeviceType {
|
2019-01-29 15:39:30 +00:00
|
|
|
DEVICE_NONE = 0,
|
2011-04-27 11:58:34 +00:00
|
|
|
DEVICE_CPU,
|
|
|
|
DEVICE_CUDA,
|
2019-09-12 12:50:06 +00:00
|
|
|
DEVICE_MULTI,
|
|
|
|
DEVICE_OPTIX,
|
2021-09-28 14:51:14 +00:00
|
|
|
DEVICE_HIP,
|
2023-04-24 17:05:30 +00:00
|
|
|
DEVICE_HIPRT,
|
2021-12-07 15:11:35 +00:00
|
|
|
DEVICE_METAL,
|
2022-06-29 10:58:04 +00:00
|
|
|
DEVICE_ONEAPI,
|
2020-10-28 18:55:41 +00:00
|
|
|
DEVICE_DUMMY,
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2019-01-29 15:39:30 +00:00
|
|
|
enum DeviceTypeMask {
|
|
|
|
DEVICE_MASK_CPU = (1 << DEVICE_CPU),
|
|
|
|
DEVICE_MASK_CUDA = (1 << DEVICE_CUDA),
|
2019-09-12 12:50:06 +00:00
|
|
|
DEVICE_MASK_OPTIX = (1 << DEVICE_OPTIX),
|
2021-09-28 14:51:14 +00:00
|
|
|
DEVICE_MASK_HIP = (1 << DEVICE_HIP),
|
2021-12-07 15:11:35 +00:00
|
|
|
DEVICE_MASK_METAL = (1 << DEVICE_METAL),
|
2022-06-29 10:58:04 +00:00
|
|
|
DEVICE_MASK_ONEAPI = (1 << DEVICE_ONEAPI),
|
2019-01-29 15:39:30 +00:00
|
|
|
DEVICE_MASK_ALL = ~0
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEVICE_MASK(type) (DeviceTypeMask)(1 << type)
|
|
|
|
|
2023-01-04 16:01:24 +00:00
|
|
|
enum KernelOptimizationLevel {
|
|
|
|
KERNEL_OPTIMIZATION_LEVEL_OFF = 0,
|
|
|
|
KERNEL_OPTIMIZATION_LEVEL_INTERSECT = 1,
|
|
|
|
KERNEL_OPTIMIZATION_LEVEL_FULL = 2,
|
|
|
|
|
|
|
|
KERNEL_OPTIMIZATION_NUM_LEVELS
|
|
|
|
};
|
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
class DeviceInfo {
|
|
|
|
public:
|
|
|
|
DeviceType type;
|
|
|
|
string description;
|
Cycles: Refactor Device selection to allow individual GPU compute device selection
Previously, it was only possible to choose a single GPU or all of that type (CUDA or OpenCL).
Now, a toggle button is displayed for every device.
These settings are tied to the PCI Bus ID of the devices, so they're consistent across hardware addition and removal (but not when swapping/moving cards).
From the code perspective, the more important change is that now, the compute device properties are stored in the Addon preferences of the Cycles addon, instead of directly in the User Preferences.
This allows for a cleaner implementation, removing the Cycles C API functions that were called by the RNA code to specify the enum items.
Note that this change is neither backwards- nor forwards-compatible, but since it's only a User Preference no existing files are broken.
Reviewers: #cycles, brecht
Reviewed By: #cycles, brecht
Subscribers: brecht, juicyfruit, mib2berlin, Blendify
Differential Revision: https://developer.blender.org/D2338
2016-11-07 01:33:53 +00:00
|
|
|
string id; /* used for user preferences, should stay fixed with changing hardware config */
|
2012-01-04 18:06:32 +00:00
|
|
|
int num;
|
2023-03-16 10:56:55 +00:00
|
|
|
bool display_device; /* GPU is used as a display device. */
|
|
|
|
bool has_nanovdb; /* Support NanoVDB volumes. */
|
|
|
|
bool has_light_tree; /* Support light tree. */
|
2023-06-15 14:15:50 +00:00
|
|
|
bool has_mnee; /* Support MNEE. */
|
2023-03-16 10:56:55 +00:00
|
|
|
bool has_osl; /* Support Open Shading Language. */
|
|
|
|
bool has_guiding; /* Support path guiding. */
|
|
|
|
bool has_profiling; /* Supports runtime collection of profiling info. */
|
|
|
|
bool has_peer_memory; /* GPU has P2P access to memory of another GPU. */
|
|
|
|
bool has_gpu_queue; /* Device supports GPU queue. */
|
2023-04-24 17:05:30 +00:00
|
|
|
bool use_hardware_raytracing; /* Use hardware instructions to accelerate ray tracing. */
|
2023-01-04 16:01:24 +00:00
|
|
|
KernelOptimizationLevel kernel_optimization_level; /* Optimization level applied to path tracing
|
2023-03-08 23:39:49 +00:00
|
|
|
* kernels (Metal only). */
|
2023-01-04 16:01:24 +00:00
|
|
|
DenoiserTypeMask denoisers; /* Supported denoiser types. */
|
2017-10-21 16:58:59 +00:00
|
|
|
int cpu_threads;
|
2012-01-04 18:06:32 +00:00
|
|
|
vector<DeviceInfo> multi_devices;
|
2020-10-28 18:55:41 +00:00
|
|
|
string error_msg;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
DeviceInfo()
|
|
|
|
{
|
|
|
|
type = DEVICE_CPU;
|
|
|
|
id = "CPU";
|
|
|
|
num = 0;
|
2017-10-21 16:58:59 +00:00
|
|
|
cpu_threads = 0;
|
2012-01-04 18:06:32 +00:00
|
|
|
display_device = false;
|
2021-03-29 20:58:19 +00:00
|
|
|
has_nanovdb = false;
|
2022-12-02 18:04:00 +00:00
|
|
|
has_light_tree = true;
|
2023-06-15 14:15:50 +00:00
|
|
|
has_mnee = true;
|
2017-10-20 03:08:26 +00:00
|
|
|
has_osl = false;
|
2022-09-21 15:58:34 +00:00
|
|
|
has_guiding = false;
|
2018-11-29 01:06:30 +00:00
|
|
|
has_profiling = false;
|
2020-06-08 15:16:10 +00:00
|
|
|
has_peer_memory = false;
|
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
|
|
|
has_gpu_queue = false;
|
2023-03-16 10:56:55 +00:00
|
|
|
use_hardware_raytracing = false;
|
2020-05-31 21:49:10 +00:00
|
|
|
denoisers = DENOISER_NONE;
|
2012-01-04 18:06:32 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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
|
|
|
bool operator==(const DeviceInfo &info) const
|
Cycles: Refactor Device selection to allow individual GPU compute device selection
Previously, it was only possible to choose a single GPU or all of that type (CUDA or OpenCL).
Now, a toggle button is displayed for every device.
These settings are tied to the PCI Bus ID of the devices, so they're consistent across hardware addition and removal (but not when swapping/moving cards).
From the code perspective, the more important change is that now, the compute device properties are stored in the Addon preferences of the Cycles addon, instead of directly in the User Preferences.
This allows for a cleaner implementation, removing the Cycles C API functions that were called by the RNA code to specify the enum items.
Note that this change is neither backwards- nor forwards-compatible, but since it's only a User Preference no existing files are broken.
Reviewers: #cycles, brecht
Reviewed By: #cycles, brecht
Subscribers: brecht, juicyfruit, mib2berlin, Blendify
Differential Revision: https://developer.blender.org/D2338
2016-11-07 01:33:53 +00:00
|
|
|
{
|
|
|
|
/* Multiple Devices with the same ID would be very bad. */
|
|
|
|
assert(id != info.id ||
|
|
|
|
(type == info.type && num == info.num && description == info.description));
|
|
|
|
return id == info.id;
|
|
|
|
}
|
2015-05-09 14:05:49 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Device */
|
|
|
|
|
|
|
|
class Device {
|
2017-05-07 12:40:58 +00:00
|
|
|
friend class device_sub_ptr;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
protected:
|
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
|
|
|
Device(const DeviceInfo &info_, Stats &stats_, Profiler &profiler_)
|
|
|
|
: info(info_), stats(stats_), profiler(profiler_)
|
2018-11-29 22:54:30 +00:00
|
|
|
{
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-11-22 20:49:33 +00:00
|
|
|
string error_msg;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2021-09-23 15:38:56 +00:00
|
|
|
virtual device_ptr mem_alloc_sub_ptr(device_memory & /*mem*/, size_t /*offset*/, size_t /*size*/)
|
2017-05-07 12:40:58 +00:00
|
|
|
{
|
|
|
|
/* Only required for devices that implement denoising. */
|
|
|
|
assert(false);
|
|
|
|
return (device_ptr)0;
|
|
|
|
}
|
|
|
|
virtual void mem_free_sub_ptr(device_ptr /*ptr*/){};
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
public:
|
2020-06-05 14:39:57 +00:00
|
|
|
/* noexcept needed to silence TBB warning. */
|
|
|
|
virtual ~Device() noexcept(false);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* info */
|
2012-01-26 19:07:01 +00:00
|
|
|
DeviceInfo info;
|
2012-01-04 18:06:32 +00:00
|
|
|
virtual const string &error_message()
|
|
|
|
{
|
|
|
|
return error_msg;
|
|
|
|
}
|
2012-12-23 12:53:58 +00:00
|
|
|
bool have_error()
|
|
|
|
{
|
|
|
|
return !error_message().empty();
|
|
|
|
}
|
2017-03-11 12:03:17 +00:00
|
|
|
virtual void set_error(const string &error)
|
|
|
|
{
|
|
|
|
if (!have_error()) {
|
|
|
|
error_msg = error;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s\n", error.c_str());
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
2023-04-06 10:16:13 +00:00
|
|
|
virtual BVHLayoutMask get_bvh_layout_mask(uint kernel_features) const = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-11-05 08:04:57 +00:00
|
|
|
/* statistics */
|
|
|
|
Stats &stats;
|
2018-11-29 22:30:17 +00:00
|
|
|
Profiler &profiler;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* constant memory */
|
|
|
|
virtual void const_copy_to(const char *name, void *host, size_t size) = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-07-06 08:17:58 +00:00
|
|
|
/* load/compile kernels, must be called before adding tasks */
|
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
|
|
|
virtual bool load_kernels(uint /*kernel_features*/)
|
2015-05-09 14:05:49 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2022-11-09 13:25:32 +00:00
|
|
|
virtual bool load_osl_kernels()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:23:33 +00:00
|
|
|
/* Request cancellation of any long-running work. */
|
2023-03-29 14:50:54 +00:00
|
|
|
virtual void cancel() {}
|
2023-01-04 14:23:33 +00:00
|
|
|
|
2023-02-28 10:42:08 +00:00
|
|
|
/* Report status and return true if device is ready for rendering. */
|
2023-01-04 16:30:55 +00:00
|
|
|
virtual bool is_ready(string & /*status*/) const
|
2023-01-04 14:23:33 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* GPU device only functions.
|
|
|
|
* These may not be used on CPU or multi-devices. */
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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
|
|
|
/* Create new queue for executing kernels in. */
|
|
|
|
virtual unique_ptr<DeviceQueue> gpu_queue_create();
|
|
|
|
|
|
|
|
/* CPU device only functions.
|
|
|
|
* These may not be used on GPU or multi-devices. */
|
2019-09-12 12:50:06 +00:00
|
|
|
|
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
|
|
|
/* Get CPU kernel functions for native instruction set. */
|
2021-11-05 20:01:23 +00:00
|
|
|
static const CPUKernels &get_cpu_kernels();
|
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
|
|
|
/* Get kernel globals to pass to kernels. */
|
|
|
|
virtual void get_cpu_kernel_thread_globals(
|
|
|
|
vector<CPUKernelThreadGlobals> & /*kernel_thread_globals*/);
|
|
|
|
/* Get OpenShadingLanguage memory buffer. */
|
|
|
|
virtual void *get_cpu_osl_memory();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-09-12 12:50:06 +00:00
|
|
|
/* acceleration structure building */
|
2020-12-10 13:18:25 +00:00
|
|
|
virtual void build_bvh(BVH *bvh, Progress &progress, bool refit);
|
2019-09-12 12:50:06 +00:00
|
|
|
|
2021-05-18 22:55:22 +00:00
|
|
|
/* OptiX specific destructor. */
|
2021-05-21 09:19:33 +00:00
|
|
|
virtual void release_optix_bvh(BVH * /*bvh*/){};
|
2021-05-18 22:55:22 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* multi device */
|
2015-03-27 10:47:55 +00:00
|
|
|
virtual int device_number(Device * /*sub_device*/)
|
2019-04-17 04:17:24 +00:00
|
|
|
{
|
2015-03-27 10:47:55 +00:00
|
|
|
return 0;
|
2017-05-07 12:40:58 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2022-07-12 13:32:46 +00:00
|
|
|
/* Called after kernel texture setup, and prior to integrator state setup. */
|
2023-03-29 14:50:54 +00:00
|
|
|
virtual void optimize_for_scene(Scene * /*scene*/) {}
|
2022-07-12 13:32:46 +00:00
|
|
|
|
2020-06-08 15:16:10 +00:00
|
|
|
virtual bool is_resident(device_ptr /*key*/, Device *sub_device)
|
|
|
|
{
|
|
|
|
/* Memory is always resident if this is not a multi device, regardless of whether the pointer
|
|
|
|
* is valid or not (since it may not have been allocated yet). */
|
|
|
|
return sub_device == this;
|
|
|
|
}
|
|
|
|
virtual bool check_peer_access(Device * /*peer_device*/)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* Graphics resources interoperability.
|
|
|
|
*
|
|
|
|
* The interoperability comes here by the meaning that the device is capable of computing result
|
|
|
|
* directly into an OpenGL (or other graphics library) buffer. */
|
|
|
|
|
2021-09-22 04:48:01 +00:00
|
|
|
/* Check display is to be updated using graphics interoperability.
|
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
|
|
|
* The interoperability can not be used is it is not supported by the device. But the device
|
|
|
|
* might also force disable the interoperability if it detects that it will be slower than
|
|
|
|
* copying pixels from the render buffer. */
|
|
|
|
virtual bool should_use_graphics_interop()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:58:34 +00:00
|
|
|
/* Guiding */
|
|
|
|
|
|
|
|
/* Returns path guiding device handle. */
|
|
|
|
virtual void *get_guiding_device() const
|
|
|
|
{
|
|
|
|
LOG(ERROR) << "Request guiding field from a device which does not support it.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* Sub-devices */
|
|
|
|
|
|
|
|
/* Run given callback for every individual device which will be handling rendering.
|
|
|
|
* For the single device the callback is called for the device itself. For the multi-device the
|
|
|
|
* callback is only called for the sub-devices. */
|
|
|
|
virtual void foreach_device(const function<void(Device *)> &callback)
|
|
|
|
{
|
|
|
|
callback(this);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* static */
|
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
|
|
|
static Device *create(const DeviceInfo &info, Stats &stats, Profiler &profiler);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
static DeviceType type_from_string(const char *name);
|
|
|
|
static string string_from_type(DeviceType type);
|
2019-01-29 15:39:30 +00:00
|
|
|
static vector<DeviceType> available_types();
|
|
|
|
static vector<DeviceInfo> available_devices(uint device_type_mask = DEVICE_MASK_ALL);
|
2020-10-28 18:55:41 +00:00
|
|
|
static DeviceInfo dummy_device(const string &error_msg = "");
|
2019-01-29 15:39:30 +00:00
|
|
|
static string device_capabilities(uint device_type_mask = DEVICE_MASK_ALL);
|
2017-10-21 16:58:59 +00:00
|
|
|
static DeviceInfo get_multi_device(const vector<DeviceInfo> &subdevices,
|
|
|
|
int threads,
|
|
|
|
bool background);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-01-12 11:00:48 +00:00
|
|
|
/* Tag devices lists for update. */
|
|
|
|
static void tag_update();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-02-06 22:40:41 +00:00
|
|
|
static void free_memory();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
protected:
|
|
|
|
/* Memory allocation, only accessed through device_memory. */
|
|
|
|
friend class MultiDevice;
|
|
|
|
friend class DeviceServer;
|
|
|
|
friend class device_memory;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
virtual void mem_alloc(device_memory &mem) = 0;
|
|
|
|
virtual void mem_copy_to(device_memory &mem) = 0;
|
2021-09-23 15:38:56 +00:00
|
|
|
virtual void mem_copy_from(device_memory &mem, size_t y, size_t w, size_t h, size_t elem) = 0;
|
2017-10-20 23:09:59 +00:00
|
|
|
virtual void mem_zero(device_memory &mem) = 0;
|
|
|
|
virtual void mem_free(device_memory &mem) = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-01-12 11:00:48 +00:00
|
|
|
private:
|
|
|
|
/* Indicted whether device types and devices lists were initialized. */
|
|
|
|
static bool need_types_update, need_devices_update;
|
2017-10-11 07:48:19 +00:00
|
|
|
static thread_mutex device_mutex;
|
2019-01-29 15:39:30 +00:00
|
|
|
static vector<DeviceInfo> cuda_devices;
|
2019-09-12 12:50:06 +00:00
|
|
|
static vector<DeviceInfo> optix_devices;
|
2019-01-29 15:39:30 +00:00
|
|
|
static vector<DeviceInfo> cpu_devices;
|
2021-09-28 14:51:14 +00:00
|
|
|
static vector<DeviceInfo> hip_devices;
|
2021-12-07 15:11:35 +00:00
|
|
|
static vector<DeviceInfo> metal_devices;
|
2022-06-29 10:58:04 +00:00
|
|
|
static vector<DeviceInfo> oneapi_devices;
|
2019-01-29 15:39:30 +00:00
|
|
|
static uint devices_initialized_mask;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2023-03-27 01:08:14 +00:00
|
|
|
/* Device, which is GPU, with some common functionality for GPU back-ends. */
|
2023-02-01 16:22:53 +00:00
|
|
|
class GPUDevice : public Device {
|
|
|
|
protected:
|
|
|
|
GPUDevice(const DeviceInfo &info_, Stats &stats_, Profiler &profiler_)
|
|
|
|
: Device(info_, stats_, profiler_),
|
|
|
|
texture_info(this, "texture_info", MEM_GLOBAL),
|
|
|
|
need_texture_info(false),
|
|
|
|
can_map_host(false),
|
|
|
|
map_host_used(0),
|
|
|
|
map_host_limit(0),
|
|
|
|
device_texture_headroom(0),
|
|
|
|
device_working_headroom(0),
|
|
|
|
device_mem_map(),
|
|
|
|
device_mem_map_mutex(),
|
|
|
|
move_texture_to_host(false),
|
|
|
|
device_mem_in_use(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~GPUDevice() noexcept(false);
|
|
|
|
|
|
|
|
/* For GPUs that can use bindless textures in some way or another. */
|
|
|
|
device_vector<TextureInfo> texture_info;
|
|
|
|
bool need_texture_info;
|
|
|
|
/* Returns true if the texture info was copied to the device (meaning, some more
|
|
|
|
* re-initialization might be needed). */
|
|
|
|
virtual bool load_texture_info();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/* Memory allocation, only accessed through device_memory. */
|
|
|
|
friend class device_memory;
|
|
|
|
|
|
|
|
bool can_map_host;
|
|
|
|
size_t map_host_used;
|
|
|
|
size_t map_host_limit;
|
|
|
|
size_t device_texture_headroom;
|
|
|
|
size_t device_working_headroom;
|
|
|
|
typedef unsigned long long texMemObject;
|
|
|
|
typedef unsigned long long arrayMemObject;
|
|
|
|
struct Mem {
|
2023-03-29 14:50:54 +00:00
|
|
|
Mem() : texobject(0), array(0), use_mapped_host(false) {}
|
2023-02-01 16:22:53 +00:00
|
|
|
|
|
|
|
texMemObject texobject;
|
|
|
|
arrayMemObject array;
|
|
|
|
|
|
|
|
/* If true, a mapped host memory in shared_pointer is being used. */
|
|
|
|
bool use_mapped_host;
|
|
|
|
};
|
|
|
|
typedef map<device_memory *, Mem> MemMap;
|
|
|
|
MemMap device_mem_map;
|
|
|
|
thread_mutex device_mem_map_mutex;
|
|
|
|
bool move_texture_to_host;
|
|
|
|
/* Simple counter which will try to track amount of used device memory */
|
|
|
|
size_t device_mem_in_use;
|
|
|
|
|
|
|
|
virtual void init_host_memory(size_t preferred_texture_headroom = 0,
|
|
|
|
size_t preferred_working_headroom = 0);
|
|
|
|
virtual void move_textures_to_host(size_t size, bool for_texture);
|
|
|
|
|
2023-02-07 03:17:01 +00:00
|
|
|
/* Allocation, deallocation and copy functions, with corresponding
|
2023-02-01 16:22:53 +00:00
|
|
|
* support of device/host allocations. */
|
|
|
|
virtual GPUDevice::Mem *generic_alloc(device_memory &mem, size_t pitch_padding = 0);
|
|
|
|
virtual void generic_free(device_memory &mem);
|
|
|
|
virtual void generic_copy_to(device_memory &mem);
|
|
|
|
|
|
|
|
/* total - amount of device memory, free - amount of available device memory */
|
|
|
|
virtual void get_device_memory_info(size_t &total, size_t &free) = 0;
|
|
|
|
|
|
|
|
virtual bool alloc_device(void *&device_pointer, size_t size) = 0;
|
|
|
|
|
|
|
|
virtual void free_device(void *device_pointer) = 0;
|
|
|
|
|
|
|
|
virtual bool alloc_host(void *&shared_pointer, size_t size) = 0;
|
|
|
|
|
|
|
|
virtual void free_host(void *shared_pointer) = 0;
|
|
|
|
|
2023-02-07 03:17:01 +00:00
|
|
|
/* This function should return device pointer corresponding to shared pointer, which
|
2023-02-01 16:22:53 +00:00
|
|
|
* is host buffer, allocated in `alloc_host`. The function should `true`, if such
|
2023-02-07 03:17:01 +00:00
|
|
|
* address transformation is possible and `false` otherwise. */
|
2023-03-17 20:40:31 +00:00
|
|
|
virtual void transform_host_pointer(void *&device_pointer, void *&shared_pointer) = 0;
|
2023-02-01 16:22:53 +00:00
|
|
|
|
|
|
|
virtual void copy_host_to_device(void *device_pointer, void *host_pointer, size_t size) = 0;
|
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __DEVICE_H__ */
|