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 19, 2024
1 parent 0d122e7 commit 67eb1cb
Show file tree
Hide file tree
Showing 23 changed files with 897 additions and 230 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
10 changes: 7 additions & 3 deletions src/include/OSL/llvm_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,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
10 changes: 10 additions & 0 deletions src/liboslexec/batched_backendllvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,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
3 changes: 3 additions & 0 deletions src/liboslexec/batched_backendllvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class BatchedBackendLLVM : public OSOProcessorBase {
bool op_is_uniform = true,
bool index_is_uniform = true);

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
2 changes: 1 addition & 1 deletion src/liboslexec/batched_llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3300,7 +3300,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
11 changes: 7 additions & 4 deletions src/liboslexec/llvm_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,13 @@ 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::Type::getInt64Ty(*m_llvm_context);
}
m_llvm_type_wide_ustring_ptr
= llvm::PointerType::get(m_llvm_type_wide_ustring, 0);
}
Expand Down
12 changes: 6 additions & 6 deletions src/liboslexec/wide/wide_opcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions src/liboslexec/wide/wide_opdictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BatchedShaderGlobals*>(bsg_);
return bsg->uniform.context->dict_find(
nullptr /*causes errors be reported through ShadingContext*/, nodeID,
USTR(query));
ustring_from(query));
}


Expand Down Expand Up @@ -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<BatchedShaderGlobals*>(bsg_);
return bsg->uniform.context->dict_find(
nullptr /*causes errors be reported through ShadingContext*/,
USTR(dictionary), USTR(query));
ustring_from(dictionary), ustring_from(query));
}


Expand Down Expand Up @@ -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<BatchedShaderGlobals*>(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);
}
Expand Down
Loading

0 comments on commit 67eb1cb

Please sign in to comment.