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 <stdlib.h>
|
|
|
|
#include <string.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"
|
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 "util/util_debug.h"
|
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_half.h"
|
|
|
|
#include "util/util_math.h"
|
|
|
|
#include "util/util_opengl.h"
|
|
|
|
#include "util/util_time.h"
|
|
|
|
#include "util/util_types.h"
|
|
|
|
#include "util/util_vector.h"
|
|
|
|
#include "util/util_string.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2016-01-12 11:00:48 +00:00
|
|
|
bool Device::need_types_update = true;
|
|
|
|
bool Device::need_devices_update = true;
|
2016-02-06 22:40:41 +00:00
|
|
|
vector<DeviceType> Device::types;
|
|
|
|
vector<DeviceInfo> Device::devices;
|
2016-01-12 11:00:48 +00:00
|
|
|
|
2015-07-18 14:00:07 +00:00
|
|
|
/* Device Requested Features */
|
|
|
|
|
|
|
|
std::ostream& operator <<(std::ostream &os,
|
|
|
|
const DeviceRequestedFeatures& requested_features)
|
|
|
|
{
|
|
|
|
os << "Experimental features: "
|
|
|
|
<< (requested_features.experimental ? "On" : "Off") << std::endl;
|
|
|
|
os << "Max closure count: " << requested_features.max_closure << std::endl;
|
|
|
|
os << "Max nodes group: " << requested_features.max_nodes_group << std::endl;
|
|
|
|
/* TODO(sergey): Decode bitflag into list of names. */
|
|
|
|
os << "Nodes features: " << requested_features.nodes_features << std::endl;
|
2017-03-27 20:52:33 +00:00
|
|
|
os << "Use Hair: "
|
2016-10-24 10:31:11 +00:00
|
|
|
<< string_from_bool(requested_features.use_hair) << std::endl;
|
2017-03-27 20:52:33 +00:00
|
|
|
os << "Use Object Motion: "
|
2016-10-24 10:31:11 +00:00
|
|
|
<< string_from_bool(requested_features.use_object_motion) << std::endl;
|
2017-03-27 20:52:33 +00:00
|
|
|
os << "Use Camera Motion: "
|
2016-10-24 10:31:11 +00:00
|
|
|
<< string_from_bool(requested_features.use_camera_motion) << std::endl;
|
2015-07-18 14:00:07 +00:00
|
|
|
os << "Use Baking: "
|
2016-10-24 10:31:11 +00:00
|
|
|
<< string_from_bool(requested_features.use_baking) << std::endl;
|
2016-08-15 13:08:38 +00:00
|
|
|
os << "Use Subsurface: "
|
|
|
|
<< string_from_bool(requested_features.use_subsurface) << std::endl;
|
2016-05-16 22:36:22 +00:00
|
|
|
os << "Use Volume: "
|
2016-10-24 10:31:11 +00:00
|
|
|
<< string_from_bool(requested_features.use_volume) << std::endl;
|
2016-08-15 13:08:38 +00:00
|
|
|
os << "Use Branched Integrator: "
|
|
|
|
<< string_from_bool(requested_features.use_integrator_branched) << std::endl;
|
|
|
|
os << "Use Patch Evaluation: "
|
|
|
|
<< string_from_bool(requested_features.use_patch_evaluation) << std::endl;
|
2016-12-09 15:28:04 +00:00
|
|
|
os << "Use Transparent Shadows: "
|
|
|
|
<< string_from_bool(requested_features.use_transparent) << std::endl;
|
2017-04-21 10:56:54 +00:00
|
|
|
os << "Use Principled BSDF: "
|
|
|
|
<< string_from_bool(requested_features.use_principled) << std::endl;
|
2015-07-18 14:00:07 +00:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Device */
|
|
|
|
|
2015-05-11 14:28:41 +00:00
|
|
|
Device::~Device()
|
|
|
|
{
|
|
|
|
if(!background && vertex_buffer != 0) {
|
|
|
|
glDeleteBuffers(1, &vertex_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Device::pixels_alloc(device_memory& mem)
|
|
|
|
{
|
2016-12-14 01:45:09 +00:00
|
|
|
mem_alloc("pixels", mem, MEM_READ_WRITE);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Device::pixels_copy_from(device_memory& mem, int y, int w, int h)
|
|
|
|
{
|
2013-08-30 23:49:38 +00:00
|
|
|
if(mem.data_type == TYPE_HALF)
|
|
|
|
mem_copy_from(mem, y, w, h, sizeof(half4));
|
|
|
|
else
|
|
|
|
mem_copy_from(mem, y, w, h, sizeof(uchar4));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Device::pixels_free(device_memory& mem)
|
|
|
|
{
|
|
|
|
mem_free(mem);
|
|
|
|
}
|
|
|
|
|
2015-05-11 14:40:38 +00:00
|
|
|
void Device::draw_pixels(device_memory& rgba, int y, int w, int h, int dx, int dy, int width, int height, bool transparent,
|
2014-03-26 08:57:30 +00:00
|
|
|
const DeviceDrawParams &draw_params)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
pixels_copy_from(rgba, y, w, h);
|
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
if(transparent) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
|
|
|
|
2013-08-30 23:49:38 +00:00
|
|
|
glColor3f(1.0f, 1.0f, 1.0f);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-10-12 13:55:52 +00:00
|
|
|
if(rgba.data_type == TYPE_HALF) {
|
2014-08-02 06:53:52 +00:00
|
|
|
/* for multi devices, this assumes the inefficient method that we allocate
|
2013-10-18 20:11:07 +00:00
|
|
|
* all pixels on the device even though we only render to a subset */
|
|
|
|
GLhalf *data_pointer = (GLhalf*)rgba.data_pointer;
|
2015-05-11 14:28:41 +00:00
|
|
|
float vbuffer[16], *basep;
|
|
|
|
float *vp = NULL;
|
|
|
|
|
2013-10-18 20:11:07 +00:00
|
|
|
data_pointer += 4*y*w;
|
|
|
|
|
2013-10-12 13:55:52 +00:00
|
|
|
/* draw half float texture, GLSL shader for display transform assumed to be bound */
|
|
|
|
GLuint texid;
|
|
|
|
glGenTextures(1, &texid);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texid);
|
2013-10-18 20:11:07 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGBA, GL_HALF_FLOAT, data_pointer);
|
2013-10-12 13:55:52 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
2014-03-26 08:57:30 +00:00
|
|
|
if(draw_params.bind_display_space_shader_cb) {
|
|
|
|
draw_params.bind_display_space_shader_cb();
|
|
|
|
}
|
|
|
|
|
2015-05-11 14:28:41 +00:00
|
|
|
if(GLEW_VERSION_1_5) {
|
2015-06-01 13:11:57 +00:00
|
|
|
if(!vertex_buffer)
|
2015-05-11 14:28:41 +00:00
|
|
|
glGenBuffers(1, &vertex_buffer);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
|
|
|
|
/* invalidate old contents - avoids stalling if buffer is still waiting in queue to be rendered */
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), NULL, GL_STREAM_DRAW);
|
|
|
|
|
|
|
|
vp = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
|
|
|
|
|
|
|
basep = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
basep = vbuffer;
|
|
|
|
vp = vbuffer;
|
|
|
|
}
|
|
|
|
|
2015-06-01 13:11:57 +00:00
|
|
|
if(vp) {
|
2015-05-11 14:28:41 +00:00
|
|
|
/* texture coordinate - vertex pair */
|
|
|
|
vp[0] = 0.0f;
|
|
|
|
vp[1] = 0.0f;
|
2015-05-11 14:40:38 +00:00
|
|
|
vp[2] = dx;
|
2015-05-11 14:28:41 +00:00
|
|
|
vp[3] = dy;
|
|
|
|
|
|
|
|
vp[4] = 1.0f;
|
|
|
|
vp[5] = 0.0f;
|
2015-05-11 14:40:38 +00:00
|
|
|
vp[6] = (float)width + dx;
|
2015-05-11 14:28:41 +00:00
|
|
|
vp[7] = dy;
|
|
|
|
|
|
|
|
vp[8] = 1.0f;
|
|
|
|
vp[9] = 1.0f;
|
2015-05-11 14:40:38 +00:00
|
|
|
vp[10] = (float)width + dx;
|
2015-05-11 14:28:41 +00:00
|
|
|
vp[11] = (float)height + dy;
|
|
|
|
|
|
|
|
vp[12] = 0.0f;
|
|
|
|
vp[13] = 1.0f;
|
2015-05-11 14:40:38 +00:00
|
|
|
vp[14] = dx;
|
2015-05-11 14:28:41 +00:00
|
|
|
vp[15] = (float)height + dy;
|
|
|
|
|
2015-06-01 13:11:57 +00:00
|
|
|
if(vertex_buffer)
|
2015-05-11 14:28:41 +00:00
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
|
|
}
|
|
|
|
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), basep);
|
|
|
|
glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), ((char *)basep) + 2 * sizeof(float));
|
|
|
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
|
|
|
if(vertex_buffer) {
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2014-03-26 08:57:30 +00:00
|
|
|
if(draw_params.unbind_display_space_shader_cb) {
|
|
|
|
draw_params.unbind_display_space_shader_cb();
|
|
|
|
}
|
|
|
|
|
2013-10-12 13:55:52 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glDeleteTextures(1, &texid);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* fallback for old graphics cards that don't support GLSL, half float,
|
|
|
|
* and non-power-of-two textures */
|
|
|
|
glPixelZoom((float)width/(float)w, (float)height/(float)h);
|
2015-05-18 01:37:19 +00:00
|
|
|
glRasterPos2f(dx, dy);
|
2013-10-12 13:55:52 +00:00
|
|
|
|
|
|
|
uint8_t *pixels = (uint8_t*)rgba.data_pointer;
|
|
|
|
|
|
|
|
pixels += 4*y*w;
|
|
|
|
|
|
|
|
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
|
|
|
|
|
|
|
glRasterPos2f(0.0f, 0.0f);
|
|
|
|
glPixelZoom(1.0f, 1.0f);
|
|
|
|
}
|
2011-08-28 13:55:59 +00:00
|
|
|
|
|
|
|
if(transparent)
|
|
|
|
glDisable(GL_BLEND);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 21:00:49 +00:00
|
|
|
Device *Device::create(DeviceInfo& info, Stats &stats, bool background)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Device *device;
|
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
switch(info.type) {
|
2011-04-27 11:58:34 +00:00
|
|
|
case DEVICE_CPU:
|
2013-12-07 01:29:53 +00:00
|
|
|
device = device_cpu_create(info, stats, background);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#ifdef WITH_CUDA
|
|
|
|
case DEVICE_CUDA:
|
2014-08-05 07:57:50 +00:00
|
|
|
if(device_cuda_init())
|
2012-11-05 08:04:57 +00:00
|
|
|
device = device_cuda_create(info, stats, background);
|
2011-04-27 11:58:34 +00:00
|
|
|
else
|
|
|
|
device = NULL;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_MULTI
|
|
|
|
case DEVICE_MULTI:
|
2012-11-05 08:04:57 +00:00
|
|
|
device = device_multi_create(info, stats, background);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_NETWORK
|
|
|
|
case DEVICE_NETWORK:
|
2012-11-05 08:04:57 +00:00
|
|
|
device = device_network_create(info, stats, "127.0.0.1");
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_OPENCL
|
|
|
|
case DEVICE_OPENCL:
|
2014-08-05 07:57:50 +00:00
|
|
|
if(device_opencl_init())
|
2012-11-05 08:04:57 +00:00
|
|
|
device = device_opencl_create(info, stats, background);
|
2011-09-01 19:00:23 +00:00
|
|
|
else
|
|
|
|
device = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceType Device::type_from_string(const char *name)
|
|
|
|
{
|
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
|
|
|
if(strcmp(name, "CPU") == 0)
|
2011-04-27 11:58:34 +00:00
|
|
|
return DEVICE_CPU;
|
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
|
|
|
else if(strcmp(name, "CUDA") == 0)
|
2011-04-27 11:58:34 +00:00
|
|
|
return DEVICE_CUDA;
|
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
|
|
|
else if(strcmp(name, "OPENCL") == 0)
|
2011-04-27 11:58:34 +00:00
|
|
|
return DEVICE_OPENCL;
|
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
|
|
|
else if(strcmp(name, "NETWORK") == 0)
|
2011-04-27 11:58:34 +00:00
|
|
|
return DEVICE_NETWORK;
|
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
|
|
|
else if(strcmp(name, "MULTI") == 0)
|
2011-04-27 11:58:34 +00:00
|
|
|
return DEVICE_MULTI;
|
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
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return DEVICE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
string Device::string_from_type(DeviceType type)
|
|
|
|
{
|
|
|
|
if(type == DEVICE_CPU)
|
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
|
|
|
return "CPU";
|
2011-04-27 11:58:34 +00:00
|
|
|
else if(type == DEVICE_CUDA)
|
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
|
|
|
return "CUDA";
|
2011-04-27 11:58:34 +00:00
|
|
|
else if(type == DEVICE_OPENCL)
|
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
|
|
|
return "OPENCL";
|
2011-04-27 11:58:34 +00:00
|
|
|
else if(type == DEVICE_NETWORK)
|
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
|
|
|
return "NETWORK";
|
2011-04-27 11:58:34 +00:00
|
|
|
else if(type == DEVICE_MULTI)
|
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
|
|
|
return "MULTI";
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
vector<DeviceType>& Device::available_types()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-01-12 11:00:48 +00:00
|
|
|
if(need_types_update) {
|
|
|
|
types.clear();
|
2012-01-04 18:06:32 +00:00
|
|
|
types.push_back(DEVICE_CPU);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#ifdef WITH_CUDA
|
2014-08-05 07:57:50 +00:00
|
|
|
if(device_cuda_init())
|
2012-01-04 18:06:32 +00:00
|
|
|
types.push_back(DEVICE_CUDA);
|
2011-04-27 11:58:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_OPENCL
|
2014-08-05 07:57:50 +00:00
|
|
|
if(device_opencl_init())
|
2012-01-04 18:06:32 +00:00
|
|
|
types.push_back(DEVICE_OPENCL);
|
2011-04-27 11:58:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_NETWORK
|
2012-01-04 18:06:32 +00:00
|
|
|
types.push_back(DEVICE_NETWORK);
|
2011-04-27 11:58:34 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-12 11:00:48 +00:00
|
|
|
need_types_update = false;
|
2012-01-04 18:06:32 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
vector<DeviceInfo>& Device::available_devices()
|
|
|
|
{
|
2016-01-24 12:05:02 +00:00
|
|
|
if(need_devices_update) {
|
2016-01-12 11:00:48 +00:00
|
|
|
devices.clear();
|
2012-01-04 18:06:32 +00:00
|
|
|
#ifdef WITH_CUDA
|
2014-08-05 07:57:50 +00:00
|
|
|
if(device_cuda_init())
|
2012-01-04 18:06:32 +00:00
|
|
|
device_cuda_info(devices);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_OPENCL
|
2014-08-05 07:57:50 +00:00
|
|
|
if(device_opencl_init())
|
2012-01-04 18:06:32 +00:00
|
|
|
device_opencl_info(devices);
|
|
|
|
#endif
|
|
|
|
|
2012-01-11 13:18:06 +00:00
|
|
|
device_cpu_info(devices);
|
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
#ifdef WITH_NETWORK
|
|
|
|
device_network_info(devices);
|
|
|
|
#endif
|
|
|
|
|
2016-01-24 12:05:02 +00:00
|
|
|
need_devices_update = false;
|
2012-01-04 18:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
2015-01-06 09:13:21 +00:00
|
|
|
string Device::device_capabilities()
|
|
|
|
{
|
|
|
|
string capabilities = "CPU device capabilities: ";
|
|
|
|
capabilities += device_cpu_capabilities() + "\n";
|
|
|
|
#ifdef WITH_CUDA
|
|
|
|
if(device_cuda_init()) {
|
|
|
|
capabilities += "\nCUDA device capabilities:\n";
|
|
|
|
capabilities += device_cuda_capabilities();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_OPENCL
|
|
|
|
if(device_opencl_init()) {
|
|
|
|
capabilities += "\nOpenCL device capabilities:\n";
|
|
|
|
capabilities += device_opencl_capabilities();
|
|
|
|
}
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2015-01-06 09:13:21 +00:00
|
|
|
return capabilities;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
DeviceInfo Device::get_multi_device(vector<DeviceInfo> subdevices)
|
|
|
|
{
|
|
|
|
assert(subdevices.size() > 1);
|
|
|
|
|
|
|
|
DeviceInfo info;
|
|
|
|
info.type = DEVICE_MULTI;
|
|
|
|
info.id = "MULTI";
|
|
|
|
info.description = "Multi Device";
|
|
|
|
info.multi_devices = subdevices;
|
|
|
|
info.num = 0;
|
|
|
|
|
|
|
|
info.has_bindless_textures = true;
|
|
|
|
info.pack_images = false;
|
|
|
|
foreach(DeviceInfo &device, subdevices) {
|
|
|
|
assert(device.type == info.multi_devices[0].type);
|
|
|
|
|
|
|
|
info.pack_images |= device.pack_images;
|
|
|
|
info.has_bindless_textures &= device.has_bindless_textures;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2016-01-12 11:00:48 +00:00
|
|
|
void Device::tag_update()
|
|
|
|
{
|
|
|
|
need_types_update = true;
|
|
|
|
need_devices_update = true;
|
|
|
|
}
|
|
|
|
|
2016-02-06 22:40:41 +00:00
|
|
|
void Device::free_memory()
|
|
|
|
{
|
2016-02-16 11:47:12 +00:00
|
|
|
need_types_update = true;
|
|
|
|
need_devices_update = true;
|
2016-02-06 22:40:41 +00:00
|
|
|
types.free_memory();
|
|
|
|
devices.free_memory();
|
|
|
|
}
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
|
|
|
|
device_sub_ptr::device_sub_ptr(Device *device, device_memory& mem, int offset, int size, MemoryType type)
|
|
|
|
: device(device)
|
|
|
|
{
|
|
|
|
ptr = device->mem_alloc_sub_ptr(mem, offset, size, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_sub_ptr::~device_sub_ptr()
|
|
|
|
{
|
|
|
|
device->mem_free_sub_ptr(ptr);
|
|
|
|
}
|
|
|
|
|
2015-01-06 09:13:21 +00:00
|
|
|
CCL_NAMESPACE_END
|