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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DEVICE_H__
|
|
|
|
#define __DEVICE_H__
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "device_memory.h"
|
2012-09-04 13:29:07 +00:00
|
|
|
#include "device_task.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-12-20 17:36:56 +00:00
|
|
|
#include "util_list.h"
|
2012-11-05 08:04:57 +00:00
|
|
|
#include "util_stats.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_string.h"
|
|
|
|
#include "util_thread.h"
|
|
|
|
#include "util_types.h"
|
|
|
|
#include "util_vector.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class Progress;
|
2012-09-04 13:29:07 +00:00
|
|
|
class RenderTile;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
/* Device Types */
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
enum DeviceType {
|
|
|
|
DEVICE_NONE,
|
|
|
|
DEVICE_CPU,
|
|
|
|
DEVICE_OPENCL,
|
|
|
|
DEVICE_CUDA,
|
|
|
|
DEVICE_NETWORK,
|
|
|
|
DEVICE_MULTI
|
|
|
|
};
|
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
class DeviceInfo {
|
|
|
|
public:
|
|
|
|
DeviceType type;
|
|
|
|
string description;
|
|
|
|
string id;
|
|
|
|
int num;
|
|
|
|
bool display_device;
|
2012-01-26 19:07:01 +00:00
|
|
|
bool advanced_shading;
|
2012-05-13 12:32:44 +00:00
|
|
|
bool pack_images;
|
2014-05-11 01:38:39 +00:00
|
|
|
bool extended_images; /* flag for GPU and Multi device */
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
bool use_split_kernel; /* Denotes if the device is going to run cycles using split-kernel */
|
2012-01-04 18:06:32 +00:00
|
|
|
vector<DeviceInfo> multi_devices;
|
|
|
|
|
|
|
|
DeviceInfo()
|
|
|
|
{
|
|
|
|
type = DEVICE_CPU;
|
|
|
|
id = "CPU";
|
|
|
|
num = 0;
|
|
|
|
display_device = false;
|
2012-01-26 19:07:01 +00:00
|
|
|
advanced_shading = true;
|
2012-05-13 12:32:44 +00:00
|
|
|
pack_images = false;
|
2014-05-11 01:38:39 +00:00
|
|
|
extended_images = false;
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +00:00
|
|
|
use_split_kernel = false;
|
2012-01-04 18:06:32 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2015-05-09 14:05:49 +00:00
|
|
|
class DeviceRequestedFeatures {
|
|
|
|
public:
|
|
|
|
/* Use experimental feature set. */
|
|
|
|
bool experimental;
|
|
|
|
|
2015-05-09 14:28:00 +00:00
|
|
|
/* Maximum number of closures in shader trees. */
|
|
|
|
int max_closure;
|
|
|
|
|
|
|
|
/* Selective nodes compilation. */
|
|
|
|
|
|
|
|
/* Identifier of a node group up to which all the nodes needs to be
|
|
|
|
* compiled in. Nodes from higher group indices will be ignores.
|
|
|
|
*/
|
|
|
|
int max_nodes_group;
|
|
|
|
|
|
|
|
/* Features bitfield indicating which features from the requested group
|
|
|
|
* will be compiled in. Nodes which corresponds to features which are not
|
|
|
|
* in this bitfield will be ignored even if they're in the requested group.
|
|
|
|
*/
|
|
|
|
int nodes_features;
|
|
|
|
|
2015-06-05 17:50:22 +00:00
|
|
|
/* BVH/sampling kernel features. */
|
|
|
|
bool use_hair;
|
|
|
|
bool use_object_motion;
|
|
|
|
bool use_camera_motion;
|
|
|
|
|
2015-07-18 13:34:32 +00:00
|
|
|
/* Denotes whether baking functionality is needed. */
|
|
|
|
bool use_baking;
|
|
|
|
|
2015-05-09 14:05:49 +00:00
|
|
|
DeviceRequestedFeatures()
|
|
|
|
{
|
2015-05-09 14:28:00 +00:00
|
|
|
/* TODO(sergey): Find more meaningful defaults. */
|
2015-05-09 14:05:49 +00:00
|
|
|
experimental = false;
|
2015-05-09 14:28:00 +00:00
|
|
|
max_closure = 0;
|
|
|
|
max_nodes_group = 0;
|
|
|
|
nodes_features = 0;
|
2015-06-05 17:50:22 +00:00
|
|
|
use_hair = false;
|
|
|
|
use_object_motion = false;
|
|
|
|
use_camera_motion = false;
|
2015-07-18 13:34:32 +00:00
|
|
|
use_baking = false;
|
2015-05-09 14:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool modified(const DeviceRequestedFeatures& requested_features)
|
|
|
|
{
|
2015-05-09 14:28:00 +00:00
|
|
|
return !(experimental == requested_features.experimental &&
|
|
|
|
max_closure == requested_features.max_closure &&
|
|
|
|
max_nodes_group == requested_features.max_nodes_group &&
|
2015-07-18 13:34:32 +00:00
|
|
|
nodes_features == requested_features.nodes_features &&
|
|
|
|
use_hair == requested_features.use_hair &&
|
|
|
|
use_object_motion == requested_features.use_object_motion &&
|
|
|
|
use_camera_motion == requested_features.use_camera_motion &&
|
|
|
|
use_baking == requested_features.use_baking);
|
2015-05-09 14:05:49 +00:00
|
|
|
}
|
2015-07-18 14:00:07 +00:00
|
|
|
|
2015-05-09 14:05:49 +00:00
|
|
|
};
|
|
|
|
|
2015-07-18 14:00:07 +00:00
|
|
|
std::ostream& operator <<(std::ostream &os,
|
|
|
|
const DeviceRequestedFeatures& requested_features);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Device */
|
|
|
|
|
2014-03-26 08:57:30 +00:00
|
|
|
struct DeviceDrawParams {
|
2015-03-29 20:12:22 +00:00
|
|
|
function<void(void)> bind_display_space_shader_cb;
|
|
|
|
function<void(void)> unbind_display_space_shader_cb;
|
2014-03-26 08:57:30 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
class Device {
|
|
|
|
protected:
|
2015-05-11 14:28:41 +00:00
|
|
|
Device(DeviceInfo& info_, Stats &stats_, bool background) : background(background), vertex_buffer(0), info(info_), stats(stats_) {}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
bool background;
|
2011-11-22 20:49:33 +00:00
|
|
|
string error_msg;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2015-05-11 14:28:41 +00:00
|
|
|
/* used for real time display */
|
|
|
|
unsigned int vertex_buffer;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
public:
|
2015-05-11 14:28:41 +00:00
|
|
|
virtual ~Device();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* info */
|
2012-01-26 19:07:01 +00:00
|
|
|
DeviceInfo info;
|
2012-01-04 18:06:32 +00:00
|
|
|
virtual const string& error_message() { return error_msg; }
|
2012-12-23 12:53:58 +00:00
|
|
|
bool have_error() { return !error_message().empty(); }
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-11-05 08:04:57 +00:00
|
|
|
/* statistics */
|
|
|
|
Stats &stats;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* regular memory */
|
|
|
|
virtual void mem_alloc(device_memory& mem, MemoryType type) = 0;
|
|
|
|
virtual void mem_copy_to(device_memory& mem) = 0;
|
|
|
|
virtual void mem_copy_from(device_memory& mem,
|
2012-01-09 16:58:01 +00:00
|
|
|
int y, int w, int h, int elem) = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
virtual void mem_zero(device_memory& mem) = 0;
|
|
|
|
virtual void mem_free(device_memory& mem) = 0;
|
|
|
|
|
|
|
|
/* constant memory */
|
|
|
|
virtual void const_copy_to(const char *name, void *host, size_t size) = 0;
|
|
|
|
|
|
|
|
/* texture memory */
|
2015-03-27 10:47:55 +00:00
|
|
|
virtual void tex_alloc(const char * /*name*/,
|
|
|
|
device_memory& /*mem*/,
|
|
|
|
InterpolationType interpolation = INTERPOLATION_NONE,
|
2015-07-28 11:51:10 +00:00
|
|
|
ExtensionType extension = EXTENSION_REPEAT)
|
2015-03-27 10:47:55 +00:00
|
|
|
{
|
|
|
|
(void)interpolation; /* Ignored. */
|
2015-07-28 11:51:10 +00:00
|
|
|
(void)extension; /* Ignored. */
|
2015-03-27 10:47:55 +00:00
|
|
|
};
|
|
|
|
virtual void tex_free(device_memory& /*mem*/) {};
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* pixel memory */
|
|
|
|
virtual void pixels_alloc(device_memory& mem);
|
|
|
|
virtual void pixels_copy_from(device_memory& mem, int y, int w, int h);
|
|
|
|
virtual void pixels_free(device_memory& mem);
|
|
|
|
|
|
|
|
/* open shading language, only for CPU device */
|
|
|
|
virtual void *osl_memory() { return NULL; }
|
|
|
|
|
2011-09-02 00:10:03 +00:00
|
|
|
/* load/compile kernels, must be called before adding tasks */
|
2015-05-09 14:05:49 +00:00
|
|
|
virtual bool load_kernels(
|
|
|
|
const DeviceRequestedFeatures& /*requested_features*/)
|
|
|
|
{ return true; }
|
2011-09-02 00:10:03 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* tasks */
|
2014-07-22 21:41:01 +00:00
|
|
|
virtual int get_split_task_count(DeviceTask& task) = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
virtual void task_add(DeviceTask& task) = 0;
|
|
|
|
virtual void task_wait() = 0;
|
|
|
|
virtual void task_cancel() = 0;
|
|
|
|
|
|
|
|
/* opengl drawing */
|
|
|
|
virtual void draw_pixels(device_memory& mem, int y, int w, int h,
|
2015-05-11 14:40:38 +00:00
|
|
|
int dx, int dy, int width, int height, bool transparent,
|
2014-03-26 08:57:30 +00:00
|
|
|
const DeviceDrawParams &draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#ifdef WITH_NETWORK
|
|
|
|
/* networking */
|
|
|
|
void server_run();
|
|
|
|
#endif
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* multi device */
|
2015-03-27 10:47:55 +00:00
|
|
|
virtual void map_tile(Device * /*sub_device*/, RenderTile& /*tile*/) {}
|
|
|
|
virtual int device_number(Device * /*sub_device*/) { return 0; }
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* static */
|
2012-11-07 21:00:49 +00:00
|
|
|
static Device *create(DeviceInfo& info, Stats &stats, bool background = true);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
static DeviceType type_from_string(const char *name);
|
|
|
|
static string string_from_type(DeviceType type);
|
2012-01-04 18:06:32 +00:00
|
|
|
static vector<DeviceType>& available_types();
|
|
|
|
static vector<DeviceInfo>& available_devices();
|
2015-01-06 09:13:21 +00:00
|
|
|
static string device_capabilities();
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __DEVICE_H__ */
|
|
|
|
|