Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .github/workflows/Engine-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 'ZEngine/**'
- 'Tetragrama/**'
- 'Obelisk/**'
- 'Runtime/**'
- 'Resources/**'
- 'Scripts/**'
- 'tests/**'
Expand All @@ -20,6 +21,7 @@ on:
- 'ZEngine/**'
- 'Tetragrama/**'
- 'Obelisk/**'
- 'Runtime/**'
- 'Resources/**'
- 'Scripts/**'
- 'tests/**'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/job-clangformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .github/workflows/job-cmakebuild-macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .github/workflows/job-cmakebuild-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/job-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/job-test-macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/job-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
43 changes: 43 additions & 0 deletions Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}/$<CONFIG>")
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=$<TARGET_FILE:ZEngineRuntime>"
-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 "$<TARGET_FILE:SceneCookProcess>" --obelisk "$<TARGET_FILE:ZEngineRuntime>"
--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()
98 changes: 98 additions & 0 deletions Runtime/EntryPoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <CLI/CLI.hpp>
#include <ZEngine/Applications/StandaloneRuntimeApplication.h>
#include <ZEngine/Core/EngineAssetRoot.h>
#include <ZEngine/Core/Memory/MemoryManager.h>
#include <ZEngine/CrashHandlers/CrashHandler.h>
#include <ZEngine/Helpers/ThreadPool.h>
#include <ZEngine/Logging/Logger.h>
#include <ZEngine/Profiling/MemoryProfiler.h>
#include <cstdio>
#include <filesystem>
#include <optional>

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>{} : 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<StandaloneRuntimeApplication>(&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 <windows.h>
#include <winrt/Windows.Foundation.h>
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
27 changes: 27 additions & 0 deletions Runtime/README.md
Original file line number Diff line number Diff line change
@@ -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 <scene-uuid>
```

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.
24 changes: 24 additions & 0 deletions Runtime/tests/RuntimeCli.cmake
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 2 additions & 1 deletion Scripts/hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Tetragrama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ target_compile_definitions(Tetragrama

target_link_libraries(Tetragrama PUBLIC zEngineLib)

add_subdirectory(tests)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
4 changes: 3 additions & 1 deletion ZEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 5 additions & 0 deletions ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ZEngine/ZEngine/Applications/StandaloneRuntimeApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading