CLAUDE

Chuck Smith edited this page 2026-11-25 01:11:11 +00:00 · 1 commit

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Primal — notes for Claude

Primal is a C++ game engine (D3D12 + Vulkan) with a C# WPF editor. This repo is Charles Smith's ("Chuck") fork of Arash Khatami's Primal. Work is done on two machines: Linux (CachyOS, AMD RX 6800 XT, clang 23 / GCC 16, CMake + Ninja, Vulkan) and Windows (Visual Studio / MSBuild, D3D12 + Vulkan, the editor). Claude's memory is per machine, so this file and Docs/ are the shared state: keep them current as work goes.

Where things are

  • Docs/LinuxVulkanPort.md: the port plan (done 2026-11-08) and the "Open items" list. Open items A is the next-Windows-session checklist and B is known bugs. Read its "Start here" paragraph first.
  • Forgejo issues are the backlog (migrated from Docs/Tickets/ on 2026-11-10, from Gitea to Forgejo on 2026-11-16): https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal/issues. The old gitea. address redirects; Gitea tokens don't work. The token file keeps its old name.
    • T01–T21 are issues #1–#21, with the old Tnn — title prefix. #25 (pinned) is the suggested order.
    • Labels: area/*, priority/*, size/*, bug, needs-windows-check, roadmap.
    • Read and update them through the API (/api/v1/repos/UnflavoredMeson/Primal/issues) with the token in ~/.config/primal-gitea-token (Authorization: token …; each machine needs its own copy of the file). Never print the token. The repo is public, so the issues are too: no personal paths or hostnames in them.
    • Add new ideas as new issues. Record progress as a comment or a body edit, and close an issue when it is done.
  • Docs/Multithreading.md: the design for the job system and logging (issues #1 and #19), with what each step did and measured.
  • Docs/RendererThreading.md: the renderer's frame and threading model for #3 (step 8 of #1).
  • Docs/Renderer.md: #3's plan (one renderer for both backends: duplication measured, option A decided, the renderer reading the ECS components, order of work, the user's decisions).
  • Docs/Math.md: the math library evaluation for #6 (benchmarks, recommendation, decisions).
  • Docs/Ecs.md: the ECS for #31 (benchmarks, the user's decisions, the in-engine prototype); the rest is #52.
  • Docs/Actors.md: the actor model for #59 (editor-first: prefabs, actors with typed parts and behaviors on top of the ECS, how they interact, decisions for the user).
  • Docs/Reflection.md: scripts and components declaring themselves and their fields for #41 + #52 step 3 (prototype, compile times, recommendation, decisions).
  • Docs/CSharpScripting.md: the CoreCLR experiment for #47 (hosting, C# scripts in the frame phases and #41's tables, interop cost, GC, hot reload, decisions).
  • Docs/LinuxVulkanPortSteps.md: a commit-by-commit rebuild of port phases 0–5. The user may redo these steps themselves.
  • Docs/VulkanPortDrivers/: scripted test drivers from Phase 6.
  • Tools/CI/ and .forgejo/workflows/: CI on Forgejo Actions (Tools/CI/README.md; the Linux jobs are listed at the top of ci.sh; publish-image.sh publishes the image; WindowsRunner.md is the Windows runner, a VM the user runs since 2026-11-17).
  • Tools/WinVM/: the Windows 11 development VM (issue #37; KVM, driven over SSH): winvm.sh sync copies the working tree to C:\primal, winvm.sh run '<PowerShell>' runs there (Invoke-MSBuild, Invoke-Interactive for GUI programs). Use it for Windows checks that don't need the real GPU (D3D12 runs on WARP); reboot for performance and visual checks. winvm.sh screenshot shows the VM's own screen, never the host desktop. Complete since 2026-11-13: all four configurations + 8 EngineTest variants build, D3D12 runs on WARP, Vulkan on lavapipe (Invoke-GuiProgram runs the GUI tests). winvm.sh shutdown at the end of the day; winvm.sh revert clean-2026-11-13 restores the provisioned state. The FBX SDK isn't used any more (#38: ufbx); the VM's C:\winvm\baseline\ holds the SDK-built ContentTools.dll and C:\winvm\fbx\ the SDK's sample files, for comparisons.
  • Tools/WindowsCompileDb/: compile databases that let clang-tidy check Windows-only code on Linux. The README covers setup and lessons learned.
  • Tools/EditorAutomation/EditorUi.psm1: drives the WPF editor through UI Automation (Windows PowerShell 5.1): open a project, click, read the log panel. Tools/DebugOutput/Capture-DebugOutput.ps1: runs a Windows program under the debugging API and prints its OutputDebugString output (CRT leak report, D3D12 live objects). Usage in the files.
  • Code areas:
    • Engine/: the engine.
    • Engine/ECS/: the entity component system (#31; Ecs.h API, World.cpp core).
    • Engine/Graphics/Direct3D12, Engine/Graphics/Vulkan: one module per D3D12 module.
    • Engine/Graphics/Shaders: the shared HLSL.
    • EngineDLL/: the C API the editor calls.
    • ContentTools/: asset import. Windows-only except geometry processing and FBX import (ufbx), which CMake builds as the static library ContentTools for UnitTests.
    • EngineTest/: four interactive test programs (entity components, window, surfaces, renderer).
    • UnitTests/: the automated tests that need no window or GPU (doctest). One executable.
    • GraphicsTests/: the automated tests that open windows and render (doctest), on Vulkan or D3D12. One executable.
    • ShaderCompilerTool/: compiles the engine shaders at build time.
    • PrimalEditor/: the WPF editor, frozen (bug fixes only) until the new C++ editor reaches parity.
    • Editor/ (new, #13): the C++ editor on Dear ImGui inside the engine (Docs/Editor.md).
  • Docs/Editor.md: the new editor's design for #13 (decisions, architecture, order of work).

Current state / next step (2026-11-24)

  • #13 redesigned (user, 2026-11-24): a C++ editor on Dear ImGui inside the engine, side by side with the frozen WPF editor, same project files (Docs/Editor.md). Avalonia, Uno, Qt and C# ImGui bindings were rejected (section 4 there). Step 1, ImGui in the engine, done in the code 2026-11-24 (uncommitted parts; Docs/Editor.md section 9, plan doc A59 for the desktop): the renderer's UI pass (SurfaceFrame::ui), the platform's pointer/text/focus events, cursor, clipboard and display scale, the ImGui backend in Editor/UI/, the EDITOR_UI EngineTest. Step 2, offscreen views and theme v1, done in the code 2026-11-24 (uncommitted; plan doc A60): offscreen surfaces (graphics::create_offscreen_surface()), shown by the UI pass (UiDrawCommand::surface_id, imgui_backend::surface_image()), readback (graphics::request_readback()), Editor/UI/Theme.* (Inter + Lucide, fonts copied to x64/<Config>/fonts/). Next: step 3 (Docs/Editor.md section 6). Game UI on the same pass: #82 (after #13). The parented-window work is dropped (viewports render to textures). #78 and the plain view-model library of #61 are dropped.

  • Was next until 2026-11-24: #13 as the Avalonia editor. #61, #63, #38 and #12 are done in the code (uncommitted, bullets below). Not needed before #13: #64, #68, #5, #10, #46, #39, #33, #71-#77. Open checks: plan doc A48-A58 (desktop), the CI image publish, the runner's desktop session. Right after #13: #81 (user, 2026-11-23), replacing DirectXTex's CPU BC7/BC6H encoders; until then BC7 uses TEX_COMPRESS_BC7_QUICK.

  • #12 ContentTools on Linux done in the code (2026-11-23, uncommitted; Docs/ContentTools.md section 6, plan doc A58). Everything builds on both OSes: DirectXTex compiled from the downloaded sources (vcpkg gone; Linux adds DirectX-Headers and stb_image), no D3D11 (BC6H/BC7 on DirectXTex's CPU encoders, in strips on the job system), IBL on ContentTools' own Vulkan compute device (VulkanCompute.*, ContentTools.shaders → shaders/ContentTools.shaderpack, compiled by ShaderCompilerTool and, in the editor configurations, by InitializeEngine()). CMake: static ContentTools + shared libContentTools.so (only the 8 exports). The Vulkan SDK is needed for ContentTools on Windows; UnitTests'/GraphicsTests' ContentTools parts are conditional on it. Tests: UnitTests "texture import" and "primitive meshes", GraphicsTests "image based lighting", benchmark: cases for both. Checked on Linux (clang, GCC, tidy, checks, ASan/UBSan, TSan) and in the VM (4 configurations, UnitTests, GraphicsTests both backends, editor tests, the editor's start). Open: A58 on the desktop, a comparison with C:\winvm\baseline\ (needs a texture dump tool). The bullets below are the history, newest work near the top of each group.

  • #38 ufbx done in the code (2026-11-23, uncommitted; plan doc A57): FBX import uses ufbx 0.23.1 (downloaded, hash-pinned: cmake/PrimalDependencies.cmake + ContentTools/ThirdParty.targets); the FBX SDK is gone. Compared with the SDK importer on 9 files: the same up to n-gon triangulation; 10-20x faster. MikkTSpace is downloaded the same way (pinned to commit 3e895b4; the vendored copy is gone). ContentTools' geometry + FBX import build on Linux (CMake target ContentTools, static, linked by UnitTests): the first piece of #12. Open: A57 on the desktop. Next: #12.

  • #63 cause found, fixed in the code (2026-11-23, uncommitted; plan doc A56): "everything black" = scenes without lights (and no ambient light editor, #64). Decided (user): new scenes and the templates get a directional light (Scene.AddsDefaultLight); lights added by any actor go into the scene's light set. Open: the desktop checks of A56 (the lit cube was not seen in the VM), then the rest of #63's list (FBX, material textures). Next: #38.

  • #61 editor tests done in the code (2026-11-23, uncommitted; plan doc A55): PrimalEditor.Tests (36 tests, run in the VM), the seams (engine API interfaces, EditorServices), no WPF types in Actor/ActorPart, Windows CI step. Decided (user): seams now, the plain view-model library at #13; xUnit v3. A test found a real bug (removing a behavior duplicated another in the engine), fixed. Open: A55 on the desktop, the CI run after the push; then #63.

  • Where things stand (2026-11-13): #30 (script registration + GameScript), #37 (Windows VM) and #40 are done; the Windows VM (Tools/WinVM/) is where MSVC checks happen now, as edits are made. Next, in the user's order (roadmap #25, rewritten 2026-11-13): #18 → #17 items 1–4 → #4 groups A + C (C = decisions for the user) → #14 (Windows CI runner in the VM; no longer held) → #31 + #41 (decisions, before #3) → #3 + #4 group B → #28 (no longer held) → #5/#10 → content and editor (#35, #38, #39, #33, #12, #13, #16). #4 is now a checklist of what's left (updated 2026-11-13). Next Windows boot: plan doc A28 (FBX SDK 2020.3.11 on the desktop) and A29 (rebuild game projects for #30; REGISTER_SCRIPT is gone).

  • #18 Vulkan function loader done (2026-11-14, uncommitted, branch vulcan_loader): new Engine/Graphics/Vulkan/VulkanLoader.h/.cpp; nothing links the Vulkan loader on either OS. Checked on Linux (clang

    • GCC, ASan/UBSan, tidy, validation + sync validation; GPU-AV 0 errors) and in the Windows VM (4 configurations, D3D12 + Vulkan runs). Left for the desktop: plan doc A30 (Vulkan on the real GPU).
  • #17 items 1–4 done (2026-11-14, uncommitted, branch unify_shader_logic): one tile size (LightCullingTileSize), one engine shader table, the binding contract in ShaderBindings.h, and a build-time layout check of the shared structs ("Shaders" below). Checked on Linux (clang + GCC, Debug + Release, tidy, validation) and in the VM (4 configurations, D3D12 + Vulkan runs). Left for the desktop: plan doc A31. Items 5–7: next bullet.

  • #17 items 5–7 done on Linux (2026-11-15, uncommitted, branch unify_shader_logic), with the engine half of #35: shader packs (material shaders + variants per backend, compiled at build time), shader hot reload on both backends, Debug shader debug info, the Slang decision (stay on HLSL/DXC), MaxAverageLightsPerTile shared. The editor stores DXIL and SPIR-V per material variant (C#, blind). Checked on Linux (clang + GCC, Debug + Release, tidy, UnitTests 148, GraphicsTests 21 with validation, renderer test + a live hot reload) and in the VM the same day (4 configurations + 8 variants, D3D12 + Vulkan hot reload, the editor on both backends). #17 and #35 closed. Left for the desktop: plan doc A32 (end) / #46. Known limit: the distro DXC makes no DXIL on Linux (B13). Next per roadmap #25 (updated 2026-11-15): #4 groups A + C. New tickets: #45 Slang experiment, #46 shader follow-ups, #47 C# scripting prototype.

  • #4 group A done (2026-11-15, uncommitted, branch slang_experiment): std::to_underlying for the engine's enum casts, and 11 wrapper enums → enum class (ShaderType, InputCode, MaterialType, AssetType, the camera/light parameters, ...). Bitmasks, array-slot enums and enums nested in data structs stay wrappers on purpose (the list and reasons: #4). InputCode::invalid is the platform key maps' "unknown key". Checked on Linux (clang, GCC, tidy, tests) and in the VM (4 configurations + 8 variants, renderer test on both backends). Also fixed: gen_windb.py didn't define VK_NO_PROTOTYPES (since #18 every Windows database with Vulkan code failed to parse).

  • #4 group C decided and applied (2026-11-15, uncommitted; the rules: Docs/Preferences.md):

    1. utl::vector stays (the USE_STL_VECTOR switch and its workarounds are gone). free_list relocated its items as bytes: fixed by #48 (2026-11-16, below).
    2. Headers include what they use (gradual).
    3. Tools/check_layers.py checks the layer table (in ci.sh checks).
    4. std::expected for fallible functions from now on (no .value()).
    5. The game API headers (EngineAPI/) include only a public set (checked by the same script).

    Game projects whose scripts relied on what CommonHeaders.h brought in through GameEntity.h (<mutex>, <unordered_map>, utl::free_list) need their own includes. Next per roadmap #25: #14 is on hold (user, 2026-11-16); #31 followed (next bullet).

  • #31 ECS done and closed (2026-11-16, uncommitted, branch ecs_test). Decided (user): an own archetype ECS, scripts stay objects (Docs/Ecs.md section 5, Docs/Preferences.md). The benchmarks behind it: Prototypes/EcsBench/ (opt-in -DPRIMAL_ECS_BENCH=ON, CMake only; downloads EnTT and flecs pinned). The in-engine prototype (Docs/Ecs.md section 7): Engine/ECS/, and transforms are ECS components ("ECS" under Backend notes). Checked on Linux (clang + GCC, ASan/UBSan, TSan, tidy, UnitTests 159, GraphicsTests 21) and in the VM (4 configurations + 8 variants, UnitTests, renderer on D3D12 + Vulkan). Desktop: plan doc A34. The rest: #52. Next per roadmap #25 (reevaluated 2026-11-16): #6 (keep DirectXMath or switch), then #41 (with #52 step 3), #52 steps 1-2, #3.

  • #6 math library decided and done (2026-11-17, uncommitted, branch math_library), closed. Prototypes/MathBench/ (opt-in -DPRIMAL_MATH_BENCH=ON; downloads GLM and rtm pinned) compared DirectXMath, GLM, rtm and an own SSE prototype. Decided (user): DirectXMath stays behind math::; the storage types (v3, m4x4, ...) are the engine's own structs in MathTypes.h (no DirectXMath there any more); rotate3() is faster and math::Frustum is new (Docs/Math.md section 6). Checked on Linux and in the VM. Next per roadmap #25: #41 (with #52 step 3).

  • #52 steps 4-5, game API + editor + game.bin v2, done (2026-11-19, branch better_script_reflection; code committed in 9f34259, the 2026-11-19 fixes uncommitted) (Docs/Ecs.md section 10; decided: every recommendation of 10.6). Engine: EngineDLL/EditorSupport.*, the new EngineDLL exports, SaveGame, game.bin v2. The editor (scene tree, several scripts, reflection-driven field editor, the game's components, game.bin through SaveGame) was driven in the VM on 2026-11-19 and works (results: plan doc A41, Docs/Ecs.md 10.7); one fix there (a value the engine refuses no longer sticks, ReflectedComponent.cs). Linux all green (clang, GCC, ASan/UBSan, TSan, tidy, ci.sh checks, UnitTests 218, GraphicsTests 21) after two tidy fixes and a layer table entry (Content → Core, ECS). Desktop: plan doc A41, done on the desktop 2026-11-19 (issue #52; that session's doc edits weren't committed and are only on the desktop). Next: the actor model, #59 (user, 2026-11-19; before #3 on roadmap #25; #58 closed into it). Design note Docs/Actors.md (rewritten 2026-11-19: editor-first, prefabs as the unit, our own names Actor/Behavior/Part/Prefab); all 12 decisions of its section 16 decided (user: every recommendation; summary in Docs/Preferences.md "Actors"). Next: its step 1, one engine as a shared library. Then #3.

  • #59 step 1, one engine library, done (2026-11-19, branch actor_based_model, uncommitted; Docs/Actors.md section 17). The engine is PrimalEngine.dll / libPrimalEngine.so; a game executable also links EngineMain (its main()/WinMain). Exports are marked PRIMAL_API (Linux: hidden visibility, so a missing mark fails the Linux link). One reflection registry and one ECS for every binary: a header's type registered again by the same C++ type (TypeInfo::identity) is no error; types a library registers between reflect::begin_library_load() and end_library_load() are copied so they outlive it. EngineDLL no longer uses game DLL exports; log forwarding is gone. Checked on Linux (clang, GCC, tidy, ASan/UBSan, UnitTests 218 with a real dlopen game library, GraphicsTests 21) and in the VM (4 configurations + 8 variants, UnitTests, renderer test both backends, ScriptTest's DLL and executable, the editor). Workaround: JobTests.cpp without /GL (MSVC 14.52 LTCG crash, plan doc B16). Desktop: plan doc A42. Exports are marked member by member (no C4251 pragma). UnitTests/GameExecutable/ is a test game executable (CTest label graphics, run by ci.sh's graphics step). Shipping one static executable: #60 (later). One export macro while the engine is one library (Docs/Preferences.md).

  • #59 step 2, the actor runtime, done (2026-11-19, branch actor_based_model, uncommitted; Docs/Actors.md section 18). Engine/EngineAPI/Actor.h (game API) + Engine/Actors/ (new layer): actor::Actor, Part, Behavior, ActorOwner, ActorRef/PartRef, spawn()/destroy(), ticking in the frame. "Actors" under Backend notes. Checked on Linux and in the VM (results: the plan doc A43). Next: step 3, the engine's parts (MeshPart, lights, CameraPart) and their components; ask the user before starting it. ActorRef/PartRef convert from a pointer implicitly (user, 2026-11-19). Step 1 is committed in 226c139, step 2 in 9fcb52b.

  • #59 step 3, the engine's parts and the scene sync, done (2026-11-20, branch actor_based_model, committed in 0f0115b; Docs/Actors.md section 19). render::MeshRenderer, the four light components and render::Camera (Engine/EngineAPI/RenderComponents.h), the part classes that write them (RenderParts.h), and graphics::scene::sync() (Engine/Graphics/SceneSync.h), which makes the renderer's objects from them each frame (decided by the user: an adapter at render time, the renderer test converted to actors). Also fixed: actor::destroy() of an empty reference asserted, destroy_all() was quadratic, and both Linux Release builds failed at the step 2 commit (Entity.cpp). Checked on Linux (clang + GCC, Debug + Release, ASan/UBSan, tidy, UnitTests 239, GraphicsTests 22, renderer test) and in the VM (4 configurations + 8 variants, UnitTests, renderer test exit 0 on D3D12 and Vulkan). Desktop: plan doc A44, checked by the user the same day (the picture right). Next: step 4, reflection (started 2026-11-20).

  • #59 step 5, prefabs and game.bin v3, done (2026-11-20, branch actor_based_model, committed in db7854c; Docs/Actors.md section 21). Engine/Actors/Prefab.h (actor records, capture(), building with default-part matching, prefab registry and assets, instance overrides), actor::spawn_prefab()/PrefabRef in the game API, game.bin v3 (plain entities, prefabs, actors). Also FieldType::s64/u64 (user) and prefab_ref. Checked on Linux (clang + GCC, Debug + Release, ASan/UBSan, tidy, UnitTests 252, GraphicsTests 22, the test game) and in the VM (4 configurations, UnitTests, renderer test on D3D12 + Vulkan). Desktop: plan doc A46. Next: step 6, the editor, on the Windows desktop (next bullet).

  • #3 step 3, one frame for every surface, done (2026-11-23, committed in a1938dc; Docs/Renderer.md section 10). Decided (user): one call per frame, graphics::render_frame(std::span<const SurfaceFrame>); Surface::render() is gone. Both backends: one fence wait, one submission and one present call per engine frame; each surface has its own gpass render targets, barrier tracker, gpass cache and light buffers. The editor's export is RenderFrames(count, ids, cameras, light sets), called once per loop by RenderSurfaceHost.cs. Four windows: 1.92 → 1.84 ms (noise; RADV). Checked: plan doc A50.

  • #3 step 4 done (2026-11-23, committed in 5b936e6; Docs/Renderer.md section 11). A surface is prepared first (render targets, constant buffer data, light buffers, delight::prepare() resizes the light culling buffers), then gpass::record_batches() records both scene passes' batches in one parallel pass, then the frame's list. D3D12's ExecuteIndirect path and PRIMAL_D3D12_DRAW_INDIRECT are gone. Four windows 1.60 → 1.28 ms, 6,400 items 0.78 → 0.70 ms (RADV). Checked on Linux and in the VM (plan doc A51).

  • #3 step 5 done (2026-11-23; Docs/Renderer.md section 12). Render items are collected in jobs (per surface and per 1,024 items) under shared content locks (std::shared_mutex); gpass::prepare() only allocates and sets addresses; gpass::plan_jobs()/run_job() put every surface's data fill and batches into one parallel pass. Four windows 1.28 → 0.84 ms, 6,400 items 0.70 → 0.60 ms (RADV). scene::prepare() per chunk was left out (0.04 ms). Checked on Linux (also TSan) and in the VM (plan doc A52). Committed in aa9c480 (step 4: 5b936e6).

  • #28 done in the code (2026-11-23, uncommitted; plan doc A54): GraphicsTests.vcxproj, the tests on the backend PRIMAL_GRAPHICS names, graphics::validation_stats() for both backends, a D3D12 restart hang fixed (B17), and ci.sh coverage (clang source-based coverage, PRIMAL_ENABLE_COVERAGE; a coverage job uploads the HTML). Windows CI runs the graphics tests when the repository variable PRIMAL_CI_GRAPHICS is true (the runner needs a desktop session first). The CI image tag is 2026-11-09-d (adds llvm): publish it before the push. #28's items 3, 5-7 are #74-#77. Next: see the first bullet of this section.

  • #3 step 6 done (2026-11-23, uncommitted; Docs/Renderer.md section 13). vkx::set_name()/d3dx::set_name() replace the NAME_*_OBJECT macros; per-pass debug markers (vkx::ScopedMarker, d3dx::ScopedMarker); std::span at the content reads. Duplication measured again with Tools/measure_backend_duplication.py: 44% → 34% identical, 1,653 fewer backend lines. RAII left for #67/#71. Follow-ups #71-#73 created. #3's code is done; it stays open for the desktop checks: one list, plan doc A53. Next: #28 (done, bullet above), then the #13 path (first bullet of this section).

  • #3 step 2 done (2026-11-22, committed in 54bfffe; Docs/Renderer.md section 9), with #52 step 6: the renderer reads the render components: cameras (camera::camera_of()), lights (light::rebuild()) and meshes (graphics::scene, Scene.*, was SceneSync.*) each frame; the light/camera/render-item API, graphics::Camera/Light and the old geometry component are gone (decided by the user: every recommendation of section 9). Checked on Linux and in the VM (also the editor). Desktop: plan doc A49.

  • #3 step 1 done (2026-11-21, committed in 54bfffe; Docs/Renderer.md section 8): camera, light sets + the light API, engine shader loading and frame_buffer_count are shared in Engine/Graphics/ (Camera.*, Lights.*, EngineShaderFile.*, FramesInFlight.h); each backend keeps its light buffers (derived from light::LightBuffers) and its byte code wrapper. D3D12Camera.* was moved, VulkanCamera.* deleted: the user stages those. Checked on Linux and in the VM. Desktop: plan doc A48.

  • #3 planned (2026-11-21; Docs/Renderer.md). Decided (user): option A (shared CPU-side modules, the frame packet as the boundary; render graph #66 and RHI #67 later), the renderer reads the ECS components (#52 step 6; SceneSync and the object API go), every other recommendation (section 7). Plan: section 6. Started 2026-11-21 (user).

  • #59 step 7, conversion, done (2026-11-21; desktop, then the Linux checks and the VM; code in 8f333d9, the Linux fixes uncommitted; Docs/Actors.md section 23). #59 is closed. Next per roadmap #25: #3 (ask the user). Decided (user): entity scripts are removed (EntityScript, PRIMAL_SCRIPT(), script components and their exports, scripts in game.bin, now v5); old scenes' plain entities are dropped on load with a warning (the plain-entity UI and the old light entities are gone); one New Class dialog (Behavior, Actor, Part, Game Script). Done and checked on the desktop (4 configurations, UnitTests 238, renderer test, the editor driven: warning, New Class, build, Run, clean exit). game_entity::Entity has transform setters now (they were EntityScript's). Linux checks done 2026-11-21 (all green; fixes uncommitted: formatting, one tidy fix, the test game's game.bin v5). The VM's ScriptTest is converted to behaviors and loads in the editor. Ambient light in editor scenes: issue #64.

  • #59 step 6 done (2026-11-21, desktop, uncommitted). Was "in progress" below.

  • #59 step 6 in progress (2026-11-20 evening, desktop, uncommitted; next session starts here). A42/A45/A46 passed. Decided (user): every recommendation (Docs/Actors.md section 22: editor scenes are actors only, C# holds the values, saving a prefab rebuilds open instances, new-script template cleanup). Slices 1-4 done and driven (outliner, details, Add Actor, undo, game.bin v4 with actor attachments and without the editor's viewport cameras: section 22 "Progress"); slice 5, prefabs, done and driven 2026-11-21 (UnitTests 255; results Docs/Actors.md section 22); decided with every recommendation (.asset type, Edit Prefab as a temporary scene, decision-6 overrides only). Every game project must be run once from the editor again (v3 is refused). Nullable is on for the whole editor project (472 warnings left; Actor.cs/ActorView.xaml.cs clean). C# tests: issue #61. The C++ of slice 4 (ContentLoader.*, EngineDLL/Common.h, EngineAPI.cpp, EntityAPI.cpp, UnitTests/PrefabTests.cpp, ContentLoaderTests.cpp) still needs the Linux checks (clang, GCC, tidy, sanitizers). New C# rules (user, 2026-11-20; full text Docs/Preferences.md "C# (the editor)", IDE checks .editorconfig [*.cs]): newer C# syntax, braces on every if/else/loop body, LINQ in method syntax only, and nullable reference types: #nullable enable in new and changed files, ? on what may be null, null handled at the access, never silenced (!, #pragma, = null!). New and touched code only, no pass. Still to do: Components/Actor.cs and ActorView.xaml.cs were written before the nullable rule (enable + fix). Driving the editor on the desktop: see Tools/EditorAutomation/EditorUi.psm1 (lessons of 2026-11-20 at the top).

  • #59 step 6, the editor: continues on the Windows desktop (user, 2026-11-20). Handoff for that session:

    1. Pull actor_based_model (code of steps 1-5 in 226c139..db7854c; check that Docs/ and this file are committed too). Build the four configurations.
    2. Desktop checks first: plan doc A45 and A46 (A44 is done). Every game project must be run once from the editor (Ctrl+F5) to write game.bin v3; a v2 file is refused with "build the game again".
    3. Read Docs/Actors.md sections 6, 9, 10, 12, 15 (step 6) and 21 (the record, prefab assets PPFB, overrides, game.bin v3). The engine side for the editor is Engine/Actors/Prefab.h (capture(), spawn(), save_asset()/load_asset(), capture_overrides()); EngineDLL needs new C exports for it (EDITOR_INTERFACE, UTF-8, the Avalonia constraints). SaveGame writes only plain entities so far.
    4. Step 6's scope: outliner and details for actors (section 9), prefab editing, save as prefab, the content browser drag, Add Actor. 64-bit fields stay text in the editor, never double (Docs/Preferences.md).
    5. On the desktop the editor runs directly (real GPU, the user watches); the Linux checks (clang, GCC, tidy, sanitizers, ci.sh checks) of the C++ written there come after, on Linux or through CI on push: plan doc Open items C.
  • #59 step 4, reflection, done (2026-11-20, branch actor_based_model, committed in 4bba32b; Docs/Actors.md section 20). PRIMAL_ACTOR()/PRIMAL_PART()/PRIMAL_BEHAVIOR() (the generated body writes is_a()/class_name()), spawn_by_name()/add_part_by_type()/add_behavior_by_type(), ActorRef/PartRef fields (stored as entities), log helpers on actors and behaviors, the render components and engine parts reflected. Checked on Linux (clang + GCC, Debug + Release, tidy, UnitTests 245, GraphicsTests 22) and in the VM (4 configurations + 8 variants, UnitTests, renderer test on D3D12 + Vulkan). Desktop: plan doc A45. Next: step 5, prefabs and files (ask the user first).

  • #52 step 2, scripts and components, done (2026-11-18, uncommitted) (Docs/Ecs.md section 9): scripts write transforms directly (#57 fixed: 17.2 → 0.32 ms for 10,000 moving scripts), Entity::get<T>()/write<T>()/has<T>()/ queue_add_component(), several scripts per entity (add_script(), script<T>()), late_update(), Ecs.h in the game API. Desktop: plan doc A40. #58 (new): entity trees from code and prefabs. Next per roadmap #25: #3 (with #52 step 6), or #52 steps 4-5 first: ask the user.

  • #52 step 1, the transform hierarchy, done (2026-11-18, branch better_script_reflection, uncommitted) (Docs/Ecs.md section 8; decided: world space for the short names, local_* relative to the parent, reparenting keeps the world transform, removing a parent removes its children, a depth-sorted child list). transform::Parent + HierarchyDepth, game_entity::set_parent()/queue_set_parent(), EntityInfo::parent, children updated level by level on the job system. Checked on Linux (clang, GCC, TSan, ASan, tidy, UnitTests 206, GraphicsTests) and in the VM (4 configurations, UnitTests, renderer on D3D12 + Vulkan). Desktop: plan doc A39. Next: #52 step 2 (scripts reaching components; #57 there).

  • #41 reflection done (2026-11-18, branch better_script_reflection, uncommitted), with #52 step 3. Decided (user; Docs/Reflection.md section 7, Docs/Preferences.md "Reflection"): the generator PrimalReflectGen with Unreal-style markers ("Scripts" below), C++26 reflection later. #47 (C#) was decided against the same day: the experiment is in the history on branch core_clr (8ec6a81, Docs/CSharpScripting.md); Prototypes/CSharpScripting/ here holds only ignored bin//obj/ folders, safe to delete. Done: the runtime (one registry for scripts and components), the generator (ReflectionTool/) with CMake (cmake/PrimalReflection.cmake) and MSBuild (Engine/Reflection.targets) integration, every script converted, the editor's templates, ECS components by name (ecs::find_component()), the transform components reflected. Checked on Linux (clang + GCC, tidy, UnitTests 192, GraphicsTests 21) and in the VM (4 configurations, UnitTests, a template game project). Desktop: plan doc A38 (the editor's blind C#). Open: the editor ABI and game.bin (#52 step 5). Next per roadmap #25: #52 steps 1-2.

  • #14 Windows CI done and closed (2026-11-17), with the move to Forgejo. Workflows are in .forgejo/workflows/; windows.yml runs on the user's Windows runner VM (host mode, label windows, one job at a time; Tools/CI/WindowsRunner.md): four configurations, EngineTest variants, UnitTests, the entity-components test, a build without Vulkan. Linux and Windows both green on the first run with the fixes. The CI image is in Forgejo's registry (Tools/CI/publish-image.sh). Next per roadmap #25: #41.

  • #48 done and closed (2026-11-16, uncommitted, branch ecs_test): utl::free_list keeps its items in blocks that never move (8, 16, 32, ... slots), with a live bit per slot: any type can go in, references stay valid, remove() of a dead id is refused in every build, the destructor and clear() destroy what's left. ShaderGroup holds its map directly. Lookups cost ~1.4 ns (0.2-0.5 before); a 6,400-item frame is unchanged. Checked on Linux (all CI jobs) and in the VM (4 configurations, UnitTests, renderer on D3D12 + Vulkan). Windows: (std::max) in headers that <windows.h> may precede.

  • #45 Slang experiment done and closed (2026-11-15, branch slang_experiment). Decision (user): stay on DXC, keep the Slang path as a tested opt-in. Slang 2026.18.2 (distro shader-slang) compiles every engine and material shader to SPIR-V next to DXC: opt-in with CMake -DPRIMAL_ENABLE_SLANG=ON and PRIMAL_SHADER_COMPILER=slang at run time (EngineDLL/SlangCompilation.h, Linux only). Results on #45: validation, sync validation and GPU-AV clean, GraphicsTests 21/21, the layout check passes, RADV's final ISA practically identical (no frame-time difference), compiles ~6x slower (~50 ms per shader), no DXIL on Linux (same DXC crash, B13). Kept for both compilers: the heap at set 1 binding 2 (ShaderBindings.h) and typed heap casts (Texture2D<float4>(ResourceDescriptorHeap[i])). Checked in the VM; desktop: plan doc A33. Committed (908057d). CI (2026-11-15, uncommitted): ci.sh slang (build with Slang, recompile the shaders with it, unit + graphics tests with PRIMAL_SHADER_COMPILER=slang), a slang job in linux.yml, a Slang pass in ci.sh tidy, shader-slang in the image (tag 2026-11-09-c, same snapshot). Run in a local build of the image; Tools/CI/publish-image.sh must run before the push (not published yet).

  • #2 closed out (2026-11-14, uncommitted, branch code_style): CLion inspection review (comment on #2). Small fixes in Log.cpp, Renderer.cpp, Input.cpp, ContentToEngine.cpp, VulkanContent.cpp, D3D12Content.cpp, EngineTest/Test.h. New: Docs/Preferences.md (all style and workflow preferences, imported below), the shared CLion profile/scope/dictionary in .idea/ (.gitignore now tracks only those), Docs/Inspections/ ignored. New rule: const everywhere it fits, in new and touched code.

  • Uncommitted (2026-11-13, A25/A26 fixes): clang-format in Log.h, Log.cpp, D3D12Core.cpp, D3D12Gpass.cpp; clang-tidy fixes in UnitTests/LogTests.cpp, EngineTest/RenderItem.cpp, D3D12Gpass.cpp (blind); new Tools/WinVM/ (untracked); FBX SDK path as a property (ContentTools.vcxproj, FbxImporter.cpp, README.md, Tools/CI/WindowsRunner.md). Code before that is committed (HEAD 00d1d6e); Docs/, CLAUDE.md, Tools/CI/WindowsRunner.md and Tools/WindowsCompileDb/README.md are staged, not committed. The bullets below are the history: their "uncommitted" marks are outdated, and their "Not yet seen by MSVC" notes are all settled.

  • Windows session 2026-11-11: A13, A14, A16, A17.1 checked with MSVC (plan doc "Windows session 2026-11-11"). All 4 configurations + the 8 EngineTest variant builds clean, UnitTests.exe 83/83 in Debug and Release, both renderer tests exit 0 (Vulkan validation clean, picture right per the user). One fix (uncommitted): ContentToEngine.cpp gpu_id_from_fake_pointer() lost its constexpr (MSVC C3615: reinterpret_cast in a constexpr function); clang-tidy re-run on Linux 2026-11-11: clean. Editor run OK too (user: FBX/texture import, primitive mesh, materials, reload), so A13 is closed. A generated script project builds clean with MSBuild (A14.3). Issues #2, #20 and #21 are closed (CI was green on e3b428b). Left on Windows: the editor building and loading a script DLL itself (A12.5, needs Visual Studio), A16.4 (scene naming a missing script, optional), the Windows CI runner (A15, #14) and GraphicsTests on Windows (#28); the user holds #14 and #28 until after the deeper rewrites. #22 (0x80000003) closed as not reproducible. The "Not yet seen by MSVC" notes below are settled by this.

  • Issue #23 done and closed (2026-11-11, uncommitted): the editor offers to update an old game project's .vcxproj on load (PrimalEditor/GameProject/GameProjectUpgrade.cs, called from Project.Load(); plan doc B11). Its target values (v145, stdcpp23, the $(PRIMAL_ENGINE) paths, the Vulkan.props import) are constants: change them together with the four MSVCProject templates.

  • A12 (MSVC check of the Linux-only work) is done, incl. FBX/texture import and primitive mesh in the editor. Only the in-editor script build is left (needs Visual Studio; the user doesn't want it installed for now). Old game projects retargeted to v145 + C++23 (B11; 2 still have old-API scripts). Results: plan doc "Windows session 2026-11-09" under Phase 6. Fixes made there (uncommitted): EngineTest.vcxproj test defines + /W4, Engine/Vulkan.props /IGNORE:4199, FbxImporter.cpp const, game project templates → v145 + stdcpp23, script template [[maybe_unused]] dt, all engine .vcxproj stdcpplatest → stdcpp23.

  • Windows machine notes: VS 18 BuildTools only (no IDE, no debugger, no nuget.exe: restore with msbuild /t:Restore /p:RestorePackagesConfig=true). User env var PRIMAL_ENGINE now points at Primal_Plus.

  • T02 /WX done on Windows (2026-11-09; opt out with /p:PrimalWarningsAsErrors=false).

  • T02 cast pass done on Linux (2026-11-09, uncommitted): no C-style casts left, modernize-avoid-c-style-cast is on, gen_windb.py uses /std:c++23preview. Details: T02 ticket "Done, part 4". Not yet seen by MSVC: plan doc Open items A13 is the next Windows session's checklist (FbxImporter.cpp was edited without any compiler).

  • T20 done on Linux (2026-11-09, uncommitted): no include cycles, every header compiles alone, includes are sorted. Not yet seen by MSVC: plan doc Open items A14.

  • T14 CI, Linux part done (2026-11-10): Gitea Actions, .gitea/workflows/linux.yml → Tools/CI/ci.sh in the image from Tools/CI/Dockerfile. Runs on the Gitea runner on every push. windows.yml.disabled is commented out and never run (Open items A15). How-to: the comments at the top of Tools/CI/ci.sh.

  • Remotes (2026-11-10; origin moved to Forgejo 2026-11-16): origin is the user's Forgejo (primary, CI runs there), github the public mirror, upstream a private Gitea mirror of Arash's repo (push disabled).

  • T21 automated tests done on Linux (2026-11-10, uncommitted): UnitTests/ with 83 doctest cases (ids, utl::vector, utl::free_list, math, blob streams, entities/transforms/scripts, input, load_game, the PSHB shader file) and GraphicsTests/ with 15 (windows, surfaces, a hand-made scene through the whole Vulkan renderer; no assets needed). ci.sh build and sanitizers run both, the graphics tests on Xvfb + lavapipe with validation on. Not yet seen by MSVC: plan doc Open items A16 and A17 (UnitTests.vcxproj is blind; GraphicsTests has no .vcxproj: issue #28, with the other follow-ups). Issue #21 closed 2026-11-11.

  • Issue #6 first step done on Linux (2026-11-11, uncommitted): DirectXMath is named only in Engine/Utilities/MathTypes.h and the new MathSimd.h (math::vec, math::mat and thin math:: functions, plus quat_from_euler(v3) -> v4, to_v3(), to_v4()). Tools/check_math_usage.py enforces it in ci.sh checks. The storage types are still DirectXMath aliases, and keep-or-switch is still open in #6. 90 unit tests now. Not yet seen by MSVC: plan doc Open items A18 (the vec operator lookup and XM_CALLCONV can only be checked there; the D3D12 and ContentTools edits were blind).

  • Issues #1 + #19: design proposal written (2026-11-11, branch job_system): Docs/Multithreading.md. Nothing is implemented; its section 8 lists the decisions the user still has to make, section 9 the order of work (logging first). All decided by the user 2026-11-11 (own job system, no fibers, scripts stay serial for now, a Vulkan-only prototype of parallel recording at the end of #1).

  • #19 logging, steps 1 and 2 done on Linux (2026-11-11, committed): everything logs through primal::log (Engine/Core/Log.h/.cpp): log::info(log::Category::vulkan, "text {}", value). Logger thread, console sink (stderr + debugger on Windows), log file (primal.log / EngineTest.log next to the executable), ring buffer, DrainLog in EngineDLL with a timer in the editor. Tools/check_log_usage.py (in ci.sh checks) fails on direct OutputDebugString/printf/std::cout. 100 unit tests. Not yet seen by MSVC, and the editor's C# is unbuilt: plan doc Open items A19. Still open in #19: a log helper for game scripts, and routing the D3D12 debug layer's messages into the log.

  • Module trial (2026-11-11, committed in e9efb4f): logging was converted to a module and reverted (see "Modules" below). Kept from it: CMake 3.28, the module steps in ci.sh tidy and gen_windb.py, Engine/Modules.props and its imports in five .vcxproj files (blind).

  • #1 step 3 done (2026-11-12, committed e9efb4f): ThreadSanitizer option PRIMAL_ENABLE_TSAN, preset linux-tsan, ci.sh tsan and a tsan job in linux.yml (made during the module trial; the user kept them). ci.sh tsan now also runs the graphics tests; Tools/CI/tsan.supp suppresses lavapipe and LLVM. The 28 reports were one real lock-order inversion (DescriptorHeap::free(), both backends, plan doc B12; D3D12 blind: A19.8), now fixed. Checked in the CI image (twice clean) and on RADV.

  • #1 step 4 done on Linux (2026-11-12, committed bb86a00): the job system, the first named module. Engine/Core/Jobs.ixx (primal.jobs) + Jobs.cpp, 12 tests in UnitTests/JobTests.cpp (112 in all). Clean on clang and GCC, Debug and Release, clang-tidy (Linux and Windows databases) and TSan. Nothing calls it yet. Differences from the design: Docs/Multithreading.md section 9, step 4. Not yet seen by MSVC: plan doc Open items A20 (the first module on MSVC, and the first real use of Engine/Modules.props).

  • #1 step 5 done on Linux (2026-11-12, committed 1303f06): the first users of the job system. The pool runs in the game's main(), EngineDLL, EngineTest and GraphicsTests. Loader threads → background jobs, eager transform matrices with parallel_for (transform::update_matrices()), per-worker script caches, per-object data with parallel_for (both backends). Measured: matrices 3.5-4x faster with 100,000 entities; loading and render preparation unchanged at today's sizes (numbers in Docs/Multithreading.md step 5 and issue #1). ContentTools keeps its threads. Not yet seen by MSVC: plan doc Open items A21 (D3D12 and EngineDLL parts blind).

  • #1 step 6 done on Linux (2026-11-12, committed 5be9776): explicit frame phases. Module primal.frame (Engine/Core/Frame.ixx): frame::run(dt, render) = sync point, scripts, transforms, render. Entity command queue (game_entity::queue_create/queue_remove), TicketMutex → std::mutex in EngineDLL (blind). Details and what was left out on purpose: Docs/Multithreading.md step 6. Not yet seen by MSVC: plan doc Open items A22. The editor renders on its own thread (RenderSurfaceHost.cs), outside the pool: A21.2 was corrected.

  • #1 step 7 done on Linux (2026-11-12, uncommitted): parallel command recording on Vulkan (prototype). More than 512 render items are recorded in jobs into secondary command buffers (record_pass() in VulkanGPass.cpp), with command pools per thread and frame (VulkanCore.cpp); the gpass cache is per surface. A frame with 6,400 items: 3.3 ms → 2.25 ms; recording itself ~4x faster, render preparation (~1.5 ms) is now the largest cost. Numbers: Docs/Multithreading.md step 7. PRIMAL_VULKAN_PARALLEL_RECORDING=0 turns it off. Engine/Utilities/Threading.h deleted (stage it with git rm; until then ci.sh checks fails on it). Not yet seen by MSVC: plan doc Open items A23.

  • Script lifetime (2026-11-12, uncommitted): begin_play() was never called; now it runs at the sync point after a script is created, and the new end_play() runs before a script is removed (only after its begin_play()). 6 tests in UnitTests/FrameTests.cpp. The editor's new-script template has end_play() (blind). Registration rework and script kinds: issue #30. Not yet seen by MSVC: plan doc Open items A24.

  • CMake presets per EngineTest test (2026-11-12): linux-debug-renderer, -surfaces, -window, -entity-components, linux-release-renderer; CLion shows them as profiles.

  • #1 step 8 done (2026-11-12): Docs/RendererThreading.md, the design note for #3. #1 is done on Linux; it stays open (label needs-windows-check) until the MSVC checks A20-A24 pass.

  • Windows session 2026-11-12: A18–A24 checked with MSVC (plan doc "Windows session 2026-11-12"). All 4 configurations + 8 EngineTest variants clean, UnitTests.exe 125/125 Debug and Release, renderer tests D3D12 + Vulkan exit 0 (picture right per the user), editor fine (user). Fixes (committed in 2260632): MathSimd.h C4459 (tolerance), ContentToEngine.cpp constexpr again (the 2026-11-11 fix was lost), Log.cpp C4530 (<chrono> pragma + PRIMAL_LOG_HAS_EXCEPTIONS), Modules.props C5050 off in importers. Next on Linux: plan doc Open items A25 (clang-format/clang-tidy/GCC re-check of those and of the #19 work below). Then #30 or #3 (Docs/RendererThreading.md); #31 (ECS evaluation: DOTS, Unreal Mass, EnTT, flecs) comes after #30.

  • Same session, later (committed in 2260632): the editor builds and runs game code without Visual Studio (MSBuild + VS Code, PrimalEditor/GameDev/VisualStudio.CommandLine.cs; A12.5 done), a built game finds the engine shaders (copied on Run), and #19's last two parts: script log helpers (log_info() etc. on EntityScript), game DLL log forwarded into the editor, D3D12 debug layer messages in the log. #19 closed (2026-11-13, all checked on Windows). Also fixed: an editor crash on a game code reload (RemoveScriptComponents), and games with meshes no longer crash on Run (meshes left out of game.bin for now: issue #33). Details: plan doc "Windows session 2026-11-12", second half.

  • D3D12 parallel recording + direct draws (2026-11-13, committed in 577e005): D3D12 now draws directly by default (ExecuteIndirect was 2.5-4x slower on the GPU; PRIMAL_D3D12_DRAW_INDIRECT=1 for it) and records batches in jobs like Vulkan. Both backends' per-frame constant buffer grows with the item count (it crashed above ~4,000 objects). Stress option PRIMAL_TEST_EXTRA_SPHERES. Numbers: plan doc "Windows session 2026-11-12", second half. Linux check: plan doc Open items A25 and A26.

  • Windows checks finished (2026-11-13). A19.4 passes (no CRT leaks; Tools/DebugOutput/Capture-DebugOutput.ps1 captures OutputDebugString without a debugger installed). A16.4 passes. A23.3 (the editor on Vulkan) fails: material shaders in assets are DXIL only, issue #35. Left on Windows: #14 and #28 (held by the user then; no longer held since 2026-11-13), #33 and #35 (new work, later). Old test game projects are left as they are.

  • Driving the editor from scripts: Tools/EditorAutomation/EditorUi.psm1 (Windows PowerShell 5.1, UI Automation, no screenshots). Ask the user only for what a script can't do, in short numbered steps.

  • Docs/, CLAUDE.md and Tools/WindowsCompileDb/README.md are staged but not committed yet (2026-11-13). The user knows.

Preferences and code style

All of the user's standing preferences (working rules, language, naming, const, modules, formatting, CLion inspections and their known false positives) are in Docs/Preferences.md, imported here so every session loads it. Add new decisions there, not here.

@Docs/Preferences.md

Scripts (engine API)

  • Reflection (#41, 2026-11-18; Docs/Reflection.md): types declare themselves with markers that PrimalReflectGen (ReflectionTool/) reads before compiling: PRIMAL_COMPONENT(), PRIMAL_GAME_SCRIPT(), PRIMAL_ACTOR(), PRIMAL_PART(), PRIMAL_BEHAVIOR() before a class (options: .name = "..."), PRIMAL_ENUM() before an enum class at namespace scope, PRIMAL_GENERATED_BODY() inside each class, PRIMAL_PROPERTY(.min = 0.f, .tooltip = "...") before a member. Components reflect every field, classes only PRIMAL_PROPERTY ones. PRIMAL_SCRIPT() is gone (#59 step 7): the generator says to make the class a behavior. The file's last include is #include "<file name>.generated.h". A new file with markers goes in primal_reflect(<target> ...) in its CMakeLists.txt; MSBuild runs the generator on every item of a project that imports Engine\Reflection.targets (a header must be a ClInclude item). Field types: bool, s32, u32, s64, u64 (name hashes, seeds), f32, v2-v4, m4x4, game_entity::Entity, PRIMAL_ENUM() enums, std::array of those; in classes also std::vector/utl::vector of those and std::string (not in components: they allocate). No C arrays. One registry for every reflected type (Engine/EngineAPI/Reflection.h, Engine/Reflection/Reflection.cpp), keyed by the FNV-1a hash of the name: the class name, or .name (the engine's own types use qualified names: transform::Position). A duplicate name is logged as an error in every build and the first registration stays. reflect::find_type(), ecs::find_component(name_hash) (the same id as component_id<T>()). PRIMAL_SCRIPT(Type); after the class is gone (no backwards compatibility): game projects are converted by hand. Actor classes: PRIMAL_ACTOR(), PRIMAL_PART(), PRIMAL_BEHAVIOR() (Docs/Actors.md section 20); their PRIMAL_GENERATED_BODY() goes first in the class (it ends with private:), and their fields may also be actor::ActorRef<T>/PartRef<T> (in components too).
  • Behaviors are the per-object logic (entity scripts are gone since #59 step 7): PRIMAL_BEHAVIOR() + class X : public actor::Behavior with using Behavior::Behavior;, reaching the actor with owner(). Plain entities have no per-entity logic: ECS systems are theirs, and Entity::set_position() etc. write their transforms.
  • Game scripts: PRIMAL_GAME_SCRIPT() + class X : public script::GameScript for game-level logic with no actor (game mode, managers). Every registered one runs: created and begin_play() at the first frame's sync point (before actors begin play), update(dt) before the actors, end_play() + destroyed by script::end_game_scripts() (the game calls it in engine_shutdown() before unloading its entities); a later frame starts them again. The editor runs no frames, so it never starts them. Game scripts share the name registry with every other reflected type; ScriptBase has their name and log helpers.
  • Game DLL ABI (since #59 step 1): the game DLL links PrimalEngine.dll like EngineDLL, and exports nothing: its classes and components register in the engine's registry while EngineDLL loads it (reflect::begin_library_load()/end_library_load() around LoadLibrary, release_library_types() before FreeLibrary), and EngineDLL finds them there by name. A game project still linking Engine.lib doesn't build: the editor's upgrade replaces it with PrimalEngine.lib;EngineMain.lib;.

Building and running

Linux (CMake presets; all write to x64/<Config>/, so the last build wins)

cmake --preset linux-debug -DPRIMAL_ENGINE_TEST=RENDERER   # or ENTITY_COMPONENTS, WINDOW, SURFACES, EDITOR_UI
cmake --build --preset linux-debug
  • Or a preset per test, each with its own build folder (in CLion: one CMake profile each, then run the EngineTest configuration): linux-debug-renderer, linux-debug-surfaces, linux-debug-window, linux-debug-entity-components, linux-debug-editor-ui, linux-release-renderer. They still write to x64/<Config>/. The editor UI test (Dear ImGui's demo) stops after PRIMAL_TEST_FRAMES=<n> frames when set.

  • Presets: linux-debug, linux-release (clang) and linux-gcc-debug, linux-gcc-release.

  • The engine is a shared library, x64/<Config>/libPrimalEngine.so (Windows: PrimalEngine.dll + .lib), next to the programs, which find it through RUNPATH $ORIGIN. New engine API that another binary calls gets PRIMAL_API (Docs/Preferences.md, "The engine library").

  • -DPRIMAL_ENABLE_SANITIZERS=ON turns on ASan and UBSan.

  • The test content assets are already in x64/. They were generated on Windows, before ContentTools built on Linux (#12). On Linux ContentTools is x64/<Config>/libContentTools.so (no editor calls it yet: #13).

Windows

  • Open Primal.slnx and build Debug, Release, DebugEditor or ReleaseEditor.
  • Pick the EngineTest test with /p:PrimalEngineTest=RENDERER|ENTITY_COMPONENTS|WINDOW|SURFACES|EDITOR_UI.
  • Building EngineTest.vcxproj alone needs /p:SolutionDir=<repo>\.
  • The Vulkan backend builds only when the Vulkan SDK is installed (Engine\Vulkan.props, PrimalVulkan).
  • The tests are GUI-subsystem. Use Start-Process -Wait -NoNewWindow -RedirectStandardError <file> to capture the log.

Automated tests

  • x64/<Config>/UnitTests runs every test and exits non-zero when one fails (ctest --test-dir build/<preset> does the same). -ts="utl::vector" runs one suite, -tc="*erase*" matching cases, --help lists the options.
  • doctest is one header, downloaded and not in the repo (the user's choice): CMake fetches it at configure time (cmake/PrimalDependencies.cmake), MSBuild in a DownloadDoctest target of UnitTests.vcxproj (into packages\). Both pin the same version and SHA-256: change them together.
  • One .cpp per area in UnitTests/. A new file goes in UnitTests/CMakeLists.txt and UnitTests.vcxproj.
  • The entity, transform, script and input systems are global and keep their state between test cases: a test must not rely on particular ids or on empty systems, and removes what it creates.
  • Tests need their own checks (CHECK): the engine's asserts are off in Release.
  • Test files go in UnitTests/Data/ (PRIMAL_TEST_DATA_DIR, both build systems): ImportTest.fbx is the FBX import tests' scene (ASCII, written with the FBX SDK before #38; its expected numbers are the SDK importer's).
  • The editor's tests (PrimalEditor.Tests/, xUnit v3, issue #61): x64\<DebugEditor|ReleaseEditor>\EditorTests\PrimalEditor.Tests.exe (Windows only: the WPF runtime; built with the solution, in the VM too; -method "*Behavior*" picks tests, -? lists options). On Linux dotnet build PrimalEditor.Tests -c DebugEditor -p:Platform=x64 -p:EnableWindowsTargeting=true checks that it compiles. View-model tests run against FakeEngine.cs (actors, parts, behaviors, fields as text; extend it with what a new test needs) through EditorTest, which installs it and makes an in-memory project; the editor's statics make the tests run one at a time (xunit.runner.json). NativeEngineTests call EngineDll.dll (no window, GPU or game code) and remove what they make. A failed Debug.Assert fails the test.
  • x64/<Config>/GraphicsTests runs the graphics tests the same way (same doctest options), on the backend PRIMAL_GRAPHICS names (the platform's default otherwise: D3D12 on Windows). It needs a display (on Windows a desktop session: swapchains fail over SSH) and a device (Vulkan 1.3, or D3D12 incl. WARP), and shows its windows for a few seconds; xvfb-run -a x64/<Config>/GraphicsTests runs it on a virtual display where lavapipe is installed (the CI image). ctest -LE graphics leaves it out.
    • A test starts the renderer with graphics_test::Session and ends with shutdown_and_check(): in Debug, any validation error or warning fails it (graphics::validation_stats(): Vulkan's layer, D3D12's debug layer), also those reported while the device is destroyed. PRIMAL_TEST_REQUIRE_VALIDATION=1 also fails a Debug run whose validation isn't active.
    • Content is made in memory (GraphicsTests/TestContent.h: meshes in the three vertex formats of TestShader.hlsl, LODs, textures, cube maps). Nothing is read from x64/, so new tests must not need assets.
    • Sizes are compared with each other, never with the numbers asked for: a window manager may scale a window or choose its size.
    • New sources go in GraphicsTests/CMakeLists.txt and GraphicsTests.vcxproj.
    • In the VM: run it inside Invoke-Interactive (a desktop session). doctest's -tc splits on commas, so a test name with a comma is selected with a * in its place.
  • Benchmarks are test cases named benchmark: ... and marked * doctest::skip(), so they don't run by default: x64/Release/UnitTests -tc="benchmark*" --no-skip (also GraphicsTests). They print their numbers with MESSAGE; compare PRIMAL_JOBS=0 with the default. No commas in test names: -tc splits on them.
  • Tools/CI/ci.sh build <preset> builds everything and runs the tests the way CI does; ci.sh graphics [Debug] runs only the graphics tests of an existing build.
  • GCC 16 at -O2/-O3 reports false -Wstringop-overflow errors inside std::vector::insert(range) and assign(n, value) in test code: use resize() + std::memcpy, or a std::array.
  • doctest's CAPTURE/INFO/*_MESSAGE macros trip misc-const-correctness with the MSVC headers only (Tools/WindowsCompileDb, database unittests): put a NOLINTNEXTLINE on them in UnitTests/.

Shaders

  • ShaderCompilerTool runs as a build step on both build systems. It writes x64/<Config>/shaders/{d3d12,vulkan}/shaders.bin, a PSHB v2 layout read by content::get_engine_shaders().
  • shaders.bin.key holds a hash of the format version, the DXC version and all arguments; shaders recompile only when it changes.
  • The HLSL is shared by both backends and compiled with DXC (T17 has the decision).
  • Single sources (#17, 2026-11-14): a constant both C++ and HLSL need goes in CommonConstants.hlsli as PRIMAL_SHARED_CONSTANT uint Name = ...; (C++ reads hlsl::Name through SharedTypes.h; no -D defines). The engine shaders are one table, Engine/Graphics/Shaders/EngineShaders.h (a new engine shader is an id + a row there). The binding contract (register → Vulkan set/binding, the -fvk-*-shift values) is Engine/Graphics/Shaders/ShaderBindings.h, documented for HLSL at the top of Common.hlsli.
  • Layout check: on every run, PrimalShaderCompiler compiles a generated shader with each struct of CommonTypes.hlsli to SPIR-V, reads DXC's offsets and strides, and compares them with offsetof/sizeof (ShaderCompilerTool/ShaderLayoutCheck.cpp); a difference fails the build. A new shared struct gets a row in its shared_structs table, with the usage the engine binds it with (constant or structured buffer).
  • Material shaders are shader packs (#17, 2026-11-15): a manifest (*.shaders, format at the top of EngineTest/TestShader.shaders) lists groups (stage, file, entry point) and their variants (key + -D defines). PrimalShaderCompiler --pack <manifest> <pack> compiles it at build time (same up-to-date check, <pack>.key) into x64/<Config>/shaders/TestShader.shaderpack, with DXIL + SPIR-V on Windows and SPIR-V only on Linux (the distro DXC can't make DXIL, plan doc B13). Format: Engine/Content/ShaderPack.ixx (module primal.shader_pack); load with content::add_shader_pack(blob, size, platform, groups). Variant keys mean one thing everywhere: content::shader_variant_key() (vertex shaders: the elements type; other stages: u32_invalid_id). A new manifest gets a --pack line in ShaderCompilerTool/CMakeLists.txt and ShaderCompilerTool.vcxproj.
  • Shader hot reload (EngineDLL/ShaderHotReload.h, programs that link the compiler): watch_engine_shaders(), watch_shader_pack(manifest, groups, platform), then shader_hot_reload::update() between frames and stop() before the groups go. It compiles in a background job and applies with content::update_shader_group() + graphics::reload_shaders(), which rebuilds every pipeline in place (render items keep their pipeline ids). The renderer test does it: edit TestShader.hlsl or an engine shader while it runs. Not in the editor yet (it renders on its own thread; needs a hook there). Pipelines remember their sources (PsoSource, with shader group serials: content::shader_group_serial()), and the pipeline caches are keyed by shader hashes, not byte code pointers.
  • Debug shader info: SPIR-V gets -Zi (the full source in OpSource + OpLine, for RenderDoc); not -fspv-debug=vulkan*, which crashes DXC 1.10. DXIL PDBs go to x64/Debug/shaders/d3d12/pdb/ (PIX search path).
  • Editor materials hold both bytecodes (#35): ShaderGroup (PrimalEditor/Content/Shader.cs) keeps byte code per GraphicsPlatform; the asset writes -2 where the variant count was (older assets: DXIL only), and upload compiles a missing backend from the stored source. EngineAPI.GraphicsPlatform (export GetGraphicsPlatform) is the backend that runs.
  • Slang (#17 item 7, user 2026-11-15): stay on HLSL/DXC. Revisit for Metal/WebGPU targets or if the material system needs generics/interfaces. #45 measured it (numbers there) and confirmed the decision; the Slang path stays as an opt-in that CI tests (ci.sh slang). What Slang needs from the HLSL: heap casts with the type (Texture2D<float4>(ResourceDescriptorHeap[i]), not Texture2D(...)); its bindless set is fixed (samplers binding 0, resources binding 2), so the contract follows it; Debug SPIR-V embeds the module path and the whole command line, so the source is passed by file name only and nothing per file goes on the command line (hot reload compares byte code hashes).

Runtime environment variables

  • PRIMAL_GRAPHICS=vulkan|d3d12 picks the backend. The default is D3D12 on Windows and Vulkan on Linux.
  • PRIMAL_VULKAN_VALIDATION=0 turns off the validation layers.
  • PRIMAL_JOBS=<n> sets the number of job system workers (0: every job runs on its caller).
  • PRIMAL_VULKAN_PARALLEL_RECORDING=0 / PRIMAL_D3D12_PARALLEL_RECORDING=0 record every draw on the rendering thread.
  • PRIMAL_SHADER_COMPILER=slang compiles every SPIR-V shader with Slang instead of DXC (only in a build configured with -DPRIMAL_ENABLE_SLANG=ON; needs the shader-slang package; issue #45). The up-to-date keys name the compiler, so switching recompiles.
  • Renderer test only: PRIMAL_TEST_EXTRA_SPHERES=<n> adds n spheres (stress test), PRIMAL_TEST_VSYNC=0 starts without vsync.
  • VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 turns on GPU-assisted validation.

Verification standard for a change

  1. The affected configurations build with 0 warnings.
  2. clang-tidy reports 0 warnings.
  3. UnitTests passes, and the relevant EngineTest runs and exits 0. New non-graphics engine code gets unit tests.
  4. For graphics changes, GraphicsTests passes in Debug (validation and sync validation clean), and a new renderer feature gets a test case there when it can be reached without assets.
  5. The user does the visual checks.

Troubleshooting

  • ninja 1.13.2 asserts (Plan::RefreshDyndepDependents ... Assertion 'edge && !edge->outputs_ready()') in an existing build folder after files start importing a module: delete build/<preset> and configure again. It hides compile errors while it happens (the build stops before compiling), so don't trust a build that printed it. Seen 2026-11-12 three times, once with "ninja: warning: premature end of file; recovering" before it; a small project didn't reproduce it.

  • CMake 4.5 (on the Linux machine since 2026-11-12; the CI image still has 4.4.5) adds the standard library's module source (/usr/include/c++/16/bits/std.cc) to the compile database: ci.sh tidy checks only files under the repository (fixed 2026-11-13). Do the same when running run-clang-tidy by hand.

  • Unit tests fail with "Two types are registered as ..." right after switching compilers: the clang and GCC presets write to the same x64/<Config>/, and an incremental build relinks only what changed, so GCC-built programs end up next to a clang-built libPrimalEngine.so (or the other way round). Rebuild with --clean-first (seen 2026-11-21).

  • If the frame rate looks throttled (about 21 fps) or XWayland hangs, compare against a build of HEAD first. It is usually the display session (for example, a locked screen), not the code.

Backend notes

  • Logging: log::debug/info/warning/error(log::Category::x, "format {}", args) (Engine/Core/Log.h, std::format syntax), never printf/OutputDebugString/std::cout (Tools/check_log_usage.py). No trailing \n, no "Vulkan:" prefix: the category says it. error() waits until the message is written, so don't call it per frame. Actors, behaviors and game scripts use log_info("fmt", ...) etc. (category script plus their name). A game DLL in the editor logs into the one log (one engine library); the ring buffer copies file names, since a game DLL's go away with it. In Debug, D3D12 debug layer messages arrive as [d3d12] Debug layer: ... (ID3D12InfoQueue1 callback; don't call SetMuteDebugOutput(TRUE), it stops the callback).
  • Editor without Visual Studio: when VS's COM server isn't registered (or PRIMAL_EDITOR_BUILD=msbuild), the editor builds game projects with MSBuild, edits the .vcxproj for new scripts, opens them in VS Code, and runs the game as a process with its stderr in the log panel (VisualStudio.CommandLine.cs).
  • GUI tests on Windows without the user: post WM_CLOSE to each top-level window of the process after a few seconds (EnumWindows + PostMessage); a kill loses the log's queued lines. PRIMAL_VK_DEBUG_BREAK() and DXCall log before they break. A program calls log::initialize() at start and log::shutdown() at the end; command-line tools whose output a build reads use log::set_console_style(log::ConsoleStyle::plain).
  • Vulkan design: push descriptors stand in for D3D12 root descriptors, and a mutable-descriptor resource heap stands in for the D3D12 descriptor heap. There is reversed Z, an FP16 scRGB swapchain when available, and direct gpass draws (D3D12 too; its ExecuteIndirect path was removed in #3 step 4). Both record more than 512 items in jobs. The reasons for each difference are in the plan doc's "Phase 6x – done" sections.
  • Vulkan functions are loaded, not linked (#18, Engine/Graphics/Vulkan/VulkanLoader.h): VK_NO_PROTOTYPES everywhere, and each function is a global pointer with its Vulkan name, so calls stay ::vkX(...). A function the engine starts to use goes in one of the X-macro lists there (global, instance, device; VK_EXT_debug_utils is loaded only when enabled, so null-check those). Window-system surface functions are fetched in VulkanSurface.cpp with loader::instance_function<>(). VMA gets vkGet*ProcAddr and loads its own.
  • Frame phases: a frame is frame::run(dt, render) (Engine/Core/Frame.ixx). Inside it (game code, jobs, render) entities are created and removed only through game_entity::queue_create()/queue_remove(), which run at the next sync point; the immediate create()/remove()/update_component() assert that they run between frames. A queued entity exists from the next frame.
  • Job system in the frame: transform::update_matrices() runs at the end of script::update() and before each graphics::render_frame(); after it, render preparation reads transforms from several threads, so nothing there may write to a component. Game code writes transforms directly (transform::apply()); it runs one object at a time on the frame thread, which makes that safe (parallel game code needs queued writes: Docs/Ecs.md 9.6).
  • Behavior lifetime (Engine/EngineAPI/Actor.h; game scripts: "Scripts" above): constructor → begin_play() at the next sync point → update(dt) each frame → late_update(dt) after every update and the game systems → end_play() when the behavior or its actor goes (only after begin_play()) → destructor. The editor runs no frames, so nothing begins play there.
  • ECS (Engine/ECS/Ecs.h, Docs/Ecs.md section 7): game_entity::world() is the game world; its ids are the entity ids. Components are plain data (trivially copyable, alignment <= 16); const T in a query or system means read-only. get<T>() reads, write<T>() marks the chunk as changed (versions per chunk and component), locate() for several accesses to one entity. Structural changes are immediate only between frames or at the sync point; inside a frame, game_entity::queue_add_component<T>()/queue_remove_component<T>() (or world.queue_*). Systems: world.add_system<const A, B>(name, group, [](const ecs::ChunkView &chunk) {...}), run by run_systems(group); a system's function runs on several threads at once. Transforms are six components (transform::Position, ... in Components/Transform.h) plus Parent/HierarchyDepth on children; position, rotation and scale are relative to the parent. Derived ones (local frame = world axes, matrices) are current after transform::update_matrices() (roots, then children level by level, then frames and inverses), and readers compute them before that. position() etc. are world space, local_* relative to the parent. At most 64 component types (u64 masks).
  • New game classes: the editor's New Class dialog (PrimalEditor/GameDev/NewClassDialog.xaml.cs) writes a behavior, actor class, part class or game script from its template and adds it to the game's .vcxproj.
  • Actors (Engine/EngineAPI/Actor.h, Docs/Actors.md sections 3-8 and 18): an actor owns a part tree (each part one entity with actor::ActorOwner, attached like the tree; the first part is the root) and behaviors. Every class derived from Actor, Part or Behavior is marked PRIMAL_ACTOR()/PRIMAL_PART()/PRIMAL_BEHAVIOR(); one the generator can't see (a template, a local class) says PRIMAL_ACTOR_CLASS(Self, Base) and isn't registered. spawn() is immediate between frames and at the sync point, queued inside a frame; destroy()/remove_part() are immediate between frames only; add_part()/add_behavior() are immediate only, queue_add_*() inside a frame. Actors begin play at the sync point (behaviors first), tick in spawn order after the scripts (only those that override update()), and are destroyed by actor::destroy_all() at the game's shutdown. Never remove an actor's entity with game_entity::remove() (asserts); removing a plain entity detaches actors attached to it.
  • Render parts and the scene (Engine/EngineAPI/RenderParts.h, RenderComponents.h, Engine/Graphics/Scene.h; Docs/Renderer.md sections 3 and 9): MeshPart, the light parts and CameraPart write render:: components on their entity; plain entities may have them too. They are the only way to draw something: the renderer has no light, camera or render-item objects of its own, and no graphics::Camera/Light handles. Call graphics::scene::prepare() once a frame in the render function before the surfaces render (it rebuilds the light sets from the light components and keeps one backend render item per MeshRenderer entity), and again after removing entities and before destroying the content they used. A frame is graphics::render_frame() over SurfaceFrame{surface, FrameInfo{.light_set_key, .camera_entity, ...}}s (one wait, submission and present for all of them): it adds the visible meshes and their LOD (distance to the camera). A light set is the lights whose components name its key.

Pages 19

View all

Clone this repository