Repository navigation
Conversation
A full barrier at every render-pass boundary (ALL_COMMANDS -> ALL_COMMANDS) is the most expensive thing to ask of a tiler between two render passes: it drains every stage at every boundary, hundreds of times a frame - on a Helio G95's Mali-G76 (Redmi Note 9 Pro) removing it entirely (LARECOMP_VK_NO_PASS_BARRIER=1) was worth a large fps gain, at the price of flickering: a new pass read targets whose stores were not visible yet, or wrote one the previous pass was still sampling. This keeps the dependencies and drops the drain. Writers into the main command buffer since the last barrier are tracked by kind - a pass's colour and depth/stencil stores (vk_end_pass, vkCmdClearAttachments), a compute dispatch's storage writes (dispatch, gfast_finish's placed window), and every real transfer write recorded there (the vkCmdCopy* / vkCmdBlitImage / vkCmdResolveImage calls, copy_buffer: all kept as real commands) - and the barrier before a pass (or a dispatch that isn't chained) is built from exactly those, with the stages that consume them: attachment loads and depth tests, sampled and storage reads in the shader stages, vertex/index fetches, indirect commands for a compute writer. Nothing at all is emitted when nothing was written since the last barrier. The tracking is exact, not a heuristic: bits are cleared by the barrier itself, by vk_full_barrier on the main buffer only (the upload buffer's end-of-submission publication barrier does not order the main buffer's recorded work, so those writers stay), and in vk_wait_seq only for the submissions that actually completed (pass_writers_seq) - commands recorded after a waited-on submission's buffers were closed are not lost. LARECOMP_VK_PASS_BARRIER: 0 none (as NO_PASS_BARRIER, unsafe), 1 scoped (default), 2 the full barrier, as before. The dchain deferred barrier (the one owed after a storing dispatch) is scoped the same way.
|
Thanks, the copies are all real calls now. But the barriers still miss hazards, and it's on by default on every GPU:
Please make it opt-in (an env switch) and run the Vulkan synchronization validation ( |
…rs back The destination carries the reader's stages now (a pass, a dispatch, or whatever follows): COMPUTE_SHADER before a dispatch, TRANSFER where the reader isn't known, colour/depth attachment writes between passes (WAW), and the stages the reads belong to. The source gains a draw's vertex/fragment storage writes (note_gmem_store). Indirect-command and uniform reads are in every destination. The full barriers after gfast_finish's copy-back and gres_get's merge copies are back (everything reads the heap and the arena, not a tracked subset), and vk_wait_seq no longer touches the tracking: the game's thread is not the one recording it, and a host wait orders nothing on the GPU. copy_buffer_to_texture's write is tracked. Opt-in: LARECOMP_VK_PASS_BARRIER=1; the default is the full barrier exactly as main has it.
|
All seven taken, and you were right to be suspicious of the masks: with them completed (5 and 6 included) I can see how part of the measured gain was missing dependencies, not saved work. Pushed as 977411b, one commit on top:
It's opt-in now: |
|
Thanks, every item is done, and making it opt-in (
Then, as said: the sync-validation log with zero hazards (title, Plateau, map), and I'll A/B |
pass_note_writers() still noted writers with the full barrier on (the default), and a note straddling a submission boundary added a vk_full_barrier main doesn't have - the default wasn't the same as main. The tracking (and that boundary barrier) is the scoped mode's alone now: pass_barrier_mode() is shared, and every other mode notes nothing, so the default is exactly main's and 0 exactly the old NO_PASS_BARRIER switch. The header comment also listed copy_buffer among the tracked transfers; it isn't (every caller is followed by a full barrier, which orders and clears all of the tracking anyway) - the comment says so now.
|
Both taken, pushed as f645172:
|
mamcjr
left a comment
There was a problem hiding this comment.
Thanks for the patience on this one. Main has moved under it, so it needs a rebase before I can test it:
- Conflicts in the dispatch chaining added since (7845d58, and d36c06a's arena copy-back):
gfast_finish, thegres_getmerge, anddispatch_compute, where main now carriesdchain_after = owe_afterand the PR resets it tofalse. That code runs in the copy mode, which Turnip uses, so the rebase has to keep main'sowe_afterexactly, or the default barriers change on Adreno. - Mode 0 and AB
nobarrieraren't the old switch any more. On main they only removed thebegin_passbarrier. Herepass_barrierreturns early for them, and it is also used before dispatches, after the gfast window and at the dchain end. So those measurement switches now drop the dispatch and compute barriers too, and old A/B numbers aren't comparable. Applying that early return only forPB_PASSwould keep them as they were. - Mode 1 records a full barrier from inside
pass_note_writerswhen the submission changes, wherever the note is made, possibly inside a dynamic-rendering instance (clears throughvkCmdClearAttachments,note_gmem_storeafter an in-pass draw), where an ALL_COMMANDS barrier is invalid. It's probably unreachable becausebegin_passclearspass_writers, but that is what the sync-validation run would prove. Could you post it (title, Plateau, map, zero hazards)? - After the rebase, the scoped masks need checking against the paths main gained since: the in-place feedback reads (#507) and the per-submission cbwin snapshot.
Once it's rebased I'll compare debug frames and barrier counts against main on the POCO with the default, then try =1.
|
The four points from 11-24 are still open:
About the numbers: this PR says the Helio G95 went 19-21 to 23-26 fps, and #466 says the same phone went 14-15 to 23-26 with the waiter alone. Which build was each measured on? (#466 is merged now, with the waiter on by default on Mali, so new measurements here should start from main.) If there's no update in a couple of weeks, I'll close it as stale; it can always be reopened. |
What
A full barrier at every render-pass boundary (
ALL_COMMANDS -> ALL_COMMANDS) is the most expensive thing to ask of a tiler between two render passes: it drains every stage at every boundary, hundreds of times a frame. On a Helio G95's Mali-G76,LARECOMP_VK_NO_PASS_BARRIER=1measured what removing it entirely was worth - a large fps gain - at the price of flickering: a new pass read targets whose stores were not visible yet, or wrote one the previous pass was still sampling.This keeps the dependency and drops the drain: the barrier is built from the writers actually recorded into the main command buffer since the last barrier, with the stages of that exact reader - a pass's draws, a dispatch, or whatever follows where the reader isn't known. Opt-in:
LARECOMP_VK_PASS_BARRIER=1; the default is the full barrier exactly as main has it (every boundary, unconditionally). The gain measured below was with the first version's incomplete masks, so treat it as an upper bound: the number to trust is the one with complete masks, and the Vulkan sync validation on top of it.The seven points, and where each lives
pass_barrier(cb, reader):PB_PASSfor a pass's draws (shader reads in every graphics stage, vertex/index fetches, indirect commands, attachment loads, tests and stores),PB_DISPATCHfor a dispatch (COMPUTE_SHADER, its storage/uniform/sampled reads and its own writes - the WAW between two dispatches included),PB_ANYwhere what follows isn't known (the gfast window path, the dchain end): a pass, a dispatch or a copy, with TRANSFER reads and writes among them.note_gmem_storeitself (PW_SHADER): the source of the next barrier carries VERTEX_SHADER | FRAGMENT_SHADER with SHADER_STORAGE_WRITE, and SHADER_READ beside it - an atomic counts as a read.gfast_finish's copy-back and aftergres_get's merge copies: the heap and the arena are read by draws' attributes, dispatches and copies alike, not a tracked subset.copy_buffer_to_textureis noted - right aftervkCmdCopyBufferToImage, past the full barrier that cleared everything before it.vk_wait_seqdoesn't touch the tracking - dropped: it runs on the game's thread while the render thread records, and a host wait orders nothing on the GPU anyway. The clearing ispass_barrier's andvk_full_barrier's alone.Where it touches
runtime/nvn/vulkan/exec.conly: the tracker (a draw's shader stores added to the pass/dispatch/transfer bits),pass_barrierwith its reader parameter, the two restored full barriers, and the note after each transfer call - everyvkCmdCopy*/BlitImage/ResolveImagea real call, as before.Measurements
On the Helio G95 (Mali-G76): the full barrier at every pass boundary was ~10% of each frame's GPU-side cost in the world; with the scoped barriers the same scenes held the no-barrier frame rate with no flickering across a 30-minute session (title screen, Great Plateau, menus with the map open) - 23-26 fps with the scoped barriers vs 19-21 with the full ones. As said above: an upper bound until re-measured with the complete masks. The Vulkan synchronization validation (
VK_LAYER_KHRONOS_validation, sync validation) on the title screen, the Plateau and the map is the next thing I'll post.