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
39 changes: 38 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function print_help {
echo " This is sometimes needed instead of -c (which still misses some clean steps)."
echo " -d"
echo " Enable matdbg."
echo " -t"
echo " Enable fgviewer."
echo " -f"
echo " Always invoke CMake before incremental builds."
echo " -g"
Expand Down Expand Up @@ -125,6 +127,27 @@ function print_matdbg_help {
echo ""
}

function print_fgviewer_help {
echo "fgviewer is enabled in the build, but some extra steps are needed."
echo ""
echo "FOR DESKTOP BUILDS:"
echo ""
echo "Please set the port environment variable before launching. e.g., on macOS do:"
echo " export FILAMENT_FGVIEWER_PORT=8085"
echo ""
echo "FOR ANDROID BUILDS:"
echo ""
echo "1) For Android Studio builds, make sure to set:"
echo " -Pcom.google.android.filament.fgviewer"
echo " option in Preferences > Build > Compiler > Command line options."
echo ""
echo "2) The port number is hardcoded to 8085 so you will need to do:"
echo " adb forward tcp:8085 tcp:8085"
echo ""
echo "3) Be sure to enable INTERNET permission in your app's manifest file."
echo ""
}

# Unless explicitly specified, NDK version will be selected as highest available version within same major release chain
FILAMENT_NDK_VERSION=${FILAMENT_NDK_VERSION:-$(cat `dirname $0`/build/android/ndk.version | cut -f 1 -d ".")}

Expand Down Expand Up @@ -172,6 +195,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 +264,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 +401,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 +639,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 @@ -802,7 +829,7 @@ function check_debug_release_build {

pushd "$(dirname "$0")" > /dev/null

while getopts ":hacCfgijmp:q:uvslwedk:bx:S:X:" opt; do
while getopts ":hacCfgijmp:q:uvslwedtk:bx:S:X:" opt; do
case ${opt} in
h)
print_help
Expand All @@ -823,6 +850,12 @@ while getopts ":hacCfgijmp:q:uvslwedk:bx:S:X:" opt; do
MATDBG_OPTION="-DFILAMENT_ENABLE_MATDBG=ON, -DFILAMENT_BUILD_FILAMAT=ON"
MATDBG_GRADLE_OPTION="-Pcom.google.android.filament.matdbg"
;;
t)
# TODO: Uncomment below when fgviewer is ready
# PRINT_FGVIEWER_HELP=true
# FGVIEWER_OPTION="-DFILAMENT_ENABLE_FGVIEWER=ON"
#FGVIEWER_GRADLE_OPTION="-Pcom.google.android.filament.fgviewer"
;;
f)
ISSUE_CMAKE_ALWAYS=true
;;
Expand Down Expand Up @@ -1027,3 +1060,7 @@ fi
if [[ "${PRINT_MATDBG_HELP}" == "true" ]]; then
print_matdbg_help
fi

if [[ "${PRINT_FGVIEWER_HELP}" == "true" ]]; then
print_fgviewer_help
fi
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)
88 changes: 88 additions & 0 deletions libs/fgviewer/include/fgviewer/DebugServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2024 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 <utils/Mutex.h>

#include <unordered_map>
#include <vector>

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:
CivetServer* mServer;

std::unordered_map<FrameGraphInfoKey, FrameGraphInfo> mViews;
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
Loading
Loading