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:
authorTon Roosendaal <ton@blender.org>2011-04-27 15:58:34 +0400
committerTon Roosendaal <ton@blender.org>2011-04-27 15:58:34 +0400
commitda376e0237517543aa21740ee2363234ee1c20ae (patch)
tree014a513ed8d0eccc5e54fef42347781e85bae56a /intern/cycles/util/util_cache.h
parent693780074388111e7b9ef1c3825e462f398dc6c4 (diff)
Cycles render engine, initial commit. This is the engine itself, blender modifications and build instructions will follow later.
Cycles uses code from some great open source projects, many thanks them: * BVH building and traversal code from NVidia's "Understanding the Efficiency of Ray Traversal on GPUs": http://code.google.com/p/understanding-the-efficiency-of-ray-traversal-on-gpus/ * Open Shading Language for a large part of the shading system: http://code.google.com/p/openshadinglanguage/ * Blender for procedural textures and a few other nodes. * Approximate Catmull Clark subdivision from NVidia Mesh tools: http://code.google.com/p/nvidia-mesh-tools/ * Sobol direction vectors from: http://web.maths.unsw.edu.au/~fkuo/sobol/ * Film response functions from: http://www.cs.columbia.edu/CAVE/software/softlib/dorf.php
Diffstat (limited to 'intern/cycles/util/util_cache.h')
-rw-r--r--intern/cycles/util/util_cache.h132
1 files changed, 132 insertions, 0 deletions
diff --git a/intern/cycles/util/util_cache.h b/intern/cycles/util/util_cache.h
new file mode 100644
index 00000000000..25b1f2e7a51
--- /dev/null
+++ b/intern/cycles/util/util_cache.h
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+
+#ifndef __UTIL_CACHE_H__
+#define __UTIL_CACHE_H__
+
+/* Disk Cache based on Hashing
+ *
+ * To be used to cache expensive computations. The hash key is created from an
+ * arbitrary number of bytes, by hashing the bytes using MD5, which then gives
+ * the file name containing the data. This data then is read from the file
+ * again into the appropriate data structures.
+ *
+ * This way we do not need to accurately track changes, compare dates and
+ * invalidate cache entries, at the cost of exta computation. If everything
+ * is stored in a global cache, computations can perhaps even be shared between
+ * different scenes where it may be hard to detect duplicate work.
+ */
+
+#include "util_string.h"
+#include "util_vector.h"
+
+CCL_NAMESPACE_BEGIN
+
+class CacheBuffer {
+public:
+ const void *data;
+ size_t size;
+
+ CacheBuffer(const void *data_, size_t size_)
+ { data = data_; size = size_; }
+};
+
+class CacheData {
+public:
+ vector<CacheBuffer> buffers;
+ string name;
+ FILE *f;
+
+ CacheData(const string& name = "");
+ ~CacheData();
+
+ template<typename T> void add(const vector<T>& data)
+ {
+ CacheBuffer buffer(&data[0], data.size()*sizeof(T));
+ buffers.push_back(buffer);
+ }
+
+ template<typename T> void add(const array<T>& data)
+ {
+ CacheBuffer buffer(&data[0], data.size()*sizeof(T));
+ buffers.push_back(buffer);
+ }
+
+ void add(void *data, size_t size)
+ {
+ CacheBuffer buffer(data, size);
+ buffers.push_back(buffer);
+ }
+
+ void add(int& data)
+ {
+ CacheBuffer buffer(&data, sizeof(int));
+ buffers.push_back(buffer);
+ }
+
+ void add(size_t& data)
+ {
+ CacheBuffer buffer(&data, sizeof(size_t));
+ buffers.push_back(buffer);
+ }
+
+ template<typename T> void read(array<T>& data)
+ {
+ size_t size;
+
+ if(!fread(&size, sizeof(size), 1, f)) {
+ fprintf(stderr, "Failed to read vector size from cache.\n");
+ return;
+ }
+
+ data.resize(size/sizeof(T));
+
+ if(!fread(&data[0], size, 1, f)) {
+ fprintf(stderr, "Failed to read vector data from cache (%ld).\n", size);
+ return;
+ }
+ }
+
+ void read(int& data)
+ {
+ if(!fread(&data, sizeof(data), 1, f))
+ fprintf(stderr, "Failed to read int from cache.\n");
+ }
+
+ void read(size_t& data)
+ {
+ if(!fread(&data, sizeof(data), 1, f))
+ fprintf(stderr, "Failed to read size_t from cache.\n");
+ }
+};
+
+class Cache {
+public:
+ static Cache global;
+
+ void insert(const CacheData& key, const CacheData& value);
+ bool lookup(const CacheData& key, CacheData& value);
+
+protected:
+ string data_filename(const CacheData& key);
+};
+
+CCL_NAMESPACE_END
+
+#endif /* __UTIL_CACHE_H__ */
+