-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from Esri/issue98-avoid-RPK-unpacking
#98: adding new palladio_fs component to avoid RPK unpacking
- Loading branch information
Showing
11 changed files
with
267 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
|
||
### project definition | ||
|
||
project(palladio_fs CXX) | ||
|
||
|
||
### target definition | ||
|
||
add_library(${PROJECT_NAME} SHARED | ||
main.cpp | ||
RulePackageFS.cpp | ||
../palladio/Utils.cpp | ||
../palladio/LogHandler.cpp) | ||
|
||
target_include_directories(${PROJECT_NAME} PRIVATE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||
${CMAKE_CURRENT_SOURCE_DIR}/..) | ||
|
||
### compiler settings | ||
|
||
add_toolchain_definition(${PROJECT_NAME}) | ||
pld_add_version_definitions(${PROJECT_NAME}) | ||
|
||
if(PLD_WINDOWS) | ||
# nothing, inheriting compiler flags from houdini | ||
|
||
elseif(PLD_LINUX) | ||
if (${CMAKE_BUILD_TYPE} STREQUAL "Release") | ||
target_compile_options(${PROJECT_NAME} PRIVATE -O3 -flto) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE -DNDEBUG) | ||
elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") | ||
target_compile_options(${PROJECT_NAME} PRIVATE -O3 -ggdb -pg) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE -DNDEBUG) | ||
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug") | ||
target_compile_options(${PROJECT_NAME} PRIVATE -O0 -ggdb -pg) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE -DDEBUG) | ||
endif() | ||
|
||
set_target_properties(${PROJECT_NAME} PROPERTIES | ||
INSTALL_RPATH "\$ORIGIN/../../packages/palladio" | ||
INSTALL_RPATH_USE_LINK_PATH FALSE | ||
SKIP_RPATH FALSE | ||
BUILD_WITH_INSTALL_RPATH TRUE) | ||
endif() | ||
|
||
|
||
### dependencies | ||
|
||
pld_add_dependency_prt(${PROJECT_NAME}) | ||
pld_add_dependency_houdini(${PROJECT_NAME}) | ||
|
||
|
||
### setup install target | ||
|
||
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${HOUDINI_RELATIVE_DSO_PATH}/fs LIBRARY DESTINATION ${HOUDINI_RELATIVE_DSO_PATH}/fs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#include "RulePackageFS.h" | ||
|
||
#include "prtx/DataBackend.h" // !!! use of PRTX requires palladio_fs to be built with the same compiler as PRT | ||
|
||
#include "FS/FS_ReaderStream.h" | ||
|
||
#include <iostream> | ||
#include <map> | ||
#include <mutex> | ||
|
||
namespace { | ||
|
||
const std::string SCHEMA_RPK = "rpk:"; | ||
|
||
bool isRulePackageURI(const char* p) { | ||
if (p == nullptr) | ||
return false; | ||
|
||
// needs to start with rpk: schema | ||
if (std::strncmp(p, SCHEMA_RPK.c_str(), SCHEMA_RPK.length()) != 0) | ||
return false; | ||
|
||
// needs to contain '!' separator | ||
if (std::strchr(p, '!') == nullptr) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
// The base URI is the "inner most" URI as defined by prtx::URI, i.e. the actual file | ||
std::string getBaseURI(const char* p) { | ||
const char* lastSchemaSep = std::strrchr(p, ':'); | ||
const char* firstInnerSep = std::strchr(p, '!'); | ||
if (lastSchemaSep < firstInnerSep) { | ||
return std::string(lastSchemaSep + 1, firstInnerSep); | ||
} | ||
else | ||
return {}; | ||
} | ||
|
||
prtx::BinaryVectorPtr resolveRulePackageFile(const char* source, prt::Cache* cache) { | ||
assert(source != nullptr); | ||
const std::wstring uri = toUTF16FromOSNarrow(source); | ||
|
||
try { | ||
std::wstring warnings; | ||
const prtx::BinaryVectorPtr data = prtx::DataBackend::resolveBinaryData(cache, uri, nullptr, &warnings); | ||
if (!warnings.empty()) | ||
std::wcerr << L"resolveBinaryData warnings: " << warnings << std::endl; | ||
return data; | ||
} | ||
catch (std::exception& e) { | ||
std::cerr << "caught exception: " << e.what() << std::endl; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
} // namespace | ||
|
||
RulePackageReader::RulePackageReader(prt::Cache* cache) : mCache(cache) { | ||
UTaddAbsolutePathPrefix(SCHEMA_RPK.c_str()); | ||
} | ||
|
||
FS_ReaderStream* RulePackageReader::createStream(const char* source, const UT_Options*) { | ||
if (isRulePackageURI(source)) { | ||
const prtx::BinaryVectorPtr buf = resolveRulePackageFile(source, mCache); | ||
if (!buf) | ||
return nullptr; | ||
return new FS_ReaderStream((const char*)buf->data(), buf->size(), 0); // freed by Houdini | ||
} | ||
return nullptr; | ||
} | ||
|
||
RulePackageInfoHelper::RulePackageInfoHelper(prt::Cache* cache) : mCache(cache) {} | ||
|
||
bool RulePackageInfoHelper::canHandle(const char* source) { | ||
return isRulePackageURI(source); | ||
} | ||
|
||
bool RulePackageInfoHelper::hasAccess(const char* source, int mode) { | ||
std::string src(source); | ||
if (isRulePackageURI(source)) | ||
src = getBaseURI(source); | ||
FS_Info info(src.c_str()); | ||
return info.hasAccess(mode); | ||
} | ||
|
||
bool RulePackageInfoHelper::getIsDirectory(const char* source) { | ||
if (isRulePackageURI(source)) | ||
return false; | ||
FS_Info info(source); | ||
return info.getIsDirectory(); | ||
} | ||
|
||
int RulePackageInfoHelper::getModTime(const char* source) { | ||
std::string src(source); | ||
if (isRulePackageURI(source)) | ||
src = getBaseURI(source); | ||
FS_Info info(src.c_str()); | ||
return info.getModTime(); | ||
} | ||
|
||
int64 RulePackageInfoHelper::getSize(const char* source) { | ||
if (isRulePackageURI(source)) { | ||
const prtx::BinaryVectorPtr buf = resolveRulePackageFile(source, mCache); | ||
return buf->size(); | ||
} | ||
FS_Info info(source); | ||
return info.getFileDataSize(); | ||
} | ||
|
||
UT_String RulePackageInfoHelper::getExtension(const char* source) { | ||
if (isRulePackageURI(source)) { | ||
const char* lastSchemaSep = std::strrchr(source, '.'); | ||
return UT_String(lastSchemaSep); | ||
} | ||
FS_Info info(source); | ||
return info.getExtension(); | ||
} | ||
|
||
bool RulePackageInfoHelper::getContents(const char* source, UT_StringArray& contents, UT_StringArray* dirs) { | ||
if (isRulePackageURI(source)) | ||
return false; // we only support individual texture files atm | ||
FS_Info info(source); | ||
return info.getContents(contents, dirs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "FS/FS_Info.h" | ||
#include "FS/FS_Reader.h" | ||
|
||
#include "palladio/Utils.h" | ||
|
||
/** | ||
* support for nested file RPK URIs: | ||
* rpk:file:/path/to/file.rpk!/nested/file.cgb | ||
*/ | ||
|
||
class RulePackageReader : public FS_ReaderHelper { | ||
public: | ||
RulePackageReader(prt::Cache* cache); | ||
virtual ~RulePackageReader() = default; | ||
|
||
FS_ReaderStream* createStream(const char* source, const UT_Options* options) override; | ||
|
||
private: | ||
prt::Cache* mCache; | ||
}; | ||
|
||
class RulePackageInfoHelper : public FS_InfoHelper { | ||
public: | ||
RulePackageInfoHelper(prt::Cache* cache); | ||
virtual ~RulePackageInfoHelper() = default; | ||
|
||
bool canHandle(const char* source) override; | ||
bool hasAccess(const char* source, int mode) override; | ||
bool getIsDirectory(const char* source) override; | ||
int getModTime(const char* source) override; | ||
int64 getSize(const char* source) override; | ||
UT_String getExtension(const char* source) override; | ||
bool getContents(const char* source, UT_StringArray& contents, UT_StringArray* dirs) override; | ||
|
||
private: | ||
prt::Cache* mCache; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "RulePackageFS.h" | ||
|
||
#include "FS/FS_Utils.h" // required for installFSHelpers to work below | ||
#include "UT/UT_DSOVersion.h" // required for valid Houdini DSO | ||
|
||
#include <iostream> | ||
#include <memory> | ||
|
||
namespace { | ||
|
||
CacheObjectUPtr prtCache; // TODO: prevent from growing too much | ||
|
||
std::unique_ptr<RulePackageReader> rpkReader; | ||
std::unique_ptr<RulePackageInfoHelper> rpkInfoHelper; | ||
|
||
} // namespace | ||
|
||
void installFSHelpers() { | ||
prtCache.reset(prt::CacheObject::create(prt::CacheObject::CACHE_TYPE_NONREDUNDANT)); | ||
|
||
rpkReader = std::make_unique<RulePackageReader>(prtCache.get()); | ||
rpkInfoHelper = std::make_unique<RulePackageInfoHelper>(prtCache.get()); | ||
|
||
std::clog << "Palladio: Registered custom FS reader for Rule Packages.\n"; | ||
} |