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

Add skeleton code of fgviewer #8303

Merged
merged 12 commits into from
Dec 20, 2024
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,14 @@ else()
option(FILAMENT_BUILD_FILAMAT "Build filamat and JNI buildings" OFF)
endif()

# By default, link in matdbg for Desktop + Debug only since it pulls in filamat and a web server.
# By default, link in matdbg/fgviewer for Desktop + Debug only since it pulls in filamat and a web server.
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND IS_HOST_PLATFORM)
option(FILAMENT_ENABLE_MATDBG "Enable the material debugger" ON)
# TODO: Uncomment below when fgviewer is ready
# option(FILAMENT_ENABLE_FGVIEWER "Enable the frame graph viewer" ON)
else()
option(FILAMENT_ENABLE_MATDBG "Enable the material debugger" OFF)
option(FILAMENT_ENABLE_FGVIEWER "Enable the frame graph viewer" OFF)
endif()

# Only optimize materials in Release mode (so error message lines match the source code)
Expand Down Expand Up @@ -778,6 +781,11 @@ if (FILAMENT_BUILD_FILAMAT OR IS_HOST_PLATFORM)
if (FILAMENT_ENABLE_MATDBG OR IS_HOST_PLATFORM)
add_subdirectory(${LIBRARIES}/matdbg)
endif()

# TODO: Uncomment below when fgviewer is ready
# if (FILAMENT_ENABLE_FGVIEWER OR IS_HOST_PLATFORM)
# add_subdirectory(${LIBRARIES}/fgviewer)
# endif()
endif()

if (FILAMENT_SUPPORTS_VULKAN)
Expand Down
10 changes: 10 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// com.google.android.filament.exclude-vulkan
// When set, support for Vulkan will be excluded.
//
// com.google.android.filament.fgviewer
// When set, enables fgviewer
//
// com.google.android.filament.matdbg
// When set, enables matdbg
//
Expand Down Expand Up @@ -61,6 +64,11 @@ buildscript {
.gradleProperty("com.google.android.filament.exclude-vulkan")
.isPresent()

// TODO: Uncomment below when fgviewer is ready
// def fgviewer = providers
// .gradleProperty("com.google.android.filament.fgviewer")
// .isPresent()

def matdbg = providers
.gradleProperty("com.google.android.filament.matdbg")
.isPresent()
Expand Down Expand Up @@ -115,6 +123,8 @@ buildscript {
"-DANDROID_STL=c++_static",
"-DFILAMENT_DIST_DIR=${filamentPath}".toString(),
"-DFILAMENT_SUPPORTS_VULKAN=${excludeVulkan ? 'OFF' : 'ON'}".toString(),
// TODO: Uncomment below when fgviewer is ready
// "-DFILAMENT_ENABLE_FGVIEWER=${fgviewer ? 'ON' : 'OFF'}".toString(),
"-DFILAMENT_ENABLE_MATDBG=${matdbg ? 'ON' : 'OFF'}".toString(),
"-DFILAMENT_DISABLE_MATOPT=${matnopt ? 'ON' : 'OFF'}".toString()
]
Expand Down
11 changes: 11 additions & 0 deletions android/filament-android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.19)
project(filament-android)

option(FILAMENT_SUPPORTS_VULKAN "Enables Vulkan on Android" OFF)
# TODO: Uncomment below when fgviewer is ready
# option(FILAMENT_ENABLE_FGVIEWER "Enables Frame Graph Viewer" OFF)
option(FILAMENT_ENABLE_MATDBG "Enables Material debugger" OFF)
option(FILAMENT_DISABLE_MATOPT "Disables material optimizations" OFF)

Expand Down Expand Up @@ -51,6 +53,13 @@ add_library(smol-v STATIC IMPORTED)
set_target_properties(smol-v PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libsmol-v.a)

# TODO: Uncomment below when fgviewer is ready
# if (FILAMENT_ENABLE_FGVIEWER)
# add_library(fgviewer STATIC IMPORTED)
# set_target_properties(fgviewer PROPERTIES IMPORTED_LOCATION
# ${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfgviewer.a)
# endif()

if (FILAMENT_ENABLE_MATDBG)
add_library(matdbg STATIC IMPORTED)
set_target_properties(matdbg PROPERTIES IMPORTED_LOCATION
Expand Down Expand Up @@ -117,6 +126,8 @@ target_link_libraries(filament-jni
# libgeometry is PUBLIC because gltfio uses it.
PUBLIC geometry

# TODO: Uncomment below when fgviewer is ready
# $<$<STREQUAL:${FILAMENT_ENABLE_FGVIEWER},ON>:fgviewer>
$<$<STREQUAL:${FILAMENT_ENABLE_MATDBG},ON>:matdbg>
$<$<STREQUAL:${FILAMENT_ENABLE_MATDBG},ON>:filamat>
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:bluevk>
Expand Down
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ VULKAN_ANDROID_GRADLE_OPTION=""
EGL_ON_LINUX_OPTION="-DFILAMENT_SUPPORTS_EGL_ON_LINUX=OFF"

MATDBG_OPTION="-DFILAMENT_ENABLE_MATDBG=OFF"
FGVIEWER_OPTION="-DFILAMENT_ENABLE_FGVIEWER=OFF"
MATDBG_GRADLE_OPTION=""

MATOPT_OPTION=""
Expand Down Expand Up @@ -240,6 +241,7 @@ function build_desktop_target {
-DCMAKE_BUILD_TYPE="$1" \
-DCMAKE_INSTALL_PREFIX="../${lc_target}/filament" \
${EGL_ON_LINUX_OPTION} \
${FGVIEWER_OPTION} \
${MATDBG_OPTION} \
${MATOPT_OPTION} \
${ASAN_UBSAN_OPTION} \
Expand Down Expand Up @@ -376,6 +378,7 @@ function build_android_target {
-DFILAMENT_NDK_VERSION="${FILAMENT_NDK_VERSION}" \
-DCMAKE_INSTALL_PREFIX="../android-${lc_target}/filament" \
-DCMAKE_TOOLCHAIN_FILE="../../build/toolchain-${arch}-linux-android.cmake" \
${FGVIEWER_OPTION} \
${MATDBG_OPTION} \
${MATOPT_OPTION} \
${VULKAN_ANDROID_OPTION} \
Expand Down Expand Up @@ -613,6 +616,7 @@ function build_ios_target {
-DPLATFORM_NAME="${platform}" \
-DIOS=1 \
-DCMAKE_TOOLCHAIN_FILE=../../third_party/clang/iOS.cmake \
${FGVIEWER_OPTION} \
${MATDBG_OPTION} \
${MATOPT_OPTION} \
${STEREOSCOPIC_OPTION} \
Expand Down Expand Up @@ -820,6 +824,8 @@ while getopts ":hacCfgijmp:q:uvslwedk:bx:S:X:" opt; do
;;
d)
PRINT_MATDBG_HELP=true
# TODO: Uncomment below when fgviewer is ready
# FGVIEWER_OPTION="-DFILAMENT_ENABLE_FGVIEWER=ON"
show50726 marked this conversation as resolved.
Show resolved Hide resolved
MATDBG_OPTION="-DFILAMENT_ENABLE_MATDBG=ON, -DFILAMENT_BUILD_FILAMAT=ON"
MATDBG_GRADLE_OPTION="-Pcom.google.android.filament.matdbg"
;;
Expand Down
7 changes: 7 additions & 0 deletions filament/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,13 @@ target_link_libraries(${TARGET} PUBLIC filaflat)
target_link_libraries(${TARGET} PUBLIC filabridge)
target_link_libraries(${TARGET} PUBLIC ibl-lite)

if (FILAMENT_ENABLE_FGVIEWER)
target_link_libraries(${TARGET} PUBLIC fgviewer)
add_definitions(-DFILAMENT_ENABLE_FGVIEWER=1)
else()
add_definitions(-DFILAMENT_ENABLE_FGVIEWER=0)
endif()

if (FILAMENT_ENABLE_MATDBG)
target_link_libraries(${TARGET} PUBLIC matdbg)
add_definitions(-DFILAMENT_ENABLE_MATDBG=1)
Expand Down
71 changes: 71 additions & 0 deletions libs/fgviewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 3.19)
project(fgviewer C ASM)

set(TARGET fgviewer)
set(PUBLIC_HDR_DIR include)

if (CMAKE_CROSSCOMPILING)
include(${IMPORT_EXECUTABLES})
endif()

# ==================================================================================================
# Sources and headers
# ==================================================================================================

set(PUBLIC_HDRS
include/fgviewer/DebugServer.h
include/fgviewer/JsonWriter.h
)

set(SRCS
src/ApiHandler.cpp
src/ApiHandler.h
src/DebugServer.cpp
)

# ==================================================================================================
# Include and target definitions
# ==================================================================================================

include_directories(${PUBLIC_HDR_DIR})

add_library(${TARGET} STATIC ${PUBLIC_HDRS} ${SRCS})

target_link_libraries(${TARGET} PUBLIC
civetweb
utils
)

target_include_directories(${TARGET} PRIVATE ${filamat_SOURCE_DIR}/src)

target_include_directories(${TARGET} PUBLIC ${PUBLIC_HDR_DIR})
set_target_properties(${TARGET} PROPERTIES FOLDER Libs)

# ==================================================================================================
# Compiler flags
# ==================================================================================================

if (MSVC)
else()
target_compile_options(${TARGET} PRIVATE -Wno-deprecated-register)
endif()

# ==================================================================================================
# Installation
# ==================================================================================================

# matdbg has dependencies on non-installed libraries. Here we bundle them all together into a single
# library that gets copied into the installation folder so users are only required to link against
# matdbg.
set(FGVIEWER_DEPS
fgviewer
civetweb
)

set(FGVIEWER_COMBINED_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libfgviewer_combined.a")
combine_static_libs(fgviewer "${FGVIEWER_COMBINED_OUTPUT}" "${FGVIEWER_DEPS}")

set(FGVIEWER_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}fgviewer${CMAKE_STATIC_LIBRARY_SUFFIX})
install(FILES "${FGVIEWER_COMBINED_OUTPUT}" DESTINATION lib/${DIST_DIR} RENAME ${FGVIEWER_LIB_NAME})
# We do not need fgviewer headers in the install directory
# install(DIRECTORY ${PUBLIC_HDR_DIR}/fgviewer DESTINATION include)
90 changes: 90 additions & 0 deletions libs/fgviewer/include/fgviewer/DebugServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FGVIEWER_DEBUGSERVER_H
#define FGVIEWER_DEBUGSERVER_H

#include <utils/CString.h>

#include <tsl/robin_map.h>
#include <utils/Mutex.h>

class CivetServer;

namespace filament::fgviewer {

using FrameGraphInfoKey = uint32_t;

struct FrameGraphPassInfo {
utils::CString pass_name;
// TODO: Add struct detail properties
};

struct FrameGraphInfo {
utils::CString view_name;
std::vector<FrameGraphPassInfo> passes;
};

/**
* Server-side frame graph debugger.
*
* This class manages an HTTP server. It receives frame graph packages from the Filament C++ engine or
* from a standalone tool such as fginfo.
*/
class DebugServer {
public:
static std::string_view const kSuccessHeader;
static std::string_view const kErrorHeader;

DebugServer(int port);
~DebugServer();

/**
* Notifies the debugger that a new view has been added.
*/
void addView(const utils::CString& name, FrameGraphInfo info);

/**
* Notifies the debugger that the given view has been deleted.
*/
void removeView(const utils::CString& name);

/**
* Updates the information for a given view.
*/
void updateView(const utils::CString& name, FrameGraphInfo info);

bool isReady() const { return mServer; }

private:
static FrameGraphInfoKey getKeybyString(const utils::CString &input,
uint32_t seed);

CivetServer* mServer;

tsl::robin_map<FrameGraphInfoKey, FrameGraphInfo> mViews;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we use robin_map in a lot of places, but we're thinking about moving away from it enventually. So for this, I would just suggest to stuck to the std::unordered_map, it's probably fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.
BTW, I'm wondering what's the different between using these two classes? And why do we want to use robin_map at the beginning?

mutable utils::Mutex mViewsMutex;

class FileRequestHandler* mFileHandler = nullptr;
class ApiHandler* mApiHandler = nullptr;

friend class FileRequestHandler;
friend class ApiHandler;
};

} // namespace filament::fgviewer

#endif // FGVIEWER_DEBUGSERVER_H
47 changes: 47 additions & 0 deletions libs/fgviewer/include/fgviewer/JsonWriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2019 The Android Open Source Project
show50726 marked this conversation as resolved.
Show resolved Hide resolved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FGVIEWER_JSONWRITER_H
#define FGVIEWER_JSONWRITER_H

#include <utils/CString.h>

namespace filament {
show50726 marked this conversation as resolved.
Show resolved Hide resolved
namespace fgviewer {

struct FrameGraphInfo;

// This class generates portions of JSON messages that are sent to the web client.
// Note that some portions of these JSON strings are generated by directly in DebugServer,
// as well as CommonWriter.
class JsonWriter {
public:

// Retrieves the most recently generated string.
const char* getJsonString() const;
size_t getJsonSize() const;

// Generates a JSON string describing the given FrameGraphInfo.
bool writeFrameGraphInfo(const FrameGraphInfo& frameGraph);

private:
utils::CString mJsonString;
};

} // namespace fgviewer
} // namespace filament

#endif // FGVIEWER_JSONWRITER_H
Loading
Loading