GPU: query the allocation type when guarding mapped memory #119

Closed
github-bot wants to merge 1 commit from gh-pr/119/head into gh-pr/119/base
Owner

@⁠ifBars on GitHub · 2026-11-24 00:40 UTC · original
ifBars:perf/mapped-region-query → main · +82 −6 · 1 files · 1 commits · closed without merging

When GetWriteWatch falls back to guarded memory, guard asks whether the first address belongs to a mapped view. VirtualQuery also determines the length of the run of pages with matching protection. On a large, clean view, finding that length can dominate the call.

This changes the first query to QueryVirtualMemoryInformation(MemoryRegionInfo). File-backed, page-file-backed and physical views take the mapped path. Private allocations and images take the existing non-view path. Unrecognized or combined flags and failed queries fall back to the original VirtualQuery check. Windows allocation information

Synthetic benchmark

On an i5-11600K running Windows 10 22H2, both versions of writes() ran in one optimized test executable against the same 174 MiB file-backed section. Each workload had a warm-up and nine paired samples with alternating order. The sparse case wrote to one guarded page before each call and checked its journal entry. Values are the median microseconds per call, including construction of the page journal.

Range Writes before the call Current main This change
6 MiB None 327.30 4.28
6 MiB One page 19.72 9.20
174 MiB None 893.68 94.44
174 MiB One page 321.94 108.32

Validation

  • Built and ran the focused unit tests directly from watch.rs on Windows. Both tests passed on the upstream baseline. All three passed with this change, including the new file-view, stack, image and free-address cases.
  • A separate synthetic section-mapping check agreed with the prior query for aliased views, reserved and committed pages, and an address reused for a private allocation.
  • The staged and full asset-policy checks passed. The measurements above cover CPU memory tracking. Gameplay frame time was not measured.

AI-assisted development and testing with Codex.

**@⁠ifBars** on GitHub · 2026-11-24 00:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/119) `ifBars:perf/mapped-region-query` → `main` · +82 −6 · 1 files · 1 commits · closed without merging When `GetWriteWatch` falls back to guarded memory, `guard` asks whether the first address belongs to a mapped view. `VirtualQuery` also determines the length of the run of pages with matching protection. On a large, clean view, finding that length can dominate the call. This changes the first query to `QueryVirtualMemoryInformation(MemoryRegionInfo)`. File-backed, page-file-backed and physical views take the mapped path. Private allocations and images take the existing non-view path. Unrecognized or combined flags and failed queries fall back to the original `VirtualQuery` check. [Windows allocation information](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/ns-memoryapi-win32_memory_region_information) ### Synthetic benchmark On an i5-11600K running Windows 10 22H2, both versions of `writes()` ran in one optimized test executable against the same 174 MiB file-backed section. Each workload had a warm-up and nine paired samples with alternating order. The sparse case wrote to one guarded page before each call and checked its journal entry. Values are the median microseconds per call, including construction of the page journal. | Range | Writes before the call | Current main | This change | | --- | --- | ---: | ---: | | 6 MiB | None | 327.30 | 4.28 | | 6 MiB | One page | 19.72 | 9.20 | | 174 MiB | None | 893.68 | 94.44 | | 174 MiB | One page | 321.94 | 108.32 | ### Validation - Built and ran the focused unit tests directly from `watch.rs` on Windows. Both tests passed on the upstream baseline. All three passed with this change, including the new file-view, stack, image and free-address cases. - A separate synthetic section-mapping check agreed with the prior query for aliased views, reserved and committed pages, and an address reused for a private allocation. - The staged and full asset-policy checks passed. The measurements above cover CPU memory tracking. Gameplay frame time was not measured. AI-assisted development and testing with Codex.
Ask Windows for the live allocation type before guarding physical-page views. Keep the existing VirtualQuery fallback for unknown region flags and query failures. This avoids walking a long run of read-only pages solely to learn its memory type.

Validate ordinary mapped files, executable images, private stack memory and free addresses alongside the existing pagefile guard and write-watch tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:58 +00:00
github-bot closed this pull request 2026-11-26 03:50:58 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:46 UTC · original

Tested under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build of 095e44a with cargo xwin ... --target x86_64-pc-windows-msvc: pass, no regression.

  • victory_gpu test binary: 37 passed, 3 failed — the PR adds one test (36 → 37).
  • The 3 failures are the same environment-only ones as on main: argument_clamp_builds (Wine's d3dcompiler_47 cannot compile the clamp shader), a_rejected_blob_gives_an_empty_library (vkd3d returns E_INVALIDARG for an empty pipeline library), buffer_data_reaches_the_host_texture (see #128 — VirtualQuery reports vkd3d-mapped memory as MEM_FREE).
  • This does not fix #128: that guard is texture::committed in copy_mapped, not watch::guard. The new QueryVirtualMemoryInformation path was exercised by the passing tests.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/119#issuecomment-7118422064) Tested under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build of `095e44a` with `cargo xwin ... --target x86_64-pc-windows-msvc`: **pass, no regression**. - `victory_gpu` test binary: **37 passed, 3 failed** — the PR adds one test (36 → 37). - The 3 failures are the same environment-only ones as on `main`: `argument_clamp_builds` (Wine's `d3dcompiler_47` cannot compile the clamp shader), `a_rejected_blob_gives_an_empty_library` (vkd3d returns `E_INVALIDARG` for an empty pipeline library), `buffer_data_reaches_the_host_texture` (see #128 — `VirtualQuery` reports vkd3d-mapped memory as `MEM_FREE`). - This does not fix #128: that guard is `texture::committed` in `copy_mapped`, not `watch::guard`. The new `QueryVirtualMemoryInformation` path was exercised by the passing tests. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!119
No description provided.