Memory: preserve XMem graphics alignment in the Windows fallback #1333

Open
anakatt wants to merge 1 commit from upstream-pr/1343 into main
anakatt commented 2026-11-24 15:00:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by anakatt on 2026-11-24T15:00:30Z.


I fixed XMemAllocDefault dropping its computed graphics alignment when allocation falls back to Windows memory. The sparse and coherent paths receive that alignment; the final VirtualAlloc call did not.

What is in it

  • Keep the normal 64 KiB Windows allocation path unchanged.
  • Use VirtualAlloc2 with MEM_ADDRESS_REQUIREMENTS for larger alignments, without padding allocations or changing their native release mechanism.
  • Test the native fallback directly so global UMA initialization cannot mask it: 64 KiB, 128 KiB, 4 MiB, 32 MiB and 2 GiB alignments, rounded region size, committed/read-write state, zero initialization and successful release. Update README.

Tested

I ran cargo test --locked -p xcl --lib hle::kernelx::tests::windows_graphics_allocations_preserve_alignment -- --exact --test-threads=4 in a Windows 11 Pro ARM64 UTM VM (10.0.26100.1742, 4 GiB RAM, Red Hat VirtIO GPU DOD 22.7.38.43), with Rust 1.100.0, x86_64-pc-windows-msvc and Windows 11 SDK.

  • Before the fix, after extracting the existing native fallback unchanged: 0 passed, 1 failed, 0 ignored, 719 filtered out. A 128 KiB-alignment request returned 0x29abfa30000, offset 65536 from the required boundary.
  • After the fix: 1 passed, 0 failed, 0 ignored, 719 filtered out. All five cases ran; no SKIPPED output.

Source: main 47efa2ecea0a12934719ae69b81930cf02a4b1c3 archive with the changed kernelx.rs copied in before committing ab3a1ec936e42de18cf0a0e3d30b8a1290930555; not a clean head checkout. Shared target directory cleaned for xcl before the reproduction; one build job; dev/test debug info disabled.

Not tested

Full workspace suite, Windows 10, native x64 Windows hardware, Wine, GPU allocation paths, forced whole-API UMA exhaustion and real-title runs. I did not build or run XCL on macOS. This changes address alignment, not physical page sizes.

Regression run

The required clean main/head real-title scripts/smoke.ps1 runs have not been performed. No xcl-smoke blocks are available; this remains a draft.

AI use

omp, openai-codex/gpt-6-astra: investigated, wrote the fix and regression test, ran the Windows checks, and prepared this PR.

<!-- greyfinch-sync:ivall/xcl:issue:5474656142 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1343). Originally posted by [anakatt](https://github.com/anakatt) on 2026-11-24T15:00:30Z. --- I fixed XMemAllocDefault dropping its computed graphics alignment when allocation falls back to Windows memory. The sparse and coherent paths receive that alignment; the final VirtualAlloc call did not. ## What is in it - Keep the normal 64 KiB Windows allocation path unchanged. - Use VirtualAlloc2 with [MEM_ADDRESS_REQUIREMENTS](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-mem_address_requirements) for larger alignments, without padding allocations or changing their native release mechanism. - Test the native fallback directly so global UMA initialization cannot mask it: 64 KiB, 128 KiB, 4 MiB, 32 MiB and 2 GiB alignments, rounded region size, committed/read-write state, zero initialization and successful release. Update README. ## Tested I ran `cargo test --locked -p xcl --lib hle::kernelx::tests::windows_graphics_allocations_preserve_alignment -- --exact --test-threads=4` in a Windows 11 Pro ARM64 UTM VM (10.0.26100.1742, 4 GiB RAM, Red Hat VirtIO GPU DOD 22.7.38.43), with Rust 1.100.0, x86_64-pc-windows-msvc and Windows 11 SDK. - Before the fix, after extracting the existing native fallback unchanged: **0 passed, 1 failed, 0 ignored, 719 filtered out**. A 128 KiB-alignment request returned `0x29abfa30000`, offset 65536 from the required boundary. - After the fix: **1 passed, 0 failed, 0 ignored, 719 filtered out**. All five cases ran; no `SKIPPED` output. Source: main `47efa2ecea0a12934719ae69b81930cf02a4b1c3` archive with the changed kernelx.rs copied in before committing `ab3a1ec936e42de18cf0a0e3d30b8a1290930555`; not a clean head checkout. Shared target directory cleaned for xcl before the reproduction; one build job; dev/test debug info disabled. ## Not tested Full workspace suite, Windows 10, native x64 Windows hardware, Wine, GPU allocation paths, forced whole-API UMA exhaustion and real-title runs. I did not build or run XCL on macOS. This changes address alignment, not physical page sizes. ## Regression run The required clean main/head real-title `scripts/smoke.ps1` runs have not been performed. No `xcl-smoke` blocks are available; this remains a draft. ## AI use omp, openai-codex/gpt-6-astra: investigated, wrote the fix and regression test, ran the Windows checks, and prepared this PR.
DavidM1911 commented 2026-11-24 17:06:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T16:11:16Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7137257892 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1343#issuecomment-7137257892). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T16:11:16Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. Thanks!
Toons29 commented 2026-11-25 04:10:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:24:51Z.


Regression run of ab3a1ec9 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: ab3a1ec936e42de18cf0a0e3d30b8a1290930555
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1632 (PresentX 1632)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14811 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7151891181 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1343#issuecomment-7151891181). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T03:24:51Z. --- Regression run of `ab3a1ec9` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: ab3a1ec936e42de18cf0a0e3d30b8a1290930555 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1632 (PresentX 1632) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14811 MB ``` Against the limits in CONTRIBUTING.md: 101 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
github-actions[bot] commented 2026-11-29 07:43:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:43:00Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7252645582 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1343#issuecomment-7252645582). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T07:43:00Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:29:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:29:15Z.


Triage (#1607) – head ab3a1ec

No open or merged PR makes the same change; main's XMemAllocDefault still ends in a plain VirtualAlloc that ignores align. #3092 changes the page-size grain in the same function but not the Windows fallback.
windows_graphics_alloc uses VirtualAlloc2 address requirements only above the 64 KiB grain, which is what Windows requires. The README line is an implementation detail placed under the title-data paths bullet; consider dropping it. The failing check is the PR description check.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301820806 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1343#issuecomment-7301820806). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:29:15Z. --- **Triage (#1607)** – head ab3a1ec No open or merged PR makes the same change; main's `XMemAllocDefault` still ends in a plain `VirtualAlloc` that ignores `align`. #3092 changes the page-size grain in the same function but not the Windows fallback. `windows_graphics_alloc` uses `VirtualAlloc2` address requirements only above the 64 KiB grain, which is what Windows requires. The README line is an implementation detail placed under the title-data paths bullet; consider dropping it. The failing check is the PR description check. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1343:upstream-pr/1343'
git switch 'upstream-pr/1343'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1343'
git switch 'upstream-pr/1343'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1343'
git switch 'upstream-pr/1343'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1343'
git switch 'main'
git merge --squash 'upstream-pr/1343'
git switch 'main'
git merge --ff-only 'upstream-pr/1343'
git switch 'main'
git merge 'upstream-pr/1343'
git push origin 'main'
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
xcl-dev/xcl!1333
No description provided.