Skip to content

Commit 67eb1cb

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

23 files changed

+897
-230
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
}

src/liboslexec/wide/wide_opcolor.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,14 @@ wide_transformc(const ColorSystem cs, ustring fromspace, ustring tospace,
473473
OSL_BATCHOP void
474474
__OSL_MASKED_OP3(transform_color, Wv, s,
475475
s)(void* bsg_, void* Cin, int Cin_derivs, void* Cout,
476-
int Cout_derivs, ustring_pod from_, ustring_pod to_,
476+
int Cout_derivs, ustringhash_pod from_, ustringhash_pod to_,
477477
unsigned int mask_value)
478478
{
479479
const ColorSystem& cs = cs_from_bsg(bsg_);
480480
ShadingContext* ctx = context_from_bsg(bsg_);
481481

482-
const ustring& from = USTR(from_);
483-
const ustring& to = USTR(to_);
482+
ustring from = ustring_from(from_);
483+
ustring to = ustring_from(to_);
484484

485485
if (Cout_derivs) {
486486
if (Cin_derivs) {
@@ -512,13 +512,13 @@ __OSL_MASKED_OP3(transform_color, Wv, s,
512512
OSL_BATCHOP void
513513
__OSL_OP3(transform_color, v, s, s)(void* bsg_, void* Cin, int Cin_derivs,
514514
void* Cout, int Cout_derivs,
515-
ustring_pod from_, ustring_pod to_)
515+
ustringhash_pod from_, ustringhash_pod to_)
516516
{
517517
const ColorSystem& cs = cs_from_bsg(bsg_);
518518
ShadingContext* ctx = context_from_bsg(bsg_);
519519

520-
const ustring& from = USTR(from_);
521-
const ustring& to = USTR(to_);
520+
ustring from = ustring_from(from_);
521+
ustring to = ustring_from(to_);
522522

523523
if (Cout_derivs) {
524524
if (Cin_derivs) {

src/liboslexec/wide/wide_opdictionary.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ OSL_USING_DATA_WIDTH(__OSL_WIDTH)
4848
#include "define_opname_macros.h"
4949

5050
OSL_BATCHOP int
51-
__OSL_OP(dict_find_iis)(void* bsg_, int nodeID, ustring_pod query)
51+
__OSL_OP(dict_find_iis)(void* bsg_, int nodeID, ustringhash_pod query)
5252
{
5353
auto* bsg = reinterpret_cast<BatchedShaderGlobals*>(bsg_);
5454
return bsg->uniform.context->dict_find(
5555
nullptr /*causes errors be reported through ShadingContext*/, nodeID,
56-
USTR(query));
56+
ustring_from(query));
5757
}
5858

5959

@@ -82,12 +82,13 @@ __OSL_MASKED_OP3(dict_find, Wi, Wi, Ws)(void* bsg_, void* wout, void* wnodeID,
8282

8383

8484
OSL_BATCHOP int
85-
__OSL_OP(dict_find_iss)(void* bsg_, ustring_pod dictionary, ustring_pod query)
85+
__OSL_OP(dict_find_iss)(void* bsg_, ustringhash_pod dictionary,
86+
ustringhash_pod query)
8687
{
8788
auto* bsg = reinterpret_cast<BatchedShaderGlobals*>(bsg_);
8889
return bsg->uniform.context->dict_find(
8990
nullptr /*causes errors be reported through ShadingContext*/,
90-
USTR(dictionary), USTR(query));
91+
ustring_from(dictionary), ustring_from(query));
9192
}
9293

9394

@@ -145,11 +146,11 @@ __OSL_MASKED_OP(dict_next)(void* bsg_, void* wout, void* wNodeID,
145146

146147

147148
OSL_BATCHOP int
148-
__OSL_OP(dict_value)(void* bsg_, int nodeID, ustring_pod attribname,
149+
__OSL_OP(dict_value)(void* bsg_, int nodeID, ustringhash_pod attribname,
149150
long long type, void* data)
150151
{
151152
auto* bsg = reinterpret_cast<BatchedShaderGlobals*>(bsg_);
152-
return bsg->uniform.context->dict_value(nodeID, USTR(attribname),
153+
return bsg->uniform.context->dict_value(nodeID, ustring_from(attribname),
153154
TYPEDESC(type), data,
154155
/*treat_ustrings_as_hash*/ false);
155156
}

0 commit comments

Comments
 (0)