forked from bartvdbraak/blender
07b2241fb1
=== BVH build time optimizations === * BVH building was multithreaded. Not all building is multithreaded, packing and the initial bounding/splitting is still single threaded, but recursive splitting is, which was the main bottleneck. * Object splitting now uses binning rather than sorting of all elements, using code from the Embree raytracer from Intel. http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ * Other small changes to avoid allocations, pack memory more tightly, avoid some unnecessary operations, ... These optimizations do not work yet when Spatial Splits are enabled, for that more work is needed. There's also other optimizations still needed, in particular for the case of many low poly objects, the packing step and node memory allocation. BVH raytracing time should remain about the same, but BVH build time should be significantly reduced, test here show speedup of about 5x to 10x on a dual core and 5x to 25x on an 8-core machine, depending on the scene. === Threads === Centralized task scheduler for multithreading, which is basically the CPU device threading code wrapped into something reusable. Basic idea is that there is a single TaskScheduler that keeps a pool of threads, one for each core. Other places in the code can then create a TaskPool that they can drop Tasks in to be executed by the scheduler, and wait for them to complete or cancel them early. === Normal ==== Added a Normal output to the texture coordinate node. This currently gives the object space normal, which is the same under object animation. In the future this might become a "generated" normal so it's also stable for deforming objects, but for now it's already useful for non-deforming objects. === Render Layers === Per render layer Samples control, leaving it to 0 will use the common scene setting. Environment pass will now render environment even if film is set to transparent. Exclude Layers" added. Scene layers (all object that influence the render, directly or indirectly) are shared between all render layers. However sometimes it's useful to leave out some object influence for a particular render layer. That's what this option allows you to do. === Filter Glossy === When using a value higher than 0.0, this will blur glossy reflections after blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good starting value to tweak. Some light paths have a low probability of being found while contributing much light to the pixel. As a result these light paths will be found in some pixels and not in others, causing fireflies. An example of such a difficult path might be a small light that is causing a small specular highlight on a sharp glossy material, which we are seeing through a rough glossy material. With path tracing it is difficult to find the specular highlight, but if we increase the roughness on the material the highlight gets bigger and softer, and so easier to find. Often this blurring will be hardly noticeable, because we are seeing it through a blurry material anyway, but there are also cases where this will lead to a loss of detail in lighting.
280 lines
5.5 KiB
C++
280 lines
5.5 KiB
C++
/*
|
|
* Copyright 2011, Blender Foundation.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "device.h"
|
|
#include "device_intern.h"
|
|
|
|
#include "util_cuda.h"
|
|
#include "util_debug.h"
|
|
#include "util_foreach.h"
|
|
#include "util_math.h"
|
|
#include "util_opencl.h"
|
|
#include "util_opengl.h"
|
|
#include "util_types.h"
|
|
#include "util_vector.h"
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
/* Device Task */
|
|
|
|
DeviceTask::DeviceTask(Type type_)
|
|
: type(type_), x(0), y(0), w(0), h(0), rng_state(0), rgba(0), buffer(0),
|
|
sample(0), resolution(0),
|
|
shader_input(0), shader_output(0),
|
|
shader_eval_type(0), shader_x(0), shader_w(0)
|
|
{
|
|
}
|
|
|
|
void DeviceTask::split_max_size(list<DeviceTask>& tasks, int max_size)
|
|
{
|
|
int num;
|
|
|
|
if(type == SHADER) {
|
|
num = (shader_w + max_size - 1)/max_size;
|
|
}
|
|
else {
|
|
max_size = max(1, max_size/w);
|
|
num = (h + max_size - 1)/max_size;
|
|
}
|
|
|
|
split(tasks, num);
|
|
}
|
|
|
|
void DeviceTask::split(list<DeviceTask>& tasks, int num)
|
|
{
|
|
if(type == SHADER) {
|
|
num = min(shader_w, num);
|
|
|
|
for(int i = 0; i < num; i++) {
|
|
int tx = shader_x + (shader_w/num)*i;
|
|
int tw = (i == num-1)? shader_w - i*(shader_w/num): shader_w/num;
|
|
|
|
DeviceTask task = *this;
|
|
|
|
task.shader_x = tx;
|
|
task.shader_w = tw;
|
|
|
|
tasks.push_back(task);
|
|
}
|
|
}
|
|
else {
|
|
num = min(h, num);
|
|
|
|
for(int i = 0; i < num; i++) {
|
|
int ty = y + (h/num)*i;
|
|
int th = (i == num-1)? h - i*(h/num): h/num;
|
|
|
|
DeviceTask task = *this;
|
|
|
|
task.y = ty;
|
|
task.h = th;
|
|
|
|
tasks.push_back(task);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Device */
|
|
|
|
void Device::pixels_alloc(device_memory& mem)
|
|
{
|
|
mem_alloc(mem, MEM_READ_WRITE);
|
|
}
|
|
|
|
void Device::pixels_copy_from(device_memory& mem, int y, int w, int h)
|
|
{
|
|
mem_copy_from(mem, y, w, h, sizeof(uint8_t)*4);
|
|
}
|
|
|
|
void Device::pixels_free(device_memory& mem)
|
|
{
|
|
mem_free(mem);
|
|
}
|
|
|
|
void Device::draw_pixels(device_memory& rgba, int y, int w, int h, int dy, int width, int height, bool transparent)
|
|
{
|
|
pixels_copy_from(rgba, y, w, h);
|
|
|
|
if(transparent) {
|
|
glEnable(GL_BLEND);
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
}
|
|
|
|
glPixelZoom((float)width/(float)w, (float)height/(float)h);
|
|
glRasterPos2f(0, dy);
|
|
|
|
uint8_t *pixels = (uint8_t*)rgba.data_pointer;
|
|
|
|
/* for multi devices, this assumes the ineffecient method that we allocate
|
|
all pixels on the device even though we only render to a subset */
|
|
pixels += 4*y*w;
|
|
|
|
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
|
|
|
glRasterPos2f(0.0f, 0.0f);
|
|
glPixelZoom(1.0f, 1.0f);
|
|
|
|
if(transparent)
|
|
glDisable(GL_BLEND);
|
|
}
|
|
|
|
Device *Device::create(DeviceInfo& info, bool background, int threads)
|
|
{
|
|
Device *device;
|
|
|
|
switch(info.type) {
|
|
case DEVICE_CPU:
|
|
device = device_cpu_create(info, threads);
|
|
break;
|
|
#ifdef WITH_CUDA
|
|
case DEVICE_CUDA:
|
|
if(cuLibraryInit())
|
|
device = device_cuda_create(info, background);
|
|
else
|
|
device = NULL;
|
|
break;
|
|
#endif
|
|
#ifdef WITH_MULTI
|
|
case DEVICE_MULTI:
|
|
device = device_multi_create(info, background);
|
|
break;
|
|
#endif
|
|
#ifdef WITH_NETWORK
|
|
case DEVICE_NETWORK:
|
|
device = device_network_create(info, "127.0.0.1");
|
|
break;
|
|
#endif
|
|
#ifdef WITH_OPENCL
|
|
case DEVICE_OPENCL:
|
|
if(clLibraryInit())
|
|
device = device_opencl_create(info, background);
|
|
else
|
|
device = NULL;
|
|
break;
|
|
#endif
|
|
default:
|
|
return NULL;
|
|
}
|
|
|
|
if(device)
|
|
device->info = info;
|
|
|
|
return device;
|
|
}
|
|
|
|
DeviceType Device::type_from_string(const char *name)
|
|
{
|
|
if(strcmp(name, "cpu") == 0)
|
|
return DEVICE_CPU;
|
|
else if(strcmp(name, "cuda") == 0)
|
|
return DEVICE_CUDA;
|
|
else if(strcmp(name, "opencl") == 0)
|
|
return DEVICE_OPENCL;
|
|
else if(strcmp(name, "network") == 0)
|
|
return DEVICE_NETWORK;
|
|
else if(strcmp(name, "multi") == 0)
|
|
return DEVICE_MULTI;
|
|
|
|
return DEVICE_NONE;
|
|
}
|
|
|
|
string Device::string_from_type(DeviceType type)
|
|
{
|
|
if(type == DEVICE_CPU)
|
|
return "cpu";
|
|
else if(type == DEVICE_CUDA)
|
|
return "cuda";
|
|
else if(type == DEVICE_OPENCL)
|
|
return "opencl";
|
|
else if(type == DEVICE_NETWORK)
|
|
return "network";
|
|
else if(type == DEVICE_MULTI)
|
|
return "multi";
|
|
|
|
return "";
|
|
}
|
|
|
|
vector<DeviceType>& Device::available_types()
|
|
{
|
|
static vector<DeviceType> types;
|
|
static bool types_init = false;
|
|
|
|
if(!types_init) {
|
|
types.push_back(DEVICE_CPU);
|
|
|
|
#ifdef WITH_CUDA
|
|
if(cuLibraryInit())
|
|
types.push_back(DEVICE_CUDA);
|
|
#endif
|
|
|
|
#ifdef WITH_OPENCL
|
|
if(clLibraryInit())
|
|
types.push_back(DEVICE_OPENCL);
|
|
#endif
|
|
|
|
#ifdef WITH_NETWORK
|
|
types.push_back(DEVICE_NETWORK);
|
|
#endif
|
|
#ifdef WITH_MULTI
|
|
types.push_back(DEVICE_MULTI);
|
|
#endif
|
|
|
|
types_init = true;
|
|
}
|
|
|
|
return types;
|
|
}
|
|
|
|
vector<DeviceInfo>& Device::available_devices()
|
|
{
|
|
static vector<DeviceInfo> devices;
|
|
static bool devices_init = false;
|
|
|
|
if(!devices_init) {
|
|
#ifdef WITH_CUDA
|
|
if(cuLibraryInit())
|
|
device_cuda_info(devices);
|
|
#endif
|
|
|
|
#ifdef WITH_OPENCL
|
|
if(clLibraryInit())
|
|
device_opencl_info(devices);
|
|
#endif
|
|
|
|
#ifdef WITH_MULTI
|
|
device_multi_info(devices);
|
|
#endif
|
|
|
|
device_cpu_info(devices);
|
|
|
|
#ifdef WITH_NETWORK
|
|
device_network_info(devices);
|
|
#endif
|
|
|
|
devices_init = true;
|
|
}
|
|
|
|
return devices;
|
|
}
|
|
|
|
CCL_NAMESPACE_END
|
|
|