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

Upgrade To Latest Filament #6511

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions 3rdparty/filament/filament_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ endif()
set(filament_LIBRARIES
filameshio
filament
filamat_lite
filamat
filaflat
filabridge
geometry
backend
bluegl
bluevk
ibl
image
ktxreader
meshoptimizer
smol-v
utils
vkshaders
)

# Locate byproducts
Expand All @@ -52,8 +53,8 @@ endif()
ExternalProject_Add(
ext_filament
PREFIX filament
URL https://github.com/isl-org/filament/archive/d1d873d27f43ba0cee1674a555cc0f18daac3008.tar.gz
URL_HASH SHA256=00c3f41af0fcfb2df904e1f77934f2678d943ddac5eb889788a5e22590e497bd
URL https://github.com/google/filament/archive/refs/tags/v1.49.1.tar.gz
URL_HASH SHA256=f092aeb1d24d9d84a3cc2327fc3359a5e2893d16e7ac55aab9a56aaae64e121f
DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/filament"
UPDATE_COMMAND ""
CMAKE_ARGS
Expand All @@ -69,7 +70,7 @@ ExternalProject_Add(
-DCMAKE_INSTALL_PREFIX=${FILAMENT_ROOT}
-DUSE_STATIC_CRT=${STATIC_WINDOWS_RUNTIME}
-DUSE_STATIC_LIBCXX=ON
-DFILAMENT_SUPPORTS_VULKAN=OFF
-DFILAMENT_SKIP_SDL2=ON
-DFILAMENT_SKIP_SAMPLES=ON
-DFILAMENT_OPENGL_HANDLE_ARENA_SIZE_IN_MB=20 # to support many small entities
BUILD_BYPRODUCTS ${lib_byproducts}
Expand Down
34 changes: 15 additions & 19 deletions 3rdparty/filament/filament_download.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(FetchContent)

set(filament_LIBRARIES filameshio filament filamat_lite filaflat filabridge geometry backend bluegl bluevk ibl image meshoptimizer smol-v utils vkshaders)
set(filament_LIBRARIES filameshio filament filaflat filabridge geometry backend bluegl bluevk ibl image ktxreader meshoptimizer smol-v utils vkshaders)

if (FILAMENT_PRECOMPILED_ROOT)
if (EXISTS "${FILAMENT_PRECOMPILED_ROOT}")
Expand All @@ -13,43 +13,38 @@ else()
set(lib_dir lib)
# Setup download links
if(WIN32)
set(FILAMENT_URL https://github.com/google/filament/releases/download/v1.9.9/filament-v1.9.9-windows.tgz)
set(FILAMENT_SHA256 3a937a54a0c6b693c833737878761f8ba8ee02744be3c2f9ec33b1c6399ba31b)
# Required for filament v1.9.9
# Older versions of filament do not contain vkshaders.
# They also have a different directory structure.
# Remove vkshaders here so we can use newer versions with FILAMENT_PRECOMPILED_ROOT.
list(REMOVE_ITEM filament_LIBRARIES vkshaders)
set(FILAMENT_URL https://github.com/google/filament/releases/download/v1.49.1/filament-v1.49.1-windows.tgz)
set(FILAMENT_SHA256 afbd43c106f14065c6672923e51a6bfd7ea0d87d404df62b4b6c29c81d078d2d)
if (STATIC_WINDOWS_RUNTIME)
string(APPEND lib_dir /x86_64/mt)
else()
string(APPEND lib_dir /x86_64/md)
endif()
elseif(APPLE)
set(FILAMENT_URL https://github.com/google/filament/releases/download/v1.9.19/filament-v1.9.19-mac.tgz)
set(FILAMENT_SHA256 2765d0ce60647fc17d1880c4618cf7d6b5343d8be4dad87978c3917d9c723b4e)
string(APPEND lib_dir /x86_64)
set(FILAMENT_URL https://github.com/google/filament/releases/download/v1.49.1/filament-v1.49.1-mac.tgz)
set(FILAMENT_SHA256 e7d02060d264f40b365251bebf6a4f4ed5602182cdae429b28ab419277ebc5e7)
else() # Linux: Check glibc version and use open3d filament binary if new (Ubuntu 20.04 and similar)
execute_process(COMMAND ldd --version OUTPUT_VARIABLE ldd_version)
string(REGEX MATCH "([0-9]+\.)+[0-9]+" glibc_version ${ldd_version})
if(${glibc_version} VERSION_LESS "2.31")
if(${glibc_version} VERSION_LESS "2.33")
set(FILAMENT_URL
https://github.com/isl-org/open3d_downloads/releases/download/filament/filament-v1.9.19-linux.tgz)
set(FILAMENT_SHA256 f0c0b05a543dd0c82b1cd571957a90f28e72cfeee36d19a527c17ac9de4733d5)
https://github.com/isl-org/open3d_downloads/releases/download/filament/filament-v1.49.1-ubuntu20.04.tgz)
set(FILAMENT_SHA256 f4ba020f0ca63540e2f86b36d1728a1ea063ddd5eb55b0ba6fc621ee815a60a7)
message(STATUS "GLIBC version ${glibc_version} found: Using "
"Google Filament binary.")
"Open3D built Filament binary for Ubuntu 20.04.")
else()
set(FILAMENT_URL
https://github.com/isl-org/open3d_downloads/releases/download/filament/filament-v1.9.19-linux-20.04.tgz)
set(FILAMENT_SHA256 c756fd76f5c6a40ca554f8c3cca424354a2a22ea6fce3c8ea893d4c4aa39514c)
set(FILAMENT_URL
https://github.com/google/filament/releases/download/v1.49.1/filament-v1.49.1-linux.tgz)
set(FILAMENT_SHA256 ddd086310d1ee650831e21f6a11f489cb385826fbeea446e7803bec8d6e7442b)
message(STATUS "GLIBC version ${glibc_version} found: Using "
"Open3D Filament binary.")
"Google Filament binary.")
endif()
endif()

set(lib_byproducts ${filament_LIBRARIES})
list(TRANSFORM lib_byproducts PREPEND <SOURCE_DIR>/${lib_dir}/${CMAKE_STATIC_LIBRARY_PREFIX})
list(TRANSFORM lib_byproducts APPEND ${CMAKE_STATIC_LIBRARY_SUFFIX})
message(STATUS "Filament byproducts: ${lib_byproducts}")

if(WIN32)
set(lib_byproducts_debug ${filament_LIBRARIES})
Expand All @@ -73,6 +68,7 @@ else()
BUILD_BYPRODUCTS ${lib_byproducts}
)
ExternalProject_Get_Property(ext_filament SOURCE_DIR)
message(STATUS "Filament source dir is ${SOURCE_DIR}")
set(FILAMENT_ROOT ${SOURCE_DIR})
endif()

Expand Down
1 change: 1 addition & 0 deletions 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,7 @@ if(BUILD_GUI)
endif()
endif()
endif()
set(FILAMENT_RUNTIME_VER x86_64)
if (APPLE)
if (APPLE_AARCH64)
set(FILAMENT_RUNTIME_VER arm64)
Expand Down
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,9 @@ if(BUILD_SYCL_MODULE AND BUILD_CUDA_MODULE)
message(FATAL_ERROR "BUILD_SYCL_MODULE and BUILD_SYCL_MODULE cannot be on at the same time for now.")
endif()

# Global flag to set CXX standard.
# This does not affect 3rd party libraries.
# Tensorflow 2.9+ requires cxx_17, but MSVC 19.29 throws errors with C++17
# enabled.
if (BUILD_SYCL_MODULE OR BUILD_TENSORFLOW_OPS)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
if (MSVC)
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_EXTENSIONS OFF) # Improved compatibility

Expand Down Expand Up @@ -461,6 +456,10 @@ if(WIN32)
#
# See: https://github.com/tensorflow/tensorflow/pull/10962
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/bigobj;/Ob2>")

# Suppress deprecation warnings that become errors for features depcrecated in
# C++20 that we still use.
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/D_SILENCE_CXX20_IS_POD_DEPRECATION_WARNING>")
endif()
if (STATIC_WINDOWS_RUNTIME)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Expand Down
2 changes: 1 addition & 1 deletion cmake/Open3DAddCompiledMaterials.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function(open3d_add_compiled_materials target)
if (IOS OR ANDROID)
set(FILAMENT_MATC_ARGS "--platform=mobile")
else()
set(FILAMENT_MATC_ARGS "--platform=desktop")
set(FILAMENT_MATC_ARGS "--api=all")
endif()

get_filename_component(OUTPUT_DIRECTORY_FULL_PATH "${ARG_OUTPUT_DIRECTORY}" ABSOLUTE)
Expand Down
6 changes: 3 additions & 3 deletions cpp/open3d/visualization/gui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ struct Application::Impl {
InitWindowSystem();

// Initialize rendering
visualization::rendering::EngineInstance::SelectBackend(
visualization::rendering::EngineInstance::RenderingType::
kOpenGL);
// NOTE: This is where we used to manually select a backend for Filament
// but we feel comfortable now allowing Filament to select the best
// backend for the platform so there's no code here anymore
}

void CleanupAfterRunning() {
Expand Down
11 changes: 1 addition & 10 deletions cpp/open3d/visualization/gui/BitmapWindowSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,7 @@ struct BitmapWindowSystem::Impl {
};

BitmapWindowSystem::BitmapWindowSystem(Rendering mode /*= Rendering::NORMAL*/)
: impl_(new BitmapWindowSystem::Impl()) {
if (mode == Rendering::HEADLESS) {
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(_WIN64)
rendering::EngineInstance::EnableHeadless();
#else
utility::LogWarning(
"BitmapWindowSystem(): HEADLESS is only supported on Linux.");
#endif
}
}
: impl_(new BitmapWindowSystem::Impl()) {}

BitmapWindowSystem::~BitmapWindowSystem() {}

Expand Down
1 change: 1 addition & 0 deletions cpp/open3d/visualization/gui/BitmapWindowSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct TextInputEvent;

class BitmapWindowSystem : public WindowSystem {
public:
// Not needed anymore - may be removed
enum class Rendering {
NORMAL, // normal OpenGL rendering, requires X11, Win32, or Cocoa
HEADLESS // uses EGL, does not require the OS to have a window system.
Expand Down
22 changes: 12 additions & 10 deletions cpp/open3d/visualization/gui/GLFWWindowSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,18 @@ GLFWWindowSystem::OSWindow GLFWWindowSystem::CreateOSWindow(Window* o3d_window,
int height,
const char* title,
int flags) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// NOTE: Setting alpha and stencil bits to match GLX standard default
// values. GLFW sets these internally to 8 and 8 respectively if not
// specified which causes problems with Filament on Linux with Nvidia binary
// driver
glfwWindowHint(GLFW_ALPHA_BITS, 0);
glfwWindowHint(GLFW_STENCIL_BITS, 0);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// // NOTE: Setting alpha and stencil bits to match GLX standard default
// // values. GLFW sets these internally to 8 and 8 respectively if not
// // specified which causes problems with Filament on Linux with Nvidia
// binary
// // driver
// glfwWindowHint(GLFW_ALPHA_BITS, 0);
// glfwWindowHint(GLFW_STENCIL_BITS, 0);

#if __APPLE__
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE);
Expand Down
15 changes: 10 additions & 5 deletions cpp/open3d/visualization/gui/ImguiFilamentBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
* limitations under the License.
*/

// clang-format off
// NOTE: this must precede header files that bring in Filament headers
#include <cstring>
// clang-format on

#include "open3d/visualization/gui/ImguiFilamentBridge.h"

// 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags
Expand All @@ -38,18 +43,18 @@
#include <filament/TransformManager.h>
#include <utils/EntityManager.h>

#include <cerrno>
#include <iostream>
#include <map>
#include <vector>

#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER

#include <fcntl.h>
#include <imgui.h>

#include <cerrno>
#include <iostream>
#include <map>
#include <vector>

#include "open3d/utility/FileSystem.h"
#include "open3d/visualization/gui/Application.h"
#include "open3d/visualization/gui/Color.h"
Expand Down
1 change: 0 additions & 1 deletion cpp/open3d/visualization/gui/Materials/img_blit.mat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
vec2 uv = getUV0();
uv.y = 1.0 - uv.y;
/* OpenGL spec 8.4.4.4 says that texture().a is 1.0 if there
is no alpha channel, so this shader can handle both RGB and RGBA
images */
Expand Down
1 change: 1 addition & 0 deletions cpp/open3d/visualization/gui/SceneWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <imgui.h>

#include <Eigen/Geometry>
#include <cstring>
#include <set>
#include <unordered_set>

Expand Down
25 changes: 14 additions & 11 deletions cpp/open3d/visualization/rendering/filament/FilamentCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ Camera::Transform FilamentToCameraTransform(const filament::math::mat4& ft) {
return Camera::Transform(m);
}

Camera::Transform FilamentToCameraTransform(const filament::math::mat4f& ft) {
Camera::Transform::MatrixType m;

m << ft(0, 0), ft(0, 1), ft(0, 2), ft(0, 3), ft(1, 0), ft(1, 1), ft(1, 2),
ft(1, 3), ft(2, 0), ft(2, 1), ft(2, 2), ft(2, 3), ft(3, 0),
ft(3, 1), ft(3, 2), ft(3, 3);

return Camera::Transform(m);
}
// Camera::Transform FilamentToCameraTransform(const filament::math::mat4f& ft)
// {
// Camera::Transform::MatrixType m;
//
// m << ft(0, 0), ft(0, 1), ft(0, 2), ft(0, 3), ft(1, 0), ft(1, 1), ft(1,
// 2),
// ft(1, 3), ft(2, 0), ft(2, 1), ft(2, 2), ft(2, 3), ft(3, 0),
// ft(3, 1), ft(3, 2), ft(3, 3);
//
// return Camera::Transform(m);
// }

filament::math::mat4f CameraToFilamentTransformF(const Camera::Transform& t) {
auto e_matrix = t.matrix();
Expand Down Expand Up @@ -240,7 +242,8 @@ void FilamentCamera::LookAt(const Eigen::Vector3f& center,

Eigen::Vector3f FilamentCamera::GetPosition() const {
auto cam_pos = camera_->getPosition();
return {cam_pos.x, cam_pos.y, cam_pos.z};
return {static_cast<float>(cam_pos.x), static_cast<float>(cam_pos.y),
static_cast<float>(cam_pos.z)};
}

Eigen::Vector3f FilamentCamera::GetForwardVector() const {
Expand Down Expand Up @@ -314,7 +317,7 @@ void FilamentCamera::SetModelMatrix(const Eigen::Vector3f& forward,
const Eigen::Vector3f& up) {
using namespace filament;

math::mat4f ftransform = camera_->getModelMatrix();
math::mat4 ftransform = camera_->getModelMatrix();
ftransform[0].xyz = math::float3(left.x(), left.y(), left.z());
ftransform[1].xyz = math::float3(up.x(), up.y(), up.z());
ftransform[2].xyz = math::float3(forward.x(), forward.y(), forward.z());
Expand Down
19 changes: 1 addition & 18 deletions cpp/open3d/visualization/rendering/filament/FilamentEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ static std::shared_ptr<EngineInstance> g_instance = nullptr;
} // namespace

EngineInstance::RenderingType EngineInstance::type_ = RenderingType::kDefault;
bool EngineInstance::is_headless_ = false;
std::string EngineInstance::resource_path_ = "";

void EngineInstance::SelectBackend(RenderingType type) { type_ = type; }

void EngineInstance::EnableHeadless() { is_headless_ = true; }

void EngineInstance::SetResourcePath(const std::string& resource_path) {
resource_path_ = resource_path;
if (!utility::filesystem::DirectoryExists(resource_path_)) {
Expand Down Expand Up @@ -74,10 +71,6 @@ EngineInstance& EngineInstance::Get() {

void EngineInstance::DestroyInstance() { g_instance.reset(); }

/// external function defined in custom Filament EGL backend for headless
/// rendering
extern "C" filament::backend::Platform* CreateEGLHeadlessPlatform();

EngineInstance::EngineInstance() {
filament::backend::Backend backend = filament::backend::Backend::DEFAULT;
switch (type_) {
Expand All @@ -95,17 +88,7 @@ EngineInstance::EngineInstance() {
break;
}

filament::backend::Platform* custom_platform = nullptr;
if (is_headless_) {
#ifdef __linux__
utility::LogInfo("EGL headless mode enabled.");
custom_platform = CreateEGLHeadlessPlatform();
#else
utility::LogError("EGL Headless is not supported on this platform.");
#endif
}

engine_ = filament::Engine::create(backend, custom_platform);
engine_ = filament::Engine::create(backend);
resource_manager_ = new FilamentResourceManager(*engine_);
}

Expand Down
5 changes: 0 additions & 5 deletions cpp/open3d/visualization/rendering/filament/FilamentEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class EngineInstance {
// If not called, platform available default backend will be used.
static void SelectBackend(RenderingType type);

/// Initialize Engine for headless rendering. Must be called before first
/// access to the Engine (GetInstance).
static void EnableHeadless();

// Specifies path to load shaders and skyboxes from. Must be called before
// instance usage, or default path will be used.
static void SetResourcePath(const std::string& resource_path);
Expand All @@ -53,7 +49,6 @@ class EngineInstance {
EngineInstance();

static RenderingType type_;
static bool is_headless_;
static std::string resource_path_;
filament::Engine* engine_;
FilamentResourceManager* resource_manager_;
Expand Down
Loading
Loading