vulkan_present: the capture buffer is made of host-cached memory (RT-PRESENT-CAPTURE-CACHED) #1694
Closed
leonida/mandy
DadaCap wants to merge 0 commits from
present-capture-cached into main
pull from: present-capture-cached
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!1694
Loading…
Reference in a new issue
No description provided.
Delete branch "present-capture-cached"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: RT-PRESENT-CAPTURE-CACHED (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157004451)
What and why
VulkanPresenter::make_capture_buffertook the first memory type that is host visible and coherent. On NVIDIA the first such type is uncached (flags0x6on this RTX 5080; the cached one,0xe, comes after it), and a host read of uncached memory is many times slower than of cached memory.That did not matter much while the buffer was read once per capture. Since the launch splash (#939),
finish_startup_framereads the whole buffer on the CPU for every frame the title presents before its first non-black one, with the submit and tracker locks held. On a large window that scan takes over the boot:LEONIDA_STACKSdumps 20 s apart:submit_now->present->PresentX);device-stall: could not sample the submit lock for 15 s; submitted ticket 424, last observed retired ticket 328;The change: choose a host-cached, non-device-local type first and fall back to the first host-visible coherent one, exactly as
probe_read_sourcein the same file already does. One function, 11 lines.Measured
Native Windows 11, RTX 5080 16 GB, NVIDIA 621.24, 64 GB, own 1.0.2.1, MSVC RelWithDebInfo with SDL3. Window client area 3824x1841 when the first frame is presented. Every run: keyboard pad with A every 5 s from 30 s,
LEONIDA_SKIP_INT3=1,LEONIDA_PEEK=0x7446510,0x98f828c, an existing save, shaders frommain's translator.d)main3f81d46acLEONIDA_TITLE_WINDOWS_MB=4096 LEONIDA_ARENA_MB=4096 LEONIDA_DEVICE_FAULT=1main+ #1558 + #1631LEONIDA_ARENA_MB=2048main+ #1558 + #1631,LEONIDA_WINDOW=960x540(no code change, 14 times fewer texels to scan)LEONIDA_ARENA_MB=2048main+ #1558 + #1631 + this changeLEONIDA_ARENA_MB=2048main+ this change only (this branch)So on this machine the first and last rows differ only by this commit. Before #939 (
main3ff2a2adc) the same launcher passed the landing screen every time, which is how I found it.It probably costs time on smaller windows too, in proportion to the texel count: the report on #939 of 182 to 362 PresentX in 51 to 74 s on an RTX 4070 SUPER is a few presents a second. I have not measured another machine.
Tested
runtime/pass on this branch on the same GPU:xbox_present_readback_size,vk_presenter_capture_colour,present_window,xs_present_lazy,vk_present_dump,vk_present_dump_default,vk_present_dump_invalid,vk_presenter_sync,d3d12_present,xbox_present.Not done, not tested
Counters, switch names and addresses of the executable only; no game data. AI-assisted (Claude Code).
🤖 Generated with Claude Code
@kawaii-shakal thank you for the review. On the helper: I agree the two searches should not drift apart, and I would do it as a follow-up once this and #1223 are in. #1223 adds its guard directly above the
vkGetPhysicalDeviceMemoryProperties_call inmake_capture_buffer, which is the line a sharedpick_host_read_typewould take out of that function, so folding it in here would put the two pull requests in conflict for a nit. If a maintainer prefers it in this one, I will add it and help rebase #1223. AI-assisted (Claude Code).Tested
3768be502applied ontomain42537e7b6on AMD: Radeon RX 7900 XT, AMD driver 32.0.32029.2010 (26.11.2), no Resizable BAR, Windows 11 build 26300, VS 2022 RelWithDebInfo. No game files.What the change picks here. In this driver's memory-type list, type 1 is
HOST_VISIBLE | HOST_COHERENTin system memory and comes first, somaintakes it. Type 3 addsHOST_CACHEDin the same heap, and this PR takes it.I measured CPU reads from each host-visible type with a small standalone Vulkan program. It maps a 3840x2160x4 buffer (33 MB) and
memcpys it out 10 times:main)0x006coherent, uncached0x00ecoherent, cached0x007device-local (BAR window)0x0c7/0x007device-local (BAR window)0x0c6/0x006uncached variants0x0ce/0x00ecached variants(
0x0c6/0x0c7/0x0ceadd AMD's device-coherent/uncached bits. They are allocated here without enablingdeviceCoherentMemory, for reference only. Neithermainnor this PR picks them.)So the order is the same as on your RTX 5080 (uncached
0x6first, cached0xelater), and on AMD the uncached type is about 75 times slower to read. That is the raw read speed of each memory type, measured outside leonida, not the presenter's scan itself, which the description says was not timed. From it, a full scan of a 4K capture should take about 114 ms onmainand about 2 ms with this PR on this card. It scales with the window's texel count. I did not time the scan itself or boot the title on AMD, so this is an estimate from the read speed.Tests,
mainand this PR:xbox_present,xbox_present_readback_size,vk_presenter_capture_colour,present_window,xs_present_lazy,vk_present_dump*,vk_presenter_sync,d3d12_presentandpackage_splash: 11 of 11 pass on both.xbox_present,vk_present_dumpandvk_presenter_syncwith--repeat until-fail:10: no failure on either.xbox_presentreuses one capture buffer while the colour changes between frames, so a stale cached read would show up there.ctest -j 6: 399 of 402 with this PR, with the same three failures asmain42537e7b6(d3d12_texture_tiles,d3d12_clear,d3d12_geometry_views), none of them presenter tests.I didn't run a retail boot.
Thanks, that is a useful second vendor: the same memory-type order and a 75 times slower uncached read on the RX 7900 XT. I agree the 114 ms per 4K capture on
mainis an estimate from the read speed, not a timed scan. AI-assisted (Claude Code).Merge test for the #2464 campaign on an 8 GB laptop (profile M), done for the author. Main ec91d695c was merged without conflict, in one tree together with #1705, #1694 and #1284, which touch different code. The numbers were recomputed from the raw logs. AI-assisted (Claude Code, Claude Opus 5.5).
Retest status on the new code: this head (3768be502) still merges cleanly with
maind44285197. That merge changed nothing underruntime/, and this pull request touches onlyruntime/src/vulkan_present.h, which #2509 did not change either. It has no unit test of its own; OreoFR's merge-test run above is its latest in-game check.This comment was AI-assisted (Claude Code, Opus 5.5).
Windows 11 + MSVC
19.44+ RTX 3090 Verification — PASS (3768be5020)Verified
3768be5020(RT-PRESENT-CAPTURE-CACHED) merged ontoorigin/main(5825b02ff8/53b77df14f,0conflicts) on native Windows 11 (10.0.26200.9974) with MSVC19.44.35228, NVIDIA GeForce RTX 3090, andVK_LAYER_KHRONOS_validation1.4.363.1.Checks Run
vkGetBufferMemoryRequirementson a1920 x 1080 x 4VK_BUFFER_USAGE_TRANSFER_DST_BITcapture buffer andvkGetPhysicalDeviceMemoryPropertieson NVIDIA GeForce RTX 3090:origin/mainsingle-pass loop): selected memory type3(propertyFlags = 0x6:HOST_VISIBLE | HOST_COHERENT, uncachedHOST_CACHED == 0).#1694two-passHOST_CACHED && !DEVICE_LOCALloop): selected memory type4(propertyFlags = 0xe:HOST_VISIBLE | HOST_COHERENT | HOST_CACHED,HOST_CACHED == 1).LEONIDA_VK_VALIDATION=1):vk_present_dump_test.exe:rc=0,0VUID-/ validation errors.vk_presenter_sync_test.exe(default &--sparse-capture):rc=0,0VUID-/ validation errors.AI-assisted.
Verified by OreoFR on the Runtime workflow of his fork (GitHub
windows-latest, MSVC), main 452d1d1b6, PR head 3768be502. MEASURED. This PR has no test of its own, so there is no red; the comparison is main alone vs main + this PR, with the Windows job limit raised to 120 min on the fork branches only.windowsctest 513/514, 2 disabled; the one failure isdisplay_white_cache("the first get() has no value yet"), a threaded timing test ofsrc/display_white_cache.hthat this PR does not touch.merge --no-ff), https://github.com/OreoFR/leonida/actions/runs/46318840575:windowsctest 514/514 passed, 2 disabled (gameinput,gameinput_script), out of 516.linux-gpu-toolspassed.macosfails at "GPU tests on MoltenVK", as on upstreammain's own latest Runtime runs. Wine jobs not covered.So the change builds and breaks no runtime test on Windows. Not covered: the host-cached memory choice and its read-back speed, which no test exercises (needs a GPU run).
AI-assisted: Claude Code
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.