WIP: feat(vk): programs whose layouts are defined alike can share one (RX_VK_SHARED_LAYOUTS, off) #2046
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2046
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-shared-layouts"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
bind_descriptors(gpu/vk/vk_draw.cpp) pushes only the descriptor writes that changed while the pipeline layout is the one it pushed with. Each program has its ownVkPipelineLayout, so every switch to another program pushes its whole set again. This adds an experiment, off by default: withRX_VK_SHARED_LAYOUTS=1,ensure_layouttakes its layouts fromlayout_take: one descriptor set layout and one pipeline layout per definition (the bindings in order with their types, counts and stages, the push flag, the push constant stages), counted, and destroyed with their last program bylayout_release, which the three places that let a program's layouts go now call (prepare_run's warm of compute programs;program_cache_borrowandprogram_cache_borrow_allingpu/vk/vk_progcache.cppthroughprogram_layout_release). A layout not made whole stays the program's own. The log saysvk: shared layouts: N definitions for M programsat 64, 128, 256 ... programs. The result expected with it on is fewer full pushes when draws switch between programs defined alike.make_layouts(the callsensure_layoutmade, moved) now checks the driver's results: a set layout or pipeline layout the driver did not make is logged and leftVK_NULL_HANDLE(Vulkan leaves a failed create's handle undefined), and a set layout not made makes no pipeline layout; on main those results were not checked.Switch:
RX_VK_SHARED_LAYOUTS(kind attempt, off by default, the branch's default; its row ingpu/vk/switches.def). Unset or=0: a layout a program, main's code (make_layouts, the same callsensure_layoutmade). The switch is read once, at its first use (soHOS_ABcannot alternate it); any value but0,false,offornoturns it on; with it on, its first read logs so.From 2c9bb476 on
exp/x86-asm-sync.Read first:
layout_key,LayoutShare,layout_take,layout_releaseandensure_layoutingpu/vk/vk_draw.cpp; the release ingpu/vk/vk_progcache.cpp.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
364d2d05on main @75317e1f. Every check ran throughtests/run_all.py --strict --exactin build jobs of the PC's job queue, in a hidden console (logt-dc3-vk-shared-layouts):tests/test_shared_layouts.py(new:make_layouts,layout_key,LayoutShare,layout_takeandlayout_releasewith a counting driver (a create that fails leaves no handle): same definition, same objects made once; each difference, others; the last release destroys once; a layout not made whole stays the program's own; and the call sites; and the switch's reader, cut from the source, runs in fresh processes: unset,0,off,false,1,onand another value, twice each, and set to the other answer after its first read): pass.--changed 75317e1f; its own are among them): 167 passed, 20 failed. Failed:tests/test_recorder_sync.py,tests/test_fsr_uniform_ownership.py,tests/test_sampler_admission.py,tests/test_pipeline_play_cache.py,tests/test_draw_stream_visibility.py,tests/test_device_lost_exit.py,tests/test_dev_packs.py,tests/test_draw_binds.py,tests/test_dev_ab.py,tests/test_crash_dialog.py,tests/test_frame_overlap.py,tests/test_linux_pressure.py,tests/test_mesh_conv.py,tests/test_prepare_cache_save.py,tests/test_present_queue_default.py,tests/test_recorder_own_idle.py,tests/test_target_reuse_memory.py,tests/test_upscaler_rows.py,tests/test_vk_occlusion_queries.py: each fails on main @75317e1ftoo (the same checks on main in the same queue batch, logt-dc3-base).tests/test_recording_admission.pyalso failed in that run (itsparallelcase, "worker slot ownership") and passed when run again on this head (logt-dc4-vk-shared-layouts); main passed it in that batch and in five runs of the next (logst-dc4-base-ra1tot-dc4-base-ra5).It has NOT run in the game on this PC yet.
Still to test:
75317e1f, this PR withRX_VK_SHARED_LAYOUTS=0and this PR with it =1, each warmed a minute in the scene first, then interleaved (main, =0, =1, =1, =0, main), two runs each, expecting the same picture all three ways, =0 as main, theshared layoutslog line with =1, and with =1 the replay's time a frame the same as or lower than =0's and main's (by hand)RX_VK_SHARED_LAYOUTS=0and=1, warmed, in ABBA order, expecting the same picture every way and no crash or validation error (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest a minute, main against this PR with RX_VK_SHARED_LAYOUTS=0 and =1, ABBA, the same picture)tests/test_shared_layouts.pywith--cxx g++and--cxx clang++, expecting PASS (by hand)Measurements
Verdict: not measured: no micro-benchmark of this port and no run in the game on this PC yet; the in-game A/B is in Still to test.
RX_VK_SHARED_LAYOUTSships off (kind attempt), the branch's default; it is not measured on main.Risks
Off by default: unset, nothing changes. On: a layout destroyed while a program still used it (a crash or a device loss), or two programs given one layout though their definitions differ (wrong bindings); the count and the key are what the test checks.
program_cache_borrow_all's release goes throughlayout_releaseeither way (unset it destroys as before). The renderer is compiled again after updating. A layout the driver does not make is now logged and left null (on main its handle was used as the driver left it); what a program does without its layout is as on main.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). Not yet: only the checks in Testing ran.main, or Measurements says why there is nothing to measure. Not yet (Measurements).third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. Its row is in; not measured yet.Assisted-by:/Co-Authored-By:trailers.Possibly related, for context:
On BeanBot's note: this pull request overlaps #800 (dyst's, open first), which makes programs with the same layout definitions share one set layout and pipeline layout in the same files. It is on hold in #800's favour and gets no further push while #800 is open.
What the two diffs differ in: #800 shares by default (
RX_VK_LAYOUT_EACH=1restores a layout per program) and keeps the shared layouts for the device's life; this one is off by default (RX_VK_SHARED_LAYOUTS=1turns it on) and counts each shared layout, destroying it with its last program, with its row ingpu/vk/switches.def.@siantm — on your note that this "overlaps #800 … and gets no further push while #800 is open": #800 is still open and unmerged, and both change the same shared set-layout/pipeline-layout path in the same files.
Would you rather close #2046 as a duplicate of #800, or keep it parked and rebase it onto #800 once #800 lands?
Either is fine; this is only so the queue shows the right owner, and nothing needs doing until you decide.
@dazemc Thanks for checking. It stays parked for now: nothing is pushed to it while #800 is open, and it is not a merge candidate. Whether it is closed as a duplicate of #800 or rebased onto #800 once that lands is still to be decided on my side; I will post here when it is, and close it myself if it goes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.