diff --git a/tsd/CMakeLists.txt b/tsd/CMakeLists.txt index 0e2f11605..05af06bc6 100644 --- a/tsd/CMakeLists.txt +++ b/tsd/CMakeLists.txt @@ -62,6 +62,8 @@ option(TSD_USE_MPI "Enable MPI support" OFF) option(TSD_USE_NETWORKING "Enable networking support via boost.asio" OFF) option(TSD_NANOVDB_SKIP_INVALID_VOLUMES "Skip NanoVDB volumes with zero active voxels" OFF) +option(TSD_NANOVDB_USE_ZIP + "Enable zlib so NanoVDB importer can read ZIP-compressed .nvdb files" ON) option(TSD_USE_LUA "Enable Lua scripting support" ON) if (APPLE) diff --git a/tsd/external/CMakeLists.txt b/tsd/external/CMakeLists.txt index b7d51152c..7ba084651 100644 --- a/tsd/external/CMakeLists.txt +++ b/tsd/external/CMakeLists.txt @@ -12,6 +12,7 @@ add_subdirectory(tsd_tinyexr) add_subdirectory(tsd_tinygltf) add_subdirectory(tsd_tinyobjloader) add_subdirectory(tsd_tinyply) +add_subdirectory(tsd_zlib EXCLUDE_FROM_ALL) add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/../../devices/rtx/external diff --git a/tsd/external/tsd_nanovdb/CMakeLists.txt b/tsd/external/tsd_nanovdb/CMakeLists.txt index e86e9ff73..ca64cc2b6 100644 --- a/tsd/external/tsd_nanovdb/CMakeLists.txt +++ b/tsd/external/tsd_nanovdb/CMakeLists.txt @@ -9,3 +9,12 @@ if (TSD_USE_TBB) project_link_libraries(INTERFACE TBB::tbb) project_compile_definitions(INTERFACE NANOVDB_USE_TBB) endif() + +if (TSD_NANOVDB_USE_ZIP) + # zlib decompresses ZIP-encoded .nvdb files at read time. ANARI always + # receives the decompressed in-memory grid buffer — the codec only + # affects on-disk storage. The tsd FindZLIB.cmake module supplies a + # fetched static fallback when no system zlib is available. + project_link_libraries(INTERFACE tsd_ext_zlib) + project_compile_definitions(INTERFACE NANOVDB_USE_ZIP) +endif() diff --git a/tsd/external/tsd_zlib/CMakeLists.txt b/tsd/external/tsd_zlib/CMakeLists.txt new file mode 100644 index 000000000..4b039a712 --- /dev/null +++ b/tsd/external/tsd_zlib/CMakeLists.txt @@ -0,0 +1,58 @@ +## Copyright 2026 NVIDIA Corporation +## SPDX-License-Identifier: Apache-2.0 + +# zlib - compression/decompression library +# Static fallback build when no system zlib is available. + +project(tsd_ext_zlib LANGUAGES C) + +find_package(ZLIB QUIET) +if(ZLIB_FOUND) + project_add_library(INTERFACE) + project_link_libraries(INTERFACE ZLIB::ZLIB) + return() +endif() + +message(STATUS + "ZLIB not found via find_package — fetching upstream zlib 1.3.1.") +anari_sdk_fetch_project( + NAME ${PROJECT_NAME} + URL https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz + MD5 9855b6d802d7fe5b7bd5b196a2271655 +) + +# Minimal static build — only the bits the compress/uncompress path needs. +# gzip stream I/O (gz*.c) is intentionally excluded. +project_add_library(STATIC + ${tsd_ext_zlib_LOCATION}/adler32.c + ${tsd_ext_zlib_LOCATION}/crc32.c + ${tsd_ext_zlib_LOCATION}/deflate.c + ${tsd_ext_zlib_LOCATION}/infback.c + ${tsd_ext_zlib_LOCATION}/inffast.c + ${tsd_ext_zlib_LOCATION}/inflate.c + ${tsd_ext_zlib_LOCATION}/inftrees.c + ${tsd_ext_zlib_LOCATION}/trees.c + ${tsd_ext_zlib_LOCATION}/zutil.c + ${tsd_ext_zlib_LOCATION}/compress.c + ${tsd_ext_zlib_LOCATION}/uncompr.c +) + +project_include_directories( + PUBLIC + $ +) + +set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) + +# Suppress warnings from zlib code +if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") + project_compile_options(PRIVATE -w) +elseif(MSVC) + # zlib uses a handful of CRT functions MSVC flags as "unsafe". + project_compile_options(PRIVATE /W0) + project_compile_definitions(PRIVATE + _CRT_SECURE_NO_DEPRECATE + _CRT_NONSTDC_NO_DEPRECATE + ) +endif() + diff --git a/tsd/src/tsd/io/importers/import_NVDB.cpp b/tsd/src/tsd/io/importers/import_NVDB.cpp index e492a03f6..b1abcab42 100644 --- a/tsd/src/tsd/io/importers/import_NVDB.cpp +++ b/tsd/src/tsd/io/importers/import_NVDB.cpp @@ -15,6 +15,7 @@ #include #include +#include namespace tsd::io { @@ -186,7 +187,17 @@ SpatialFieldRef import_NVDB(Scene &scene, const char *filepath) logStatus("[import_NVDB] ...done!"); } catch (const std::exception &e) { + using namespace std::string_view_literals; + const std::string_view msg(e.what()); logStatus("[import_NVDB] failed: %s", e.what()); + if (msg.find("compression codec was disabled"sv) != std::string_view::npos) { + logStatus( + "[import_NVDB] '%s' is stored with a compressed codec but TSD was " + "built without it. Reconfigure with -DTSD_NANOVDB_USE_ZIP=ON (and " + "ensure zlib is available) to decompress at read time. ANARI is " + "always handed the uncompressed in-memory grid buffer.", + filepath); + } scene.removeObject(field.data()); return {}; }