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"
|
2017-04-28 17:25:57 +00:00
|
|
|
#include "util/util_logging.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_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;
|
2017-06-09 07:11:54 +00:00
|
|
|
os << "Use Denoising: "
|
|
|
|
<< string_from_bool(requested_features.use_denoising) << 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()
|
|
|
|
{
|
2017-04-28 17:25:57 +00:00
|
|
|
if(!background) {
|
|
|
|
if(vertex_buffer != 0) {
|
|
|
|
glDeleteBuffers(1, &vertex_buffer);
|
|
|
|
}
|
|
|
|
if(fallback_shader_program != 0) {
|
|
|
|
glDeleteProgram(fallback_shader_program);
|
|
|
|
}
|
2015-05-11 14:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
/* TODO move shaders to standalone .glsl file. */
|
|
|
|
const char *FALLBACK_VERTEX_SHADER =
|
|
|
|
"#version 330\n"
|
|
|
|
"uniform vec2 fullscreen;\n"
|
|
|
|
"in vec2 texCoord;\n"
|
|
|
|
"in vec2 pos;\n"
|
|
|
|
"out vec2 texCoord_interp;\n"
|
|
|
|
"\n"
|
|
|
|
"vec2 normalize_coordinates()\n"
|
|
|
|
"{\n"
|
|
|
|
" return (vec2(2.0) * (pos / fullscreen)) - vec2(1.0);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_Position = vec4(normalize_coordinates(), 0.0, 1.0);\n"
|
|
|
|
" texCoord_interp = texCoord;\n"
|
|
|
|
"}\n\0";
|
|
|
|
|
|
|
|
const char *FALLBACK_FRAGMENT_SHADER =
|
|
|
|
"#version 330\n"
|
|
|
|
"uniform sampler2D image_texture;\n"
|
|
|
|
"in vec2 texCoord_interp;\n"
|
|
|
|
"out vec4 fragColor;\n"
|
|
|
|
"\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" fragColor = texture(image_texture, texCoord_interp);\n"
|
|
|
|
"}\n\0";
|
|
|
|
|
|
|
|
static void shader_print_errors(const char *task, const char *log, const char *code)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-04-28 17:25:57 +00:00
|
|
|
LOG(ERROR) << "Shader: " << task << " error:";
|
|
|
|
LOG(ERROR) << "===== shader string ====";
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
stringstream stream(code);
|
|
|
|
string partial;
|
|
|
|
|
|
|
|
int line = 1;
|
|
|
|
while(getline(stream, partial, '\n')) {
|
|
|
|
if(line < 10) {
|
|
|
|
LOG(ERROR) << " " << line << " " << partial;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(ERROR) << line << " " << partial;
|
|
|
|
}
|
|
|
|
line++;
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
2017-04-28 17:25:57 +00:00
|
|
|
LOG(ERROR) << log;
|
|
|
|
}
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
static int bind_fallback_shader(void)
|
|
|
|
{
|
|
|
|
GLint status;
|
|
|
|
GLchar log[5000];
|
|
|
|
GLsizei length = 0;
|
|
|
|
GLuint program = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
struct Shader {
|
|
|
|
const char *source;
|
|
|
|
GLenum type;
|
|
|
|
} shaders[2] = {
|
|
|
|
{FALLBACK_VERTEX_SHADER, GL_VERTEX_SHADER},
|
|
|
|
{FALLBACK_FRAGMENT_SHADER, GL_FRAGMENT_SHADER}
|
|
|
|
};
|
2015-05-11 14:28:41 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
program = glCreateProgram();
|
2013-10-18 20:11:07 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
for(int i = 0; i < 2; i++) {
|
|
|
|
GLuint shader = glCreateShader(shaders[i].type);
|
|
|
|
|
|
|
|
string source_str = shaders[i].source;
|
|
|
|
const char *c_str = source_str.c_str();
|
2013-10-12 13:55:52 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
glShaderSource(shader, 1, &c_str, NULL);
|
|
|
|
glCompileShader(shader);
|
2013-10-12 13:55:52 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
|
|
|
|
|
|
|
if(!status) {
|
|
|
|
glGetShaderInfoLog(shader, sizeof(log), &length, log);
|
|
|
|
shader_print_errors("compile", log, c_str);
|
|
|
|
return 0;
|
2014-03-26 08:57:30 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
glAttachShader(program, shader);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Link output. */
|
|
|
|
glBindFragDataLocation(program, 0, "fragColor");
|
2015-05-11 14:28:41 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
/* Link and error check. */
|
|
|
|
glLinkProgram(program);
|
2015-05-11 14:28:41 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
glGetProgramiv(program, GL_LINK_STATUS, &status);
|
|
|
|
if(!status) {
|
|
|
|
glGetShaderInfoLog(program, sizeof(log), &length, log);
|
|
|
|
shader_print_errors("linking", log, FALLBACK_VERTEX_SHADER);
|
|
|
|
shader_print_errors("linking", log, FALLBACK_FRAGMENT_SHADER);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-11 14:28:41 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Device::bind_fallback_display_space_shader(const float width, const float height)
|
|
|
|
{
|
|
|
|
if(fallback_status == FALLBACK_SHADER_STATUS_ERROR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fallback_status == FALLBACK_SHADER_STATUS_NONE) {
|
|
|
|
fallback_shader_program = bind_fallback_shader();
|
|
|
|
fallback_status = FALLBACK_SHADER_STATUS_ERROR;
|
|
|
|
|
|
|
|
if (fallback_shader_program == 0) {
|
|
|
|
return false;
|
2015-05-11 14:28:41 +00:00
|
|
|
}
|
2017-04-28 17:25:57 +00:00
|
|
|
|
|
|
|
glUseProgram(fallback_shader_program);
|
|
|
|
image_texture_location = glGetUniformLocation(fallback_shader_program, "image_texture");
|
|
|
|
if(image_texture_location < 0) {
|
|
|
|
LOG(ERROR) << "Shader doesn't containt the 'image_texture' uniform.";
|
|
|
|
return false;
|
2015-05-11 14:28:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
fullscreen_location = glGetUniformLocation(fallback_shader_program, "fullscreen");
|
|
|
|
if(fullscreen_location < 0) {
|
|
|
|
LOG(ERROR) << "Shader doesn't containt the 'fullscreen' uniform.";
|
|
|
|
return false;
|
2015-05-11 14:28:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
fallback_status = FALLBACK_SHADER_STATUS_SUCCESS;
|
|
|
|
}
|
2015-05-11 14:28:41 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
/* Run this every time. */
|
|
|
|
glUseProgram(fallback_shader_program);
|
|
|
|
glUniform1i(image_texture_location, 0);
|
|
|
|
glUniform2f(fullscreen_location, width, height);
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-11 14:28:41 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
void Device::draw_pixels(
|
|
|
|
device_memory& rgba, int y,
|
|
|
|
int w, int h, int width, int height,
|
|
|
|
int dx, int dy, int dw, int dh,
|
|
|
|
bool transparent, const DeviceDrawParams &draw_params)
|
|
|
|
{
|
|
|
|
const bool use_fallback_shader = (draw_params.bind_display_space_shader_cb == NULL);
|
|
|
|
pixels_copy_from(rgba, y, w, h);
|
2015-05-11 14:28:41 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
GLuint texid;
|
|
|
|
glGenTextures(1, &texid);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texid);
|
2015-05-11 14:28:41 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
if(rgba.data_type == TYPE_HALF) {
|
|
|
|
GLhalf *data_pointer = (GLhalf*)rgba.data_pointer;
|
|
|
|
data_pointer += 4 * y * w;
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGBA, GL_HALF_FLOAT, data_pointer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uint8_t *data_pointer = (uint8_t*)rgba.data_pointer;
|
|
|
|
data_pointer += 4 * y * w;
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data_pointer);
|
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2017-04-28 17:25:57 +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);
|
|
|
|
|
|
|
|
if(transparent) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
2014-03-26 08:57:30 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
GLint shader_program;
|
|
|
|
if(use_fallback_shader) {
|
|
|
|
if (!bind_fallback_display_space_shader(dw, dh)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
shader_program = fallback_shader_program;
|
2013-10-12 13:55:52 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-04-28 17:25:57 +00:00
|
|
|
draw_params.bind_display_space_shader_cb();
|
|
|
|
glGetIntegerv(GL_CURRENT_PROGRAM, &shader_program);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!vertex_buffer) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
float *vpointer = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
|
|
|
|
|
|
|
if(vpointer) {
|
|
|
|
/* texture coordinate - vertex pair */
|
|
|
|
vpointer[0] = 0.0f;
|
|
|
|
vpointer[1] = 0.0f;
|
|
|
|
vpointer[2] = dx;
|
|
|
|
vpointer[3] = dy;
|
2013-10-12 13:55:52 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
vpointer[4] = 1.0f;
|
|
|
|
vpointer[5] = 0.0f;
|
|
|
|
vpointer[6] = (float)width + dx;
|
|
|
|
vpointer[7] = dy;
|
2013-10-12 13:55:52 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
vpointer[8] = 1.0f;
|
|
|
|
vpointer[9] = 1.0f;
|
|
|
|
vpointer[10] = (float)width + dx;
|
|
|
|
vpointer[11] = (float)height + dy;
|
2013-10-12 13:55:52 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
vpointer[12] = 0.0f;
|
|
|
|
vpointer[13] = 1.0f;
|
|
|
|
vpointer[14] = dx;
|
|
|
|
vpointer[15] = (float)height + dy;
|
2013-10-12 13:55:52 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
if(vertex_buffer) {
|
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
|
|
}
|
2013-10-12 13:55:52 +00:00
|
|
|
}
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2017-04-28 17:25:57 +00:00
|
|
|
GLuint vertex_array_object;
|
|
|
|
GLuint position_attribute, texcoord_attribute;
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &vertex_array_object);
|
|
|
|
glBindVertexArray(vertex_array_object);
|
|
|
|
|
|
|
|
texcoord_attribute = glGetAttribLocation(shader_program, "texCoord");
|
|
|
|
position_attribute = glGetAttribLocation(shader_program, "pos");
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(texcoord_attribute);
|
|
|
|
glEnableVertexAttribArray(position_attribute);
|
|
|
|
|
|
|
|
glVertexAttribPointer(texcoord_attribute, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)0);
|
|
|
|
glVertexAttribPointer(position_attribute, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)(sizeof(float) * 2));
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
|
|
|
|
if(vertex_buffer) {
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(use_fallback_shader) {
|
|
|
|
glUseProgram(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
draw_params.unbind_display_space_shader_cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glDeleteTextures(1, &texid);
|
|
|
|
|
|
|
|
if(transparent) {
|
2011-08-28 13:55:59 +00:00
|
|
|
glDisable(GL_BLEND);
|
2017-04-28 17:25:57 +00:00
|
|
|
}
|
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;
|
|
|
|
foreach(DeviceInfo &device, subdevices) {
|
|
|
|
assert(device.type == info.multi_devices[0].type);
|
|
|
|
|
|
|
|
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
|