Skip to content

Commit

Permalink
Add new testminimal and closure-string test.
Browse files Browse the repository at this point in the history
Signed-off-by: Tuomas Tonteri <[email protected]>
  • Loading branch information
johnfea committed Jun 20, 2024
1 parent 0d122e7 commit 9f8b3d0
Show file tree
Hide file tree
Showing 32 changed files with 1,275 additions and 549 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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 ()
Expand Down Expand Up @@ -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 ()
Expand Down
2 changes: 1 addition & 1 deletion src/cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/include/OSL/llvm_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<llvm::Constant*> constants);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 20 additions & 3 deletions src/liboslexec/batched_backendllvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,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.
Expand Down Expand Up @@ -780,9 +781,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");
Expand All @@ -796,7 +803,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)
Expand Down
10 changes: 7 additions & 3 deletions src/liboslexec/batched_backendllvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/liboslexec/batched_llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#endif

#include "batched_backendllvm.h"

//#include <llvm/Support/raw_ostream.h>


using namespace OSL;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
// Always use real ustring here
llvm::Value* loaded
= rop.llvm_load_value(sym, 0, arrind, c,
TypeDesc::UNKNOWN,
/*op_is_uniform*/ arg_is_uniform,
/*index_is_uniform*/ true);
/*index_is_uniform*/ true,
/*always_real_ustring*/ true);

// Always expand llvm booleans to integers
if (sym.forced_llvm_bool()) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -3300,7 +3304,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
Expand Down
3 changes: 2 additions & 1 deletion src/liboslexec/builtindecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ 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, "sh")
//DECL(osl_gen_ustringhash_pod, "hs")
DECL(osl_gen_ustring, "sh")
DECL(osl_gen_printfmt, "xXhiXiX")
DECL(osl_gen_filefmt, "xXhhiXiX")
Expand Down
70 changes: 35 additions & 35 deletions src/liboslexec/builtindecl_wide_xmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,51 +263,51 @@ 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), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wf, Wf, f), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wf, f, Wf), "xXsXXiii")


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), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, df), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, df), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdf, df, Wdf), "xXsXXiii")

DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, f), "xXXXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, f), "xXsXXiii")

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), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wv, Wf, v), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wv, f, Wv), "xXsXXiii")

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), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, dv), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wdv), "xXsXXiii")

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), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wv), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wv), "xXsXXiii")

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), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, Wdf), "xXsXXiii")

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), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, Wdv), "xXsXXiii")
DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, dv), "xXsXXiii")

//---------------------------------------------------------------
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), "xXsXXiii")
DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, f), "xXsXXiii")
DECL(__OSL_MASKED_OP3(splineinverse, Wf, f, Wf), "xXsXXiii")

//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), "xXsXXiii") //redone
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, df), "xXsXXiii")
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, df, Wdf), "xXsXXiii")
//======
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, f), "xXXXXiii")
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, f), "xXsXXiii")

//dffdf is treated as fff
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, f, Wdf), "xXXXXiii")
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, f, Wdf), "xXsXXiii")
// // unreachable, can't find .osl to produce this combination
//DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wf, Wdf), "xXXXXiii")

Expand Down Expand Up @@ -345,9 +345,9 @@ 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), "iXXssi")
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, s), "iXXXsi")
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, Ws), "iXXsXi")
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, Ws), "iXXXXi")

DECL(__OSL_OP(dict_find_iis), "iXis")
Expand Down Expand Up @@ -620,8 +620,8 @@ DECL(__OSL_OP(regex_impl), "iXsXisi")
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(resolve_udim_uniform), "XXsXff")
DECL(__OSL_MASKED_OP(resolve_udim), "xXsXXXXi")
DECL(__OSL_OP(get_textureinfo_uniform), "iXsXsXX")

// Wide Code generator will set trace options directly in LLVM IR
Expand Down
25 changes: 20 additions & 5 deletions src/liboslexec/llvm_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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*
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/liboslexec/opfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -114,4 +116,4 @@ get_max_warnings_per_thread(OpaqueExecContextPtr oec)
} //namespace pvt


OSL_NAMESPACE_EXIT
OSL_NAMESPACE_EXIT
2 changes: 0 additions & 2 deletions src/liboslexec/oslexec_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,13 @@ 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<ustring>(s);
}


#define MAT(m) (*(Matrix44*)m)
#define VEC(v) (*(Vec3*)v)
#define DFLOAT(x) (*(Dual2<Float>*)x)
Expand Down
Loading

0 comments on commit 9f8b3d0

Please sign in to comment.