Skip to content

Commit 2b413f5

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

17 files changed

+716
-67
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

+7-3
Original file line numberDiff line numberDiff line change
@@ -1058,10 +1058,14 @@ class OSLEXECPUBLIC LLVM_Util {
10581058
IRBuilder& builder();
10591059

10601060
int m_debug;
1061-
bool m_dumpasm = false;
1062-
bool m_jit_fma = false;
1063-
bool m_jit_aggressive = false;
1061+
bool m_dumpasm = false;
1062+
bool m_jit_fma = false;
1063+
bool m_jit_aggressive = false;
1064+
#ifndef OSL_USTRINGREP_IS_HASH
10641065
UstringRep m_ustring_rep = UstringRep::charptr;
1066+
#else
1067+
UstringRep m_ustring_rep = UstringRep::hash;
1068+
#endif
10651069
PerThreadInfo::Impl* m_thread;
10661070
llvm::LLVMContext* m_llvm_context;
10671071
llvm::Module* m_llvm_module;

src/liboslexec/batched_backendllvm.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,17 @@ BatchedBackendLLVM::llvm_load_value(const Symbol& sym, int deriv,
796796
sym.forced_llvm_bool());
797797
}
798798

799+
llvm::Value*
800+
BatchedBackendLLVM::llvm_const_hash(string_view str)
801+
{
802+
return llvm_const_hash(ustring(str));
803+
}
799804

805+
llvm::Value*
806+
BatchedBackendLLVM::llvm_const_hash(ustring str)
807+
{
808+
return ll.constant64((uint64_t)str.hash());
809+
}
800810

801811
llvm::Value*
802812
BatchedBackendLLVM::llvm_load_mask(const Symbol& cond)

src/liboslexec/batched_backendllvm.h

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class BatchedBackendLLVM : public OSOProcessorBase {
102102
bool op_is_uniform = true,
103103
bool index_is_uniform = true);
104104

105+
llvm::Value* llvm_const_hash(string_view str);
106+
107+
llvm::Value* llvm_const_hash(ustring str);
105108

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

src/liboslexec/batched_llvm_gen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3300,7 +3300,7 @@ LLVMGEN(llvm_gen_construct_triple)
33003300
= { rop.sg_void_ptr(), rop.ll.void_ptr(transform),
33013301
space_is_uniform ? rop.llvm_load_value(Space)
33023302
: rop.llvm_void_ptr(Space),
3303-
rop.ll.constant(Strings::common),
3303+
rop.llvm_const_hash(Strings::common),
33043304
rop.ll.mask_as_int(rop.ll.current_mask()) };
33053305

33063306
// Dynamically build function name

src/liboslexec/llvm_util.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,13 @@ 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 = llvm::Type::getInt64Ty(*m_llvm_context);
573+
}
571574
m_llvm_type_wide_ustring_ptr
572575
= llvm::PointerType::get(m_llvm_type_wide_ustring, 0);
573576
}

0 commit comments

Comments
 (0)