Skip to content

gpu: 8 GB over-budget guard, profile and page-pool prototype - #2658

Draft
olgundemirkan wants to merge 1 commit into
ProjectLeonida:mainfrom
olgundemirkan:pr/8gb-memory
Draft

olgundemirkan wants to merge 1 commit into
ProjectLeonida:mainfrom
olgundemirkan:pr/8gb-memory

Conversation

@olgundemirkan

Copy link
Copy Markdown

Claimed in coordination issue as: n/a — draft for review; I can split it if the page-pool prototype should be separate.

Depends on: none.

Fixes: none.

What and why

This is the 8 GB memory work from testing the D3D12 runtime on an RTX 3060 Ti
8 GB / 16 GB RAM PC. It has four parts, and only the first two are meant for
play today:

  1. resource.rs over-budget guard. room() now refuses new host copies
    while Windows reports the card over its DXGI budget, even when a
    LEONIDA_TEXTURE_BUDGET_MB is set. The 8 GB profiles set that budget, so the
    old order kept adding copies at 7.8 GB of a 7.25 GB budget until the driver
    faulted.
  2. scripts/play-8gb.ps1. The measured 540p profile: title upscaler, no
    DLSS and no frame generation, texture budget 4000 MB, staging 1024 MB, card
    buffers 1024 MB, 512 MB of title-memory windows, page writes 262, heap
    recheck 120.
  3. LEONIDA_PRELOAD_DLLS (preload.rs + loader/app call). Loads
    user-supplied DLLs before the GPU is made. Off unless set; no DLLs are in
    the repository.
  4. Page-pool in-place prototype (inplace.rs, port.rs, shadow.rs).
    LEONIDA_PORT_CONSTANTS=2, off by default, gathers the 64 KiB pages of a
    page-pool window into one view of ours and opens it as a host heap, so the
    card reads the title's bytes without a PC copy. This is the part that needs
    review: it is not ready — the gathered view currently fails with
    MapViewOfFile3 os error 487 on many windows, and only 4 MB of 4,780 MB of
    windows were placed in the test run. The usable parts are 1 and 2.

The full measurements and the failed paths are in
d3d12/docs/8gb-memory-2026-11-30.md.

Tested

cargo check --locked -p leonida --features diagnostics    pass
scripts\play-8gb.ps1 -DryRun                             resolves 540p/own upscaler
RTX 3060 Ti 8 GB, 540p, textures 4000, card 1024          18-19 fps, 7.76-7.82 GB
same, heaviest cutscene                                   driver fault after 6m54s
RTX 3060 Ti 8 GB, 540p, textures 3000, card 1024          17 fps, device removed after 8m51s
RTX 3060 Ti 8 GB, page-pool prototype                     1 region/4 MB, 65 host refusals, 10 fps

The remaining crash is the 8 GB VRAM + WDDM shared-memory wall, not a missing
HRESULT check. A debug-layer/full-DRED run found no failed Create* and no
severity=3 message before the device was removed.

GPUs tested: NVIDIA RTX 3060 Ti 8 GB, driver 621.40, Windows 11 26H2, Ryzen 5
5600, 16 GB RAM.

AI-assisted: yes — the code changes, the measurements and this text were done
with an AI agent and checked by hand. No game data or DLLs are included.

Checklist

  • Based on current main (c139ba1c8) and merges cleanly.
  • One topic: 8 GB memory work; the page-pool prototype is opt-in and can be
    split into a separate PR if preferred.
  • No game data, keys or decryption.
  • New translator rule: n/a.

@merzleckeier

Copy link
Copy Markdown
Contributor

I reviewed 52cc2580c on GitHub merge 33ac52e6 into 452d1d1b6.

  • MEASURED, build. The exact merge fails in inplace.rs:323 with E0277 and E0308. Main changed sections from a vector to BTreeMap<usize, (u64, bool)>. Replacing the body of section_bytes with views().sections.get(&section).map(|&(bytes, _)| bytes) let the Win64 diagnostics test build complete locally.
  • MEASURED, budget guard. With that lookup adjustment and synthetic memory counters, room() allowed copies on main at and above the reported DXGI budget. The PR refused them at both points and allowed them again below the budget. This repeated in 3/3 runs with the 4000 MiB texture cap and 3/3 with the cap unset. A missing DXGI sample retained the previous decision in these cases.
  • MEASURED, scattered pages. A Win32-only probe reproduced error 487 in 3/3 attempts when mapping one 64 KiB page into an unsplit 128 KiB placeholder. Splitting the reservation first mapped section offsets 0 and 128 KiB into adjacent slots and read the expected bytes in 3/3 controls. VirtualQuery also showed the unsplit range still reserved after the failure. gather_region needs to split the placeholder and release reserved ranges and partial mappings on error. The probe covers the Win32 mapping step. MapViewOfFile3 sizing requirement · Placeholder splitting
  • MEASURED, launcher. In three PowerShell dry runs with mocked RTX 4060 Ti and Streamline present, play-8gb.ps1 resolved 540p with the title upscaler and also emitted LEONIDA_FRAME_GEN=2. RTX 3060 Ti and RTX 4060 Ti without Streamline left it off in three runs each. Adding -NoFrameGen to the wrapper suppressed the clean initial launch, but the generated F1 command dropped it on this base. Replaying the F1 arguments also dropped the texture budget and staging settings and restored 3072 MiB of windows in place of the profile's 512 MiB. The emitted command omits -More.

Win64 probes under Wine 11.22 and launcher dry runs under PowerShell 7.4.21 with synthetic inputs. AI-assisted with OpenAI Codex.

@merzleckeier

Copy link
Copy Markdown
Contributor

Follow-up on the F1 loss of the 8 GB profile's -More values. I prepared a shared launcher fix on main 452d1d1b6. The launcher passes the explicit overrides through the environment as serialized data and applies them with their original precedence when F1 relaunches. A fresh start reads its own arguments and saved settings. Claim · Tested branch da729f60

MEASURED. The regression failed at both restart stages in all three runs on main and passed all three on the fixed branch. In local integration tree 0eebd274, which includes this PR plus #2626 and #2647, the actual play-8gb.ps1 kept all 11 overrides across F1 replay in 3/3 runs, including 4000 MiB for textures, 1024 MiB for staging and 512 MiB for windows. The Motion Blur and -NoFrameGen launcher tests passed on that tree.

PowerShell 7.4.21 on CachyOS, mocked CIM/SDK presence, dry runs only. AI-assisted with OpenAI Codex.

@merzleckeier

Copy link
Copy Markdown
Contributor

Native Windows follow-up for the 8 GB F1 restart with the -More fix. Windows Actions job and logs.

  • Started play-8gb.ps1 -DryRun three times each under Windows PowerShell 5.1 and PowerShell 7.6. Each start was followed by two new powershell.exe processes invoked with the launcher’s emitted restart arguments.
  • All 18 invocations preserved all 11 -More overrides, including the 4,000 MiB texture budget, 1,024 MiB staging limit, and 512 MiB upload window. The 0.5 render scale and title upscaler flag also survived both restarts.
  • The committed -More, NoFrameGen, and MotionBlur launcher tests passed on the same run.

The test combined this PR with #2626, #2647, and the fix above. It exercised the restart command and environment handoff on native Windows using a synthetic executable path in DryRun mode.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026

@aslan2142 aslan2142 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the 8 GB prototype and measurements. This PR is still a draft and currently has merge conflicts with main; as @merzleckeier also measured, d3d12/crates/leonida-gpu/src/inplace.rs:323 no longer compiles against main's BTreeMap-based sections, and the F1 restart -More preservation issue needs to be addressed. Please rebase onto main, fix the inplace.rs compilation against BTreeMap, ensure the new d3d12 (windows-latest) CI check passes, and mark ready when finalized.

(AI-assisted review.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants