d3d12/vulkan: add 4 GB low-VRAM budget steering, priority/pageable memory, and LEONIDA_RT_AS=off (VK-LOW-VRAM-BUDGET) #443
Closed
leonida/mandy
jujumoneylol wants to merge 0 commits from
pr/vulkan-low-vram into main
pull from: pr/vulkan-low-vram
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!443
Loading…
Reference in a new issue
No description provided.
Delete branch "pr/vulkan-low-vram"
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: VK-LOW-VRAM-BUDGET (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122816234)
What and why
Adds an automatic low-VRAM survival layer in the Vulkan D3D12 shim for discrete GPUs with <= 4.5 GiB dedicated VRAM (e.g., 4 GB GTX 1650 / RTX 3050 4 GB) while leaving larger GPUs (>= 6 GB) and UMA iGPUs untouched by default.
VK_EXT_memory_budget,VK_EXT_memory_priority, andVK_EXT_pageable_device_local_memorywhen advertised by the driver, chainingVkMemoryPriorityAllocateInfoEXT(1.0for critical render targets / depth-stencil / arena allocations vs0.25for spillable textures/buffers).runtime/src/vulkan_memory.h,runtime/shims/d3d12_vulkan_device.cpp):DEVICE_LOCALVRAM (overridable viaLEONIDA_LOW_VRAM=on|off|auto,LEONIDA_VRAM_RESERVE_MB,LEONIDA_VRAM_CAP_MB,LEONIDA_VRAM_LOG=1).DEVICE_LOCALheadroom reserve for critical RT/DS targets; once liveVK_EXT_memory_budgetheadroom drops below the reserve, spillable allocations are proactively routed to system RAM (HOST_VISIBLE) instead of evicting render targets or causingVK_ERROR_OUT_OF_DEVICE_MEMORY.Heap::tiles) to fall back to system memory when VRAM is exhausted instead of returningE_OUTOFMEMORY.LEONIDA_RT_AS=off): cleanly disables RT acceleration structures on non-RT / low-VRAM GPUs and answersGetRaytracingAccelerationStructurePrebuildInfowith minimal 256-byte aligned sizes so callers do not allocate or divide by zero.runtime/test/d3d12_state_map_test.cppand a live GPU stress test (runtime/test/d3d12_low_vram_test.cpp) that oversubscribes VRAM past 100% and verifies critical RT/DS pinning + spillable steering +LEONIDA_RT_AS=off.Tested
d3d12_state_map_test,d3d12_low_vram_test, andd3d12_vulkan_device_testwith MSVC 19.44 (vcvars64) + Ninja on top ofmain8f481cf16.d3d12_state_map_test: PASSED (including new low-VRAM policy & placement unit tests).d3d12_low_vram_test: ALL CHECKS PASSED on GTX 1650 (3,935 MiB VRAM,budget=1 priority=1 pageable=1, 512 MiB reserve):LEONIDA_RT_AS=offdisables RT and returns 256-byte prebuild sizes.d3d12_vulkan_device_test: PASSED (60/60 resolves matched, 20/20ID3D12Heap::GetDescmatched, host-image/staging copies, castable formats, and Xbox-ABI proxy checks matched).py -3.13 -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/shims/d3d12_com.h runtime/shims/d3d12_vulkan_device.cpp runtime/src/vulkan_memory.h runtime/test/d3d12_low_vram_test.cpp runtime/test/d3d12_state_map_test.cpp: clean.GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a — Vulkan D3D12 runtime only)Tested ccffa86b on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, 16 GB), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows:
d3d12_state_mappasses,d3d12_low_vramfails on this 16 GB cardBuilt at this head with
scripts\build_runtime.ps1(MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files.d3d12_state_map: passed (state map, enhanced barriers, subresource decoding, layout tracking, discard ranges, block formats, BAR detection and memory types OK).d3d12_low_vram(ctest, verbose):The 5120 MiB stress fits in 16 GB, so nothing is steered and the
> 0check fails. Note too that the stress run reportslow_vram_mode=0 ... reserve=0 MiB, although the line above it turns the mode on with 2048 MiB reserved, so the stress device may not be the one the env enabled. Sizing the stress to the device's budget, or forcing a small budget for the test, would make it pass on large cards. Happy to rerun.Thanks for testing on a 16 GB RTX 3080 Ti and catching both issues, @Sangonapou!
Fixed in
08e18bdfc:Large-VRAM GPU test failure (
d3d12_low_vram_test):LEONIDA_LOW_VRAM=1andLEONIDA_VRAM_RESERVE_MB=2048without a cap, leaving ~14 GiB of headroom on a 16 GB card so the 5,120 MiB stress loop never crossed the reserve.LEONIDA_VRAM_CAP_MB=2048+LEONIDA_VRAM_RESERVE_MB=512and sizes the stress allocation toeffective_budget + 512 MiB(2,560 MiB on capped large GPUs), so spillover is deterministically exercised on 8/16/24/32 GB cards while keeping all 6 critical RT/DS targets pinned inDEVICE_LOCALVRAM.low_vram_mode=0and thestderrbanner no longer interleave misleadingly.Environment-variable docs check (
tests/test_docs_env_vars.py):LEONIDA_LOW_VRAM,LEONIDA_VRAM_RESERVE_MB,LEONIDA_VRAM_CAP_MB,LEONIDA_VRAM_LOG, andLEONIDA_RT_AS=offindocs/d3d12_vulkan.md(§4.8 and §4.10).Re-verified on Windows 11 26200 / NVIDIA GTX 1650 (both uncapped 4 GB auto mode and
LEONIDA_VRAM_CAP_MB=2048mode),d3d12_state_map_test,tests/test_docs_env_vars.py(4/4), andscripts/check_no_game_data.py. Ready for a rerun on your 16 GB card!AI-assisted fix and verification.
Rebased onto
main(a73a57e13) → head922235029, resolving conflicts withmain'sVK_EXT_memory_budgetHUD reader,dedicated_image/memory_mutex(), androbustness2/device_faultsetup.Re-verified on Windows 11 / NVIDIA GeForce GTX 1650 (4 GB):
ctest:d3d12_low_vram,d3d12_vram_budget,d3d12_dxr_validation,d3d12_state_mapall PASS (0 failed;d3d12_dxr_validation_khrskipped on non-RT GPU)d3d12_low_vram_testwithLEONIDA_VRAM_CAP_MB=2048+LEONIDA_VRAM_RESERVE_MB=512: 6/6 critical RT/DS pinned in VRAM, 68 spillable allocations (1,088 MiB) steered to system RAM, 0 forced spillstests/test_docs_env_vars.py(4/4) andscripts/check_no_game_data.pyPASSRTX 3090 / 621.40 (24322 MiB VRAM), validation on, this PR merged onto current main a73a57e13: d3d12_low_vram auto-steering stays off (low_vram_mode=0, auto=0, cap=0). With LEONIDA_LOW_VRAM=1 and a 2048 MiB cap the stress path passes (75 spillable in VRAM, 85 steered; 6/6 critical RT/DS pinned; LEONIDA_RT_AS=off ok). d3d12_state_map and d3d12_vram_budget also pass, 0 VUID.
Profile M data point for #443's memory priority (
VK_EXT_memory_priority+VK_EXT_pageable_device_local_memory) on a 12 GB card, A/B with one variable (#443 in or out). Counts only. AI-assisted (Claude Code).Reading (n=1 per arm, PROVISIONAL): no shared-memory effect of #443 shows on this 12 GB card. With #443, c3-G1b stayed at ~1.2-2.2 GiB shared but c3-G1c went to ~3.1 GiB, close to the control's ~3.4 GiB; dedicated use was about 10 GiB in all three. The control's end (exit code 1 at 914 s, no fault, no device loss, no crash report) is not explained; it was not a manual close. None of the runs reached gameplay frames, so the frame-rate effect quartz-heron-58 measured is not tested here.
RUN of #443 (red/green, GPU box, merged build)
Heads: PR head
922235029ad2, main54b2a81e95c4. Tested as main + PR head (git merge --no-ff, local only): merged cleanly, no conflicts.Commands (VS 2022 x64 environment, from the worktree root):
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ONcmake --build runtime/build -j 8 --target d3d12_state_map_test d3d12_low_vram_test d3d12_vulkan_device_test gta6rtctest -R "^(d3d12_state_map|d3d12_low_vram)$" --output-on-failure -j1Also run, because the PR changes the allocation paths it uses:
ctest -R "^d3d12_vulkan_device$" -j1d3d12_com.h,d3d12_vulkan_device.cpp,vulkan_memory.hreverted to main's; tests and CMake registration kept): build failures only,max_device_local_heap_bytesnot found (d3d12_state_map_test) andrt::d3d12::device_vram_statsnot a member (d3d12_low_vram_test). That only shows the new API is needed.d3d12_vulkan_device.cppdoes not link, becausedevice_vram_statslives there, so I kept the whole PR and made one hand edit to disable the steering: the budget is never passed to the placement order inallocate(), andallocate_image()acts as if no budget were available):d3d12_low_vramfails atd3d12_low_vram_test.cpp:173,after.steered_allocations > 0; all 160 spillable textures stay in VRAM and none is steered (the critical 6 stay in VRAM too). That is a mutation of mine, not a revert of the PR.d3d12_state_mapPassed,d3d12_low_vramPassed (ALL CHECKS PASSED: with the mode forced on and a 2048 MiB cap, 75 of 160 spillable 16 MiB textures stay in VRAM and 85 are steered to system memory, 0 forced spills, 6 of 6 critical RT/DS in VRAM; theLEONIDA_RT_AS=offchecks pass),d3d12_vulkan_devicePassed. None skipped.low_vram_mode=0, and the stress device forces it withLEONIDA_LOW_VRAM=onplus a cap. The 4 GB behaviour reported in the PR is not something I could reproduce.dumpbin /importsofgta6rt.exe, DLL!symbol, sorted: 700 entries on main and on main + PR, identical).Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo,
-DLEONIDA_REQUIRE_VULKAN=ON, Vulkan SDK 1.4.363.1.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.