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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DEVICE_H__
|
|
|
|
#define __DEVICE_H__
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-01-19 09:59:58 +00:00
|
|
|
#include "bvh/bvh_params.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_memory.h"
|
|
|
|
#include "device/device_task.h"
|
|
|
|
|
|
|
|
#include "util/util_list.h"
|
|
|
|
#include "util/util_stats.h"
|
|
|
|
#include "util/util_string.h"
|
2017-10-06 19:47:41 +00:00
|
|
|
#include "util/util_texture.h"
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "util/util_thread.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 "util/util_types.h"
|
|
|
|
#include "util/util_vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2019-09-12 12:50:06 +00:00
|
|
|
class BVH;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Progress;
|
2012-09-04 13:29:07 +00:00
|
|
|
class RenderTile;
|
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_OPENCL,
|
|
|
|
DEVICE_CUDA,
|
|
|
|
DEVICE_NETWORK,
|
2019-09-12 12:50:06 +00:00
|
|
|
DEVICE_MULTI,
|
|
|
|
DEVICE_OPTIX,
|
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_OPENCL = (1 << DEVICE_OPENCL),
|
|
|
|
DEVICE_MASK_CUDA = (1 << DEVICE_CUDA),
|
2019-09-12 12:50:06 +00:00
|
|
|
DEVICE_MASK_OPTIX = (1 << DEVICE_OPTIX),
|
2019-01-29 15:39:30 +00:00
|
|
|
DEVICE_MASK_NETWORK = (1 << DEVICE_NETWORK),
|
|
|
|
DEVICE_MASK_ALL = ~0
|
|
|
|
};
|
|
|
|
|
2019-03-13 11:31:48 +00:00
|
|
|
enum DeviceKernelStatus {
|
|
|
|
DEVICE_KERNEL_FEATURE_KERNEL_AVAILABLE,
|
|
|
|
DEVICE_KERNEL_USING_FEATURE_KERNEL,
|
|
|
|
DEVICE_KERNEL_FEATURE_KERNEL_INVALID,
|
|
|
|
DEVICE_KERNEL_UNKNOWN,
|
|
|
|
};
|
|
|
|
|
2019-01-29 15:39:30 +00:00
|
|
|
#define DEVICE_MASK(type) (DeviceTypeMask)(1 << type)
|
|
|
|
|
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;
|
2020-04-07 17:43:51 +00:00
|
|
|
bool display_device; /* GPU is used as a display device. */
|
|
|
|
bool has_half_images; /* Support half-float textures. */
|
2021-03-29 20:58:19 +00:00
|
|
|
bool has_nanovdb; /* Support NanoVDB volumes. */
|
2020-04-07 17:43:51 +00:00
|
|
|
bool has_volume_decoupled; /* Decoupled volume shading. */
|
2021-01-20 12:03:09 +00:00
|
|
|
bool has_branched_path; /* Supports branched path tracing. */
|
2020-04-07 17:43:51 +00:00
|
|
|
bool has_adaptive_stop_per_sample; /* Per-sample adaptive sampling stopping. */
|
|
|
|
bool has_osl; /* Support Open Shading Language. */
|
|
|
|
bool use_split_kernel; /* Use split or mega kernel. */
|
|
|
|
bool has_profiling; /* Supports runtime collection of profiling info. */
|
2020-06-08 15:16:10 +00:00
|
|
|
bool has_peer_memory; /* GPU has P2P access to memory of another GPU. */
|
2020-05-31 21:49:10 +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-02-11 15:30:01 +00:00
|
|
|
vector<DeviceInfo> denoising_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;
|
2017-11-03 19:21:19 +00:00
|
|
|
has_half_images = false;
|
2021-03-29 20:58:19 +00:00
|
|
|
has_nanovdb = false;
|
2017-10-08 02:32:25 +00:00
|
|
|
has_volume_decoupled = false;
|
2021-01-20 12:03:09 +00:00
|
|
|
has_branched_path = true;
|
2020-04-07 17:43:51 +00:00
|
|
|
has_adaptive_stop_per_sample = false;
|
2017-10-20 03:08:26 +00:00
|
|
|
has_osl = false;
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
use_split_kernel = false;
|
2018-11-29 01:06:30 +00:00
|
|
|
has_profiling = false;
|
2020-06-08 15:16:10 +00:00
|
|
|
has_peer_memory = 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: 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
|
|
|
bool operator==(const DeviceInfo &info)
|
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
}
|
2020-05-31 21:49:10 +00:00
|
|
|
|
|
|
|
/* Add additional devices needed for the specified denoiser. */
|
|
|
|
void add_denoising_devices(DenoiserType denoiser_type);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2015-05-09 14:05:49 +00:00
|
|
|
class DeviceRequestedFeatures {
|
|
|
|
public:
|
|
|
|
/* Use experimental feature set. */
|
|
|
|
bool experimental;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-05-09 14:28:00 +00:00
|
|
|
/* Selective nodes compilation. */
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-05-09 14:28:00 +00:00
|
|
|
/* Identifier of a node group up to which all the nodes needs to be
|
|
|
|
* compiled in. Nodes from higher group indices will be ignores.
|
|
|
|
*/
|
|
|
|
int max_nodes_group;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-05-09 14:28:00 +00:00
|
|
|
/* Features bitfield indicating which features from the requested group
|
|
|
|
* will be compiled in. Nodes which corresponds to features which are not
|
|
|
|
* in this bitfield will be ignored even if they're in the requested group.
|
|
|
|
*/
|
|
|
|
int nodes_features;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-06-05 17:50:22 +00:00
|
|
|
/* BVH/sampling kernel features. */
|
|
|
|
bool use_hair;
|
2020-02-18 19:54:41 +00:00
|
|
|
bool use_hair_thick;
|
2015-06-05 17:50:22 +00:00
|
|
|
bool use_object_motion;
|
|
|
|
bool use_camera_motion;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-07-18 13:34:32 +00:00
|
|
|
/* Denotes whether baking functionality is needed. */
|
|
|
|
bool use_baking;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-11-21 17:31:58 +00:00
|
|
|
/* Use subsurface scattering materials. */
|
|
|
|
bool use_subsurface;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-05-06 21:11:41 +00:00
|
|
|
/* Use volume materials. */
|
|
|
|
bool use_volume;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-11-22 08:54:51 +00:00
|
|
|
/* Use branched integrator. */
|
|
|
|
bool use_integrator_branched;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-08-15 13:08:38 +00:00
|
|
|
/* Use OpenSubdiv patch evaluation */
|
|
|
|
bool use_patch_evaluation;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-12-09 15:28:04 +00:00
|
|
|
/* Use Transparent shadows */
|
|
|
|
bool use_transparent;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-03-21 12:55:27 +00:00
|
|
|
/* Use various shadow tricks, such as shadow catcher. */
|
|
|
|
bool use_shadow_tricks;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-04-21 10:56:54 +00:00
|
|
|
/* Per-uber shader usage flags. */
|
|
|
|
bool use_principled;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-06-09 07:11:54 +00:00
|
|
|
/* Denoising features. */
|
|
|
|
bool use_denoising;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-30 19:25:08 +00:00
|
|
|
/* Use raytracing in shaders. */
|
|
|
|
bool use_shader_raytrace;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-02-26 13:05:54 +00:00
|
|
|
/* Use true displacement */
|
|
|
|
bool use_true_displacement;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-02-26 13:05:54 +00:00
|
|
|
/* Use background lights */
|
|
|
|
bool use_background_light;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-05-09 14:05:49 +00:00
|
|
|
DeviceRequestedFeatures()
|
|
|
|
{
|
2015-05-09 14:28:00 +00:00
|
|
|
/* TODO(sergey): Find more meaningful defaults. */
|
|
|
|
max_nodes_group = 0;
|
|
|
|
nodes_features = 0;
|
2015-06-05 17:50:22 +00:00
|
|
|
use_hair = false;
|
2020-02-18 19:54:41 +00:00
|
|
|
use_hair_thick = false;
|
2015-06-05 17:50:22 +00:00
|
|
|
use_object_motion = false;
|
|
|
|
use_camera_motion = false;
|
2015-07-18 13:34:32 +00:00
|
|
|
use_baking = false;
|
2015-11-21 17:31:58 +00:00
|
|
|
use_subsurface = false;
|
2016-05-06 21:11:41 +00:00
|
|
|
use_volume = false;
|
2015-11-22 08:54:51 +00:00
|
|
|
use_integrator_branched = false;
|
2016-08-15 13:08:38 +00:00
|
|
|
use_patch_evaluation = false;
|
2016-12-09 15:28:04 +00:00
|
|
|
use_transparent = false;
|
2017-03-21 12:55:27 +00:00
|
|
|
use_shadow_tricks = false;
|
2017-04-21 10:56:54 +00:00
|
|
|
use_principled = false;
|
2017-06-09 07:11:54 +00:00
|
|
|
use_denoising = false;
|
2017-10-30 19:25:08 +00:00
|
|
|
use_shader_raytrace = false;
|
2019-02-26 13:05:54 +00:00
|
|
|
use_true_displacement = false;
|
|
|
|
use_background_light = false;
|
2015-05-09 14:05:49 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-05-09 14:05:49 +00:00
|
|
|
bool modified(const DeviceRequestedFeatures &requested_features)
|
|
|
|
{
|
2020-08-18 08:46:12 +00:00
|
|
|
return !(max_nodes_group == requested_features.max_nodes_group &&
|
2015-07-18 13:34:32 +00:00
|
|
|
nodes_features == requested_features.nodes_features &&
|
|
|
|
use_hair == requested_features.use_hair &&
|
2020-02-18 19:54:41 +00:00
|
|
|
use_hair_thick == requested_features.use_hair_thick &&
|
2015-07-18 13:34:32 +00:00
|
|
|
use_object_motion == requested_features.use_object_motion &&
|
|
|
|
use_camera_motion == requested_features.use_camera_motion &&
|
2015-11-21 17:31:58 +00:00
|
|
|
use_baking == requested_features.use_baking &&
|
2015-11-22 08:54:51 +00:00
|
|
|
use_subsurface == requested_features.use_subsurface &&
|
2016-05-06 21:11:41 +00:00
|
|
|
use_volume == requested_features.use_volume &&
|
2016-08-15 13:08:38 +00:00
|
|
|
use_integrator_branched == requested_features.use_integrator_branched &&
|
2016-12-09 15:28:04 +00:00
|
|
|
use_patch_evaluation == requested_features.use_patch_evaluation &&
|
2017-03-21 12:55:27 +00:00
|
|
|
use_transparent == requested_features.use_transparent &&
|
2017-04-21 10:56:54 +00:00
|
|
|
use_shadow_tricks == requested_features.use_shadow_tricks &&
|
2017-06-09 07:11:54 +00:00
|
|
|
use_principled == requested_features.use_principled &&
|
2017-10-30 19:25:08 +00:00
|
|
|
use_denoising == requested_features.use_denoising &&
|
2019-02-26 13:05:54 +00:00
|
|
|
use_shader_raytrace == requested_features.use_shader_raytrace &&
|
|
|
|
use_true_displacement == requested_features.use_true_displacement &&
|
|
|
|
use_background_light == requested_features.use_background_light);
|
2015-05-09 14:05:49 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-11-21 16:42:31 +00:00
|
|
|
/* Convert the requested features structure to a build options,
|
|
|
|
* which could then be passed to compilers.
|
|
|
|
*/
|
2018-11-09 11:01:38 +00:00
|
|
|
string get_build_options() const
|
2015-11-21 16:42:31 +00:00
|
|
|
{
|
|
|
|
string build_options = "";
|
|
|
|
if (experimental) {
|
|
|
|
build_options += "-D__KERNEL_EXPERIMENTAL__ ";
|
|
|
|
}
|
|
|
|
build_options += "-D__NODES_MAX_GROUP__=" + string_printf("%d", max_nodes_group);
|
|
|
|
build_options += " -D__NODES_FEATURES__=" + string_printf("%d", nodes_features);
|
|
|
|
if (!use_hair) {
|
|
|
|
build_options += " -D__NO_HAIR__";
|
|
|
|
}
|
|
|
|
if (!use_object_motion) {
|
|
|
|
build_options += " -D__NO_OBJECT_MOTION__";
|
|
|
|
}
|
|
|
|
if (!use_camera_motion) {
|
|
|
|
build_options += " -D__NO_CAMERA_MOTION__";
|
|
|
|
}
|
|
|
|
if (!use_baking) {
|
|
|
|
build_options += " -D__NO_BAKING__";
|
|
|
|
}
|
2016-05-06 21:11:41 +00:00
|
|
|
if (!use_volume) {
|
|
|
|
build_options += " -D__NO_VOLUME__";
|
|
|
|
}
|
2015-11-21 17:31:58 +00:00
|
|
|
if (!use_subsurface) {
|
|
|
|
build_options += " -D__NO_SUBSURFACE__";
|
|
|
|
}
|
2015-11-22 08:54:51 +00:00
|
|
|
if (!use_integrator_branched) {
|
|
|
|
build_options += " -D__NO_BRANCHED_PATH__";
|
|
|
|
}
|
2016-08-15 13:08:38 +00:00
|
|
|
if (!use_patch_evaluation) {
|
|
|
|
build_options += " -D__NO_PATCH_EVAL__";
|
|
|
|
}
|
2017-03-08 14:42:26 +00:00
|
|
|
if (!use_transparent && !use_volume) {
|
2016-12-09 15:28:04 +00:00
|
|
|
build_options += " -D__NO_TRANSPARENT__";
|
|
|
|
}
|
2017-03-21 12:55:27 +00:00
|
|
|
if (!use_shadow_tricks) {
|
|
|
|
build_options += " -D__NO_SHADOW_TRICKS__";
|
|
|
|
}
|
2017-04-21 10:56:54 +00:00
|
|
|
if (!use_principled) {
|
|
|
|
build_options += " -D__NO_PRINCIPLED__";
|
|
|
|
}
|
2017-06-09 07:11:54 +00:00
|
|
|
if (!use_denoising) {
|
|
|
|
build_options += " -D__NO_DENOISING__";
|
|
|
|
}
|
2017-10-30 19:25:08 +00:00
|
|
|
if (!use_shader_raytrace) {
|
|
|
|
build_options += " -D__NO_SHADER_RAYTRACE__";
|
|
|
|
}
|
2015-11-21 16:42:31 +00:00
|
|
|
return build_options;
|
|
|
|
}
|
2015-05-09 14:05:49 +00:00
|
|
|
};
|
|
|
|
|
2015-07-18 14:00:07 +00:00
|
|
|
std::ostream &operator<<(std::ostream &os, const DeviceRequestedFeatures &requested_features);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Device */
|
|
|
|
|
2014-03-26 08:57:30 +00:00
|
|
|
struct DeviceDrawParams {
|
2018-11-09 11:01:38 +00:00
|
|
|
function<void()> bind_display_space_shader_cb;
|
|
|
|
function<void()> unbind_display_space_shader_cb;
|
2014-03-26 08:57:30 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
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:
|
2017-04-28 17:25:57 +00:00
|
|
|
enum {
|
|
|
|
FALLBACK_SHADER_STATUS_NONE = 0,
|
|
|
|
FALLBACK_SHADER_STATUS_ERROR,
|
|
|
|
FALLBACK_SHADER_STATUS_SUCCESS,
|
|
|
|
};
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-11-29 22:54:30 +00:00
|
|
|
Device(DeviceInfo &info_, Stats &stats_, Profiler &profiler_, bool background)
|
|
|
|
: background(background),
|
2017-04-28 17:25:57 +00:00
|
|
|
vertex_buffer(0),
|
|
|
|
fallback_status(FALLBACK_SHADER_STATUS_NONE),
|
|
|
|
fallback_shader_program(0),
|
2018-11-29 22:54:30 +00:00
|
|
|
info(info_),
|
|
|
|
stats(stats_),
|
|
|
|
profiler(profiler_)
|
|
|
|
{
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool background;
|
2011-11-22 20:49:33 +00:00
|
|
|
string error_msg;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-05-11 14:28:41 +00:00
|
|
|
/* used for real time display */
|
|
|
|
unsigned int vertex_buffer;
|
2017-04-28 17:25:57 +00:00
|
|
|
int fallback_status, fallback_shader_program;
|
|
|
|
int image_texture_location, fullscreen_location;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
bool bind_fallback_display_space_shader(const float width, const float height);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 21:31:13 +00:00
|
|
|
virtual device_ptr mem_alloc_sub_ptr(device_memory & /*mem*/, int /*offset*/, int /*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);
|
|
|
|
}
|
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
|
|
|
virtual bool show_samples() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-31 10:46:52 +00:00
|
|
|
virtual BVHLayoutMask get_bvh_layout_mask() 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
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
/* memory alignment */
|
2018-02-05 21:13:08 +00:00
|
|
|
virtual int mem_sub_ptr_alignment()
|
|
|
|
{
|
|
|
|
return MIN_ALIGNMENT_CPU_DATA_TYPES;
|
|
|
|
}
|
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
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* open shading language, only for CPU device */
|
|
|
|
virtual void *osl_memory()
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
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 */
|
2015-05-09 14:05:49 +00:00
|
|
|
virtual bool load_kernels(const DeviceRequestedFeatures & /*requested_features*/)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-03-13 11:31:48 +00:00
|
|
|
/* Wait for device to become available to upload data and receive tasks
|
|
|
|
* This method is used by the OpenCL device to load the
|
|
|
|
* optimized kernels or when not (yet) available load the
|
|
|
|
* generic kernels (only during foreground rendering) */
|
|
|
|
virtual bool wait_for_availability(const DeviceRequestedFeatures & /*requested_features*/)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/* Check if there are 'better' kernels available to be used
|
|
|
|
* We can switch over to these kernels
|
|
|
|
* This method is used to determine if we can switch the preview kernels
|
|
|
|
* to regular kernels */
|
|
|
|
virtual DeviceKernelStatus get_active_kernel_switch_state()
|
|
|
|
{
|
|
|
|
return DEVICE_KERNEL_USING_FEATURE_KERNEL;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* tasks */
|
2019-09-12 12:50:06 +00:00
|
|
|
virtual int get_split_task_count(DeviceTask &)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
virtual void task_add(DeviceTask &task) = 0;
|
|
|
|
virtual void task_wait() = 0;
|
|
|
|
virtual void task_cancel() = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* opengl drawing */
|
2017-04-28 17:25:57 +00:00
|
|
|
virtual void draw_pixels(device_memory &mem,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int dx,
|
|
|
|
int dy,
|
|
|
|
int dw,
|
|
|
|
int dh,
|
|
|
|
bool transparent,
|
|
|
|
const DeviceDrawParams &draw_params);
|
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
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#ifdef WITH_NETWORK
|
|
|
|
/* networking */
|
|
|
|
void server_run();
|
|
|
|
#endif
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* multi device */
|
2015-03-27 10:47:55 +00:00
|
|
|
virtual void map_tile(Device * /*sub_device*/, RenderTile & /*tile*/)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2020-07-09 18:01:22 +00:00
|
|
|
virtual void map_neighbor_tiles(Device * /*sub_device*/, RenderTileNeighbors & /*neighbors*/)
|
2017-05-07 12:40:58 +00:00
|
|
|
{
|
|
|
|
}
|
2020-07-09 18:01:22 +00:00
|
|
|
virtual void unmap_neighbor_tiles(Device * /*sub_device*/, RenderTileNeighbors & /*neighbors*/)
|
2019-04-17 04:17:24 +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;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* static */
|
2018-11-29 22:30:17 +00:00
|
|
|
static Device *create(DeviceInfo &info,
|
|
|
|
Stats &stats,
|
|
|
|
Profiler &profiler,
|
|
|
|
bool background = true);
|
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;
|
|
|
|
virtual void mem_copy_from(device_memory &mem, int y, int w, int h, int elem) = 0;
|
|
|
|
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> opencl_devices;
|
|
|
|
static vector<DeviceInfo> cpu_devices;
|
|
|
|
static vector<DeviceInfo> network_devices;
|
|
|
|
static uint devices_initialized_mask;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __DEVICE_H__ */
|