WIP: d3d12: decline file-backed/multi-VMA host imports under Wine and deduplicate import memory types (RT-WINE-HOST-IMPORT-POLICY) #2126
Closed
leonida/mandy
djrolfes wants to merge 0 commits from
djrolfes/rt-wine-mapped-host-import into main
pull from: djrolfes/rt-wine-mapped-host-import
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!2126
Loading…
Reference in a new issue
No description provided.
Delete branch "djrolfes/rt-wine-mapped-host-import"
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-WINE-HOST-IMPORT-POLICY (#1608)
What and why
Under Wine on Linux,
nvidia.korejects long-term pinning (pin_user_pages/FOLL_LONGTERM) of file-backedMAP_SHAREDviews (such as the sparse temp files created underLEONIDA_XMEM_BACKING_DIR) with kernelCannot map memory with base addr ...errors and also rejects host-pointer imports spanning multiple VMAs. Asd3d12_vulkan_device.cppnotes, bursts of those kernel rejections on NVIDIA 620.73 under Wine coincide with spuriousVK_ERROR_OUT_OF_HOST_MEMORY(-1) responses on concurrent normalvkAllocateMemorycalls, causingE_OUTOFMEMORY(0x8007000e) resource-creation failures even with gigabytes of VRAM and RAM free.This change fixes four related issues in the host-import path without altering native Windows host-import eligibility or anonymous pagefile section imports (the four runtime-path invariants below — post-
holdTOCTOU re-check,memory_mutex()around importvkAllocateMemory, single-pass memory-type deduplication, and stopping early onVK_ERROR_INVALID_EXTERNAL_HANDLE— apply on native Windows as well as Wine):runtime/src/host_import_policy.h(HostImportRangeCheckandhost_import_memory_types) and CPU unit testruntime/test/host_import_policy_test.cpp:ntdll!wine_get_version), declinesMEM_MAPPEDregions backed by a named file (K32GetMappedFileNameW > 0) and ranges spanning multipleAllocationBasevalues before calling Vulkan, while keeping anonymousVirtualAlloc(MEM_PRIVATE) and anonymous pagefile sections (CreateFileMappingW(INVALID_HANDLE_VALUE, ...)) importable.HOST_VISIBLE | HOST_COHERENT) and fallback passes so a failing import never probes the same memory type twice.host_range_importableafterleonida::kernel_writes::holdincreate_host_bufferandimport_console_heap(closing the TOCTOU window between the writability check and the pin) and stops probing further memory types onVK_ERROR_INVALID_EXTERNAL_HANDLE.DeviceState::memory_mutex()consistently aroundvkAllocateMemoryinimport_console_heap,OpenExistingHeapFromAddress, and theImageMemoryblock allocator (matchingDeviceState::memory_mutex()'s documented invariant).runtime/test/d3d12_existing_heap_test.cppverifying shadow fallback without host import under Wine.Opened as a draft because prior pull requests are currently open (one-open-PR limit).
Tested
python3 -I scripts/check_no_game_data.pyon all 5 touched/added files: passed.runtime/build/native, Linux / Clang 23.1.5): 100/100 passed (98 passed, 2 conditional skips:shader_library_corpus,vk_sync_validation), including newhost_import_policy.clang-cl+xwin, Wine, network-isolated, no retail files):host_import_policy_test: passedd3d12_console_descriptor_heap_test: passedd3d12_xmem_placed_test: passedd3d12_existing_heap_test(including new sparse disk-file-backed section case): passed, 0 kernelCannot map memoryerrors.--first-run-uiA/B check (no input, 300 s bounded, read-only package/shaders/BCPack predictor, network-isolated, counts/timings only):main(490f5b9ec): exit 126 at 28.42 s (slot 133 depth texture refused,hr=0x8007000e), 16 kernelCannot map memoryerrors across 7MEM_MAPPEDaddresses, 2vkAllocateMemory failed (-1), 347PresentX ok.f5bc25cdc+ fix): ran full 300.88 s time limit (exit 124), 0 kernelCannot map memoryerrors, 0vkAllocateMemory failed (-1), 0 depth-texture refusals, 7,990PresentX ok, 200MEM_PRIVATEslot-133 imports succeeded. Rebased cleanly onto1fe5072afand re-verifiedhost_import_policy_test+d3d12_existing_heap_test.GPUs tested: NVIDIA GeForce RTX 3070 Ti (8 GB), driver 620.73.04, Linux (Arch/Omarchy) under Wine.
AI-assisted: yes.
Checklist
main(1fe5072af) and merges cleanly.docs/design.md, with how it was confirmed. (n/a: runtime-only change)Review at
1431ac4fb: code reading and the policy test (Linux). My Windows test PC is down right now, so no native run in this comment; I can add one on a GTX 1050 Ti / Windows 10 later.HostImportRangeCheckwithwine == falsestill requires a committed, writable page withoutPAGE_WRITECOMBINE | PAGE_NOCACHE | PAGE_GUARD, which is what the removed loops increate_host_buffer/import_console_heapchecked. The file-backed and multi-AllocationBaserefusals only apply under Wine (wine_get_version).kernel_writes::hold(closes the TOCTOU, as described);memory_mutex()is now held around the importvkAllocateMemorycalls (the invariant its comment states; no caller of these paths holds it already, so no self-deadlock on the plainstd::mutex);VK_ERROR_INVALID_EXTERNAL_HANDLE. That one I agree with: the error says the pointer is not importable for the handle type, which another memory type does not change.host_import_policy_testbuilds with plain g++ 20 on Linux (-fsanitize=address,undefined) and passes. It catches both Wine rules: withif (region.mapped_file) return false;removed it fails, and so it does with theallocation_basecomparison removed.The branch merges into current main without conflicts (134 commits behind).
AI-assisted (Claude Code).
Thanks @qhukz13 for the review at
1431ac4fband for checkinghost_import_policy_testunder ASan/UBSan!Verified all four scope notes against
1431ac4fbby code inspection (and left1431ac4fbunchanged so existing Wine/retail/Linux reviews remain valid;git merge-tree --write-tree origin/main HEADis still clean with no conflicts):holdTOCTOU re-check:host_range_importableruns again afterleonida::kernel_writes::holdin bothDeviceState::import_console_heapandResource::create_host_bufferregardless ofrunning_under_wine().DeviceState::memory_mutex()aroundvkAllocateMemory: Held strictly aroundvkAllocateMemoryinDeviceState::import_console_heap,Resource::create_host_buffer,Device::OpenExistingHeapFromAddress, and thestate_.image_memoryblock-allocator callback. Auditing all callers (add_console_heap/DescriptorHeap,create_at_host_address/make_title_buffer,OpenExistingHeapFromAddress, andallocate_image/ImageMemoryPool::allocate) confirms none already holdmemory_mutex()on entry and none of the critical sections call back into any other mutex or runtime function, so self-deadlock or lock-order inversion cannot occur.host_import_types_for/leonida::host_import_memory_typesprobes each allowed memory type at most once across the preferred and fallback passes on all platforms.VK_ERROR_INVALID_EXTERNAL_HANDLE: Applied inimport_console_heap,create_host_buffer, andOpenExistingHeapFromAddress.Updated the PR description accordingly to clarify
"without altering native Windows host-import eligibility"and explicitly name those four cross-platform runtime-path invariants.CPU-only verification re-run in this follow-up (no Windows, Wine, GPU, or game-data run):
python3 -I scripts/check_no_game_data.pyon all 5 touched/added files: passed.cmake -S runtime -B runtime/build && cmake --build runtime/build --target host_import_policy_test --config RelWithDebInfo -j 2 && ctest --test-dir runtime/build -R '^host_import_policy$' --output-on-failure -j 2(Linux / GCC 16.2.1): 1/1 passed.g++ -std=c++20 -O2 -Wall -Wextra -Werror -fsanitize=address,undefined runtime/test/host_import_policy_test.cpp: passed (ok).AI-assisted: yes; no game data.
Rebased onto
origin/main(ec91d695c):1431ac4fb→822d8b0b4.Conflict resolution (
runtime/shims/d3d12_vulkan_device.cpp):state_.image_memoryblock-allocator lambda, kept bothorigin/main'sleonida::memory_breakdown::Owner owner(leonida::memory_breakdown::Consumer::image_blocks);scope and this PR'sstd::lock_guard serial(DeviceState::memory_mutex());aroundvkAllocateMemory. All other hunks (host_range_importable,host_import_types_for,import_console_heap,create_host_buffer,OpenExistingHeapFromAddress,runtime/CMakeLists.txt, andruntime/test/d3d12_existing_heap_test.cpp) applied cleanly with no behavioral changes from1431ac4fb.CPU-only portable verification (Linux, GCC 16.2.1; no Windows/Wine/GPU/game-data run):
python3 -I scripts/check_no_game_data.pyon all 5 touched/added files: passed.python3 -m compileall -q make_game.py tools tests: passed.cmake -S runtime -B runtime/build -DCMAKE_BUILD_TYPE=RelWithDebInfo && cmake --build runtime/build --target host_import_policy_test image_memory_test memory_breakdown_test --config RelWithDebInfo -j 4 && ctest --test-dir runtime/build -R '^(host_import_policy|image_memory|memory_breakdown)$' --output-on-failure -j 4: 3/3 passed.g++ -std=c++20 -O2 -Wall -Wextra -Werror -fsanitize=address,undefined runtime/test/host_import_policy_test.cpp: passed (ok).git merge-tree --write-tree origin/main HEAD: clean.AI-assisted: yes (rebased with Gemini); no game data.
Fresh cold-cache A/B game-run check on current
main(43a9d562d) with--first-run-ui(LEONIDA_XMEM_BACKING_DIRenabled) on Linux + Wine 11.22 + NVIDIA RTX 3070 Ti 8 GB (Profile M), in#2464RUN-block format. All numbers independently recomputed from raw logs and resource samples by a second agent (codex/gpt-6-luna) before posting.PROVISIONAL (n=1 cold per side; plus a second warm clean-main reproduction at 24.36 s).Reading:
n=1cold per side + second warm Arm A check, PROVISIONAL): On currentmain(43a9d562d) under Wine 11.22 + NVIDIA 620.73.04,--first-run-ui(LEONIDA_XMEM_BACKING_DIR) crashes 2/2 in24.36–28.45 swithvkAllocateMemory failed (-1)on both heap 0 and heap 1 despite ~16.9 GiB RAM and ~6 GiB VRAM free. Adding#2126(822d8b0b4) eliminates those failures completely (0fatal heap-0/heap-1 failures,0depth-texture refusals) and advances throughfirst-run UI -> menu -> story load -> world load(283.75 s,5,471presents) while keeping13.08 GiBhost RAM free (vs6.46 GiBin clean-main--runwithoutLEONIDA_XMEM_BACKING_DIR).t=35 s; Arm A crashed at28.45 sbefore any scripted input fired, so the script difference could not have affected Arm A's crash.AI-assisted: Antigravity (Gemini 4 Neon) + Codex (
gpt-6-lunaindependent verification); no game data.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.