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>
|
|
|
|
|
2014-10-06 07:43:23 +00:00
|
|
|
/* So ImathMath is included before our kernel_cpu_compat. */
|
|
|
|
#ifdef WITH_OSL
|
2016-02-05 08:09:39 +00:00
|
|
|
/* So no context pollution happens from indirectly included windows.h */
|
|
|
|
# include "util_windows.h"
|
2014-10-06 07:43:23 +00:00
|
|
|
# include <OSL/oslexec.h>
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "device.h"
|
|
|
|
#include "device_intern.h"
|
2017-02-14 11:20:48 +00:00
|
|
|
#include "device_split_kernel.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#include "kernel.h"
|
2012-12-01 19:15:05 +00:00
|
|
|
#include "kernel_compat_cpu.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "kernel_types.h"
|
2017-02-14 11:20:48 +00:00
|
|
|
#include "split/kernel_split_data.h"
|
2012-12-01 19:15:05 +00:00
|
|
|
#include "kernel_globals.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#include "osl_shader.h"
|
2012-12-01 19:15:05 +00:00
|
|
|
#include "osl_globals.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
#include "buffers.h"
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_debug.h"
|
|
|
|
#include "util_foreach.h"
|
|
|
|
#include "util_function.h"
|
2015-04-10 10:36:56 +00:00
|
|
|
#include "util_logging.h"
|
2017-02-14 11:20:48 +00:00
|
|
|
#include "util_map.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_opengl.h"
|
|
|
|
#include "util_progress.h"
|
|
|
|
#include "util_system.h"
|
|
|
|
#include "util_thread.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2017-02-14 11:20:48 +00:00
|
|
|
class CPUDevice;
|
|
|
|
|
|
|
|
class CPUSplitKernel : public DeviceSplitKernel {
|
|
|
|
CPUDevice *device;
|
|
|
|
public:
|
|
|
|
explicit CPUSplitKernel(CPUDevice *device);
|
|
|
|
|
|
|
|
virtual bool enqueue_split_kernel_data_init(const KernelDimensions& dim,
|
|
|
|
RenderTile& rtile,
|
|
|
|
int num_global_elements,
|
|
|
|
device_memory& kernel_globals,
|
|
|
|
device_memory& kernel_data_,
|
|
|
|
device_memory& split_data,
|
|
|
|
device_memory& ray_state,
|
|
|
|
device_memory& queue_index,
|
|
|
|
device_memory& use_queues_flag,
|
|
|
|
device_memory& work_pool_wgs);
|
|
|
|
|
|
|
|
virtual SplitKernelFunction* get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&);
|
|
|
|
virtual int2 split_kernel_local_size();
|
2017-03-04 11:29:01 +00:00
|
|
|
virtual int2 split_kernel_global_size(device_memory& kg, device_memory& data, DeviceTask *task);
|
|
|
|
virtual size_t state_buffer_size(device_memory& kg, device_memory& data, size_t num_threads);
|
2017-02-14 11:20:48 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
class CPUDevice : public Device
|
|
|
|
{
|
2017-02-14 11:20:48 +00:00
|
|
|
static unordered_map<string, void*> kernel_functions;
|
|
|
|
|
|
|
|
static void register_kernel_function(const char* name, void* func)
|
|
|
|
{
|
|
|
|
kernel_functions[name] = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* get_arch_name()
|
|
|
|
{
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
|
|
|
|
if(system_cpu_support_avx2()) {
|
|
|
|
return "cpu_avx2";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
|
|
|
|
if(system_cpu_support_avx()) {
|
|
|
|
return "cpu_avx";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
|
|
|
|
if(system_cpu_support_sse41()) {
|
|
|
|
return "cpu_sse41";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
|
|
|
|
if(system_cpu_support_sse3()) {
|
|
|
|
return "cpu_sse3";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
|
|
|
|
if(system_cpu_support_sse2()) {
|
|
|
|
return "cpu_sse2";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
return "cpu";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename F>
|
|
|
|
static F get_kernel_function(string name)
|
|
|
|
{
|
|
|
|
name = string("kernel_") + get_arch_name() + "_" + name;
|
|
|
|
|
|
|
|
unordered_map<string, void*>::iterator it = kernel_functions.find(name);
|
|
|
|
|
|
|
|
if(it == kernel_functions.end()) {
|
|
|
|
assert(!"kernel function not found");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (F)it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class CPUSplitKernel;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
public:
|
Cycles: merging features from tomato branch.
=== 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.
2012-04-28 08:53:59 +00:00
|
|
|
TaskPool task_pool;
|
2012-12-01 19:15:05 +00:00
|
|
|
KernelGlobals kernel_globals;
|
2013-12-07 01:29:53 +00:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
#ifdef WITH_OSL
|
|
|
|
OSLGlobals osl_globals;
|
|
|
|
#endif
|
2017-02-14 11:20:48 +00:00
|
|
|
|
|
|
|
bool use_split_kernel;
|
|
|
|
|
|
|
|
DeviceRequestedFeatures requested_features;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
CPUDevice(DeviceInfo& info, Stats &stats, bool background)
|
|
|
|
: Device(info, stats, background)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-02-14 11:20:48 +00:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
#ifdef WITH_OSL
|
|
|
|
kernel_globals.osl = &osl_globals;
|
|
|
|
#endif
|
2011-08-24 10:44:04 +00:00
|
|
|
|
2011-11-15 15:13:38 +00:00
|
|
|
/* do now to avoid thread issues */
|
2013-02-04 16:12:37 +00:00
|
|
|
system_cpu_support_sse2();
|
|
|
|
system_cpu_support_sse3();
|
2013-11-22 13:16:47 +00:00
|
|
|
system_cpu_support_sse41();
|
2014-01-16 16:04:11 +00:00
|
|
|
system_cpu_support_avx();
|
2014-06-13 20:23:58 +00:00
|
|
|
system_cpu_support_avx2();
|
2016-01-12 11:00:48 +00:00
|
|
|
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
|
|
|
|
if(system_cpu_support_avx2()) {
|
|
|
|
VLOG(1) << "Will be using AVX2 kernels.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
|
|
|
|
if(system_cpu_support_avx()) {
|
|
|
|
VLOG(1) << "Will be using AVX kernels.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
|
|
|
|
if(system_cpu_support_sse41()) {
|
|
|
|
VLOG(1) << "Will be using SSE4.1 kernels.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
|
|
|
|
if(system_cpu_support_sse3()) {
|
|
|
|
VLOG(1) << "Will be using SSE3kernels.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
|
|
|
|
if(system_cpu_support_sse2()) {
|
|
|
|
VLOG(1) << "Will be using SSE2 kernels.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
VLOG(1) << "Will be using regular kernels.";
|
|
|
|
}
|
2017-02-14 11:20:48 +00:00
|
|
|
|
|
|
|
use_split_kernel = DebugFlags().cpu.split_kernel;
|
|
|
|
if(use_split_kernel) {
|
|
|
|
VLOG(1) << "Will be using split kernel.";
|
|
|
|
}
|
|
|
|
|
|
|
|
kernel_cpu_register_functions(register_kernel_function);
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
|
|
|
|
kernel_cpu_sse2_register_functions(register_kernel_function);
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
|
|
|
|
kernel_cpu_sse3_register_functions(register_kernel_function);
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
|
|
|
|
kernel_cpu_sse41_register_functions(register_kernel_function);
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
|
|
|
|
kernel_cpu_avx_register_functions(register_kernel_function);
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
|
|
|
|
kernel_cpu_avx2_register_functions(register_kernel_function);
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~CPUDevice()
|
|
|
|
{
|
Cycles: merging features from tomato branch.
=== 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.
2012-04-28 08:53:59 +00:00
|
|
|
task_pool.stop();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
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 (TaskScheduler::num_threads() == 1);
|
|
|
|
}
|
|
|
|
|
2016-12-14 01:45:09 +00:00
|
|
|
void mem_alloc(const char *name, device_memory& mem, MemoryType /*type*/)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-12-14 01:45:09 +00:00
|
|
|
if(name) {
|
|
|
|
VLOG(1) << "Buffer allocate: " << name << ", "
|
2017-03-07 10:21:36 +00:00
|
|
|
<< string_human_readable_number(mem.memory_size()) << " bytes. ("
|
|
|
|
<< string_human_readable_size(mem.memory_size()) << ")";
|
2016-12-14 01:45:09 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
mem.device_pointer = mem.data_pointer;
|
2017-02-22 12:32:57 +00:00
|
|
|
|
|
|
|
if(!mem.device_pointer) {
|
|
|
|
mem.device_pointer = (device_ptr)malloc(mem.memory_size());
|
|
|
|
}
|
|
|
|
|
2014-09-04 11:22:40 +00:00
|
|
|
mem.device_size = mem.memory_size();
|
|
|
|
stats.mem_alloc(mem.device_size);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 10:47:55 +00:00
|
|
|
void mem_copy_to(device_memory& /*mem*/)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* no-op */
|
|
|
|
}
|
|
|
|
|
2015-03-27 10:47:55 +00:00
|
|
|
void mem_copy_from(device_memory& /*mem*/,
|
|
|
|
int /*y*/, int /*w*/, int /*h*/,
|
|
|
|
int /*elem*/)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* no-op */
|
|
|
|
}
|
|
|
|
|
|
|
|
void mem_zero(device_memory& mem)
|
|
|
|
{
|
|
|
|
memset((void*)mem.device_pointer, 0, mem.memory_size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void mem_free(device_memory& mem)
|
|
|
|
{
|
2014-09-04 11:22:40 +00:00
|
|
|
if(mem.device_pointer) {
|
2017-02-22 12:32:57 +00:00
|
|
|
if(!mem.data_pointer) {
|
|
|
|
free((void*)mem.device_pointer);
|
|
|
|
}
|
|
|
|
|
2014-09-04 11:22:40 +00:00
|
|
|
mem.device_pointer = 0;
|
|
|
|
stats.mem_free(mem.device_size);
|
|
|
|
mem.device_size = 0;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void const_copy_to(const char *name, void *host, size_t size)
|
|
|
|
{
|
2012-12-01 19:15:05 +00:00
|
|
|
kernel_const_copy(&kernel_globals, name, host, size);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 19:58:19 +00:00
|
|
|
void tex_alloc(const char *name,
|
|
|
|
device_memory& mem,
|
|
|
|
InterpolationType interpolation,
|
2015-07-28 11:51:10 +00:00
|
|
|
ExtensionType extension)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-29 22:02:05 +00:00
|
|
|
VLOG(1) << "Texture allocate: " << name << ", "
|
|
|
|
<< string_human_readable_number(mem.memory_size()) << " bytes. ("
|
|
|
|
<< string_human_readable_size(mem.memory_size()) << ")";
|
2015-07-21 19:58:19 +00:00
|
|
|
kernel_tex_copy(&kernel_globals,
|
|
|
|
name,
|
|
|
|
mem.data_pointer,
|
|
|
|
mem.data_width,
|
|
|
|
mem.data_height,
|
|
|
|
mem.data_depth,
|
|
|
|
interpolation,
|
2015-07-28 11:51:10 +00:00
|
|
|
extension);
|
2011-04-27 11:58:34 +00:00
|
|
|
mem.device_pointer = mem.data_pointer;
|
2014-09-04 11:22:40 +00:00
|
|
|
mem.device_size = mem.memory_size();
|
|
|
|
stats.mem_alloc(mem.device_size);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tex_free(device_memory& mem)
|
|
|
|
{
|
2014-09-04 11:22:40 +00:00
|
|
|
if(mem.device_pointer) {
|
|
|
|
mem.device_pointer = 0;
|
|
|
|
stats.mem_free(mem.device_size);
|
|
|
|
mem.device_size = 0;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *osl_memory()
|
|
|
|
{
|
|
|
|
#ifdef WITH_OSL
|
2012-12-01 19:15:05 +00:00
|
|
|
return &osl_globals;
|
2011-04-27 11:58:34 +00:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
void thread_run(DeviceTask *task)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-02-14 11:20:48 +00:00
|
|
|
if(task->type == DeviceTask::PATH_TRACE) {
|
|
|
|
if(!use_split_kernel) {
|
|
|
|
thread_path_trace(*task);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
thread_path_trace_split(*task);
|
|
|
|
}
|
|
|
|
}
|
2013-08-30 23:49:38 +00:00
|
|
|
else if(task->type == DeviceTask::FILM_CONVERT)
|
|
|
|
thread_film_convert(*task);
|
Cycles: merging features from tomato branch.
=== 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.
2012-04-28 08:53:59 +00:00
|
|
|
else if(task->type == DeviceTask::SHADER)
|
|
|
|
thread_shader(*task);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
class CPUDeviceTask : public DeviceTask {
|
|
|
|
public:
|
|
|
|
CPUDeviceTask(CPUDevice *device, DeviceTask& task)
|
|
|
|
: DeviceTask(task)
|
|
|
|
{
|
|
|
|
run = function_bind(&CPUDevice::thread_run, device, this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void thread_path_trace(DeviceTask& task)
|
|
|
|
{
|
2013-10-26 01:06:19 +00:00
|
|
|
if(task_pool.canceled()) {
|
2012-10-13 12:38:32 +00:00
|
|
|
if(task.need_finish_queue == false)
|
|
|
|
return;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-05-17 10:30:46 +00:00
|
|
|
KernelGlobals kg = thread_kernel_globals_init();
|
2012-09-04 13:29:07 +00:00
|
|
|
RenderTile tile;
|
2014-06-13 20:23:58 +00:00
|
|
|
|
2014-10-30 09:17:42 +00:00
|
|
|
void(*path_trace_kernel)(KernelGlobals*, float*, unsigned int*, int, int, int, int, int);
|
2014-06-13 20:23:58 +00:00
|
|
|
|
2014-10-30 09:17:42 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_avx2()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
path_trace_kernel = kernel_cpu_avx2_path_trace;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-10-30 09:17:42 +00:00
|
|
|
else
|
2014-06-13 20:23:58 +00:00
|
|
|
#endif
|
2014-01-16 16:04:11 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_avx()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
path_trace_kernel = kernel_cpu_avx_path_trace;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-10-30 09:17:42 +00:00
|
|
|
else
|
2014-01-16 16:04:11 +00:00
|
|
|
#endif
|
2014-10-30 09:17:42 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse41()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
path_trace_kernel = kernel_cpu_sse41_path_trace;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-10-30 09:17:42 +00:00
|
|
|
else
|
2013-11-22 13:16:47 +00:00
|
|
|
#endif
|
2014-01-14 19:39:21 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse3()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
path_trace_kernel = kernel_cpu_sse3_path_trace;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-10-30 09:17:42 +00:00
|
|
|
else
|
2014-01-14 19:39:21 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse2()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
path_trace_kernel = kernel_cpu_sse2_path_trace;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-10-30 09:17:42 +00:00
|
|
|
else
|
2011-11-15 15:13:38 +00:00
|
|
|
#endif
|
2016-01-06 15:25:19 +00:00
|
|
|
{
|
2014-10-30 09:17:42 +00:00
|
|
|
path_trace_kernel = kernel_cpu_path_trace;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2017-02-14 11:20:48 +00:00
|
|
|
|
2014-10-30 09:17:42 +00:00
|
|
|
while(task.acquire_tile(this, tile)) {
|
|
|
|
float *render_buffer = (float*)tile.buffer;
|
|
|
|
uint *rng_state = (uint*)tile.rng_state;
|
|
|
|
int start_sample = tile.start_sample;
|
|
|
|
int end_sample = tile.start_sample + tile.num_samples;
|
|
|
|
|
2015-02-19 14:05:04 +00:00
|
|
|
for(int sample = start_sample; sample < end_sample; sample++) {
|
2015-03-27 19:15:15 +00:00
|
|
|
if(task.get_cancel() || task_pool.canceled()) {
|
2015-02-19 14:05:04 +00:00
|
|
|
if(task.need_finish_queue == false)
|
|
|
|
break;
|
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2015-02-19 14:05:04 +00:00
|
|
|
for(int y = tile.y; y < tile.y + tile.h; y++) {
|
|
|
|
for(int x = tile.x; x < tile.x + tile.w; x++) {
|
|
|
|
path_trace_kernel(&kg, render_buffer, rng_state,
|
|
|
|
sample, x, y, tile.offset, tile.stride);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-30 09:17:42 +00:00
|
|
|
|
2015-02-19 14:05:04 +00:00
|
|
|
tile.sample = sample + 1;
|
|
|
|
|
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
|
|
|
task.update_progress(&tile, tile.w*tile.h);
|
2015-02-19 14:05:04 +00:00
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
task.release_tile(tile);
|
|
|
|
|
2013-10-26 01:06:19 +00:00
|
|
|
if(task_pool.canceled()) {
|
2012-10-13 12:38:32 +00:00
|
|
|
if(task.need_finish_queue == false)
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 10:30:46 +00:00
|
|
|
thread_kernel_globals_free(&kg);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 11:20:48 +00:00
|
|
|
void thread_path_trace_split(DeviceTask& task)
|
|
|
|
{
|
|
|
|
if(task_pool.canceled()) {
|
|
|
|
if(task.need_finish_queue == false)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderTile tile;
|
|
|
|
|
|
|
|
CPUSplitKernel split_kernel(this);
|
|
|
|
|
|
|
|
/* allocate buffer for kernel globals */
|
|
|
|
device_memory kgbuffer;
|
|
|
|
kgbuffer.resize(sizeof(KernelGlobals));
|
2016-12-14 01:45:09 +00:00
|
|
|
mem_alloc("kernel_globals", kgbuffer, MEM_READ_WRITE);
|
2017-02-14 11:20:48 +00:00
|
|
|
|
|
|
|
KernelGlobals *kg = (KernelGlobals*)kgbuffer.device_pointer;
|
|
|
|
*kg = thread_kernel_globals_init();
|
|
|
|
|
|
|
|
requested_features.max_closure = MAX_CLOSURE;
|
|
|
|
if(!split_kernel.load_kernels(requested_features)) {
|
|
|
|
thread_kernel_globals_free((KernelGlobals*)kgbuffer.device_pointer);
|
|
|
|
mem_free(kgbuffer);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(task.acquire_tile(this, tile)) {
|
|
|
|
device_memory data;
|
|
|
|
split_kernel.path_trace(&task, tile, kgbuffer, data);
|
|
|
|
|
|
|
|
task.release_tile(tile);
|
|
|
|
|
|
|
|
if(task_pool.canceled()) {
|
|
|
|
if(task.need_finish_queue == false)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_kernel_globals_free((KernelGlobals*)kgbuffer.device_pointer);
|
|
|
|
mem_free(kgbuffer);
|
|
|
|
}
|
|
|
|
|
2013-08-30 23:49:38 +00:00
|
|
|
void thread_film_convert(DeviceTask& task)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-08-30 23:49:38 +00:00
|
|
|
float sample_scale = 1.0f/(task.sample + 1);
|
|
|
|
|
|
|
|
if(task.rgba_half) {
|
2014-10-30 09:17:42 +00:00
|
|
|
void(*convert_to_half_float_kernel)(KernelGlobals *, uchar4 *, float *, float, int, int, int, int);
|
2014-06-13 20:23:58 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_avx2()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_half_float_kernel = kernel_cpu_avx2_convert_to_half_float;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-06-13 20:23:58 +00:00
|
|
|
else
|
|
|
|
#endif
|
2014-01-16 16:04:11 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_avx()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_half_float_kernel = kernel_cpu_avx_convert_to_half_float;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-01-16 16:04:11 +00:00
|
|
|
else
|
|
|
|
#endif
|
2013-11-22 13:16:47 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse41()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_half_float_kernel = kernel_cpu_sse41_convert_to_half_float;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2013-11-22 13:16:47 +00:00
|
|
|
else
|
2014-01-14 19:39:21 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse3()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_half_float_kernel = kernel_cpu_sse3_convert_to_half_float;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-01-14 19:39:21 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse2()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_half_float_kernel = kernel_cpu_sse2_convert_to_half_float;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2013-08-30 23:49:38 +00:00
|
|
|
else
|
|
|
|
#endif
|
2016-01-06 15:25:19 +00:00
|
|
|
{
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_half_float_kernel = kernel_cpu_convert_to_half_float;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-10-30 09:17:42 +00:00
|
|
|
|
|
|
|
for(int y = task.y; y < task.y + task.h; y++)
|
|
|
|
for(int x = task.x; x < task.x + task.w; x++)
|
|
|
|
convert_to_half_float_kernel(&kernel_globals, (uchar4*)task.rgba_half, (float*)task.buffer,
|
|
|
|
sample_scale, x, y, task.offset, task.stride);
|
2011-11-15 15:13:38 +00:00
|
|
|
}
|
2013-08-30 23:49:38 +00:00
|
|
|
else {
|
2014-10-30 09:17:42 +00:00
|
|
|
void(*convert_to_byte_kernel)(KernelGlobals *, uchar4 *, float *, float, int, int, int, int);
|
2014-06-13 20:23:58 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_avx2()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_byte_kernel = kernel_cpu_avx2_convert_to_byte;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-06-13 20:23:58 +00:00
|
|
|
else
|
|
|
|
#endif
|
2014-01-16 16:04:11 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_avx()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_byte_kernel = kernel_cpu_avx_convert_to_byte;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-01-16 16:04:11 +00:00
|
|
|
else
|
|
|
|
#endif
|
2013-11-22 13:16:47 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse41()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_byte_kernel = kernel_cpu_sse41_convert_to_byte;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-01-06 02:22:14 +00:00
|
|
|
else
|
2013-11-22 13:16:47 +00:00
|
|
|
#endif
|
2014-01-14 19:39:21 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse3()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_byte_kernel = kernel_cpu_sse3_convert_to_byte;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-01-14 19:39:21 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse2()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_byte_kernel = kernel_cpu_sse2_convert_to_byte;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2013-08-30 23:49:38 +00:00
|
|
|
else
|
2011-11-15 15:13:38 +00:00
|
|
|
#endif
|
2016-01-06 15:25:19 +00:00
|
|
|
{
|
2014-10-30 09:17:42 +00:00
|
|
|
convert_to_byte_kernel = kernel_cpu_convert_to_byte;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-10-30 09:17:42 +00:00
|
|
|
|
|
|
|
for(int y = task.y; y < task.y + task.h; y++)
|
|
|
|
for(int x = task.x; x < task.x + task.w; x++)
|
|
|
|
convert_to_byte_kernel(&kernel_globals, (uchar4*)task.rgba_byte, (float*)task.buffer,
|
|
|
|
sample_scale, x, y, task.offset, task.stride);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-31 15:18:13 +00:00
|
|
|
void thread_shader(DeviceTask& task)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-12-01 19:15:05 +00:00
|
|
|
KernelGlobals kg = kernel_globals;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#ifdef WITH_OSL
|
2012-12-01 19:15:05 +00:00
|
|
|
OSLShader::thread_init(&kg, &kernel_globals, &osl_globals);
|
2011-04-27 11:58:34 +00:00
|
|
|
#endif
|
2016-01-15 15:00:56 +00:00
|
|
|
void(*shader_kernel)(KernelGlobals*, uint4*, float4*, float*, int, int, int, int, int);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-06-13 20:23:58 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_avx2()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
shader_kernel = kernel_cpu_avx2_shader;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-06-13 20:23:58 +00:00
|
|
|
else
|
|
|
|
#endif
|
2014-01-16 16:04:11 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_avx()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
shader_kernel = kernel_cpu_avx_shader;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-01-16 16:04:11 +00:00
|
|
|
else
|
|
|
|
#endif
|
2013-11-22 13:16:47 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse41()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
shader_kernel = kernel_cpu_sse41_shader;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-01-06 02:22:14 +00:00
|
|
|
else
|
2013-11-22 13:16:47 +00:00
|
|
|
#endif
|
2014-01-14 19:39:21 +00:00
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse3()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
shader_kernel = kernel_cpu_sse3_shader;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2014-01-14 19:39:21 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
|
2016-01-06 15:25:19 +00:00
|
|
|
if(system_cpu_support_sse2()) {
|
2014-10-30 09:17:42 +00:00
|
|
|
shader_kernel = kernel_cpu_sse2_shader;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2011-11-15 15:13:38 +00:00
|
|
|
else
|
|
|
|
#endif
|
2016-01-06 15:25:19 +00:00
|
|
|
{
|
2014-10-30 09:17:42 +00:00
|
|
|
shader_kernel = kernel_cpu_shader;
|
2016-01-06 15:25:19 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-10-30 09:17:42 +00:00
|
|
|
for(int sample = 0; sample < task.num_samples; sample++) {
|
|
|
|
for(int x = task.shader_x; x < task.shader_x + task.shader_w; x++)
|
2015-12-30 14:04:01 +00:00
|
|
|
shader_kernel(&kg,
|
|
|
|
(uint4*)task.shader_input,
|
|
|
|
(float4*)task.shader_output,
|
|
|
|
(float*)task.shader_output_luma,
|
|
|
|
task.shader_eval_type,
|
2016-01-15 15:00:56 +00:00
|
|
|
task.shader_filter,
|
2015-12-30 14:04:01 +00:00
|
|
|
x,
|
|
|
|
task.offset,
|
|
|
|
sample);
|
2014-10-30 09:17:42 +00:00
|
|
|
|
|
|
|
if(task.get_cancel() || task_pool.canceled())
|
|
|
|
break;
|
|
|
|
|
|
|
|
task.update_progress(NULL);
|
2014-07-22 21:41:01 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_OSL
|
2012-12-01 19:15:05 +00:00
|
|
|
OSLShader::thread_free(&kg);
|
2011-04-27 11:58:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-07-22 21:41:01 +00:00
|
|
|
int get_split_task_count(DeviceTask& task)
|
|
|
|
{
|
2015-03-27 19:15:15 +00:00
|
|
|
if(task.type == DeviceTask::SHADER)
|
2014-07-22 21:41:01 +00:00
|
|
|
return task.get_subtask_count(TaskScheduler::num_threads(), 256);
|
|
|
|
else
|
|
|
|
return task.get_subtask_count(TaskScheduler::num_threads());
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void task_add(DeviceTask& task)
|
|
|
|
{
|
2013-07-20 00:40:03 +00:00
|
|
|
/* split task into smaller ones */
|
Cycles: merging features from tomato branch.
=== 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.
2012-04-28 08:53:59 +00:00
|
|
|
list<DeviceTask> tasks;
|
2014-05-26 11:40:16 +00:00
|
|
|
|
|
|
|
if(task.type == DeviceTask::SHADER)
|
|
|
|
task.split(tasks, TaskScheduler::num_threads(), 256);
|
|
|
|
else
|
|
|
|
task.split(tasks, TaskScheduler::num_threads());
|
Cycles: merging features from tomato branch.
=== 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.
2012-04-28 08:53:59 +00:00
|
|
|
|
|
|
|
foreach(DeviceTask& task, tasks)
|
2012-05-05 19:44:33 +00:00
|
|
|
task_pool.push(new CPUDeviceTask(this, task));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void task_wait()
|
|
|
|
{
|
2012-05-05 19:44:33 +00:00
|
|
|
task_pool.wait_work();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void task_cancel()
|
|
|
|
{
|
Cycles: merging features from tomato branch.
=== 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.
2012-04-28 08:53:59 +00:00
|
|
|
task_pool.cancel();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2016-05-17 10:30:46 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
inline KernelGlobals thread_kernel_globals_init()
|
|
|
|
{
|
|
|
|
KernelGlobals kg = kernel_globals;
|
|
|
|
kg.transparent_shadow_intersections = NULL;
|
|
|
|
const int decoupled_count = sizeof(kg.decoupled_volume_steps) /
|
|
|
|
sizeof(*kg.decoupled_volume_steps);
|
|
|
|
for(int i = 0; i < decoupled_count; ++i) {
|
|
|
|
kg.decoupled_volume_steps[i] = NULL;
|
|
|
|
}
|
|
|
|
kg.decoupled_volume_steps_index = 0;
|
|
|
|
#ifdef WITH_OSL
|
|
|
|
OSLShader::thread_init(&kg, &kernel_globals, &osl_globals);
|
|
|
|
#endif
|
|
|
|
return kg;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void thread_kernel_globals_free(KernelGlobals *kg)
|
|
|
|
{
|
2017-02-14 11:20:48 +00:00
|
|
|
if(kg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-17 10:30:46 +00:00
|
|
|
if(kg->transparent_shadow_intersections != NULL) {
|
|
|
|
free(kg->transparent_shadow_intersections);
|
|
|
|
}
|
|
|
|
const int decoupled_count = sizeof(kg->decoupled_volume_steps) /
|
|
|
|
sizeof(*kg->decoupled_volume_steps);
|
|
|
|
for(int i = 0; i < decoupled_count; ++i) {
|
|
|
|
if(kg->decoupled_volume_steps[i] != NULL) {
|
|
|
|
free(kg->decoupled_volume_steps[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef WITH_OSL
|
|
|
|
OSLShader::thread_free(kg);
|
|
|
|
#endif
|
|
|
|
}
|
2017-02-14 11:20:48 +00:00
|
|
|
|
|
|
|
virtual bool load_kernels(DeviceRequestedFeatures& requested_features_) {
|
|
|
|
requested_features = requested_features_;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2017-02-14 11:20:48 +00:00
|
|
|
/* split kernel */
|
|
|
|
|
|
|
|
class CPUSplitKernelFunction : public SplitKernelFunction {
|
|
|
|
public:
|
|
|
|
CPUDevice* device;
|
|
|
|
void (*func)(KernelGlobals *kg, KernelData *data);
|
|
|
|
|
|
|
|
CPUSplitKernelFunction(CPUDevice* device) : device(device), func(NULL) {}
|
|
|
|
~CPUSplitKernelFunction() {}
|
|
|
|
|
|
|
|
virtual bool enqueue(const KernelDimensions& dim, device_memory& kernel_globals, device_memory& data)
|
|
|
|
{
|
|
|
|
if(!func) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
KernelGlobals *kg = (KernelGlobals*)kernel_globals.device_pointer;
|
|
|
|
kg->global_size = make_int2(dim.global_size[0], dim.global_size[1]);
|
|
|
|
|
|
|
|
for(int y = 0; y < dim.global_size[1]; y++) {
|
|
|
|
for(int x = 0; x < dim.global_size[0]; x++) {
|
|
|
|
kg->global_id = make_int2(x, y);
|
|
|
|
|
|
|
|
func(kg, (KernelData*)data.device_pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CPUSplitKernel::CPUSplitKernel(CPUDevice *device) : DeviceSplitKernel(device), device(device)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPUSplitKernel::enqueue_split_kernel_data_init(const KernelDimensions& dim,
|
|
|
|
RenderTile& rtile,
|
|
|
|
int num_global_elements,
|
|
|
|
device_memory& kernel_globals,
|
|
|
|
device_memory& data,
|
|
|
|
device_memory& split_data,
|
|
|
|
device_memory& ray_state,
|
|
|
|
device_memory& queue_index,
|
|
|
|
device_memory& use_queues_flags,
|
|
|
|
device_memory& work_pool_wgs)
|
|
|
|
{
|
|
|
|
typedef void(*data_init_t)(KernelGlobals *kg,
|
2017-03-07 10:21:36 +00:00
|
|
|
ccl_constant KernelData *data,
|
|
|
|
ccl_global void *split_data_buffer,
|
|
|
|
int num_elements,
|
|
|
|
ccl_global char *ray_state,
|
|
|
|
ccl_global uint *rng_state,
|
|
|
|
int start_sample,
|
|
|
|
int end_sample,
|
|
|
|
int sx, int sy, int sw, int sh, int offset, int stride,
|
|
|
|
ccl_global int *Queue_index,
|
|
|
|
int queuesize,
|
|
|
|
ccl_global char *use_queues_flag,
|
|
|
|
ccl_global unsigned int *work_pool_wgs,
|
|
|
|
unsigned int num_samples,
|
|
|
|
ccl_global float *buffer);
|
2017-02-14 11:20:48 +00:00
|
|
|
|
|
|
|
data_init_t data_init;
|
|
|
|
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2
|
|
|
|
if(system_cpu_support_avx2()) {
|
|
|
|
data_init = kernel_cpu_avx2_data_init;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_AVX
|
|
|
|
if(system_cpu_support_avx()) {
|
|
|
|
data_init = kernel_cpu_avx_data_init;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41
|
|
|
|
if(system_cpu_support_sse41()) {
|
|
|
|
data_init = kernel_cpu_sse41_data_init;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE3
|
|
|
|
if(system_cpu_support_sse3()) {
|
|
|
|
data_init = kernel_cpu_sse3_data_init;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2
|
|
|
|
if(system_cpu_support_sse2()) {
|
|
|
|
data_init = kernel_cpu_sse2_data_init;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
data_init = kernel_cpu_data_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
KernelGlobals *kg = (KernelGlobals*)kernel_globals.device_pointer;
|
|
|
|
kg->global_size = make_int2(dim.global_size[0], dim.global_size[1]);
|
|
|
|
|
|
|
|
for(int y = 0; y < dim.global_size[1]; y++) {
|
|
|
|
for(int x = 0; x < dim.global_size[0]; x++) {
|
|
|
|
kg->global_id = make_int2(x, y);
|
|
|
|
|
|
|
|
data_init((KernelGlobals*)kernel_globals.device_pointer,
|
2017-03-07 10:21:36 +00:00
|
|
|
(KernelData*)data.device_pointer,
|
|
|
|
(void*)split_data.device_pointer,
|
|
|
|
num_global_elements,
|
|
|
|
(char*)ray_state.device_pointer,
|
|
|
|
(uint*)rtile.rng_state,
|
|
|
|
rtile.start_sample,
|
|
|
|
rtile.start_sample + rtile.num_samples,
|
|
|
|
rtile.x,
|
|
|
|
rtile.y,
|
|
|
|
rtile.w,
|
|
|
|
rtile.h,
|
|
|
|
rtile.offset,
|
|
|
|
rtile.stride,
|
|
|
|
(int*)queue_index.device_pointer,
|
|
|
|
dim.global_size[0] * dim.global_size[1],
|
|
|
|
(char*)use_queues_flags.device_pointer,
|
|
|
|
(uint*)work_pool_wgs.device_pointer,
|
|
|
|
rtile.num_samples,
|
|
|
|
(float*)rtile.buffer);
|
2017-02-14 11:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SplitKernelFunction* CPUSplitKernel::get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&)
|
|
|
|
{
|
|
|
|
CPUSplitKernelFunction *kernel = new CPUSplitKernelFunction(device);
|
|
|
|
|
|
|
|
kernel->func = device->get_kernel_function<void(*)(KernelGlobals*, KernelData*)>(kernel_name);
|
|
|
|
if(!kernel->func) {
|
|
|
|
delete kernel;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kernel;
|
|
|
|
}
|
|
|
|
|
|
|
|
int2 CPUSplitKernel::split_kernel_local_size()
|
|
|
|
{
|
|
|
|
return make_int2(1, 1);
|
|
|
|
}
|
|
|
|
|
2017-03-04 11:29:01 +00:00
|
|
|
int2 CPUSplitKernel::split_kernel_global_size(device_memory& /*kg*/, device_memory& /*data*/, DeviceTask *task) {
|
2017-02-14 11:20:48 +00:00
|
|
|
/* TODO(mai): this needs investigation but cpu gives incorrect render if global size doesnt match tile size */
|
|
|
|
return task->requested_tile_size;
|
|
|
|
}
|
|
|
|
|
2017-03-04 11:29:01 +00:00
|
|
|
size_t CPUSplitKernel::state_buffer_size(device_memory& kernel_globals, device_memory& /*data*/, size_t num_threads) {
|
|
|
|
KernelGlobals *kg = (KernelGlobals*)kernel_globals.device_pointer;
|
|
|
|
|
|
|
|
return split_data_buffer_size(kg, num_threads);
|
|
|
|
}
|
|
|
|
|
2017-02-14 11:20:48 +00:00
|
|
|
unordered_map<string, void*> CPUDevice::kernel_functions;
|
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
Device *device_cpu_create(DeviceInfo& info, Stats &stats, bool background)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-12-07 01:29:53 +00:00
|
|
|
return new CPUDevice(info, stats, background);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
void device_cpu_info(vector<DeviceInfo>& devices)
|
|
|
|
{
|
|
|
|
DeviceInfo info;
|
|
|
|
|
|
|
|
info.type = DEVICE_CPU;
|
|
|
|
info.description = system_cpu_brand_string();
|
|
|
|
info.id = "CPU";
|
|
|
|
info.num = 0;
|
2012-01-26 19:07:01 +00:00
|
|
|
info.advanced_shading = true;
|
2012-05-13 12:32:44 +00:00
|
|
|
info.pack_images = false;
|
2012-01-04 18:06:32 +00:00
|
|
|
|
2012-01-11 13:18:06 +00:00
|
|
|
devices.insert(devices.begin(), info);
|
2012-01-04 18:06:32 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 09:13:21 +00:00
|
|
|
string device_cpu_capabilities(void)
|
|
|
|
{
|
|
|
|
string capabilities = "";
|
|
|
|
capabilities += system_cpu_support_sse2() ? "SSE2 " : "";
|
|
|
|
capabilities += system_cpu_support_sse3() ? "SSE3 " : "";
|
|
|
|
capabilities += system_cpu_support_sse41() ? "SSE41 " : "";
|
|
|
|
capabilities += system_cpu_support_avx() ? "AVX " : "";
|
|
|
|
capabilities += system_cpu_support_avx2() ? "AVX2" : "";
|
|
|
|
if(capabilities[capabilities.size() - 1] == ' ')
|
|
|
|
capabilities.resize(capabilities.size() - 1);
|
|
|
|
return capabilities;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2015-01-06 09:13:21 +00:00
|
|
|
CCL_NAMESPACE_END
|