From 854769d6d7b7983283ab9bec2d480b24cccec28c Mon Sep 17 00:00:00 2001 From: Thomas Arcila <134677+tarcila@users.noreply.github.com> Date: Fri, 20 Mar 2026 16:13:19 -0400 Subject: [PATCH 1/3] Support for loading compress NVDBs --- tsd/CMakeLists.txt | 2 + tsd/external/tsd_nanovdb/CMakeLists.txt | 47 ++++++++++++++++++++++++ tsd/src/tsd/io/importers/import_NVDB.cpp | 11 ++++++ 3 files changed, 60 insertions(+) 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/tsd_nanovdb/CMakeLists.txt b/tsd/external/tsd_nanovdb/CMakeLists.txt index e86e9ff73..31140e8e6 100644 --- a/tsd/external/tsd_nanovdb/CMakeLists.txt +++ b/tsd/external/tsd_nanovdb/CMakeLists.txt @@ -9,3 +9,50 @@ if (TSD_USE_TBB) project_link_libraries(INTERFACE TBB::tbb) project_compile_definitions(INTERFACE NANOVDB_USE_TBB) endif() +if (TSD_NANOVDB_USE_ZIP) + # zlib is required at read time to decompress ZIP-encoded .nvdb files. + # ANARI consumes the decompressed in-memory grid buffer, so the codec + # only affects on-disk storage, not what crosses the ANARI boundary. + find_package(ZLIB QUIET) + if (NOT TARGET ZLIB::ZLIB) + message(STATUS + "ZLIB not found via find_package — fetching upstream zlib 1.3.1.") + anari_sdk_fetch_project( + NAME tsd_ext_zlib + URL https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz + MD5 9855b6d802d7fe5b7bd5b196a2271655 + ) + + # Build a minimal static zlib — only the bits NanoVDB's compress/uncompress + # path needs. gzip stream I/O (gz*.c) is intentionally excluded. + add_library(tsd_ext_zlib 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 + ) + target_include_directories(tsd_ext_zlib + PUBLIC $ + ) + set_target_properties(tsd_ext_zlib PROPERTIES POSITION_INDEPENDENT_CODE ON) + if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") + target_compile_options(tsd_ext_zlib PRIVATE -w) + elseif (MSVC) + target_compile_options(tsd_ext_zlib PRIVATE /W0 + # zlib uses a handful of CRT functions MSVC flags as "unsafe". + /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE + ) + endif() + + add_library(ZLIB::ZLIB ALIAS tsd_ext_zlib) + endif() + project_link_libraries(INTERFACE ZLIB::ZLIB) + project_compile_definitions(INTERFACE NANOVDB_USE_ZIP) +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 {}; } From 3e1ea2210650f66156f033497735d21e1c2311fd Mon Sep 17 00:00:00 2001 From: Thomas Arcila <134677+tarcila@users.noreply.github.com> Date: Fri, 20 Mar 2026 16:13:19 -0400 Subject: [PATCH 2/3] Split FindZLIB in its own file --- tsd/external/CMakeLists.txt | 1 + tsd/external/tsd_nanovdb/CMakeLists.txt | 50 +++------------------ tsd/external/tsd_zlib/CMakeLists.txt | 58 +++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 44 deletions(-) create mode 100644 tsd/external/tsd_zlib/CMakeLists.txt diff --git a/tsd/external/CMakeLists.txt b/tsd/external/CMakeLists.txt index b7d51152c..ee5c03c09 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) 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 31140e8e6..ca64cc2b6 100644 --- a/tsd/external/tsd_nanovdb/CMakeLists.txt +++ b/tsd/external/tsd_nanovdb/CMakeLists.txt @@ -9,50 +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 is required at read time to decompress ZIP-encoded .nvdb files. - # ANARI consumes the decompressed in-memory grid buffer, so the codec - # only affects on-disk storage, not what crosses the ANARI boundary. - find_package(ZLIB QUIET) - if (NOT TARGET ZLIB::ZLIB) - message(STATUS - "ZLIB not found via find_package — fetching upstream zlib 1.3.1.") - anari_sdk_fetch_project( - NAME tsd_ext_zlib - URL https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz - MD5 9855b6d802d7fe5b7bd5b196a2271655 - ) - - # Build a minimal static zlib — only the bits NanoVDB's compress/uncompress - # path needs. gzip stream I/O (gz*.c) is intentionally excluded. - add_library(tsd_ext_zlib 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 - ) - target_include_directories(tsd_ext_zlib - PUBLIC $ - ) - set_target_properties(tsd_ext_zlib PROPERTIES POSITION_INDEPENDENT_CODE ON) - if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") - target_compile_options(tsd_ext_zlib PRIVATE -w) - elseif (MSVC) - target_compile_options(tsd_ext_zlib PRIVATE /W0 - # zlib uses a handful of CRT functions MSVC flags as "unsafe". - /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE - ) - endif() - add_library(ZLIB::ZLIB ALIAS tsd_ext_zlib) - endif() - project_link_libraries(INTERFACE ZLIB::ZLIB) +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() + From a545d93650892203aaac8c43a15f93f0872d801b Mon Sep 17 00:00:00 2001 From: Thomas Arcila <134677+tarcila@users.noreply.github.com> Date: Tue, 12 May 2026 20:57:06 -0400 Subject: [PATCH 3/3] Exclude zlib from all So it is only build is referenced by another target. --- tsd/external/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsd/external/CMakeLists.txt b/tsd/external/CMakeLists.txt index ee5c03c09..7ba084651 100644 --- a/tsd/external/CMakeLists.txt +++ b/tsd/external/CMakeLists.txt @@ -12,7 +12,7 @@ add_subdirectory(tsd_tinyexr) add_subdirectory(tsd_tinygltf) add_subdirectory(tsd_tinyobjloader) add_subdirectory(tsd_tinyply) -add_subdirectory(tsd_zlib) +add_subdirectory(tsd_zlib EXCLUDE_FROM_ALL) add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/../../devices/rtx/external