Skip to content

Commit 47c66e8

Browse files
committed
Add new testminimal and closure-string test.
Signed-off-by: Tuomas Tonteri <[email protected]>
1 parent 0d122e7 commit 47c66e8

31 files changed

+1273
-548
lines changed

CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ else ()
9595
endif ()
9696
set (OSL_LIBNAME_SUFFIX "" CACHE STRING
9797
"Optional name appended to ${PROJECT_NAME} libraries that are built")
98-
option (OSL_BUILD_TESTS "Build the unit tests, testshade, testrender" ON)
98+
option (OSL_BUILD_TESTS "Build the unit tests, testminimal, testshade, testrender" ON)
9999
if (WIN32)
100100
option (USE_LLVM_BITCODE "Generate embedded LLVM bitcode" OFF)
101101
else ()
@@ -113,10 +113,14 @@ set (OSL_SHADER_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/shade
113113
set (OSL_PTX_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/ptx"
114114
CACHE STRING "Directory where OptiX PTX files will be installed")
115115
set (CMAKE_DEBUG_POSTFIX "" CACHE STRING "Library naming postfix for Debug builds (e.g., '_debug')")
116-
option (OSL_USTRINGREP_IS_HASH "Always use ustringhash for strings" OFF)
116+
option (OSL_USTRINGREP_IS_HASH "Always use ustringhash for strings" ON)
117117

118118

119119
set (OSL_NO_DEFAULT_TEXTURESYSTEM OFF CACHE BOOL "Do not use create a raw OIIO::TextureSystem")
120+
121+
if (OSL_USTRINGREP_IS_HASH)
122+
add_definitions ("-DOSL_USTRINGREP_IS_HASH=1")
123+
endif ()
120124
if (OSL_NO_DEFAULT_TEXTURESYSTEM)
121125
add_definitions ("-DOSL_NO_DEFAULT_TEXTURESYSTEM=1")
122126
endif ()
@@ -220,6 +224,7 @@ add_subdirectory (src/oslc)
220224
add_subdirectory (src/oslinfo)
221225

222226
if (OSL_BUILD_TESTS AND BUILD_TESTING)
227+
add_subdirectory (src/testminimal)
223228
add_subdirectory (src/testshade)
224229
add_subdirectory (src/testrender)
225230
endif ()

src/cmake/testing.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ macro (osl_add_all_tests)
270270
bug-array-heapoffsets bug-locallifetime bug-outputinit
271271
bug-param-duplicate bug-peep bug-return
272272
calculatenormal-reg
273-
cellnoise closure closure-array closure-layered closure-parameters closure-zero closure-conditional
273+
cellnoise closure closure-array closure-layered closure-parameters closure-string closure-zero closure-conditional
274274
color color-reg colorspace comparison
275275
complement-reg compile-buffer compassign-bool compassign-reg
276276
component-range

src/include/OSL/llvm_util.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ class OSLEXECPUBLIC LLVM_Util {
718718
/// Return an llvm::Value holding the given string constant (as
719719
/// determined by the ustring_rep).
720720
llvm::Value* constant(ustring s);
721+
llvm::Value* constant_real_ustring(ustring s);
721722
llvm::Value* constant(string_view s) { return constant(ustring(s)); }
722723

723724
llvm::Constant* constant_array(cspan<llvm::Constant*> constants);
@@ -750,6 +751,7 @@ class OSLEXECPUBLIC LLVM_Util {
750751
llvm::Constant* wide_constant(size_t i);
751752
llvm::Constant* wide_constant_bool(bool b);
752753
llvm::Value* wide_constant(ustring s);
754+
llvm::Value* wide_constant_real_ustring(ustring s);
753755
llvm::Value* wide_constant(string_view s)
754756
{
755757
return wide_constant(ustring(s));
@@ -1058,10 +1060,14 @@ class OSLEXECPUBLIC LLVM_Util {
10581060
IRBuilder& builder();
10591061

10601062
int m_debug;
1061-
bool m_dumpasm = false;
1062-
bool m_jit_fma = false;
1063-
bool m_jit_aggressive = false;
1063+
bool m_dumpasm = false;
1064+
bool m_jit_fma = false;
1065+
bool m_jit_aggressive = false;
1066+
#ifndef OSL_USTRINGREP_IS_HASH
10641067
UstringRep m_ustring_rep = UstringRep::charptr;
1068+
#else
1069+
UstringRep m_ustring_rep = UstringRep::hash;
1070+
#endif
10651071
PerThreadInfo::Impl* m_thread;
10661072
llvm::LLVMContext* m_llvm_context;
10671073
llvm::Module* m_llvm_module;

src/liboslexec/batched_backendllvm.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ llvm::Value*
715715
BatchedBackendLLVM::llvm_load_value(const Symbol& sym, int deriv,
716716
llvm::Value* arrayindex, int component,
717717
TypeDesc cast, bool op_is_uniform,
718-
bool index_is_uniform)
718+
bool index_is_uniform,
719+
bool always_real_ustring)
719720
{
720721
// A uniform symbol can be broadcast into a varying value.
721722
// But a varying symbol can NOT be loaded into a uniform value.
@@ -780,9 +781,15 @@ BatchedBackendLLVM::llvm_load_value(const Symbol& sym, int deriv,
780781
if (sym.typespec().is_string()) {
781782
ustring string_val = sym.get_string();
782783
if (op_is_uniform) {
783-
return ll.constant(string_val);
784+
if (!always_real_ustring)
785+
return ll.constant(string_val);
786+
else
787+
return ll.constant_real_ustring(string_val);
784788
} else {
785-
return ll.wide_constant(string_val);
789+
if (!always_real_ustring)
790+
return ll.wide_constant(string_val);
791+
else
792+
return ll.wide_constant_real_ustring(string_val);
786793
}
787794
}
788795
OSL_ASSERT(0 && "unhandled constant type");
@@ -796,7 +803,17 @@ BatchedBackendLLVM::llvm_load_value(const Symbol& sym, int deriv,
796803
sym.forced_llvm_bool());
797804
}
798805

806+
llvm::Value*
807+
BatchedBackendLLVM::llvm_const_hash(string_view str)
808+
{
809+
return llvm_const_hash(ustring(str));
810+
}
799811

812+
llvm::Value*
813+
BatchedBackendLLVM::llvm_const_hash(ustring str)
814+
{
815+
return ll.constant64((uint64_t)str.hash());
816+
}
800817

801818
llvm::Value*
802819
BatchedBackendLLVM::llvm_load_mask(const Symbol& cond)

src/liboslexec/batched_backendllvm.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ class BatchedBackendLLVM : public OSOProcessorBase {
9898
/// performed if cast is the default of UNKNOWN).
9999
llvm::Value* llvm_load_value(const Symbol& sym, int deriv,
100100
llvm::Value* arrayindex, int component,
101-
TypeDesc cast = TypeDesc::UNKNOWN,
102-
bool op_is_uniform = true,
103-
bool index_is_uniform = true);
101+
TypeDesc cast = TypeDesc::UNKNOWN,
102+
bool op_is_uniform = true,
103+
bool index_is_uniform = true,
104+
bool always_real_ustring = false);
104105

106+
llvm::Value* llvm_const_hash(string_view str);
107+
108+
llvm::Value* llvm_const_hash(ustring str);
105109

106110
/// Given an llvm::Value* of a pointer (and the type of the data
107111
/// that it points to), Return the llvm::Value* corresponding to the

src/liboslexec/batched_llvm_gen.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#endif
1616

1717
#include "batched_backendllvm.h"
18-
18+
//#include <llvm/Support/raw_ostream.h>
1919

2020

2121
using namespace OSL;
@@ -375,6 +375,7 @@ LLVMGEN(llvm_gen_printf)
375375
std::string ourformat(oldfmt, format); // straddle the format
376376
// Doctor it to fix mismatches between format and data
377377
Symbol& sym(*rop.opargsym(op, arg));
378+
378379
OSL_ASSERT(!sym.typespec().is_structure_based());
379380

380381
bool arg_is_uniform = sym.is_uniform();
@@ -416,11 +417,13 @@ LLVMGEN(llvm_gen_printf)
416417
// widened, so our typical op_is_uniform doesn't do what we
417418
// want for this when loading. So just pass arg_is_uniform
418419
// which will avoid widening any uniform arguments.
420+
// Always use real ustring here
419421
llvm::Value* loaded
420422
= rop.llvm_load_value(sym, 0, arrind, c,
421423
TypeDesc::UNKNOWN,
422424
/*op_is_uniform*/ arg_is_uniform,
423-
/*index_is_uniform*/ true);
425+
/*index_is_uniform*/ true,
426+
/*always_real_ustring*/ true);
424427

425428
// Always expand llvm booleans to integers
426429
if (sym.forced_llvm_bool()) {
@@ -482,6 +485,7 @@ LLVMGEN(llvm_gen_printf)
482485
llvm::Value* ret = rop.ll.call_function(rop.build_name(func_spec),
483486
call_args);
484487

488+
485489
// The format op returns a string value, put in in the right spot
486490
if (op.opname() == op_format)
487491
rop.llvm_store_value(ret, *rop.opargsym(op, 0));
@@ -3300,7 +3304,7 @@ LLVMGEN(llvm_gen_construct_triple)
33003304
= { rop.sg_void_ptr(), rop.ll.void_ptr(transform),
33013305
space_is_uniform ? rop.llvm_load_value(Space)
33023306
: rop.llvm_void_ptr(Space),
3303-
rop.ll.constant(Strings::common),
3307+
rop.llvm_const_hash(Strings::common),
33043308
rop.ll.mask_as_int(rop.ll.current_mask()) };
33053309

33063310
// Dynamically build function name

src/liboslexec/builtindecl_wide_xmacro.h

+35-35
Original file line numberDiff line numberDiff line change
@@ -263,51 +263,51 @@ DECL(__OSL_MASKED_OP3(hash, Wi, Wv, Wf), "xXXXi")
263263
// first vs. directly passing the shader global. We don't expect this
264264
// to be encountered, but is possible
265265

266-
DECL(__OSL_MASKED_OP3(spline, Wf, Wf, Wf), "xXXXXiii")
267-
DECL(__OSL_MASKED_OP3(spline, Wf, Wf, f), "xXXXXiii")
268-
DECL(__OSL_MASKED_OP3(spline, Wf, f, Wf), "xXXXXiii")
266+
DECL(__OSL_MASKED_OP3(spline, Wf, Wf, Wf), "xXsXXiii")
267+
DECL(__OSL_MASKED_OP3(spline, Wf, Wf, f), "xXsXXiii")
268+
DECL(__OSL_MASKED_OP3(spline, Wf, f, Wf), "xXsXXiii")
269269

270270

271-
DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, Wdf), "xXXXXiii")
272-
DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, df), "xXXXXiii")
273-
DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, df), "xXXXXiii")
274-
DECL(__OSL_MASKED_OP3(spline, Wdf, df, Wdf), "xXXXXiii")
271+
DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, Wdf), "xXsXXiii")
272+
DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, df), "xXsXXiii")
273+
DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, df), "xXsXXiii")
274+
DECL(__OSL_MASKED_OP3(spline, Wdf, df, Wdf), "xXsXXiii")
275275

276-
DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, f), "xXXXXiii")
276+
DECL(__OSL_MASKED_OP3(spline, Wdf, Wdf, f), "xXsXXiii")
277277

278-
DECL(__OSL_MASKED_OP3(spline, Wv, Wf, Wv), "xXXXXiii")
279-
DECL(__OSL_MASKED_OP3(spline, Wv, Wf, v), "xXXXXiii")
280-
DECL(__OSL_MASKED_OP3(spline, Wv, f, Wv), "xXXXXiii")
278+
DECL(__OSL_MASKED_OP3(spline, Wv, Wf, Wv), "xXsXXiii")
279+
DECL(__OSL_MASKED_OP3(spline, Wv, Wf, v), "xXsXXiii")
280+
DECL(__OSL_MASKED_OP3(spline, Wv, f, Wv), "xXsXXiii")
281281

282-
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wdv), "xXXXXiii")
283-
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, dv), "xXXXXiii")
284-
DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wdv), "xXXXXiii")
282+
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wdv), "xXsXXiii")
283+
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, dv), "xXsXXiii")
284+
DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wdv), "xXsXXiii")
285285

286-
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, v), "xXXXXiii")
287-
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wv), "xXXXXiii")
288-
DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wv), "xXXXXiii")
286+
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, v), "xXsXXiii")
287+
DECL(__OSL_MASKED_OP3(spline, Wdv, Wdf, Wv), "xXsXXiii")
288+
DECL(__OSL_MASKED_OP3(spline, Wdv, df, Wv), "xXsXXiii")
289289

290-
DECL(__OSL_MASKED_OP3(spline, Wdf, f, Wdf), "xXXXXiii")
291-
DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, Wdf), "xXXXXiii")
290+
DECL(__OSL_MASKED_OP3(spline, Wdf, f, Wdf), "xXsXXiii")
291+
DECL(__OSL_MASKED_OP3(spline, Wdf, Wf, Wdf), "xXsXXiii")
292292

293-
DECL(__OSL_MASKED_OP3(spline, Wdv, f, Wdv), "xXXXXiii")
294-
DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, Wdv), "xXXXXiii")
295-
DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, dv), "xXXXXiii")
293+
DECL(__OSL_MASKED_OP3(spline, Wdv, f, Wdv), "xXsXXiii")
294+
DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, Wdv), "xXsXXiii")
295+
DECL(__OSL_MASKED_OP3(spline, Wdv, Wf, dv), "xXsXXiii")
296296

297297
//---------------------------------------------------------------
298-
DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, Wf), "xXXXXiii")
299-
DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, f), "xXXXXiii")
300-
DECL(__OSL_MASKED_OP3(splineinverse, Wf, f, Wf), "xXXXXiii")
298+
DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, Wf), "xXsXXiii")
299+
DECL(__OSL_MASKED_OP3(splineinverse, Wf, Wf, f), "xXsXXiii")
300+
DECL(__OSL_MASKED_OP3(splineinverse, Wf, f, Wf), "xXsXXiii")
301301

302302
//dfdfdf is treated as dfdff
303-
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, Wdf), "xXXXXiii") //redone
304-
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, df), "xXXXXiii")
305-
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, df, Wdf), "xXXXXiii")
303+
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, Wdf), "xXsXXiii") //redone
304+
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, df), "xXsXXiii")
305+
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, df, Wdf), "xXsXXiii")
306306
//======
307-
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, f), "xXXXXiii")
307+
DECL(__OSL_MASKED_OP3(splineinverse, Wdf, Wdf, f), "xXsXXiii")
308308

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

@@ -345,9 +345,9 @@ DECL(__OSL_MASKED_OP2(prepend_matrix_from, Wm, Ws), "xXXXi")
345345
// DECL (osl_transform_triple, "iXXiXiXXi") // unneeded
346346
// DECL (osl_transform_triple_nonlinear, "iXXiXiXXi") // unneeded
347347

348-
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, s), "iXXXXi")
349-
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, s), "iXXXXi")
350-
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, Ws), "iXXXXi")
348+
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, s), "iXXssi")
349+
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, s), "iXXXsi")
350+
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, s, Ws), "iXXsXi")
351351
DECL(__OSL_MASKED_OP3(build_transform_matrix, Wm, Ws, Ws), "iXXXXi")
352352

353353
DECL(__OSL_OP(dict_find_iis), "iXis")
@@ -620,8 +620,8 @@ DECL(__OSL_OP(regex_impl), "iXsXisi")
620620
DECL(__OSL_MASKED_OP(texture), "iXsXXXXXXXXiXiXiXi")
621621
DECL(__OSL_MASKED_OP(texture3d), "iXsXXXXXXiXiXiXi")
622622
DECL(__OSL_MASKED_OP(environment), "iXsXXXXXiXiXiXi")
623-
DECL(__OSL_OP(resolve_udim_uniform), "XXXXff")
624-
DECL(__OSL_MASKED_OP(resolve_udim), "xXXXXXXi")
623+
DECL(__OSL_OP(resolve_udim_uniform), "XXsXff")
624+
DECL(__OSL_MASKED_OP(resolve_udim), "xXsXXXXi")
625625
DECL(__OSL_OP(get_textureinfo_uniform), "iXsXsXX")
626626

627627
// Wide Code generator will set trace options directly in LLVM IR

src/liboslexec/llvm_util.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,15 @@ LLVM_Util::ustring_rep(UstringRep rep)
564564
}
565565
m_llvm_type_ustring_ptr = llvm::PointerType::get(m_llvm_type_ustring, 0);
566566

567-
// Batched versions haven't been updated to handle hash yet.
568-
// For now leave them using the real ustring regardless of UstringRep
569-
m_llvm_type_wide_ustring = llvm_vector_type(m_llvm_type_real_ustring,
570-
m_vector_width);
567+
if (m_ustring_rep == UstringRep::charptr) {
568+
m_llvm_type_wide_ustring = llvm_vector_type(m_llvm_type_real_ustring,
569+
m_vector_width);
570+
} else {
571+
OSL_ASSERT(m_ustring_rep == UstringRep::hash);
572+
m_llvm_type_wide_ustring
573+
= llvm_vector_type(llvm::Type::getInt64Ty(*m_llvm_context),
574+
m_vector_width);
575+
}
571576
m_llvm_type_wide_ustring_ptr
572577
= llvm::PointerType::get(m_llvm_type_wide_ustring, 0);
573578
}
@@ -3533,6 +3538,11 @@ LLVM_Util::constant(ustring s)
35333538
}
35343539
}
35353540

3541+
llvm::Value*
3542+
LLVM_Util::constant_real_ustring(ustring s)
3543+
{
3544+
return constant_ptr((void*)s.c_str(), type_char_ptr());
3545+
}
35363546

35373547

35383548
llvm::Value*
@@ -3541,7 +3551,12 @@ LLVM_Util::wide_constant(ustring s)
35413551
return builder().CreateVectorSplat(m_vector_width, constant(s));
35423552
}
35433553

3544-
3554+
llvm::Value*
3555+
LLVM_Util::wide_constant_real_ustring(ustring s)
3556+
{
3557+
return builder().CreateVectorSplat(m_vector_width,
3558+
constant_real_ustring(s));
3559+
}
35453560

35463561
llvm::Value*
35473562
LLVM_Util::llvm_mask_to_native(llvm::Value* llvm_mask)

src/liboslexec/opfmt.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ namespace pvt {
3131
// Shims to convert llvm gen to rs free function C++ parameter types
3232
// and forward on calls to re free functions.
3333

34+
// TODO this can be removed now that batched supports ustringhash_pod
3435
OSL_RSOP OSL::ustringhash_pod
35-
osl_gen_ustringhash_pod(ustring_pod s)
36+
osl_gen_ustringhash_pod(ustringhash_pod s)
3637
{
37-
return USTR(s).hash();
38+
return s;
39+
//return USTR(s).hash();
3840
}
3941

4042
OSL_RSOP const char*
@@ -114,4 +116,4 @@ get_max_warnings_per_thread(OpaqueExecContextPtr oec)
114116
} //namespace pvt
115117

116118

117-
OSL_NAMESPACE_EXIT
119+
OSL_NAMESPACE_EXIT

src/liboslexec/oslexec_pvt.h

-2
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,13 @@ struct AttributeNeeded {
245245
// "C" linkage (no C++ name mangling).
246246
#define OSL_SHADEOP extern "C" OSL_DLL_LOCAL
247247

248-
249248
// Handy re-casting macros
250249
inline ustring
251250
USTR(ustring_pod s) noexcept
252251
{
253252
return OSL::bitcast<ustring>(s);
254253
}
255254

256-
257255
#define MAT(m) (*(Matrix44*)m)
258256
#define VEC(v) (*(Vec3*)v)
259257
#define DFLOAT(x) (*(Dual2<Float>*)x)

0 commit comments

Comments
 (0)