From fadb6f34662fb60e1a48c2c053c500f017206f27 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 2 May 2019 12:40:24 +0200 Subject: 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. --- intern/cycles/kernel/osl/osl_globals.h | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'intern/cycles/kernel/osl/osl_globals.h') 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 +# include +# include + # 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 OSLTextureHandleRef; +typedef OIIO::unordered_map_concurrent + 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 attribute_map; ObjectNameMap object_name_map; vector object_names; + + /* textures */ + OSLTextureHandleMap textures; }; /* trace() call result */ -- cgit v1.2.3