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 __SCENE_H__
|
|
|
|
#define __SCENE_H__
|
|
|
|
|
|
|
|
#include "image.h"
|
2014-05-19 10:49:36 +00:00
|
|
|
#include "shader.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#include "device_memory.h"
|
|
|
|
|
|
|
|
#include "util_param.h"
|
|
|
|
#include "util_string.h"
|
2014-12-16 15:11:37 +00:00
|
|
|
#include "util_system.h"
|
2016-04-15 21:01:20 +00:00
|
|
|
#include "util_texture.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_thread.h"
|
|
|
|
#include "util_types.h"
|
|
|
|
#include "util_vector.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
class AttributeRequestSet;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Background;
|
|
|
|
class Camera;
|
|
|
|
class Device;
|
2012-09-04 13:29:07 +00:00
|
|
|
class DeviceInfo;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Film;
|
|
|
|
class Integrator;
|
|
|
|
class Light;
|
|
|
|
class LightManager;
|
2013-04-01 20:26:43 +00:00
|
|
|
class LookupTables;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Mesh;
|
|
|
|
class MeshManager;
|
|
|
|
class Object;
|
|
|
|
class ObjectManager;
|
2012-08-31 17:27:08 +00:00
|
|
|
class ParticleSystemManager;
|
|
|
|
class ParticleSystem;
|
2012-12-28 14:21:30 +00:00
|
|
|
class CurveSystemManager;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Shader;
|
|
|
|
class ShaderManager;
|
|
|
|
class Progress;
|
2014-01-02 21:05:07 +00:00
|
|
|
class BakeManager;
|
|
|
|
class BakeData;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* Scene Device Data */
|
|
|
|
|
|
|
|
class DeviceScene {
|
|
|
|
public:
|
|
|
|
/* BVH */
|
|
|
|
device_vector<float4> bvh_nodes;
|
2015-04-13 18:05:09 +00:00
|
|
|
device_vector<float4> bvh_leaf_nodes;
|
2011-04-27 11:58:34 +00:00
|
|
|
device_vector<uint> object_node;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
device_vector<uint> prim_tri_index;
|
|
|
|
device_vector<float4> prim_tri_verts;
|
2014-03-29 12:03:46 +00:00
|
|
|
device_vector<uint> prim_type;
|
2011-09-01 15:53:36 +00:00
|
|
|
device_vector<uint> prim_visibility;
|
2011-04-27 11:58:34 +00:00
|
|
|
device_vector<uint> prim_index;
|
|
|
|
device_vector<uint> prim_object;
|
2017-02-15 09:56:54 +00:00
|
|
|
device_vector<float2> prim_time;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* mesh */
|
2014-09-24 11:34:28 +00:00
|
|
|
device_vector<uint> tri_shader;
|
2011-04-27 11:58:34 +00:00
|
|
|
device_vector<float4> tri_vnormal;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
device_vector<uint4> tri_vindex;
|
2016-07-16 23:42:28 +00:00
|
|
|
device_vector<uint> tri_patch;
|
|
|
|
device_vector<float2> tri_patch_uv;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-03 12:09:09 +00:00
|
|
|
device_vector<float4> curves;
|
2013-01-03 12:08:54 +00:00
|
|
|
device_vector<float4> curve_keys;
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
device_vector<uint> patches;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* objects */
|
|
|
|
device_vector<float4> objects;
|
2012-12-20 19:26:57 +00:00
|
|
|
device_vector<float4> objects_vector;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* attributes */
|
|
|
|
device_vector<uint4> attributes_map;
|
|
|
|
device_vector<float> attributes_float;
|
|
|
|
device_vector<float4> attributes_float3;
|
2014-06-13 21:40:39 +00:00
|
|
|
device_vector<uchar4> attributes_uchar4;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* lights */
|
|
|
|
device_vector<float4> light_distribution;
|
2011-09-27 20:37:24 +00:00
|
|
|
device_vector<float4> light_data;
|
2012-01-20 17:49:17 +00:00
|
|
|
device_vector<float2> light_background_marginal_cdf;
|
|
|
|
device_vector<float2> light_background_conditional_cdf;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-06-08 16:17:57 +00:00
|
|
|
/* particles */
|
|
|
|
device_vector<float4> particles;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* shaders */
|
|
|
|
device_vector<uint4> svm_nodes;
|
2011-09-27 20:37:24 +00:00
|
|
|
device_vector<uint> shader_flag;
|
2012-05-02 09:33:45 +00:00
|
|
|
device_vector<uint> object_flag;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-04-01 20:26:43 +00:00
|
|
|
/* lookup tables */
|
|
|
|
device_vector<float> lookup_table;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* integrator */
|
|
|
|
device_vector<uint> sobol_directions;
|
|
|
|
|
2014-05-11 01:38:39 +00:00
|
|
|
/* cpu images */
|
2016-05-27 20:58:33 +00:00
|
|
|
device_vector<uchar4> tex_byte4_image[TEX_NUM_BYTE4_CPU];
|
|
|
|
device_vector<float4> tex_float4_image[TEX_NUM_FLOAT4_CPU];
|
|
|
|
device_vector<float> tex_float_image[TEX_NUM_FLOAT_CPU];
|
|
|
|
device_vector<uchar> tex_byte_image[TEX_NUM_BYTE_CPU];
|
2016-06-19 15:31:16 +00:00
|
|
|
device_vector<half4> tex_half4_image[TEX_NUM_HALF4_CPU];
|
|
|
|
device_vector<half> tex_half_image[TEX_NUM_HALF_CPU];
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-05-13 12:32:44 +00:00
|
|
|
/* opencl images */
|
2016-05-09 15:06:22 +00:00
|
|
|
device_vector<uchar4> tex_image_byte4_packed;
|
|
|
|
device_vector<float4> tex_image_float4_packed;
|
2016-08-14 18:21:08 +00:00
|
|
|
device_vector<uchar> tex_image_byte_packed;
|
|
|
|
device_vector<float> tex_image_float_packed;
|
2012-05-13 12:32:44 +00:00
|
|
|
device_vector<uint4> tex_image_packed_info;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
KernelData data;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Scene Parameters */
|
|
|
|
|
|
|
|
class SceneParams {
|
|
|
|
public:
|
2014-05-16 13:43:28 +00:00
|
|
|
ShadingSystem shadingsystem;
|
2016-02-10 14:09:45 +00:00
|
|
|
enum BVHType {
|
|
|
|
BVH_DYNAMIC = 0,
|
|
|
|
BVH_STATIC = 1,
|
|
|
|
|
|
|
|
BVH_NUM_TYPES,
|
|
|
|
} bvh_type;
|
2011-04-27 11:58:34 +00:00
|
|
|
bool use_bvh_spatial_split;
|
2016-07-07 16:04:16 +00:00
|
|
|
bool use_bvh_unaligned_nodes;
|
2017-01-17 14:13:01 +00:00
|
|
|
int num_bvh_time_steps;
|
2011-04-27 11:58:34 +00:00
|
|
|
bool use_qbvh;
|
2013-02-14 16:48:43 +00:00
|
|
|
bool persistent_data;
|
2016-11-17 11:13:22 +00:00
|
|
|
int texture_limit;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
SceneParams()
|
|
|
|
{
|
2014-05-19 10:49:36 +00:00
|
|
|
shadingsystem = SHADINGSYSTEM_SVM;
|
2011-04-27 11:58:34 +00:00
|
|
|
bvh_type = BVH_DYNAMIC;
|
|
|
|
use_bvh_spatial_split = false;
|
2016-07-07 16:04:16 +00:00
|
|
|
use_bvh_unaligned_nodes = true;
|
2017-01-17 14:13:01 +00:00
|
|
|
num_bvh_time_steps = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
use_qbvh = false;
|
2013-09-03 22:39:21 +00:00
|
|
|
persistent_data = false;
|
2016-11-17 11:13:22 +00:00
|
|
|
texture_limit = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool modified(const SceneParams& params)
|
|
|
|
{ return !(shadingsystem == params.shadingsystem
|
|
|
|
&& bvh_type == params.bvh_type
|
|
|
|
&& use_bvh_spatial_split == params.use_bvh_spatial_split
|
2016-07-07 16:04:16 +00:00
|
|
|
&& use_bvh_unaligned_nodes == params.use_bvh_unaligned_nodes
|
2017-01-17 14:13:01 +00:00
|
|
|
&& num_bvh_time_steps == params.num_bvh_time_steps
|
2012-11-09 08:46:53 +00:00
|
|
|
&& use_qbvh == params.use_qbvh
|
2016-11-17 11:13:22 +00:00
|
|
|
&& persistent_data == params.persistent_data
|
|
|
|
&& texture_limit == params.texture_limit); }
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Scene */
|
|
|
|
|
|
|
|
class Scene {
|
|
|
|
public:
|
|
|
|
/* data */
|
|
|
|
Camera *camera;
|
2013-04-01 20:26:43 +00:00
|
|
|
LookupTables *lookup_tables;
|
2011-04-27 11:58:34 +00:00
|
|
|
Film *film;
|
|
|
|
Background *background;
|
|
|
|
Integrator *integrator;
|
|
|
|
|
|
|
|
/* data lists */
|
|
|
|
vector<Object*> objects;
|
|
|
|
vector<Mesh*> meshes;
|
|
|
|
vector<Shader*> shaders;
|
|
|
|
vector<Light*> lights;
|
2012-08-31 17:27:08 +00:00
|
|
|
vector<ParticleSystem*> particle_systems;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* data managers */
|
|
|
|
ImageManager *image_manager;
|
|
|
|
LightManager *light_manager;
|
|
|
|
ShaderManager *shader_manager;
|
|
|
|
MeshManager *mesh_manager;
|
|
|
|
ObjectManager *object_manager;
|
2012-08-31 17:27:08 +00:00
|
|
|
ParticleSystemManager *particle_system_manager;
|
2012-12-28 14:21:30 +00:00
|
|
|
CurveSystemManager *curve_system_manager;
|
2014-01-02 21:05:07 +00:00
|
|
|
BakeManager *bake_manager;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* default shaders */
|
2016-05-14 12:50:03 +00:00
|
|
|
Shader *default_surface;
|
|
|
|
Shader *default_light;
|
|
|
|
Shader *default_background;
|
|
|
|
Shader *default_empty;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* device */
|
|
|
|
Device *device;
|
|
|
|
DeviceScene dscene;
|
|
|
|
|
|
|
|
/* parameters */
|
|
|
|
SceneParams params;
|
|
|
|
|
|
|
|
/* mutex must be locked manually by callers */
|
|
|
|
thread_mutex mutex;
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
Scene(const SceneParams& params, const DeviceInfo& device_info);
|
2011-04-27 11:58:34 +00:00
|
|
|
~Scene();
|
|
|
|
|
|
|
|
void device_update(Device *device, Progress& progress);
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
bool need_global_attribute(AttributeStandard std);
|
|
|
|
void need_global_attributes(AttributeRequestSet& attributes);
|
|
|
|
|
|
|
|
enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
|
2012-10-15 21:12:58 +00:00
|
|
|
MotionType need_motion(bool advanced_shading = true);
|
2016-07-16 16:56:59 +00:00
|
|
|
float motion_shutter_time();
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool need_update();
|
|
|
|
bool need_reset();
|
2012-11-09 08:46:53 +00:00
|
|
|
|
|
|
|
void reset();
|
|
|
|
void device_free();
|
|
|
|
|
|
|
|
protected:
|
2016-04-22 08:55:26 +00:00
|
|
|
/* Check if some heavy data worth logging was updated.
|
|
|
|
* Mainly used to suppress extra annoying logging.
|
|
|
|
*/
|
|
|
|
bool need_data_update();
|
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
void free_memory(bool final);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __SCENE_H__ */
|
|
|
|
|