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@gmail.com>2019-05-02 13:40:24 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-03 16:36:20 +0300
commitfadb6f34662fb60e1a48c2c053c500f017206f27 (patch)
tree48c16c2215e7110e00b4255f6230aa3491d94ee0 /intern/cycles/kernel/osl/osl_globals.h
parent08a44d29815f6b0b9b675a503829d2e2ce7f6426 (diff)
Cleanup: refactor Cycles OSL texture handling
This adds our own OSL texture handle, that has info for OIIO textures or our own custom texture types. A filename to handle hash map is used for lookups. This is efficient because it happens at OSL compile time, because the optimizer can figure out constant strings and replace them with texture handles.
Diffstat (limited to 'intern/cycles/kernel/osl/osl_globals.h')
-rw-r--r--intern/cycles/kernel/osl/osl_globals.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/intern/cycles/kernel/osl/osl_globals.h b/intern/cycles/kernel/osl/osl_globals.h
index 641c9967586..414aaf891db 100644
--- a/intern/cycles/kernel/osl/osl_globals.h
+++ b/intern/cycles/kernel/osl/osl_globals.h
@@ -21,10 +21,14 @@
# include <OSL/oslexec.h>
+# include <OpenImageIO/refcnt.h>
+# include <OpenImageIO/unordered_map_concurrent.h>
+
# include "util/util_map.h"
# include "util/util_param.h"
# include "util/util_thread.h"
# include "util/util_vector.h"
+# include "util/util_unique_ptr.h"
# ifndef WIN32
using std::isfinite;
@@ -34,6 +38,48 @@ CCL_NAMESPACE_BEGIN
class OSLRenderServices;
+/* OSL Texture Handle
+ *
+ * OSL texture lookups are string based. If those strings are known at compile
+ * time, the OSL compiler can cache a texture handle to use instead of a string.
+ *
+ * By default it uses TextureSystem::TextureHandle. But since we want to support
+ * different kinds of textures and color space conversions, this is our own handle
+ * with additional data.
+ *
+ * These are stored in a concurrent hash map, because OSL can compile multiple
+ * shaders in parallel. */
+
+struct OSLTextureHandle : public OIIO::RefCnt {
+ enum Type { OIIO, SVM, IES, BEVEL, AO };
+
+ OSLTextureHandle() : type(OIIO), svm_slot(-1), oiio_handle(NULL)
+ {
+ }
+
+ OSLTextureHandle(Type type) : type(type), svm_slot(-1), oiio_handle(NULL)
+ {
+ }
+
+ OSLTextureHandle(Type type, int svm_slot) : type(type), svm_slot(svm_slot), oiio_handle(NULL)
+ {
+ }
+
+ Type type;
+ int svm_slot;
+ OSL::TextureSystem::TextureHandle *oiio_handle;
+};
+
+typedef OIIO::intrusive_ptr<OSLTextureHandle> OSLTextureHandleRef;
+typedef OIIO::unordered_map_concurrent<ustring, OSLTextureHandleRef, ustringHash>
+ OSLTextureHandleMap;
+
+/* OSL Globals
+ *
+ * Data needed by OSL render services, that is global to a rendering session.
+ * This includes all OSL shaders, name to attribute mapping and texture handles.
+ * */
+
struct OSLGlobals {
OSLGlobals()
{
@@ -70,6 +116,9 @@ struct OSLGlobals {
vector<AttributeMap> attribute_map;
ObjectNameMap object_name_map;
vector<ustring> object_names;
+
+ /* textures */
+ OSLTextureHandleMap textures;
};
/* trace() call result */