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

Closed
ifBars wants to merge 1 commit from upstream-pr/119 into main
ifBars commented 2026-11-24 00:40:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ifBars on 2026-11-24T00:40:24Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571929639 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/119). Originally posted by [ifBars](https://github.com/ifBars) on 2026-11-24T00:40:24Z. --- 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.
DaviTostes commented 2026-11-24 06:54:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:46:40Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118422064 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/119#issuecomment-7118422064). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:46:40Z. --- 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).
mercuryVM commented 2026-11-24 10:05:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:05:31Z.

Review: APPROVED


Tested 095e44a on Windows 11, RTX 5070, MSVC: the workspace passes (187 outside victory-shader; older base), including allocation_query_recognizes_file_views_and_rejects_nonviews. I didn't re-run the benchmark.

  • QueryVirtualMemoryInformation(MemoryRegionInfo) answers "what kind of allocation is this" without walking same-protection pages, which is the cost VirtualQuery's RegionSize computation adds on a big guarded view.
  • The flag constants match the SDK's bitfield order: Private, MappedDataFile, MappedImage, MappedPageFile, MappedPhysical. Data-file, page-file and physical count as views, matching MEM_MAPPED. Anything else falls back to the old VirtualQuery test, so unknown combinations can't change the answer.
  • Compatibility: the API needs Windows 10 1607 or later, and the import is static, so the binary won't load on older builds. That is below anything with the D3D12 runtime this project requires, so it's fine, but worth a line in the README's requirements.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037224185 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/119#pullrequestreview-6037224185). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:05:31Z. **Review:** APPROVED --- Tested 095e44a on Windows 11, RTX 5070, MSVC: the workspace passes (187 outside `victory-shader`; older base), including `allocation_query_recognizes_file_views_and_rejects_nonviews`. I didn't re-run the benchmark. - `QueryVirtualMemoryInformation(MemoryRegionInfo)` answers "what kind of allocation is this" without walking same-protection pages, which is the cost `VirtualQuery`'s `RegionSize` computation adds on a big guarded view. - The flag constants match the SDK's bitfield order: Private, MappedDataFile, MappedImage, MappedPageFile, MappedPhysical. Data-file, page-file and physical count as views, matching `MEM_MAPPED`. Anything else falls back to the old `VirtualQuery` test, so unknown combinations can't change the answer. - Compatibility: the API needs Windows 10 1607 or later, and the import is static, so the binary won't load on older builds. That is below anything with the D3D12 runtime this project requires, so it's fine, but worth a line in the README's requirements. No issues found. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 23:03:53 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!119
No description provided.