Status: a design. One Switch game's measurements (about 2,100 draws a present) showed what remains after the share lock's cheap cuts (the write tracking with no lock, the range generations of the constant buffer and vertex entries, the kept targets' read checks once a present):
perf c2c showed only the lock's own word
as a line that the two cores fight over.So the remaining takes are the cost, and they are takes of state that both threads change at each draw.
A map of the per-draw calls under the lock (vk_surf_use, target_written, render_draw_main, vk_query_draw, stage_set_, and the lookups vk_tex_recheck, vk_buf_get_storage, vk_buf_get_window, vk_shader_get, vk_table_words, vk_tex_view, vk_rec_new_set) found 13 objects that both threads write in one split run:
g_wseq and Surf.wseq; g_surf_gen and Surf.wgen; g_take_gen and Surf.take_seen (surface.c's
vk_surf_wrote, take_changed).g_drawn, g_ndrawn, in_drawn, drawn_from, g_drawn_pages) and a target's draw_* fields
(vk_rt_drawn).fb_snap, fb_draw and fb_gen (texture.c).Surf.stage through vk_surf_read_covered, which takes no lock, and g_written's counts.g_pipeline; g_table; g_frame_sets.g_vk_drawn, g_stats's slot counts, g_predraw_stats, g_draws.Of these, only a surface's layout, stage and access are deferred to the splice and checked there (surf_use_splice).
On the GPU, the renderer thread's half of a split run comes before the worker's half. The shared counters do not follow that order:
wseq (the write-back order,
rt_superseded, rt_take_pixels, the discard check in render.c's load_op) can then pick the older pixels.wgen and the take count) see neither the rest of the renderer
thread's half nor anything that checks them at the join. A texture that the worker samples can keep a copy made
before the renderer thread's half drew its target.Neither shows in a default run, as draw_batches is 0. Both must be fixed before the split goes on by default.
Each thread owns what its half changes, and the renderer thread applies the worker's changes at the join, in the order of the GPU:
t_sv does for the layouts today.CNT pattern), folded in at the join: g_vk_drawn,
the slot counts, g_draws, g_frame_sets, g_tex_checks, the buffer cache's LRU stamps.The journal is right only when the worker's half reads nothing that the renderer thread's half writes, as the worker's half can't see those writes before the join. The split chooses its point so:
The batch probe already counts such dependencies ("sample a target an earlier batch of the present wrote"): in the other game's scene they were a few percent of the draws.
Each step keeps the picture of the base run (screenshots at the same frame) and is measured with draw_timing=1:
the share lock's takes a draw, the ns a draw on each thread, and the fps in A/B/B/A runs.
wseq follows the GPU order (a check that compares, at each
join, the numbers of the targets of both halves), and no take of the lock in target_written on either thread.Built: step 1 (vk_drawn, the feedback statistics), step 2 (the journal), step 3 (built as a wait, not a cut: a worker draw that reads a target of the renderer thread's half waits for that half's end, which needs no rollback), and step 4's lock-free calls (the texture table, new sets, a target's read note once a present). In one Switch game (about 2,100 draws a present) the worker's journal held 687 writes a present with none applied early, and the worker waited for the other half 1.1 times a present.
The share lock's takes a draw went from about 12 to 6.5 on the renderer thread and 5.7 on the worker, and its waits from 0.93 to 0.45 ms a present. The split did not gain from it: in A/B runs it stayed about 6 fps under the base (63.7 against 69.3 fps). A draw on the renderer thread still costs about 44% more than in base (4,617 against 3,205 ns), and in parts that take no lock:
g_dyn, the index buffer, the sets), and the worker does at each run's start: about 70
splits a present each emit the whole state again.g_fs_last, the kept draws) then compare with a draw many records back, and hit less.Then the join kept the worker's record of the bound state (g_dyn, the index buffer), and a renderer-thread draw cost what it does in base (resolve, setup and binds 1,058, 1,874 and 352 ns, against 1,058, 1,809 and 338). Most of the 44% was the state bound again after each join, and its effect on the caches after it. The split still lost, in all three games measured, A/B/B/A with the same build:
| Game | Base fps | Split fps |
|---|---|---|
| One Switch game's town | 70.6, 68.6, 69.2 | 64.0, 63.7, 63.8 |
| Another's open world | 101.6, 102.7 | 84.4, 83.0 |
| A third's race (its windows) | 290 to 317 | 250 to 300 |
In none of them is the renderer thread what limits the frame: in the first it is busy about 10 of 14.5 ms, and the GPU
waits about 4 ms a frame for submissions. The worker's draws reach the ring only at each join, in bursts, where in
base they go as they are recorded; that is the likely cost, not measured yet. So draw_batches stays 0. The split
can gain only in a scene that the renderer thread limits (the 6,860-draw scene above).
These are costs of cutting one stream into two halves, not of the lock. They fall when a split's runs are longer: the scene where the split gained had about 6,860 draws a present. The next steps, if the split goes on, are runs cut where the state changes anyway (a pass or a program change), not at the half; and binds the join keeps when both halves end in the same state.
Made from docs/dev/parallel-draw-batches.md at 69237645142c. GPL-3.0-or-later.