Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-01-16 17:13:37 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-01-16 17:13:37 +0400
commit92764260d7050800572c9d5b8a80f954572e9a0f (patch)
treefe2f6821b5dd93e0cb49cc2ae1f78c4e04235df6 /intern/cycles/bvh
parent3123ad12a395031a1bf5a964582762a3831e9b1c (diff)
Cycles: add option to cache BVH's between subsequent renders, storing the BVH on
disk to be reused by the next render. This is useful for rendering animations where only the camera or materials change. Note that saving the BVH to disk only to be removed for the next frame is slower if this is not the case and the meshes do actually change. For a render, it will save bvh files to the cache user directory, and remove all cache files from other renders. The files are named using a MD5 hash based on the mesh, to verify if the meshes are still the same.
Diffstat (limited to 'intern/cycles/bvh')
-rw-r--r--intern/cycles/bvh/bvh.cpp31
-rw-r--r--intern/cycles/bvh/bvh.h4
-rw-r--r--intern/cycles/bvh/bvh_params.h11
3 files changed, 42 insertions, 4 deletions
diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp
index cd3ad709812..c9bfa964332 100644
--- a/intern/cycles/bvh/bvh.cpp
+++ b/intern/cycles/bvh/bvh.cpp
@@ -75,12 +75,18 @@ bool BVH::cache_read(CacheData& key)
foreach(Object *ob, objects) {
key.add(ob->mesh->verts);
key.add(ob->mesh->triangles);
+ key.add(&ob->bounds, sizeof(ob->bounds));
+ key.add(&ob->visibility, sizeof(ob->visibility));
+ key.add(&ob->mesh->transform_applied, sizeof(bool));
}
CacheData value;
if(Cache::global.lookup(key, value)) {
+ cache_filename = key.get_filename();
+
value.read(pack.root_index);
+ value.read(pack.SAH);
value.read(pack.nodes);
value.read(pack.object_node);
@@ -101,6 +107,7 @@ void BVH::cache_write(CacheData& key)
CacheData value;
value.add(pack.root_index);
+ value.add(pack.SAH);
value.add(pack.nodes);
value.add(pack.object_node);
@@ -111,6 +118,26 @@ void BVH::cache_write(CacheData& key)
value.add(pack.is_leaf);
Cache::global.insert(key, value);
+
+ cache_filename = key.get_filename();
+}
+
+void BVH::clear_cache_except()
+{
+ set<string> except;
+
+ if(!cache_filename.empty())
+ except.insert(cache_filename);
+
+ foreach(Object *ob, objects) {
+ Mesh *mesh = ob->mesh;
+ BVH *bvh = mesh->bvh;
+
+ if(bvh && !bvh->cache_filename.empty())
+ except.insert(bvh->cache_filename);
+ }
+
+ Cache::global.clear_except("bvh", except);
}
/* Building */
@@ -177,6 +204,10 @@ void BVH::build(Progress& progress)
if(params.use_cache) {
progress.set_substatus("Writing BVH cache");
cache_write(key);
+
+ /* clear other bvh files from cache */
+ if(params.top_level)
+ clear_cache_except();
}
}
diff --git a/intern/cycles/bvh/bvh.h b/intern/cycles/bvh/bvh.h
index e502af72335..30ae7dac106 100644
--- a/intern/cycles/bvh/bvh.h
+++ b/intern/cycles/bvh/bvh.h
@@ -20,6 +20,7 @@
#include "bvh_params.h"
+#include "util_string.h"
#include "util_types.h"
#include "util_vector.h"
@@ -83,6 +84,7 @@ public:
PackedBVH pack;
BVHParams params;
vector<Object*> objects;
+ string cache_filename;
static BVH *create(const BVHParams& params, const vector<Object*>& objects);
virtual ~BVH() {}
@@ -90,6 +92,8 @@ public:
void build(Progress& progress);
void refit(Progress& progress);
+ void clear_cache_except();
+
protected:
BVH(const BVHParams& params, const vector<Object*>& objects);
diff --git a/intern/cycles/bvh/bvh_params.h b/intern/cycles/bvh/bvh_params.h
index b38e40cfbda..38093438500 100644
--- a/intern/cycles/bvh/bvh_params.h
+++ b/intern/cycles/bvh/bvh_params.h
@@ -26,7 +26,7 @@ class BVHParams
{
public:
/* spatial split area threshold */
- bool use_spatial_split;
+ int use_spatial_split;
float spatial_split_alpha;
/* SAH costs */
@@ -38,13 +38,15 @@ public:
int max_leaf_size;
/* object or mesh level bvh */
- bool top_level;
+ int top_level;
/* disk cache */
- bool use_cache;
+ int use_cache;
/* QBVH */
- bool use_qbvh;
+ int use_qbvh;
+
+ int pad;
/* fixed parameters */
enum {
@@ -67,6 +69,7 @@ public:
top_level = false;
use_cache = false;
use_qbvh = false;
+ pad = false;
}
/* SAH costs */