gpu: probe a CPU-visible placed-buffer arena #501

Closed
github-bot wants to merge 11 commits from gh-pr/501/head into gh-pr/501/base
Owner

@⁠ToxicmaggotRP on GitHub · 2026-11-24 04:14 UTC · original
ToxicmaggotRP:gpu/unified-memory-arena-probe → main · +444 −10 · 1 files · 11 commits · closed without merging

[Related to #407. This is the first isolated step toward the CPU/GPU shared-memory path described there, and groundwork for the commit-limit investigation in #471.

What

  • Adds a lazily initialized 256 MiB D3D12 custom heap with CPU write-back pages in L0 memory.
  • Places one buffer resource across the heap and maps it once, so every 256-byte-aligned suballocation uses the same mapped CPU base and GPU virtual-address base plus its offset.
  • Uses checked size/offset arithmetic and returns None if heap creation or mapping fails, capacity is exhausted, or size rounding overflows.
  • Exercises CPU writes, root-SRV reads, UAV writes, and CPU readback after the queue fence. The test verifies a 174 MiB allocation fits, and that exhaustion and overflow return None.

The arena uses one placed resource across the heap because separate placed resources are not guaranteed to have contiguous GPU virtual addresses. The test uses the D3D12 aliasing barrier to activate the resource before its first GPU use, then transitions it for shader access.

Scope and limits

This PR verifies shared CPU/GPU backing and relative offsets on the tested adapter. It does not set the GPU virtual address equal to a title/guest address, route title/XMEM allocations through the arena, or remove the shadow-copy bridge. The world-load commit-limit report in #471 remains outside this PR's scope.

Verification

  • cargo test --locked -p victory-gpu: 44 passed, 1 ignored (benchmark).
  • cargo test --locked --workspace: passed.
  • cargo clippy --locked -p victory-gpu --all-targets: passed.
  • Hardware: Windows 11 Home build 26300, NVIDIA GeForce RTX 4060 Ti.
  • cargo fmt --all -- --check reports formatting differences across existing workspace files; no broad formatting change is included here.
  • GitHub currently reports 0 checks for this PR.

References:

AI-assisted contribution (ChatGPT).](#501)

**@⁠ToxicmaggotRP** on GitHub · 2026-11-24 04:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/501) `ToxicmaggotRP:gpu/unified-memory-arena-probe` → `main` · +444 −10 · 1 files · 11 commits · closed without merging [Related to #407. This is the first isolated step toward the CPU/GPU shared-memory path described there, and groundwork for the commit-limit investigation in #471. ## What - Adds a lazily initialized 256 MiB D3D12 custom heap with CPU write-back pages in L0 memory. - Places one buffer resource across the heap and maps it once, so every 256-byte-aligned suballocation uses the same mapped CPU base and GPU virtual-address base plus its offset. - Uses checked size/offset arithmetic and returns `None` if heap creation or mapping fails, capacity is exhausted, or size rounding overflows. - Exercises CPU writes, root-SRV reads, UAV writes, and CPU readback after the queue fence. The test verifies a 174 MiB allocation fits, and that exhaustion and overflow return `None`. The arena uses one placed resource across the heap because separate placed resources are not guaranteed to have contiguous GPU virtual addresses. The test uses the D3D12 aliasing barrier to activate the resource before its first GPU use, then transitions it for shader access. ## Scope and limits This PR verifies shared CPU/GPU backing and relative offsets on the tested adapter. It does not set the GPU virtual address equal to a title/guest address, route title/XMEM allocations through the arena, or remove the shadow-copy bridge. The world-load commit-limit report in #471 remains outside this PR's scope. ## Verification - `cargo test --locked -p victory-gpu`: 44 passed, 1 ignored (benchmark). - `cargo test --locked --workspace`: passed. - `cargo clippy --locked -p victory-gpu --all-targets`: passed. - Hardware: Windows 11 Home build 26300, NVIDIA GeForce RTX 4060 Ti. - `cargo fmt --all -- --check` reports formatting differences across existing workspace files; no broad formatting change is included here. - GitHub currently reports 0 checks for this PR. References: - [CreatePlacedResource and aliasing-barrier requirements](https://learn.microsoft.com/en-us/windows/desktop/api/d3d12/nf-d3d12-id3d12device-createplacedresource) - [D3D12 resource heaps specification](https://microsoft.github.io/DirectX-Specs/d3d/ResourceHeaps.html) AI-assisted contribution (ChatGPT).](https://git.gtahub.st/github/Marvisak--VIctory/pulls/501)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:06:17 +00:00
github-bot closed this pull request 2026-11-26 04:06:17 +00:00
Author
Owner

@⁠aycow on GitHub · 2026-11-24 04:44 UTC · original

Independent Windows validation of 4ec7939: the stock cargo test -p victory-gpu --features diagnostics host::tests::placed_custom_heap_shares_memory_between_cpu_and_gpu -- --exact --nocapture passed. I also ran the same arena and compute fixture with a local test-only adapter selector using Agility SDK 1.620.2. AMD Radeon Graphics, NVIDIA RTX 5070 Laptop GPU, and WARP all allocated the 256 MiB arena, reserved the 174 MiB slice, and returned 0xb7910c22 through the mapped destination after the fence. Full GPU-based validation and the debug layer reported zero errors.

All three emitted the same advisory: CreatePlacedResource ignored UNORDERED_ACCESS as the buffer’s initial state and used COMMON. I would specify COMMON in the arena and document first-use buffer promotion (or transition explicitly). This validates the Windows placed-buffer primitive and offset arithmetic. Guest VA identity, allocation routing, concurrency and residency remain separate.

I can rerun this matrix on a revised head.

**@⁠aycow** on GitHub · 2026-11-24 04:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/501#issuecomment-7122300395) Independent Windows validation of `4ec7939`: the stock `cargo test -p victory-gpu --features diagnostics host::tests::placed_custom_heap_shares_memory_between_cpu_and_gpu -- --exact --nocapture` passed. I also ran the same arena and compute fixture with a local test-only adapter selector using Agility SDK 1.620.2. AMD Radeon Graphics, NVIDIA RTX 5070 Laptop GPU, and WARP all allocated the 256 MiB arena, reserved the 174 MiB slice, and returned `0xb7910c22` through the mapped destination after the fence. Full GPU-based validation and the debug layer reported zero errors. All three emitted the same advisory: `CreatePlacedResource` ignored `UNORDERED_ACCESS` as the buffer’s initial state and used `COMMON`. I would specify `COMMON` in the arena and document first-use buffer promotion (or transition explicitly). This validates the Windows placed-buffer primitive and offset arithmetic. Guest VA identity, allocation routing, concurrency and residency remain separate. I can rerun this matrix on a revised head.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 06:34 UTC · original

Thanks for switching the placed buffer to COMMON in 262874b. I'm evaluating a narrow opt-in integration that uses the mapped arena for bounded, allocator-owned, GPU-read-only scratch chunks. The committed upload path remains the per-allocation fallback. This gives us a place to measure translated addresses, ownership and allocation pressure before routing title-owned memory. I'll test the exact output and implementation on AMD, NVIDIA and WARP and share the branch and results here.

**@⁠aycow** on GitHub · 2026-11-24 06:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/501#issuecomment-7124072040) Thanks for switching the placed buffer to COMMON in `262874b`. I'm evaluating a narrow opt-in integration that uses the mapped arena for bounded, allocator-owned, GPU-read-only scratch chunks. The committed upload path remains the per-allocation fallback. This gives us a place to measure translated addresses, ownership and allocation pressure before routing title-owned memory. I'll test the exact output and implementation on AMD, NVIDIA and WARP and share the branch and results here.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 06:49 UTC · original

The opt-in scratch integration is available at f68b332 on top of 262874b. It routes only allocator-owned, GPU-read-only list scratch to the mapped arena. The byte-exact fixture checks a nonzero CPU/GPU offset, reset reuse, and committed-upload fallback after capacity is exhausted. AMD Radeon Graphics, RTX 5070 Laptop, and WARP passed with full GBV.

The separate 1 MiB synthetic shadow comparison across three access strides measured 49–89 µs of median submit preparation through the ordinary private-memory shadow and 0–1 µs through the arena. These numbers exclude arena initialization, list and PSO creation, and output checking. The queue-fence interval is recorded separately in the fixture. Branch and reproducible benchmark

**@⁠aycow** on GitHub · 2026-11-24 06:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/501#issuecomment-7124332365) The opt-in scratch integration is available at `f68b332` on top of `262874b`. It routes only allocator-owned, GPU-read-only list scratch to the mapped arena. The byte-exact fixture checks a nonzero CPU/GPU offset, reset reuse, and committed-upload fallback after capacity is exhausted. AMD Radeon Graphics, RTX 5070 Laptop, and WARP passed with full GBV. The separate 1 MiB synthetic shadow comparison across three access strides measured 49–89 µs of median submit preparation through the ordinary private-memory shadow and 0–1 µs through the arena. These numbers exclude arena initialization, list and PSO creation, and output checking. The queue-fence interval is recorded separately in the fixture. [Branch and reproducible benchmark](https://github.com/aycow/VIctory/blob/f68b3329f79ad90feaf958d9a8f84431fae943f2/docs/shared-scratch-probe.md)
Author
Owner

@⁠aycow on GitHub · 2026-11-24 07:29 UTC · original

I extended the read-only scratch work with an opt-in allocation for the host's GPU-writable indirect budget word. It uses independent placed resources in a 4 MiB L0 heap, returns slots only after completion and falls back to a committed buffer per allocation. AMD, RTX 5070 Laptop and WARP checked reset reuse, slot replacement, exhaustion fallback and byte-exact atomic output under full GBV.

The guide separates CPU allocation, submission preparation, and actual GPU timestamps. The results describe one 1,024-thread contended atomic workload. Guest memory and Wine remain separate because their ownership and mapping conditions differ. Implementation and benchmark

**@⁠aycow** on GitHub · 2026-11-24 07:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/501#issuecomment-7125055308) I extended the read-only scratch work with an opt-in allocation for the host's GPU-writable indirect budget word. It uses independent placed resources in a 4 MiB L0 heap, returns slots only after completion and falls back to a committed buffer per allocation. AMD, RTX 5070 Laptop and WARP checked reset reuse, slot replacement, exhaustion fallback and byte-exact atomic output under full GBV. The guide separates CPU allocation, submission preparation, and actual GPU timestamps. The results describe one 1,024-thread contended atomic workload. Guest memory and Wine remain separate because their ownership and mapping conditions differ. [Implementation and benchmark](https://github.com/aycow/VIctory/blob/137c4b11a3ba8b054e5f7063a8e83d9c7a4a9bb3/docs/owned-uav-budget-arena.md)

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!501
No description provided.