Multithreading

Chuck Smith edited this page 2026-11-25 01:11:19 +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.

Multithreading and logging: design proposal

Issues #1 (job system) and #19 (logging). Status (2026-11-11): the decisions in section 8 are made. Steps 1 and 2 of section 9 (logging) are done on Linux, not yet built by MSVC; the job system is not started.

1. Goals

  • Every core can do frame work, and long work (loading, pipeline creation) never stalls a frame.
  • One set of rules that says which thread may touch which data, so that new systems are written to them.
  • A threading model that #3 (backend unification) can build on without being redone.
  • One logging API that is safe from any thread and reaches the terminal, the debugger and the editor.

Not goals for #1: a render thread, parallel command recording and asynchronous uploads. They are designed here (section 5) and built with #3, because they change the same backend code that #3 restructures.

2. Where the code is today

Area Today What stands in the way of threads
Frame loop script::update(dt), then surface.render(info) per surface, one after another Nothing is split into phases
Scripts Serial loop over entity_scripts set_position() etc. push into one shared transform_cache (+ cache_map)
Transforms transform::update() applies the cache serially get_transform_matrices() computes a matrix on first read and sets has_transform: a read that writes
Entities Free lists and generations, no locks Create and remove from one thread only
Render prep gpass::prepare_render_frame() fills one global frame_cache One cache, one resource_barriers, one bump-allocated constant buffer per frame
Recording One command buffer per frame (gfx_command), submit + present per surface Single recorder
Content add_mesh/texture/material/render_item are thread-safe (module mutexes) Fine as it is
Uploads Submit, then wait for the GPU, per upload Blocks the calling thread; Vulkan shares the graphics queue under a lock
Threads in use 14 raw std::threads in the renderer test, one per cube face in ContentTools No pool
Editor Every EngineDLL call takes one global utl::TicketMutex (a spin lock) A thread that spins while the holder waits for jobs burns a core
Logging Five mechanisms (see #19); the Vulkan debug callback can run on any thread No common sink, no locking

3. Threading model

Threads

  • Frame thread. The thread that runs the frame: main() in a game, the editor's caller of RenderFrame in the editor. It pumps OS events, runs the phases below, and works on jobs whenever it waits.
  • Workers. A fixed pool, by default hardware threads − 1 (23 on the 24-thread desktop). They only run jobs.
  • Logger thread. One small thread that writes log records to the sinks (section 6).

No thread is special apart from the OS event pump, which stays on the thread that created the windows.

A frame is a list of phases

Each phase starts jobs and waits for them (the frame thread helps). Within a phase the rules in section 4 say what may be read and written; between phases everything is quiet, and that is where structural changes happen.

  1. Input and events (frame thread only).
  2. Sync point: entities created and removed, queued commands from the previous frame applied.
  3. Game update: scripts. They read the previous frame's transforms and write into caches.
  4. Transform update: caches applied, world matrices of changed transforms computed. After this phase, transforms are read-only until the next frame.
  5. Render preparation: per surface, visibility and LOD, per-object and material data.
  6. Recording and submit.

Background work (loading, pipeline creation) runs across phases on a separate lane and hands its results over at the sync point.

Stage 2, with #3: frame packets

Phase 5 ends by producing a frame packet: everything recording needs (camera matrices, per-object data, the render item list, light data), copied or bump-allocated for that frame. Recording then reads only the packet, never the component arrays. That is what later allows the game update of frame N+1 to run while frame N is recorded, at the cost of one frame of latency. #1 does not build it, but the first users in #1 are written so that render preparation is the only code that reads component data.

4. Data access rules

Data Phase 3 (scripts) Phase 4 (transforms) Phases 5–6 (render) Background jobs
Entity lists (create/remove) queue a command no no queue a command
Transforms read old values; write through the cache written by the transform jobs read only no
Script objects own script only no no no
Input state read read read no
Renderer content (meshes, textures, materials, render items) add/remove (locked, as today) same read add/remove
Lights, cameras set parameters no read no

Consequences for the existing code:

  • Transform cache per worker. script.cpp's transform_cache becomes one cache per worker (jobs::worker_index()), merged in phase 4. A script writes only its own entity's transform, so entries never collide.
  • No lazy matrices. Phase 4 computes the matrices of every changed transform; get_transform_matrices() becomes a pure read. read_write_flag goes away: phase 4 clears changes_from_previous_frame at its start. (Step 6 kept read_write_flag: see there.)
  • Entity commands. Creating or removing an entity from a script or a background job goes into a queue that the sync point runs. (Today it is immediate, which only works single-threaded.)

5. Job system

Own code or a library

Recommendation: own code, about 500 lines plus tests.

  • The engine's needs are small: a pool, counters, parallel_for, two lanes.
  • It fits the code base: C++23, the naming and build rules, no new download step on two build systems.
  • enkiTS (zlib license) is the alternative I would pick if we wanted a library: small, proven, pinned tasks, priorities. It costs a dependency on both build systems and a foreign API style at every call site. Taskflow is larger than we need.
  • stdexec (the reference implementation of C++26 std::execution) is a way to compose asynchronous work, not a job system: it still needs a pool underneath. It is heavy on compile time and its API follows a standard the project doesn't use yet (C++23 only). The pool can get a scheduler adapter for it once std::execution ships in all three compilers.

The risk of own code is subtle bugs. The answer is ThreadSanitizer in CI from the first commit (section 7) and a simple first implementation.

Shape

  • Fixed pool, created by jobs::initialize(), joined by jobs::shutdown().
  • One queue per worker with stealing. First version: a short mutex per queue. A lock-free deque (Chase–Lev) can replace it behind the same interface if profiling shows contention; it is not worth its risk before that.
  • A job is a function pointer plus 48 bytes of inline data. No heap allocation per job. Larger captures are a compile error; pass a pointer.
  • Counters instead of handles. A job is started against a jobs::Counter; jobs::wait(counter) returns when it reaches zero, and runs other jobs while it waits. No futures.
  • No fibers. A waiting job runs other jobs on its own stack. Rules that follow: never wait while holding a lock, and keep wait depth shallow (phases wait; leaf jobs don't).
  • Two lanes. Frame jobs are short and are always taken first. Background jobs may take long or block on files; at most half of the workers run them at once, so a load never starves a frame.
  • Jobs are noexcept. The engine doesn't use exceptions across module boundaries; a throwing job terminates.
  • Inline mode. With zero workers, every job runs immediately on the caller, in order. PRIMAL_JOBS=0 selects it at run time. Unit tests of other systems use it, and it is the first thing to try when a bug looks like a race.

API sketch (a named module: Engine/Core/Jobs.ixx, import primal.jobs;)

namespace primal::jobs
{

enum class Lane : u8 { frame, background };

class Counter; // non-copyable; must outlive its jobs

auto initialize(u32 worker_count = u32_invalid_id) -> bool; // default: hardware threads - 1
auto shutdown() -> void;

[[nodiscard]] auto worker_count() -> u32; // workers + the frame thread
[[nodiscard]] auto worker_index() -> u32; // 0 .. worker_count() - 1, for per-thread data

template <typename F>
auto run(Counter &counter, F &&function, Lane lane = Lane::frame) -> void;

auto wait(Counter &counter) -> void; // helps: runs other frame jobs meanwhile

// Calls function(begin, end) for [0, count) in batches, and returns when all are done.
template <typename F>
auto parallel_for(u32 count, u32 batch_size, F &&function) -> void;

}

Typical use:

jobs::parallel_for(count, 256, [&](u32 begin, u32 end) {
    for (u32 i{begin}; i < end; ++i)
    {
        calculate_transform_matrices(changed[i]);
    }
});

What each later feature needs from it (built with #3, listed so the API is enough)

  • Per-thread command recording. worker_index() selects a command pool (Vulkan) or command list (D3D12) per worker and frame. The Vulkan backend uses dynamic rendering, so a pass is split either into secondary command buffers (VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT) or into several primaries with the suspend/resume flags; D3D12 executes its lists in order. The choice belongs to #3.
  • Per-surface jobs. frame_cache, resource_barriers and the constant buffer allocation become members of a per-surface frame context instead of globals.
  • Asynchronous uploads. An upload returns at once; the resource carries the fence value at which it becomes usable, and render preparation skips items that aren't ready. Vulkan gets a transfer queue where the device has one.
  • Background pipeline creation (#10): background-lane jobs; items whose pipeline isn't ready are skipped.

The editor

  • InitializeEngine starts the pool; ShutdownEngine stops it.
  • The thread that calls RenderFrame is the frame thread for that call and helps with its jobs.
  • The global TicketMutex in EngineDLL becomes a std::mutex: a spin lock is wrong once the holder can wait for jobs. Lock scope stays as it is for now.
  • Nothing here needs a specific UI toolkit, so the Avalonia constraints hold (C ABI, no thread affinity beyond window creation).

6. Logging (#19)

API (Engine/Core/Log.h)

namespace primal::log
{

enum class Level : u8 { debug, info, warning, error };
enum class Category : u8 { core, graphics, vulkan, d3d12, content, input, script, tools };

template <typename... Args>
auto info(Category category, std::format_string<Args...> format, Args &&...args) -> void;
// debug(), warning(), error() alike. warning() and error() record the source location.

auto flush() -> void; // returns when every record so far has reached the sinks

}

How a message travels

  1. Format on the calling thread into a thread-local 1 KiB buffer (longer messages are cut and marked). The template only packs the arguments; one non-template function in Log.cpp calls std::vformat_to, so <format> costs compile time in one place.
  2. Push a record (level, category, time, thread index, frame number, text) into a bounded queue. If it is full, the caller waits: records are never dropped.
  3. The logger thread takes records in order and gives them to the sinks. Slow sinks (a file, a terminal) never stall a worker.
  4. error() flushes before it returns, and so do PRIMAL_VK_DEBUG_BREAK, DXCall failures and assert handlers, so the last line before a crash is on disk.

A dedicated thread rather than a job, because logging must work before the pool exists and while it shuts down.

Sinks

  • stderr, colored when it is a terminal.
  • Debugger (OutputDebugStringA), Windows only.
  • File (primal.log next to the executable, the previous run kept as primal.1.log).
  • Ring buffer in memory: the last few thousand records, for the editor and for tests.

Editor

Recommendation: the editor pulls. One C function, DrainLog(buffer, size), copies the records since the last call as UTF-8 with level and category; the editor calls it from a UI timer. Compared with a callback from the logger thread, there is no native-to-managed call on a foreign thread, nothing to unregister when the DLL unloads, and the same code serves WPF now and Avalonia later.

Other points

  • Compile-time level: PRIMAL_LOG_LEVEL removes debug() calls from Release; errors stay in shipping builds.
  • Scripts call the same API with Category::script; EntityScript gets a helper that adds the script's name.
  • Tests: GraphicsTests already counts validation messages; the ring buffer lets unit tests check that an operation logged an error.
  • Migration: vulkan::log_message(), shader_log(), the OutputDebugString calls and the test fprintfs are replaced by category. The D3D12 and Win32 ones are edited blind on Linux.

7. Tools

  • ThreadSanitizer: a linux-tsan preset (-fsanitize=thread, clang) and a CI job that runs UnitTests under it. GraphicsTests under TSan is tried too, but driver threads (lavapipe) may need a suppression file, as LSan did.
  • Profiling: Tracy is the likely choice, later. The job system gets one hook now (a named scope around each job) so that adding it doesn't touch call sites.
  • Unit tests for the job system: inline mode, counters, nested waits, parallel_for coverage (every index exactly once), stealing under load, background lane limit, start and stop many times.

8. Decisions to make

All decided by the user, 2026-11-11. 1, 2, 3, 5, 6 and 7 as recommended. 4: the full features stay with #3, but #1 ends with a Vulkan-only prototype of parallel recording (step 7 in section 9), because the threading should be built in from the start, before there is a lot to render.

# Question Recommendation
1 Own job system or enkiTS? Decided. Own code
2 Fibers? Decided. No; waiting helps instead. Scripts that wait can use C++20 coroutines later.
3 Scripts in parallel? Decided. Not yet: keep the script loop serial in #1, but move it to the per-worker cache so that turning it on later is a one-line change. Parallel scripts change what a script may do (touch only its own entity, entity create/remove deferred), and with a handful of scripts there is nothing to gain today.
4 Render thread and parallel recording in #1? Decided. With #3, plus a Vulkan-only prototype of parallel recording at the end of #1.
5 How does the editor get log messages? Decided. It pulls (DrainLog)
6 Order of work Decided. Logging first: it is smaller, independent, and the job system uses it.
7 Entity create/remove from scripts becomes deferred to the sync point Decided. Yes, even while scripts are serial: it is the rule every later step relies on. It changes behavior: an entity created in update() exists from the next frame.

9. Order of work

Each step is a commit-sized piece that leaves both builds working.

  1. Log core: API, queue, logger thread, stderr and debugger sinks, ring buffer, unit tests. Done on Linux 2026-11-11 (Engine/Core/Log.h/.cpp, UnitTests/LogTests.cpp). Differences from section 6:

    • Messages may be 2 KiB, not 1 KiB (Vulkan validation messages are long), and are formatted into a record on the caller's stack.
    • A record has no frame number yet: there is no frame counter until the phases exist (step 6).
    • log::debug() below the compiled level does nothing, but its arguments are still evaluated: keep expensive expressions out of the argument list.
    • Before log::initialize() and after log::shutdown() a message is written by its caller, so tools and tests can log without the thread.
  2. Log migration: replace the five mechanisms; file sink; DrainLog in EngineDLL and the editor's log panel (Windows, blind). Done on Linux 2026-11-11. Notes:

    • Command-line tools that a build system reads (PrimalShaderCompiler) use ConsoleStyle::plain, and the shader compiler's output is logged line by line, so error lines arrive as the compiler wrote them.
    • DrainLog(buffer, size, cursor) returns packed messages (a 40-byte header, then text and file name); the editor calls it from a 250 ms UI timer.
    • The log's state is a static object: at exit it stops the thread and writes what is queued. Messages logged after that (by static destructors) go straight to stderr. A DLL must still call log::shutdown() before it is unloaded.
    • Tools/check_log_usage.py keeps direct output calls out (ci.sh checks).
    • Tried as a named module on 2026-11-11 and reverted. It built everywhere, but GCC needs every import after the last #include, so headers, macros and (later) game scripts could not log without wrappers. Logging stays a header; the job system, which only .cpp files call, is to be the first module. The rules are in CLAUDE.md, "Modules".
    • Left for later: a helper for game scripts, and the D3D12 debug layer's own messages (they still go to the debugger only).
  3. TSan preset and CI job. Done on Linux 2026-11-12. -DPRIMAL_ENABLE_TSAN=ON, preset linux-tsan (clang Debug, writes to x64/Debug/), ci.sh tsan and a tsan job in linux.yml. It runs the unit tests and the graphics tests, with halt_on_error=1. Notes:

    • On lavapipe (the CI image) TSan reports races inside the driver and LLVM, which aren't built with it: Tools/CI/tsan.supp suppresses them by library. Add a library there only after checking that no engine frame is involved.
    • It found one real bug at once, a lock-order inversion between a descriptor heap and the deferred releases (plan doc B12), fixed in both backends. On RADV the path didn't run, which is why it showed only in CI.
  4. Job system core with unit tests, TSan clean. Done on Linux 2026-11-12: Engine/Core/Jobs.ixx (export module primal.jobs;) + Jobs.cpp, 12 tests in UnitTests/JobTests.cpp. Differences from section 5:

    • GCC 16 refused initialize(u32 worker_count = u32_invalid_id) at first: the constant had internal linkage, and an exported declaration may not name it (-Wexpose-global-module-tu-local). The *_invalid_id constants in PrimitiveTypes.h are now inline constexpr.
    • A job is a function object of at most 48 bytes that is trivially copyable (compile error otherwise): capture by reference or pass a pointer. That rules out owning captures such as a std::string.
    • The rule "never wait on background work inside a background job" isn't needed: a background job that waits gives its slot back and helps with background jobs meanwhile (with one worker, it would deadlock otherwise). The frame thread and frame jobs still only help with frame jobs.
    • A thread outside the pool may run() and wait(); its jobs go to the frame thread's queue, it blocks instead of helping, and its worker_index() is u32_invalid_id.
    • shutdown() runs every queued job (all workers may then run background jobs) before it joins.
    • Before initialize(), after shutdown() and with PRIMAL_JOBS=0 everything is inline, as planned; the engine doesn't call initialize() yet (that is step 5).
    • Checked: clang and GCC, Debug and Release, 200 runs of the suite in each Release build and 30 under TSan.
  5. First users, measured before and after:

    • the renderer test's 14 loader threads and ContentTools' cube-face threads become background jobs;

    • transform phase: per-worker caches, eager matrices, parallel_for;

    • prepare_render_frame(): per-object data filled with parallel_for (both backends). Done on Linux 2026-11-12. What was done:

    • Who starts the pool: the game's main() (MainLinux.cpp, MainWin32.cpp), EngineDLL (InitializeEngine/ShutdownEngine; the editor's UI thread is the frame thread), EngineTest's main() and GraphicsTests' main(), each next to log::initialize()/shutdown(). UnitTests stays inline, except in the tests that start a pool themselves.

    • Loading: the renderer test's 14 loader threads are background jobs (EngineTest/RenderItem.cpp). ContentTools keeps its cube-face threads: it doesn't link the engine library at all, and it is a DLL the editor loads, so it would need its own pool started and stopped inside the DLL, all written blind. Revisit with #12.

    • Transforms: transform::update_matrices() computes the matrices of the transforms that changed (a list, each entry once) with parallel_for. script::update() calls it at the end of the transform phase, and graphics::Surface::render() calls it before rendering (for transforms changed elsewhere, e.g. the editor; a no-op after the first surface). After it, get_transform_matrices() only reads; its lazy computation stays as a fallback for other callers. Script transform caches are per worker (jobs::worker_index()), applied one after another; scripts still run serially.

    • Render preparation: fill_per_object_data() (both backends) lists the entities once, allocates one block in the constant buffer, and fills it with parallel_for.

    • Measurements (clang Release, 24 hardware threads, RADV; benchmarks are skipped test cases, run with --no-skip, see the test files):

      What One thread (PRIMAL_JOBS=0) Before (HEAD) After (24 threads)
      Renderer test content loading 170-185 ms 98-107 ms (a thread per asset) 101-106 ms
      Transform phase, 100,000 entities: matrices 1.6 ms (computed lazily, serially) 0.36-0.47 ms
      Transform phase, 100,000 entities: applying the caches 1.6 ms same same (serial)
      fill_per_object_data(), 1,526 objects 34 us same 37-48 us
      A frame with 1,526 objects, one view 0.83-0.90 ms same 0.88-0.90 ms
      • Matrices scale to about 8 threads, then stop (memory bound: ~15 MB written per frame). Batches of 1024 (16 us of work each); batches of 256 were about half as fast.
      • Render preparation doesn't gain at today's sizes: an object takes ~22 ns, so 1,500 objects are 34 us, less than waking the sleeping workers costs. Its batch size is 1024, so up to 1,024 objects run on the calling thread and nothing is lost; the constant buffer (1 MB a frame) limits a frame to ~3,000 objects anyway. Gains need bigger work per phase (frame packets, #3) or workers that are already awake (spinning briefly before sleeping): left for step 7 and #3.
      • Loading is limited by the work itself, not by the threads: background jobs (at most 11 at once) match a thread per asset.
  6. Phases made explicit in engine_update() and the renderer test; entity command queue; TicketMutex → std::mutex in EngineDLL. Done on Linux 2026-11-12. What was done:

    • primal.frame (Engine/Core/Frame.ixx + .cpp), the second named module. frame::run(dt, render) runs phase 2 (the sync point: game_entity::process_queued_commands()), 3 (script::update_scripts()), 4 (script::apply_transform_changes(): the per-worker caches, then transform::update_matrices()) and calls render as phases 5-6. Phase 1 (platform::pump_events()) stays in each main loop. It keeps frame::phase() (atomic, any thread may ask) and frame::index(). Callers: the game's engine_update(), the renderer test and the graphics tests' Scene. script::update() (both phases) stays for tests.
    • Entity command queue: game_entity::queue_create(info, callback, user_data) and queue_remove(id) from any thread at any time; they run at the next sync point in queue order, with copies of the init infos (also the geometry's material ids). A removal of an entity that is already gone is skipped. create(), remove() and update_component() assert in Debug that they run between frames or at the sync point (frame::structural_changes_allowed()). Before this, a script that removed its own entity erased from the script list while it was being iterated.
    • TicketMutex → std::mutex in EngineDLL. The editor calls in from two threads: its UI thread and a render thread that calls RenderFrame() (RenderSurfaceHost.cs), which holds the lock for a whole frame; the spin lock kept the other thread busy meanwhile. Engine/Utilities/Threading.h is now unused.
    • Not done, on purpose:
      • read_write_flag stays (section 4 said phase 4 would clear the change flags at its start). Changes made between frames (the editor, new entities) would be cleared before render reads them, and a frame that renders nothing would lose them. The flags are cleared after someone has read them, as before.
      • The editor doesn't use frame::run(): it has no game update, and renders on its own thread.
      • Log records don't carry the frame number yet (section 6): DrainLog's header (and the editor's C#) would change; frame::index() is there when it is wanted.
  7. Prototype: parallel command recording on Vulkan. A per-surface frame context in place of the gpass globals, a command pool per worker and frame, and the gpass draws recorded by jobs. Measured with a scene of many render items (the graphics tests can make one in memory). Vulkan only: its purpose is to settle the design, and #3 redoes it for both backends. Done on Linux 2026-11-12. What was done:

    • Recording in jobs: gpass::depth_prepass() and gpass::render() record their draws through record_pass(): up to 512 items into the primary command buffer as before; more, in batches of 512, each into a secondary command buffer that a job records (jobs::parallel_for), executed by the primary in batch order inside one vkCmdBeginRendering with VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT. Each batch starts with the bindings a command buffer needs (resource heap, global root parameters, viewport and scissor, which secondaries don't inherit). The draw order is unchanged.

    • Command pools per thread and frame (VulkanCore.cpp, ThreadCommandPools): one pool per job system thread and frame, plus one for a thread outside the pool (the editor's render thread); created by core::prepare_thread_command_pools() before the jobs start, reset when that frame's fence has been waited for, buffers reused. core::begin_secondary() hands a job a begun secondary of its own thread's pool.

    • The gpass cache is per surface (frame_caches, by surface id) instead of one global. The other per-frame state (barriers, constant buffer) is still shared: surfaces render one after another.

    • Two parallel passes per frame, not one: the gpass binds the light culling buffers, which delight::cull_lights() may recreate (when the surface size changes) while it records; so the gpass batches are recorded after it. Separating the resize from the recording would allow one pass for both.

    • PRIMAL_VULKAN_PARALLEL_RECORDING=0 records serially, for measurements.

    • Measured (clang Release, RADV, 24 threads; GraphicsTests benchmark "a frame with 6400 render items": 100 entities of 64 box submeshes, one view):

      Serial recording Parallel, batches of 512
      Whole frame 3.2-3.4 ms 2.23-2.27 ms
      Depth prepass recording (incl. render preparation) 2.38 ms 1.82 ms
      Gpass recording 0.92 ms 0.23 ms
      prepare_render_frame() 1.49 ms 1.64 ms

      Batches of 64: 3.2 ms (no better than serial); 128: 2.5 ms; 256: 2.35 ms; 1024: 2.3 ms. PRIMAL_JOBS=0 matches serial recording (3.3-3.4 ms).

    • Findings for the design note (step 8): recording itself goes from ~1.8 ms to ~0.42 ms (4x). What is left is render preparation, ~240 ns per item and serial apart from the per-object data: the content queries (get_vulkan_render_item_ids, get_items, get_views, get_materials), the material data loop, and a mutex lock per item in ConstantBuffer::range(). That is the next thing to make parallel or cheaper, and what a frame packet (#3) would be built from.

    • D3D12 counterpart, done on Windows 2026-11-13 (plan doc "Windows session 2026-11-12", second half):

      • D3D12 drew through ExecuteIndirect, which records almost nothing on the CPU but was 2.5-4x slower on the GPU (RX 6800 XT); direct draws are now the default (PRIMAL_D3D12_DRAW_INDIRECT=1 for the old path).
      • Direct draws are recorded like Vulkan's: batches of 512 in jobs, each into a command list of its own (allocator per thread and frame); the frame's list is closed and continued in another list around them, and all are executed in order in one ExecuteCommandLists. PRIMAL_D3D12_PARALLEL_RECORDING=0 turns it off.
      • The ConstantBuffer::range()/gpu_address() mutex named above is gone on both backends (lock-free offset), and the per-frame constant buffer grows with the item count (reserve()); it was a fixed 1 MB, and more than ~4,000 objects crashed both backends.
      • Measured with the renderer test (PRIMAL_TEST_EXTRA_SPHERES=6400, 4 windows, Release): recording per window 895 us serial → 333 us parallel; the frame stays at ~14.9 ms on both backends because that scene is GPU-bound.
  8. Design note for #3: frame context per surface, per-worker command pools, asynchronous uploads, updated from what steps 5 to 7 showed. Done 2026-11-12: Docs/RendererThreading.md (frame context per engine frame and surface context per surface, frame packet, recording, asynchronous uploads, the editor's render thread, an order of work for #3).

"Done" for #1 is steps 3 to 8 with the measurements recorded in the issue; for #19, steps 1 and 2.

Pages 19

View all

Clone this repository