Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ShadingSystem attribute "searchpath:library" (similar to searchpa… #1310

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/liboslexec/oslexec_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ class ShadingSystemImpl
ustring debug_groupname() const { return m_debug_groupname; }
ustring debug_layername() const { return m_debug_layername; }

std::string library_searchpath() const { return m_library_searchpath; }
const std::vector<std::string> & library_searchpath_dirs() const { return m_library_searchpath_dirs; }

/// Look within the group for separate nodes that are actually
/// duplicates of each other and combine them. Return the number of
/// instances that were eliminated.
Expand Down Expand Up @@ -790,6 +793,8 @@ class ShadingSystemImpl
ustring m_archive_filename; ///< Name of filename for group archive
std::string m_searchpath; ///< Shader search path
std::vector<std::string> m_searchpath_dirs; ///< All searchpath dirs
std::string m_library_searchpath; ///< Library search path
std::vector<std::string> m_library_searchpath_dirs; ///< All library searchpath dirs
ustring m_commonspace_synonym; ///< Synonym for "common" space
std::vector<ustring> m_raytypes; ///< Names of ray types
std::vector<ustring> m_renderer_outputs; ///< Names of renderer outputs
Expand Down
6 changes: 6 additions & 0 deletions src/liboslexec/shadingsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,11 @@ ShadingSystemImpl::attribute (string_view name, TypeDesc type,
OIIO::Filesystem::searchpath_split (m_searchpath, m_searchpath_dirs);
return true;
}
if (name == "searchpath:library" && type == TypeDesc::STRING) {
m_library_searchpath = std::string (*(const char **)val);
OIIO::Filesystem::searchpath_split (m_library_searchpath, m_library_searchpath_dirs);
return true;
}
if (name == "colorspace" && type == TypeDesc::STRING) {
ustring c = ustring (*(const char **)val);
if (colorsystem().set_colorspace(c))
Expand Down Expand Up @@ -1473,6 +1478,7 @@ ShadingSystemImpl::getattribute (string_view name, TypeDesc type,
lock_guard guard (m_mutex); // Thread safety

ATTR_DECODE_STRING ("searchpath:shader", m_searchpath);
ATTR_DECODE_STRING ("searchpath:library", m_library_searchpath);
lgritz marked this conversation as resolved.
Show resolved Hide resolved
ATTR_DECODE ("statistics:level", int, m_statslevel);
ATTR_DECODE ("lazylayers", int, m_lazylayers);
ATTR_DECODE ("lazyglobals", int, m_lazyglobals);
Expand Down
45 changes: 44 additions & 1 deletion src/testshade/testshade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static std::vector<std::string> outputvars;
static std::vector<ustring> outputvarnames;
static std::string dataformatname = "";
static std::string shaderpath;
static std::string librarypath;
static std::vector<std::string> entrylayers;
static std::vector<std::string> entryoutputs;
static std::vector<int> entrylayer_index;
Expand Down Expand Up @@ -113,7 +114,36 @@ inject_params ()
pv.interp() == ParamValue::INTERP_CONSTANT);
}


static std::string get_executable_directory() {
AlexMWells marked this conversation as resolved.
Show resolved Hide resolved
#if (defined(_WIN32) || defined(_WIN64))
// TODO: test on windows
char path_to_exec[PATH_MAX+1];
int len = GetModuleFileNameA(NULL, path_to_exec, PATH_MAX);
ASSERT(len < (PATH_MAX+1));
for(;;) {
if (success[--len] == '\\') {
path_to_exec[len] = 0;
break;
}
}
//std::cout << path_to_exec << std::endl;
return path_to_exec;
#else
char path_to_exec[PATH_MAX+1];
char * success = realpath("/proc/self/exe", path_to_exec);
ASSERT(success);
int len = strlen(path_to_exec);
ASSERT(len < (PATH_MAX+1));
for(;;) {
if (success[--len] == '/') {
path_to_exec[len] = 0;
break;
}
}
//std::cout << path_to_exec << std::endl;
return path_to_exec;
#endif
}

// Set shading system global attributes based on command line options.
static void
Expand Down Expand Up @@ -159,6 +189,18 @@ set_shadingsys_options ()
shadingsys->attribute ("userdata_isconnected", userdata_isconnected);
if (! shaderpath.empty())
shadingsys->attribute ("searchpath:shader", shaderpath);
if (librarypath.empty()) {
// Look in expected dist directory tree,
// also look in expected build tree for the unittests
// TODO: test on windows
#if (defined(_WIN32) || defined(_WIN64))
static const char * relative_lib_dir = "\\..\\lib64:\\..\\liboslexec";
#else
static const char * relative_lib_dir = "/../lib64:/../liboslexec";
AlexMWells marked this conversation as resolved.
Show resolved Hide resolved
#endif
librarypath = get_executable_directory() + relative_lib_dir;
AlexMWells marked this conversation as resolved.
Show resolved Hide resolved
}
shadingsys->attribute ("searchpath:library", librarypath);
if (extraoptions.size())
shadingsys->attribute ("options", extraoptions);
if (texoptions.size())
Expand Down Expand Up @@ -571,6 +613,7 @@ getargs (int argc, const char *argv[])
"--saveptx", &saveptx, "Save the generated PTX (OptiX mode only)",
"--warmup", &warmup, "Perform a warmup launch",
"--path %s", &shaderpath, "Specify oso search path",
"--library %s", &librarypath, "Specify library search path",
AlexMWells marked this conversation as resolved.
Show resolved Hide resolved
"--res %d %d", &xres, &yres, "Make an W x H image",
"-g %d %d", &xres, &yres, "", // synonym for -res
"--options %s", &extraoptions, "Set extra OSL options",
Expand Down