diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c612a27e2..c3fe4b873b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ else () endif () set (OSL_LIBNAME_SUFFIX "" CACHE STRING "Optional name appended to ${PROJECT_NAME} libraries that are built") -option (OSL_BUILD_TESTS "Build the unit tests, testshade, testrender" ON) +option (OSL_BUILD_TESTS "Build the unit tests, testminimal, testshade, testrender" ON) if (WIN32) option (USE_LLVM_BITCODE "Generate embedded LLVM bitcode" OFF) else () @@ -113,10 +113,14 @@ 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) +option (OSL_USTRINGREP_IS_HASH "Always use ustringhash for strings" ON) set (OSL_NO_DEFAULT_TEXTURESYSTEM OFF CACHE BOOL "Do not use create a raw OIIO::TextureSystem") + +if (OSL_USTRINGREP_IS_HASH) + add_definitions ("-DOSL_USTRINGREP_IS_HASH=1") +endif () if (OSL_NO_DEFAULT_TEXTURESYSTEM) add_definitions ("-DOSL_NO_DEFAULT_TEXTURESYSTEM=1") endif () @@ -220,6 +224,7 @@ add_subdirectory (src/oslc) add_subdirectory (src/oslinfo) if (OSL_BUILD_TESTS AND BUILD_TESTING) + add_subdirectory (src/testminimal) add_subdirectory (src/testshade) add_subdirectory (src/testrender) endif () diff --git a/src/cmake/testing.cmake b/src/cmake/testing.cmake index fc5e956b05..c3c0bee88e 100644 --- a/src/cmake/testing.cmake +++ b/src/cmake/testing.cmake @@ -270,7 +270,7 @@ macro (osl_add_all_tests) bug-array-heapoffsets bug-locallifetime bug-outputinit bug-param-duplicate bug-peep bug-return calculatenormal-reg - cellnoise closure closure-array closure-layered closure-parameters closure-zero closure-conditional + cellnoise closure closure-array closure-layered closure-parameters closure-string closure-zero closure-conditional color color-reg colorspace comparison complement-reg compile-buffer compassign-bool compassign-reg component-range diff --git a/src/include/OSL/llvm_util.h b/src/include/OSL/llvm_util.h index 7f112ccf52..9e428950f7 100644 --- a/src/include/OSL/llvm_util.h +++ b/src/include/OSL/llvm_util.h @@ -718,6 +718,7 @@ class OSLEXECPUBLIC LLVM_Util { /// Return an llvm::Value holding the given string constant (as /// determined by the ustring_rep). llvm::Value* constant(ustring s); + llvm::Value* constant_real_ustring(ustring s); llvm::Value* constant(string_view s) { return constant(ustring(s)); } llvm::Constant* constant_array(cspan constants); @@ -750,6 +751,7 @@ class OSLEXECPUBLIC LLVM_Util { llvm::Constant* wide_constant(size_t i); llvm::Constant* wide_constant_bool(bool b); llvm::Value* wide_constant(ustring s); + llvm::Value* wide_constant_real_ustring(ustring s); llvm::Value* wide_constant(string_view s) { return wide_constant(ustring(s)); @@ -1058,10 +1060,14 @@ class OSLEXECPUBLIC LLVM_Util { IRBuilder& builder(); int m_debug; - bool m_dumpasm = false; - bool m_jit_fma = false; - bool m_jit_aggressive = false; + bool m_dumpasm = false; + bool m_jit_fma = false; + bool m_jit_aggressive = false; +#ifndef OSL_USTRINGREP_IS_HASH UstringRep m_ustring_rep = UstringRep::charptr; +#else + UstringRep m_ustring_rep = UstringRep::hash; +#endif PerThreadInfo::Impl* m_thread; llvm::LLVMContext* m_llvm_context; llvm::Module* m_llvm_module; diff --git a/src/liboslexec/batched_backendllvm.cpp b/src/liboslexec/batched_backendllvm.cpp index e94122ef43..c25904a3f0 100644 --- a/src/liboslexec/batched_backendllvm.cpp +++ b/src/liboslexec/batched_backendllvm.cpp @@ -143,6 +143,10 @@ BatchedBackendLLVM::BatchedBackendLLVM(ShadingSystemImpl& shadingsys, case 8: m_true_mask_value = Mask<8>(true).value(); break; default: OSL_ASSERT(0 && "unsupported vector width"); } + + // Select the appropriate ustring representation + ll.ustring_rep(LLVM_Util::UstringRep::hash); + ll.dumpasm(shadingsys.m_llvm_dumpasm); ll.jit_fma(shadingsys.m_llvm_jit_fma); ll.jit_aggressive(shadingsys.m_llvm_jit_aggressive); @@ -191,7 +195,7 @@ BatchedBackendLLVM::llvm_pass_type(const TypeSpec& typespec) else if (t == TypeDesc::INT) lt = ll.type_int(); else if (t == TypeDesc::STRING) - lt = (llvm::Type*)ll.type_ustring(); + lt = (llvm::Type*)ll.type_real_ustring(); else if (t.aggregate == TypeDesc::VEC3) lt = (llvm::Type*)ll.type_void_ptr(); //llvm_type_triple_ptr(); else if (t.aggregate == TypeDesc::MATRIX44) @@ -667,10 +671,11 @@ BatchedBackendLLVM::llvm_get_pointer(const Symbol& sym, int deriv, #endif int d = deriv * std::max(1, t.arraylen); - if (arrayindex) + if (arrayindex) { arrayindex = ll.op_add(arrayindex, ll.constant(d)); - else + } else { arrayindex = ll.constant(d); + } llvm::Type* result_type = llvm_type(t.elementtype()); if (!sym.is_uniform()) { @@ -715,7 +720,8 @@ llvm::Value* BatchedBackendLLVM::llvm_load_value(const Symbol& sym, int deriv, llvm::Value* arrayindex, int component, TypeDesc cast, bool op_is_uniform, - bool index_is_uniform) + bool index_is_uniform, + bool always_real_ustring) { // A uniform symbol can be broadcast into a varying value. // But a varying symbol can NOT be loaded into a uniform value. @@ -780,9 +786,15 @@ BatchedBackendLLVM::llvm_load_value(const Symbol& sym, int deriv, if (sym.typespec().is_string()) { ustring string_val = sym.get_string(); if (op_is_uniform) { - return ll.constant(string_val); + if (!always_real_ustring) + return ll.constant(string_val); + else + return ll.constant_real_ustring(string_val); } else { - return ll.wide_constant(string_val); + if (!always_real_ustring) + return ll.wide_constant(string_val); + else + return ll.wide_constant_real_ustring(string_val); } } OSL_ASSERT(0 && "unhandled constant type"); @@ -796,7 +808,17 @@ BatchedBackendLLVM::llvm_load_value(const Symbol& sym, int deriv, sym.forced_llvm_bool()); } +llvm::Value* +BatchedBackendLLVM::llvm_const_hash(string_view str) +{ + return llvm_const_hash(ustring(str)); +} +llvm::Value* +BatchedBackendLLVM::llvm_const_hash(ustring str) +{ + return ll.constant64((uint64_t)str.hash()); +} llvm::Value* BatchedBackendLLVM::llvm_load_mask(const Symbol& cond) @@ -1717,6 +1739,7 @@ BatchedBackendLLVM::llvm_call_function(const FuncSpec& name, = llvm_load_value(s, /*deriv=*/d, /*component*/ c, TypeUnknown, function_is_uniform); + // Store our wide pointer on the stack llvm_store_value(wide_value, tmpptr, t, d, NULL, c, /*dst_is_uniform*/ false); diff --git a/src/liboslexec/batched_backendllvm.h b/src/liboslexec/batched_backendllvm.h index 9bafa77676..e8da8a678e 100644 --- a/src/liboslexec/batched_backendllvm.h +++ b/src/liboslexec/batched_backendllvm.h @@ -98,10 +98,14 @@ class BatchedBackendLLVM : public OSOProcessorBase { /// performed if cast is the default of UNKNOWN). llvm::Value* llvm_load_value(const Symbol& sym, int deriv, llvm::Value* arrayindex, int component, - TypeDesc cast = TypeDesc::UNKNOWN, - bool op_is_uniform = true, - bool index_is_uniform = true); + TypeDesc cast = TypeDesc::UNKNOWN, + bool op_is_uniform = true, + bool index_is_uniform = true, + bool always_real_ustring = false); + llvm::Value* llvm_const_hash(string_view str); + + llvm::Value* llvm_const_hash(ustring str); /// Given an llvm::Value* of a pointer (and the type of the data /// that it points to), Return the llvm::Value* corresponding to the diff --git a/src/liboslexec/batched_llvm_gen.cpp b/src/liboslexec/batched_llvm_gen.cpp index dacf4f0ba9..31676f5101 100644 --- a/src/liboslexec/batched_llvm_gen.cpp +++ b/src/liboslexec/batched_llvm_gen.cpp @@ -15,7 +15,7 @@ #endif #include "batched_backendllvm.h" - +#include using namespace OSL; @@ -375,6 +375,7 @@ LLVMGEN(llvm_gen_printf) std::string ourformat(oldfmt, format); // straddle the format // Doctor it to fix mismatches between format and data Symbol& sym(*rop.opargsym(op, arg)); + OSL_ASSERT(!sym.typespec().is_structure_based()); bool arg_is_uniform = sym.is_uniform(); @@ -416,11 +417,13 @@ LLVMGEN(llvm_gen_printf) // widened, so our typical op_is_uniform doesn't do what we // want for this when loading. So just pass arg_is_uniform // which will avoid widening any uniform arguments. - llvm::Value* loaded - = rop.llvm_load_value(sym, 0, arrind, c, - TypeDesc::UNKNOWN, - /*op_is_uniform*/ arg_is_uniform, - /*index_is_uniform*/ true); + // Always use real ustring here because wide/opstring printf va_args expects + // strings and not hashes + bool always_real_ustring = true; + llvm::Value* loaded = rop.llvm_load_value( + sym, 0, arrind, c, TypeDesc::UNKNOWN, + /*op_is_uniform*/ arg_is_uniform, + /*index_is_uniform*/ true, always_real_ustring); // Always expand llvm booleans to integers if (sym.forced_llvm_bool()) { @@ -482,6 +485,7 @@ LLVMGEN(llvm_gen_printf) llvm::Value* ret = rop.ll.call_function(rop.build_name(func_spec), call_args); + // The format op returns a string value, put in in the right spot if (op.opname() == op_format) rop.llvm_store_value(ret, *rop.opargsym(op, 0)); @@ -861,6 +865,7 @@ LLVMGEN(llvm_gen_generic) && (uniformFormOfFunction || functionIsLlvmInlined)) { OSL_DEV_ONLY(std::cout << ">>stores return value " << rop.build_name(func_spec) << std::endl); + llvm::Value* r = rop.llvm_call_function( func_spec, &(args[1]), op.nargs() - 1, /*deriv_ptrs*/ false, uniformFormOfFunction, @@ -3300,7 +3305,7 @@ LLVMGEN(llvm_gen_construct_triple) = { rop.sg_void_ptr(), rop.ll.void_ptr(transform), space_is_uniform ? rop.llvm_load_value(Space) : rop.llvm_void_ptr(Space), - rop.ll.constant(Strings::common), + rop.llvm_const_hash(Strings::common), rop.ll.mask_as_int(rop.ll.current_mask()) }; // Dynamically build function name diff --git a/src/liboslexec/builtindecl.h b/src/liboslexec/builtindecl.h index 5db1d902cd..39d877189c 100644 --- a/src/liboslexec/builtindecl.h +++ b/src/liboslexec/builtindecl.h @@ -133,7 +133,7 @@ DECL(osl_closure_to_string, "sXX") DECL(osl_closure_to_ustringhash, "hXX") #endif DECL(osl_format, "hh*") -DECL(osl_gen_ustringhash_pod, "hs") +DECL(osl_gen_ustringhash_pod, "hh") DECL(osl_gen_ustring, "sh") DECL(osl_gen_printfmt, "xXhiXiX") DECL(osl_gen_filefmt, "xXhhiXiX") diff --git a/src/liboslexec/builtindecl_wide_xmacro.h b/src/liboslexec/builtindecl_wide_xmacro.h index 37171c0b19..db0263cd92 100644 --- a/src/liboslexec/builtindecl_wide_xmacro.h +++ b/src/liboslexec/builtindecl_wide_xmacro.h @@ -45,14 +45,14 @@ #define WIDE_GENERIC_NOISE_DERIV_IMPL_INDIRECT(name) \ - DECL(__OSL_MASKED_OP2(name, Wdf, Wdf), "xsXXXXXi") \ - DECL(__OSL_MASKED_OP3(name, Wdf, Wdf, Wdf), "xsXXXXXXi") \ - DECL(__OSL_MASKED_OP2(name, Wdf, Wdv), "xsXXXXXi") \ - DECL(__OSL_MASKED_OP3(name, Wdf, Wdv, Wdf), "xsXXXXXXi") \ - DECL(__OSL_MASKED_OP2(name, Wdv, Wdf), "xsXXXXXi") \ - DECL(__OSL_MASKED_OP3(name, Wdv, Wdf, Wdf), "xsXXXXXXi") \ - DECL(__OSL_MASKED_OP2(name, Wdv, Wdv), "xsXXXXXi") \ - DECL(__OSL_MASKED_OP3(name, Wdv, Wdv, Wdf), "xsXXXXXXi") + DECL(__OSL_MASKED_OP2(name, Wdf, Wdf), "xhXXXXXi") \ + DECL(__OSL_MASKED_OP3(name, Wdf, Wdf, Wdf), "xhXXXXXXi") \ + DECL(__OSL_MASKED_OP2(name, Wdf, Wdv), "xhXXXXXi") \ + DECL(__OSL_MASKED_OP3(name, Wdf, Wdv, Wdf), "xhXXXXXXi") \ + DECL(__OSL_MASKED_OP2(name, Wdv, Wdf), "xhXXXXXi") \ + DECL(__OSL_MASKED_OP3(name, Wdv, Wdf, Wdf), "xhXXXXXXi") \ + DECL(__OSL_MASKED_OP2(name, Wdv, Wdv), "xhXXXXXi") \ + DECL(__OSL_MASKED_OP3(name, Wdv, Wdv, Wdf), "xhXXXXXXi") #define WIDE_GENERIC_NOISE_DERIV_IMPL(name) \ WIDE_GENERIC_NOISE_DERIV_IMPL_INDIRECT(name) @@ -90,14 +90,14 @@ #define WIDE_GENERIC_PNOISE_DERIV_IMPL_INDIRECT(name) \ - DECL(__OSL_MASKED_OP3(name, Wdf, Wdf, Wf), "xsXXXXXXi") \ - DECL(__OSL_MASKED_OP5(name, Wdf, Wdf, Wdf, Wf, Wf), "xsXXXXXXXXi") \ - DECL(__OSL_MASKED_OP3(name, Wdf, Wdv, Wv), "xsXXXXXXi") \ - DECL(__OSL_MASKED_OP5(name, Wdf, Wdv, Wdf, Wv, Wf), "xsXXXXXXXXi") \ - DECL(__OSL_MASKED_OP3(name, Wdv, Wdf, Wf), "xsXXXXXXi") \ - DECL(__OSL_MASKED_OP5(name, Wdv, Wdf, Wdf, Wf, Wf), "xsXXXXXXXXi") \ - DECL(__OSL_MASKED_OP3(name, Wdv, Wdv, Wv), "xsXXXXXXi") \ - DECL(__OSL_MASKED_OP5(name, Wdv, Wdv, Wdf, Wv, Wf), "xsXXXXXXXXi") + DECL(__OSL_MASKED_OP3(name, Wdf, Wdf, Wf), "xhXXXXXXi") \ + DECL(__OSL_MASKED_OP5(name, Wdf, Wdf, Wdf, Wf, Wf), "xhXXXXXXXXi") \ + DECL(__OSL_MASKED_OP3(name, Wdf, Wdv, Wv), "xhXXXXXXi") \ + DECL(__OSL_MASKED_OP5(name, Wdf, Wdv, Wdf, Wv, Wf), "xhXXXXXXXXi") \ + DECL(__OSL_MASKED_OP3(name, Wdv, Wdf, Wf), "xhXXXXXXi") \ + DECL(__OSL_MASKED_OP5(name, Wdv, Wdf, Wdf, Wf, Wf), "xhXXXXXXXXi") \ + DECL(__OSL_MASKED_OP3(name, Wdv, Wdv, Wv), "xhXXXXXXi") \ + DECL(__OSL_MASKED_OP5(name, Wdv, Wdv, Wdf, Wv, Wf), "xhXXXXXXXXi") #define WIDE_GENERIC_PNOISE_DERIV_IMPL(name) \ WIDE_GENERIC_PNOISE_DERIV_IMPL_INDIRECT(name) @@ -175,12 +175,12 @@ DECL(__OSL_MASKED_OP(mul_closure_float), "xXXXXi") DECL(__OSL_MASKED_OP(mul_closure_color), "xXXXXi") DECL(__OSL_OP(closure_to_string), "sXX") -DECL(__OSL_OP(format), "xXis*") -DECL(__OSL_OP(format_uniform), "ss*") -DECL(__OSL_OP(printf), "xXis*") -DECL(__OSL_OP(error), "xXis*") -DECL(__OSL_OP(warning), "xXis*") -DECL(__OSL_OP(fprintf), "xXiss*") +DECL(__OSL_OP(format), "xXih*") +DECL(__OSL_OP(format_uniform), "hh*") +DECL(__OSL_OP(printf), "xXih*") +DECL(__OSL_OP(error), "xXih*") +DECL(__OSL_OP(warning), "xXih*") +DECL(__OSL_OP(fprintf), "xXihh*") DECL(__OSL_MASKED_OP(split), "xXXXXXii") @@ -263,61 +263,61 @@ DECL(__OSL_MASKED_OP3(hash, Wi, Wv, Wf), "xXXXi") // first vs. directly passing the shader global. We don't expect this // to be encountered, but is possible -DECL(__OSL_MASKED_OP3(spline, Wf, Wf, Wf), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wf, Wf, f), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wf, f, Wf), "xXXXXiii") +DECL(__OSL_MASKED_OP3(spline, Wf, Wf, Wf), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wf, Wf, f), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wf, f, Wf), "xXhXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, Wdf), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, df), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, df), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdf, df, Wdf), "xXXXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, Wdf), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, df), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, df), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdf, df, Wdf), "xXhXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, f), "xXXXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, f), "xXhXXiii") -DECL(__OSL_MASKED_OP3(spline, Wv, Wf, Wv), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wv, Wf, v), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wv, f, Wv), "xXXXXiii") +DECL(__OSL_MASKED_OP3(spline, Wv, Wf, Wv), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wv, Wf, v), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wv, f, Wv), "xXhXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wdv), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, dv), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wdv), "xXXXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wdv), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, dv), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wdv), "xXhXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, v), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wv), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wv), "xXXXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, v), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wv), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wv), "xXhXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdf, f, Wdf), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, Wdf), "xXXXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdf, f, Wdf), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, Wdf), "xXhXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, f, Wdv), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, Wdv), "xXXXXiii") -DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, dv), "xXXXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, f, Wdv), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, Wdv), "xXhXXiii") +DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, dv), "xXhXXiii") //--------------------------------------------------------------- -DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, Wf), "xXXXXiii") -DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, f), "xXXXXiii") -DECL(__OSL_MASKED_OP3(splineinverse, Wf, f, Wf), "xXXXXiii") +DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, Wf), "xXhXXiii") +DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, f), "xXhXXiii") +DECL(__OSL_MASKED_OP3(splineinverse, Wf, f, Wf), "xXhXXiii") //dfdfdf is treated as dfdff -DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, Wdf), "xXXXXiii") //redone -DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, df), "xXXXXiii") -DECL(__OSL_MASKED_OP3(splineinverse, Wdf, df, Wdf), "xXXXXiii") +DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, Wdf), "xXhXXiii") //redone +DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, df), "xXhXXiii") +DECL(__OSL_MASKED_OP3(splineinverse, Wdf, df, Wdf), "xXhXXiii") //====== -DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, f), "xXXXXiii") +DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, f), "xXhXXiii") //dffdf is treated as fff -DECL(__OSL_MASKED_OP3(splineinverse, Wdf, f, Wdf), "xXXXXiii") +DECL(__OSL_MASKED_OP3(splineinverse, Wdf, f, Wdf), "xXhXXiii") // // unreachable, can't find .osl to produce this combination //DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wf, Wdf), "xXXXXiii") -DECL(__OSL_MASKED_OP(pointcloud_search), "xXXsXXiiXiXiiii*") -DECL(__OSL_MASKED_OP(pointcloud_get), "iXsXiXsLXi") -DECL(__OSL_MASKED_OP(pointcloud_write), "iXsXiXXXi") +DECL(__OSL_MASKED_OP(pointcloud_search), "xXXhXXiiXiXiiii*") +DECL(__OSL_MASKED_OP(pointcloud_get), "iXhXiXhLXi") +DECL(__OSL_MASKED_OP(pointcloud_write), "iXhXiXXXi") -DECL(__OSL_MASKED_OP(getmessage), "xXXssLXiisii") -DECL(__OSL_MASKED_OP2(setmessage, s, WX), "xXsLXisii") -DECL(__OSL_MASKED_OP2(setmessage, Ws, WX), "xXXLXisii") +DECL(__OSL_MASKED_OP(getmessage), "xXXhhLXiihii") +DECL(__OSL_MASKED_OP2(setmessage, s, WX), "xXhLXihii") +DECL(__OSL_MASKED_OP2(setmessage, Ws, WX), "xXXLXihii") DECL(__OSL_OP(blackbody_vf), "xXXf") DECL(__OSL_MASKED_OP2(blackbody, Wv, Wf), "xXXXi") @@ -329,13 +329,13 @@ DECL(__OSL_MASKED_OP2(wavelength_color, Wv, Wf), "xXXXi") //DECL (osl_luminance_fv, "xXXX") //DECL (osl_luminance_dfdv, "xXXX") -DECL(__OSL_OP(prepend_color_from_vs), "xXXs") -DECL(__OSL_MASKED_OP2(prepend_color_from, Wv, s), "xXXsi") +DECL(__OSL_OP(prepend_color_from_vs), "xXXh") +DECL(__OSL_MASKED_OP2(prepend_color_from, Wv, s), "xXXhi") DECL(__OSL_MASKED_OP2(prepend_color_from, Wv, Ws), "xXXXi") // forced masked version only -DECL(__OSL_MASKED_OP2(prepend_matrix_from, Wm, s), "xXXsi") +DECL(__OSL_MASKED_OP2(prepend_matrix_from, Wm, s), "xXXhi") DECL(__OSL_MASKED_OP2(prepend_matrix_from, Wm, Ws), "xXXXi") // Batched code gen uses a combination of osl_build_transform_matrix @@ -345,42 +345,42 @@ DECL(__OSL_MASKED_OP2(prepend_matrix_from, Wm, Ws), "xXXXi") // DECL (osl_transform_triple, "iXXiXiXXi") // unneeded // DECL (osl_transform_triple_nonlinear, "iXXiXiXXi") // unneeded -DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, s), "iXXXXi") -DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, s), "iXXXXi") -DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, Ws), "iXXXXi") +DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, s), "iXXhhi") +DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, s), "iXXXhi") +DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, Ws), "iXXhXi") DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, Ws), "iXXXXi") -DECL(__OSL_OP(dict_find_iis), "iXis") +DECL(__OSL_OP(dict_find_iis), "iXih") DECL(__OSL_MASKED_OP3(dict_find, Wi, Wi, Ws), "xXXXXi") -DECL(__OSL_OP(dict_find_iss), "iXss") +DECL(__OSL_OP(dict_find_iss), "iXhh") DECL(__OSL_MASKED_OP3(dict_find, Wi, Ws, Ws), "xXXXXi") DECL(__OSL_OP(dict_next), "iXi") DECL(__OSL_MASKED_OP(dict_next), "xXXXi") -DECL(__OSL_OP(dict_value), "iXisLX") +DECL(__OSL_OP(dict_value), "iXihLX") DECL(__OSL_MASKED_OP(dict_value), "xXXXXLXi") -DECL(__OSL_OP(raytype_name), "iXs") +DECL(__OSL_OP(raytype_name), "iXh") DECL(__OSL_MASKED_OP(raytype_name), "xXXXi") -DECL(__OSL_OP(naninf_check), "xiXiXsisiis") -DECL(__OSL_MASKED_OP1(naninf_check_offset, i), "xiiXiXsisiis") -DECL(__OSL_MASKED_OP1(naninf_check_offset, Wi), "xiiXiXsisXis") -DECL(__OSL_OP(range_check), "iiisXsisiss") -DECL(__OSL_MASKED_OP(range_check), "xXiisXsisiss") -DECL(__OSL_OP2(uninit_check_values_offset, X, i), "xLXXsisissisisii") -DECL(__OSL_MASKED_OP2(uninit_check_values_offset, X, Wi), "xiLXXsisissisisXi") -DECL(__OSL_MASKED_OP2(uninit_check_values_offset, WX, i), "xiLXXsisissisisii") -DECL(__OSL_MASKED_OP2(uninit_check_values_offset, WX, Wi), "xiLXXsisissisisXi") - -DECL(__OSL_OP1(get_attribute, s), "iXissiiXXi") -DECL(__OSL_MASKED_OP1(get_attribute, Ws), "iXisXiiXXi") -DECL(__OSL_OP(get_attribute_uniform), "iXissiiXX") +DECL(__OSL_OP(naninf_check), "xiXiXhihiih") +DECL(__OSL_MASKED_OP1(naninf_check_offset, i), "xiiXiXhihiih") +DECL(__OSL_MASKED_OP1(naninf_check_offset, Wi), "xiiXiXhihXih") +DECL(__OSL_OP(range_check), "iiihXhihihh") +DECL(__OSL_MASKED_OP(range_check), "xXiihXhihihh") +DECL(__OSL_OP2(uninit_check_values_offset, X, i), "xLXXhihihhihihii") +DECL(__OSL_MASKED_OP2(uninit_check_values_offset, X, Wi), "xiLXXhihihhihihXi") +DECL(__OSL_MASKED_OP2(uninit_check_values_offset, WX, i), "xiLXXhihihhihihii") +DECL(__OSL_MASKED_OP2(uninit_check_values_offset, WX, Wi), "xiLXXhihihhihihXi") + +DECL(__OSL_OP1(get_attribute, s), "iXihhiiXXi") +DECL(__OSL_MASKED_OP1(get_attribute, Ws), "iXihXiiXXi") +DECL(__OSL_OP(get_attribute_uniform), "iXihhiiXX") // TODO: shouldn't bind_interpolated_param be MASKED? change name to reflect -DECL(__OSL_OP(bind_interpolated_param), "iXsLiXiXiXii") +DECL(__OSL_OP(bind_interpolated_param), "iXhLiXiXiXii") //DECL (osl_get_texture_options, "XX") // unneeded DECL(__OSL_OP(get_noise_options), "XX") @@ -588,9 +588,9 @@ DECL(__OSL_MASKED_OP3(div, Wm, Wm, Wf), "xXXXi") DECL(__OSL_MASKED_OP3(div, Wm, Wf, Wm), "xXXXi") // forced masked version only -DECL(__OSL_MASKED_OP3(get_from_to_matrix, Wm, s, s), "iXXssi") -DECL(__OSL_MASKED_OP3(get_from_to_matrix, Wm, s, Ws), "iXXsXi") -DECL(__OSL_MASKED_OP3(get_from_to_matrix, Wm, Ws, s), "iXXXsi") +DECL(__OSL_MASKED_OP3(get_from_to_matrix, Wm, s, s), "iXXhhi") +DECL(__OSL_MASKED_OP3(get_from_to_matrix, Wm, s, Ws), "iXXhXi") +DECL(__OSL_MASKED_OP3(get_from_to_matrix, Wm, Ws, s), "iXXXhi") DECL(__OSL_MASKED_OP3(get_from_to_matrix, Wm, Ws, Ws), "iXXXXi") //varying vs non varying @@ -612,17 +612,17 @@ DECL(__OSL_MASKED_OP2(stof, Wf, Ws), "xXXi") DECL(__OSL_MASKED_OP4(substr, Ws, Ws, Wi, Wi), "xXXXXi") DECL(__OSL_MASKED_OP(regex_impl), "xXXXXiXii") -DECL(__OSL_OP(regex_impl), "iXsXisi") +DECL(__OSL_OP(regex_impl), "iXhXihi") // BATCH texturing manages the BatchedTextureOptions // directly in LLVM ir, and has no need for wide versions // of osl_texture_set_XXX functions -DECL(__OSL_MASKED_OP(texture), "iXsXXXXXXXXiXiXiXi") -DECL(__OSL_MASKED_OP(texture3d), "iXsXXXXXXiXiXiXi") -DECL(__OSL_MASKED_OP(environment), "iXsXXXXXiXiXiXi") -DECL(__OSL_OP(resolve_udim_uniform), "XXXXff") -DECL(__OSL_MASKED_OP(resolve_udim), "xXXXXXXi") -DECL(__OSL_OP(get_textureinfo_uniform), "iXsXsXX") +DECL(__OSL_MASKED_OP(texture), "iXhXXXXXXXXiXiXiXi") +DECL(__OSL_MASKED_OP(texture3d), "iXhXXXXXXiXiXiXi") +DECL(__OSL_MASKED_OP(environment), "iXhXXXXXiXiXiXi") +DECL(__OSL_OP(resolve_udim_uniform), "XXhXff") +DECL(__OSL_MASKED_OP(resolve_udim), "xXhXXXXi") +DECL(__OSL_OP(get_textureinfo_uniform), "iXhXhXX") // Wide Code generator will set trace options directly in LLVM IR // without calling helper functions diff --git a/src/liboslexec/llvm_util.cpp b/src/liboslexec/llvm_util.cpp index 3dd888cab0..3b3db39423 100644 --- a/src/liboslexec/llvm_util.cpp +++ b/src/liboslexec/llvm_util.cpp @@ -564,10 +564,15 @@ LLVM_Util::ustring_rep(UstringRep rep) } m_llvm_type_ustring_ptr = llvm::PointerType::get(m_llvm_type_ustring, 0); - // Batched versions haven't been updated to handle hash yet. - // For now leave them using the real ustring regardless of UstringRep - m_llvm_type_wide_ustring = llvm_vector_type(m_llvm_type_real_ustring, - m_vector_width); + if (m_ustring_rep == UstringRep::charptr) { + m_llvm_type_wide_ustring = llvm_vector_type(m_llvm_type_real_ustring, + m_vector_width); + } else { + OSL_ASSERT(m_ustring_rep == UstringRep::hash); + m_llvm_type_wide_ustring + = llvm_vector_type(llvm::Type::getInt64Ty(*m_llvm_context), + m_vector_width); + } m_llvm_type_wide_ustring_ptr = llvm::PointerType::get(m_llvm_type_wide_ustring, 0); } @@ -3533,6 +3538,11 @@ LLVM_Util::constant(ustring s) } } +llvm::Value* +LLVM_Util::constant_real_ustring(ustring s) +{ + return constant_ptr((void*)s.c_str(), type_char_ptr()); +} llvm::Value* @@ -3541,7 +3551,12 @@ LLVM_Util::wide_constant(ustring s) return builder().CreateVectorSplat(m_vector_width, constant(s)); } - +llvm::Value* +LLVM_Util::wide_constant_real_ustring(ustring s) +{ + return builder().CreateVectorSplat(m_vector_width, + constant_real_ustring(s)); +} llvm::Value* LLVM_Util::llvm_mask_to_native(llvm::Value* llvm_mask) diff --git a/src/liboslexec/opfmt.cpp b/src/liboslexec/opfmt.cpp index c0caa21fde..d66326e850 100644 --- a/src/liboslexec/opfmt.cpp +++ b/src/liboslexec/opfmt.cpp @@ -31,10 +31,12 @@ namespace pvt { // Shims to convert llvm gen to rs free function C++ parameter types // and forward on calls to re free functions. +// TODO this can be removed now that batched supports ustringhash_pod OSL_RSOP OSL::ustringhash_pod -osl_gen_ustringhash_pod(ustring_pod s) +osl_gen_ustringhash_pod(OSL::ustringhash_pod hash) { - return USTR(s).hash(); + return hash; + //return USTR(s).hash(); } OSL_RSOP const char* @@ -114,4 +116,4 @@ get_max_warnings_per_thread(OpaqueExecContextPtr oec) } //namespace pvt -OSL_NAMESPACE_EXIT \ No newline at end of file +OSL_NAMESPACE_EXIT diff --git a/src/liboslexec/oslexec_pvt.h b/src/liboslexec/oslexec_pvt.h index 5921c4ba65..163b09f688 100644 --- a/src/liboslexec/oslexec_pvt.h +++ b/src/liboslexec/oslexec_pvt.h @@ -245,14 +245,14 @@ struct AttributeNeeded { // "C" linkage (no C++ name mangling). #define OSL_SHADEOP extern "C" OSL_DLL_LOCAL - +/* // Handy re-casting macros inline ustring USTR(ustring_pod s) noexcept { return OSL::bitcast(s); } - +*/ #define MAT(m) (*(Matrix44*)m) #define VEC(v) (*(Vec3*)v) diff --git a/src/liboslexec/wide/wide_opcolor.cpp b/src/liboslexec/wide/wide_opcolor.cpp index d1e96320f1..8b75141237 100644 --- a/src/liboslexec/wide/wide_opcolor.cpp +++ b/src/liboslexec/wide/wide_opcolor.cpp @@ -163,12 +163,12 @@ __OSL_MASKED_OP2(wavelength_color, Wv, Wf)(void* bsg_, void* wout_, OSL_BATCHOP void -__OSL_OP(prepend_color_from_vs)(void* bsg_, void* c_, const char* from) +__OSL_OP(prepend_color_from_vs)(void* bsg_, void* c_, ustringhash_pod from) { const ColorSystem& cs = cs_from_bsg(bsg_); Color3& c(*(Color3*)c_); - c = cs.to_rgb(USTR(from), c, context_from_bsg(bsg_)); + c = cs.to_rgb(ustringhash_from(from), c, context_from_bsg(bsg_)); } namespace { @@ -176,12 +176,12 @@ namespace { // NOTE: keep implementation as mirror of ColorSystem::to_rgb void wide_prepend_color_from(ShadingContext* ctx, const ColorSystem& cs, - Masked wR, ustring fromspace) + Masked wR, ustringhash fromspace) { // Rather than attempt outer loop vectorization of ColorSystem::to_rgb // we will pull it's implementation up and insert SIMD loops inside // the uniform branches - if (fromspace == Strings::RGB || fromspace == Strings::rgb + if (fromspace == Hashes::RGB || fromspace == Hashes::rgb || fromspace == cs.colorspace()) { OSL_OMP_PRAGMA(omp simd simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { @@ -190,7 +190,7 @@ wide_prepend_color_from(ShadingContext* ctx, const ColorSystem& cs, } return; } - if (fromspace == Strings::hsv) { + if (fromspace == Hashes::hsv) { OSL_OMP_PRAGMA(omp simd simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { Color3 C = wR[lane]; @@ -201,7 +201,7 @@ wide_prepend_color_from(ShadingContext* ctx, const ColorSystem& cs, } return; } - if (fromspace == Strings::hsl) { + if (fromspace == Hashes::hsl) { OSL_OMP_PRAGMA(omp simd simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { Color3 C = wR[lane]; @@ -212,7 +212,7 @@ wide_prepend_color_from(ShadingContext* ctx, const ColorSystem& cs, } return; } - if (fromspace == Strings::YIQ) { + if (fromspace == Hashes::YIQ) { OSL_OMP_PRAGMA(omp simd simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { Color3 C = wR[lane]; @@ -223,7 +223,7 @@ wide_prepend_color_from(ShadingContext* ctx, const ColorSystem& cs, } return; } - if (fromspace == Strings::XYZ) { + if (fromspace == Hashes::XYZ) { OSL_OMP_PRAGMA(omp simd simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { Color3 C = wR[lane]; @@ -234,7 +234,7 @@ wide_prepend_color_from(ShadingContext* ctx, const ColorSystem& cs, } return; } - if (fromspace == Strings::xyY) { + if (fromspace == Hashes::xyY) { OSL_OMP_PRAGMA(omp simd simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { Color3 C = wR[lane]; @@ -249,7 +249,7 @@ wide_prepend_color_from(ShadingContext* ctx, const ColorSystem& cs, // Serialize calls to ocio wR.mask().foreach ([=, &cs](ActiveLane lane) -> void { Color3 C = wR[lane]; - Color3 R = cs.ocio_transform(fromspace, Strings::RGB, C, ctx); + Color3 R = cs.ocio_transform(fromspace, Hashes::RGB, C, ctx); wR[lane] = R; }); } @@ -260,14 +260,14 @@ wide_prepend_color_from(ShadingContext* ctx, const ColorSystem& cs, OSL_BATCHOP void __OSL_MASKED_OP2(prepend_color_from, Wv, s)(void* bsg_, void* c_, - const char* from, + ustringhash_pod from, unsigned int mask_value) { const ColorSystem& cs = cs_from_bsg(bsg_); ShadingContext* ctx = context_from_bsg(bsg_); Masked wR(c_, Mask(mask_value)); - ustring fromspace = USTR(from); + ustringhash fromspace = ustringhash_from(from); wide_prepend_color_from(ctx, cs, wR, fromspace); } @@ -322,14 +322,14 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, bool use_colorconfig = false; Block bCrgb; Wide wCrgb(bCrgb); - if (fromspace == Strings::RGB || fromspace == Strings::rgb - || fromspace == Strings::linear || fromspace == cs.colorspace()) { + if (fromspace == Hashes::RGB || fromspace == Hashes::rgb + || fromspace == Hashes::linear || fromspace == cs.colorspace()) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR C = wInput[lane]; wCrgb[lane] = C; } - } else if (fromspace == Strings::hsv) { + } else if (fromspace == Hashes::hsv) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR C = wInput[lane]; @@ -338,7 +338,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wCrgb[ActiveLane(lane)] = R; } } - } else if (fromspace == Strings::hsl) { + } else if (fromspace == Hashes::hsl) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR C = wInput[lane]; @@ -347,7 +347,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wCrgb[ActiveLane(lane)] = R; } } - } else if (fromspace == Strings::YIQ) { + } else if (fromspace == Hashes::YIQ) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR C = wInput[lane]; @@ -356,7 +356,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wCrgb[ActiveLane(lane)] = R; } } - } else if (fromspace == Strings::XYZ) { + } else if (fromspace == Hashes::XYZ) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR C = wInput[lane]; @@ -365,7 +365,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wCrgb[ActiveLane(lane)] = R; } } - } else if (fromspace == Strings::xyY) { + } else if (fromspace == Hashes::xyY) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR C = wInput[lane]; @@ -374,7 +374,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wCrgb[ActiveLane(lane)] = R; } } - } else if (fromspace == Strings::sRGB) { + } else if (fromspace == Hashes::sRGB) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR C = wInput[lane]; @@ -389,14 +389,14 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, if (use_colorconfig) { // do things the ColorConfig way, so skip all these other clauses... - } else if (tospace == Strings::RGB || tospace == Strings::rgb - || tospace == Strings::linear || tospace == cs.colorspace()) { + } else if (tospace == Hashes::RGB || tospace == Hashes::rgb + || tospace == Hashes::linear || tospace == cs.colorspace()) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR C = wCrgb[lane]; wOutput[lane] = C; } - } else if (tospace == Strings::hsv) { + } else if (tospace == Hashes::hsv) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR Crgb = wCrgb[lane]; @@ -405,7 +405,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wOutput[ActiveLane(lane)] = Cto; } } - } else if (tospace == Strings::hsl) { + } else if (tospace == Hashes::hsl) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR Crgb = wCrgb[lane]; @@ -414,7 +414,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wOutput[ActiveLane(lane)] = Cto; } } - } else if (tospace == Strings::YIQ) { + } else if (tospace == Hashes::YIQ) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR Crgb = wCrgb[lane]; @@ -423,7 +423,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wOutput[ActiveLane(lane)] = Cto; } } - } else if (tospace == Strings::XYZ) { + } else if (tospace == Hashes::XYZ) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR Crgb = wCrgb[lane]; @@ -432,7 +432,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wOutput[ActiveLane(lane)] = Cto; } } - } else if (tospace == Strings::xyY) { + } else if (tospace == Hashes::xyY) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR Crgb = wCrgb[lane]; @@ -441,7 +441,7 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, wOutput[ActiveLane(lane)] = Cto; } } - } else if (tospace == Strings::sRGB) { + } else if (tospace == Hashes::sRGB) { WIDE_TRANSFORMC_OMP_SIMD_LOOP(simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { COLOR Crgb = wCrgb[lane]; @@ -473,14 +473,14 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace, OSL_BATCHOP void __OSL_MASKED_OP3(transform_color, Wv, s, s)(void* bsg_, void* Cin, int Cin_derivs, void* Cout, - int Cout_derivs, ustring_pod from_, ustring_pod to_, + int Cout_derivs, ustringhash_pod from_, ustringhash_pod to_, unsigned int mask_value) { const ColorSystem& cs = cs_from_bsg(bsg_); ShadingContext* ctx = context_from_bsg(bsg_); - const ustring& from = USTR(from_); - const ustring& to = USTR(to_); + ustring from = ustring_from(from_); + ustring to = ustring_from(to_); if (Cout_derivs) { if (Cin_derivs) { @@ -512,13 +512,13 @@ __OSL_MASKED_OP3(transform_color, Wv, s, OSL_BATCHOP void __OSL_OP3(transform_color, v, s, s)(void* bsg_, void* Cin, int Cin_derivs, void* Cout, int Cout_derivs, - ustring_pod from_, ustring_pod to_) + ustringhash_pod from_, ustringhash_pod to_) { const ColorSystem& cs = cs_from_bsg(bsg_); ShadingContext* ctx = context_from_bsg(bsg_); - const ustring& from = USTR(from_); - const ustring& to = USTR(to_); + ustring from = ustring_from(from_); + ustring to = ustring_from(to_); if (Cout_derivs) { if (Cin_derivs) { diff --git a/src/liboslexec/wide/wide_opdictionary.cpp b/src/liboslexec/wide/wide_opdictionary.cpp index b209d9bf84..2c47e0cdc7 100644 --- a/src/liboslexec/wide/wide_opdictionary.cpp +++ b/src/liboslexec/wide/wide_opdictionary.cpp @@ -48,12 +48,12 @@ OSL_USING_DATA_WIDTH(__OSL_WIDTH) #include "define_opname_macros.h" OSL_BATCHOP int -__OSL_OP(dict_find_iis)(void* bsg_, int nodeID, ustring_pod query) +__OSL_OP(dict_find_iis)(void* bsg_, int nodeID, ustringhash_pod query) { auto* bsg = reinterpret_cast(bsg_); return bsg->uniform.context->dict_find( nullptr /*causes errors be reported through ShadingContext*/, nodeID, - USTR(query)); + ustring_from(query)); } @@ -82,12 +82,13 @@ __OSL_MASKED_OP3(dict_find, Wi, Wi, Ws)(void* bsg_, void* wout, void* wnodeID, OSL_BATCHOP int -__OSL_OP(dict_find_iss)(void* bsg_, ustring_pod dictionary, ustring_pod query) +__OSL_OP(dict_find_iss)(void* bsg_, ustringhash_pod dictionary, + ustringhash_pod query) { auto* bsg = reinterpret_cast(bsg_); return bsg->uniform.context->dict_find( nullptr /*causes errors be reported through ShadingContext*/, - USTR(dictionary), USTR(query)); + ustring_from(dictionary), ustring_from(query)); } @@ -145,11 +146,11 @@ __OSL_MASKED_OP(dict_next)(void* bsg_, void* wout, void* wNodeID, OSL_BATCHOP int -__OSL_OP(dict_value)(void* bsg_, int nodeID, ustring_pod attribname, +__OSL_OP(dict_value)(void* bsg_, int nodeID, ustringhash_pod attribname, long long type, void* data) { auto* bsg = reinterpret_cast(bsg_); - return bsg->uniform.context->dict_value(nodeID, USTR(attribname), + return bsg->uniform.context->dict_value(nodeID, ustring_from(attribname), TYPEDESC(type), data, /*treat_ustrings_as_hash*/ false); } diff --git a/src/liboslexec/wide/wide_opmatrix.cpp b/src/liboslexec/wide/wide_opmatrix.cpp index 33b3ef2aac..2679d50e82 100644 --- a/src/liboslexec/wide/wide_opmatrix.cpp +++ b/src/liboslexec/wide/wide_opmatrix.cpp @@ -532,33 +532,35 @@ makeIdentity(Masked wrm) OSL_FORCEINLINE Mask impl_get_uniform_from_matrix_masked(void* bsg_, Masked wrm, - const char* from) + ustringhash_pod from_) { + ustringhash from = ustringhash_from(from_); auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; - if (USTR(from) == Strings::common - || USTR(from) == ctx->shadingsys().commonspace_synonym()) { + if (from == Hashes::common + || from == ctx->shadingsys().commonspace_synonym()) { makeIdentity(wrm); return wrm.mask(); } - if (USTR(from) == Strings::shader) { + if (from == Hashes::shader) { ctx->batched<__OSL_WIDTH>().renderer()->get_matrix( bsg, wrm, bsg->varying.shader2common, bsg->varying.time); // NOTE: matching scalar version of code which ignores the renderservices return value return wrm.mask(); } - if (USTR(from) == Strings::object) { + if (from == Hashes::object) { ctx->batched<__OSL_WIDTH>().renderer()->get_matrix( bsg, wrm, bsg->varying.object2common, bsg->varying.time); // NOTE: matching scalar version of code which ignores the renderservices return value return wrm.mask(); } - Mask succeeded = ctx->batched<__OSL_WIDTH>().renderer()->get_matrix( - bsg, wrm, USTR(from), bsg->varying.time); + Mask succeeded + = ctx->batched<__OSL_WIDTH>().renderer()->get_matrix(bsg, wrm, from, + bsg->varying.time); auto failedResults = wrm & succeeded.invert(); if (failedResults.mask().any_on()) { makeIdentity(failedResults); @@ -572,24 +574,24 @@ impl_get_uniform_from_matrix_masked(void* bsg_, Masked wrm, OSL_FORCEINLINE Mask impl_get_uniform_to_inverse_matrix_masked(void* bsg_, Masked wrm, - const char* to) + ustringhash_pod to_) { + ustringhash to = ustringhash_from(to_); auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; - if (USTR(to) == Strings::common - || USTR(to) == ctx->shadingsys().commonspace_synonym()) { + if (to == Hashes::common || to == ctx->shadingsys().commonspace_synonym()) { makeIdentity(wrm); return wrm.mask(); } - if (USTR(to) == Strings::shader) { + if (to == Hashes::shader) { dispatch_get_inverse_matrix(ctx->batched<__OSL_WIDTH>().renderer(), bsg, wrm, bsg->varying.shader2common, bsg->varying.time); // NOTE: matching scalar version of code which ignores the renderservices return value return wrm.mask(); } - if (USTR(to) == Strings::object) { + if (to == Hashes::object) { dispatch_get_inverse_matrix(ctx->batched<__OSL_WIDTH>().renderer(), bsg, wrm, bsg->varying.object2common, bsg->varying.time); @@ -602,7 +604,7 @@ impl_get_uniform_to_inverse_matrix_masked(void* bsg_, Masked wrm, // so no need to make sure that the values are valid (assuming FP exceptions are disabled) Mask succeeded = dispatch_get_inverse_matrix(ctx->batched<__OSL_WIDTH>().renderer(), - bsg, wrm, USTR(to), bsg->varying.time); + bsg, wrm, to, bsg->varying.time); auto failedResults = wrm & succeeded.invert(); if (failedResults.mask().any_on()) { @@ -658,13 +660,13 @@ impl_get_varying_from_matrix_batched(BatchedShaderGlobals* bsg, for (int lane = 0; lane < __OSL_WIDTH; ++lane) { ustringhash from = wFrom[lane]; if (wMfrom.mask()[lane]) { - if (from == Strings::common || from == commonspace_synonym) { + if (from == Hashes::common || from == commonspace_synonym) { // inline of Mask::set_on(lane) common_space_bits |= 1 << lane; - } else if (from == Strings::shader) { + } else if (from == Hashes::shader) { // inline of Mask::set_on(lane) shader_space_bits |= 1 << lane; - } else if (from == Strings::object) { + } else if (from == Hashes::object) { // inline of Mask::set_on(lane) object_space_bits |= 1 << lane; } else { @@ -731,7 +733,7 @@ impl_get_varying_from_matrix_batched(BatchedShaderGlobals* bsg, OSL_BATCHOP void __OSL_MASKED_OP2(prepend_matrix_from, Wm, s)(void* bsg_, void* wr, - const char* from, + ustringhash_pod from_, unsigned int mask_value) { auto* bsg = reinterpret_cast(bsg_); @@ -739,7 +741,7 @@ __OSL_MASKED_OP2(prepend_matrix_from, Wm, s)(void* bsg_, void* wr, Block wMfrom; Masked from_matrix(wMfrom, Mask(mask_value)); /*Mask succeeded =*/ - impl_get_uniform_from_matrix_masked(bsg, from_matrix, from); + impl_get_uniform_from_matrix_masked(bsg, from_matrix, from_); Masked wrm(wr, Mask(mask_value)); @@ -796,13 +798,13 @@ impl_get_varying_to_matrix_masked(BatchedShaderGlobals* bsg, for (int lane = 0; lane < __OSL_WIDTH; ++lane) { ustringhash to = wTo[lane]; if (wMto.mask()[lane]) { - if (to == Strings::common || to == commonspace_synonym) { + if (to == Hashes::common || to == commonspace_synonym) { // inline of Mask::set_on(lane) common_space_bits |= 1 << lane; - } else if (to == Strings::shader) { + } else if (to == Hashes::shader) { // inline of Mask::set_on(lane) shader_space_bits |= 1 << lane; - } else if (to == Strings::object) { + } else if (to == Hashes::object) { // inline of Mask::set_on(lane) object_space_bits |= 1 << lane; } else { @@ -867,18 +869,19 @@ impl_get_varying_to_matrix_masked(BatchedShaderGlobals* bsg, OSL_FORCEINLINE Mask impl_get_uniform_from_to_matrix_masked(BatchedShaderGlobals* bsg, - Masked wrm, const char* from, - const char* to) + Masked wrm, + ustringhash_pod from_, + ustringhash_pod to_) { Block wMfrom, wMto; Masked from_matrix(wMfrom, wrm.mask()); Mask succeeded = impl_get_uniform_from_matrix_masked(bsg, from_matrix, - from); + from_); // 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 Masked to_matrix(wMto, wrm.mask()); - succeeded &= impl_get_uniform_to_inverse_matrix_masked(bsg, to_matrix, to); + succeeded &= impl_get_uniform_to_inverse_matrix_masked(bsg, to_matrix, to_); impl_wide_mat_multiply(wrm, from_matrix, to_matrix); return succeeded; @@ -886,27 +889,27 @@ impl_get_uniform_from_to_matrix_masked(BatchedShaderGlobals* bsg, } // namespace OSL_BATCHOP int -__OSL_MASKED_OP3(get_from_to_matrix, Wm, s, s)(void* bsg_, void* wr, - const char* from, const char* to, - unsigned int mask_value) +__OSL_MASKED_OP3(get_from_to_matrix, Wm, s, + s)(void* bsg_, void* wr, ustringhash_pod from_, + ustringhash_pod to_, unsigned int mask_value) { auto* bsg = reinterpret_cast(bsg_); Masked wrm(wr, Mask(mask_value)); - return impl_get_uniform_from_to_matrix_masked(bsg, wrm, from, to).value(); + return impl_get_uniform_from_to_matrix_masked(bsg, wrm, from_, to_).value(); } OSL_BATCHOP int __OSL_MASKED_OP3(get_from_to_matrix, Wm, s, - Ws)(void* bsg_, void* wr, const char* from, void* w_to_ptr, - unsigned int mask_value) + Ws)(void* bsg_, void* wr, ustringhash_pod from_, + void* w_to_ptr, unsigned int mask_value) { auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; Block wMfrom; Masked from_matrix(wMfrom, Mask(mask_value)); Mask succeeded = impl_get_uniform_from_matrix_masked(bsg, from_matrix, - from); + from_); Block bwToSpace; block_ustringhash_from_ptr(bwToSpace, w_to_ptr); @@ -927,7 +930,7 @@ __OSL_MASKED_OP3(get_from_to_matrix, Wm, s, OSL_BATCHOP int __OSL_MASKED_OP3(get_from_to_matrix, Wm, Ws, - s)(void* bsg_, void* wr, void* w_from_ptr, const char* to, + s)(void* bsg_, void* wr, void* w_from_ptr, ustringhash_pod to_, unsigned int mask_value) { auto* bsg = reinterpret_cast(bsg_); @@ -940,7 +943,7 @@ __OSL_MASKED_OP3(get_from_to_matrix, Wm, Ws, Block wMto; Masked to_matrix(wMto, Mask(mask_value)); Mask succeeded = impl_get_uniform_to_inverse_matrix_masked(bsg, to_matrix, - to); + to_); Block wMfrom; // NOTE: even if we failed to get a to matrix, it should have been set to @@ -1001,34 +1004,30 @@ __OSL_MASKED_OP3(get_from_to_matrix, Wm, Ws, OSL_BATCHOP int __OSL_MASKED_OP3(build_transform_matrix, Wm, s, - s)(void* bsg_, void* WM_, ustring_pod from_, ustring_pod to_, - unsigned int mask_value) + s)(void* bsg_, void* WM_, ustringhash_pod from_, + ustringhash_pod to_, unsigned int mask_value) { - auto* bsg = reinterpret_cast(bsg_); + ustringhash from = ustringhash_from(from_); + ustringhash to = ustringhash_from(to_); + auto* bsg = reinterpret_cast(bsg_); Mask mask(mask_value); Masked mm(WM_, mask); ShadingContext* ctx = bsg->uniform.context; - ustring from = USTR(from_); - ustring to = USTR(to_); - Mask succeeded; // Avoid matrix concatenation if possible by detecting when the // adjacent matrix would be identity // We don't expect both from and to == common, so we are not // optimizing for it - if (from == Strings::common + if (from == Hashes::common || from == ctx->shadingsys().commonspace_synonym()) { - succeeded = impl_get_uniform_to_inverse_matrix_masked(bsg, mm, - to.c_str()); - } else if (to == Strings::common + succeeded = impl_get_uniform_to_inverse_matrix_masked(bsg, mm, to_); + } else if (to == Hashes::common || to == ctx->shadingsys().commonspace_synonym()) { - succeeded = impl_get_uniform_from_matrix_masked(bsg, mm, from.c_str()); + succeeded = impl_get_uniform_from_matrix_masked(bsg, mm, from_); } else { - succeeded = impl_get_uniform_from_to_matrix_masked(bsg, mm, - from.c_str(), - to.c_str()); + succeeded = impl_get_uniform_from_to_matrix_masked(bsg, mm, from_, to_); } return succeeded.value(); } @@ -1037,7 +1036,7 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, s, OSL_BATCHOP int __OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, - s)(void* bsg_, void* WM_, void* wfrom_, ustring_pod to_, + s)(void* bsg_, void* WM_, void* wfrom_, ustringhash_pod to_, unsigned int mask_value) { auto* bsg = reinterpret_cast(bsg_); @@ -1049,8 +1048,6 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, block_ustringhash_from_ptr(bwfrom_space, wfrom_); Wide wfrom_space(bwfrom_space); - ustring to_space = USTR(to_); - Block wMfrom, wMto; Masked from_matrix(wMfrom, wrm.mask()); ShadingContext* ctx = bsg->uniform.context; @@ -1058,8 +1055,7 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, Mask succeeded = impl_get_varying_from_matrix_batched(bsg, ctx, wfrom_space, from_matrix); Masked to_matrix(wMto, wrm.mask() & succeeded); - succeeded &= impl_get_uniform_to_inverse_matrix_masked(bsg, to_matrix, - to_space.c_str()); + succeeded &= impl_get_uniform_to_inverse_matrix_masked(bsg, to_matrix, to_); impl_wide_mat_multiply(wrm, from_matrix, to_matrix); return succeeded.value(); @@ -1069,7 +1065,7 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, OSL_BATCHOP int __OSL_MASKED_OP3(build_transform_matrix, Wm, s, - Ws)(void* bsg_, void* WM_, ustring_pod from_, void* wto_, + Ws)(void* bsg_, void* WM_, ustringhash_pod from_, void* wto_, unsigned int mask_value) { auto* bsg = reinterpret_cast(bsg_); @@ -1077,7 +1073,6 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, s, Mask mask(mask_value); Masked wrm(WM_, mask); - ustring from = USTR(from_); Block bwto_space; block_ustringhash_from_ptr(bwto_space, wto_); Wide wto_space(bwto_space); @@ -1087,7 +1082,7 @@ __OSL_MASKED_OP3(build_transform_matrix, Wm, s, ShadingContext* ctx = bsg->uniform.context; Mask succeeded = impl_get_uniform_from_matrix_masked(bsg, from_matrix, - from.c_str()); + from_); Masked to_matrix(wMto, wrm.mask() & succeeded); succeeded &= impl_get_varying_to_matrix_masked(bsg, ctx, wto_space, to_matrix); diff --git a/src/liboslexec/wide/wide_opmessage.cpp b/src/liboslexec/wide/wide_opmessage.cpp index de426f9c7c..be2c11e3e6 100644 --- a/src/liboslexec/wide/wide_opmessage.cpp +++ b/src/liboslexec/wide/wide_opmessage.cpp @@ -201,18 +201,19 @@ impl_setmessage(BatchedShaderGlobals* bsg, ustring sourcefile, int sourceline, OSL_BATCHOP void __OSL_MASKED_OP2(setmessage, s, WX)(BatchedShaderGlobals* bsg_, - ustring_pod name_, long long type, + ustringhash_pod name_, long long type, void* wvalue, int layeridx, - ustring_pod sourcefile_, int sourceline, + ustringhash_pod sourcefile_, int sourceline, unsigned int mask_value) { Mask mask(mask_value); OSL_ASSERT(mask.any_on()); - ustring name = USTR(name_); + ustring name = ustring_from(name_); + MaskedData wsrcval(TYPEDESC(type), false /*has_derivs*/, mask, wvalue); - ustring sourcefile = USTR(sourcefile_); + ustring sourcefile = ustring_from(sourcefile_); auto* bsg = reinterpret_cast(bsg_); @@ -238,8 +239,8 @@ __OSL_MASKED_OP2(setmessage, s, WX)(BatchedShaderGlobals* bsg_, OSL_BATCHOP void __OSL_MASKED_OP2(setmessage, Ws, WX)(BatchedShaderGlobals* bsg_, void* wname, long long type, void* wvalue, int layeridx, - ustring_pod sourcefile_, int sourceline, - unsigned int mask_value) + ustringhash_pod sourcefile_, + int sourceline, unsigned int mask_value) { Mask mask(mask_value); OSL_ASSERT(mask.any_on()); @@ -247,7 +248,7 @@ __OSL_MASKED_OP2(setmessage, Ws, WX)(BatchedShaderGlobals* bsg_, void* wname, Wide wName(wname); MaskedData wsrcval(TYPEDESC(type), false /*has_derivs*/, mask, wvalue); - ustring sourcefile = USTR(sourcefile_); + ustring sourcefile = ustring_from(sourcefile_); auto* bsg = reinterpret_cast(bsg_); @@ -275,14 +276,15 @@ __OSL_MASKED_OP2(setmessage, Ws, WX)(BatchedShaderGlobals* bsg_, void* wname, OSL_BATCHOP void -__OSL_MASKED_OP(getmessage)(void* bsg_, void* result, ustring_pod source_, - ustring_pod name_, long long type_, void* val, - int derivs, int layeridx, ustring_pod sourcefile_, - int sourceline, unsigned int mask_value) +__OSL_MASKED_OP(getmessage)(void* bsg_, void* result, ustringhash_pod source_, + ustringhash_pod name_, long long type_, void* val, + int derivs, int layeridx, + ustringhash_pod sourcefile_, int sourceline, + unsigned int mask_value) { - ustring source = USTR(source_); - ustring name = USTR(name_); - ustring sourcefile = USTR(sourcefile_); + ustring source = ustring_from(source_); + ustring name = ustring_from(name_); + ustring sourcefile = ustring_from(sourcefile_); Mask mask(mask_value); @@ -301,7 +303,7 @@ __OSL_MASKED_OP(getmessage)(void* bsg_, void* result, ustring_pod source_, static ustring ktrace("trace"); OSL_ASSERT(val != nullptr); MaskedData valRef(type, derivs, mask, val); - if (USTR(source_) == ktrace) { + if (source == ktrace) { // Source types where we need to ask the renderer return bsg->uniform.renderer->batched(WidthTag()) ->getmessage(bsg, wR, source, name, valRef); diff --git a/src/liboslexec/wide/wide_opnoise_gabor_impl.cpp b/src/liboslexec/wide/wide_opnoise_gabor_impl.cpp index 7dd2b66b51..8008c18f3c 100644 --- a/src/liboslexec/wide/wide_opnoise_gabor_impl.cpp +++ b/src/liboslexec/wide/wide_opnoise_gabor_impl.cpp @@ -79,8 +79,8 @@ dispatch_Vec3_result(const NoiseParams* opt, Block* opt_varying_direction, } // namespace OSL_BATCHOP void -__OSL_NOISE_OP2(Wdf, Wdf)(char* name, char* r_ptr, char* x_ptr, char* bsg, - char* opt, char* varying_direction_ptr, +__OSL_NOISE_OP2(Wdf, Wdf)(ustringhash_pod name, char* r_ptr, char* x_ptr, + char* bsg, char* opt, char* varying_direction_ptr, unsigned int mask_value) { dispatch_float_result(reinterpret_cast(opt), @@ -92,7 +92,7 @@ __OSL_NOISE_OP2(Wdf, Wdf)(char* name, char* r_ptr, char* x_ptr, char* bsg, OSL_BATCHOP void -__OSL_NOISE_OP3(Wdf, Wdf, Wdf)(char* name, char* r_ptr, char* x_ptr, +__OSL_NOISE_OP3(Wdf, Wdf, Wdf)(ustringhash_pod name, char* r_ptr, char* x_ptr, char* y_ptr, char* bsg, char* opt, char* varying_direction_ptr, unsigned int mask_value) @@ -107,8 +107,8 @@ __OSL_NOISE_OP3(Wdf, Wdf, Wdf)(char* name, char* r_ptr, char* x_ptr, OSL_BATCHOP void -__OSL_NOISE_OP2(Wdf, Wdv)(char* name, char* r_ptr, char* p_ptr, char* bsg, - char* opt, char* varying_direction_ptr, +__OSL_NOISE_OP2(Wdf, Wdv)(ustringhash_pod name, char* r_ptr, char* p_ptr, + char* bsg, char* opt, char* varying_direction_ptr, unsigned int mask_value) { dispatch_float_result(reinterpret_cast(opt), @@ -120,7 +120,7 @@ __OSL_NOISE_OP2(Wdf, Wdv)(char* name, char* r_ptr, char* p_ptr, char* bsg, OSL_BATCHOP void -__OSL_NOISE_OP3(Wdf, Wdv, Wdf)(char* name, char* r_ptr, char* p_ptr, +__OSL_NOISE_OP3(Wdf, Wdv, Wdf)(ustringhash_pod name, char* r_ptr, char* p_ptr, char* t_ptr, char* bsg, char* opt, char* varying_direction_ptr, unsigned int mask_value) @@ -135,7 +135,7 @@ __OSL_NOISE_OP3(Wdf, Wdv, Wdf)(char* name, char* r_ptr, char* p_ptr, OSL_BATCHOP void -__OSL_NOISE_OP3(Wdv, Wdv, Wdf)(char* name, char* r_ptr, char* p_ptr, +__OSL_NOISE_OP3(Wdv, Wdv, Wdf)(ustringhash_pod name, char* r_ptr, char* p_ptr, char* t_ptr, char* bsg, char* opt, char* varying_direction_ptr, unsigned int mask_value) @@ -150,8 +150,8 @@ __OSL_NOISE_OP3(Wdv, Wdv, Wdf)(char* name, char* r_ptr, char* p_ptr, OSL_BATCHOP void -__OSL_NOISE_OP2(Wdv, Wdf)(char* name, char* r_ptr, char* x_ptr, char* bsg, - char* opt, char* varying_direction_ptr, +__OSL_NOISE_OP2(Wdv, Wdf)(ustringhash_pod name, char* r_ptr, char* x_ptr, + char* bsg, char* opt, char* varying_direction_ptr, unsigned int mask_value) { dispatch_Vec3_result(reinterpret_cast(opt), @@ -163,7 +163,7 @@ __OSL_NOISE_OP2(Wdv, Wdf)(char* name, char* r_ptr, char* x_ptr, char* bsg, OSL_BATCHOP void -__OSL_NOISE_OP3(Wdv, Wdf, Wdf)(char* name, char* r_ptr, char* x_ptr, +__OSL_NOISE_OP3(Wdv, Wdf, Wdf)(ustringhash_pod name, char* r_ptr, char* x_ptr, char* y_ptr, char* bsg, char* opt, char* varying_direction_ptr, unsigned int mask_value) @@ -178,8 +178,8 @@ __OSL_NOISE_OP3(Wdv, Wdf, Wdf)(char* name, char* r_ptr, char* x_ptr, OSL_BATCHOP void -__OSL_NOISE_OP2(Wdv, Wdv)(char* name, char* r_ptr, char* p_ptr, char* bsg, - char* opt, char* varying_direction_ptr, +__OSL_NOISE_OP2(Wdv, Wdv)(ustringhash_pod name, char* r_ptr, char* p_ptr, + char* bsg, char* opt, char* varying_direction_ptr, unsigned int mask_value) { dispatch_Vec3_result(reinterpret_cast(opt), diff --git a/src/liboslexec/wide/wide_opnoise_generic_impl.cpp b/src/liboslexec/wide/wide_opnoise_generic_impl.cpp index 2f5679ada7..8f6ff99dd8 100644 --- a/src/liboslexec/wide/wide_opnoise_generic_impl.cpp +++ b/src/liboslexec/wide/wide_opnoise_generic_impl.cpp @@ -78,11 +78,9 @@ zero_derivs(Masked> wr) #define __OSL_GENERIC_DISPATCH2(A, B, NONDERIV_A, NONDERIV_B, DUALTYPE) \ - OSL_BATCHOP void __OSL_MASKED_OP2(gabornoise, A, \ - B)(char* name_ptr, char* r_ptr, \ - char* x_ptr, char* bsg, char* opt, \ - char* varying_direction_ptr, \ - unsigned int mask_value); \ + OSL_BATCHOP void __OSL_MASKED_OP2(gabornoise, A, B)( \ + ustringhash_pod name_ptr, char* r_ptr, char* x_ptr, char* bsg, \ + char* opt, char* varying_direction_ptr, unsigned int mask_value); \ OSL_BATCHOP void __OSL_MASKED_OP2(noise, A, B)(char* r_ptr, char* x_ptr, \ unsigned int mask_value); \ OSL_BATCHOP void __OSL_MASKED_OP2(simplexnoise, A, \ @@ -105,38 +103,35 @@ zero_derivs(Masked> wr) OSL_BATCHOP void __OSL_MASKED_OP2(hashnoise, NONDERIV_A, \ NONDERIV_B)(char* r_ptr, char* x_ptr, \ unsigned int mask_value); \ - OSL_BATCHOP void __OSL_MASKED_OP2(genericnoise, A, \ - B)(char* name_ptr, char* r_ptr, \ - char* x_ptr, char* bsg, char* opt, \ - char* varying_direction_ptr, \ - unsigned int mask_value) \ + OSL_BATCHOP void __OSL_MASKED_OP2(genericnoise, A, B)( \ + ustringhash_pod name_ptr, char* r_ptr, char* x_ptr, char* bsg, \ + char* opt, char* varying_direction_ptr, unsigned int mask_value) \ { \ - ustring name = USTR(name_ptr); \ - if (name == Strings::uperlin || name == Strings::noise) { \ + ustringhash name = ustringhash_from(name_ptr); \ + if (name == Hashes::uperlin || name == Hashes::noise) { \ __OSL_MASKED_OP2(noise, A, B)(r_ptr, x_ptr, mask_value); \ - } else if (name == Strings::perlin || name == Strings::snoise) { \ + } else if (name == Hashes::perlin || name == Hashes::snoise) { \ __OSL_MASKED_OP2(snoise, A, B)(r_ptr, x_ptr, mask_value); \ - } else if (name == Strings::simplexnoise \ - || name == Strings::simplex) { \ + } else if (name == Hashes::simplexnoise || name == Hashes::simplex) { \ __OSL_MASKED_OP2(simplexnoise, A, B)(r_ptr, x_ptr, mask_value); \ - } else if (name == Strings::usimplexnoise \ - || name == Strings::usimplex) { \ + } else if (name == Hashes::usimplexnoise \ + || name == Hashes::usimplex) { \ __OSL_MASKED_OP2(usimplexnoise, A, B)(r_ptr, x_ptr, mask_value); \ - } else if (name == Strings::cell) { \ + } else if (name == Hashes::cell) { \ /* NOTE: calling non derivative version */ \ __OSL_MASKED_OP2(cellnoise, NONDERIV_A, NONDERIV_B) \ (r_ptr, x_ptr, mask_value); \ Masked wr(r_ptr, Mask(mask_value)); \ zero_derivs(wr); \ - } else if (name == Strings::gabor) { \ + } else if (name == Hashes::gabor) { \ __OSL_MASKED_OP2(gabornoise, A, B) \ (name_ptr, r_ptr, x_ptr, bsg, opt, varying_direction_ptr, \ mask_value); \ - } else if (name == Strings::null) { \ + } else if (name == Hashes::null) { \ __OSL_MASKED_OP2(nullnoise, A, B)(r_ptr, x_ptr, mask_value); \ - } else if (name == Strings::unull) { \ + } else if (name == Hashes::unull) { \ __OSL_MASKED_OP2(unullnoise, A, B)(r_ptr, x_ptr, mask_value); \ - } else if (name == Strings::hash) { \ + } else if (name == Hashes::hash) { \ /* NOTE: calling non derivative version */ \ __OSL_MASKED_OP2(hashnoise, NONDERIV_A, NONDERIV_B) \ (r_ptr, x_ptr, mask_value); \ @@ -155,9 +150,12 @@ __OSL_GENERIC_DISPATCH2(Wdf, Wdf, Wf, Wf, Dual2) #define __OSL_GENERIC_DISPATCH3(A, B, C, NONDERIV_A, NONDERIV_B, NONDERIV_C, \ DUALTYPE) \ - OSL_BATCHOP void __OSL_MASKED_OP3(gabornoise, A, B, C)( \ - char* name_ptr, char* r_ptr, char* x_ptr, char* y_ptr, char* bsg, \ - char* opt, char* varying_direction_ptr, unsigned int mask_value); \ + OSL_BATCHOP void __OSL_MASKED_OP3(gabornoise, A, B, \ + C)(ustringhash_pod name_ptr, \ + char* r_ptr, char* x_ptr, \ + char* y_ptr, char* bsg, char* opt, \ + char* varying_direction_ptr, \ + unsigned int mask_value); \ OSL_BATCHOP void __OSL_MASKED_OP3(noise, A, B, \ C)(char* r_ptr, char* x_ptr, \ char* y_ptr, \ @@ -190,41 +188,43 @@ __OSL_GENERIC_DISPATCH2(Wdf, Wdf, Wf, Wf, Dual2) NONDERIV_C)(char* r_ptr, char* x_ptr, \ char* y_ptr, \ unsigned int mask_value); \ - OSL_BATCHOP void __OSL_MASKED_OP3(genericnoise, A, B, C)( \ - char* name_ptr, char* r_ptr, char* x_ptr, char* y_ptr, char* bsg, \ - char* opt, char* varying_direction_ptr, unsigned int mask_value) \ + OSL_BATCHOP void __OSL_MASKED_OP3(genericnoise, A, B, \ + C)(ustringhash_pod name_ptr, \ + char* r_ptr, char* x_ptr, \ + char* y_ptr, char* bsg, char* opt, \ + char* varying_direction_ptr, \ + unsigned int mask_value) \ { \ - ustring name = USTR(name_ptr); \ - if (name == Strings::uperlin || name == Strings::noise) { \ + ustringhash name = ustringhash_from(name_ptr); \ + if (name == Hashes::uperlin || name == Hashes::noise) { \ __OSL_MASKED_OP3(noise, A, B, C)(r_ptr, x_ptr, y_ptr, mask_value); \ - } else if (name == Strings::perlin || name == Strings::snoise) { \ + } else if (name == Hashes::perlin || name == Hashes::snoise) { \ __OSL_MASKED_OP3(snoise, A, B, C) \ (r_ptr, x_ptr, y_ptr, mask_value); \ - } else if (name == Strings::simplexnoise \ - || name == Strings::simplex) { \ + } else if (name == Hashes::simplexnoise || name == Hashes::simplex) { \ __OSL_MASKED_OP3(simplexnoise, A, B, C) \ (r_ptr, x_ptr, y_ptr, mask_value); \ - } else if (name == Strings::usimplexnoise \ - || name == Strings::usimplex) { \ + } else if (name == Hashes::usimplexnoise \ + || name == Hashes::usimplex) { \ __OSL_MASKED_OP3(usimplexnoise, A, B, C) \ (r_ptr, x_ptr, y_ptr, mask_value); \ - } else if (name == Strings::cell) { \ + } else if (name == Hashes::cell) { \ /* NOTE: calling non derivative version */ \ __OSL_MASKED_OP3(cellnoise, NONDERIV_A, NONDERIV_B, NONDERIV_C) \ (r_ptr, x_ptr, y_ptr, mask_value); \ Masked wr(r_ptr, Mask(mask_value)); \ zero_derivs(wr); \ - } else if (name == Strings::gabor) { \ + } else if (name == Hashes::gabor) { \ __OSL_MASKED_OP3(gabornoise, A, B, C) \ (name_ptr, r_ptr, x_ptr, y_ptr, bsg, opt, varying_direction_ptr, \ mask_value); \ - } else if (name == Strings::null) { \ + } else if (name == Hashes::null) { \ __OSL_MASKED_OP3(nullnoise, A, B, C) \ (r_ptr, x_ptr, y_ptr, mask_value); \ - } else if (name == Strings::unull) { \ + } else if (name == Hashes::unull) { \ __OSL_MASKED_OP3(unullnoise, A, B, C) \ (r_ptr, x_ptr, y_ptr, mask_value); \ - } else if (name == Strings::hash) { \ + } else if (name == Hashes::hash) { \ /* NOTE: calling non derivative version */ \ __OSL_MASKED_OP3(hashnoise, NONDERIV_A, NONDERIV_B, NONDERIV_C) \ (r_ptr, x_ptr, y_ptr, mask_value); \ diff --git a/src/liboslexec/wide/wide_opnoise_periodic_generic_impl.cpp b/src/liboslexec/wide/wide_opnoise_periodic_generic_impl.cpp index 8d0357640a..8250fd66b9 100644 --- a/src/liboslexec/wide/wide_opnoise_periodic_generic_impl.cpp +++ b/src/liboslexec/wide/wide_opnoise_periodic_generic_impl.cpp @@ -24,9 +24,12 @@ OSL_USING_DATA_WIDTH(__OSL_WIDTH) #define __OSL_GENERIC_DISPATCH3(A, B, C, NONDERIV_A, NONDERIV_B, DUALTYPE) \ - OSL_BATCHOP void __OSL_MASKED_OP3(gaborpnoise, A, B, C)( \ - char* name_ptr, char* r_ptr, char* x_ptr, char* px_ptr, char* bsg, \ - char* opt, char* varying_direction_ptr, unsigned int mask_value); \ + OSL_BATCHOP void __OSL_MASKED_OP3(gaborpnoise, A, B, \ + C)(ustringhash_pod name_ptr, \ + char* r_ptr, char* x_ptr, \ + char* px_ptr, char* bsg, char* opt, \ + char* varying_direction_ptr, \ + unsigned int mask_value); \ OSL_BATCHOP void __OSL_MASKED_OP3(pnoise, A, B, \ C)(char* r_ptr, char* x_ptr, \ char* px_ptr, \ @@ -43,11 +46,14 @@ OSL_USING_DATA_WIDTH(__OSL_WIDTH) C)(char* r_ptr, char* x_ptr, \ char* px_ptr, \ unsigned int mask_value); \ - OSL_BATCHOP void __OSL_MASKED_OP3(genericpnoise, A, B, C)( \ - char* name_ptr, char* r_ptr, char* x_ptr, char* px_ptr, char* bsg, \ - char* opt, char* varying_direction_ptr, unsigned int mask_value) \ + OSL_BATCHOP void __OSL_MASKED_OP3(genericpnoise, A, B, \ + C)(ustringhash_pod name_ptr, \ + char* r_ptr, char* x_ptr, \ + char* px_ptr, char* bsg, char* opt, \ + char* varying_direction_ptr, \ + unsigned int mask_value) \ { \ - ustring name = USTR(name_ptr); \ + ustringhash name = ustringhash_from(name_ptr); \ if (name == Strings::uperlin || name == Strings::noise) { \ __OSL_MASKED_OP3(pnoise, A, B, C) \ (r_ptr, x_ptr, px_ptr, mask_value); \ @@ -95,9 +101,9 @@ OSL_USING_DATA_WIDTH(__OSL_WIDTH) #define __OSL_GENERIC_DISPATCH5(A, B, C, D, E, NONDERIV_A, NONDERIV_B, \ NONDERIV_C, DUALTYPE) \ OSL_BATCHOP void __OSL_MASKED_OP5(gaborpnoise, A, B, C, D, E)( \ - char* name_ptr, char* r_ptr, char* x_ptr, char* y_ptr, char* px_ptr, \ - char* py_ptr, char* bsg, char* opt, char* varying_direction_ptr, \ - unsigned int mask_value); \ + ustringhash_pod name_ptr, char* r_ptr, char* x_ptr, char* y_ptr, \ + char* px_ptr, char* py_ptr, char* bsg, char* opt, \ + char* varying_direction_ptr, unsigned int mask_value); \ OSL_BATCHOP void __OSL_MASKED_OP5(pnoise, A, B, C, D, \ E)(char* r_ptr, char* x_ptr, \ char* y_ptr, char* px_ptr, \ @@ -121,11 +127,11 @@ OSL_USING_DATA_WIDTH(__OSL_WIDTH) char* py_ptr, \ unsigned int mask_value); \ OSL_BATCHOP void __OSL_MASKED_OP5(genericpnoise, A, B, C, D, E)( \ - char* name_ptr, char* r_ptr, char* x_ptr, char* y_ptr, char* px_ptr, \ - char* py_ptr, char* bsg, char* opt, char* varying_direction_ptr, \ - unsigned int mask_value) \ + ustringhash_pod name_ptr, char* r_ptr, char* x_ptr, char* y_ptr, \ + char* px_ptr, char* py_ptr, char* bsg, char* opt, \ + char* varying_direction_ptr, unsigned int mask_value) \ { \ - ustring name = USTR(name_ptr); \ + ustringhash name = ustringhash_from(name_ptr); \ if (name == Strings::uperlin || name == Strings::noise) { \ __OSL_MASKED_OP5(pnoise, A, B, C, D, E) \ (r_ptr, x_ptr, y_ptr, px_ptr, py_ptr, mask_value); \ diff --git a/src/liboslexec/wide/wide_oppointcloud.cpp b/src/liboslexec/wide/wide_oppointcloud.cpp index 1ed34138b0..091921e2c5 100644 --- a/src/liboslexec/wide/wide_oppointcloud.cpp +++ b/src/liboslexec/wide/wide_oppointcloud.cpp @@ -494,7 +494,7 @@ dispatch_pointcloud_write(BatchedShaderGlobals* bsg, ustringhash filename, OSL_BATCHOP void __OSL_MASKED_OP(pointcloud_search)( - BatchedShaderGlobals* bsg, void* wout_num_points_, ustring_pod filename, + BatchedShaderGlobals* bsg, void* wout_num_points_, ustringhash_pod filename, const void* wcenter_, void* wradius_, int max_points, int sort, void* wout_indices_, int indices_array_length, void* wout_distances_, int distances_array_length, int distances_has_derivs, int mask_value, @@ -521,8 +521,8 @@ __OSL_MASKED_OP(pointcloud_search)( Wide wradius(wradius_); - dispatch_pointcloud_search(bsg, USTR(filename).uhash(), wcenter_, wradius, - max_points, sort, pcsr); + dispatch_pointcloud_search(bsg, ustringhash_from(filename), wcenter_, + wradius, max_points, sort, pcsr); if (nattrs > 0) { Wide windices { wout_indices_, indices_array_length }; @@ -531,12 +531,15 @@ __OSL_MASKED_OP(pointcloud_search)( va_list args; va_start(args, nattrs); for (int i = 0; i < nattrs; i++) { - ustring attr_name = USTR(va_arg(args, ustring_pod)); + ustringhash attr_name = ustringhash_from( + va_arg(args, ustringhash_pod)); TypeDesc attr_type = TYPEDESC(va_arg(args, long long)); void* out_data = va_arg(args, void*); - dispatch_pointcloud_get( - bsg, USTR(filename), windices, wnum_points, attr_name, - MaskedData { attr_type, false, Mask { mask_value }, out_data }); + dispatch_pointcloud_get(bsg, ustringhash_from(filename), windices, + wnum_points, attr_name, + MaskedData { attr_type, false, + Mask { mask_value }, + out_data }); } va_end(args); } @@ -548,11 +551,11 @@ __OSL_MASKED_OP(pointcloud_search)( OSL_BATCHOP int -__OSL_MASKED_OP(pointcloud_get)(BatchedShaderGlobals* bsg, ustring_pod filename, - void* windices_, int indices_array_length, - void* wnum_points_, ustring_pod attr_name, - long long attr_type_, void* wout_data_, - int mask_value) +__OSL_MASKED_OP(pointcloud_get)(BatchedShaderGlobals* bsg, + ustringhash_pod filename, void* windices_, + int indices_array_length, void* wnum_points_, + ustringhash_pod attr_name, long long attr_type_, + void* wout_data_, int mask_value) { ShadingContext* ctx = bsg->uniform.context; if (ctx->shadingsys() @@ -565,8 +568,8 @@ __OSL_MASKED_OP(pointcloud_get)(BatchedShaderGlobals* bsg, ustring_pod filename, TypeDesc attr_type = TYPEDESC(attr_type_); Mask success = dispatch_pointcloud_get( - bsg, USTR(filename).uhash(), windices, wnum_points, - USTR(attr_name).uhash(), + bsg, ustringhash_from(filename), windices, wnum_points, + ustringhash_from(attr_name), MaskedData { attr_type, false, Mask { mask_value }, wout_data_ }); return success.value(); } @@ -575,7 +578,7 @@ __OSL_MASKED_OP(pointcloud_get)(BatchedShaderGlobals* bsg, ustring_pod filename, OSL_BATCHOP int __OSL_MASKED_OP(pointcloud_write)(BatchedShaderGlobals* bsg, - ustring_pod filename, const void* wpos_, + ustringhash_pod filename, const void* wpos_, int nattribs, const ustring* attr_names, const TypeDesc* attr_types, const void** ptrs_to_wide_attr_value, @@ -589,10 +592,10 @@ __OSL_MASKED_OP(pointcloud_write)(BatchedShaderGlobals* bsg, Wide wpos(wpos_); - Mask success = dispatch_pointcloud_write(bsg, USTR(filename).uhash(), wpos, - nattribs, attr_names, attr_types, - ptrs_to_wide_attr_value, - Mask(mask_value)); + Mask success + = dispatch_pointcloud_write(bsg, ustringhash_from(filename), wpos, + nattribs, attr_names, attr_types, + ptrs_to_wide_attr_value, Mask(mask_value)); return success.value(); } diff --git a/src/liboslexec/wide/wide_opspline.cpp b/src/liboslexec/wide/wide_opspline.cpp index 0b77b9cb26..6e48e2bd37 100644 --- a/src/liboslexec/wide/wide_opspline.cpp +++ b/src/liboslexec/wide/wide_opspline.cpp @@ -431,7 +431,7 @@ spline_evaluate_wide_with_static_matrix(RAccessorT wR, XAccessorT wX, template OSL_FORCEINLINE void -spline_evaluate_wide(RAccessorT wR, ustring spline_basis, XAccessorT wX, +spline_evaluate_wide(RAccessorT wR, ustringhash spline_basis, XAccessorT wX, KAccessor_T wK, int knot_count) { typedef void (*FuncPtr)(RAccessorT, XAccessorT, KAccessor_T, @@ -514,8 +514,8 @@ splineinverse_evaluate_wide_with_static_matrix(RAccessorT wR, XAccessorT wX, template OSL_FORCEINLINE void -splineinverse_evaluate_wide(RAccessorT wR, ustring spline_basis, XAccessorT wX, - KAccessor_T wK, int knot_count) +splineinverse_evaluate_wide(RAccessorT wR, ustringhash spline_basis, + XAccessorT wX, KAccessor_T wK, int knot_count) { typedef void (*FuncPtr)(RAccessorT, XAccessorT, KAccessor_T, int /*knot_count*/); @@ -554,12 +554,12 @@ splineinverse_evaluate_wide(RAccessorT wR, ustring spline_basis, XAccessorT wX, // spline (hermite, bezier, etc.) vs. making us doing a bunch of comparisons OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wf, Wf, f)(void* wout_, const char* spline_, void* wx_, - float* knots, int knot_count, +__OSL_MASKED_OP3(spline, Wf, Wf, f)(void* wout_, ustringhash_pod spline_, + void* wx_, float* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { - spline_evaluate_wide(Masked(wout_, Mask(mask_value)), USTR(spline_), - Wide(wx_), + spline_evaluate_wide(Masked(wout_, Mask(mask_value)), + ustringhash_from(spline_), Wide(wx_), UniformAsWide(knots, knot_arraylen), knot_count); } @@ -567,11 +567,12 @@ __OSL_MASKED_OP3(spline, Wf, Wf, f)(void* wout_, const char* spline_, void* wx_, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wf, f, Wf)(void* wout_, const char* spline_, void* wx_, - float* knots, int knot_count, +__OSL_MASKED_OP3(spline, Wf, f, Wf)(void* wout_, ustringhash_pod spline_, + void* wx_, float* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { - spline_evaluate_wide(Masked(wout_, Mask(mask_value)), USTR(spline_), + spline_evaluate_wide(Masked(wout_, Mask(mask_value)), + ustringhash_from(spline_), UniformAsWide(wx_), Wide(knots, knot_arraylen), knot_count); } @@ -579,13 +580,14 @@ __OSL_MASKED_OP3(spline, Wf, f, Wf)(void* wout_, const char* spline_, void* wx_, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdf, Wdf, Wdf)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wdf, Wdf, Wdf)(void* wout_, ustringhash_pod spline_, void* wx_, float* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide>(wx_), + ustringhash_from(spline_), + Wide>(wx_), Wide[]>(knots, knot_arraylen), knot_count); } @@ -593,26 +595,27 @@ __OSL_MASKED_OP3(spline, Wdf, Wdf, Wdf)(void* wout_, const char* spline_, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdf, Wdf, - df)(void* wout_, const char* spline_, void* wx_, float* knots, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(spline, Wdf, Wdf, df)(void* wout_, ustringhash_pod spline_, + void* wx_, float* knots, int knot_count, + int knot_arraylen, + unsigned int mask_value) { - spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide>(wx_), - UniformAsWide[]>(knots, - knot_arraylen), - knot_count); + spline_evaluate_wide( + Masked>(wout_, Mask(mask_value)), + ustringhash_from(spline_), Wide>(wx_), + UniformAsWide[]>(knots, knot_arraylen), knot_count); } OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdf, Wf, - df)(void* wout_, const char* spline_, void* wx_, float* knots, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(spline, Wdf, Wf, df)(void* wout_, ustringhash_pod spline_, + void* wx_, float* knots, int knot_count, + int knot_arraylen, + unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide(wx_), + ustringhash_from(spline_), Wide(wx_), UniformAsWide[]>(knots, knot_arraylen), knot_count); @@ -621,13 +624,14 @@ __OSL_MASKED_OP3(spline, Wdf, Wf, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdf, df, Wdf)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wdf, df, Wdf)(void* wout_, ustringhash_pod spline_, void* wx_, float* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), UniformAsWide>(wx_), + ustringhash_from(spline_), + UniformAsWide>(wx_), Wide[]>(knots, knot_arraylen), knot_count); } @@ -637,26 +641,27 @@ __OSL_MASKED_OP3(spline, Wdf, df, Wdf)(void* wout_, const char* spline_, //=========================================================================== OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdf, f, Wdf)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wdf, f, Wdf)(void* wout_, ustringhash_pod spline_, void* wx_, float* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), UniformAsWide(wx_), + ustringhash_from(spline_), + UniformAsWide(wx_), Wide[]>(knots, knot_arraylen), knot_count); } OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdf, Wf, Wdf)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wdf, Wf, Wdf)(void* wout_, ustringhash_pod spline_, void* wx_, float* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide(wx_), + ustringhash_from(spline_), Wide(wx_), Wide[]>(knots, knot_arraylen), knot_count); } @@ -665,12 +670,14 @@ __OSL_MASKED_OP3(spline, Wdf, Wf, Wdf)(void* wout_, const char* spline_, //=========================================================================== OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdf, Wdf, - f)(void* wout_, const char* spline_, void* wx_, float* knots, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(spline, Wdf, Wdf, f)(void* wout_, ustringhash_pod spline_, + void* wx_, float* knots, int knot_count, + int knot_arraylen, + unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide>(wx_), + ustringhash_from(spline_), + Wide>(wx_), UniformAsWide(knots, knot_arraylen), knot_count); } @@ -678,12 +685,12 @@ __OSL_MASKED_OP3(spline, Wdf, Wdf, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wf, Wf, Wf)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wf, Wf, Wf)(void* wout_, ustringhash_pod spline_, void* wx_, void* wknots_, int knot_count, int knot_arraylen, unsigned int mask_value) { - spline_evaluate_wide(Masked(wout_, Mask(mask_value)), USTR(spline_), - Wide(wx_), + spline_evaluate_wide(Masked(wout_, Mask(mask_value)), + ustringhash_from(spline_), Wide(wx_), Wide(wknots_, knot_arraylen), knot_count); } @@ -692,12 +699,12 @@ __OSL_MASKED_OP3(spline, Wf, Wf, Wf)(void* wout_, const char* spline_, //======================================================================= OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wv, Wf, v)(void* wout_, const char* spline_, void* wx_, - Vec3* knots, int knot_count, +__OSL_MASKED_OP3(spline, Wv, Wf, v)(void* wout_, ustringhash_pod spline_, + void* wx_, Vec3* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { - spline_evaluate_wide(Masked(wout_, Mask(mask_value)), USTR(spline_), - Wide(wx_), + spline_evaluate_wide(Masked(wout_, Mask(mask_value)), + ustringhash_from(spline_), Wide(wx_), UniformAsWide(knots, knot_arraylen), knot_count); } @@ -705,23 +712,24 @@ __OSL_MASKED_OP3(spline, Wv, Wf, v)(void* wout_, const char* spline_, void* wx_, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wv, Wf, Wv)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wv, Wf, Wv)(void* wout_, ustringhash_pod spline_, void* wx_, Vec3* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { - spline_evaluate_wide(Masked(wout_, Mask(mask_value)), USTR(spline_), - Wide(wx_), + spline_evaluate_wide(Masked(wout_, Mask(mask_value)), + ustringhash_from(spline_), Wide(wx_), Wide(knots, knot_arraylen), knot_count); } OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wv, f, Wv)(void* wout_, const char* spline_, void* wx_, - Vec3* knots, int knot_count, +__OSL_MASKED_OP3(spline, Wv, f, Wv)(void* wout_, ustringhash_pod spline_, + void* wx_, Vec3* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { - spline_evaluate_wide(Masked(wout_, Mask(mask_value)), USTR(spline_), + spline_evaluate_wide(Masked(wout_, Mask(mask_value)), + ustringhash_from(spline_), UniformAsWide(wx_), Wide(knots, knot_arraylen), knot_count); } @@ -729,12 +737,14 @@ __OSL_MASKED_OP3(spline, Wv, f, Wv)(void* wout_, const char* spline_, void* wx_, //======================================================================= OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, Wdf, - v)(void* wout_, const char* spline_, void* wx_, Vec3* knots, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(spline, Wdv, Wdf, v)(void* wout_, ustringhash_pod spline_, + void* wx_, Vec3* knots, int knot_count, + int knot_arraylen, + unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide>(wx_), + ustringhash_from(spline_), + Wide>(wx_), UniformAsWide(knots, knot_arraylen), knot_count); } @@ -742,24 +752,28 @@ __OSL_MASKED_OP3(spline, Wdv, Wdf, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, Wdf, - Wv)(void* wout_, const char* spline_, void* wx_, Vec3* knots, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(spline, Wdv, Wdf, Wv)(void* wout_, ustringhash_pod spline_, + void* wx_, Vec3* knots, int knot_count, + int knot_arraylen, + unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide>(wx_), + ustringhash_from(spline_), + Wide>(wx_), Wide(knots, knot_arraylen), knot_count); } OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, df, - Wv)(void* wout_, const char* spline_, void* wx_, Vec3* knots, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(spline, Wdv, df, Wv)(void* wout_, ustringhash_pod spline_, + void* wx_, Vec3* knots, int knot_count, + int knot_arraylen, + unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), UniformAsWide>(wx_), + ustringhash_from(spline_), + UniformAsWide>(wx_), Wide(knots, knot_arraylen), knot_count); } @@ -767,13 +781,14 @@ __OSL_MASKED_OP3(spline, Wdv, df, //======================================================================= OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, f, Wdv)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wdv, f, Wdv)(void* wout_, ustringhash_pod spline_, void* wx_, Vec3* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), UniformAsWide(wx_), + ustringhash_from(spline_), + UniformAsWide(wx_), Wide[]>(knots, knot_arraylen), knot_count); } @@ -781,13 +796,13 @@ __OSL_MASKED_OP3(spline, Wdv, f, Wdv)(void* wout_, const char* spline_, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, Wf, Wdv)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wdv, Wf, Wdv)(void* wout_, ustringhash_pod spline_, void* wx_, Vec3* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide(wx_), + ustringhash_from(spline_), Wide(wx_), Wide[]>(knots, knot_arraylen), knot_count); } @@ -795,12 +810,13 @@ __OSL_MASKED_OP3(spline, Wdv, Wf, Wdv)(void* wout_, const char* spline_, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, Wf, - dv)(void* wout_, const char* spline_, void* wx_, Vec3* knots, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(spline, Wdv, Wf, dv)(void* wout_, ustringhash_pod spline_, + void* wx_, Vec3* knots, int knot_count, + int knot_arraylen, + unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide(wx_), + ustringhash_from(spline_), Wide(wx_), UniformAsWide[]>(knots, knot_arraylen), knot_count); @@ -810,13 +826,14 @@ __OSL_MASKED_OP3(spline, Wdv, Wf, //======================================================================= OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, Wdf, Wdv)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wdv, Wdf, Wdv)(void* wout_, ustringhash_pod spline_, void* wx_, Vec3* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide>(wx_), + ustringhash_from(spline_), + Wide>(wx_), Wide[]>(knots, knot_arraylen), knot_count); } @@ -824,27 +841,28 @@ __OSL_MASKED_OP3(spline, Wdv, Wdf, Wdv)(void* wout_, const char* spline_, OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, Wdf, - dv)(void* wout_, const char* spline_, void* wx_, Vec3* knots, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(spline, Wdv, Wdf, dv)(void* wout_, ustringhash_pod spline_, + void* wx_, Vec3* knots, int knot_count, + int knot_arraylen, + unsigned int mask_value) { - spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide>(wx_), - UniformAsWide[]>(knots, - knot_arraylen), - knot_count); + spline_evaluate_wide( + Masked>(wout_, Mask(mask_value)), ustringhash_from(spline_), + Wide>(wx_), + UniformAsWide[]>(knots, knot_arraylen), knot_count); } OSL_BATCHOP void -__OSL_MASKED_OP3(spline, Wdv, df, Wdv)(void* wout_, const char* spline_, +__OSL_MASKED_OP3(spline, Wdv, df, Wdv)(void* wout_, ustringhash_pod spline_, void* wx_, Vec3* knots, int knot_count, int knot_arraylen, unsigned int mask_value) { spline_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), UniformAsWide>(wx_), + ustringhash_from(spline_), + UniformAsWide>(wx_), Wide[]>(knots, knot_arraylen), knot_count); } @@ -861,12 +879,14 @@ __OSL_MASKED_OP3(spline, Wdv, df, Wdv)(void* wout_, const char* spline_, OSL_BATCHOP void __OSL_MASKED_OP3(splineinverse, Wf, Wf, - Wf)(void* wout_, const char* spline_, void* wx_, void* wknots_, - int knot_count, int knot_arraylen, unsigned int mask_value) + Wf)(void* wout_, ustringhash_pod spline_, void* wx_, + void* wknots_, int knot_count, int knot_arraylen, + unsigned int mask_value) { // Version with no derivs splineinverse_evaluate_wide(Masked(wout_, Mask(mask_value)), - USTR(spline_), Wide(wx_), + ustringhash_from(spline_), + Wide(wx_), Wide(wknots_, knot_arraylen), knot_count); } @@ -874,28 +894,30 @@ __OSL_MASKED_OP3(splineinverse, Wf, Wf, OSL_BATCHOP void -__OSL_MASKED_OP3(splineinverse, Wf, Wf, - f)(void* wout_, const char* spline_, void* wx_, void* wknots_, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(splineinverse, Wf, Wf, f)(void* wout_, ustringhash_pod spline_, + void* wx_, void* wknots_, + int knot_count, int knot_arraylen, + unsigned int mask_value) { // Version with no derivs - splineinverse_evaluate_wide(Masked(wout_, Mask(mask_value)), - USTR(spline_), Wide(wx_), - UniformAsWide(wknots_, - knot_arraylen), - knot_count); + splineinverse_evaluate_wide( + Masked(wout_, Mask(mask_value)), ustringhash_from(spline_), + Wide(wx_), + UniformAsWide(wknots_, knot_arraylen), knot_count); } OSL_BATCHOP void -__OSL_MASKED_OP3(splineinverse, Wf, f, - Wf)(void* wout_, const char* spline_, void* wx_, void* wknots_, - int knot_count, int knot_arraylen, unsigned int mask_value) +__OSL_MASKED_OP3(splineinverse, Wf, f, Wf)(void* wout_, ustringhash_pod spline_, + void* wx_, void* wknots_, + int knot_count, int knot_arraylen, + unsigned int mask_value) { // Version with no derivs splineinverse_evaluate_wide(Masked(wout_, Mask(mask_value)), - USTR(spline_), UniformAsWide(wx_), + ustringhash_from(spline_), + UniformAsWide(wx_), Wide(wknots_, knot_arraylen), knot_count); } @@ -904,22 +926,22 @@ __OSL_MASKED_OP3(splineinverse, Wf, f, OSL_BATCHOP void __OSL_MASKED_OP3(splineinverse, Wdf, Wdf, - f)(void* wout_, const char* spline_, void* wx_, void* wknots_, - int knot_count, int knot_arraylen, unsigned int mask_value) + f)(void* wout_, ustringhash_pod spline_, void* wx_, + void* wknots_, int knot_count, int knot_arraylen, + unsigned int mask_value) { // x has derivs, so return derivs as well - splineinverse_evaluate_wide(Masked>(wout_, Mask(mask_value)), - USTR(spline_), Wide>(wx_), - UniformAsWide(wknots_, - knot_arraylen), - knot_count); + splineinverse_evaluate_wide( + Masked>(wout_, Mask(mask_value)), + ustringhash_from(spline_), Wide>(wx_), + UniformAsWide(wknots_, knot_arraylen), knot_count); } OSL_BATCHOP void __OSL_MASKED_OP3(splineinverse, Wdf, Wdf, - Wdf)(void* wout_, const char* spline_, void* wx_, + Wdf)(void* wout_, ustringhash_pod spline_, void* wx_, void* wknots_, int knot_count, int knot_arraylen, unsigned int mask_value) { @@ -927,8 +949,8 @@ __OSL_MASKED_OP3(splineinverse, Wdf, Wdf, // // x has derivs, so return derivs as well splineinverse_evaluate_wide( - Masked>(wout_, Mask(mask_value)), USTR(spline_), - Wide>(wx_), + Masked>(wout_, Mask(mask_value)), + ustringhash_from(spline_), Wide>(wx_), // wknots_ is really a Wide[]>, // but we are ignoring knot derivatives, // so just treat it as Wide which is binary compatible. @@ -938,8 +960,9 @@ __OSL_MASKED_OP3(splineinverse, Wdf, Wdf, OSL_BATCHOP void __OSL_MASKED_OP3(splineinverse, Wdf, Wdf, - df)(void* wout_, const char* spline_, void* wx_, void* wknots_, - int knot_count, int knot_arraylen, unsigned int mask_value) + df)(void* wout_, ustringhash_pod spline_, void* wx_, + void* wknots_, int knot_count, int knot_arraylen, + unsigned int mask_value) { // Ignore knot derivatives __OSL_MASKED_OP3(splineinverse, Wdf, Wdf, f) @@ -949,15 +972,15 @@ __OSL_MASKED_OP3(splineinverse, Wdf, Wdf, OSL_BATCHOP void -__OSL_MASKED_OP3(splineinverse, Wdf, df, Wdf)(void* wout_, const char* spline_, - void* wx_, void* wknots_, - int knot_count, int knot_arraylen, - unsigned int mask_value) +__OSL_MASKED_OP3(splineinverse, Wdf, df, + Wdf)(void* wout_, ustringhash_pod spline_, void* wx_, + void* wknots_, int knot_count, int knot_arraylen, + unsigned int mask_value) { // Ignore knot derivatives splineinverse_evaluate_wide( - Masked>(wout_, Mask(mask_value)), USTR(spline_), - UniformAsWide>(wx_), + Masked>(wout_, Mask(mask_value)), + ustringhash_from(spline_), UniformAsWide>(wx_), // wknots_ is really a Wide[]>, // but we are ignoring knot derivatives, // so just treat it as Wide which is binary compatible. @@ -967,10 +990,10 @@ __OSL_MASKED_OP3(splineinverse, Wdf, df, Wdf)(void* wout_, const char* spline_, OSL_BATCHOP void -__OSL_MASKED_OP3(splineinverse, Wdf, f, Wdf)(void* wout_, const char* spline_, - void* wx_, void* wknots_, - int knot_count, int knot_arraylen, - unsigned int mask_value) +__OSL_MASKED_OP3(splineinverse, Wdf, f, + Wdf)(void* wout_, ustringhash_pod spline_, void* wx_, + void* wknots_, int knot_count, int knot_arraylen, + unsigned int mask_value) { // Ignore knot derivs // treated as fff diff --git a/src/liboslexec/wide/wide_opstring.cpp b/src/liboslexec/wide/wide_opstring.cpp index b08474e5e7..2bb7e68cce 100644 --- a/src/liboslexec/wide/wide_opstring.cpp +++ b/src/liboslexec/wide/wide_opstring.cpp @@ -10,6 +10,7 @@ /// ///////////////////////////////////////////////////////////////////////// + #include #include @@ -29,13 +30,13 @@ OSL_USING_DATA_WIDTH(__OSL_WIDTH) #include "define_opname_macros.h" - OSL_BATCHOP void __OSL_MASKED_OP3(concat, Ws, Ws, Ws)(void* wr_, void* ws_, void* wt_, unsigned int mask_value) { - Wide wS(ws_); - Wide wT(wt_); + // TODO: ustringhash_pod doesn't work inside Wide<> + Wide wS(ws_); + Wide wT(wt_); Masked wR(wr_, Mask(mask_value)); char local_buf[256]; @@ -46,8 +47,8 @@ __OSL_MASKED_OP3(concat, Ws, Ws, Ws)(void* wr_, void* ws_, void* wt_, // as they are undefined when masked off wR.mask().foreach ( [=, &local_buf, &heap_buf, &heap_buf_len](ActiveLane lane) -> void { - ustring s = wS[lane]; - ustring t = wT[lane]; + ustring s = ustring_from(wS[lane]); + ustring t = ustring_from(wT[lane]); size_t sl = s.length(); size_t tl = t.length(); size_t len = sl + tl; @@ -70,7 +71,7 @@ __OSL_MASKED_OP3(concat, Ws, Ws, Ws)(void* wr_, void* ws_, void* wt_, OSL_BATCHOP void __OSL_MASKED_OP2(strlen, Wi, Ws)(void* wr_, void* ws_, unsigned int mask_value) { - Wide wS(ws_); + Wide wS(ws_); Masked wR(wr_, Mask(mask_value)); OSL_FORCEINLINE_BLOCK @@ -81,7 +82,7 @@ __OSL_MASKED_OP2(strlen, Wi, Ws)(void* wr_, void* ws_, unsigned int mask_value) OSL_OMP_PRAGMA(omp simd simdlen(__OSL_WIDTH)) #endif for (int lane = 0; lane < __OSL_WIDTH; ++lane) { - ustring s = wS[lane]; + ustring s = ustring_from(wS[lane]); if (wR.mask()[lane]) { wR[ActiveLane(lane)] = (int)s.length(); } @@ -93,14 +94,14 @@ __OSL_MASKED_OP2(strlen, Wi, Ws)(void* wr_, void* ws_, unsigned int mask_value) OSL_BATCHOP void __OSL_MASKED_OP2(hash, Wi, Ws)(void* wr_, void* ws_, unsigned int mask_value) { - Wide wS(ws_); + Wide wS(ws_); Masked wR(wr_, Mask(mask_value)); OSL_FORCEINLINE_BLOCK { OSL_OMP_PRAGMA(omp simd simdlen(__OSL_WIDTH)) for (int lane = 0; lane < __OSL_WIDTH; ++lane) { - ustring s = wS[lane]; + ustring s = ustring_from(wS[lane]); if (wR.mask()[lane]) { wR[ActiveLane(lane)] = (int)s.hash(); } @@ -114,13 +115,13 @@ OSL_BATCHOP void __OSL_MASKED_OP3(getchar, Wi, Ws, Wi)(void* wr_, void* ws_, void* wi_, unsigned int mask_value) { - Wide wS(ws_); + Wide wS(ws_); Wide wI(wi_); Masked wR(wr_, Mask(mask_value)); #if 1 // SIMD version may not be profitable, need to benchmark to confirm wR.mask().foreach ([=](ActiveLane lane) -> void { - ustring str = wS[lane]; + ustring str = ustring_from(wS[lane]); int index = wI[lane]; wR[lane] = ((!str.empty()) && unsigned(index) < str.length()) ? str[index] @@ -168,13 +169,13 @@ OSL_BATCHOP void __OSL_MASKED_OP3(startswith, Wi, Ws, Ws)(void* wr_, void* ws_, void* wsubs_, unsigned int mask_value) { - Wide wS(ws_); + Wide wS(ws_); Wide wSubs(wsubs_); Masked wR(wr_, Mask(mask_value)); wR.mask().foreach ([=](ActiveLane lane) -> void { - ustring substr = wSubs[lane]; - ustring s = wS[lane]; + ustring substr = ustring_from(wSubs[lane]); + ustring s = ustring_from(wS[lane]); wR[lane] = startswith_iss_impl(s, substr); }); } @@ -200,13 +201,13 @@ OSL_BATCHOP void __OSL_MASKED_OP3(endswith, Wi, Ws, Ws)(void* wr_, void* ws_, void* wsubs_, unsigned int mask_value) { - Wide wS(ws_); - Wide wSubs(wsubs_); + Wide wS(ws_); + Wide wSubs(wsubs_); Masked wR(wr_, Mask(mask_value)); wR.mask().foreach ([=](ActiveLane lane) -> void { - ustring substr = wSubs[lane]; - ustring s = wS[lane]; + ustring substr = ustring_from(wSubs[lane]); + ustring s = ustring_from(wS[lane]); wR[lane] = endswith_iss_impl(s, substr); }); } @@ -217,14 +218,14 @@ OSL_BATCHOP void __OSL_MASKED_OP2(stoi, Wi, Ws)(void* wint_ptr, void* wstr_ptr, unsigned int mask_value) { - Wide wstr(wstr_ptr); + Wide wstr(wstr_ptr); Masked wR(wint_ptr, Mask(mask_value)); // Avoid cost of strtol if lane is masked off // Also the value of str for a masked off lane could be // invalid/undefined and not safe to call strtol on. wR.mask().foreach ([=](ActiveLane lane) -> void { - const char* str = unproxy(wstr[lane]).c_str(); + const char* str = ustring_from(unproxy(wstr[lane])).c_str(); // TODO: Suspect we could implement SIMD friendly version // that is more efficient than the library call wR[lane] = str ? OIIO::Strutil::from_string(str) : 0; @@ -236,14 +237,14 @@ __OSL_MASKED_OP2(stoi, Wi, Ws)(void* wint_ptr, void* wstr_ptr, OSL_BATCHOP void __OSL_MASKED_OP2(stof, Wf, Ws)(void* wr_, void* ws_, unsigned int mask_value) { - Wide wS(ws_); + Wide wS(ws_); Masked wR(wr_, Mask(mask_value)); // Avoid cost of strtof if lane is masked off // Also the value of str for a masked off lane could be // invalid/undefined and not safe to call strtod on. wR.mask().foreach ([=](ActiveLane lane) -> void { - const char* str = unproxy(wS[lane]).c_str(); + const char* str = ustring_from(unproxy(wS[lane])).c_str(); // TODO: Suspect we could implement SIMD friendly version // that is more efficient than the library call wR[lane] = str ? OIIO::Strutil::from_string(str) : 0.0f; @@ -274,13 +275,13 @@ __OSL_MASKED_OP4(substr, Ws, Ws, Wi, Wi)(void* wr_, void* ws_, void* wstart_, void* wlength_, unsigned int mask_value) { - Wide wS(ws_); + Wide wS(ws_); Wide wL(wlength_); Wide wSt(wstart_); Masked wR(wr_, Mask(mask_value)); wR.mask().foreach ([=](ActiveLane lane) -> void { - ustring s = wS[lane]; + ustring s = ustring_from(wS[lane]); int start = wSt[lane]; int length = wL[lane]; wR[lane] = substr_ssii_impl(s, start, length); @@ -290,19 +291,20 @@ __OSL_MASKED_OP4(substr, Ws, Ws, Wi, Wi)(void* wr_, void* ws_, void* wstart_, OSL_BATCHOP int -__OSL_OP(regex_impl)(void* bsg_, const char* subject_, void* results, - int nresults, const char* pattern, int fullmatch) +__OSL_OP(regex_impl)(void* bsg_, ustringhash_pod subject_, void* results, + int nresults, ustringhash_pod pattern, int fullmatch) { auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; // TODO: probably could share implementation from here with osl_regex_impl from opstring.cpp - OSL_ASSERT(ustring::is_unique(subject_)); - OSL_ASSERT(ustring::is_unique(pattern)); + OSL_ASSERT(ustring::is_unique(ustring_from(subject_).c_str())); + OSL_ASSERT(ustring::is_unique(ustring_from(pattern).c_str())); - const std::string& subject(ustring::from_unique(subject_).string()); + const std::string& subject( + ustring::from_unique(ustring_from(subject_).c_str()).string()); std::match_results mresults; - const std::regex& regex(ctx->find_regex(USTR(pattern))); + const std::regex& regex(ctx->find_regex(ustring_from(pattern))); if (nresults > 0) { std::string::const_iterator start = subject.begin(); int res = fullmatch ? std::regex_match(subject, mresults, regex) @@ -315,7 +317,7 @@ __OSL_OP(regex_impl)(void* bsg_, const char* subject_, void* results, else m[r] = mresults[r / 2].second - start; } else { - m[r] = USTR(pattern).length(); + m[r] = ustring_from(pattern).length(); } } return res; @@ -341,12 +343,12 @@ __OSL_MASKED_OP(regex_impl)(void* bsg_, void* wsuccess_ptr, void* wsubject_ptr, Masked wsuccess(wsuccess_ptr, mask); Masked wresults(wresults_ptr, nresults, mask); - Wide wsubject(wsubject_ptr); - Wide wpattern(wpattern_ptr); + Wide wsubject(wsubject_ptr); + Wide wpattern(wpattern_ptr); mask.foreach ([=](ActiveLane lane) -> void { - ustring usubject = wsubject[lane]; - ustring pattern = wpattern[lane]; + ustring usubject = ustring_from(wsubject[lane]); + ustring pattern = ustring_from(wpattern[lane]); OSL_ASSERT(ustring::is_unique(usubject.c_str())); OSL_ASSERT(ustring::is_unique(pattern.c_str())); @@ -381,11 +383,11 @@ __OSL_MASKED_OP(regex_impl)(void* bsg_, void* wsuccess_ptr, void* wsubject_ptr, OSL_BATCHOP void __OSL_OP(format)(void* wide_output, unsigned int mask_value, - const char* format_str, ...) + ustringhash_pod format_str, ...) { va_list args; va_start(args, format_str); - std::string s = Strutil::vsprintf(format_str, args); + std::string s = Strutil::vsprintf(ustring_from(format_str).c_str(), args); va_end(args); ustring result = ustring(s); @@ -395,11 +397,11 @@ __OSL_OP(format)(void* wide_output, unsigned int mask_value, } OSL_BATCHOP const char* -__OSL_OP(format_uniform)(const char* format_str, ...) +__OSL_OP(format_uniform)(ustringhash_pod format_str, ...) { va_list args; va_start(args, format_str); - std::string s = Strutil::vsprintf(format_str, args); + std::string s = Strutil::vsprintf(ustring_from(format_str).c_str(), args); va_end(args); return ustring(s).c_str(); } @@ -407,7 +409,7 @@ __OSL_OP(format_uniform)(const char* format_str, ...) OSL_BATCHOP void __OSL_OP(printf)(BatchedShaderGlobals* bsg, unsigned int mask_value, - const char* format_str, ...) + ustringhash_pod format_str, ...) { Mask mask(mask_value); // Not strictly necessary, but using to ensure "current" logic that conditionals should skip @@ -416,7 +418,7 @@ __OSL_OP(printf)(BatchedShaderGlobals* bsg, unsigned int mask_value, va_list args; va_start(args, format_str); - std::string s = Strutil::vsprintf(format_str, args); + std::string s = Strutil::vsprintf(ustring_from(format_str).c_str(), args); va_end(args); bsg->uniform.context->record_error( @@ -428,7 +430,7 @@ __OSL_OP(printf)(BatchedShaderGlobals* bsg, unsigned int mask_value, OSL_BATCHOP void __OSL_OP(error)(BatchedShaderGlobals* bsg, unsigned int mask_value, - const char* format_str, ...) + ustringhash_pod format_str, ...) { Mask mask(mask_value); // Not strictly necessary, but using to ensure "current" logic that conditionals should skip @@ -437,7 +439,7 @@ __OSL_OP(error)(BatchedShaderGlobals* bsg, unsigned int mask_value, va_list args; va_start(args, format_str); - std::string s = Strutil::vsprintf(format_str, args); + std::string s = Strutil::vsprintf(ustring_from(format_str).c_str(), args); va_end(args); bsg->uniform.context->record_error( @@ -449,7 +451,7 @@ __OSL_OP(error)(BatchedShaderGlobals* bsg, unsigned int mask_value, OSL_BATCHOP void __OSL_OP(warning)(BatchedShaderGlobals* bsg, unsigned int mask_value, - const char* format_str, ...) + ustringhash_pod format_str, ...) { if (bsg->uniform.context->allow_warnings()) { Mask mask(mask_value); @@ -459,7 +461,8 @@ __OSL_OP(warning)(BatchedShaderGlobals* bsg, unsigned int mask_value, va_list args; va_start(args, format_str); - std::string s = Strutil::vsprintf(format_str, args); + std::string s = Strutil::vsprintf(ustring_from(format_str).c_str(), + args); va_end(args); bsg->uniform.context->record_error( @@ -472,11 +475,10 @@ __OSL_OP(warning)(BatchedShaderGlobals* bsg, unsigned int mask_value, OSL_BATCHOP void __OSL_OP(fprintf)(BatchedShaderGlobals* bsg, unsigned int mask_value, - const char* filename, const char* format_str, ...) + ustringhash_pod filename, ustringhash_pod format_str, ...) { OSL_ASSERT(bsg != nullptr); - OSL_ASSERT(filename != nullptr); - OSL_ASSERT(format_str != nullptr); + //OSL_ASSERT(format_str != nullptr); Mask mask(mask_value); // Not strictly necessary, but using to ensure "current" logic that conditionals should skip // any code block with no active lanes, this could be changed in future @@ -484,11 +486,11 @@ __OSL_OP(fprintf)(BatchedShaderGlobals* bsg, unsigned int mask_value, va_list args; va_start(args, format_str); - std::string s = Strutil::vsprintf(format_str, args); + std::string s = Strutil::vsprintf(ustring_from(format_str).c_str(), args); va_end(args); bsg->uniform.context->record_to_file( - USTR(filename), s, + ustring_from(filename), s, static_cast>(mask)); } @@ -502,19 +504,19 @@ __OSL_MASKED_OP(split)(void* wresults, void* wmaxsplit, /*void *wrlen,*/ int resultslen, unsigned int mask_value) { - Wide wS(wstr); + Wide wS(wstr); Masked wR(wresults, Mask(mask_value)); //length of split array Masked wRString(wresult_string, resultslen, Mask(mask_value)); //Split string - Wide wSep(wsep); + Wide wSep(wsep); Wide wMaxSplit(wmaxsplit); wR.mask().foreach ([=](ActiveLane lane) -> void { int maxsplit = wMaxSplit[lane]; - ustring str = wS[lane]; - ustring sep = wSep[lane]; + ustring str = ustring_from(wS[lane]); + ustring sep = ustring_from(wSep[lane]); auto resultStrings = wRString[lane]; maxsplit = OIIO::clamp(maxsplit, 0, resultslen); diff --git a/src/liboslexec/wide/wide_optexture.cpp b/src/liboslexec/wide/wide_optexture.cpp index 63353be226..7b721c70b0 100644 --- a/src/liboslexec/wide/wide_optexture.cpp +++ b/src/liboslexec/wide/wide_optexture.cpp @@ -33,7 +33,7 @@ namespace { Mask -default_texture(BatchedRendererServices* bsr, ustring filename, +default_texture(BatchedRendererServices* bsr, ustringhash_pod filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, BatchedShaderGlobals* bsg, @@ -49,7 +49,7 @@ default_texture(BatchedRendererServices* bsr, ustring filename, texture_thread_info = context->texture_thread_info(); if (!texture_handle) texture_handle - = bsr->texturesys()->get_texture_handle(filename, + = bsr->texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); Mask mask = outputs.mask(); @@ -194,7 +194,7 @@ default_texture(BatchedRendererServices* bsr, ustring filename, OSL_FORCEINLINE Mask -dispatch_texture(BatchedRendererServices* bsr, ustring filename, +dispatch_texture(BatchedRendererServices* bsr, ustringhash_pod filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, @@ -204,9 +204,9 @@ dispatch_texture(BatchedRendererServices* bsr, ustring filename, Wide dtdy, BatchedTextureOutputs& outputs) { if (bsr->is_overridden_texture()) { - return bsr->texture(filename, texture_handle, texture_thread_info, - options, bsg, s, t, dsdx, dtdx, dsdy, dtdy, - outputs); + return bsr->texture(ustringhash_from(filename), texture_handle, + texture_thread_info, options, bsg, s, t, dsdx, dtdx, + dsdy, dtdy, outputs); } else { return default_texture(bsr, filename, texture_handle, texture_thread_info, options, bsg, s, t, dsdx, @@ -217,7 +217,7 @@ dispatch_texture(BatchedRendererServices* bsr, ustring filename, Mask -default_texture3d(BatchedRendererServices* bsr, ustring filename, +default_texture3d(BatchedRendererServices* bsr, ustringhash_pod filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, @@ -232,7 +232,7 @@ default_texture3d(BatchedRendererServices* bsr, ustring filename, texture_thread_info = context->texture_thread_info(); if (!texture_handle) texture_handle - = bsr->texturesys()->get_texture_handle(filename, + = bsr->texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); Mask mask = outputs.mask(); @@ -391,7 +391,7 @@ default_texture3d(BatchedRendererServices* bsr, ustring filename, OSL_FORCEINLINE Mask -dispatch_texture3d(BatchedRendererServices* bsr, ustring filename, +dispatch_texture3d(BatchedRendererServices* bsr, ustringhash_pod filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, @@ -400,8 +400,9 @@ dispatch_texture3d(BatchedRendererServices* bsr, ustring filename, Wide dPdz, BatchedTextureOutputs& outputs) { if (bsr->is_overridden_texture3d()) { - return bsr->texture3d(filename, texture_handle, texture_thread_info, - options, bsg, P, dPdx, dPdy, dPdz, outputs); + return bsr->texture3d(ustringhash_from(filename), texture_handle, + texture_thread_info, options, bsg, P, dPdx, dPdy, + dPdz, outputs); } else { return default_texture3d(bsr, filename, texture_handle, texture_thread_info, options, bsg, P, dPdx, @@ -412,7 +413,7 @@ dispatch_texture3d(BatchedRendererServices* bsr, ustring filename, Mask -default_environment(BatchedRendererServices* bsr, ustring filename, +default_environment(BatchedRendererServices* bsr, ustringhash_pod filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, @@ -427,7 +428,7 @@ default_environment(BatchedRendererServices* bsr, ustring filename, texture_thread_info = context->texture_thread_info(); if (!texture_handle) texture_handle - = bsr->texturesys()->get_texture_handle(filename, + = bsr->texturesys()->get_texture_handle(ustring_from(filename), texture_thread_info); Mask mask = outputs.mask(); @@ -539,7 +540,7 @@ default_environment(BatchedRendererServices* bsr, ustring filename, OSL_FORCEINLINE Mask -dispatch_environment(BatchedRendererServices* bsr, ustring filename, +dispatch_environment(BatchedRendererServices* bsr, ustringhash_pod filename, TextureSystem::TextureHandle* texture_handle, TextureSystem::Perthread* texture_thread_info, const BatchedTextureOptions& options, @@ -548,8 +549,9 @@ dispatch_environment(BatchedRendererServices* bsr, ustring filename, BatchedTextureOutputs& outputs) { if (bsr->is_overridden_texture3d()) { - return bsr->environment(filename, texture_handle, texture_thread_info, - options, bsg, R, dRdx, dRdy, outputs); + return bsr->environment(ustringhash_from(filename), texture_handle, + texture_thread_info, options, bsg, R, dRdx, + dRdy, outputs); } else { return default_environment(bsr, filename, texture_handle, texture_thread_info, options, bsg, R, dRdx, @@ -563,7 +565,7 @@ dispatch_environment(BatchedRendererServices* bsr, ustring filename, OSL_BATCHOP int -__OSL_MASKED_OP(texture)(void* bsg_, ustring_pod name_, void* handle, +__OSL_MASKED_OP(texture)(void* bsg_, ustringhash_pod name_, void* handle, const void* opt_, const void* s, const void* t, const void* dsdx, const void* dtdx, const void* dsdy, const void* dtdy, int chans, void* result, @@ -582,8 +584,8 @@ __OSL_MASKED_OP(texture)(void* bsg_, ustring_pod name_, void* handle, (bool)alphaHasDerivs, errormessage, mask); Mask retVal - = dispatch_texture(bsg->uniform.renderer->batched(WidthTag()), - USTR(name_), (TextureSystem::TextureHandle*)handle, + = dispatch_texture(bsg->uniform.renderer->batched(WidthTag()), name_, + (TextureSystem::TextureHandle*)handle, bsg->uniform.context->texture_thread_info(), opt, bsg, Wide(s), Wide(t), Wide(dsdx), Wide(dtdx), @@ -607,7 +609,7 @@ __OSL_MASKED_OP(texture)(void* bsg_, ustring_pod name_, void* handle, OSL_BATCHOP int -__OSL_MASKED_OP(texture3d)(void* bsg_, ustring_pod name_, void* handle, +__OSL_MASKED_OP(texture3d)(void* bsg_, ustringhash_pod name_, void* handle, const void* opt_, const void* wP, const void* wPdx, const void* wPdy, const void* wPdz, int chans, void* result, int resultHasDerivs, void* alpha, @@ -630,8 +632,8 @@ __OSL_MASKED_OP(texture3d)(void* bsg_, ustring_pod name_, void* handle, // NOTE: If overridden, BatchedRendererServiced::texture is responsible // for correcting our str texture space gradients into xyz-space gradients Mask retVal - = dispatch_texture3d(bsg->uniform.renderer->batched(WidthTag()), - USTR(name_), (TextureSystem::TextureHandle*)handle, + = dispatch_texture3d(bsg->uniform.renderer->batched(WidthTag()), name_, + (TextureSystem::TextureHandle*)handle, bsg->uniform.context->texture_thread_info(), opt, bsg, Wide(wP), Wide(wPdx), Wide(wPdy), Wide(wPdz), @@ -653,7 +655,7 @@ __OSL_MASKED_OP(texture3d)(void* bsg_, ustring_pod name_, void* handle, OSL_BATCHOP int -__OSL_MASKED_OP(environment)(void* bsg_, ustring_pod name_, void* handle, +__OSL_MASKED_OP(environment)(void* bsg_, ustringhash_pod name_, void* handle, const void* opt_, const void* wR, const void* wRdx, const void* wRdy, int chans, void* result, int resultHasDerivs, void* alpha, @@ -670,12 +672,13 @@ __OSL_MASKED_OP(environment)(void* bsg_, ustring_pod name_, void* handle, // NOTE: If overridden, BatchedRendererServiced::texture is responsible // for correcting our str texture space gradients into xyz-space gradients - Mask retVal = dispatch_environment( - bsg->uniform.renderer->batched(WidthTag()), USTR(name_), - (TextureSystem::TextureHandle*)handle, - bsg->uniform.context->texture_thread_info(), opt, bsg, - Wide(wR), Wide(wRdx), Wide(wRdy), - outputs); + Mask retVal + = dispatch_environment(bsg->uniform.renderer->batched(WidthTag()), + name_, (TextureSystem::TextureHandle*)handle, + bsg->uniform.context->texture_thread_info(), opt, + bsg, Wide(wR), + Wide(wRdx), Wide(wRdy), + outputs); // For now, just zero out the result derivatives. If somebody needs // derivatives of environment lookups, we'll fix it. The reason @@ -723,7 +726,7 @@ __OSL_MASKED_OP(environment)(void* bsg_, ustring_pod name_, void* handle, OSL_BATCHOP TextureSystem::TextureHandle* -__OSL_OP(resolve_udim_uniform)(void* bsg_, const char* name, void* handle, +__OSL_OP(resolve_udim_uniform)(void* bsg_, ustringhash_pod name, void* handle, float S, float T) { // recreate TypeDesc @@ -731,14 +734,14 @@ __OSL_OP(resolve_udim_uniform)(void* bsg_, const char* name, void* handle, return bsg->uniform.renderer->batched(WidthTag()) ->resolve_udim_uniform(bsg, bsg->uniform.context->texture_thread_info(), - USTR(name), + ustring_from(name), (RendererServices::TextureHandle*)handle, S, T); } OSL_BATCHOP void -__OSL_MASKED_OP(resolve_udim)(void* bsg_, const char* name, void* handle, +__OSL_MASKED_OP(resolve_udim)(void* bsg_, ustringhash_pod name, void* handle, void* wS_, void* wT_, void* wResult_, int mask_value) { @@ -747,7 +750,8 @@ __OSL_MASKED_OP(resolve_udim)(void* bsg_, const char* name, void* handle, bsg->uniform.renderer->batched(WidthTag()) ->resolve_udim(bsg, bsg->uniform.context->texture_thread_info(), - USTR(name), (RendererServices::TextureHandle*)handle, + ustring_from(name), + (RendererServices::TextureHandle*)handle, Wide(wS_), Wide(wT_), Masked( wResult_, Mask(mask_value))); @@ -756,9 +760,9 @@ __OSL_MASKED_OP(resolve_udim)(void* bsg_, const char* name, void* handle, OSL_BATCHOP int -__OSL_OP(get_textureinfo_uniform)(void* bsg_, ustring_pod name_, void* handle, - ustring_pod dataname_, const void* attr_type, - void* attr_dest) +__OSL_OP(get_textureinfo_uniform)(void* bsg_, ustringhash_pod name_, + void* handle, ustringhash_pod dataname_, + const void* attr_type, void* attr_dest) { // recreate TypeDesc auto* bsg = reinterpret_cast(bsg_); @@ -768,8 +772,9 @@ __OSL_OP(get_textureinfo_uniform)(void* bsg_, ustring_pod name_, void* handle, bool retVal = bsg->uniform.renderer->batched(WidthTag()) ->get_texture_info_uniform( bsg, bsg->uniform.context->texture_thread_info(), - USTR(name_), (RendererServices::TextureHandle*)handle, - 0 /*FIXME-ptex*/, USTR(dataname_), dest); + ustringhash_from(name_), + (RendererServices::TextureHandle*)handle, + 0 /*FIXME-ptex*/, ustringhash_from(dataname_), dest); return retVal; } diff --git a/src/liboslexec/wide/wide_shadingsys.cpp b/src/liboslexec/wide/wide_shadingsys.cpp index db52f8c0c3..0d1c3d74bd 100644 --- a/src/liboslexec/wide/wide_shadingsys.cpp +++ b/src/liboslexec/wide/wide_shadingsys.cpp @@ -29,9 +29,9 @@ using WidthTag = OSL::WidthOf<__OSL_WIDTH>; // firstcheck,nchecks are used to check just one element of an array. OSL_BATCHOP void __OSL_OP(naninf_check)(int ncomps, const void* vals_, int has_derivs, - void* bsg_, ustring_pod sourcefile, int sourceline, - ustring_pod symbolname, int firstcheck, int nchecks, - ustring_pod opname) + void* bsg_, ustringhash_pod sourcefile, int sourceline, + ustringhash_pod symbolname, int firstcheck, int nchecks, + ustringhash_pod opname) { auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; @@ -42,8 +42,9 @@ __OSL_OP(naninf_check)(int ncomps, const void* vals_, int has_derivs, if (!OIIO::isfinite(vals[i])) { ctx->errorfmt("Detected {} value in {}{} at {}:{} (op {})", vals[i], d > 0 ? "the derivatives of " : "", - USTR(symbolname), USTR(sourcefile), sourceline, - USTR(opname)); + ustring_from(symbolname), + ustring_from(sourcefile), sourceline, + ustring_from(opname)); return; } } @@ -56,9 +57,9 @@ __OSL_OP(naninf_check)(int ncomps, const void* vals_, int has_derivs, OSL_BATCHOP void __OSL_MASKED_OP1(naninf_check_offset, i)(int mask_value, int ncomps, const void* vals_, - int has_derivs, void* bsg_, ustring_pod sourcefile, - int sourceline, ustring_pod symbolname, int firstcheck, - int nchecks, ustring_pod opname) + int has_derivs, void* bsg_, ustringhash_pod sourcefile, + int sourceline, ustringhash_pod symbolname, int firstcheck, + int nchecks, ustringhash_pod opname) { auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; @@ -72,9 +73,9 @@ __OSL_MASKED_OP1(naninf_check_offset, ctx->errorfmt( "Detected {} value in {}{} at {}:{} (op {}) batch lane:{}", vals[i * __OSL_WIDTH + lane], - d > 0 ? "the derivatives of " : "", USTR(symbolname), - USTR(sourcefile), sourceline, USTR(opname), - lane.value()); + d > 0 ? "the derivatives of " : "", + ustring_from(symbolname), ustring_from(sourcefile), + sourceline, ustring_from(opname), lane.value()); // continue checking all data lanes, and all components // for that matter, we want to find all issues, not just // the 1st, right? @@ -91,10 +92,10 @@ __OSL_MASKED_OP1(naninf_check_offset, OSL_BATCHOP void __OSL_MASKED_OP1(naninf_check_offset, Wi)(int mask_value, int ncomps, const void* vals_, - int has_derivs, void* bsg_, ustring_pod sourcefile, - int sourceline, ustring_pod symbolname, + int has_derivs, void* bsg_, ustringhash_pod sourcefile, + int sourceline, ustringhash_pod symbolname, const void* wide_offsets_ptr, int nchecks, - ustring_pod opname) + ustringhash_pod opname) { auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; @@ -111,9 +112,9 @@ __OSL_MASKED_OP1(naninf_check_offset, ctx->errorfmt( "Detected {} value in {}{} at {}:{} (op {}) batch lane:{}", vals[i * __OSL_WIDTH + lane], - d > 0 ? "the derivatives of " : "", USTR(symbolname), - USTR(sourcefile), sourceline, USTR(opname), - lane.value()); + d > 0 ? "the derivatives of " : "", + ustring_from(symbolname), ustring_from(sourcefile), + sourceline, ustring_from(opname), lane.value()); // continue checking all data lanes, and all components // for that matter, we want to find all issues, not just // the 1st, right? @@ -131,10 +132,11 @@ __OSL_MASKED_OP1(naninf_check_offset, OSL_BATCHOP void __OSL_OP2(uninit_check_values_offset, X, i)(long long typedesc_, void* vals_, void* bsg_, - ustring_pod sourcefile, int sourceline, ustring_pod groupname_, - int layer, ustring_pod layername_, ustring_pod shadername, - int opnum, ustring_pod opname, int argnum, ustring_pod symbolname, - int firstcheck, int nchecks) + ustringhash_pod sourcefile, int sourceline, + ustringhash_pod groupname_, int layer, ustringhash_pod layername_, + ustringhash_pod shadername, int opnum, ustringhash_pod opname, + int argnum, ustringhash_pod symbolname, int firstcheck, + int nchecks) { TypeDesc typedesc = TYPEDESC(typedesc_); auto* bsg = reinterpret_cast(bsg_); @@ -165,8 +167,8 @@ __OSL_OP2(uninit_check_values_offset, X, } } if (uninit) { - ustring groupname = USTR(groupname_); - ustring layername = USTR(layername_); + ustring groupname = ustring_from(groupname_); + ustring layername = ustring_from(layername_); ctx->errorfmt( "Detected possible use of uninitialized value in {} {} at {}:{} (group {}, layer {} {}, shader {}, op {} '{}', arg {})", typedesc, symbolname, sourcefile, sourceline, @@ -183,11 +185,11 @@ __OSL_OP2(uninit_check_values_offset, X, OSL_BATCHOP void __OSL_MASKED_OP2(uninit_check_values_offset, WX, i)(int mask_value, long long typedesc_, void* vals_, - void* bsg_, ustring_pod sourcefile, int sourceline, - ustring_pod groupname_, int layer, ustring_pod layername_, - ustring_pod shadername, int opnum, ustring_pod opname, - int argnum, ustring_pod symbolname, int firstcheck, - int nchecks) + void* bsg_, ustringhash_pod sourcefile, int sourceline, + ustringhash_pod groupname_, int layer, + ustringhash_pod layername_, ustringhash_pod shadername, + int opnum, ustringhash_pod opname, int argnum, + ustringhash_pod symbolname, int firstcheck, int nchecks) { TypeDesc typedesc = TYPEDESC(typedesc_); auto* bsg = reinterpret_cast(bsg_); @@ -229,8 +231,8 @@ __OSL_MASKED_OP2(uninit_check_values_offset, WX, }); } if (lanes_uninit.any_on()) { - ustring groupname = USTR(groupname_); - ustring layername = USTR(layername_); + ustring groupname = ustring_from(groupname_); + ustring layername = ustring_from(layername_); ctx->errorfmt( "Detected possible use of uninitialized value in {} {} at {}:{} (group {}, layer {} {}, shader {}, op {} '{}', arg {}) for lanes({:x}) of batch", typedesc, symbolname, sourcefile, sourceline, @@ -247,11 +249,12 @@ __OSL_MASKED_OP2(uninit_check_values_offset, WX, OSL_BATCHOP void __OSL_MASKED_OP2(uninit_check_values_offset, X, Wi)(int mask_value, long long typedesc_, void* vals_, - void* bsg_, ustring_pod sourcefile, int sourceline, - ustring_pod groupname_, int layer, ustring_pod layername_, - ustring_pod shadername, int opnum, ustring_pod opname, - int argnum, ustring_pod symbolname, - const void* wide_offsets_ptr, int nchecks) + void* bsg_, ustringhash_pod sourcefile, int sourceline, + ustringhash_pod groupname_, int layer, + ustringhash_pod layername_, ustringhash_pod shadername, + int opnum, ustringhash_pod opname, int argnum, + ustringhash_pod symbolname, const void* wide_offsets_ptr, + int nchecks) { TypeDesc typedesc = TYPEDESC(typedesc_); auto* bsg = reinterpret_cast(bsg_); @@ -295,8 +298,8 @@ __OSL_MASKED_OP2(uninit_check_values_offset, X, } if (lanes_uninit.any_on()) { - ustring groupname = USTR(groupname_); - ustring layername = USTR(layername_); + ustring groupname = ustring_from(groupname_); + ustring layername = ustring_from(layername_); ctx->errorfmt( "Detected possible use of uninitialized value in {} {} at {}:{} (group {}, layer {} {}, shader {}, op {} '{}', arg {}) for lanes({:x}) of batch", typedesc, symbolname, sourcefile, sourceline, @@ -313,11 +316,12 @@ __OSL_MASKED_OP2(uninit_check_values_offset, X, OSL_BATCHOP void __OSL_MASKED_OP2(uninit_check_values_offset, WX, Wi)(int mask_value, long long typedesc_, void* vals_, - void* bsg_, ustring_pod sourcefile, int sourceline, - ustring_pod groupname_, int layer, ustring_pod layername_, - ustring_pod shadername, int opnum, ustring_pod opname, - int argnum, ustring_pod symbolname, - const void* wide_offsets_ptr, int nchecks) + void* bsg_, ustringhash_pod sourcefile, int sourceline, + ustringhash_pod groupname_, int layer, + ustringhash_pod layername_, ustringhash_pod shadername, + int opnum, ustringhash_pod opname, int argnum, + ustringhash_pod symbolname, const void* wide_offsets_ptr, + int nchecks) { TypeDesc typedesc = TYPEDESC(typedesc_); auto* bsg = reinterpret_cast(bsg_); @@ -363,8 +367,8 @@ __OSL_MASKED_OP2(uninit_check_values_offset, WX, } if (lanes_uninit.any_on()) { - ustring groupname = USTR(groupname_); - ustring layername = USTR(layername_); + ustring groupname = ustring_from(groupname_); + ustring layername = ustring_from(layername_); ctx->errorfmt( "Detected possible use of uninitialized value in {} {} at {}:{} (group {}, layer {} {}, shader {}, op {} '{}', arg {}) for lanes({:x}) of batch", typedesc, symbolname, sourcefile, sourceline, @@ -377,24 +381,24 @@ __OSL_MASKED_OP2(uninit_check_values_offset, WX, OSL_BATCHOP int -__OSL_OP(range_check)(int indexvalue, int length, ustring_pod symname, - void* bsg_, ustring_pod sourcefile, int sourceline, - ustring_pod groupname_, int layer, ustring_pod layername_, - ustring_pod shadername) +__OSL_OP(range_check)(int indexvalue, int length, ustringhash_pod symname, + void* bsg_, ustringhash_pod sourcefile, int sourceline, + ustringhash_pod groupname_, int layer, + ustringhash_pod layername_, ustringhash_pod shadername) { if (indexvalue < 0 || indexvalue >= length) { - ustring groupname = USTR(groupname_); - ustring layername = USTR(layername_); + ustring groupname = ustring_from(groupname_); + ustring layername = ustring_from(layername_); auto* bsg = reinterpret_cast(bsg_); ShadingContext* ctx = bsg->uniform.context; ctx->errorfmt("Index [{}] out of range {}[0..{}]: {}:{}" " (group {}, layer {} {}, shader {})", - indexvalue, USTR(symname), length - 1, USTR(sourcefile), - sourceline, + indexvalue, ustring_from(symname), length - 1, + ustring_from(sourcefile), sourceline, groupname.empty() ? "" : groupname.c_str(), layer, layername.empty() ? "" : layername.c_str(), - USTR(shadername)); + ustring_from(shadername)); if (indexvalue >= length) indexvalue = length - 1; else @@ -407,13 +411,14 @@ __OSL_OP(range_check)(int indexvalue, int length, ustring_pod symname, OSL_BATCHOP void __OSL_MASKED_OP(range_check)(void* wide_indexvalue, unsigned int mask_value, - int length, ustring_pod symname, void* bsg_, - ustring_pod sourcefile, int sourceline, - ustring_pod groupname_, int layer, - ustring_pod layername_, ustring_pod shadername) + int length, ustringhash_pod symname, void* bsg_, + ustringhash_pod sourcefile, int sourceline, + ustringhash_pod groupname_, int layer, + ustringhash_pod layername_, + ustringhash_pod shadername) { - ustring groupname = USTR(groupname_); - ustring layername = USTR(layername_); + ustring groupname = ustring_from(groupname_); + ustring layername = ustring_from(layername_); auto* bsg = reinterpret_cast(bsg_); Masked wIndexValue(wide_indexvalue, Mask(mask_value)); wIndexValue.mask().foreach ([=](ActiveLane lane) -> void { @@ -422,12 +427,12 @@ __OSL_MASKED_OP(range_check)(void* wide_indexvalue, unsigned int mask_value, ShadingContext* ctx = bsg->uniform.context; ctx->errorfmt( "Index [{}] out of range {}[0..{}]: {}:{} (group {}, layer {} {}, shader {})", - indexvalue, USTR(symname), length - 1, USTR(sourcefile), - sourceline, + indexvalue, ustring_from(symname), length - 1, + ustring_from(sourcefile), sourceline, groupname.empty() ? "" : groupname.c_str(), layer, layername.empty() ? "" : layername.c_str(), - USTR(shadername)); + ustring_from(shadername)); if (indexvalue >= length) indexvalue = length - 1; else @@ -441,17 +446,17 @@ __OSL_MASKED_OP(range_check)(void* wide_indexvalue, unsigned int mask_value, OSL_BATCHOP int -__OSL_OP1(get_attribute, s)(void* bsg_, int dest_derivs, ustring_pod obj_name_, - ustring_pod attr_name_, int array_lookup, int index, - const void* attr_type, void* wide_attr_dest, - int mask_) +__OSL_OP1(get_attribute, + s)(void* bsg_, int dest_derivs, ustringhash_pod obj_name_, + ustringhash_pod attr_name_, int array_lookup, int index, + const void* attr_type, void* wide_attr_dest, int mask_) { Mask mask(mask_); ASSERT(mask.any_on()); auto* bsg = reinterpret_cast(bsg_); - ustring obj_name = USTR(obj_name_); - ustring attr_name = USTR(attr_name_); + ustring obj_name = ustring_from(obj_name_); + ustring attr_name = ustring_from(attr_name_); // Ignoring m_next_failed_attrib cache for now, // might be faster @@ -473,15 +478,15 @@ __OSL_OP1(get_attribute, s)(void* bsg_, int dest_derivs, ustring_pod obj_name_, OSL_BATCHOP int __OSL_MASKED_OP1(get_attribute, - Ws)(void* bsg_, int dest_derivs, ustring_pod obj_name_, - ustring_pod* wattr_name_, int array_lookup, int index, + Ws)(void* bsg_, int dest_derivs, ustringhash_pod obj_name_, + ustringhash_pod* wattr_name_, int array_lookup, int index, const void* attr_type, void* wide_attr_dest, int mask_) { Mask mask(mask_); ASSERT(mask.any_on()); auto* bsg = reinterpret_cast(bsg_); - ustring obj_name = USTR(obj_name_); + ustring obj_name = ustring_from(obj_name_); Wide wAttrName(wattr_name_); auto* renderer = bsg->uniform.context->batched<__OSL_WIDTH>().renderer(); @@ -521,13 +526,14 @@ __OSL_MASKED_OP1(get_attribute, OSL_BATCHOP bool __OSL_OP(get_attribute_uniform)(void* bsg_, int dest_derivs, - ustring_pod obj_name_, ustring_pod attr_name_, - int array_lookup, int index, - const void* attr_type, void* attr_dest) + ustringhash_pod obj_name_, + ustringhash_pod attr_name_, int array_lookup, + int index, const void* attr_type, + void* attr_dest) { auto* bsg = reinterpret_cast(bsg_); - ustring obj_name = USTR(obj_name_); - ustring attr_name = USTR(attr_name_); + ustring obj_name = ustring_from(obj_name_); + ustring attr_name = ustring_from(attr_name_); auto* renderer = bsg->uniform.context->batched<__OSL_WIDTH>().renderer(); @@ -547,10 +553,10 @@ __OSL_OP(get_attribute_uniform)(void* bsg_, int dest_derivs, OSL_BATCHOP int -__OSL_OP(bind_interpolated_param)(void* bsg_, ustring_pod name, long long type, - int userdata_has_derivs, void* userdata_data, - int symbol_has_derivs, void* symbol_data, - int symbol_data_size, +__OSL_OP(bind_interpolated_param)(void* bsg_, ustringhash_pod name, + long long type, int userdata_has_derivs, + void* userdata_data, int symbol_has_derivs, + void* symbol_data, int symbol_data_size, unsigned int* userdata_initialized, int userdata_index, unsigned int mask_value) { @@ -564,7 +570,8 @@ __OSL_OP(bind_interpolated_param)(void* bsg_, ustring_pod name, long long type, MaskedData userDest(TYPEDESC(type), userdata_has_derivs, Mask(mask_value), userdata_data); Mask foundUserData = bsg->uniform.renderer->batched(WidthTag()) - ->get_userdata(USTR(name), bsg, userDest); + ->get_userdata(ustring_from(name), bsg, + userDest); // print("Binding {} {} : index {}, ok = {}\n", name, // TYPEDESC(type).c_str(),userdata_index, foundUserData.value()); @@ -597,10 +604,11 @@ __OSL_OP(raytype_bit)(void* bsg_, int bit) // Asked if the raytype is a name we can't know until mid-shader. OSL_BATCHOP int -__OSL_OP(raytype_name)(void* bsg_, ustring_pod name) +__OSL_OP(raytype_name)(void* bsg_, ustringhash_pod name) { auto* bsg = reinterpret_cast(bsg_); - int bit = bsg->uniform.context->shadingsys().raytype_bit(USTR(name)); + int bit = bsg->uniform.context->shadingsys().raytype_bit( + ustring_from(name)); return (bsg->uniform.raytype & bit) != 0; } diff --git a/src/testminimal/CMakeLists.txt b/src/testminimal/CMakeLists.txt new file mode 100644 index 0000000000..42e6e9d115 --- /dev/null +++ b/src/testminimal/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright Contributors to the Open Shading Language project. +# SPDX-License-Identifier: BSD-3-Clause +# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage + +# The 'testminimal' executable +set ( testminimal_srcs + testminimal.cpp + oslmaterial.cpp ) + +set(include_dirs ${CMAKE_CURRENT_SOURCE_DIR}) +list(APPEND include_dirs ${CMAKE_SOURCE_DIR}/src/include) +list(APPEND include_dirs ${CMAKE_BINARY_DIR}/include) +list(APPEND include_dirs ${IMATH_INCLUDES}) +list(APPEND include_dirs ${OPENEXR_INCLUDES}) +list(APPEND include_dirs ${OpenImageIO_INCLUDES}) + +set ( rs_srcs + oslmaterial.cpp ) + +EMBED_LLVM_BITCODE_IN_CPP ( "${rs_srcs}" "_host" "testminimal_llvm_compiled_rs" testminimal_srcs "-DOSL_HOST_RS_BITCODE=1" "${include_dirs}") + +add_executable ( testminimal ${testminimal_srcs} ) + +target_link_libraries (testminimal + PRIVATE + oslexec oslquery) + +install (TARGETS testminimal RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +osl_optix_target(testminimal) diff --git a/src/testminimal/oslmaterial.cpp b/src/testminimal/oslmaterial.cpp new file mode 100644 index 0000000000..9bc5470f73 --- /dev/null +++ b/src/testminimal/oslmaterial.cpp @@ -0,0 +1,199 @@ +// Copyright Contributors to the Open Shading Language project. +// SPDX-License-Identifier: BSD-3-Clause +// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage + + +#include "oslmaterial.h" +#include + +using std::cout; +using std::endl; + +#if OSL_USE_BATCHED +template +CustomBatchedRendererServices::CustomBatchedRendererServices( + BatchedOSLMaterial& m) + : OSL::BatchedRendererServices(m.texturesys()), m_sr(m) +{ +} +#endif + +OSLMaterial::OSLMaterial() {} + +#if OSL_USE_BATCHED +template +BatchedOSLMaterial::BatchedOSLMaterial() : m_batch(*this) +{ +} + +template BatchedOSLMaterial<8>::BatchedOSLMaterial(); +template BatchedOSLMaterial<16>::BatchedOSLMaterial(); +#endif + +// Supported closures and parameters +struct EmptyParams {}; + +enum ClosureIDs { + EMISSION_ID, + BACKGROUND_ID, + MICROFACET_ID, +}; + +struct MicrofacetParams { + OSL::ustringhash dist; + OSL::Vec3 N, U; + float xalpha, yalpha, eta; + int refract; +}; + +void +register_closures(OSL::ShadingSystem* ss) +{ + // "Describe the memory layout of each closure type to the OSL runtime" + constexpr int MaxParams = 32; + struct BuiltinClosures { + const char* name; + int id; + OSL::ClosureParam params[MaxParams]; // "upper bound" + }; + + using namespace OSL; + + // Closures with support built into OSL, connected by the 1st string + BuiltinClosures supported[] = { + { "emission", EMISSION_ID, { CLOSURE_FINISH_PARAM(EmptyParams) } }, + { "background", BACKGROUND_ID, { CLOSURE_FINISH_PARAM(EmptyParams) } }, + { "microfacet", + MICROFACET_ID, + { CLOSURE_STRING_PARAM(MicrofacetParams, dist), + CLOSURE_VECTOR_PARAM(MicrofacetParams, N), + CLOSURE_VECTOR_PARAM(MicrofacetParams, U), + CLOSURE_FLOAT_PARAM(MicrofacetParams, xalpha), + CLOSURE_FLOAT_PARAM(MicrofacetParams, yalpha), + CLOSURE_FLOAT_PARAM(MicrofacetParams, eta), + CLOSURE_INT_PARAM(MicrofacetParams, refract), + CLOSURE_FINISH_PARAM(MicrofacetParams) } }, + }; + // Closure registration here enables that type of closure, when executing or compiling a shader + for (const BuiltinClosures& c : supported) + ss->register_closure(c.name, c.id, c.params, nullptr, nullptr); +} + +void +process_bsdf_closure(const OSL::ClosureColor* closure) +{ + static const ::OSL::ustringhash uh_ggx(OIIO::Strutil::strhash("ggx")); + //static const ::OSL::ustringhash uh_beckmann(OIIO::Strutil::strhash("beckmann")); + if (!closure) + return; + switch (closure->id) { + case OSL::ClosureColor::MUL: { + process_bsdf_closure(closure->as_mul()->closure); + break; + } + case OSL::ClosureColor::ADD: { + process_bsdf_closure(closure->as_add()->closureA); + process_bsdf_closure(closure->as_add()->closureB); + break; + } + default: { + const OSL::ClosureComponent* comp = closure->as_comp(); + switch (comp->id) { + case EMISSION_ID: cout << "parsing emission closure" << endl; break; + case MICROFACET_ID: { + cout << "parsing microfacet closure" << endl; + const MicrofacetParams* mp = comp->as(); + if (mp->dist.hash() == uh_ggx.hash()) { + cout << "uh_ggx" << endl; + } else { + cout << "uh_beckmann or default" << endl; + } + } break; + default: + OSL_ASSERT(false && "Invalid closure invoked in surface shader"); + break; + } + } break; + } +} + +void +OSLMaterial::run_test(OSL::ShadingSystem* ss, OSL::PerThreadInfo* thread_info, + OSL::ShadingContext* context, char* shader_name) +{ + register_closures(ss); + OSL::ShaderGlobals globals; + globals_from_hit(globals); + + std::vector options; + + // Create a new shader group + m_shaders.emplace_back(); + m_shaders[0] = ss->ShaderGroupBegin(std::to_string(0)); + OSL::ShaderGroupRef group = m_shaders[0]; + + //{ + // OSL::OSLCompiler compiler; + // std::string name = std::string(shader_name) + ".osl"; + // compiler.compile(name.c_str(), options); + //} + + ss->Shader(*group, "surface", shader_name, "Test"); + ss->ShaderGroupEnd(*group); + + ss->execute(context, *group, globals); + const OSL::ClosureColor* closure = globals.Ci; + process_bsdf_closure(closure); +} + +#if OSL_USE_BATCHED +template +void +BatchedOSLMaterial::run_test(OSL::ShadingSystem* ss, + OSL::PerThreadInfo* thread_info, + OSL::ShadingContext* context, + char* shader_name) +{ + register_closures(ss); + OSL::BatchedShaderGlobals batched_globals; + + m_batch.globals_from_hit(batched_globals); + + std::vector options; + + // Create a new shader group + m_shaders.emplace_back(); + m_shaders[0] = ss->ShaderGroupBegin(std::to_string(0)); + OSL::ShaderGroupRef group = m_shaders[0]; + + //{ + // OSL::OSLCompiler compiler; + // std::string name = std::string(shader_name) + ".osl"; + // compiler.compile(name.c_str(), options); + //} + + ss->Shader(*group, "surface", shader_name, "Test"); + ss->ShaderGroupEnd(*group); + + // Run the shader that was just created + OSL::Block wide_shadeindex_block; + char* userdata_base_ptr = NULL; + char* output_base_ptr = NULL; + ss->batched().execute(*context, *group, batch_width, + wide_shadeindex_block, batched_globals, + userdata_base_ptr, output_base_ptr); + const OSL::ClosureColor* closure = batched_globals.varying.Ci[0]; + process_bsdf_closure(closure); +} + +template void +BatchedOSLMaterial<8>::run_test(OSL::ShadingSystem* ss, + OSL::PerThreadInfo* thread_info, + OSL::ShadingContext* context, + char* shader_name); +template void +BatchedOSLMaterial<16>::run_test(OSL::ShadingSystem* ss, + OSL::PerThreadInfo* thread_info, + OSL::ShadingContext* context, + char* shader_name); +#endif diff --git a/src/testminimal/oslmaterial.h b/src/testminimal/oslmaterial.h new file mode 100644 index 0000000000..12e49fca33 --- /dev/null +++ b/src/testminimal/oslmaterial.h @@ -0,0 +1,235 @@ +// Copyright Contributors to the Open Shading Language project. +// SPDX-License-Identifier: BSD-3-Clause +// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage + + +#pragma once +#include +#include +#include +#include +#include +#include +#include + +#if OSL_USE_BATCHED +# include +# include +#endif + +class OSLMaterial; + +#if OSL_USE_BATCHED +template class BatchedOSLMaterial; + +using OSL::Vec3; + +/// Custom BatchedRendererServices +template +class CustomBatchedRendererServices + : public OSL::BatchedRendererServices { +public: + explicit CustomBatchedRendererServices(BatchedOSLMaterial& m); + + //OIIO::ErrorHandler& errhandler() const { return *m_errhandler; } + /// Turn information at hitpoint into ShaderGlobals for OSL + void globals_from_hit(OSL::BatchedShaderGlobals& bsg) + { + // Uniform + auto& usg = bsg.uniform; + // Zero it all + std::memset(&usg, 0, sizeof(OSL::UniformShaderGlobals)); + usg.raytype = 1; // 1 stands for camera ray? + // Varying + auto& vsg = bsg.varying; + + //assign_all(vsg.shader2common, TransformationPtr(&Mshad)); + //assign_all(vsg.object2common, TransformationPtr(&Mobj)); + + for (int i = 0; i < batch_width; i++) + vsg.P[i] = { 0.0f, 0.0f, 0.0f }; + + for (int i = 0; i < batch_width; i++) + vsg.I[i] = { 0.0f, 0.0f, -1.0f }; // incident ray + for (int i = 0; i < batch_width; i++) + vsg.N[i] = { 0.0f, 0.0f, 1.0f }; // shading normal + for (int i = 0; i < batch_width; i++) + vsg.Ng[i] = { 0.0f, 0.0f, 1.0f }; // true geometric normal + + assign_all(vsg.u, + 0.5f); // 2D surface parameter u, and its differentials. + assign_all(vsg.v, + 0.5f); // 2D surface parameter u, and its differentials. + + + //if (false == vary_udxdy) { + assign_all(vsg.dudx, 0.0f); //uscale / xres); + assign_all(vsg.dudy, 0.0f); + //} + //if (false == vary_vdxdy) { + assign_all(vsg.dvdx, 0.0f); + assign_all(vsg.dvdy, 0.0f); //vscale / yres); + //} + + + //if (false == vary_Pdxdy) { + // assign_all(vsg.dPdx, Vec3(vsg.dudx[0], vsg.dudy[0], 0.0f)); + // assign_all(vsg.dPdy, Vec3(vsg.dvdx[0], vsg.dvdy[0], 0.0f)); + //} + + assign_all(vsg.dPdz, + Vec3(0.0f, 0.0f, 0.0f)); // just use 0 for volume tangent + + // Tangents of P with respect to surface u,v + assign_all(vsg.dPdu, Vec3(1.0f, 0.0f, 0.0f)); + assign_all(vsg.dPdv, Vec3(0.0f, 1.0f, 0.0f)); + + assign_all(vsg.I, Vec3(0, 0, 0)); + assign_all(vsg.dIdx, Vec3(0, 0, 0)); + assign_all(vsg.dIdy, Vec3(0, 0, 0)); + + // That also implies that our normal points to (0,0,1) + assign_all(vsg.N, Vec3(0, 0, 1)); + assign_all(vsg.Ng, Vec3(0, 0, 1)); + + assign_all(vsg.time, 0.0f); + assign_all(vsg.dtime, 0.0f); + assign_all(vsg.dPdtime, Vec3(0, 0, 0)); + + assign_all(vsg.Ps, Vec3(0, 0, 0)); + assign_all(vsg.dPsdx, Vec3(0, 0, 0)); + assign_all(vsg.dPsdy, Vec3(0, 0, 0)); + + assign_all(vsg.surfacearea, 1.0f); + assign_all(vsg.flipHandedness, 0); + assign_all(vsg.backfacing, 0); + + assign_all(vsg.Ci, (::OSL::ClosureColor*)NULL); + } + + bool is_overridden_get_inverse_matrix_WmWxWf() const override + { + return false; + }; + bool is_overridden_get_matrix_WmWsWf() const override { return false; }; + bool is_overridden_get_inverse_matrix_WmsWf() const override + { + return false; + }; + bool is_overridden_get_inverse_matrix_WmWsWf() const override + { + return false; + }; + bool is_overridden_texture() const override { return false; }; + bool is_overridden_texture3d() const override { return false; }; + bool is_overridden_environment() const override { return false; }; + bool is_overridden_pointcloud_search() const override { return false; }; + bool is_overridden_pointcloud_get() const override { return false; }; + bool is_overridden_pointcloud_write() const override { return false; }; + + BatchedOSLMaterial& m_sr; + +private: +}; +#endif + +/// Custom RendererServices for non-batched case +class OSLMaterial : public OSL::RendererServices { +public: + OSLMaterial(); + + void run_test(OSL::ShadingSystem* ss, OSL::PerThreadInfo* thread_info, + OSL::ShadingContext* context, char* shader_name); + + OIIO::ErrorHandler& errhandler() const { return *m_errhandler; } + + /// Turn information at hitpoint into ShaderGlobals for OSL + void globals_from_hit(OSL::ShaderGlobals& sg) + { + sg.P = { 0.0f, 0.0f, 0.0f }; // surface pos + sg.dPdx = { 0.0f, 0.0f, 0.0f }; + sg.dPdy = { 0.0f, 0.0f, 0.0f }; + sg.dPdz = { 0.0f, 0.0f, 0.0f }; // for volume shading only + + sg.I = { 0.0f, 0.0f, -1.0f }; // incident ray + sg.dIdx = { 0.0f, 0.0f, 0.0f }; + sg.dIdy = { 0.0f, 0.0f, 0.0f }; + + sg.N = { 0.0f, 0.0f, 1.0f }; // shading normal + sg.Ng = { 0.0f, 0.0f, 1.0f }; // true geometric normal + + sg.u = 0.5f; // 2D surface parameter u, and its differentials. + sg.dudx = 0.0f; + sg.dudy = 0.0f; + sg.v = 0.5f; // 2D surface parameter v, and its differentials. + sg.dvdx = 0.0f; + sg.dvdy = 0.0f; + + // Surface tangents: derivative of P with respect to surface u and v. + sg.dPdu = { 1.0f, 0.0f, 0.0f }; + sg.dPdv = { 0.0f, 1.0f, 0.0f }; + + sg.time = 0.0f; + sg.dtime = 0.001f; + + // Velocity vector: derivative of position P with respect to time. + sg.dPdtime = { 0.0f, 0.0f, 0.0f }; + + // For lights or light attenuation shaders: the point being illuminated (???) + sg.Ps = { 0.0f, 0.0f, 0.0f }; + sg.dPsdx = { 0.0f, 0.0f, 0.0f }; + sg.dPsdy = { 0.0f, 0.0f, 0.0f }; + + // Renderer user pointers + sg.renderstate = NULL; + sg.tracedata = NULL; + sg.objdata = NULL; + + sg.renderer = this; + + sg.raytype = 1; // 1 stands for camera ray? + sg.flipHandedness = 0; + sg.backfacing = 0; + + // output closure, needs to be null initialized + sg.Ci = NULL; + } + + // ShaderGroupRef storage + std::vector& shaders() { return m_shaders; } + std::vector m_shaders; + +private: + std::unique_ptr m_errhandler; +}; + +#if OSL_USE_BATCHED + +/// Custom RendererServices for batched case +template +class BatchedOSLMaterial : public OSL::RendererServices { +public: + BatchedOSLMaterial(); + + void run_test(OSL::ShadingSystem* ss, OSL::PerThreadInfo* thread_info, + OSL::ShadingContext* context, char* shader_name); + + OIIO::ErrorHandler& errhandler() const { return *m_errhandler; } + + // ShaderGroupRef storage + std::vector& shaders() { return m_shaders; } + std::vector m_shaders; + + OSL::BatchedRendererServices* + batched(OSL::WidthOf) override + { + return &m_batch; + } + + CustomBatchedRendererServices m_batch; + +private: + std::unique_ptr m_errhandler; +}; + +#endif diff --git a/src/testminimal/testminimal.cpp b/src/testminimal/testminimal.cpp new file mode 100644 index 0000000000..94c9fcc378 --- /dev/null +++ b/src/testminimal/testminimal.cpp @@ -0,0 +1,143 @@ +// Copyright Contributors to the Open Shading Language project. +// SPDX-License-Identifier: BSD-3-Clause +// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage + + +#include +#include +#include +#include "oslmaterial.h" + +using namespace OSL; + +int +main(int argc, char** argv) +{ + int batch_width; + char* shader_name; + bool use_fma = false; + if (argc < 2) { + std::cout + << "usage: shader_name(without .oso) [+optional] batch_width (0/8/16) [+optional] use_fma 0/1" + << std::endl; + return 0; + } else if (argc >= 3) { + shader_name = argv[1]; + batch_width = atoi(argv[2]); +#if OSL_USE_BATCHED + if (batch_width != -1 && batch_width != 1 && batch_width != 8 + && batch_width != 16) + batch_width = 1; +#else + if (batch_width != 1) + batch_width = 1; +#endif + if (argc >= 4) { + use_fma = atoi(argv[3]); + } + } else { + shader_name = argv[1]; + batch_width = -1; + } + + OSLMaterial* oslmat = NULL; +#if OSL_USE_BATCHED + BatchedOSLMaterial<8>* boslmat8 = NULL; + BatchedOSLMaterial<16>* boslmat16 = NULL; +#endif + + TextureSystem* texturesys = TextureSystem::create(); + ShadingSystem* ss = NULL; + + if (batch_width == -1) { +#if OSL_USE_BATCHED + oslmat = new OSLMaterial(); + ss = new ShadingSystem(oslmat, NULL, &oslmat->errhandler()); + if (use_fma) + ss->attribute("llvm_jit_fma", true); + if (ss->configure_batch_execution_at(16)) + batch_width = 16; + else if (ss->configure_batch_execution_at(8)) + batch_width = 8; + else + batch_width = 1; + delete oslmat; + oslmat = NULL; + delete ss; + ss = NULL; +#else + if (use_fma) + ss->attribute("llvm_jit_fma", true); + batch_width = 1; +#endif + } + + switch (batch_width) { + case 1: + oslmat = new OSLMaterial(); + ss = new ShadingSystem(oslmat, texturesys, &oslmat->errhandler()); + break; +#if OSL_USE_BATCHED + case 8: + boslmat8 = new BatchedOSLMaterial<8>(); + ss = new ShadingSystem(boslmat8, texturesys, &boslmat8->errhandler()); + break; + case 16: + boslmat16 = new BatchedOSLMaterial<16>(); + ss = new ShadingSystem(boslmat16, texturesys, &boslmat16->errhandler()); + break; +#endif + } + +#if OSL_USE_BATCHED + if (batch_width > 1) { + if (use_fma) + ss->attribute("llvm_jit_fma", true); + ss->configure_batch_execution_at(batch_width); + + // build searchpath for ISA specific OSL shared libraries based on expected + // location of library directories relative to the executables path. + static const char* relative_lib_dirs[] = +# if (defined(_WIN32) || defined(_WIN64)) + { "\\..\\lib64", "\\..\\lib" }; +# else + { "/../lib64", "/../lib" }; +# endif + auto executable_directory = OIIO::Filesystem::parent_path( + OIIO::Sysutil::this_program_path()); + int dirNum = 0; + std::string librarypath; + for (const char* relative_lib_dir : relative_lib_dirs) { + if (dirNum++ > 0) + librarypath += ":"; + librarypath += executable_directory + relative_lib_dir; + } + ss->attribute("searchpath:library", librarypath); + } +#endif + + PerThreadInfo* thread_info; + ShadingContext* context; + thread_info = ss->create_thread_info(); + context = ss->get_context(thread_info); + + switch (batch_width) { + case 1: oslmat->run_test(ss, thread_info, context, shader_name); break; +#if OSL_USE_BATCHED + case 8: boslmat8->run_test(ss, thread_info, context, shader_name); break; + case 16: boslmat16->run_test(ss, thread_info, context, shader_name); break; +#endif + } + + ss->release_context(context); + ss->destroy_thread_info(thread_info); + + delete oslmat; +#if OSL_USE_BATCHED + delete boslmat8; + delete boslmat16; +#endif + delete ss; + + return 0; +} diff --git a/testsuite/closure-string/BATCHED b/testsuite/closure-string/BATCHED new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testsuite/closure-string/ref/out.txt b/testsuite/closure-string/ref/out.txt new file mode 100644 index 0000000000..d497c44d99 --- /dev/null +++ b/testsuite/closure-string/ref/out.txt @@ -0,0 +1,3 @@ +Compiled test.osl -> test.oso +parsing microfacet closure +uh_ggx diff --git a/testsuite/closure-string/run.py b/testsuite/closure-string/run.py new file mode 100755 index 0000000000..5e688f5cb9 --- /dev/null +++ b/testsuite/closure-string/run.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +# Copyright Contributors to the Open Shading Language project. +# SPDX-License-Identifier: BSD-3-Clause +# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage + +command = testminimal("test") diff --git a/testsuite/closure-string/test.osl b/testsuite/closure-string/test.osl new file mode 100644 index 0000000000..4071f5d9e4 --- /dev/null +++ b/testsuite/closure-string/test.osl @@ -0,0 +1,4 @@ +shader test(string distribution = "ggx") +{ + Ci = microfacet(distribution, N, N, 0.1, 0.1, 0.0, 0); +} diff --git a/testsuite/runtest.py b/testsuite/runtest.py index befe278a46..eceec81be2 100755 --- a/testsuite/runtest.py +++ b/testsuite/runtest.py @@ -249,6 +249,14 @@ def oiiodiff (fileA, fileB, extraargs="", silent=True, concat=True) : command += " ;\n" return command +# Construct a command that run testminimal with the specified arguments, +# appending output to the file "out.txt". +def testminimal (args) : + if os.environ.__contains__('OSL_TESTMINIMAL_NAME') : + testminimalname = os.environ['OSL_TESTMINIMAL_NAME'] + " " + else : + testminimalname = osl_app("testminimal") + return (testminimalname + args + redirect + " ;\n") # Construct a command that run testshade with the specified arguments, # appending output to the file "out.txt".