From d9ae3082c15acf3c9a2385e6b13ac8bf83666ad4 Mon Sep 17 00:00:00 2001 From: Sameer Sheorey Date: Tue, 10 Dec 2024 16:25:57 -0800 Subject: [PATCH] Hide symbols from core and visualization to reduce Windows DLL size. --- CMakeLists.txt | 1 + cpp/open3d/CMakeLists.txt | 2 + cpp/open3d/core/CMakeLists.txt | 47 ++++++++++++------- .../SurfaceReconstructionBallPivoting.cpp | 2 + .../geometry/SurfaceReconstructionPoisson.cpp | 13 +++-- cpp/open3d/visualization/CMakeLists.txt | 18 +++++-- 6 files changed, 55 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b047cd0b82..16a2e5bf94c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -476,6 +476,7 @@ if(WIN32) # Then, we could use -fvisibility=hidden for Linux as well SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) if(MSVC) + add_compile_options("/permissive-") # MSVC standards-compliant mode # Make sure we don't hit the 65535 object member limit with MSVC # # /bigobj allows object files with more than 65535 members diff --git a/cpp/open3d/CMakeLists.txt b/cpp/open3d/CMakeLists.txt index e31bb2b83f3..00b04684b2c 100644 --- a/cpp/open3d/CMakeLists.txt +++ b/cpp/open3d/CMakeLists.txt @@ -89,6 +89,7 @@ target_sources(Open3D PRIVATE open3d_ispc_target_sources_TARGET_OBJECTS(Open3D PRIVATE camera core + core_impl data geometry tgeometry @@ -101,6 +102,7 @@ open3d_ispc_target_sources_TARGET_OBJECTS(Open3D PRIVATE tpipelines_kernel utility visualization + visualization_impl ) if (BUILD_GUI) diff --git a/cpp/open3d/core/CMakeLists.txt b/cpp/open3d/core/CMakeLists.txt index 7926d3fbcc6..c34cea3fc6d 100644 --- a/cpp/open3d/core/CMakeLists.txt +++ b/cpp/open3d/core/CMakeLists.txt @@ -41,22 +41,7 @@ target_sources(core PRIVATE hashmap/HashBackendBuffer.cpp hashmap/HashMap.cpp hashmap/HashSet.cpp - kernel/Arange.cpp - kernel/ArangeCPU.cpp - kernel/BinaryEW.cpp - kernel/BinaryEWCPU.cpp - kernel/IndexGetSet.cpp - kernel/IndexGetSetCPU.cpp - kernel/IndexReduction.cpp - kernel/IndexReductionCPU.cpp kernel/Kernel.cpp - kernel/NonZero.cpp - kernel/NonZeroCPU.cpp - kernel/Reduction.cpp - kernel/ReductionCPU.cpp - kernel/UnaryEW.cpp - kernel/UnaryEWCPU.cpp - kernel/UnaryEWSYCL.cpp linalg/AddMM.cpp linalg/AddMMCPU.cpp linalg/Det.cpp @@ -82,11 +67,33 @@ target_sources(core PRIVATE nns/NNSIndex.cpp ) +# core_impl contains the implementation of core functions that are not exposed in the public API +open3d_ispc_add_library(core_impl OBJECT) +set_target_properties(core_impl PROPERTIES CXX_VISIBILITY_PRESET "hidden") + +target_sources(core_impl PRIVATE + kernel/Arange.cpp + kernel/ArangeCPU.cpp + kernel/BinaryEW.cpp + kernel/BinaryEWCPU.cpp + kernel/IndexGetSet.cpp + kernel/IndexGetSetCPU.cpp + kernel/IndexReduction.cpp + kernel/IndexReductionCPU.cpp + kernel/NonZero.cpp + kernel/NonZeroCPU.cpp + kernel/Reduction.cpp + kernel/ReductionCPU.cpp + kernel/UnaryEW.cpp + kernel/UnaryEWCPU.cpp + kernel/UnaryEWSYCL.cpp +) + if (BUILD_CUDA_MODULE) target_sources(core PRIVATE MemoryManagerCUDA.cpp ) - target_sources(core PRIVATE + target_sources(core_impl PRIVATE hashmap/CUDA/CreateCUDAHashBackend.cu hashmap/CUDA/CUDAHashBackendBuffer.cu hashmap/CUDA/SlabNodeManager.cu @@ -116,6 +123,8 @@ endif() if (BUILD_ISPC_MODULE) target_sources(core PRIVATE Indexer.ispc + ) + target_sources(core_impl PRIVATE kernel/BinaryEWCPU.ispc kernel/UnaryEWCPU.ispc ) @@ -126,6 +135,12 @@ open3d_set_global_properties(core) open3d_set_open3d_lib_properties(core) open3d_link_3rdparty_libraries(core) +open3d_show_and_abort_on_warning(core_impl) +open3d_set_global_properties(core_impl) +open3d_set_open3d_lib_properties(core_impl) +open3d_link_3rdparty_libraries(core_impl) + if(BUILD_CUDA_MODULE) target_include_directories(core SYSTEM PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) + target_include_directories(core_impl SYSTEM PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) endif() diff --git a/cpp/open3d/geometry/SurfaceReconstructionBallPivoting.cpp b/cpp/open3d/geometry/SurfaceReconstructionBallPivoting.cpp index 994dbc6e8c8..2774b314364 100644 --- a/cpp/open3d/geometry/SurfaceReconstructionBallPivoting.cpp +++ b/cpp/open3d/geometry/SurfaceReconstructionBallPivoting.cpp @@ -17,6 +17,7 @@ namespace open3d { namespace geometry { +namespace { class BallPivotingVertex; class BallPivotingEdge; @@ -733,6 +734,7 @@ class BallPivoting { std::vector vertices; std::shared_ptr mesh_; }; +} // namespace std::shared_ptr TriangleMesh::CreateFromPointCloudBallPivoting( const PointCloud& pcd, const std::vector& radii) { diff --git a/cpp/open3d/geometry/SurfaceReconstructionPoisson.cpp b/cpp/open3d/geometry/SurfaceReconstructionPoisson.cpp index a1553d6a653..7195166701f 100644 --- a/cpp/open3d/geometry/SurfaceReconstructionPoisson.cpp +++ b/cpp/open3d/geometry/SurfaceReconstructionPoisson.cpp @@ -39,7 +39,7 @@ namespace open3d { namespace geometry { -namespace poisson { +namespace { // The order of the B-Spline used to splat in data for color interpolation static const int DATA_DEGREE = 0; @@ -713,7 +713,7 @@ void Execute(const open3d::geometry::PointCloud& pcd, Time() - startTime, FEMTree::MaxMemoryUsage()); } -} // namespace poisson +} // namespace std::tuple, std::vector> TriangleMesh::CreateFromPointCloudPoisson(const PointCloud& pcd, @@ -722,10 +722,9 @@ TriangleMesh::CreateFromPointCloudPoisson(const PointCloud& pcd, float scale, bool linear_fit, int n_threads) { - static const BoundaryType BType = poisson::DEFAULT_FEM_BOUNDARY; + static const BoundaryType BType = DEFAULT_FEM_BOUNDARY; typedef IsotropicUIntPack< - poisson::DIMENSION, - FEMDegreeAndBType::Signature> + DIMENSION, FEMDegreeAndBType::Signature> FEMSigs; if (!pcd.HasNormals()) { @@ -746,8 +745,8 @@ TriangleMesh::CreateFromPointCloudPoisson(const PointCloud& pcd, auto mesh = std::make_shared(); std::vector densities; - poisson::Execute(pcd, mesh, densities, static_cast(depth), - width, scale, linear_fit, FEMSigs()); + Execute(pcd, mesh, densities, static_cast(depth), width, scale, + linear_fit, FEMSigs()); ThreadPool::Terminate(); diff --git a/cpp/open3d/visualization/CMakeLists.txt b/cpp/open3d/visualization/CMakeLists.txt index fd794dcea24..8cf18c2088c 100644 --- a/cpp/open3d/visualization/CMakeLists.txt +++ b/cpp/open3d/visualization/CMakeLists.txt @@ -1,6 +1,9 @@ open3d_ispc_add_library(visualization OBJECT) -target_sources(visualization PRIVATE +open3d_ispc_add_library(visualization_impl OBJECT) +set_target_properties(visualization_impl PROPERTIES CXX_VISIBILITY_PRESET hidden) + +target_sources(visualization_impl PRIVATE shader/GeometryRenderer.cpp shader/ImageMaskShader.cpp shader/ImageShader.cpp @@ -62,14 +65,14 @@ if (BUILD_GUI) rendering/Renderer.cpp rendering/RendererHandle.cpp rendering/RotationInteractorLogic.cpp + rendering/filament/FilamentEngine.cpp + rendering/filament/FilamentRenderer.cpp ) - target_sources(visualization PRIVATE + target_sources(visualization_impl PRIVATE rendering/filament/FilamentCamera.cpp - rendering/filament/FilamentEngine.cpp rendering/filament/FilamentEntitiesMods.cpp rendering/filament/FilamentGeometryBuffersBuilder.cpp - rendering/filament/FilamentRenderer.cpp rendering/filament/FilamentRenderToBuffer.cpp rendering/filament/FilamentResourceManager.cpp rendering/filament/FilamentScene.cpp @@ -131,7 +134,7 @@ open3d_add_encoded_shader(shader # Source group for Visual Studio add_source_group(shader/glsl) -add_dependencies(visualization shader) +add_dependencies(visualization_impl shader) open3d_show_and_abort_on_warning(visualization) @@ -139,6 +142,11 @@ open3d_set_global_properties(visualization) open3d_set_open3d_lib_properties(visualization) open3d_link_3rdparty_libraries(visualization) +open3d_show_and_abort_on_warning(visualization_impl) +open3d_set_global_properties(visualization_impl) +open3d_set_open3d_lib_properties(visualization_impl) +open3d_link_3rdparty_libraries(visualization_impl) + # export GUI_RESOURCE_DIR to parent scope if (BUILD_GUI) set(GUI_RESOURCE_DIR ${GUI_RESOURCE_DIR} PARENT_SCOPE)