ScarletNX / ScarletNX documentation / Parallel draw batches (design, not built) · ← previous · next →
Batches
The renderer thread cuts the records into batches. A batch ends at a new pass and at a record that is not a draw,
except constant buffer writes, which stay inside it in their order. Measured over 600 presents: 480,000 batches, 8.6
draws each, 88% of the draws in batches of 16 or more. A batch of fewer than 16 draws (12% of the draws) runs on the
renderer thread, as today.
Workers and the order
- A pool of workers (2 or 3), each with a single-producer ring of batches and a slot for each batch's result. A
worker wakes once for each batch.
- A worker writes its batch's commands into a command list of its own, in the format of the record ring
(
record.c). The recording thread replays the lists in batch order. No secondary command buffers.
- The commits of a batch (targets written, results added, images, queries, transform feedback) go to the renderer
thread with the list, which applies them in batch order.
The state each thread owns
- Per worker: the per-draw memos (
g_draw.last, g_targets, g_fs_last, g_tex_recent, g_dyn, the stage-set
caches g_cb_windows, g_storage_recent, g_table_words, g_dset), a staging arena, the command list, the
statistics. A batch starts with the memos of the last batch the worker ran. The draws of one pass are mostly the
same state, so the memos stay warm on that core.
- Shared, read on the hit path by all: the draw table (
g_draw.e), the surface table and the surfaces, the texture
memo (g_tex_memo), the buffer cache, the pipeline cache, the descriptor set cache. Today none of these has a lock
of its own: vk_lock guards them all (texture.c, surface.c and descriptors.c take no lock of their own).
- Renderer thread only: submits, landings of results, waits for the GPU, presents, the records that are not draws,
render pass begins and ends.
Shared caches
43% of the draws are in batches with a miss of the draw table, the targets or the texture cache. So a worker must handle
misses, not only hits. Each shared cache gets a rule:
- Reads on the hit path without a lock: entries that are written whole and published with a release store (a
generation word last), and entries freed only when no batch of an older generation runs (epoch reclamation, as the
frames in flight already keep descriptor sets and views alive).
- Misses under a lock of that cache. A miss that needs the GPU (an upload, a reload of a target, a decode) records
its copy into the worker's list, before the draw, as the commands of an upload do today.
- A miss that needs a submit, a wait or a landing stops the batch. The renderer thread runs the rest of the batch.
The LRU lists and the statistics become per worker, merged at a present.
Batches that depend on others
19% of the draws are in batches that sample a target that an earlier batch of the present wrote. The command order of
the replay keeps the GPU's order correct. The CPU's view must also be correct: a texture memo that checks a target's
wgen, a copy of a target that a draw samples, the layout and the barriers.
- Each batch notes the surfaces it samples and writes, with the generation it saw.
- Before the renderer thread replays a batch's list, it compares those with the commits of the earlier batches. A
mismatch discards the batch's list, and the renderer thread sets the batch up again, in order.
- A batch that is known to depend on an earlier one (the same pass's targets sampled, a pass that follows a target's
pass) waits for it instead of running at the same time.
← previous · next →