Blender  V2.93
blender_device.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "blender/blender_device.h"
19 #include "blender/blender_util.h"
20 
21 #include "util/util_foreach.h"
22 
24 
30 
32 };
33 
35 {
36  BL::RenderSettings b_r = b_scene.render();
37 
38  if (b_r.threads_mode() == BL::RenderSettings::threads_mode_FIXED)
39  return b_r.threads();
40  else
41  return 0;
42 }
43 
44 DeviceInfo blender_device_info(BL::Preferences &b_preferences, BL::Scene &b_scene, bool background)
45 {
46  PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
47 
48  /* Find cycles preferences. */
49  PointerRNA cpreferences;
50  for (BL::Addon &b_addon : b_preferences.addons) {
51  if (b_addon.module() == "cycles") {
52  cpreferences = b_addon.preferences().ptr;
53  break;
54  }
55  }
56 
57  /* Default to CPU device. */
59 
62 
63  if (devices.empty()) {
64  device = Device::dummy_device("Found no Cycles device of the specified type");
65  }
66  else {
67  int threads = blender_device_threads(b_scene);
68  device = Device::get_multi_device(devices, threads, background);
69  }
70  }
71  else if (get_enum(cscene, "device") == 2) {
72  /* Find network device. */
74  if (!devices.empty()) {
75  device = devices.front();
76  }
77  }
78  else if (get_enum(cscene, "device") == 1) {
79  /* Test if we are using GPU devices. */
80  ComputeDevice compute_device = (ComputeDevice)get_enum(
81  cpreferences, "compute_device_type", COMPUTE_DEVICE_NUM, COMPUTE_DEVICE_CPU);
82 
83  if (compute_device != COMPUTE_DEVICE_CPU) {
84  /* Query GPU devices with matching types. */
86  if (compute_device == COMPUTE_DEVICE_CUDA) {
88  }
89  else if (compute_device == COMPUTE_DEVICE_OPTIX) {
91  }
92  else if (compute_device == COMPUTE_DEVICE_OPENCL) {
94  }
96 
97  /* Match device preferences and available devices. */
98  vector<DeviceInfo> used_devices;
99  RNA_BEGIN (&cpreferences, device, "devices") {
100  if (get_boolean(device, "use")) {
101  string id = get_string(device, "id");
102  foreach (DeviceInfo &info, devices) {
103  if (info.id == id) {
104  used_devices.push_back(info);
105  break;
106  }
107  }
108  }
109  }
110  RNA_END;
111 
112  if (!used_devices.empty()) {
113  int threads = blender_device_threads(b_scene);
114  device = Device::get_multi_device(used_devices, threads, background);
115  }
116  /* Else keep using the CPU device that was set before. */
117  }
118  }
119 
120  if (!get_boolean(cpreferences, "peer_memory")) {
121  device.has_peer_memory = false;
122  }
123 
124  return device;
125 }
126 
unsigned int uint
Definition: BLI_sys_types.h:83
struct Scene Scene
#define RNA_BEGIN(sptr, itemptr, propname)
Definition: RNA_access.h:1248
#define RNA_END
Definition: RNA_access.h:1255
ComputeDevice
@ COMPUTE_DEVICE_CUDA
@ COMPUTE_DEVICE_OPTIX
@ COMPUTE_DEVICE_NUM
@ COMPUTE_DEVICE_OPENCL
@ COMPUTE_DEVICE_CPU
int blender_device_threads(BL::Scene &b_scene)
DeviceInfo blender_device_info(BL::Preferences &b_preferences, BL::Scene &b_scene, bool background)
static bool get_boolean(PointerRNA &ptr, const char *name)
Definition: blender_util.h:349
static int get_enum(PointerRNA &ptr, const char *name, int num_values=-1, int default_value=-1)
Definition: blender_util.h:386
static string get_string(PointerRNA &ptr, const char *name)
Definition: blender_util.h:420
static DeviceTypeMask device_override
string id
Definition: device.h:76
bool has_peer_memory
Definition: device.h:87
static DeviceInfo dummy_device(const string &error_msg="")
Definition: device.cpp:565
static vector< DeviceInfo > available_devices(uint device_type_mask=DEVICE_MASK_ALL)
Definition: device.cpp:488
static DeviceInfo get_multi_device(const vector< DeviceInfo > &subdevices, int threads, bool background)
Definition: device.cpp:604
@ DEVICE_MASK_OPTIX
Definition: device.h:58
@ DEVICE_MASK_NETWORK
Definition: device.h:59
@ DEVICE_MASK_CPU
Definition: device.h:55
@ DEVICE_MASK_OPENCL
Definition: device.h:56
@ DEVICE_MASK_ALL
Definition: device.h:60
@ DEVICE_MASK_CUDA
Definition: device.h:57
#define CCL_NAMESPACE_END
Vector< CPUDevice > devices
list of all CPUDevices. for every hardware thread an instance of CPUDevice is created
ListBase threads
list of all thread for every CPUDevice in cpudevices a thread exists.
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6562
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)