diff --git a/.github/workflows/Engine-CI.yml b/.github/workflows/Engine-CI.yml index fb2307c02..6c7741118 100644 --- a/.github/workflows/Engine-CI.yml +++ b/.github/workflows/Engine-CI.yml @@ -7,6 +7,7 @@ on: - 'ZEngine/**' - 'Tetragrama/**' - 'Obelisk/**' + - 'Runtime/**' - 'Resources/**' - 'Scripts/**' - 'tests/**' @@ -20,6 +21,7 @@ on: - 'ZEngine/**' - 'Tetragrama/**' - 'Obelisk/**' + - 'Runtime/**' - 'Resources/**' - 'Scripts/**' - 'tests/**' diff --git a/.github/workflows/job-clangformat.yml b/.github/workflows/job-clangformat.yml index 151b19ab8..8e4089fb6 100644 --- a/.github/workflows/job-clangformat.yml +++ b/.github/workflows/job-clangformat.yml @@ -24,5 +24,6 @@ jobs: ./Scripts/ClangFormat.ps1 -SourceDirectory (Join-Path $env:GITHUB_WORKSPACE 'ZEngine') -RunAsCheck ./Scripts/ClangFormat.ps1 -SourceDirectory (Join-Path $env:GITHUB_WORKSPACE 'Tetragrama') -RunAsCheck ./Scripts/ClangFormat.ps1 -SourceDirectory (Join-Path $env:GITHUB_WORKSPACE 'Obelisk') -RunAsCheck + ./Scripts/ClangFormat.ps1 -SourceDirectory (Join-Path $env:GITHUB_WORKSPACE 'Runtime') -RunAsCheck ./Scripts/ClangFormat.ps1 -SourceDirectory (Join-Path $env:GITHUB_WORKSPACE 'Resources/Shaders') -RunAsCheck shell: pwsh diff --git a/.github/workflows/job-cmakebuild-macOS.yml b/.github/workflows/job-cmakebuild-macOS.yml index 45d446dbf..750b86908 100644 --- a/.github/workflows/job-cmakebuild-macOS.yml +++ b/.github/workflows/job-cmakebuild-macOS.yml @@ -42,4 +42,5 @@ jobs: Result.Darwin.${{inputs.architecture}}.${{inputs.configuration}}/bin/ Result.Darwin.${{inputs.architecture}}.${{inputs.configuration}}/lib/*vulkan* Result.Darwin.${{inputs.architecture}}.${{inputs.configuration}}/lib/freetype.framework/** + Result.Darwin.${{inputs.architecture}}.${{inputs.configuration}}/Library/Frameworks/freetype.framework/** Result.Darwin.${{inputs.architecture}}.${{inputs.configuration}}/tests diff --git a/.github/workflows/job-cmakebuild-windows.yml b/.github/workflows/job-cmakebuild-windows.yml index 648591e01..0bed82b29 100644 --- a/.github/workflows/job-cmakebuild-windows.yml +++ b/.github/workflows/job-cmakebuild-windows.yml @@ -43,6 +43,7 @@ jobs: Result.Windows.x64.MultiConfig/tests/TetragramaTests.exe Result.Windows.x64.MultiConfig/tests/SceneDocumentProcess.exe Result.Windows.x64.MultiConfig/tests/SceneDocumentProcess.cmake + Result.Windows.x64.MultiConfig/tests/RuntimeCli.cmake Result.Windows.x64.MultiConfig/tests/SceneCookProcess.exe Result.Windows.x64.MultiConfig/tests/SceneCookProcess.cmake Result.Windows.x64.MultiConfig/tests/SceneCookStressProcess.cmake diff --git a/.github/workflows/job-test-linux.yml b/.github/workflows/job-test-linux.yml index 2c99b04b5..8ee985c6d 100644 --- a/.github/workflows/job-test-linux.yml +++ b/.github/workflows/job-test-linux.yml @@ -23,7 +23,12 @@ jobs: name: Build-linux-${{ inputs.configuration }} - name: Update test executable permissions - run: chmod +x ${{github.workspace}}/tests/ZEngineTests ${{github.workspace}}/tests/TetragramaTests ${{github.workspace}}/tests/SceneDocumentProcess ${{github.workspace}}/tests/SceneCookProcess ${{github.workspace}}/tests/SceneCookResourceProcess + run: chmod +x ${{github.workspace}}/bin/ZEngineRuntime ${{github.workspace}}/tests/ZEngineTests ${{github.workspace}}/tests/TetragramaTests ${{github.workspace}}/tests/SceneDocumentProcess ${{github.workspace}}/tests/SceneCookProcess ${{github.workspace}}/tests/SceneCookResourceProcess + + - name: Verify runtime command-line arguments + env: + LD_LIBRARY_PATH: ${{github.workspace}}/lib + run: cmake "-DRUNTIME_EXECUTABLE=${{github.workspace}}/bin/ZEngineRuntime" -P "${{github.workspace}}/tests/RuntimeCli.cmake" - name: Run Independent-Process Scene Tests env: diff --git a/.github/workflows/job-test-macOS.yml b/.github/workflows/job-test-macOS.yml index 14eb0ac82..4d8bd957d 100644 --- a/.github/workflows/job-test-macOS.yml +++ b/.github/workflows/job-test-macOS.yml @@ -23,7 +23,10 @@ jobs: name: Build-macOS-${{ inputs.architecture }}-${{ inputs.configuration }} - name: Update test executable permissions - run: chmod +x ${{github.workspace}}/tests/ZEngineTests ${{github.workspace}}/tests/TetragramaTests ${{github.workspace}}/tests/SceneDocumentProcess ${{github.workspace}}/tests/SceneCookProcess ${{github.workspace}}/tests/SceneCookResourceProcess + run: chmod +x ${{github.workspace}}/bin/ZEngineRuntime ${{github.workspace}}/tests/ZEngineTests ${{github.workspace}}/tests/TetragramaTests ${{github.workspace}}/tests/SceneDocumentProcess ${{github.workspace}}/tests/SceneCookProcess ${{github.workspace}}/tests/SceneCookResourceProcess + + - name: Verify runtime command-line arguments + run: cmake "-DRUNTIME_EXECUTABLE=${{github.workspace}}/bin/ZEngineRuntime" -P "${{github.workspace}}/tests/RuntimeCli.cmake" - name: Run Independent-Process Scene Tests run: cmake -P "${{github.workspace}}/tests/SceneDocumentProcess.cmake" diff --git a/.github/workflows/job-test-windows.yml b/.github/workflows/job-test-windows.yml index 699879136..dfbf92a5d 100644 --- a/.github/workflows/job-test-windows.yml +++ b/.github/workflows/job-test-windows.yml @@ -19,6 +19,12 @@ jobs: with: name: Build-Windows-x64-${{ inputs.configuration }} + - name: Verify runtime command-line arguments + shell: pwsh + run: | + $env:PATH = "${{github.workspace}}\lib;$env:PATH" + cmake "-DRUNTIME_EXECUTABLE=${{github.workspace}}/bin/ZEngineRuntime.exe" -P "${{github.workspace}}/tests/RuntimeCli.cmake" + - name: Run Independent-Process Scene Tests shell: pwsh run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 787ceddea..b234b89f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ include(Scripts/CMake/LoggingDefaults.cmake) include(Scripts/CMake/MacOSCodeSign.cmake) option (ZENGINE_TRACY "Enable Tracy profiler" OFF) +option (ZENGINE_BUILD_EDITOR "Build the editor and editor application" ON) set (MACOSX_ARCHITECTURE_ARM64 OFF) if (APPLE) @@ -70,10 +71,10 @@ add_subdirectory (Resources) # add_subdirectory (ZEngine) -# Editor is here -# -add_subdirectory (Tetragrama) +# Runtime has no editor dependency. +add_subdirectory (Runtime) -# Entry point is here -# -add_subdirectory (Obelisk) +if(ZENGINE_BUILD_EDITOR) + add_subdirectory (Tetragrama) + add_subdirectory (Obelisk) +endif() diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt new file mode 100644 index 000000000..3a0a74fb9 --- /dev/null +++ b/Runtime/CMakeLists.txt @@ -0,0 +1,43 @@ +add_executable(ZEngineRuntime) +target_sources(ZEngineRuntime PRIVATE EntryPoint.cpp) +target_link_libraries(ZEngineRuntime PRIVATE zEngineLib CLI11::CLI11) +target_compile_definitions(ZEngineRuntime PRIVATE NOMINMAX UNICODE _UNICODE) +# Use an explicit per-configuration output directory so asset copying can run +# before the executable without a target-file dependency cycle. +if(CMAKE_CONFIGURATION_TYPES) + set(_runtime_output_dir "${CMAKE_CURRENT_BINARY_DIR}/$") +else() + set(_runtime_output_dir "${CMAKE_CURRENT_BINARY_DIR}") +endif() +set_target_properties(ZEngineRuntime PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${_runtime_output_dir}") +add_custom_target(ZEngineRuntimeAssets + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/Resources/Editor/Settings" "${_runtime_output_dir}/ZodiacEngine/Settings" + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/Resources/Shaders/Cache" "${_runtime_output_dir}/ZodiacEngine/Shaders/Cache" + DEPENDS CompileShaders + VERBATIM) +add_dependencies(ZEngineRuntime ZEngineRuntimeAssets) + +if(APPLE) + set_target_properties(ZEngineRuntime PROPERTIES INSTALL_RPATH "@loader_path/../lib;@loader_path/../Library/Frameworks") +elseif(UNIX) + set_target_properties(ZEngineRuntime PROPERTIES INSTALL_RPATH "$ORIGIN/../lib") +endif() +install(TARGETS ZEngineRuntime DESTINATION bin) +zengine_sign_installed_target(ZEngineRuntime bin) + +if(BUILD_TESTING) + install(FILES tests/RuntimeCli.cmake DESTINATION tests) + add_test(NAME RuntimeCLI.StartupArguments + COMMAND ${CMAKE_COMMAND} "-DRUNTIME_EXECUTABLE=$" + -P "${CMAKE_CURRENT_SOURCE_DIR}/tests/RuntimeCli.cmake") +endif() + +option(ZENGINE_ENABLE_RUNTIME_DESKTOP_TESTS "Register editor-free runtime Vulkan smoke tests" OFF) +if(BUILD_TESTING AND ZENGINE_ENABLE_RUNTIME_DESKTOP_TESTS) + find_package(Python3 REQUIRED COMPONENTS Interpreter) + add_test(NAME RuntimeDesktop.CookedStartupAndFailures + COMMAND "${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tests/scene/cooked_scene_smoke.py" + --cooker "$" --obelisk "$" + --standalone --runtime-camera main --failure-cases --audit-source --require-validation) + set_tests_properties(RuntimeDesktop.CookedStartupAndFailures PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE LABELS "runtime;scene;desktop") +endif() diff --git a/Runtime/EntryPoint.cpp b/Runtime/EntryPoint.cpp new file mode 100644 index 000000000..1d2fceb0c --- /dev/null +++ b/Runtime/EntryPoint.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ZEngine; +using namespace ZEngine::Applications; +using namespace ZEngine::Core::Memory; +using namespace ZEngine::CrashHandlers; +using namespace ZEngine::Logging; + +/// @brief Run the renderer-only application using a cooked scene package. +static int RunRuntime(int argc, char* argv[]) +{ + CLI::App cli{"ZEngine standalone runtime"}; + argv = cli.ensure_utf8(argv); + std::string package, scene, camera, log_directory; + bool standalone = false, exit_after_frame = false, audit_source = false; + uint32_t expected_draws = 0; + cli.add_option("--cookedPackage", package, "Cooked package directory")->required(); + cli.add_option("--cookedScene", scene, "Startup scene UUID")->required(); + cli.add_option("--cookedCamera", camera, "Authored camera UUID"); + cli.add_option("--logDirectory", log_directory, "Output directory for logs"); + cli.add_flag("--cookedStandalone", standalone, "Use the standalone runtime"); + cli.add_flag("--cookedExitAfterFrame", exit_after_frame, "Exit after the first scene frame"); + cli.add_flag("--cookedAuditSource", audit_source, "Audit source access during a test run"); + cli.add_option("--cookedExpectedDraws", expected_draws, "Expected draw count in a test run"); + CLI11_PARSE(cli, argc, argv); + + const auto scene_id = uuids::uuid::from_string(scene); + const auto camera_id = camera.empty() ? std::optional{} : uuids::uuid::from_string(camera); + if (!scene_id || scene_id->is_nil() || (!camera.empty() && (!camera_id || camera_id->is_nil())) || ((audit_source || expected_draws) && !exit_after_frame)) + { + std::fprintf(stderr, "A non-nil scene UUID is required; camera UUID and test options must be valid.\n"); + return 2; + } + + const auto executable_directory = Core::GetExecutablePath().parent_path(); + const auto crash_directory = (executable_directory / "CrashDumps").string(); + CrashHandler::Install("ZEngineRuntime", "1.0.0", crash_directory.c_str()); + MemoryManager memory = {}; + // The runtime scene loader currently shares the editor scene-load arena profile. + memory.Initialize(ZGiga(8ULL), MemoryBudgetConfig::Editor()); +#if ZENGINE_PROFILING + Profiling::MemoryProfiler::Initialize(&memory.BootstrapArena); + Profiling::MemoryProfiler::TrackArena("Bootstrap", &memory.BootstrapArena); +#endif + Helpers::ThreadPoolHelper::Initialize(); + ArenaAllocator logger_arena = {}; + LoggerConfiguration logger_config = {}; + logger_config.OutputDirectory = log_directory.empty() ? (executable_directory / "Logs").string() : log_directory; + logger_config.CrashLogDir = crash_directory; + memory.CreateBudgetedArena(memory.Budget.Logging, &logger_arena); + Logger::Initialize(&logger_arena, logger_config); + CrashHandler::SetPreCrashCallback([](void*) { + Logger::FlushRingBufferToCrashLog(); + Logger::Flush(); + }); + + auto* app = ZPushStructCtor(&memory.BootstrapArena); + app->Configure(package, *scene_id, camera_id.value_or(uuids::uuid{}), exit_after_frame, expected_draws); + if (audit_source) + app->EnableSourceIndependenceAudit(); + app->Initialize(&memory); + app->Run(); + const bool frame_recorded = !exit_after_frame || app->FrameRecorded(); + const bool failed = app->Failed(); + app->Shutdown(); + const bool audit_passed = !audit_source || app->SourceAuditPassed(); + Logger::Flush(); + Logger::Dispose(); + app->OnClosed(); + memory.Shutdown(); + CrashHandler::Uninstall(); + return frame_recorded && !failed && audit_passed ? 0 : 2; +} + +#ifdef _WIN32 +#include +#include +int main(int argc, char* argv[]) +{ + winrt::init_apartment(); + return RunRuntime(argc, argv); +} +#else +int main(int argc, char* argv[]) +{ + return RunRuntime(argc, argv); +} +#endif diff --git a/Runtime/README.md b/Runtime/README.md new file mode 100644 index 000000000..f43f7e25c --- /dev/null +++ b/Runtime/README.md @@ -0,0 +1,27 @@ +# Editor-free runtime + +`ZEngineRuntime` is a renderer-only executable linked to `zEngineLib`; it does +not link the Tetragrama editor. Configure with `-DZENGINE_BUILD_EDITOR=OFF` to +omit the editor and its Obelisk entry point from the build. Build the +`ZEngineRuntime` target. The build copies engine settings and compiled shaders +into `ZodiacEngine` next to the executable and refreshes them on subsequent builds. + +Launch it with a cooked package and startup scene UUID: + +``` +ZEngineRuntime --cookedPackage /path/to/package --cookedScene +``` + +The scene must contain exactly one main camera, unless `--cookedCamera` selects +one explicitly. The package must already exist; creating a user-facing cooking +and export workflow is separate work. Simulation is disabled. The current +runtime shares the existing scene-loading memory profile, including the arenas +currently named for the editor. + +To register the desktop Vulkan smoke test, configure with +`-DZENGINE_ENABLE_RUNTIME_DESKTOP_TESTS=ON`, build `ZEngineRuntime` and +`SceneCookProcess`, and run `ctest -R RuntimeDesktop --output-on-failure`. +The test requires a desktop GPU and Vulkan validation layer. + +The `RuntimeCLI.StartupArguments` CTest checks command-line validation without +a desktop GPU. Build `ZEngineRuntime` before running it. diff --git a/Runtime/tests/RuntimeCli.cmake b/Runtime/tests/RuntimeCli.cmake new file mode 100644 index 000000000..7ca6b898a --- /dev/null +++ b/Runtime/tests/RuntimeCli.cmake @@ -0,0 +1,24 @@ +if(NOT EXISTS "${RUNTIME_EXECUTABLE}") + message(FATAL_ERROR "Runtime executable is missing: ${RUNTIME_EXECUTABLE}") +endif() + +execute_process(COMMAND "${RUNTIME_EXECUTABLE}" --help + RESULT_VARIABLE help_result OUTPUT_VARIABLE help_output ERROR_VARIABLE help_error) +if(NOT help_result EQUAL 0 OR NOT help_output MATCHES "--cookedPackage" OR NOT help_output MATCHES "--cookedScene") + message(FATAL_ERROR "Runtime help failed (${help_result}): ${help_error}") +endif() + +foreach(scene IN ITEMS "not-a-uuid" "00000000-0000-0000-0000-000000000000") + execute_process(COMMAND "${RUNTIME_EXECUTABLE}" --cookedPackage unused --cookedScene "${scene}" + RESULT_VARIABLE invalid_result OUTPUT_VARIABLE invalid_output ERROR_VARIABLE invalid_error) + if(NOT invalid_result EQUAL 2 OR NOT invalid_error MATCHES "non-nil scene UUID") + message(FATAL_ERROR "Invalid scene '${scene}' was not rejected (${invalid_result}): ${invalid_output} ${invalid_error}") + endif() +endforeach() + +execute_process(COMMAND "${RUNTIME_EXECUTABLE}" --cookedPackage unused + --cookedScene 10000000-0000-0000-0000-000000000001 --cookedAuditSource + RESULT_VARIABLE audit_result OUTPUT_VARIABLE audit_output ERROR_VARIABLE audit_error) +if(NOT audit_result EQUAL 2 OR NOT audit_error MATCHES "test options must be valid") + message(FATAL_ERROR "Invalid audit options were not rejected (${audit_result}): ${audit_output} ${audit_error}") +endif() diff --git a/Scripts/hooks/pre-push b/Scripts/hooks/pre-push index 16b894c05..0a317950b 100755 --- a/Scripts/hooks/pre-push +++ b/Scripts/hooks/pre-push @@ -11,7 +11,7 @@ if ! command -v pwsh > /dev/null 2>&1; then fi FAILED=0 -for DIR in ZEngine Tetragrama Obelisk Resources/Shaders; do +for DIR in ZEngine Tetragrama Obelisk Runtime Resources/Shaders; do echo "[pre-push] Checking clang-format: $DIR ..." pwsh -NonInteractive -NoProfile -File \ "$REPO_ROOT/Scripts/ClangFormat.ps1" \ @@ -28,6 +28,7 @@ if [ $FAILED -ne 0 ]; then echo " pwsh Scripts/ClangFormat.ps1 -SourceDirectory ZEngine" echo " pwsh Scripts/ClangFormat.ps1 -SourceDirectory Tetragrama" echo " pwsh Scripts/ClangFormat.ps1 -SourceDirectory Obelisk" + echo " pwsh Scripts/ClangFormat.ps1 -SourceDirectory Runtime" echo " pwsh Scripts/ClangFormat.ps1 -SourceDirectory Resources/Shaders" echo "" exit 1 diff --git a/Tetragrama/CMakeLists.txt b/Tetragrama/CMakeLists.txt index ff8ec6e8e..0bb0ab28c 100644 --- a/Tetragrama/CMakeLists.txt +++ b/Tetragrama/CMakeLists.txt @@ -38,4 +38,6 @@ target_compile_definitions(Tetragrama target_link_libraries(Tetragrama PUBLIC zEngineLib) -add_subdirectory(tests) +if(BUILD_TESTING) + add_subdirectory(tests) +endif() diff --git a/ZEngine/CMakeLists.txt b/ZEngine/CMakeLists.txt index 929e9d82e..60be94532 100644 --- a/ZEngine/CMakeLists.txt +++ b/ZEngine/CMakeLists.txt @@ -13,4 +13,6 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON) set (CMAKE_CXX_STANDARD 20) add_subdirectory (ZEngine) -add_subdirectory (tests) +if(BUILD_TESTING) + add_subdirectory (tests) +endif() diff --git a/ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.cpp b/ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.cpp index ffe7c8167..40b311990 100644 --- a/ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.cpp +++ b/ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.cpp @@ -1045,6 +1045,11 @@ namespace ZEngine::Applications return m_staging_refusal_observed; } + bool StandaloneRuntimeApplication::Failed() const noexcept + { + return m_failed; + } + bool StandaloneRuntimeApplication::FrameRecorded() const noexcept { return m_frame_recorded; diff --git a/ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.h b/ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.h index be7349457..4f819a0dc 100644 --- a/ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.h +++ b/ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.h @@ -71,6 +71,8 @@ namespace ZEngine::Applications [[nodiscard]] bool ShutdownProbePassed() const noexcept; /// @brief Report whether the staging refusal probe observed its failure. [[nodiscard]] bool StagingRefusalObserved() const noexcept; + /// @brief Report whether runtime scene startup or replacement failed. + [[nodiscard]] bool Failed() const noexcept; /// @brief Report whether the requested scene frame was recorded. [[nodiscard]] bool FrameRecorded() const noexcept; /// @brief Set the output path for the optional scene-target capture.