diff --git a/.github/overlays/x264/allow-clang-cl.patch b/.github/overlays/x264/allow-clang-cl.patch new file mode 100644 index 000000000..c4fe44ddb --- /dev/null +++ b/.github/overlays/x264/allow-clang-cl.patch @@ -0,0 +1,15 @@ +diff --git a/configure b/configure +index 6f95e2314..e677e36f4 100644 +--- a/configure ++++ b/configure +@@ -606,9 +606,9 @@ if [[ $host_os = mingw* || $host_os = msys* || $host_os = cygwin* ]]; then + if cc_check '' -Qdiag-error:10006,10157 ; then + CHECK_CFLAGS="$CHECK_CFLAGS -Qdiag-error:10006,10157" + fi +- elif [[ "$cc_base" = cl || "$cc_base" = cl[\ .]* ]]; then ++ elif [[ "$cc_base" = cl || "$cc_base" = cl[\ .]* || "$cc_base" = clang-cl || "$cc_base" = clang-cl[\ .]* ]]; then + # Standard Microsoft Visual Studio + compiler=CL + compiler_style=MS + CFLAGS="$CFLAGS -nologo -GS- -DHAVE_STRING_H -I\$(SRCPATH)/extras" + cpp_check '' '' '_MSC_VER > 1800 || (_MSC_VER == 1800 && _MSC_FULL_VER >= 180030324)' || die "Microsoft Visual Studio support requires Visual Studio 2013 Update 2 or newer" diff --git a/.github/overlays/x264/configure.patch b/.github/overlays/x264/configure.patch new file mode 100644 index 000000000..788a1a51e --- /dev/null +++ b/.github/overlays/x264/configure.patch @@ -0,0 +1,40 @@ +diff --git a/configure b/configure +index e242e73c..e0d1df76 100755 +--- a/configure ++++ b/configure +@@ -1,4 +1,7 @@ +-#!/bin/bash ++#!/usr/bin/env bash ++ ++export CFLAGS="${CPPFLAGS} ${CFLAGS}" ++test "${AS:-:}" = ":" && unset AS + + if test x"$1" = x"-h" -o x"$1" = x"--help" ; then + cat <> config.mak +- echo 'install: install-cli' >> config.mak ++ echo 'install:' >> config.mak ++ echo ' $(MAKE) install-cli' >> config.mak + fi + + if [ "$shared" = "yes" ]; then diff --git a/.github/overlays/x264/portfile.cmake b/.github/overlays/x264/portfile.cmake new file mode 100644 index 000000000..ada2a4e93 --- /dev/null +++ b/.github/overlays/x264/portfile.cmake @@ -0,0 +1,133 @@ +# The latest ref in branch stable +set(ref 31e19f92f00c7003fa115047ce50978bc98c3a0d) + +# Note on x264 versioning: +# The pc file exports "0.164." where is the number of commits. +# The binary releases on https://artifacts.videolan.org/x264/ are named x264-r-. +# With a git clone, this can be determined by running `versions.sh`. +# With vcpkg_from_gitlab, we modify `versions.sh` accordingly. +# For --editable mode, use configured patch instead of vcpkg_replace_string. +string(REGEX MATCH "^......." short_ref "${ref}") +string(REGEX MATCH "[0-9]+$" revision "${VERSION}") +configure_file("${CURRENT_PORT_DIR}/version.diff.in" "${CURRENT_BUILDTREES_DIR}/src/version-${VERSION}.diff" @ONLY) + +vcpkg_from_gitlab( + GITLAB_URL https://code.videolan.org/ + OUT_SOURCE_PATH SOURCE_PATH + REPO videolan/x264 + REF "${ref}" + SHA512 707ff486677a1b5502d6d8faa588e7a03b0dee45491c5cba89341be4be23d3f2e48272c3b11d54cfc7be1b8bf4a3dfc3c3bb6d9643a6b5a2ed77539c85ecf294 + HEAD_REF master + PATCHES + "${CURRENT_BUILDTREES_DIR}/src/version-${VERSION}.diff" + uwp-cflags.patch + parallel-install.patch + allow-clang-cl.patch + configure.patch + srcpath-relative-path.patch +) + +function(add_cross_prefix) + if(configure_env MATCHES "CC=([^/]*)-gcc$") + vcpkg_list(APPEND arg_OPTIONS "--cross-prefix=${CMAKE_MATCH_1}") + endif() + set(arg_OPTIONS "${arg_OPTIONS}" PARENT_SCOPE) +endfunction() + +set(nasm_archs x86 x64) +set(gaspp_archs arm arm64) +if(NOT "asm" IN_LIST FEATURES) + vcpkg_list(APPEND OPTIONS --disable-asm) +elseif(NOT "$ENV{AS}" STREQUAL "") + # Accept setting from triplet +elseif(VCPKG_TARGET_ARCHITECTURE IN_LIST nasm_archs) + vcpkg_find_acquire_program(NASM) + vcpkg_insert_program_into_path("${NASM}") + set(ENV{AS} "${NASM}") +elseif(VCPKG_TARGET_ARCHITECTURE IN_LIST gaspp_archs AND VCPKG_TARGET_IS_WINDOWS AND VCPKG_HOST_IS_WINDOWS) + vcpkg_find_acquire_program(GASPREPROCESSOR) + list(FILTER GASPREPROCESSOR INCLUDE REGEX gas-preprocessor) + file(INSTALL "${GASPREPROCESSOR}" DESTINATION "${SOURCE_PATH}/tools" RENAME "gas-preprocessor.pl") +endif() + +vcpkg_list(SET OPTIONS_RELEASE) +if("tool" IN_LIST FEATURES) + vcpkg_list(APPEND OPTIONS_RELEASE --enable-cli) +else() + vcpkg_list(APPEND OPTIONS_RELEASE --disable-cli) +endif() + +if("chroma-format-all" IN_LIST FEATURES) + vcpkg_list(APPEND OPTIONS --chroma-format=all) +endif() + +if(NOT "gpl" IN_LIST FEATURES) + vcpkg_list(APPEND OPTIONS --disable-gpl) +endif() + +if(VCPKG_TARGET_IS_UWP) + list(APPEND OPTIONS --extra-cflags=-D_WIN32_WINNT=0x0A00) +endif() + +vcpkg_make_configure( + SOURCE_PATH "${SOURCE_PATH}" + DISABLE_CPPFLAGS # Build is not using CPP/CPPFLAGS + DISABLE_MSVC_WRAPPERS + LANGUAGES ASM C CXX # Requires NASM to compile + DISABLE_MSVC_TRANSFORMATIONS # disable warnings about unknown -Xcompiler/-Xlinker flags + PRE_CONFIGURE_CMAKE_COMMANDS + add_cross_prefix + OPTIONS + ${OPTIONS} + --enable-pic + --disable-lavf + --disable-swscale + --disable-avs + --disable-ffms + --disable-gpac + --disable-lsmash + --disable-bashcompletion + OPTIONS_RELEASE + ${OPTIONS_RELEASE} + --enable-strip + "--bindir=\\${prefix}/bin" + OPTIONS_DEBUG + --enable-debug + --disable-cli + "--bindir=\\${prefix}/bin" +) + +vcpkg_make_install() + +if("tool" IN_LIST FEATURES) + vcpkg_copy_tools(TOOL_NAMES x264 AUTO_CLEAN) +endif() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/lib/pkgconfig/x264.pc" "-lx264" "-llibx264") + if(NOT VCPKG_BUILD_TYPE) + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/x264.pc" "-lx264" "-llibx264") + endif() +endif() + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" AND VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) + file(RENAME "${CURRENT_PACKAGES_DIR}/lib/libx264.dll.lib" "${CURRENT_PACKAGES_DIR}/lib/libx264.lib") + if (NOT VCPKG_BUILD_TYPE) + file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/libx264.dll.lib" "${CURRENT_PACKAGES_DIR}/debug/lib/libx264.lib") + endif() + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/x264.h" "#ifdef X264_API_IMPORTS" "#if 1") +elseif(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/x264.h" "defined(U_STATIC_IMPLEMENTATION)" "1" IGNORE_UNCHANGED) + file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/bin" + "${CURRENT_PACKAGES_DIR}/debug/bin" + ) +endif() + +vcpkg_fixup_pkgconfig() + +vcpkg_copy_pdbs() + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") diff --git a/.github/overlays/x264/srcpath-relative-path.patch b/.github/overlays/x264/srcpath-relative-path.patch new file mode 100644 index 000000000..06a0f672f --- /dev/null +++ b/.github/overlays/x264/srcpath-relative-path.patch @@ -0,0 +1,28 @@ +diff --git a/configure b/configure +index 36c4f7af..8c01ca2b 100755 +--- a/configure ++++ b/configure +@@ -345,16 +345,20 @@ rm -rf conftest* + # Construct a path to the specified directory relative to the working directory + relative_path() { + local base="${PWD%/}" +- local path="$(cd "$1" >/dev/null; printf '%s/.' "${PWD%/}")" ++ local path="$(cd "$1" >/dev/null; printf '%s' "${PWD%/}")" + local up='' + +- while [[ $path != "$base/"* ]]; do ++ while [[ $path != "$base" && $path != "$base/"* ]]; do + base="${base%/*}" + up="../$up" + done + +- dirname "$up${path#"$base/"}" ++ if [[ $path = "$base" ]]; then ++ printf '.\n' ++ else ++ printf '%s\n' "$up${path#"$base/"}" ++ fi + } + + SRCPATH="$(relative_path "$(dirname "$0")")" + echo "$SRCPATH" | grep -q ' ' && die "Out of tree builds are impossible with whitespace in source path." diff --git a/.github/overlays/x264/uwp-cflags.patch b/.github/overlays/x264/uwp-cflags.patch new file mode 100644 index 000000000..792e99927 --- /dev/null +++ b/.github/overlays/x264/uwp-cflags.patch @@ -0,0 +1,12 @@ +diff --git a/configure b/configure +index f7b14d9..2c92b2a 100644 +--- a/configure ++++ b/configure +@@ -821,7 +821,6 @@ if [ $SYS = WINDOWS ]; then + if cpp_check "winapifamily.h" "" "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)" ; then + [ $compiler = CL ] || die "WinRT requires MSVC" + define HAVE_WINRT +- CFLAGS="$CFLAGS -MD" + LDFLAGS="$LDFLAGS -appcontainer" + if ! cpp_check "" "" "defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603" ; then + die "_WIN32_WINNT must be defined to at least 0x0603 (Windows 8.1) for WinRT" diff --git a/.github/overlays/x264/vcpkg.json b/.github/overlays/x264/vcpkg.json new file mode 100644 index 000000000..1a9b14f80 --- /dev/null +++ b/.github/overlays/x264/vcpkg.json @@ -0,0 +1,41 @@ +{ + "name": "x264", + "version": "0.164.3108", + "port-version": 2, + "description": "x264 is a free software library and application for encoding video streams into the H.264/MPEG-4 AVC compression format", + "homepage": "https://www.videolan.org/developers/x264.html", + "license": "GPL-2.0-or-later", + "supports": "!xbox", + "dependencies": [ + { + "name": "vcpkg-make", + "host": true + } + ], + "default-features": [ + { + "name": "asm", + "platform": "!(arm32 & windows)" + }, + { + "name": "gpl", + "platform": "!(arm32 & windows)" + } + ], + "features": { + "asm": { + "description": "Enable platform-specific assembly optimizations", + "supports": "!(arm32 & windows)" + }, + "chroma-format-all": { + "description": "Output all chroma formats" + }, + "gpl": { + "description": "Allow use of GPL code, the resulting libs and binaries will be under GPL" + }, + "tool": { + "description": "Build the command line tool", + "supports": "!uwp" + } + } +} diff --git a/.github/overlays/x264/version.diff.in b/.github/overlays/x264/version.diff.in new file mode 100644 index 000000000..3f13fda68 --- /dev/null +++ b/.github/overlays/x264/version.diff.in @@ -0,0 +1,15 @@ +diff --git a/version.sh b/version.sh +index 178fc952..06728796 100755 +--- a/version.sh ++++ b/version.sh +@@ -3,8 +3,8 @@ + cd "$(dirname "$0")" >/dev/null && [ -f x264.h ] || exit 1 + + api="$(grep '#define X264_BUILD' < x264.h | sed 's/^.* \([1-9][0-9]*\).*$/\1/')" +-ver="x" +-version="" ++ver="@revision@ @short_ref@" ++version=" r${ver} vcpkg" + + if [ -d .git ] && command -v git >/dev/null 2>&1 ; then + localver="$(($(git rev-list HEAD | wc -l)))" diff --git a/docs/building_and_distribution.md b/docs/building_and_distribution.md index 54041dbfc..cc73367d5 100644 --- a/docs/building_and_distribution.md +++ b/docs/building_and_distribution.md @@ -34,7 +34,10 @@ Builds for your GPU only. Fastest compile time. ```bash cmake -B build cmake --build build -j 16 -./build/LichtFeld-Studio -d data/test +./build/LichtFeld-Studio --help + +# Example training run +./build/LichtFeld-Studio -d /path/to/data -o /path/to/output ``` ### 2. Portable Build (Distribution) @@ -46,7 +49,10 @@ cmake -B build -DBUILD_PORTABLE=ON cmake --build build -j 16 cmake --install build --prefix ./dist -./dist/bin/run_lichtfeld.sh -d data/test +./dist/bin/run_lichtfeld.sh --help + +# Example training run +./dist/bin/run_lichtfeld.sh -d /path/to/data -o /path/to/output ``` ## What's the Difference? diff --git a/src/visualizer/window/window_manager.cpp b/src/visualizer/window/window_manager.cpp index fa6d3a024..edb099d79 100644 --- a/src/visualizer/window/window_manager.cpp +++ b/src/visualizer/window/window_manager.cpp @@ -8,6 +8,7 @@ #include "input/input_controller.hpp" #include "input/sdl_key_mapping.hpp" #include +#include #include #include #include @@ -75,6 +76,30 @@ namespace lfs::vis { return false; } + bool containsToken(const char* const haystack, const char* const needle) { + return haystack && needle && std::strstr(haystack, needle) != nullptr; + } + + bool shouldPreferX11OnGnome() { +#if defined(__linux__) + // GNOME on Wayland can present undecorated SDL toplevels when the + // compositor expects client-side decorations but libdecor is not + // available at runtime. Prefer X11/Xwayland in that case so the + // native min/max/close buttons remain available. + const char* const current_desktop = std::getenv("XDG_CURRENT_DESKTOP"); + const char* const session_desktop = std::getenv("XDG_SESSION_DESKTOP"); + const bool is_gnome = containsToken(current_desktop, "GNOME") || + containsToken(session_desktop, "gnome") || + containsToken(session_desktop, "GNOME"); + const bool has_wayland = std::getenv("WAYLAND_DISPLAY") != nullptr; + const bool has_x11 = std::getenv("DISPLAY") != nullptr; + const bool explicit_driver = std::getenv("SDL_VIDEO_DRIVER") != nullptr; + return is_gnome && has_wayland && has_x11 && !explicit_driver; +#else + return false; +#endif + } + void reportSdlVideoInitFailure() { std::cerr << "Failed to initialize SDL: " << SDL_GetError() << std::endl; @@ -121,11 +146,20 @@ namespace lfs::vis { } bool WindowManager::init() { + if (shouldPreferX11OnGnome()) { + SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "x11,wayland"); + LOG_INFO("GNOME Wayland session detected; preferring X11/Xwayland for native window decorations"); + } + if (!SDL_Init(SDL_INIT_VIDEO)) { reportSdlVideoInitFailure(); return false; } + if (const char* const video_driver = SDL_GetCurrentVideoDriver(); video_driver) { + LOG_INFO("SDL video driver: {}", video_driver); + } + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);