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

Replace InMemoryAssetResolver with DynamicTextureProvider #252

Merged
merged 11 commits into from
Apr 27, 2023
71 changes: 4 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ execute_process(
OUTPUT_VARIABLE CESIUM_OMNI_GIT_HASH_ABBREVIATED
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)

set(CESIUM_OMNI_CXX_DEFINES ${CESIUM_OMNI_CXX_DEFINES} CESIUM_OMNI_GIT_HASH_ABBREVIATED="${CESIUM_OMNI_GIT_HASH_ABBREVIATED}")
set(CESIUM_OMNI_CXX_DEFINES ${CESIUM_OMNI_CXX_DEFINES}
CESIUM_OMNI_GIT_HASH_ABBREVIATED="${CESIUM_OMNI_GIT_HASH_ABBREVIATED}")

# Add DEBUG definition to be able to #ifdef
set(CESIUM_OMNI_CXX_DEFINES_DEBUG ${CESIUM_OMNI_CXX_DEFINES_DEBUG} CESIUM_OMNI_DEBUG)
Expand Down Expand Up @@ -450,23 +451,10 @@ endforeach()
# Hide CONAN_CMD_PATH from CMake GUI
mark_as_advanced(CONAN_CMD_PATH)

# Configure plugInfo.json for InMemoryAssetResolver
set(PLUG_INFO_LIBRARY_FILE_NAME "${CMAKE_SHARED_LIBRARY_PREFIX}InMemoryAssetResolver${CMAKE_SHARED_LIBRARY_SUFFIX}")

set(PLUG_INFO_LIBRARY_PATH_BUILD "../../${PLUG_INFO_LIBRARY_FILE_NAME}")
set(PLUG_INFO_LIBRARY_PATH_INSTALL "../../lib/${PLUG_INFO_LIBRARY_FILE_NAME}")
set(PLUG_INFO_LIBRARY_PATH_KIT "../../bin/${PLUG_INFO_LIBRARY_FILE_NAME}")

set(PLUG_INFO_LIBRARY_PATH ${PLUG_INFO_LIBRARY_PATH_BUILD})
configure_file("${PROJECT_SOURCE_DIR}/src/plugins/InMemoryAssetResolver/plugInfo.json.in"
"${PROJECT_BINARY_DIR}/inMemoryAssetResolver.plugInfo.json.build")
set(PLUG_INFO_LIBRARY_PATH ${PLUG_INFO_LIBRARY_PATH_INSTALL})
configure_file("${PROJECT_SOURCE_DIR}/src/plugins/InMemoryAssetResolver/plugInfo.json.in"
"${PROJECT_BINARY_DIR}/inMemoryAssetResolver.plugInfo.json.install")
set(PLUG_INFO_LIBRARY_PATH ${PLUG_INFO_LIBRARY_PATH_KIT})
configure_file("${PROJECT_SOURCE_DIR}/src/plugins/InMemoryAssetResolver/plugInfo.json.in"
"${PROJECT_BINARY_DIR}/inMemoryAssetResolver.plugInfo.json.kit")

# Configure plugInfo.json for CesiumUsdSchemas
set(PLUG_INFO_LIBRARY_FILE_NAME "${CMAKE_SHARED_LIBRARY_PREFIX}CesiumUsdSchemas${CMAKE_SHARED_LIBRARY_SUFFIX}")

Expand All @@ -492,9 +480,6 @@ configure_file("${PROJECT_SOURCE_DIR}/src/plugins/CesiumUsdSchemas/generatedSche
configure_file("${PROJECT_SOURCE_DIR}/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in"
"${PROJECT_BINARY_DIR}/cesiumUsdSchemas.generatedSchema.usda.kit")

# Create mem.cesium
file(TOUCH "${PROJECT_BINARY_DIR}/mem.cesium")

set(KIT_EXTENSION_BIN_PATH "${PROJECT_SOURCE_DIR}/exts/cesium.omniverse/bin")
set(KIT_PLUGIN_EXTENSION_BIN_PATH "${PROJECT_SOURCE_DIR}/exts/cesium.usd.plugins/bin")
set(KIT_EXTENSION_BINDINGS_PATH "${PROJECT_SOURCE_DIR}/exts/cesium.omniverse/cesium/omniverse/bindings")
Expand All @@ -517,35 +502,11 @@ set(KIT_EXTENSION_PLUGINS_PATH "${PROJECT_SOURCE_DIR}/exts/cesium.usd.plugins/pl
# to the search path. Unfortunately CMake will print a warning when python .so is
# found this way.

set(INSTALL_SEARCH_PATHS $<TARGET_FILE_DIR:python37> $<TARGET_FILE_DIR:usd> $<TARGET_FILE_DIR:carb>)
get_property(INSTALL_SEARCH_PATHS GLOBAL PROPERTY NVIDIA_ADDITIONAL_SEARCH_PATHS_PROPERTY)

set(INSTALL_PRE_EXCLUDE_REGEXES "api-ms-*" "ext-ms-*")
set(INSTALL_POST_EXCLUDE_REGEXES "system32" "^\/lib")

install(
TARGETS InMemoryAssetResolver
ARCHIVE DESTINATION ${KIT_PLUGIN_EXTENSION_BIN_PATH} COMPONENT install
LIBRARY DESTINATION ${KIT_PLUGIN_EXTENSION_BIN_PATH} COMPONENT install
RUNTIME DESTINATION ${KIT_PLUGIN_EXTENSION_BIN_PATH} COMPONENT install)

install(
TARGETS InMemoryAssetResolver
RUNTIME_DEPENDENCIES
DIRECTORIES
${INSTALL_SEARCH_PATHS}
PRE_EXCLUDE_REGEXES
${INSTALL_PRE_EXCLUDE_REGEXES}
POST_EXCLUDE_REGEXES
${INSTALL_POST_EXCLUDE_REGEXES}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL)

install(
TARGETS CesiumUsdSchemas
ARCHIVE DESTINATION ${KIT_PLUGIN_EXTENSION_BIN_PATH} COMPONENT install
Expand Down Expand Up @@ -647,36 +608,12 @@ install(
COMPONENT library
EXCLUDE_FROM_ALL)

install(
FILES "${PROJECT_BINARY_DIR}/mem.cesium"
DESTINATION ${KIT_EXTENSION_BIN_PATH}
COMPONENT install)

install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT library
EXCLUDE_FROM_ALL)

install(
FILES "${PROJECT_BINARY_DIR}/mem.cesium"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL)

install(
FILES "${PROJECT_BINARY_DIR}/inMemoryAssetResolver.plugInfo.json.kit"
DESTINATION "${KIT_EXTENSION_PLUGINS_PATH}/InMemoryAssetResolver/resources/"
RENAME "plugInfo.json"
COMPONENT install)

install(
FILES "${PROJECT_BINARY_DIR}/inMemoryAssetResolver.plugInfo.json.install"
DESTINATION "plugins/InMemoryAssetResolver/resources/"
RENAME "plugInfo.json"
COMPONENT library
EXCLUDE_FROM_ALL)

install(
FILES "${PROJECT_BINARY_DIR}/cesiumUsdSchemas.plugInfo.json.kit"
DESTINATION "${KIT_EXTENSION_PLUGINS_PATH}/CesiumUsdSchemas/resources/"
Expand Down
30 changes: 22 additions & 8 deletions cmake/Macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function(setup_lib)
""
""
"TARGET_NAME;TYPE"
"SOURCES;INCLUDE_DIRS;PRIVATE_INCLUDE_DIRS;LIBRARIES;DEPENDENCIES;CXX_FLAGS;CXX_FLAGS_DEBUG;CXX_DEFINES;CXX_DEFINES_DEBUG"
"SOURCES;INCLUDE_DIRS;PRIVATE_INCLUDE_DIRS;LIBRARIES;ADDITIONAL_LIBRARIES;DEPENDENCIES;CXX_FLAGS;CXX_FLAGS_DEBUG;CXX_DEFINES;CXX_DEFINES_DEBUG"
${ARGN})

if(_TYPE)
Expand Down Expand Up @@ -52,6 +52,17 @@ function(setup_lib)
COMMAND_EXPAND_LISTS)
endif()

if(WIN32 AND _ADDITIONAL_LIBRARIES)
# TARGET_RUNTIME_DLLS only works for IMPORTED targets. In some cases we can't create IMPORTED targets
# because there's no import library (.lib) just a shared library (.dll)
# We need to copy these to the build folder manually
add_custom_command(
TARGET ${_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${_ADDITIONAL_LIBRARIES} $<TARGET_FILE_DIR:${_TARGET_NAME}>
COMMAND_EXPAND_LISTS)
endif()

endfunction(setup_lib)

# Set up a python module
Expand Down Expand Up @@ -155,14 +166,16 @@ function(setup_usd_python_lib)

target_compile_options(${_PREFIXED_TARGET_NAME} PRIVATE ${_CXX_FLAGS} "$<$<CONFIG:DEBUG>:${_CXX_FLAGS_DEBUG}>")

target_compile_definitions(${_PREFIXED_TARGET_NAME} PRIVATE ${_CXX_DEFINES} "$<$<CONFIG:DEBUG>:${_CXX_DEFINES_DEBUG}>")
target_compile_definitions(${_PREFIXED_TARGET_NAME} PRIVATE ${_CXX_DEFINES}
"$<$<CONFIG:DEBUG>:${_CXX_DEFINES_DEBUG}>")

# cmake-format: off
target_compile_definitions(${_PREFIXED_TARGET_NAME}
PRIVATE
MFB_PACKAGE_NAME=${_TARGET_NAME}
MFB_ALT_PACKAGE_NAME=${_TARGET_NAME}
MFB_PACKAGE_MODULE=${_TARGET_NAME}.${_PYTHON_MODULE_NAME}
)
PRIVATE
MFB_PACKAGE_NAME=${_TARGET_NAME}
MFB_ALT_PACKAGE_NAME=${_TARGET_NAME}
MFB_PACKAGE_MODULE=${_TARGET_NAME}.${_PYTHON_MODULE_NAME})
# cmake-format: on

target_link_libraries(${_PREFIXED_TARGET_NAME} PRIVATE ${_LIBRARIES})

Expand Down Expand Up @@ -198,7 +211,8 @@ function(setup_usd_python_lib)
add_custom_command(
TARGET ${_PREFIXED_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:${_PREFIXED_TARGET_NAME}> $<TARGET_FILE_DIR:${_PREFIXED_TARGET_NAME}>
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:${_PREFIXED_TARGET_NAME}>
$<TARGET_FILE_DIR:${_PREFIXED_TARGET_NAME}>
COMMAND_EXPAND_LISTS)
endif()

Expand Down
49 changes: 49 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set(CARB_ROOT "${NVIDIA_BUILD_DIR}/target-deps/carb_sdk_plugins")
set(KIT_SDK_ROOT "${NVIDIA_BUILD_DIR}/target-deps/kit-sdk")
set(PYBIND11_ROOT "${NVIDIA_BUILD_DIR}/target-deps/pybind11")
set(CUDA_ROOT "${NVIDIA_BUILD_DIR}/target-deps/cuda")
set(RTX_PLUGINS_ROOT "${NVIDIA_BUILD_DIR}/target-deps/rtx_plugins")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, please raise this up to Nvidia so we can understand if this is an expected dependency.


set(NVIDIA_USD_LIBRARIES
ar
Expand Down Expand Up @@ -303,3 +304,51 @@ else()
)
# cmake-format: on
endif()

# cmake-format: off
# omni.ui gives us access to DynamicTextureProvider.h
add_prebuilt_project(
RELEASE_INCLUDE_DIR
"${KIT_SDK_ROOT}/dev/include"
DEBUG_INCLUDE_DIR
"${KIT_SDK_ROOT}/dev/include"
RELEASE_LIBRARY_DIR
"${KIT_SDK_ROOT}/extscore/omni.ui/bin"
DEBUG_LIBRARY_DIR
"${KIT_SDK_ROOT}/extscore/omni.ui/bin"
RELEASE_LIBRARIES
omni.ui
DEBUG_LIBRARIES
omni.ui
TARGET_NAMES
omni_ui
)
# cmake-format: on

# cmake-format: off
# DynamicTextureProvider.h includes IImaging.h which only exists in the rtx_plugin package
add_prebuilt_project_header_only(
INCLUDE_DIR
"${RTX_PLUGINS_ROOT}/include"
TARGET_NAME
rtx_plugins
)
# cmake-format: on

if(WIN32)
set(NVIDIA_ADDITIONAL_LIBRARIES
"${PROJECT_SOURCE_DIR}/extern/nvidia/_build/target-deps/kit-sdk/extscore/omni.kit.renderer.imgui/bin/imgui.dll"
"${PROJECT_SOURCE_DIR}/extern/nvidia/_build/target-deps/kit-sdk/extscore/omni.kit.renderer.imgui/bin/deps/freetype.dll"
)

set_property(GLOBAL PROPERTY NVIDIA_ADDITIONAL_LIBRARIES_PROPERTY "${NVIDIA_ADDITIONAL_LIBRARIES}")
else()
set(NVIDIA_ADDITIONAL_SEARCH_PATHS
"$<TARGET_FILE_DIR:python37>"
"$<TARGET_FILE_DIR:usd>"
"$<TARGET_FILE_DIR:carb>"
# This is where freetype is located on Linux
"${PROJECT_SOURCE_DIR}/extern/nvidia/_build/target-deps/kit-sdk/plugins")

set_property(GLOBAL PROPERTY NVIDIA_ADDITIONAL_SEARCH_PATHS_PROPERTY "${NVIDIA_ADDITIONAL_SEARCH_PATHS}")
endif()
2 changes: 2 additions & 0 deletions extern/nvidia/deps/target-deps.packman.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<filter include="carb_sdk_plugins"/>
<filter include="pybind11"/>
<filter include="cuda"/>
<filter include="rtx_plugins"/>
</import>
<!-- Override the link paths to point to the correct locations. -->
<dependency name="python" linkPath="../_build/target-deps/python"/>
Expand All @@ -17,4 +18,5 @@
<dependency name="carb_sdk_plugins" linkPath="../_build/target-deps/carb_sdk_plugins"/>
<dependency name="pybind11" linkPath="../_build/target-deps/pybind11/pybind11"/>
<dependency name="cuda" linkPath="../_build/target-deps/cuda/cuda"/>
<dependency name="rtx_plugins" linkPath="../_build/target-deps/rtx_plugins"/>
</project>
3 changes: 0 additions & 3 deletions exts/cesium.omniverse/cesium/omniverse/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ def on_startup(self):
_cesium_omniverse_interface.on_startup(cesium_extension_location)

omni_settings.get_settings().set("/rtx/hydra/TBNFrameMode", 1)
# Disabling Texture Streaming is a workaround for issues with Kit 104.1. We should remove this as soon as
# the issue is fixed.
omni_settings.get_settings().set("/rtx-transient/resourcemanager/enableTextureStreaming", False)

# Show the window. It will call `self.show_window`
if show_on_startup:
Expand Down
8 changes: 0 additions & 8 deletions exts/cesium.usd.plugins/cesium/usd/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
from pxr import Plug

pluginsRoot = os.path.join(os.path.dirname(__file__), "../../../plugins")
inMemoryAssetResolverPath = pluginsRoot + "/InMemoryAssetResolver/resources"
cesiumUsdSchemasPath = pluginsRoot + "/CesiumUsdSchemas/resources"

Plug.Registry().RegisterPlugins(inMemoryAssetResolverPath)
plugin = Plug.Registry().GetPluginWithName("InMemoryAssetResolver")
if plugin:
plugin.Load()
else:
print("Cannot find plugin")

Plug.Registry().RegisterPlugins(cesiumUsdSchemasPath)
plugin = Plug.Registry().GetPluginWithName("CesiumUsdSchemas")
if plugin:
Expand Down
3 changes: 0 additions & 3 deletions exts/cesium.usd.plugins/config/extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,5 @@ icon = "doc/images/icon.png"
[[python.module]]
name = "cesium.usd.plugins"

[[native.library]]
path = "bin/${lib_prefix}InMemoryAssetResolver${lib_ext}"

[[native.library]]
path = "bin/${lib_prefix}CesiumUsdSchemas${lib_ext}"
7 changes: 6 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ include(Macros)

glob_files(SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp")

get_property(ADDITIONAL_LIBRARIES GLOBAL PROPERTY NVIDIA_ADDITIONAL_LIBRARIES_PROPERTY)

# cmake-format: off
setup_lib(
TARGET_NAME
Expand All @@ -31,7 +33,6 @@ setup_lib(
INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}/include"
LIBRARIES
InMemoryAssetResolver
CesiumUsdSchemas
CesiumIonClient
Cesium3DTilesSelection
Expand Down Expand Up @@ -82,8 +83,12 @@ setup_lib(
carb
cudart
omni_kit_app
omni_ui
rtx_plugins
pybind11
python37
ADDITIONAL_LIBRARIES
"${ADDITIONAL_LIBRARIES}"
DEPENDENCIES
cesium-native-external
CXX_FLAGS
Expand Down
2 changes: 0 additions & 2 deletions src/core/include/cesium/omniverse/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class Context {
uint64_t assetEventId);

std::filesystem::path getCesiumExtensionLocation() const;
std::filesystem::path getMemCesiumPath() const;
std::filesystem::path getCertificatePath() const;
bool getDebugDisableMaterials() const;

Expand Down Expand Up @@ -146,7 +145,6 @@ class Context {
mutable std::atomic<int64_t> _tileId{};

std::filesystem::path _cesiumExtensionLocation;
std::filesystem::path _memCesiumPath;
std::filesystem::path _certificatePath;

bool _debugDisableMaterials{false};
Expand Down
51 changes: 51 additions & 0 deletions src/core/include/cesium/omniverse/DynamicTextureProviderCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include <omni/ui/ImageProvider/DynamicTextureProvider.h>
#include <tbb/concurrent_hash_map.h>

namespace cesium::omniverse {

class DynamicTextureProviderCacheItem;

class DynamicTextureProviderCache {
public:
using Accessor = tbb::concurrent_hash_map<std::string, std::shared_ptr<DynamicTextureProviderCacheItem>>::accessor;
using ConstAccessor =
tbb::concurrent_hash_map<std::string, std::shared_ptr<DynamicTextureProviderCacheItem>>::const_accessor;

DynamicTextureProviderCache(const DynamicTextureProviderCache&) = delete;
DynamicTextureProviderCache(DynamicTextureProviderCache&&) = delete;

static DynamicTextureProviderCache& getInstance() {
static DynamicTextureProviderCache instance;
return instance;
}

DynamicTextureProviderCache& operator=(const DynamicTextureProviderCache&) = delete;
DynamicTextureProviderCache& operator=(DynamicTextureProviderCache) = delete;

void insert(const std::string& name, std::unique_ptr<omni::ui::DynamicTextureProvider> dynamicTextureProvider);
void addReference(const std::string& name);
void removeReference(const std::string& name);
bool contains(const std::string& name) const;

protected:
DynamicTextureProviderCache() = default;
~DynamicTextureProviderCache() = default;

private:
tbb::concurrent_hash_map<std::string, std::shared_ptr<DynamicTextureProviderCacheItem>> _items;
};

class DynamicTextureProviderCacheItem {
public:
DynamicTextureProviderCacheItem(std::unique_ptr<omni::ui::DynamicTextureProvider> dynamicTextureProvider);

private:
std::unique_ptr<omni::ui::DynamicTextureProvider> _dynamicTextureProvider;
size_t _referenceCount;

friend DynamicTextureProviderCache;
};

} // namespace cesium::omniverse
Loading