From 66747ac1e65ff8425e73771dee754df308b10e37 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Tue, 11 Oct 2022 15:54:23 -0700 Subject: [PATCH] Move string representation entirely to ustringhash -- phase I (#1603) The first step of the great ustringhash conversion: This changes all RendererServices methods (i.e., callbacks to the renderer from the shader JITed code) that used to take ustring parameters, switched to take ustringhash instead. The second step -- which I will tackle after this part is merged -- will be to fully switch the in-memory representation of strings during shading execution to ustringhash on the CPU (thus matching how we've been doing it on GPU and making a number of data stuctures and representations identical/shared for CPU and GPU). But in the mean time, this lets renderers get started changing their RendererServices specializations. Just like with OSL's internal implementation, it may be easier for renderers to break the job into phase I (rendererservices) and phase II (in-memory rep). Some notes and guideposts: * In oslconfig.h, define ustringrep to alias to either ustring or ustringhash, depending on a new (but temporary) CMake variable `OSL_USTRINGREP_IS_HASH`, which is OFF for now, meaning that ustringrep is still ustring. * Also in oslconfig.h, several helper conversion functions among ustring, ustringhash, ustringrip. * RendererServices and BatchedRendererServices (and their various subclasses in testshade and testrender): change the method signatures from ustring to ustringhash for all methods that are reachable from shader code. Signed-off-by: Larry Gritz --- CMakeLists.txt | 3 +- src/include/OSL/batched_rendererservices.h | 67 ++--- src/include/OSL/oslconfig.h.in | 50 ++++ src/include/OSL/rendererservices.h | 241 +++++++++--------- src/include/OSL/wide.h | 59 +++++ src/liboslexec/batched_rendservices.cpp | 43 ++-- src/liboslexec/constfold.cpp | 5 +- src/liboslexec/optexture.cpp | 63 +++-- src/liboslexec/pointcloud.cpp | 59 +++-- src/liboslexec/pointcloud.h | 8 +- src/liboslexec/rendservices.cpp | 145 ++++++++--- src/liboslexec/wide/wide_opmatrix.cpp | 122 ++++++--- src/liboslexec/wide/wide_oppointcloud.cpp | 32 +-- src/testrender/optixraytracer.cpp | 10 +- src/testrender/optixraytracer.h | 28 +- src/testrender/simpleraytracer.cpp | 66 ++--- src/testrender/simpleraytracer.h | 96 +++---- src/testshade/batched_simplerend.cpp | 101 ++++---- src/testshade/batched_simplerend.h | 81 +++--- src/testshade/optixgridrender.cpp | 10 +- src/testshade/optixgridrender.h | 30 +-- src/testshade/simplerend.cpp | 75 +++--- src/testshade/simplerend.h | 113 ++++---- testsuite/example-cuda/cuda_grid_renderer.cpp | 16 +- testsuite/example-cuda/cuda_grid_renderer.h | 36 ++- 25 files changed, 938 insertions(+), 621 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf5fbb7f0..1c656f729 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required (VERSION 3.12) -set (OSL_VERSION "1.13.1.0" CACHE STRING "Version") +set (OSL_VERSION "1.13.2.0" CACHE STRING "Version") project (OSL VERSION ${OSL_VERSION} LANGUAGES CXX C HOMEPAGE_URL "https://github.com/AcademySoftwareFoundation/OpenShadingLanguage") @@ -100,6 +100,7 @@ set (OSL_SHADER_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/shade set (OSL_PTX_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/ptx" CACHE STRING "Directory where OptiX PTX files will be installed") set (CMAKE_DEBUG_POSTFIX "" CACHE STRING "Library naming postfix for Debug builds (e.g., '_debug')") +option (OSL_USTRINGREP_IS_HASH "Always use ustringhash for strings" OFF) set (OSL_NO_DEFAULT_TEXTURESYSTEM OFF CACHE BOOL "Do not use create a raw OIIO::TextureSystem") diff --git a/src/include/OSL/batched_rendererservices.h b/src/include/OSL/batched_rendererservices.h index d78ac7412..760e5605e 100644 --- a/src/include/OSL/batched_rendererservices.h +++ b/src/include/OSL/batched_rendererservices.h @@ -82,12 +82,13 @@ template class OSLEXECPUBLIC BatchedRendererServices { /// Return a Mask with lanes set to true if ok, false if the named matrix /// is not known. virtual Mask get_matrix(BatchedShaderGlobals* bsg, Masked wresult, - ustring from, Wide wtime) + ustringhash from, Wide wtime) { return Mask(false); } virtual Mask get_matrix(BatchedShaderGlobals* bsg, Masked result, - Wide wfrom, Wide wtime); + Wide wfrom, + Wide wtime); virtual bool is_overridden_get_matrix_WmWsWf() const = 0; @@ -97,12 +98,12 @@ template class OSLEXECPUBLIC BatchedRendererServices { /// particular renderer may have a better technique and overload the /// implementation. virtual Mask get_inverse_matrix(BatchedShaderGlobals* bsg, - Masked wresult, ustring to, + Masked wresult, ustringhash to, Wide wtime); virtual bool is_overridden_get_inverse_matrix_WmsWf() const = 0; virtual Mask get_inverse_matrix(BatchedShaderGlobals* bsg, Masked wresult, - Wide wto, + Wide wto, Wide wtime); virtual bool is_overridden_get_inverse_matrix_WmWsWf() const = 0; @@ -124,22 +125,23 @@ template class OSLEXECPUBLIC BatchedRendererServices { /// specified (object == ustring()), then the renderer should search *first* /// for the attribute on the currently shaded object, and next, if /// unsuccessful, on the currently shaded "scene". - virtual Mask get_attribute(BatchedShaderGlobals* bsg, ustring object, - ustring name, MaskedData wval) + virtual Mask get_attribute(BatchedShaderGlobals* bsg, ustringhash object, + ustringhash name, MaskedData wval) { return Mask(false); } /// Similar to get_attribute(); this method will fetch the 'index' /// element of an attribute array. - virtual Mask get_array_attribute(BatchedShaderGlobals* bsg, ustring object, - ustring name, int index, MaskedData wval) + virtual Mask get_array_attribute(BatchedShaderGlobals* bsg, + ustringhash object, ustringhash name, + int index, MaskedData wval) { return Mask(false); } virtual bool get_attribute_uniform(BatchedShaderGlobals* bsg, - ustring object, ustring name, + ustringhash object, ustringhash name, RefData val) { return false; @@ -148,8 +150,9 @@ template class OSLEXECPUBLIC BatchedRendererServices { /// Similar to get_attribute(); this method will fetch the 'index' /// element of an attribute array. virtual bool get_array_attribute_uniform(BatchedShaderGlobals* bsg, - ustring object, ustring name, - int index, RefData val) + ustringhash object, + ustringhash name, int index, + RefData val) { return false; } @@ -159,7 +162,7 @@ template class OSLEXECPUBLIC BatchedRendererServices { /// as well. It is assumed the results are varying and returns Mask // with its bit set to off if no user-data with the given name and type was /// found. - virtual Mask get_userdata(ustring name, BatchedShaderGlobals* bsg, + virtual Mask get_userdata(ustringhash name, BatchedShaderGlobals* bsg, MaskedData wval) { return Mask(false); @@ -206,7 +209,7 @@ template class OSLEXECPUBLIC BatchedRendererServices { /// error. /// virtual Mask - texture(ustring filename, TextureSystem::TextureHandle* texture_handle, + texture(ustringhash filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, BatchedShaderGlobals* bsg, Wide ws, Wide wt, Wide wdsdx, @@ -240,7 +243,7 @@ template class OSLEXECPUBLIC BatchedRendererServices { /// messages (in case of failure, when the function returns false) will /// be stored there, leaving it up to the caller/shader to handle the /// error. - virtual Mask texture3d(ustring filename, + virtual Mask texture3d(ustringhash filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, @@ -273,7 +276,7 @@ template class OSLEXECPUBLIC BatchedRendererServices { /// messages (in case of failure, when the function returns false) will /// be stored there, leaving it up to the caller/shader to handle the /// error. - virtual Mask environment(ustring filename, + virtual Mask environment(ustringhash filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, @@ -300,12 +303,12 @@ template class OSLEXECPUBLIC BatchedRendererServices { virtual TextureSystem::TextureHandle* resolve_udim_uniform( BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info, - ustring filename, TextureSystem::TextureHandle* texture_handle, float S, - float T); + ustringhash filename, TextureSystem::TextureHandle* texture_handle, + float S, float T); virtual void resolve_udim(BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info, - ustring filename, + ustringhash filename, TextureSystem::TextureHandle* texture_handle, Wide wS, Wide wT, Masked wresult); @@ -313,8 +316,8 @@ template class OSLEXECPUBLIC BatchedRendererServices { // Assumes any UDIM has been resolved already virtual bool get_texture_info_uniform( BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info, - ustring filename, TextureSystem::TextureHandle* texture_handle, - int subimage, ustring dataname, RefData val); + ustringhash filename, TextureSystem::TextureHandle* texture_handle, + int subimage, ustringhash dataname, RefData val); /// Lookup nearest points in a point cloud. It will search for @@ -407,26 +410,25 @@ template class OSLEXECPUBLIC BatchedRendererServices { }; - virtual void pointcloud_search(BatchedShaderGlobals* bsg, ustring filename, - const void* wcenter, + virtual void pointcloud_search(BatchedShaderGlobals* bsg, + ustringhash filename, const void* wcenter, Wide wradius, int max_points, bool sort, PointCloudSearchResults& results); virtual bool is_overridden_pointcloud_search() const = 0; - virtual Mask pointcloud_get(BatchedShaderGlobals* bsg, ustring filename, + virtual Mask pointcloud_get(BatchedShaderGlobals* bsg, ustringhash filename, Wide windices, - Wide wnum_points, ustring attr_name, - MaskedData wout_data); + Wide wnum_points, + ustringhash attr_name, MaskedData wout_data); virtual bool is_overridden_pointcloud_get() const = 0; - virtual Mask pointcloud_write(BatchedShaderGlobals* bsg, ustring filename, - Wide wpos, int nattribs, - const ustring* attr_names, - const TypeDesc* attr_types, - const void** pointers_to_wide_attr_value, - Mask mask); + virtual Mask + pointcloud_write(BatchedShaderGlobals* bsg, ustringhash filename, + Wide wpos, int nattribs, + const ustring* attr_names, const TypeDesc* attr_types, + const void** pointers_to_wide_attr_value, Mask mask); virtual bool is_overridden_pointcloud_write() const = 0; /// Options for the trace call. @@ -441,7 +443,8 @@ template class OSLEXECPUBLIC BatchedRendererServices { Wide wdRdy); virtual void getmessage(BatchedShaderGlobals* bsg, Masked wresult, - ustring source, ustring name, MaskedData wval); + ustringhash source, ustringhash name, + MaskedData wval); // pointcloud_search is T.B.D. diff --git a/src/include/OSL/oslconfig.h.in b/src/include/OSL/oslconfig.h.in index 64b070f92..efec1141c 100644 --- a/src/include/OSL/oslconfig.h.in +++ b/src/include/OSL/oslconfig.h.in @@ -133,6 +133,56 @@ fmtformat(const Str& fmt, Args&&... args) +/// OSL_USTRINGREP_IS_HASH will be 1 if the build-time option was enabled to +/// make the ustringrep be a ustringhash, rather than a ustring directly. +#cmakedefine01 OSL_USTRINGREP_IS_HASH + +#if OSL_USTRINGREP_IS_HASH +using ustringrep = ustringhash; +#else +using ustringrep = ustring; +#endif + + +/// Convenience function to convert to a ustring. +inline ustring +ustring_from(ustringhash h) +{ + return ustring::from_hash(h.hash()); +} + +/// Convenience function to convert to a ustring. +inline ustring +ustring_from(ustring u) +{ + return u; +} + + +/// Convenience function to convert to a ustringrep. +inline ustringrep +ustringrep_from(ustringhash h) +{ +#if OSL_USTRINGREP_IS_HASH + return h; +#else + return ustring::from_hash(h.hash()); +#endif +} + +/// Convenience function to convert to a ustringrep. +inline ustringrep +ustringrep_from(ustring u) +{ +#if OSL_USTRINGREP_IS_HASH + return u.hash(); +#else + return u; +#endif +} + + + // N.B. SymArena is not really "configuration", but we cram it here for // lack of a better home. diff --git a/src/include/OSL/rendererservices.h b/src/include/OSL/rendererservices.h index eee624432..6b8b441db 100644 --- a/src/include/OSL/rendererservices.h +++ b/src/include/OSL/rendererservices.h @@ -2,8 +2,6 @@ // SPDX-License-Identifier: BSD-3-Clause // https://github.com/AcademySoftwareFoundation/OpenShadingLanguage -// clang-format off - #pragma once @@ -13,14 +11,13 @@ OSL_NAMESPACE_ENTER class RendererServices; -template -class BatchedRendererServices; +template class BatchedRendererServices; class ShadingContext; struct ShaderGlobals; // Tags for polymorphic dispatch -template -class WidthOf {}; +template class WidthOf { +}; /// Opaque pointer to whatever the renderer uses to represent a @@ -49,7 +46,7 @@ class OSLEXECPUBLIC RendererServices { RendererServices(TextureSystem* texsys = NULL); - virtual ~RendererServices () { } + virtual ~RendererServices() {} /// Given the name of a 'feature', return whether this RendererServices /// supports it. Feature names include: @@ -62,28 +59,34 @@ class OSLEXECPUBLIC RendererServices { /// support it, as long as the OSL runtime only uses that feature if the /// supports("feature") says it's present, thus preserving source /// compatibility. - virtual int supports (string_view feature) const { return false; } + virtual int supports(string_view feature) const { return false; } /// Get the 4x4 matrix that transforms by the specified /// transformation at the given time. Return true if ok, false /// on error. - virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result, - TransformationPtr xform, float time) { return false; } + virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform, float time) + { + return false; + } /// Get the 4x4 matrix that transforms by the specified /// transformation at the given time. Return true if ok, false on /// error. The default implementation is to use get_matrix and /// invert it, but a particular renderer may have a better technique /// and overload the implementation. - virtual bool get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result, - TransformationPtr xform, float time); + virtual bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform, float time); /// Get the 4x4 matrix that transforms by the specified /// transformation. Return true if ok, false on error. Since no /// time value is given, also return false if the transformation may /// be time-varying. - virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result, - TransformationPtr xform) { return false; } + virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform) + { + return false; + } /// Get the 4x4 matrix that transforms by the specified /// transformation. Return true if ok, false on error. Since no @@ -91,29 +94,29 @@ class OSLEXECPUBLIC RendererServices { /// be time-varying. The default implementation is to use /// get_matrix and invert it, but a particular renderer may have a /// better technique and overload the implementation. - virtual bool get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result, - TransformationPtr xform); + virtual bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform); /// Get the 4x4 matrix that transforms points from the named /// 'from' coordinate system to "common" space at the given time. /// Returns true if ok, false if the named matrix is not known. - virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result, - ustring from, float time) { return false; } + virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash from, float time); /// Get the 4x4 matrix that transforms points from "common" space to /// the named 'to' coordinate system to at the given time. The /// default implementation is to use get_matrix and invert it, but a /// particular renderer may have a better technique and overload the /// implementation. - virtual bool get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result, - ustring to, float time); + virtual bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash to, float time); /// Get the 4x4 matrix that transforms 'from' to "common" space. /// Since there is no time value passed, return false if the /// transformation may be time-varying (as well as if it's not found /// at all). - virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result, - ustring from) { return false; } + virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash from); /// Get the 4x4 matrix that transforms points from "common" space to /// the named 'to' coordinate system. Since there is no time value @@ -122,8 +125,8 @@ class OSLEXECPUBLIC RendererServices { /// implementation is to use get_matrix and invert it, but a /// particular renderer may have a better technique and overload the /// implementation. - virtual bool get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result, - ustring to); + virtual bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash to); /// Transform points Pin[0..npoints-1] in named coordinate system /// 'from' into 'to' coordinates, storing the result in Pout[] using @@ -148,11 +151,10 @@ class OSLEXECPUBLIC RendererServices { /// Note to RendererServices implementations: just return 'false' /// if there isn't a special nonlinear transformation between the /// two spaces. - virtual bool transform_points (ShaderGlobals *sg, - ustring from, ustring to, float time, - const Vec3 *Pin, Vec3 *Pout, int npoints, - TypeDesc::VECSEMANTICS vectype) - { return false; } + virtual bool transform_points(ShaderGlobals* sg, ustringhash from, + ustringhash to, float time, const Vec3* Pin, + Vec3* Pout, int npoints, + TypeDesc::VECSEMANTICS vectype); /// Get the named attribute from the renderer and if found then @@ -167,36 +169,36 @@ class OSLEXECPUBLIC RendererServices { /// run on. Be robust to this situation, return 'true' (retrieve the /// attribute) if you can (known object and attribute name), but /// otherwise just fail by returning 'false'. - virtual bool get_attribute (ShaderGlobals *sg, bool derivatives, - ustring object, TypeDesc type, ustring name, - void *val) { return false; } + virtual bool get_attribute(ShaderGlobals* sg, bool derivatives, + ustringhash object, TypeDesc type, + ustringhash name, void* val); /// Similar to get_attribute(); this method will return the 'index' /// element of an attribute array. - virtual bool get_array_attribute (ShaderGlobals *sg, bool derivatives, - ustring object, TypeDesc type, - ustring name, int index, void *val) { return false; } + virtual bool get_array_attribute(ShaderGlobals* sg, bool derivatives, + ustringhash object, TypeDesc type, + ustringhash name, int index, void* val); /// Get the named user-data from the current object and write it into /// 'val'. If derivatives is true, the derivatives should be written into val /// as well. Return false if no user-data with the given name and type was /// found. - virtual bool get_userdata (bool derivatives, ustring name, TypeDesc type, - ShaderGlobals *sg, void *val) { return false; } + virtual bool get_userdata(bool derivatives, ustringhash name, TypeDesc type, + ShaderGlobals* sg, void* val); /// Given the name of a texture, return an opaque handle that can be /// used with texture calls to avoid the name lookups. - virtual TextureHandle * get_texture_handle (ustring filename, - ShadingContext *context); + virtual TextureHandle* get_texture_handle(ustringhash filename, + ShadingContext* context); /// Return true if the texture handle (previously returned by /// get_texture_handle()) is a valid texture that can be subsequently /// read or sampled. - virtual bool good (TextureHandle *texture_handle); + virtual bool good(TextureHandle* texture_handle); /// Return true if the texture handle (previously returned by /// get_texture_handle()) is udim - virtual bool is_udim (TextureHandle *texture_handle); + virtual bool is_udim(TextureHandle* texture_handle); /// Filtered 2D texture lookup for a single point. /// @@ -224,13 +226,13 @@ class OSLEXECPUBLIC RendererServices { /// messages (in case of failure, when the function returns false) will /// be stored there, leaving it up to the caller/shader to handle the /// error. - virtual bool texture (ustring filename, TextureHandle *texture_handle, - TexturePerthread *texture_thread_info, - TextureOpt &options, ShaderGlobals *sg, - float s, float t, float dsdx, float dtdx, - float dsdy, float dtdy, int nchannels, - float *result, float *dresultds, float *dresultdt, - ustring *errormessage); + virtual bool texture(ustringhash filename, TextureHandle* texture_handle, + TexturePerthread* texture_thread_info, + TextureOpt& options, ShaderGlobals* sg, float s, + float t, float dsdx, float dtdx, float dsdy, + float dtdy, int nchannels, float* result, + float* dresultds, float* dresultdt, + ustringhash* errormessage); /// Filtered 3D texture lookup for a single point. /// @@ -257,14 +259,13 @@ class OSLEXECPUBLIC RendererServices { /// messages (in case of failure, when the function returns false) will /// be stored there, leaving it up to the caller/shader to handle the /// error. - virtual bool texture3d (ustring filename, TextureHandle *texture_handle, - TexturePerthread *texture_thread_info, - TextureOpt &options, ShaderGlobals *sg, - const Vec3 &P, const Vec3 &dPdx, const Vec3 &dPdy, - const Vec3 &dPdz, int nchannels, - float *result, float *dresultds, - float *dresultdt, float *dresultdr, - ustring *errormessage); + virtual bool texture3d(ustringhash filename, TextureHandle* texture_handle, + TexturePerthread* texture_thread_info, + TextureOpt& options, ShaderGlobals* sg, + const Vec3& P, const Vec3& dPdx, const Vec3& dPdy, + const Vec3& dPdz, int nchannels, float* result, + float* dresultds, float* dresultdt, float* dresultdr, + ustringhash* errormessage); /// Filtered environment lookup for a single point. /// @@ -288,13 +289,13 @@ class OSLEXECPUBLIC RendererServices { /// messages (in case of failure, when the function returns false) will /// be stored there, leaving it up to the caller/shader to handle the /// error. - virtual bool environment (ustring filename, TextureHandle *texture_handle, - TexturePerthread *texture_thread_info, - TextureOpt &options, ShaderGlobals *sg, - const Vec3 &R, const Vec3 &dRdx, const Vec3 &dRdy, - int nchannels, float *result, - float *dresultds, float *dresultdt, - ustring *errormessage); + virtual bool environment(ustringhash filename, + TextureHandle* texture_handle, + TexturePerthread* texture_thread_info, + TextureOpt& options, ShaderGlobals* sg, + const Vec3& R, const Vec3& dRdx, const Vec3& dRdy, + int nchannels, float* result, float* dresultds, + float* dresultdt, ustringhash* errormessage); /// Get information about the given texture. Return true if found /// and the data has been put in *data. Return false if the texture @@ -315,24 +316,20 @@ class OSLEXECPUBLIC RendererServices { /// messages (in case of failure, when the function returns false) will /// be stored there, leaving it up to the caller/shader to handle the /// error. - virtual bool get_texture_info (ustring filename, - TextureHandle *texture_handle, - TexturePerthread *texture_thread_info, - ShadingContext *shading_context, - int subimage, - ustring dataname, TypeDesc datatype, - void *data, - ustring *errormessage); - - virtual bool get_texture_info (ustring filename, - TextureHandle *texture_handle, - float s, float t, - TexturePerthread *texture_thread_info, - ShadingContext *shading_context, - int subimage, - ustring dataname, TypeDesc datatype, - void *data, - ustring *errormessage); + virtual bool get_texture_info(ustringhash filename, + TextureHandle* texture_handle, + TexturePerthread* texture_thread_info, + ShadingContext* shading_context, int subimage, + ustringhash dataname, TypeDesc datatype, + void* data, ustringhash* errormessage); + + virtual bool get_texture_info(ustringhash filename, + TextureHandle* texture_handle, float s, + float t, + TexturePerthread* texture_thread_info, + ShadingContext* shading_context, int subimage, + ustringhash dataname, TypeDesc datatype, + void* data, ustringhash* errormessage); /// Lookup nearest points in a point cloud. It will search for @@ -343,40 +340,38 @@ class OSLEXECPUBLIC RendererServices { /// derivatives will be computed for distances (when provided). /// /// Return the number of points found, always < max_points - virtual int pointcloud_search (ShaderGlobals *sg, - ustring filename, const OSL::Vec3 ¢er, - float radius, int max_points, bool sort, - size_t *out_indices, - float *out_distances, int derivs_offset); + virtual int pointcloud_search(ShaderGlobals* sg, ustringhash filename, + const OSL::Vec3& center, float radius, + int max_points, bool sort, + size_t* out_indices, float* out_distances, + int derivs_offset); /// Retrieve an attribute for an index list. The result is another array /// of the requested type stored in out_data. /// /// Return 1 if the attribute is found, 0 otherwise. - virtual int pointcloud_get (ShaderGlobals *sg, - ustring filename, size_t *indices, int count, - ustring attr_name, TypeDesc attr_type, - void *out_data); + virtual int pointcloud_get(ShaderGlobals* sg, ustringhash filename, + size_t* indices, int count, + ustringhash attr_name, TypeDesc attr_type, + void* out_data); /// Write a point to the named pointcloud, which will be saved /// at the end of the frame. Return true if everything is ok, /// false if there was an error. - virtual bool pointcloud_write (ShaderGlobals *sg, - ustring filename, const OSL::Vec3 &pos, - int nattribs, const ustring *names, - const TypeDesc *types, - const void **data); + virtual bool pointcloud_write(ShaderGlobals* sg, ustringhash filename, + const OSL::Vec3& pos, int nattribs, + const ustringrep* names, + const TypeDesc* types, const void** data); /// Options for the trace call. struct TraceOpt { - float mindist; ///< ignore hits closer than this - float maxdist; ///< ignore hits farther than this - bool shade; ///< whether to shade what is hit - ustring traceset; ///< named trace set - TraceOpt () : mindist(0.0f), maxdist(1.0e30), shade(false) { } + float mindist; ///< ignore hits closer than this + float maxdist; ///< ignore hits farther than this + bool shade; ///< whether to shade what is hit + ustringrep traceset; ///< named trace set + TraceOpt() : mindist(0.0f), maxdist(1.0e30), shade(false) {} - enum class LLVMMemberIndex - { + enum class LLVMMemberIndex { mindist = 0, maxdist, shade, @@ -387,32 +382,28 @@ class OSLEXECPUBLIC RendererServices { /// Immediately trace a ray from P in the direction R. Return true /// if anything hit, otherwise false. - virtual bool trace (TraceOpt &options, ShaderGlobals *sg, - const OSL::Vec3 &P, const OSL::Vec3 &dPdx, - const OSL::Vec3 &dPdy, const OSL::Vec3 &R, - const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy) { - return false; - } + virtual bool trace(TraceOpt& options, ShaderGlobals* sg, const OSL::Vec3& P, + const OSL::Vec3& dPdx, const OSL::Vec3& dPdy, + const OSL::Vec3& R, const OSL::Vec3& dRdx, + const OSL::Vec3& dRdy); /// Get the named message from the renderer and if found then /// write it into 'val'. Otherwise, return false. This is only /// called for "sourced" messages, not ordinary intra-group messages. - virtual bool getmessage (ShaderGlobals *sg, ustring source, ustring name, - TypeDesc type, void *val, bool derivatives) { - return false; - } + virtual bool getmessage(ShaderGlobals* sg, ustringhash source, + ustringhash name, TypeDesc type, void* val, + bool derivatives); /// Return a pointer to the texture system (if available). - virtual TextureSystem *texturesys () const; + virtual TextureSystem* texturesys() const; - virtual uint64_t register_global (const std::string& var_name, - uint64_t value) + virtual uint64_t register_global(const std::string& var_name, + uint64_t value) { return 0; } - virtual bool fetch_global (const std::string& var_name, - uint64_t* value) + virtual bool fetch_global(const std::string& var_name, uint64_t* value) { return false; } @@ -426,19 +417,25 @@ class OSLEXECPUBLIC RendererServices { Vec3 direction; float bandwidth; float impulses; - NoiseOpt () : anisotropic(0), do_filter(true), - direction(1.0f,0.0f,0.0f), bandwidth(1.0f), impulses(16.0f) { } + NoiseOpt() + : anisotropic(0) + , do_filter(true) + , direction(1.0f, 0.0f, 0.0f) + , bandwidth(1.0f) + , impulses(16.0f) + { + } }; /// A renderer may choose to support batched execution by providing pointers /// to objects satisfying the BatchedRendererServices> interface /// for specific batch sizes. /// Unless overridden, a nullptr is returned. - virtual BatchedRendererServices<16> * batched(WidthOf<16>); - virtual BatchedRendererServices<8> * batched(WidthOf<8>); + virtual BatchedRendererServices<16>* batched(WidthOf<16>); + virtual BatchedRendererServices<8>* batched(WidthOf<8>); protected: - TextureSystem *m_texturesys; // A place to hold a TextureSystem + TextureSystem* m_texturesys; // A place to hold a TextureSystem }; diff --git a/src/include/OSL/wide.h b/src/include/OSL/wide.h index a706e3216..96f3cc4df 100644 --- a/src/include/OSL/wide.h +++ b/src/include/OSL/wide.h @@ -895,6 +895,8 @@ template struct alignas(VecReg) Block { } }; + +// Specialization of Block for ustring template struct alignas(VecReg) Block { static constexpr int width = WidthT; typedef ustring ValueType; @@ -942,6 +944,63 @@ template struct alignas(VecReg) Block { } }; + +// Specialization of Block for ustringhash +template struct alignas(VecReg) Block { + static constexpr int width = WidthT; + typedef ustringhash ValueType; + + // To enable vectorization, use uintptr_t to store the ustringhash (const char *) + size_t str[WidthT]; + static_assert(sizeof(ustringhash) == sizeof(size_t), + "ustringhash must be size_t"); + + OSL_FORCEINLINE Block() = default; + // We want to avoid accidentally copying these when the intent was to just pass a reference + Block(const Block& other) = delete; + + OSL_FORCEINLINE void set(int lane, const ustringhash& value) + { + str[lane] = value.hash(); + } + + OSL_FORCEINLINE void set(int lane, ustring value) + { + str[lane] = value.hash(); + } + + OSL_FORCEINLINE void set(int lane, const ustringhash& value, bool laneMask) + { + if (laneMask) + str[lane] = value.hash(); + } + + OSL_FORCEINLINE ustringhash get(int lane) const + { +#ifdef OIIO_USTRING_HAS_CTR_FROM_USTRINGHASH + return ustringhash::from_hash(str[lane]); +#else + // Dumb workaround if we are on old OIIO +# if OPENIMAGEIO_VERSION >= 20500 + return OIIO::bitcast(str[lane]); +# else + return OIIO::bit_cast(str[lane]); +# endif +#endif + } + + OSL_FORCEINLINE pvt::LaneProxy operator[](int lane) + { + return pvt::LaneProxy(*this, lane); + } + + OSL_FORCEINLINE pvt::ConstLaneProxy + operator[](int lane) const + { + return pvt::ConstLaneProxy(*this, lane); + } +}; + template struct alignas(VecReg) Block, WidthT> { typedef Dual2 ValueType; diff --git a/src/liboslexec/batched_rendservices.cpp b/src/liboslexec/batched_rendservices.cpp index 4993e3029..fbff377b2 100644 --- a/src/liboslexec/batched_rendservices.cpp +++ b/src/liboslexec/batched_rendservices.cpp @@ -41,7 +41,7 @@ template Mask BatchedRendererServices::get_matrix(BatchedShaderGlobals* bsg, Masked wresult, - Wide wfrom, + Wide wfrom, Wide wtime) { OSL_ASSERT( @@ -70,7 +70,7 @@ template Mask BatchedRendererServices::get_inverse_matrix(BatchedShaderGlobals* bsg, Masked wresult, - ustring to, + ustringhash to, Wide wtime) { OSL_ASSERT( @@ -85,7 +85,7 @@ template Mask BatchedRendererServices::get_inverse_matrix(BatchedShaderGlobals* bsg, Masked wresult, - Wide wto, + Wide wto, Wide wtime) { OSL_ASSERT( @@ -109,13 +109,13 @@ template TextureSystem::TextureHandle* BatchedRendererServices::resolve_udim_uniform( BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info, - ustring filename, TextureSystem::TextureHandle* texture_handle, float S, + ustringhash filename, TextureSystem::TextureHandle* texture_handle, float S, float T) { if (!texture_thread_info) texture_thread_info = bsg->uniform.context->texture_thread_info(); if (!texture_handle) - texture_handle = texturesys()->get_texture_handle(filename, + texture_handle = texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); if (texturesys()->is_udim(texture_handle)) { // Newer versions of the TextureSystem interface are able to determine the @@ -141,14 +141,14 @@ template void BatchedRendererServices::resolve_udim( BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info, - ustring filename, TextureSystem::TextureHandle* texture_handle, + ustringhash filename, TextureSystem::TextureHandle* texture_handle, Wide wS, Wide wT, Masked wresult) { if (!texture_thread_info) texture_thread_info = bsg->uniform.context->texture_thread_info(); if (!texture_handle) - texture_handle = texturesys()->get_texture_handle(filename, + texture_handle = texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); if (texturesys()->is_udim(texture_handle)) { // Newer versions of the TextureSystem interface are able to determine the @@ -176,17 +176,17 @@ template bool BatchedRendererServices::get_texture_info_uniform( BatchedShaderGlobals* bsg, TexturePerthread* texture_thread_info, - ustring filename, TextureSystem::TextureHandle* texture_handle, - int subimage, ustring dataname, RefData val) + ustringhash filename, TextureSystem::TextureHandle* texture_handle, + int subimage, ustringhash dataname, RefData val) { if (!texture_thread_info) texture_thread_info = bsg->uniform.context->texture_thread_info(); if (!texture_handle) - texture_handle = texturesys()->get_texture_handle(filename, + texture_handle = texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); bool status = texturesys()->get_texture_info(texture_handle, NULL, subimage, - dataname, val.type(), - val.ptr()); + ustring_from(dataname), + val.type(), val.ptr()); if (!status) { std::string err = texturesys()->geterror(); @@ -203,7 +203,7 @@ BatchedRendererServices::get_texture_info_uniform( template Mask BatchedRendererServices::texture( - ustring filename, TextureSystem::TextureHandle* texture_handle, + ustringhash filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, BatchedShaderGlobals* bsg, Wide ws, Wide wt, Wide wdsdx, @@ -221,7 +221,7 @@ BatchedRendererServices::texture( template Mask BatchedRendererServices::texture3d( - ustring filename, TextureSystem::TextureHandle* texture_handle, + ustringhash filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, BatchedShaderGlobals* bsg, Wide wP, Wide wdPdx, Wide wdPdy, @@ -238,7 +238,7 @@ BatchedRendererServices::texture3d( template Mask BatchedRendererServices::environment( - ustring filename, TextureSystem::TextureHandle* texture_handle, + ustringhash filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, BatchedShaderGlobals* bsg, Wide wR, Wide wdRdx, Wide wdRdy, @@ -255,7 +255,7 @@ BatchedRendererServices::environment( template void BatchedRendererServices::pointcloud_search( - BatchedShaderGlobals* bsg, ustring filename, const void* wcenter, + BatchedShaderGlobals* bsg, ustringhash filename, const void* wcenter, Wide wradius, int max_points, bool sort, PointCloudSearchResults& results) { @@ -269,8 +269,8 @@ BatchedRendererServices::pointcloud_search( template Mask BatchedRendererServices::pointcloud_get( - BatchedShaderGlobals* bsg, ustring filename, Wide windices, - Wide wnum_points, ustring attr_name, MaskedData wout_data) + BatchedShaderGlobals* bsg, ustringhash filename, Wide windices, + Wide wnum_points, ustringhash attr_name, MaskedData wout_data) { OSL_ASSERT( 0 @@ -283,7 +283,7 @@ BatchedRendererServices::pointcloud_get( template Mask BatchedRendererServices::pointcloud_write( - BatchedShaderGlobals* bsg, ustring filename, Wide wpos, + BatchedShaderGlobals* bsg, ustringhash filename, Wide wpos, int nattribs, const ustring* attr_names, const TypeDesc* attr_types, const void** pointers_to_wide_attr_value, Mask mask) { @@ -312,8 +312,9 @@ BatchedRendererServices::trace( template void BatchedRendererServices::getmessage(BatchedShaderGlobals* bsg, - Masked wresult, ustring source, - ustring name, MaskedData wval) + Masked wresult, + ustringhash source, + ustringhash name, MaskedData wval) { // Currently this code path should only be followed when source == "trace" OSL_DASSERT(wresult.mask() == wval.mask()); diff --git a/src/liboslexec/constfold.cpp b/src/liboslexec/constfold.cpp index 964985299..86790878c 100644 --- a/src/liboslexec/constfold.cpp +++ b/src/liboslexec/constfold.cpp @@ -2413,11 +2413,12 @@ DECLFOLDER(constfold_gettextureinfo) void* mydata = OSL_ALLOCA(char, t.size()); // FIXME(ptex) -- exclude folding of ptex, since these things // can vary per face. - ustring errormessage; + ustringhash em; int result = rop.renderer()->get_texture_info( filename, nullptr, rop.shadingcontext()->texture_thread_info(), rop.shadingcontext(), 0 /* TODO: subimage? */, dataname, t, mydata, - &errormessage); + &em); + ustring errormessage = ustring_from(em); // Now we turn // gettextureinfo result filename dataname data // into this for success: diff --git a/src/liboslexec/optexture.cpp b/src/liboslexec/optexture.cpp index dbc0eb4d1..144de35af 100644 --- a/src/liboslexec/optexture.cpp +++ b/src/liboslexec/optexture.cpp @@ -217,7 +217,7 @@ OSL_SHADEOP int osl_texture(void* sg_, const char* name, void* handle, void* opt_, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, int chans, void* result, void* dresultdx, void* dresultdy, void* alpha, - void* dalphadx, void* dalphady, ustring* errormessage) + void* dalphadx, void* dalphady, ustringrep* errormessage) { ShaderGlobals* sg = (ShaderGlobals*)sg_; TextureOpt* opt = (TextureOpt*)opt_; @@ -225,11 +225,12 @@ osl_texture(void* sg_, const char* name, void* handle, void* opt_, float s, // It's actually faster to ask for 4 channels (even if we need fewer) // and ensure that they're being put in aligned memory. OIIO::simd::float4 result_simd, dresultds_simd, dresultdt_simd; + ustringhash em; bool ok = sg->renderer->texture( - USTR(name), (TextureSystem::TextureHandle*)handle, + USTR(name).uhash(), (TextureSystem::TextureHandle*)handle, sg->context->texture_thread_info(), *opt, sg, s, t, dsdx, dtdx, dsdy, dtdy, 4, (float*)&result_simd, derivs ? (float*)&dresultds_simd : NULL, - derivs ? (float*)&dresultdt_simd : NULL, errormessage); + derivs ? (float*)&dresultdt_simd : NULL, errormessage ? &em : nullptr); for (int i = 0; i < chans; ++i) ((float*)result)[i] = result_simd[i]; @@ -256,8 +257,9 @@ osl_texture(void* sg_, const char* name, void* handle, void* opt_, float s, } } - if (ok && errormessage) - *errormessage = Strings::_emptystring_; + if (errormessage) + *errormessage = ok ? ustringrep_from(Strings::_emptystring_) + : ustringrep_from(em); return ok; } @@ -267,7 +269,7 @@ OSL_SHADEOP int osl_texture3d(void* sg_, const char* name, void* handle, void* opt_, void* P_, void* dPdx_, void* dPdy_, void* dPdz_, int chans, void* result, void* dresultdx, void* dresultdy, void* alpha, void* dalphadx, - void* dalphady, ustring* errormessage) + void* dalphady, ustringrep* errormessage) { const Vec3& P(*(Vec3*)P_); const Vec3& dPdx(*(Vec3*)dPdx_); @@ -283,12 +285,14 @@ osl_texture3d(void* sg_, const char* name, void* handle, void* opt_, void* P_, // and ensure that they're being put in aligned memory. OIIO::simd::float4 result_simd, dresultds_simd, dresultdt_simd, dresultdr_simd; + ustringhash em; bool ok = sg->renderer->texture3d( - USTR(name), (TextureSystem::TextureHandle*)handle, + USTR(name).uhash(), (TextureSystem::TextureHandle*)handle, sg->context->texture_thread_info(), *opt, sg, P, dPdx, dPdy, dPdz, 4, (float*)&result_simd, derivs ? (float*)&dresultds_simd : nullptr, derivs ? (float*)&dresultdt_simd : nullptr, - derivs ? (float*)&dresultdr_simd : nullptr, errormessage); + derivs ? (float*)&dresultdr_simd : nullptr, + errormessage ? &em : nullptr); for (int i = 0; i < chans; ++i) ((float*)result)[i] = result_simd[i]; @@ -315,8 +319,9 @@ osl_texture3d(void* sg_, const char* name, void* handle, void* opt_, void* P_, } } - if (ok && errormessage) - *errormessage = Strings::_emptystring_; + if (errormessage) + *errormessage = ok ? ustringrep_from(Strings::_emptystring_) + : ustringrep_from(em); return ok; } @@ -326,7 +331,7 @@ OSL_SHADEOP int osl_environment(void* sg_, const char* name, void* handle, void* opt_, void* R_, void* dRdx_, void* dRdy_, int chans, void* result, void* dresultdx, void* dresultdy, void* alpha, void* dalphadx, - void* dalphady, ustring* errormessage) + void* dalphady, ustringrep* errormessage) { const Vec3& R(*(Vec3*)R_); const Vec3& dRdx(*(Vec3*)dRdx_); @@ -336,12 +341,13 @@ osl_environment(void* sg_, const char* name, void* handle, void* opt_, void* R_, // It's actually faster to ask for 4 channels (even if we need fewer) // and ensure that they're being put in aligned memory. OIIO::simd::float4 local_result; - bool ok = sg->renderer->environment(USTR(name), + ustringhash em; + bool ok = sg->renderer->environment(USTR(name).uhash(), (TextureSystem::TextureHandle*)handle, sg->context->texture_thread_info(), *opt, sg, R, dRdx, dRdy, 4, (float*)&local_result, NULL, NULL, - errormessage); + errormessage ? &em : nullptr); for (int i = 0; i < chans; ++i) ((float*)result)[i] = local_result[i]; @@ -368,8 +374,9 @@ osl_environment(void* sg_, const char* name, void* handle, void* opt_, void* R_, ((float*)dalphady)[0] = 0.0f; } - if (ok && errormessage) - *errormessage = Strings::_emptystring_; + if (errormessage) + *errormessage = ok ? ustringrep_from(Strings::_emptystring_) + : ustringrep_from(em); return ok; } @@ -378,7 +385,7 @@ osl_environment(void* sg_, const char* name, void* handle, void* opt_, void* R_, OSL_SHADEOP int osl_get_textureinfo(void* sg_, const char* name, void* handle, void* dataname, int type, int arraylen, int aggregate, void* data, - ustring* errormessage) + ustringrep* errormessage) { // recreate TypeDesc TypeDesc typedesc; @@ -388,10 +395,15 @@ osl_get_textureinfo(void* sg_, const char* name, void* handle, void* dataname, ShaderGlobals* sg = (ShaderGlobals*)sg_; - return sg->renderer->get_texture_info( - USTR(name), (RendererServices::TextureHandle*)handle, + ustringhash em; + bool ok = sg->renderer->get_texture_info( + USTR(name).uhash(), (RendererServices::TextureHandle*)handle, sg->context->texture_thread_info(), sg->context, 0 /*FIXME-ptex*/, - USTR(dataname), typedesc, data, errormessage); + USTR(dataname).uhash(), typedesc, data, errormessage ? &em : nullptr); + if (errormessage) + *errormessage = ok ? ustringrep_from(Strings::_emptystring_) + : ustringrep_from(em); + return ok; } @@ -399,7 +411,7 @@ osl_get_textureinfo(void* sg_, const char* name, void* handle, void* dataname, OSL_SHADEOP int osl_get_textureinfo_st(void* sg_, const char* name, void* handle, float s, float t, void* dataname, int type, int arraylen, - int aggregate, void* data, ustring* errormessage) + int aggregate, void* data, ustringrep* errormessage) { // recreate TypeDesc TypeDesc typedesc; @@ -409,10 +421,15 @@ osl_get_textureinfo_st(void* sg_, const char* name, void* handle, float s, ShaderGlobals* sg = (ShaderGlobals*)sg_; - return sg->renderer->get_texture_info( - USTR(name), (RendererServices::TextureHandle*)handle, s, t, + ustringhash em; + bool ok = sg->renderer->get_texture_info( + USTR(name).uhash(), (RendererServices::TextureHandle*)handle, s, t, sg->context->texture_thread_info(), sg->context, 0 /*FIXME-ptex*/, - USTR(dataname), typedesc, data, errormessage); + USTR(dataname).uhash(), typedesc, data, errormessage ? &em : nullptr); + if (errormessage) + *errormessage = ok ? ustringrep_from(Strings::_emptystring_) + : ustringrep_from(em); + return ok; } diff --git a/src/liboslexec/pointcloud.cpp b/src/liboslexec/pointcloud.cpp index 97b130313..be1b99606 100644 --- a/src/liboslexec/pointcloud.cpp +++ b/src/liboslexec/pointcloud.cpp @@ -12,25 +12,26 @@ OSL_NAMESPACE_ENTER namespace pvt { #ifdef USE_PARTIO -typedef std::unordered_map> PointCloudMap; +using PointCloudMap + = std::unordered_map>; static PointCloudMap pointclouds; static OIIO::spin_mutex pointcloudmap_mutex; PointCloud* -PointCloud::get(ustring filename, bool write) +PointCloud::get(ustringhash filename, bool write) { if (filename.empty()) - return NULL; + return nullptr; spin_lock lock(pointcloudmap_mutex); PointCloudMap::const_iterator found = pointclouds.find(filename); if (found != pointclouds.end()) return found->second.get(); // Not found. Create a new one. - Partio::ParticlesDataMutable* partio_cloud = NULL; + Partio::ParticlesDataMutable* partio_cloud = nullptr; if (!write) { partio_cloud = Partio::read(filename.c_str(), false); if (!partio_cloud) - return NULL; + return nullptr; } else { partio_cloud = Partio::create(); } @@ -40,7 +41,7 @@ PointCloud::get(ustring filename, bool write) } -PointCloud::PointCloud(ustring filename, +PointCloud::PointCloud(ustringhash filename, Partio::ParticlesDataMutable* partio_cloud, bool write) : m_filename(filename), m_partio_cloud(partio_cloud), m_write(write) { @@ -76,8 +77,10 @@ PointCloud::~PointCloud() } // namespace pvt + + int -RendererServices::pointcloud_search(ShaderGlobals* sg, ustring filename, +RendererServices::pointcloud_search(ShaderGlobals* sg, ustringhash filename, const Vec3& center, float radius, int max_points, bool sort, size_t* out_indices, float* out_distances, @@ -86,17 +89,17 @@ RendererServices::pointcloud_search(ShaderGlobals* sg, ustring filename, #ifdef USE_PARTIO if (filename.empty()) return 0; - PointCloud* pc = PointCloud::get(filename); + PointCloud* pc = PointCloud::get(ustring_from(filename)); if (pc == NULL) { // The file failed to load sg->context->errorfmt("pointcloud_search: could not open \"{}\"", - filename); + ustring_from(filename)); return 0; } const Partio::ParticlesData* cloud = pc->read_access(); if (cloud == NULL) { // The file failed to load sg->context->errorfmt("pointcloud_search: could not open \"{}\"", - filename); + ustring_from(filename)); return 0; } @@ -192,25 +195,26 @@ RendererServices::pointcloud_search(ShaderGlobals* sg, ustring filename, int -RendererServices::pointcloud_get(ShaderGlobals* sg, ustring filename, - size_t* indices, int count, ustring attr_name, - TypeDesc attr_type, void* out_data) +RendererServices::pointcloud_get(ShaderGlobals* sg, ustringhash filename, + size_t* indices, int count, + ustringhash attr_name, TypeDesc attr_type, + void* out_data) { #ifdef USE_PARTIO if (!count) return 1; // always succeed if not asking for any data - PointCloud* pc = PointCloud::get(filename); + PointCloud* pc = PointCloud::get(ustring_from(filename)); if (pc == NULL) { // The file failed to load sg->context->errorfmt("pointcloud_get: could not open \"{}\"", - filename); + ustring_from(filename)); return 0; } const Partio::ParticlesData* cloud = pc->read_access(); if (cloud == NULL) { // The file failed to load sg->context->errorfmt("pointcloud_get: could not open \"{}\"", - filename); + ustring_from(filename)); return 0; } @@ -219,7 +223,7 @@ RendererServices::pointcloud_get(ShaderGlobals* sg, ustring filename, if (!attr) { sg->context->errorfmt( "Accessing unexisting attribute {} in pointcloud \"{}\"", attr_name, - filename); + ustring_from(filename)); return 0; } @@ -232,7 +236,7 @@ RendererServices::pointcloud_get(ShaderGlobals* sg, ustring filename, if (!compatiblePartioType(partio_type, element_type)) { sg->context->errorfmt( "Type of attribute \"{}\" : {} not compatible with OSL's {} in \"{}\" pointcloud", - attr_name, partio_type, element_type, filename); + attr_name, partio_type, element_type, ustring_from(filename)); return 0; } @@ -263,9 +267,9 @@ RendererServices::pointcloud_get(ShaderGlobals* sg, ustring filename, for (int i = 0; i < count; ++i) { int ind = strindices[i]; if (ind >= 0 && ind < sicount) - ((ustring*)out_data)[i] = ustring(strings[ind]); + ((ustringrep*)out_data)[i] = ustringrep(strings[ind]); else - ((ustring*)out_data)[i] = ustring(); + ((ustringrep*)out_data)[i] = ustringrep(); } } else { // All cases aside from strings are simple. @@ -286,15 +290,16 @@ RendererServices::pointcloud_get(ShaderGlobals* sg, ustring filename, bool -RendererServices::pointcloud_write(ShaderGlobals* /*sg*/, ustring filename, +RendererServices::pointcloud_write(ShaderGlobals* /*sg*/, ustringhash filename, const Vec3& pos, int nattribs, - const ustring* names, const TypeDesc* types, - const void** data) + const ustringrep* names, + const TypeDesc* types, const void** data) { #ifdef USE_PARTIO if (filename.empty()) return false; - PointCloud* pc = PointCloud::get(filename, true /* create file to write */); + PointCloud* pc = PointCloud::get(ustring_from(filename), + true /* create file to write */); spin_lock lock(pc->m_mutex); Partio::ParticlesDataMutable* cloud = pc->write_access(); if (cloud == NULL) // The file failed to load @@ -438,7 +443,7 @@ osl_pointcloud_get(ShaderGlobals* sg, const char* filename, void* in_indices, OSL_SHADEOP void -osl_pointcloud_write_helper(ustring* names, TypeDesc* types, void** values, +osl_pointcloud_write_helper(ustringrep* names, TypeDesc* types, void** values, int index, const char* name, long long type, void* val) { @@ -451,8 +456,8 @@ osl_pointcloud_write_helper(ustring* names, TypeDesc* types, void** values, OSL_SHADEOP int osl_pointcloud_write(ShaderGlobals* sg, const char* filename, const Vec3* pos, - int nattribs, const ustring* names, const TypeDesc* types, - const void** values) + int nattribs, const ustringrep* names, + const TypeDesc* types, const void** values) { ShadingSystemImpl& shadingsys(sg->context->shadingsys()); if (shadingsys.no_pointcloud()) // Debug mode to skip pointcloud expense diff --git a/src/liboslexec/pointcloud.h b/src/liboslexec/pointcloud.h index 744dede90..093435ab7 100644 --- a/src/liboslexec/pointcloud.h +++ b/src/liboslexec/pointcloud.h @@ -17,12 +17,12 @@ namespace pvt { class PointCloud { public: - PointCloud(ustring filename, Partio::ParticlesDataMutable* partio_cloud, + PointCloud(ustringhash filename, Partio::ParticlesDataMutable* partio_cloud, bool write); ~PointCloud(); - static PointCloud* get(ustring filename, bool write = false); + static PointCloud* get(ustringhash filename, bool write = false); - typedef std::unordered_map> AttributeMap; @@ -37,7 +37,7 @@ class PointCloud { return m_partio_cloud; } - ustring m_filename; + ustringhash m_filename; private: // hide just this field, because we want to control how it is accessed diff --git a/src/liboslexec/rendservices.cpp b/src/liboslexec/rendservices.cpp index 80bc9eecf..36f2fc77a 100644 --- a/src/liboslexec/rendservices.cpp +++ b/src/liboslexec/rendservices.cpp @@ -47,6 +47,24 @@ RendererServices::texturesys() const +bool +RendererServices::get_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash from, float time) +{ + return false; +} + + + +bool +RendererServices::get_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash from) +{ + return false; +} + + + bool RendererServices::get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, TransformationPtr xform, float time) @@ -73,8 +91,9 @@ RendererServices::get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, bool RendererServices::get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, - ustring to, float time) + ustringhash to, float time) { + // return get_inverse_matrix(sg, result, ustring_from(to), time); bool ok = get_matrix(sg, result, to, time); if (ok) result.invert(); @@ -85,8 +104,9 @@ RendererServices::get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, bool RendererServices::get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, - ustring to) + ustringhash to) { + // return get_inverse_matrix(sg, result, ustring_from(to)); bool ok = get_matrix(sg, result, to); if (ok) result.invert(); @@ -95,10 +115,52 @@ RendererServices::get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, +bool +RendererServices::transform_points(ShaderGlobals* sg, ustringhash from, + ustringhash to, float time, const Vec3* Pin, + Vec3* Pout, int npoints, + TypeDesc::VECSEMANTICS vectype) +{ + return false; +} + + + +bool +RendererServices::get_attribute(ShaderGlobals* sg, bool derivatives, + ustringhash object, TypeDesc type, + ustringhash name, void* val) +{ + return false; +} + + + +bool +RendererServices::get_array_attribute(ShaderGlobals* sg, bool derivatives, + ustringhash object, TypeDesc type, + ustringhash name, int index, void* val) +{ + return false; +} + + + +bool +RendererServices::get_userdata(bool derivatives, ustringhash name, + TypeDesc type, ShaderGlobals* sg, void* val) +{ + return false; + // return get_userdata(derivatives, ustring_from(name), type, sg, val); +} + + + RendererServices::TextureHandle* -RendererServices::get_texture_handle(ustring filename, ShadingContext* context) +RendererServices::get_texture_handle(ustringhash filename, + ShadingContext* context) { - return texturesys()->get_texture_handle(filename, + return texturesys()->get_texture_handle(ustring_from(filename), context->texture_thread_info()); } @@ -120,19 +182,19 @@ RendererServices::is_udim(TextureHandle* texture_handle) bool -RendererServices::texture(ustring filename, TextureHandle* texture_handle, +RendererServices::texture(ustringhash filename, TextureHandle* texture_handle, TexturePerthread* texture_thread_info, TextureOpt& options, ShaderGlobals* sg, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, int nchannels, float* result, float* dresultds, float* dresultdt, - ustring* errormessage) + ustringhash* errormessage) { ShadingContext* context = sg->context; if (!texture_thread_info) texture_thread_info = context->texture_thread_info(); if (!texture_handle) - texture_handle = texturesys()->get_texture_handle(filename, + texture_handle = texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); bool status = texturesys()->texture(texture_handle, texture_thread_info, options, s, t, dsdx, dtdx, dsdy, dtdy, @@ -142,12 +204,12 @@ RendererServices::texture(ustring filename, TextureHandle* texture_handle, std::string err = texturesys()->geterror(); if (err.size() && sg) { if (errormessage) { - *errormessage = ustring(err); + *errormessage = ustringhash(err); } else { context->errorfmt("[RendererServices::texture] {}", err); } } else if (errormessage) { - *errormessage = Strings::unknown; + *errormessage = ustringhash(Strings::unknown); } } return status; @@ -156,19 +218,19 @@ RendererServices::texture(ustring filename, TextureHandle* texture_handle, bool -RendererServices::texture3d(ustring filename, TextureHandle* texture_handle, +RendererServices::texture3d(ustringhash filename, TextureHandle* texture_handle, TexturePerthread* texture_thread_info, TextureOpt& options, ShaderGlobals* sg, const Vec3& P, const Vec3& dPdx, const Vec3& dPdy, const Vec3& dPdz, int nchannels, float* result, float* dresultds, float* dresultdt, - float* dresultdr, ustring* errormessage) + float* dresultdr, ustringhash* errormessage) { ShadingContext* context = sg->context; if (!texture_thread_info) texture_thread_info = context->texture_thread_info(); if (!texture_handle) - texture_handle = texturesys()->get_texture_handle(filename, + texture_handle = texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); bool status = texturesys()->texture3d(texture_handle, texture_thread_info, @@ -179,12 +241,12 @@ RendererServices::texture3d(ustring filename, TextureHandle* texture_handle, std::string err = texturesys()->geterror(); if (err.size() && sg) { if (errormessage) { - *errormessage = ustring(err); + *errormessage = ustringhash(err); } else { sg->context->errorfmt("[RendererServices::texture3d] {}", err); } } else if (errormessage) { - *errormessage = Strings::unknown; + *errormessage = Strings::unknown.uhash(); } } return status; @@ -193,18 +255,19 @@ RendererServices::texture3d(ustring filename, TextureHandle* texture_handle, bool -RendererServices::environment(ustring filename, TextureHandle* texture_handle, +RendererServices::environment(ustringhash filename, + TextureHandle* texture_handle, TexturePerthread* texture_thread_info, TextureOpt& options, ShaderGlobals* sg, const Vec3& R, const Vec3& dRdx, const Vec3& dRdy, int nchannels, float* result, float* dresultds, - float* dresultdt, ustring* errormessage) + float* dresultdt, ustringhash* errormessage) { ShadingContext* context = sg->context; if (!texture_thread_info) texture_thread_info = context->texture_thread_info(); if (!texture_handle) - texture_handle = texturesys()->get_texture_handle(filename, + texture_handle = texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); bool status = texturesys()->environment(texture_handle, texture_thread_info, options, R, dRdx, dRdy, nchannels, @@ -213,13 +276,13 @@ RendererServices::environment(ustring filename, TextureHandle* texture_handle, std::string err = texturesys()->geterror(); if (err.size() && sg) { if (errormessage) { - *errormessage = ustring(err); + *errormessage = ustringhash(err); } else { sg->context->errorfmt("[RendererServices::environment] {}", err); } } else if (errormessage) { - *errormessage = Strings::unknown; + *errormessage = Strings::unknown.uhash(); } } return status; @@ -228,34 +291,35 @@ RendererServices::environment(ustring filename, TextureHandle* texture_handle, bool -RendererServices::get_texture_info(ustring filename, +RendererServices::get_texture_info(ustringhash filename, TextureHandle* texture_handle, TexturePerthread* texture_thread_info, ShadingContext* shading_context, - int subimage, ustring dataname, + int subimage, ustringhash dataname, TypeDesc datatype, void* data, - ustring* errormessage) + ustringhash* errormessage) { if (!texture_thread_info) texture_thread_info = shading_context->texture_thread_info(); if (!texture_handle) - texture_handle = texturesys()->get_texture_handle(filename, + texture_handle = texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); bool status = texturesys()->get_texture_info(texture_handle, texture_thread_info, subimage, - dataname, datatype, data); + ustring_from(dataname), + datatype, data); if (!status) { std::string err = texturesys()->geterror(); if (err.size()) { if (errormessage) { - *errormessage = ustring(err); + *errormessage = ustringhash(err); } else { shading_context->errorfmt( "[RendererServices::get_texture_info] {}", err); } } else if (errormessage) { // gettextureinfo failed but did not provide an error, so none should be emitted - *errormessage = ustring(); + *errormessage = ustringhash(); } } return status; @@ -265,10 +329,10 @@ RendererServices::get_texture_info(ustring filename, bool RendererServices::get_texture_info( - ustring filename, TextureHandle* texture_handle, float s, float t, + ustringhash filename, TextureHandle* texture_handle, float s, float t, TexturePerthread* texture_thread_info, ShadingContext* shading_context, - int subimage, ustring dataname, TypeDesc datatype, void* data, - ustring* errormessage) + int subimage, ustringhash dataname, TypeDesc datatype, void* data, + ustringhash* errormessage) { #if OIIO_VERSION >= 20307 // Newer versions of the TextureSystem interface are able to determine the @@ -276,7 +340,7 @@ RendererServices::get_texture_info( if (!texture_thread_info) texture_thread_info = shading_context->texture_thread_info(); if (!texture_handle) - texture_handle = texturesys()->get_texture_handle(filename, + texture_handle = texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); if (texturesys()->is_udim(texture_handle)) { TextureSystem::TextureHandle* udim_handle @@ -297,6 +361,27 @@ RendererServices::get_texture_info( +bool +RendererServices::trace(TraceOpt& options, ShaderGlobals* sg, + const OSL::Vec3& P, const OSL::Vec3& dPdx, + const OSL::Vec3& dPdy, const OSL::Vec3& R, + const OSL::Vec3& dRdx, const OSL::Vec3& dRdy) +{ + return false; +} + + + +bool +RendererServices::getmessage(ShaderGlobals* sg, ustringhash source, + ustringhash name, TypeDesc type, void* val, + bool derivatives) +{ + return false; +} + + + BatchedRendererServices<16>* RendererServices::batched(WidthOf<16>) { diff --git a/src/liboslexec/wide/wide_opmatrix.cpp b/src/liboslexec/wide/wide_opmatrix.cpp index 2c021010b..d58e630e8 100644 --- a/src/liboslexec/wide/wide_opmatrix.cpp +++ b/src/liboslexec/wide/wide_opmatrix.cpp @@ -45,6 +45,18 @@ invoke(FunctorT f) f(); } + +// helper to make a Block from a pointer +#if !OSL_USTRINGREP_IS_HASH +inline void +block_ustringhash_from_ptr(Block& b, const void* w_ptr) +{ + for (int i = 0; i < __OSL_WIDTH; ++i) + b.set(i, reinterpret_cast(w_ptr)[i]); +} +#endif + + OSL_FORCEINLINE void invert_wide_matrix(Masked wresult, Wide wmatrix) { @@ -88,12 +100,12 @@ invert_wide_matrix(Masked wresult, Wide wmatrix) Mask default_get_matrix(BatchedRendererServices* bsr, BatchedShaderGlobals* bsg, - Masked wresult, Wide wfrom, + Masked wresult, Wide wfrom, Wide wtime) { Mask ok(false); foreach_unique(wfrom, wresult.mask(), - [=, &ok](const ustring& from, Mask from_mask) { + [=, &ok](const ustringhash& from, Mask from_mask) { // Reuse the uniform from implementation by restricting results to // just the lanes with the same value of "from". Masked wsub_result(wresult.data(), from_mask); @@ -110,7 +122,7 @@ default_get_matrix(BatchedRendererServices* bsr, BatchedShaderGlobals* bsg, // execute the ISA optimized default version built right here. OSL_FORCEINLINE Mask dispatch_get_matrix(BatchedRendererServices* bsr, BatchedShaderGlobals* bsg, - Masked result, Wide from, + Masked result, Wide from, Wide time) { if (bsr->is_overridden_get_matrix_WmWsWf()) { @@ -154,7 +166,7 @@ dispatch_get_inverse_matrix(BatchedRendererServices* bsr, Mask default_get_inverse_matrix(BatchedRendererServices* bsr, BatchedShaderGlobals* bsg, Masked result, - ustring to, Wide time) + ustringhash to, Wide time) { OSL_FORCEINLINE_BLOCK { @@ -170,7 +182,7 @@ default_get_inverse_matrix(BatchedRendererServices* bsr, OSL_FORCEINLINE Mask dispatch_get_inverse_matrix(BatchedRendererServices* bsr, BatchedShaderGlobals* bsg, Masked result, - ustring to, Wide time) + ustringhash to, Wide time) { if (bsr->is_overridden_get_inverse_matrix_WmsWf()) { return bsr->get_inverse_matrix(bsg, result, to, time); @@ -183,12 +195,12 @@ dispatch_get_inverse_matrix(BatchedRendererServices* bsr, Mask default_get_inverse_matrix(BatchedRendererServices* bsr, BatchedShaderGlobals* bsg, Masked wresult, - Wide wto, Wide wtime) + Wide wto, Wide wtime) { if (bsr->is_overridden_get_inverse_matrix_WmsWf()) { Mask ok(false); foreach_unique(wto, wresult.mask(), - [=, &ok](const ustring& to, Mask from_mask) { + [=, &ok](const ustringhash& to, Mask from_mask) { // Reuse the uniform from implementation by restricting results to // just the lanes with the same value of "from". Masked wsub_result(wresult.data(), @@ -213,7 +225,7 @@ default_get_inverse_matrix(BatchedRendererServices* bsr, OSL_FORCEINLINE Mask dispatch_get_inverse_matrix(BatchedRendererServices* bsr, BatchedShaderGlobals* bsg, Masked result, - Wide to, Wide time) + Wide to, Wide time) { if (bsr->is_overridden_get_inverse_matrix_WmWsWf()) { return bsr->get_inverse_matrix(bsg, result, to, time); @@ -627,7 +639,7 @@ impl_wide_mat_multiply(ResultAccessorT wresult, FromAccessorT wfrom, OSL_FORCEINLINE Mask impl_get_varying_from_matrix_batched(BatchedShaderGlobals* bsg, ShadingContext* ctx, - Wide wFrom, + Wide wFrom, Masked wMfrom) { // Deal with a varying 'from' space @@ -646,7 +658,7 @@ impl_get_varying_from_matrix_batched(BatchedShaderGlobals* bsg, : common_space_bits, shader_space_bits, object_space_bits, named_space_bits)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { - ustring from = wFrom[lane]; + ustringhash from = wFrom[lane]; if (wMfrom.mask()[lane]) { if (from == Strings::common || from == commonspace_synonym) { // inline of Mask::set_on(lane) @@ -703,10 +715,10 @@ impl_get_varying_from_matrix_batched(BatchedShaderGlobals* bsg, if (ctx->shadingsys().unknown_coordsys_error()) { for (int lane = 0; lane < __OSL_WIDTH; ++lane) { if (failedLanes[lane]) { - ustring from = wFrom[lane]; + ustringhash from = wFrom[lane]; ctx->batched<__OSL_WIDTH>().errorfmt( Mask(Lane(lane)), "Unknown transformation \"{}\"", - from); + ustring(from)); } } } @@ -746,7 +758,13 @@ __OSL_MASKED_OP2(prepend_matrix_from, Wm, Ws)(void* bsg_, void* wr, auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; - Wide wFromName(w_from_name); +#if OSL_USTRINGREP_IS_HASH + Wide wFromName(w_from_name); +#else + Block bwFromName; + block_ustringhash_from_ptr(bwFromName, w_from_name); + Wide wFromName(bwFromName); +#endif Block wMfrom; Masked from_matrix(wMfrom, Mask(mask_value)); @@ -762,7 +780,8 @@ __OSL_MASKED_OP2(prepend_matrix_from, Wm, Ws)(void* bsg_, void* wr, namespace { OSL_FORCEINLINE Mask impl_get_varying_to_matrix_masked(BatchedShaderGlobals* bsg, - ShadingContext* ctx, Wide wTo, + ShadingContext* ctx, + Wide wTo, Masked wMto) { // Deal with a varying 'to' space @@ -781,7 +800,7 @@ impl_get_varying_to_matrix_masked(BatchedShaderGlobals* bsg, : common_space_bits, shader_space_bits, object_space_bits, named_space_bits)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { - ustring to = wTo[lane]; + ustringhash to = wTo[lane]; if (wMto.mask()[lane]) { if (to == Strings::common || to == commonspace_synonym) { // inline of Mask::set_on(lane) @@ -836,10 +855,10 @@ impl_get_varying_to_matrix_masked(BatchedShaderGlobals* bsg, if (ctx->shadingsys().unknown_coordsys_error()) { for (int lane = 0; lane < __OSL_WIDTH; ++lane) { if (failedLanes[lane]) { - ustring to = wTo[lane]; + ustringhash to = wTo[lane]; ctx->batched<__OSL_WIDTH>().errorfmt( Mask(Lane(lane)), "Unknown transformation \"{}\"", - to); + ustring(to)); } } } @@ -895,7 +914,13 @@ __OSL_MASKED_OP3(get_from_to_matrix, Wm, s, Mask succeeded = impl_get_uniform_from_matrix_masked(bsg, from_matrix, from); - Wide wToSpace(w_to_ptr); +#if OSL_USTRINGREP_IS_HASH + Wide wToSpace(w_to_ptr); +#else + Block bwToSpace; + block_ustringhash_from_ptr(bwToSpace, w_to_ptr); + Wide wToSpace(bwToSpace); +#endif Block wMto; // NOTE: even if we failed to get a from matrix, it should have been set to // identity, so we still need to try to get the to matrix for the original mask @@ -917,7 +942,13 @@ __OSL_MASKED_OP3(get_from_to_matrix, Wm, Ws, auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; - Wide wFromName(w_from_ptr); +#if OSL_USTRINGREP_IS_HASH + Wide wFromName(w_from_ptr); +#else + Block bwFromName; + block_ustringhash_from_ptr(bwFromName, w_from_ptr); + Wide wFromName(bwFromName); +#endif Block wMto; Masked to_matrix(wMto, Mask(mask_value)); @@ -945,14 +976,26 @@ __OSL_MASKED_OP3(get_from_to_matrix, Wm, Ws, auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; - Wide wFromName(w_from_ptr); +#if OSL_USTRINGREP_IS_HASH + Wide wFromName(w_from_ptr); +#else + Block bwFromName; + block_ustringhash_from_ptr(bwFromName, w_from_ptr); + Wide wFromName(bwFromName); +#endif Block wMfrom; Masked from_matrix(wMfrom, Mask(mask_value)); Mask succeeded = impl_get_varying_from_matrix_batched(bsg, ctx, wFromName, from_matrix); - Wide wToSpace(w_to_ptr); +#if OSL_USTRINGREP_IS_HASH + Wide wToSpace(w_to_ptr); +#else + Block bwToSpace; + block_ustringhash_from_ptr(bwToSpace, w_to_ptr); + Wide wToSpace(bwToSpace); +#endif Block wMto; // NOTE: even if we failed to get a from matrix, it should have been set to // identity, so we still need to try to get the to matrix for the original mask @@ -987,8 +1030,8 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, s, s)(void* bsg_, void* WM_, Masked mm(WM_, mask); ShadingContext* ctx = bsg->uniform.context; - ustring from = USTR(from_); - ustring to = USTR(to_); + ustringrep from = USTR(from_); + ustringrep to = USTR(to_); Mask succeeded; // Avoid matrix concatenation if possible by detecting when the @@ -1022,9 +1065,15 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, s)(void* bsg_, void* WM_, Mask mask(mask_value); Masked wrm(WM_, mask); - Wide wfrom_space(wfrom_); +#if OSL_USTRINGREP_IS_HASH + Wide wfrom_space(wfrom_); +#else + Block bwfrom_space; + block_ustringhash_from_ptr(bwfrom_space, wfrom_); + Wide wfrom_space(bwfrom_space); +#endif - ustring to_space = USTR(to_); + ustringrep to_space = USTR(to_); Block wMfrom, wMto; Masked from_matrix(wMfrom, wrm.mask()); @@ -1052,8 +1101,14 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, s, Ws)(void* bsg_, void* WM_, Mask mask(mask_value); Masked wrm(WM_, mask); - ustring from = USTR(from_); - Wide wto_space(wto_); + ustringrep from = USTR(from_); +#if OSL_USTRINGREP_IS_HASH + Wide wto_space(wto_); +#else + Block bwto_space; + block_ustringhash_from_ptr(bwto_space, wto_); + Wide wto_space(bwto_space); +#endif Block wMfrom, wMto; Masked from_matrix(wMfrom, wrm.mask()); @@ -1082,8 +1137,17 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, Ws)(void* bsg_, void* WM_, Mask mask(mask_value); Masked wrm(WM_, mask); - Wide wfrom_space(wfrom_); - Wide wto_space(wto_); +#if OSL_USTRINGREP_IS_HASH + Wide wfrom_space(wfrom_); + Wide wto_space(wto_); +#else + Block bwfrom_space; + block_ustringhash_from_ptr(bwfrom_space, wfrom_); + Wide wfrom_space(bwfrom_space); + Block bwto_space; + block_ustringhash_from_ptr(bwto_space, wto_); + Wide wto_space(bwto_space); +#endif Block wMfrom, wMto; Masked from_matrix(wMfrom, wrm.mask()); diff --git a/src/liboslexec/wide/wide_oppointcloud.cpp b/src/liboslexec/wide/wide_oppointcloud.cpp index 66a34ae60..cdc114877 100644 --- a/src/liboslexec/wide/wide_oppointcloud.cpp +++ b/src/liboslexec/wide/wide_oppointcloud.cpp @@ -35,7 +35,7 @@ using PointCloudSearchResults = BatchedRendererServices::PointCloudSearchResults namespace { OSL_FORCEINLINE void -default_pointcloud_search(BatchedShaderGlobals* bsg, ustring filename, +default_pointcloud_search(BatchedShaderGlobals* bsg, ustringhash filename, const void* wcenter_, Wide wradius, int max_points, bool sort, PointCloudSearchResults& results) @@ -199,7 +199,7 @@ default_pointcloud_search(BatchedShaderGlobals* bsg, ustring filename, OSL_FORCEINLINE void -dispatch_pointcloud_search(BatchedShaderGlobals* bsg, ustring filename, +dispatch_pointcloud_search(BatchedShaderGlobals* bsg, ustringhash filename, const void* wcenter, Wide wradius, int max_points, bool sort, PointCloudSearchResults& results) @@ -217,9 +217,9 @@ dispatch_pointcloud_search(BatchedShaderGlobals* bsg, ustring filename, OSL_FORCEINLINE Mask -default_pointcloud_get(BatchedShaderGlobals* bsg, ustring filename, +default_pointcloud_get(BatchedShaderGlobals* bsg, ustringhash filename, Wide windices, Wide wnum_points, - ustring attr_name, MaskedData wout_data) + ustringhash attr_name, MaskedData wout_data) { #ifdef USE_PARTIO Mask success { false }; @@ -364,9 +364,9 @@ default_pointcloud_get(BatchedShaderGlobals* bsg, ustring filename, OSL_FORCEINLINE Mask -dispatch_pointcloud_get(BatchedShaderGlobals* bsg, ustring filename, +dispatch_pointcloud_get(BatchedShaderGlobals* bsg, ustringhash filename, Wide windices, Wide wnum_points, - ustring attr_name, MaskedData wout_data) + ustringhash attr_name, MaskedData wout_data) { auto* bsr = bsg->uniform.renderer->batched(WidthTag()); if (bsr->is_overridden_pointcloud_get()) { @@ -381,7 +381,7 @@ dispatch_pointcloud_get(BatchedShaderGlobals* bsg, ustring filename, Mask -default_pointcloud_write(BatchedShaderGlobals* bsg, ustring filename, +default_pointcloud_write(BatchedShaderGlobals* bsg, ustringhash filename, Wide wpos, int nattribs, const ustring* attr_names, const TypeDesc* attr_types, const void** ptrs_to_wide_attr_value, Mask mask) @@ -472,7 +472,7 @@ default_pointcloud_write(BatchedShaderGlobals* bsg, ustring filename, OSL_FORCEINLINE Mask -dispatch_pointcloud_write(BatchedShaderGlobals* bsg, ustring filename, +dispatch_pointcloud_write(BatchedShaderGlobals* bsg, ustringhash filename, Wide wpos, int nattribs, const ustring* attr_names, const TypeDesc* attr_types, const void** ptrs_to_wide_attr_value, Mask mask) @@ -518,7 +518,7 @@ __OSL_MASKED_OP(pointcloud_search)( Wide wradius(wradius_); - dispatch_pointcloud_search(bsg, USTR(filename), wcenter_, wradius, + dispatch_pointcloud_search(bsg, USTR(filename).uhash(), wcenter_, wradius, max_points, sort, pcsr); if (nattrs > 0) { @@ -564,7 +564,8 @@ __OSL_MASKED_OP(pointcloud_get)(BatchedShaderGlobals* bsg, const char* filename, TypeDesc attr_type = TYPEDESC(attr_type_); Mask success = dispatch_pointcloud_get( - bsg, USTR(filename), windices, wnum_points, USTR(attr_name), + bsg, USTR(filename).uhash(), windices, wnum_points, + USTR(attr_name).uhash(), MaskedData { attr_type, false, Mask { mask_value }, wout_data_ }); return success.value(); } @@ -574,19 +575,20 @@ __OSL_MASKED_OP(pointcloud_get)(BatchedShaderGlobals* bsg, const char* filename, OSL_BATCHOP int __OSL_MASKED_OP(pointcloud_write)(BatchedShaderGlobals* bsg, const char* filename, const void* wpos_, - int nattribs, const ustring* attr_names, + int nattribs, const ustringrep* attr_names, const TypeDesc* attr_types, const void** ptrs_to_wide_attr_value, int mask_value) { ShadingContext* ctx = bsg->uniform.context; - if (ctx->shadingsys() - .no_pointcloud()) // Debug mode to skip pointcloud expense - return 0; // mask_value; + + // Debug mode to skip pointcloud expense + if (ctx->shadingsys().no_pointcloud()) + return 0; // mask_value; Wide wpos(wpos_); - Mask success = dispatch_pointcloud_write(bsg, USTR(filename), wpos, + Mask success = dispatch_pointcloud_write(bsg, USTR(filename).uhash(), wpos, nattribs, attr_names, attr_types, ptrs_to_wide_attr_value, Mask(mask_value)); diff --git a/src/testrender/optixraytracer.cpp b/src/testrender/optixraytracer.cpp index 6fd35de06..04d23ab4e 100644 --- a/src/testrender/optixraytracer.cpp +++ b/src/testrender/optixraytracer.cpp @@ -882,16 +882,16 @@ OptixRaytracer::good(TextureHandle* handle OSL_MAYBE_UNUSED) /// Given the name of a texture, return an opaque handle that can be /// used with texture calls to avoid the name lookups. RendererServices::TextureHandle* -OptixRaytracer::get_texture_handle(ustring filename OSL_MAYBE_UNUSED, - ShadingContext* shading_context - OSL_MAYBE_UNUSED) +OptixRaytracer::get_texture_handle(ustringhash filename, + ShadingContext* /*shading_context*/) { auto itr = m_samplers.find(filename); if (itr == m_samplers.end()) { // Open image OIIO::ImageBuf image; - if (!image.init_spec(filename, 0, 0)) { - errhandler().errorfmt("Could not load: {}", filename); + if (!image.init_spec(ustring_from(filename), 0, 0)) { + errhandler().errorfmt("Could not load: {} (hash {})", + ustring_from(filename), filename); return (TextureHandle*)nullptr; } diff --git a/src/testrender/optixraytracer.h b/src/testrender/optixraytracer.h index 4180dd064..120ce95a0 100644 --- a/src/testrender/optixraytracer.h +++ b/src/testrender/optixraytracer.h @@ -28,7 +28,7 @@ class OptixRaytracer final : public SimpleRaytracer { uint64_t register_global(const std::string& str, uint64_t value); bool fetch_global(const std::string& str, uint64_t* value); - virtual int supports(string_view feature) const + int supports(string_view feature) const override { if (feature == "OptiX") return true; @@ -38,24 +38,24 @@ class OptixRaytracer final : public SimpleRaytracer { std::string load_ptx_file(string_view filename); bool synch_attributes(); - virtual bool init_optix_context(int xres, int yres); - virtual bool make_optix_materials(); - virtual bool finalize_scene(); - virtual void prepare_render(); - virtual void warmup(); - virtual void render(int xres, int yres); - virtual void finalize_pixel_buffer(); - virtual void clear(); + bool init_optix_context(int xres, int yres); + bool make_optix_materials(); + bool finalize_scene(); + void prepare_render() override; + void warmup() override; + void render(int xres, int yres) override; + void finalize_pixel_buffer() override; + void clear() override; /// Return true if the texture handle (previously returned by /// get_texture_handle()) is a valid texture that can be subsequently /// read or sampled. - virtual bool good(TextureHandle* handle); + bool good(TextureHandle* handle) override; /// Given the name of a texture, return an opaque handle that can be /// used with texture calls to avoid the name lookups. - virtual TextureHandle* get_texture_handle(ustring filename, - ShadingContext* shading_context); + TextureHandle* get_texture_handle(ustringhash filename, + ShadingContext* shading_context) override; // Easy way to do Optix calls optix::Context& optix_ctx() { return m_optix_ctx; } @@ -93,8 +93,8 @@ class OptixRaytracer final : public SimpleRaytracer { OptixProgramGroup* pg); std::string m_materials_ptx; - std::unordered_map m_samplers; - std::unordered_map m_globals_map; + std::unordered_map m_samplers; + std::unordered_map m_globals_map; }; diff --git a/src/testrender/simpleraytracer.cpp b/src/testrender/simpleraytracer.cpp index 4e242a316..cd58af4bd 100644 --- a/src/testrender/simpleraytracer.cpp +++ b/src/testrender/simpleraytracer.cpp @@ -441,7 +441,7 @@ SimpleRaytracer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool SimpleRaytracer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring from, float /*time*/) + ustringhash from, float /*time*/) { TransformMap::const_iterator found = m_named_xforms.find(from); if (found != m_named_xforms.end()) { @@ -468,7 +468,7 @@ SimpleRaytracer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool SimpleRaytracer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring from) + ustringhash from) { // SimpleRaytracer doesn't understand motion blur, so we never fail // on account of time-varying transformations. @@ -485,7 +485,7 @@ SimpleRaytracer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool SimpleRaytracer::get_inverse_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring to, float /*time*/) + ustringhash to, float /*time*/) { if (to == u_camera || to == u_screen || to == u_NDC || to == u_raster) { // clang-format off @@ -544,15 +544,15 @@ void SimpleRaytracer::name_transform(const char* name, const OSL::Matrix44& xform) { std::shared_ptr M(new OSL::Matrix44(xform)); - m_named_xforms[ustring(name)] = M; + m_named_xforms[ustringhash(name)] = M; } bool SimpleRaytracer::get_array_attribute(ShaderGlobals* sg, bool derivatives, - ustring object, TypeDesc type, - ustring name, int index, void* val) + ustringhash object, TypeDesc type, + ustringhash name, int index, void* val) { AttrGetterMap::const_iterator g = m_attr_getters.find(name); if (g != m_attr_getters.end()) { @@ -572,8 +572,8 @@ SimpleRaytracer::get_array_attribute(ShaderGlobals* sg, bool derivatives, bool SimpleRaytracer::get_attribute(ShaderGlobals* sg, bool derivatives, - ustring object, TypeDesc type, ustring name, - void* val) + ustringhash object, TypeDesc type, + ustringhash name, void* val) { return get_array_attribute(sg, derivatives, object, type, name, -1, val); } @@ -581,7 +581,7 @@ SimpleRaytracer::get_attribute(ShaderGlobals* sg, bool derivatives, bool -SimpleRaytracer::get_userdata(bool derivatives, ustring name, TypeDesc type, +SimpleRaytracer::get_userdata(bool derivatives, ustringhash name, TypeDesc type, ShaderGlobals* sg, void* val) { // Just to illustrate how this works, respect s and t userdata, filled @@ -612,8 +612,8 @@ SimpleRaytracer::get_userdata(bool derivatives, ustring name, TypeDesc type, bool SimpleRaytracer::get_osl_version(ShaderGlobals* /*sg*/, bool /*derivs*/, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeInt) { ((int*)val)[0] = OSL_VERSION; @@ -625,8 +625,8 @@ SimpleRaytracer::get_osl_version(ShaderGlobals* /*sg*/, bool /*derivs*/, bool SimpleRaytracer::get_camera_resolution(ShaderGlobals* /*sg*/, bool /*derivs*/, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeIntArray2) { ((int*)val)[0] = camera.xres; @@ -639,8 +639,8 @@ SimpleRaytracer::get_camera_resolution(ShaderGlobals* /*sg*/, bool /*derivs*/, bool SimpleRaytracer::get_camera_projection(ShaderGlobals* /*sg*/, bool /*derivs*/, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeString) { ((ustring*)val)[0] = m_projection; @@ -652,8 +652,8 @@ SimpleRaytracer::get_camera_projection(ShaderGlobals* /*sg*/, bool /*derivs*/, bool SimpleRaytracer::get_camera_fov(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { // N.B. in a real renderer, this may be time-dependent if (type == TypeDesc::TypeFloat) { @@ -668,8 +668,8 @@ SimpleRaytracer::get_camera_fov(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRaytracer::get_camera_pixelaspect(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_pixelaspect; @@ -683,8 +683,8 @@ SimpleRaytracer::get_camera_pixelaspect(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRaytracer::get_camera_clip(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeFloatArray2) { ((float*)val)[0] = m_hither; @@ -699,8 +699,8 @@ SimpleRaytracer::get_camera_clip(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRaytracer::get_camera_clip_near(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_hither; @@ -714,8 +714,8 @@ SimpleRaytracer::get_camera_clip_near(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRaytracer::get_camera_clip_far(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_yon; @@ -730,8 +730,8 @@ SimpleRaytracer::get_camera_clip_far(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRaytracer::get_camera_shutter(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeFloatArray2) { ((float*)val)[0] = m_shutter[0]; @@ -746,8 +746,8 @@ SimpleRaytracer::get_camera_shutter(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRaytracer::get_camera_shutter_open(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_shutter[0]; @@ -761,8 +761,8 @@ SimpleRaytracer::get_camera_shutter_open(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRaytracer::get_camera_shutter_close(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_shutter[1]; @@ -776,8 +776,8 @@ SimpleRaytracer::get_camera_shutter_close(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRaytracer::get_camera_screen_window(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { // N.B. in a real renderer, this may be time-dependent if (type == TypeFloatArray4) { diff --git a/src/testrender/simpleraytracer.h b/src/testrender/simpleraytracer.h index 3b96722d1..1c81902ce 100644 --- a/src/testrender/simpleraytracer.h +++ b/src/testrender/simpleraytracer.h @@ -30,23 +30,23 @@ class SimpleRaytracer : public RendererServices { virtual ~SimpleRaytracer() {} // RendererServices support: - virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, - TransformationPtr xform, float time); - virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, ustring from, - float time); - virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, - TransformationPtr xform); - virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, ustring from); - virtual bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, - ustring to, float time); - virtual bool get_array_attribute(ShaderGlobals* sg, bool derivatives, - ustring object, TypeDesc type, - ustring name, int index, void* val); - virtual bool get_attribute(ShaderGlobals* sg, bool derivatives, - ustring object, TypeDesc type, ustring name, - void* val); - virtual bool get_userdata(bool derivatives, ustring name, TypeDesc type, - ShaderGlobals* sg, void* val); + bool get_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform, float time) override; + bool get_matrix(ShaderGlobals* sg, Matrix44& result, ustringhash from, + float time) override; + bool get_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform) override; + bool get_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash from) override; + bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, ustringhash to, + float time) override; + bool get_array_attribute(ShaderGlobals* sg, bool derivatives, + ustringhash object, TypeDesc type, + ustringhash name, int index, void* val) override; + bool get_attribute(ShaderGlobals* sg, bool derivatives, ustringhash object, + TypeDesc type, ustringhash name, void* val) override; + bool get_userdata(bool derivatives, ustringhash name, TypeDesc type, + ShaderGlobals* sg, void* val) override; void name_transform(const char* name, const Transformation& xform); @@ -121,7 +121,7 @@ class SimpleRaytracer : public RendererServices { bool m_had_error = false; // Named transforms - typedef std::map> TransformMap; + typedef std::map> TransformMap; TransformMap m_named_xforms; // Attribute and userdata retrieval -- for fast dispatch, use a hash @@ -130,38 +130,44 @@ class SimpleRaytracer : public RendererServices { // renderer, we would encourage benchmarking various methods and // alternate data structures. typedef bool (SimpleRaytracer::*AttrGetter)(ShaderGlobals* sg, bool derivs, - ustring object, TypeDesc type, - ustring name, void* val); - typedef std::unordered_map AttrGetterMap; + ustringhash object, + TypeDesc type, ustringhash name, + void* val); + typedef std::unordered_map AttrGetterMap; AttrGetterMap m_attr_getters; // Attribute getters - bool get_osl_version(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_resolution(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_projection(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_fov(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_pixelaspect(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_clip(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_clip_near(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_clip_far(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_shutter(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_shutter_open(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); + bool get_osl_version(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_resolution(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); + bool get_camera_projection(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); + bool get_camera_fov(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_pixelaspect(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); + bool get_camera_clip(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_clip_near(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); + bool get_camera_clip_far(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_shutter(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_shutter_open(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); bool get_camera_shutter_close(ShaderGlobals* sg, bool derivs, - ustring object, TypeDesc type, ustring name, - void* val); + ustringhash object, TypeDesc type, + ustringhash name, void* val); bool get_camera_screen_window(ShaderGlobals* sg, bool derivs, - ustring object, TypeDesc type, ustring name, - void* val); + ustringhash object, TypeDesc type, + ustringhash name, void* val); // CPU renderer helpers void globals_from_hit(ShaderGlobals& sg, const Ray& r, diff --git a/src/testshade/batched_simplerend.cpp b/src/testshade/batched_simplerend.cpp index abaf3fdd5..159cba498 100644 --- a/src/testshade/batched_simplerend.cpp +++ b/src/testshade/batched_simplerend.cpp @@ -195,7 +195,7 @@ template typename BatchedSimpleRenderer::Mask BatchedSimpleRenderer::get_matrix(BatchedShaderGlobals* /*bsg*/, Masked wresult, - ustring from, + ustringhash from, Wide /*wtime*/) { auto found = m_sr.m_named_xforms.find(from); @@ -219,14 +219,14 @@ template typename BatchedSimpleRenderer::Mask BatchedSimpleRenderer::get_matrix(BatchedShaderGlobals* /*bsg*/, Masked wresult, - Wide wfrom, + Wide wfrom, Wide /*wtime*/) { Mask succeeded(false); wresult.mask().template foreach<1 /*MinOccupancyT*/>( [&](ActiveLane lane) -> void { - ustring from = wfrom[lane]; - auto found = m_sr.m_named_xforms.find(from); + ustringhash from = wfrom[lane]; + auto found = m_sr.m_named_xforms.find(from); if (found != m_sr.m_named_xforms.end()) { const Matrix44& transform = *(found->second); wresult[lane] = transform; @@ -242,7 +242,7 @@ template template bool BatchedSimpleRenderer::impl_get_inverse_matrix(RAccessorT& result, - ustring to) const + ustringhash to) const { if (to == ucache().camera || to == ucache().screen || to == ucache().NDC || to == ucache().raster) { @@ -304,7 +304,7 @@ template typename BatchedSimpleRenderer::Mask BatchedSimpleRenderer::get_inverse_matrix(BatchedShaderGlobals* bsg, Masked result, - ustring to, + ustringhash to, Wide time) { Matrix44 scalar_result; @@ -326,7 +326,7 @@ template typename BatchedSimpleRenderer::Mask BatchedSimpleRenderer::get_inverse_matrix(BatchedShaderGlobals* bsg, Masked wResult, - Wide wTo, + Wide wTo, Wide wTime) { @@ -334,8 +334,8 @@ BatchedSimpleRenderer::get_inverse_matrix(BatchedShaderGlobals* bsg, for (int i = 0; i < WidthT; ++i) { if (wResult.mask()[i]) { - ustring to = wTo[i]; - auto result = wResult[i]; + ustringhash to = wTo[i]; + auto result = wResult[i]; if (impl_get_inverse_matrix(result, to)) { status.set_on(i); } @@ -391,31 +391,32 @@ BatchedSimpleRenderer::trace( template void BatchedSimpleRenderer::getmessage(BatchedShaderGlobals* bsg, - Masked result, ustring source, - ustring name, MaskedData val) + Masked result, + ustringhash source, ustringhash name, + MaskedData val) { - OSL_ASSERT(source == ustring("trace")); + OSL_ASSERT(source == "trace"); for (int lane = 0; lane < WidthT; ++lane) { if (bsg->varying.u[lane] > 0.5) { - if (name == ustring("hitdist")) { + if (name == "hitdist") { if (Masked::is(val)) { Masked dest(val); dest[lane] = 0.5; } } - if (name == ustring("hit")) { + if (name == "hit") { if (Masked::is(val)) { Masked dest(val); dest[lane] = 1; } } - if (name == ustring("geom:name")) { + if (name == "geom:name") { if (Masked::is(val)) { Masked dest(val); dest[lane] = ustring("teapot"); } } - if (name == ustring("N")) { + if (name == "N") { if (Masked::is(val)) { Masked dest(val); dest[lane] = Vec3(1.0 - bsg->varying.v[lane], 0.25, @@ -427,7 +428,7 @@ BatchedSimpleRenderer::getmessage(BatchedShaderGlobals* bsg, result[lane] = 1; } else { - if (name == ustring("hit")) { + if (name == "hit") { if (Masked::is(val)) { Masked dest(val); dest[lane] = 0; @@ -444,8 +445,9 @@ BatchedSimpleRenderer::getmessage(BatchedShaderGlobals* bsg, template typename BatchedSimpleRenderer::Mask BatchedSimpleRenderer::get_array_attribute(BatchedShaderGlobals* bsg, - ustring object, ustring name, - int index, MaskedData val) + ustringhash object, + ustringhash name, int index, + MaskedData val) { // Normally the common_get_attribute would be for is_attribute_uniform() == true only // However a name that has a uniform answer could be part of a varying name inside @@ -551,8 +553,8 @@ BatchedSimpleRenderer::get_array_attribute(BatchedShaderGlobals* bsg, template typename BatchedSimpleRenderer::Mask BatchedSimpleRenderer::get_attribute(BatchedShaderGlobals* bsg, - ustring object, ustring name, - MaskedData val) + ustringhash object, + ustringhash name, MaskedData val) { return get_array_attribute(bsg, object, name, -1, val); } @@ -562,7 +564,7 @@ BatchedSimpleRenderer::get_attribute(BatchedShaderGlobals* bsg, template bool BatchedSimpleRenderer::get_array_attribute_uniform( - BatchedShaderGlobals* bsg, ustring object, ustring name, int index, + BatchedShaderGlobals* bsg, ustringhash object, ustringhash name, int index, RefData val) { ASSERT(!name.empty()); @@ -617,8 +619,9 @@ BatchedSimpleRenderer::get_array_attribute_uniform( template bool BatchedSimpleRenderer::get_attribute_uniform(BatchedShaderGlobals* bsg, - ustring object, - ustring name, RefData val) + ustringhash object, + ustringhash name, + RefData val) { return get_array_attribute_uniform(bsg, object, name, -1, val); } @@ -627,7 +630,7 @@ BatchedSimpleRenderer::get_attribute_uniform(BatchedShaderGlobals* bsg, template typename BatchedSimpleRenderer::Mask -BatchedSimpleRenderer::get_userdata(ustring name, +BatchedSimpleRenderer::get_userdata(ustringhash name, BatchedShaderGlobals* bsg, MaskedData val) { @@ -746,8 +749,8 @@ assign_and_zero_derivs(MaskedData data, const DataT& val) template template bool -BatchedSimpleRenderer::get_osl_version(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_osl_version(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, int(OSL_VERSION)); @@ -758,8 +761,8 @@ BatchedSimpleRenderer::get_osl_version(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_resolution(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_resolution(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { int res[2] = { m_sr.m_xres, m_sr.m_yres }; @@ -771,8 +774,8 @@ BatchedSimpleRenderer::get_camera_resolution(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_projection(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_projection(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, m_sr.m_projection); @@ -783,8 +786,8 @@ BatchedSimpleRenderer::get_camera_projection(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_fov(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_fov(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { // N.B. in a real renderer, this may be time-dependent @@ -796,8 +799,8 @@ BatchedSimpleRenderer::get_camera_fov(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_pixelaspect(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_pixelaspect(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, m_sr.m_pixelaspect); @@ -808,8 +811,8 @@ BatchedSimpleRenderer::get_camera_pixelaspect(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_clip(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_clip(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { float clip[2] = { m_sr.m_hither, m_sr.m_yon }; @@ -821,8 +824,8 @@ BatchedSimpleRenderer::get_camera_clip(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_clip_near(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_clip_near(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, m_sr.m_hither); @@ -833,8 +836,8 @@ BatchedSimpleRenderer::get_camera_clip_near(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_clip_far(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_clip_far(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, m_sr.m_yon); @@ -845,8 +848,8 @@ BatchedSimpleRenderer::get_camera_clip_far(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_shutter(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_shutter(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, m_sr.m_shutter); @@ -857,8 +860,8 @@ BatchedSimpleRenderer::get_camera_shutter(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_shutter_open(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_shutter_open(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, m_sr.m_shutter[0]); @@ -869,8 +872,8 @@ BatchedSimpleRenderer::get_camera_shutter_open(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_shutter_close(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_shutter_close(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, m_sr.m_shutter[1]); @@ -881,8 +884,8 @@ BatchedSimpleRenderer::get_camera_shutter_close(ustring /*object*/, template template bool -BatchedSimpleRenderer::get_camera_screen_window(ustring /*object*/, - ustring /*name*/, +BatchedSimpleRenderer::get_camera_screen_window(ustringhash /*object*/, + ustringhash /*name*/, RefOrMaskedT data) { return assign_and_zero_derivs(data, m_sr.m_screen_window); diff --git a/src/testshade/batched_simplerend.h b/src/testshade/batched_simplerend.h index 487007cf4..e740dfbe0 100644 --- a/src/testshade/batched_simplerend.h +++ b/src/testshade/batched_simplerend.h @@ -37,25 +37,26 @@ class BatchedSimpleRenderer : public BatchedRendererServices { } Mask get_matrix(BatchedShaderGlobals* bsg, Masked result, - ustring from, Wide time) override; + ustringhash from, Wide time) override; Mask get_matrix(BatchedShaderGlobals* bsg, Masked result, - Wide from, Wide time) override; + Wide from, + Wide time) override; bool is_overridden_get_matrix_WmWsWf() const override { return true; } private: template OSL_FORCEINLINE bool impl_get_inverse_matrix(RAccessorT& result, - ustring to) const; + ustringhash to) const; public: Mask get_inverse_matrix(BatchedShaderGlobals* bsg, Masked result, - ustring to, Wide time) override; + ustringhash to, Wide time) override; bool is_overridden_get_inverse_matrix_WmsWf() const override { return true; } Mask get_inverse_matrix(BatchedShaderGlobals* bsg, Masked result, - Wide to, + Wide to, Wide time) override; bool is_overridden_get_inverse_matrix_WmWsWf() const override { @@ -65,21 +66,22 @@ class BatchedSimpleRenderer : public BatchedRendererServices { bool is_attribute_uniform(ustring object, ustring name) override; - Mask get_array_attribute(BatchedShaderGlobals* bsg, ustring object, - ustring name, int index, MaskedData amd) override; + Mask get_array_attribute(BatchedShaderGlobals* bsg, ustringhash object, + ustringhash name, int index, + MaskedData amd) override; - Mask get_attribute(BatchedShaderGlobals* bsg, ustring object, ustring name, - MaskedData amd) override; + Mask get_attribute(BatchedShaderGlobals* bsg, ustringhash object, + ustringhash name, MaskedData amd) override; - bool get_array_attribute_uniform(BatchedShaderGlobals* bsg, ustring object, - ustring name, int index, - RefData val) override; + bool get_array_attribute_uniform(BatchedShaderGlobals* bsg, + ustringhash object, ustringhash name, + int index, RefData val) override; - bool get_attribute_uniform(BatchedShaderGlobals* bsg, ustring object, - ustring name, RefData val) override; + bool get_attribute_uniform(BatchedShaderGlobals* bsg, ustringhash object, + ustringhash name, RefData val) override; - Mask get_userdata(ustring name, BatchedShaderGlobals* bsg, + Mask get_userdata(ustringhash name, BatchedShaderGlobals* bsg, MaskedData val) override; bool is_overridden_texture() const override { return false; } @@ -95,7 +97,8 @@ class BatchedSimpleRenderer : public BatchedRendererServices { Wide dRdy) override; void getmessage(BatchedShaderGlobals* bsg, Masked result, - ustring source, ustring name, MaskedData val) override; + ustringhash source, ustringhash name, + MaskedData val) override; private: SimpleRenderer& m_sr; @@ -107,46 +110,56 @@ class BatchedSimpleRenderer : public BatchedRendererServices { // imagine this to be fairly quick, but for a performance-critical // renderer, we would encourage benchmarking various methods and // alternate data structures. - typedef bool (BatchedSimpleRenderer::*VaryingAttrGetter)(ustring object, - ustring name, + typedef bool (BatchedSimpleRenderer::*VaryingAttrGetter)(ustringhash object, + ustringhash name, MaskedData val); - typedef std::unordered_map VaryingAttrGetterMap; + typedef std::unordered_map + VaryingAttrGetterMap; VaryingAttrGetterMap m_varying_attr_getters; - typedef bool (BatchedSimpleRenderer::*UniformAttrGetter)(ustring object, - ustring name, + typedef bool (BatchedSimpleRenderer::*UniformAttrGetter)(ustringhash object, + ustringhash name, RefData val); - typedef std::unordered_map UniformAttrGetterMap; + typedef std::unordered_map + UniformAttrGetterMap; UniformAttrGetterMap m_uniform_attr_getters; // Attribute getters template - bool get_osl_version(ustring object, ustring name, RefOrMaskedT data); + bool get_osl_version(ustringhash object, ustringhash name, + RefOrMaskedT data); template - bool get_camera_resolution(ustring object, ustring name, RefOrMaskedT data); + bool get_camera_resolution(ustringhash object, ustringhash name, + RefOrMaskedT data); template - bool get_camera_projection(ustring object, ustring name, RefOrMaskedT data); + bool get_camera_projection(ustringhash object, ustringhash name, + RefOrMaskedT data); template - bool get_camera_fov(ustring object, ustring name, RefOrMaskedT data); + bool get_camera_fov(ustringhash object, ustringhash name, + RefOrMaskedT data); template - bool get_camera_pixelaspect(ustring object, ustring name, + bool get_camera_pixelaspect(ustringhash object, ustringhash name, RefOrMaskedT data); template - bool get_camera_clip(ustring object, ustring name, RefOrMaskedT data); + bool get_camera_clip(ustringhash object, ustringhash name, + RefOrMaskedT data); template - bool get_camera_clip_near(ustring object, ustring name, RefOrMaskedT data); + bool get_camera_clip_near(ustringhash object, ustringhash name, + RefOrMaskedT data); template - bool get_camera_clip_far(ustring object, ustring name, RefOrMaskedT data); + bool get_camera_clip_far(ustringhash object, ustringhash name, + RefOrMaskedT data); template - bool get_camera_shutter(ustring object, ustring name, RefOrMaskedT data); + bool get_camera_shutter(ustringhash object, ustringhash name, + RefOrMaskedT data); template - bool get_camera_shutter_open(ustring object, ustring name, + bool get_camera_shutter_open(ustringhash object, ustringhash name, RefOrMaskedT data); template - bool get_camera_shutter_close(ustring object, ustring name, + bool get_camera_shutter_close(ustringhash object, ustringhash name, RefOrMaskedT data); template - bool get_camera_screen_window(ustring object, ustring name, + bool get_camera_screen_window(ustringhash object, ustringhash name, RefOrMaskedT data); }; diff --git a/src/testshade/optixgridrender.cpp b/src/testshade/optixgridrender.cpp index f46339d2a..4128c2180 100644 --- a/src/testshade/optixgridrender.cpp +++ b/src/testshade/optixgridrender.cpp @@ -684,16 +684,16 @@ OptixGridRenderer::good(TextureHandle* handle OSL_MAYBE_UNUSED) /// Given the name of a texture, return an opaque handle that can be /// used with texture calls to avoid the name lookups. RendererServices::TextureHandle* -OptixGridRenderer::get_texture_handle(ustring filename OSL_MAYBE_UNUSED, - ShadingContext* shading_context - OSL_MAYBE_UNUSED) +OptixGridRenderer::get_texture_handle(ustringhash filename, + ShadingContext* /*shading_context*/) { auto itr = m_samplers.find(filename); if (itr == m_samplers.end()) { // Open image OIIO::ImageBuf image; - if (!image.init_spec(filename, 0, 0)) { - errhandler().errorfmt("Could not load: {}", filename); + if (!image.init_spec(ustring_from(filename), 0, 0)) { + errhandler().errorfmt("Could not load: {} (hash {})", + ustring_from(filename), filename); return (TextureHandle*)nullptr; } diff --git a/src/testshade/optixgridrender.h b/src/testshade/optixgridrender.h index fabc3f3dc..c4ccfd005 100644 --- a/src/testshade/optixgridrender.h +++ b/src/testshade/optixgridrender.h @@ -28,7 +28,7 @@ class OptixGridRenderer final : public SimpleRenderer { uint64_t register_global(const std::string& str, uint64_t value); bool fetch_global(const std::string& str, uint64_t* value); - virtual int supports(string_view feature) const + int supports(string_view feature) const override { if (feature == "OptiX") return true; @@ -38,15 +38,15 @@ class OptixGridRenderer final : public SimpleRenderer { std::string load_ptx_file(string_view filename); bool synch_attributes(); - virtual void init_shadingsys(ShadingSystem* ss); - virtual bool init_optix_context(int xres, int yres); - virtual bool make_optix_materials(); - virtual bool finalize_scene(); - virtual void prepare_render(); - virtual void warmup(); - virtual void render(int xres, int yres); - virtual void finalize_pixel_buffer(); - virtual void clear(); + void init_shadingsys(ShadingSystem* ss) final; + bool init_optix_context(int xres, int yres); + bool make_optix_materials(); + bool finalize_scene(); + void prepare_render() final; + void warmup() final; + void render(int xres, int yres) final; + void finalize_pixel_buffer() final; + void clear() final; virtual void set_transforms(const OSL::Matrix44& object2common, const OSL::Matrix44& shader2common); @@ -56,12 +56,12 @@ class OptixGridRenderer final : public SimpleRenderer { /// Return true if the texture handle (previously returned by /// get_texture_handle()) is a valid texture that can be subsequently /// read or sampled. - virtual bool good(TextureHandle* handle); + bool good(TextureHandle* handle) override; /// Given the name of a texture, return an opaque handle that can be /// used with texture calls to avoid the name lookups. - virtual TextureHandle* get_texture_handle(ustring filename, - ShadingContext* shading_context); + TextureHandle* get_texture_handle(ustringhash filename, + ShadingContext* shading_context) override; OptixDeviceContext optix_ctx() { return m_optix_ctx; } OptixDeviceContext context() { return m_optix_ctx; } @@ -90,8 +90,8 @@ class OptixGridRenderer final : public SimpleRenderer { const unsigned long OSL_PRINTF_BUFFER_SIZE = 8 * 1024 * 1024; std::string m_materials_ptx; - std::unordered_map m_samplers; - std::unordered_map m_globals_map; + std::unordered_map m_samplers; + std::unordered_map m_globals_map; OSL::Matrix44 m_shader2common; // "shader" space to "common" space matrix OSL::Matrix44 m_object2common; // "object" space to "common" space matrix diff --git a/src/testshade/simplerend.cpp b/src/testshade/simplerend.cpp index 5025c3508..7d0c9e31a 100644 --- a/src/testshade/simplerend.cpp +++ b/src/testshade/simplerend.cpp @@ -310,7 +310,7 @@ SimpleRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool SimpleRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring from, float /*time*/) + ustringhash from, float /*time*/) { TransformMap::const_iterator found = m_named_xforms.find(from); if (found != m_named_xforms.end()) { @@ -337,7 +337,7 @@ SimpleRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool SimpleRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring from) + ustringhash from) { // SimpleRenderer doesn't understand motion blur, so we never fail // on account of time-varying transformations. @@ -354,7 +354,7 @@ SimpleRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool SimpleRenderer::get_inverse_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring to, float /*time*/) + ustringhash to, float /*time*/) { if (to == u_camera || to == u_screen || to == u_NDC || to == u_raster) { Matrix44 M = m_world_to_camera; @@ -408,15 +408,15 @@ void SimpleRenderer::name_transform(const char* name, const OSL::Matrix44& xform) { std::shared_ptr M(new OSL::Matrix44(xform)); - m_named_xforms[ustring(name)] = M; + m_named_xforms[ustringhash(name)] = M; } bool SimpleRenderer::get_array_attribute(ShaderGlobals* sg, bool derivatives, - ustring object, TypeDesc type, ustring name, - int index, void* val) + ustringhash object, TypeDesc type, + ustringhash name, int index, void* val) { AttrGetterMap::const_iterator g = m_attr_getters.find(name); if (g != m_attr_getters.end()) { @@ -444,8 +444,8 @@ SimpleRenderer::get_array_attribute(ShaderGlobals* sg, bool derivatives, bool SimpleRenderer::get_attribute(ShaderGlobals* sg, bool derivatives, - ustring object, TypeDesc type, ustring name, - void* val) + ustringhash object, TypeDesc type, + ustringhash name, void* val) { return get_array_attribute(sg, derivatives, object, type, name, -1, val); } @@ -453,7 +453,7 @@ SimpleRenderer::get_attribute(ShaderGlobals* sg, bool derivatives, bool -SimpleRenderer::get_userdata(bool derivatives, ustring name, TypeDesc type, +SimpleRenderer::get_userdata(bool derivatives, ustringhash name, TypeDesc type, ShaderGlobals* sg, void* val) { // Just to illustrate how this works, respect s and t userdata, filled @@ -508,10 +508,14 @@ SimpleRenderer::trace(TraceOpt& options, ShaderGlobals* sg, const OSL::Vec3& P, } } + bool -SimpleRenderer::getmessage(ShaderGlobals* sg, ustring source, ustring name, - TypeDesc type, void* val, bool derivatives) +SimpleRenderer::getmessage(ShaderGlobals* sg, ustringhash source_, + ustringhash name_, TypeDesc type, void* val, + bool derivatives) { + ustring source = ustring_from(source_); + ustring name = ustring_from(name_); OSL_ASSERT(source == ustring("trace")); // Don't have any real ray tracing results // so just fill in some repeatable values for testsuite @@ -552,10 +556,11 @@ SimpleRenderer::getmessage(ShaderGlobals* sg, ustring source, ustring name, } + bool SimpleRenderer::get_osl_version(ShaderGlobals* /*sg*/, bool /*derivs*/, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeInt) { ((int*)val)[0] = OSL_VERSION; @@ -567,8 +572,8 @@ SimpleRenderer::get_osl_version(ShaderGlobals* /*sg*/, bool /*derivs*/, bool SimpleRenderer::get_camera_resolution(ShaderGlobals* /*sg*/, bool /*derivs*/, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeIntArray2) { ((int*)val)[0] = m_xres; @@ -581,8 +586,8 @@ SimpleRenderer::get_camera_resolution(ShaderGlobals* /*sg*/, bool /*derivs*/, bool SimpleRenderer::get_camera_projection(ShaderGlobals* /*sg*/, bool /*derivs*/, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeString) { ((ustring*)val)[0] = m_projection; @@ -594,8 +599,8 @@ SimpleRenderer::get_camera_projection(ShaderGlobals* /*sg*/, bool /*derivs*/, bool SimpleRenderer::get_camera_fov(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { // N.B. in a real renderer, this may be time-dependent if (type == TypeDesc::TypeFloat) { @@ -610,8 +615,8 @@ SimpleRenderer::get_camera_fov(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRenderer::get_camera_pixelaspect(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_pixelaspect; @@ -625,8 +630,8 @@ SimpleRenderer::get_camera_pixelaspect(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRenderer::get_camera_clip(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeFloatArray2) { ((float*)val)[0] = m_hither; @@ -641,8 +646,8 @@ SimpleRenderer::get_camera_clip(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRenderer::get_camera_clip_near(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_hither; @@ -656,8 +661,8 @@ SimpleRenderer::get_camera_clip_near(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRenderer::get_camera_clip_far(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_yon; @@ -672,8 +677,8 @@ SimpleRenderer::get_camera_clip_far(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRenderer::get_camera_shutter(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeFloatArray2) { ((float*)val)[0] = m_shutter[0]; @@ -688,8 +693,8 @@ SimpleRenderer::get_camera_shutter(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRenderer::get_camera_shutter_open(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_shutter[0]; @@ -703,8 +708,8 @@ SimpleRenderer::get_camera_shutter_open(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRenderer::get_camera_shutter_close(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { if (type == TypeDesc::TypeFloat) { ((float*)val)[0] = m_shutter[1]; @@ -718,8 +723,8 @@ SimpleRenderer::get_camera_shutter_close(ShaderGlobals* /*sg*/, bool derivs, bool SimpleRenderer::get_camera_screen_window(ShaderGlobals* /*sg*/, bool derivs, - ustring /*object*/, TypeDesc type, - ustring /*name*/, void* val) + ustringhash /*object*/, TypeDesc type, + ustringhash /*name*/, void* val) { // N.B. in a real renderer, this may be time-dependent if (type == TypeFloatArray4) { diff --git a/src/testshade/simplerend.h b/src/testshade/simplerend.h index 630b955a1..6272e5eff 100644 --- a/src/testshade/simplerend.h +++ b/src/testshade/simplerend.h @@ -40,35 +40,34 @@ class SimpleRenderer : public RendererServices { // Ensure destructor is in .cpp ~SimpleRenderer(); - virtual int supports(string_view feature) const; - virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, - TransformationPtr xform, float time); - virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, ustring from, - float time); - virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, - TransformationPtr xform); - virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, ustring from); - virtual bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, - ustring to, float time); + int supports(string_view feature) const override; + bool get_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform, float time) override; + bool get_matrix(ShaderGlobals* sg, Matrix44& result, ustringhash from, + float time) override; + bool get_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform) override; + bool get_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash from) override; + bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, ustringhash to, + float time) override; void name_transform(const char* name, const Transformation& xform); - virtual bool get_array_attribute(ShaderGlobals* sg, bool derivatives, - ustring object, TypeDesc type, - ustring name, int index, void* val); - virtual bool get_attribute(ShaderGlobals* sg, bool derivatives, - ustring object, TypeDesc type, ustring name, - void* val); - virtual bool get_userdata(bool derivatives, ustring name, TypeDesc type, - ShaderGlobals* sg, void* val); + bool get_array_attribute(ShaderGlobals* sg, bool derivatives, + ustringhash object, TypeDesc type, + ustringhash name, int index, void* val) override; + bool get_attribute(ShaderGlobals* sg, bool derivatives, ustringhash object, + TypeDesc type, ustringhash name, void* val) override; + bool get_userdata(bool derivatives, ustringhash name, TypeDesc type, + ShaderGlobals* sg, void* val) override; - virtual bool trace(TraceOpt& options, ShaderGlobals* sg, const OSL::Vec3& P, - const OSL::Vec3& dPdx, const OSL::Vec3& dPdy, - const OSL::Vec3& R, const OSL::Vec3& dRdx, - const OSL::Vec3& dRdy); + bool trace(TraceOpt& options, ShaderGlobals* sg, const OSL::Vec3& P, + const OSL::Vec3& dPdx, const OSL::Vec3& dPdy, const OSL::Vec3& R, + const OSL::Vec3& dRdx, const OSL::Vec3& dRdy) override; - virtual bool getmessage(ShaderGlobals* sg, ustring source, ustring name, - TypeDesc type, void* val, bool derivatives); + bool getmessage(ShaderGlobals* sg, ustringhash source, ustringhash name, + TypeDesc type, void* val, bool derivatives) override; // Set and get renderer attributes/options @@ -143,11 +142,11 @@ class SimpleRenderer : public RendererServices { OIIO::ParamValueList userdata; #if OSL_USE_BATCHED - virtual BatchedRendererServices<16>* batched(WidthOf<16>) + BatchedRendererServices<16>* batched(WidthOf<16>) override { return &m_batch_16_simple_renderer; } - virtual BatchedRendererServices<8>* batched(WidthOf<8>) + BatchedRendererServices<8>* batched(WidthOf<8>) override { return &m_batch_8_simple_renderer; } @@ -172,7 +171,7 @@ class SimpleRenderer : public RendererServices { std::unique_ptr m_errhandler { new OIIO::ErrorHandler }; // Named transforms - typedef std::map> TransformMap; + typedef std::map> TransformMap; TransformMap m_named_xforms; // Attribute and userdata retrieval -- for fast dispatch, use a hash @@ -181,38 +180,44 @@ class SimpleRenderer : public RendererServices { // renderer, we would encourage benchmarking various methods and // alternate data structures. typedef bool (SimpleRenderer::*AttrGetter)(ShaderGlobals* sg, bool derivs, - ustring object, TypeDesc type, - ustring name, void* val); - typedef std::unordered_map AttrGetterMap; + ustringhash object, + TypeDesc type, ustringhash name, + void* val); + typedef std::unordered_map AttrGetterMap; AttrGetterMap m_attr_getters; // Attribute getters - bool get_osl_version(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_resolution(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_projection(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_fov(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_pixelaspect(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_clip(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_clip_near(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_clip_far(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_shutter(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); - bool get_camera_shutter_open(ShaderGlobals* sg, bool derivs, ustring object, - TypeDesc type, ustring name, void* val); + bool get_osl_version(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_resolution(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); + bool get_camera_projection(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); + bool get_camera_fov(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_pixelaspect(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); + bool get_camera_clip(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_clip_near(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); + bool get_camera_clip_far(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_shutter(ShaderGlobals* sg, bool derivs, ustringhash object, + TypeDesc type, ustringhash name, void* val); + bool get_camera_shutter_open(ShaderGlobals* sg, bool derivs, + ustringhash object, TypeDesc type, + ustringhash name, void* val); bool get_camera_shutter_close(ShaderGlobals* sg, bool derivs, - ustring object, TypeDesc type, ustring name, - void* val); + ustringhash object, TypeDesc type, + ustringhash name, void* val); bool get_camera_screen_window(ShaderGlobals* sg, bool derivs, - ustring object, TypeDesc type, ustring name, - void* val); + ustringhash object, TypeDesc type, + ustringhash name, void* val); }; OSL_NAMESPACE_EXIT diff --git a/testsuite/example-cuda/cuda_grid_renderer.cpp b/testsuite/example-cuda/cuda_grid_renderer.cpp index e8c3b908a..1fb784bbf 100644 --- a/testsuite/example-cuda/cuda_grid_renderer.cpp +++ b/testsuite/example-cuda/cuda_grid_renderer.cpp @@ -20,7 +20,8 @@ using namespace OSL; using OIIO::TextureSystem; -using OIIO::ustring; +using OSL::ustring; +using OSL::ustringhash; static ustring u_camera("camera"), u_screen("screen"); static ustring u_NDC("NDC"), u_raster("raster"); @@ -64,7 +65,7 @@ CudaGridRenderer::good(TextureHandle* handle) /// Given the name of a texture, return an opaque handle that can be /// used with texture calls to avoid the name lookups. RendererServices::TextureHandle* -CudaGridRenderer::get_texture_handle(OIIO::ustring filename, +CudaGridRenderer::get_texture_handle(OSL::ustringhash filename, ShadingContext* shading_context) { auto itr = _samplers.find(filename); @@ -72,7 +73,8 @@ CudaGridRenderer::get_texture_handle(OIIO::ustring filename, // Open image OIIO::ImageBuf image; if (!image.init_spec(filename, 0, 0)) { - std::cerr << "Could not load " << filename << std::endl; + std::cerr << "Could not load " << ustring_from(filename) + << std::endl; return (TextureHandle*)nullptr; } @@ -120,7 +122,7 @@ CudaGridRenderer::get_texture_handle(OIIO::ustring filename, cudaTextureObject_t cuda_tex = 0; CUDA_CHECK( cudaCreateTextureObject(&cuda_tex, &res_desc, &tex_desc, nullptr)); - itr = _samplers.emplace(std::move(filename), std::move(cuda_tex)).first; + itr = _samplers.emplace(filename, std::move(cuda_tex)).first; } return reinterpret_cast(itr->second); } @@ -137,7 +139,7 @@ CudaGridRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool CudaGridRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring from, float /*time*/) + ustringhash from, float /*time*/) { TransformMap::const_iterator found = _named_xforms.find(from); if (found != _named_xforms.end()) { @@ -160,7 +162,7 @@ CudaGridRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool CudaGridRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring from) + ustringhash from) { // CudaGridRenderer doesn't understand motion blur, so we never fail // on account of time-varying transformations. @@ -175,7 +177,7 @@ CudaGridRenderer::get_matrix(ShaderGlobals* /*sg*/, Matrix44& result, bool CudaGridRenderer::get_inverse_matrix(ShaderGlobals* /*sg*/, Matrix44& result, - ustring to, float /*time*/) + ustringhash to, float /*time*/) { if (to == u_camera || to == u_screen || to == u_NDC || to == u_raster) { Matrix44 M = _world_to_camera; diff --git a/testsuite/example-cuda/cuda_grid_renderer.h b/testsuite/example-cuda/cuda_grid_renderer.h index 309c8f8b5..cd133ff4a 100644 --- a/testsuite/example-cuda/cuda_grid_renderer.h +++ b/testsuite/example-cuda/cuda_grid_renderer.h @@ -10,12 +10,12 @@ #include -using GlobalsMap = std::unordered_map; -using TextureSamplerMap = std::unordered_map; +using GlobalsMap = std::unordered_map; +using TextureSamplerMap = std::unordered_map; // Just use 4x4 matrix for transformations typedef OSL::Matrix44 Transformation; -typedef std::map> TransformMap; +typedef std::map> TransformMap; class CudaGridRenderer final : public OSL::RendererServices { TextureSamplerMap _samplers; @@ -25,7 +25,7 @@ class CudaGridRenderer final : public OSL::RendererServices { TransformMap _named_xforms; OSL::Matrix44 _world_to_camera; - OIIO::ustring _projection; + OSL::ustring _projection; float _fov, _pixelaspect, _hither, _yon; float _shutter[2]; float _screen_window[4]; @@ -56,21 +56,19 @@ class CudaGridRenderer final : public OSL::RendererServices { /// Given the name of a texture, return an opaque handle that can be /// used with texture calls to avoid the name lookups. - virtual TextureHandle* - get_texture_handle(OIIO::ustring filename, - OSL::ShadingContext* shading_context); - - virtual bool get_matrix(OSL::ShaderGlobals* sg, OSL::Matrix44& result, - OSL::TransformationPtr xform, float time); - virtual bool get_matrix(OSL::ShaderGlobals* sg, OSL::Matrix44& result, - OIIO::ustring from, float time); - virtual bool get_matrix(OSL::ShaderGlobals* sg, OSL::Matrix44& result, - OSL::TransformationPtr xform); - virtual bool get_matrix(OSL::ShaderGlobals* sg, OSL::Matrix44& result, - OIIO::ustring from); - virtual bool get_inverse_matrix(OSL::ShaderGlobals* sg, - OSL::Matrix44& result, OIIO::ustring to, - float time); + virtual TextureHandle* get_texture_handle(ustringhash filename, + ShadingContext* shading_context); + + virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform, float time); + virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash from, float time); + virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, + TransformationPtr xform); + virtual bool get_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash from); + virtual bool get_inverse_matrix(ShaderGlobals* sg, Matrix44& result, + ustringhash to, float time); void name_transform(const char* name, const Transformation& xform); };