Let the submitting thread go on past the replay workers' groups, with up to four groups in flight.

With NX2NAVI_REPLAY_PIPE=1 (off by default) the submitting thread hands a group's chunks to the workers, takes chunks
of it itself until none is left to take, and goes on with the ops after the group in a new command buffer after the
chunks' places in the part (vk_sync_append_later), also into the next group's front pass.
Up to four groups are handed out and not in their part yet; their chunks wait in one queue in the order of the stream.
The submitting thread waits for them only where the order needs it: for room, before a part goes to the GPU, before
copies and texture or buffer clears, where DLAA's run or the contact shadows' hook acts, and where a lookup would make
a texture entry or take back a retired one (the op goes again afterwards, as a chunk's does in turn).

What the chunks read stays as the stream had it while the submitting thread runs ahead: uniform snapshot drops count
from their place in the stream, a chunk reads only the inline uniform updates before its group, the HDR present's
source goes by stream position, the texture pool set syncs under the chunks' lock, each group keeps its own render
conditions, occlusion segments and closed query slots, and the queries after a group's last report go into the next
segment made after it. A group's first chunk runs its pass hooks after the group before began its pass; turns wait
for every earlier chunk, of earlier groups too. Locks the chunks take, the submitting thread takes while it is behind.

Draws keep the sampled-texture descriptors they resolved per draw context and reuse them without the texture lock
while their slot is unchanged; the workers waited for that lock at nearly every draw. Texture lookups that change
nothing no longer wait for their turn. The perf line says where the submitting thread waited, what the chunks took,
and which texture lookups waited; NX2NAVI_GPU_TIMELINE also shows the chunks and the waits.

Off by default because it does not pay yet: in Hyrule Field with 3 workers it shortens the replay (11.5 against 12.1
ms a frame) but not the frame (49.2 against 49.6 fps in the same batch). The GPU gets a group's commands only once its
last chunk is recorded, so the main thread's wait for the GPU after the frame's first submission grew by 0.8 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epicmeme546
2026-11-12 03:06:33 -05:00
committed by chrg6
parent 2ac56ecc6f
commit ffa599ef33
14 changed files with 623 additions and 165 deletions

View File

@@ -155,20 +155,24 @@ void vk_exec_probe_inline(VkCommandBuffer cb, uint64_t fence);
void *vk_exec_draw_ctx_new(void);
void vk_exec_draw_ctx_use(void *ctx);
// vk_exec_draw.c, before the chunks of a parallel group are recorded (submitting thread): the stand-ins are made and the
// texture pool set this submission took is brought up to date, which the chunks then only bind.
void vk_exec_draw_group_begin(VkExec *ex);
// vk_exec_xfer.c, parallel groups: vk_exec_xfer_group turns the front pass on (it lists the group's occlusion segments)
// or off; vk_exec_xfer_front replays a counter report or reset, render enable or render condition in the front pass
// (returns the condition's decision, 1 renders); vk_exec_xfer_chunk_state is the occlusion counting at a chunk's first
// op, which vk_exec_xfer_worker hands to the worker side with the chunk's decisions (on), or turns it off.
void vk_exec_xfer_group(int on);
// texture pool set this submission took is brought up to date, which the chunks then only bind. Returns the inline
// uniform updates of the submission so far (vk_exec_upd_top).
uint32_t vk_exec_draw_group_begin(VkExec *ex);
// vk_exec.c: of the submission's inline uniform updates (all), those a draw on the calling thread may read.
uint32_t vk_exec_upd_top(uint32_t all);
// vk_exec_xfer.c, parallel groups: vk_exec_xfer_group turns the front pass of the group in slot `group` on (it lists
// the group's occlusion segments) or off (-1); vk_exec_xfer_front replays a counter report or reset, render enable or
// render condition in the front pass (returns the condition's decision, 1 renders); vk_exec_xfer_chunk_state is the
// occlusion counting at a chunk's first op, which vk_exec_xfer_worker hands to the worker side with the chunk's
// decisions and its group's slot (on), or turns it off.
void vk_exec_xfer_group(int group);
int vk_exec_xfer_front(VkExec *fx, uint32_t op, const void *payload);
uint64_t vk_exec_xfer_chunk_state(void);
void vk_exec_xfer_worker(int on, const uint8_t *cond, uint32_t ncond, uint64_t state, uint32_t slot0, uint32_t nslots,
int chunk);
// After every chunk of the group is done (submitting thread): the slots the chunks closed go into their segments, in
// the order of the chunks.
void vk_exec_xfer_group_merge(int nchunks);
int chunk, int group);
// After every chunk of the group in slot `group` is done (submitting thread, groups oldest first): the slots the
// chunks closed go into their segments, in the order of the chunks.
void vk_exec_xfer_group_merge(int group, int nchunks);
// The front pass: whether a draw here counts samples (a query slot), and n slots of the ring in the order of the stream
// for one chunk (the first is returned; vk_exec_xfer_worker hands them to the chunk's worker).
int vk_exec_xfer_counting(void);