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 ofRenderFramein 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.
- Input and events (frame thread only).
- Sync point: entities created and removed, queued commands from the previous frame applied.
- Game update: scripts. They read the previous frame's transforms and write into caches.
- Transform update: caches applied, world matrices of changed transforms computed. After this phase, transforms are read-only until the next frame.
- Render preparation: per surface, visibility and LOD, per-object and material data.
- 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'stransform_cachebecomes 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_flaggoes away: phase 4 clearschanges_from_previous_frameat its start. (Step 6 keptread_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 oncestd::executionships 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 byjobs::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=0selects 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_barriersand 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
InitializeEnginestarts the pool;ShutdownEnginestops it.- The thread that calls
RenderFrameis the frame thread for that call and helps with its jobs. - The global
TicketMutexin EngineDLL becomes astd::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
- 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.cppcallsstd::vformat_to, so<format>costs compile time in one place. - 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.
- The logger thread takes records in order and gives them to the sinks. Slow sinks (a file, a terminal) never stall a worker.
error()flushes before it returns, and so doPRIMAL_VK_DEBUG_BREAK,DXCallfailures andasserthandlers, 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.lognext to the executable, the previous run kept asprimal.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_LEVELremovesdebug()calls from Release; errors stay in shipping builds. - Scripts call the same API with
Category::script;EntityScriptgets a helper that adds the script's name. - Tests:
GraphicsTestsalready counts validation messages; the ring buffer lets unit tests check that an operation logged an error. - Migration:
vulkan::log_message(),shader_log(), theOutputDebugStringcalls and the testfprintfs are replaced by category. The D3D12 and Win32 ones are edited blind on Linux.
7. Tools
- ThreadSanitizer: a
linux-tsanpreset (-fsanitize=thread, clang) and a CI job that runsUnitTestsunder it.GraphicsTestsunder 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_forcoverage (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.
-
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 afterlog::shutdown()a message is written by its caller, so tools and tests can log without the thread.
-
Log migration: replace the five mechanisms; file sink;
DrainLogin 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) useConsoleStyle::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.pykeeps 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
importafter the last#include, so headers, macros and (later) game scripts could not log without wrappers. Logging stays a header; the job system, which only.cppfiles call, is to be the first module. The rules are inCLAUDE.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).
- Command-line tools that a build system reads (
-
TSan preset and CI job. Done on Linux 2026-11-12.
-DPRIMAL_ENABLE_TSAN=ON, presetlinux-tsan(clang Debug, writes tox64/Debug/),ci.sh tsanand atsanjob inlinux.yml. It runs the unit tests and the graphics tests, withhalt_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.suppsuppresses 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.
- On lavapipe (the CI image) TSan reports races inside the driver and LLVM, which aren't built with it:
-
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 inUnitTests/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_idconstants inPrimitiveTypes.hare nowinline 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()andwait(); its jobs go to the frame thread's queue, it blocks instead of helping, and itsworker_index()isu32_invalid_id. shutdown()runs every queued job (all workers may then run background jobs) before it joins.- Before
initialize(), aftershutdown()and withPRIMAL_JOBS=0everything is inline, as planned; the engine doesn't callinitialize()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.
- GCC 16 refused
-
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 withparallel_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'smain()and GraphicsTests'main(), each next tolog::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) withparallel_for.script::update()calls it at the end of the transform phase, andgraphics::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 withparallel_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 objects34 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.
-
-
Phases made explicit in
engine_update()and the renderer test; entity command queue;TicketMutex→std::mutexin 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, thentransform::update_matrices()) and callsrenderas phases 5-6. Phase 1 (platform::pump_events()) stays in each main loop. It keepsframe::phase()(atomic, any thread may ask) andframe::index(). Callers: the game'sengine_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)andqueue_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()andupdate_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::mutexin EngineDLL. The editor calls in from two threads: its UI thread and a render thread that callsRenderFrame()(RenderSurfaceHost.cs), which holds the lock for a whole frame; the spin lock kept the other thread busy meanwhile.Engine/Utilities/Threading.his now unused.- Not done, on purpose:
read_write_flagstays (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.
-
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()andgpass::render()record their draws throughrecord_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 onevkCmdBeginRenderingwithVK_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 bycore::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=0records serially, for measurements. -
Measured (clang Release, RADV, 24 threads;
GraphicsTestsbenchmark "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=0matches 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 inConstantBuffer::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=1for 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=0turns 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.
- D3D12 drew through
-
-
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.