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

Closed
ToxicmaggotRP wants to merge 11 commits from upstream-pr/501 into main
ToxicmaggotRP commented 2026-11-24 04:14:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ToxicmaggotRP on 2026-11-24T04:14:15Z.


[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).](https://github.com/Marvisak/VIctory/pull/501)

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574462648 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/501). Originally posted by [ToxicmaggotRP](https://github.com/ToxicmaggotRP) on 2026-11-24T04:14:15Z. --- [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://github.com/Marvisak/VIctory/pull/501)
aycow commented 2026-11-24 06:55:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T04:44:49Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122300395 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/501#issuecomment-7122300395). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T04:44:49Z. --- 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 commented 2026-11-24 06:56:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T06:34:25Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124072040 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/501#issuecomment-7124072040). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T06:34:25Z. --- 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 commented 2026-11-24 06:56:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T06:49:43Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124332365 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/501#issuecomment-7124332365). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T06:49:43Z. --- 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)
aycow commented 2026-11-24 08:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T07:29:51Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125055308 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/501#issuecomment-7125055308). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T07:29:51Z. --- 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)
mercuryVM commented 2026-11-24 16:03:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T15:36:40Z.

Review: COMMENTED


Tested e5990ea on Windows 11, RTX 5070, MSVC: builds; cargo test -p victory-gpu -- --test-threads=1 44 passed, 0 failed, 1 ignored, including placed_custom_heap_shares_memory_between_cpu_and_gpu on the hardware device.

This is a probe: nothing outside the test calls unified_buffer, so it has no effect on a run. The arena itself (one placed buffer over a 256 MiB CUSTOM/WRITE_BACK/L0 heap, mapped once, bump-allocated at 256-byte alignment with checked arithmetic) looks right.

Findings:

  1. State mismatch in the test (host.rs, the dispatch in placed_custom_heap_shares_memory_between_cpu_and_gpu). source and destination are two offsets in the same ID3D12Resource, so there is one state for both. The test moves it to UNORDERED_ACCESS and then reads source through a root SRV. A shader-resource read needs NON_PIXEL_SHADER_RESOURCE, and that can't be combined with UNORDERED_ACCESS. It works on hardware, but it is outside the resource-state rules, and GPU-based validation flags it. Fix: read the source through a second root UAV (RWByteAddressBuffer source : register(u1), root signature UAV(u0), UAV(u1)).
  2. Design point for the follow-ups (worth stating in #407). Because the arena is one resource, every suballocation shares one state. Anything that later binds title memory from it as SRV, index, vertex or indirect arguments has to switch the state of the whole arena between uses, or keep it in COMMON and rely on promotion and decay. That constrains how title allocations can be routed here.
  3. Nit: the aliasing barrier isn't needed. Nothing else is placed in this heap, and buffers need no initialization. It is harmless.
  4. Nit: the test asserts exact offsets (world_heap.offset == 2 * SLOT), so it relies on being the first user of the process-wide host's arena. Once anything else allocates from it, this test breaks. Compare offsets relative to the first allocation instead.

It conflicts with current main in host.rs (2 hunks), so it isn't merged into our fork.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6042367876 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/501#pullrequestreview-6042367876). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T15:36:40Z. **Review:** COMMENTED --- Tested e5990ea on Windows 11, RTX 5070, MSVC: builds; `cargo test -p victory-gpu -- --test-threads=1` 44 passed, 0 failed, 1 ignored, including `placed_custom_heap_shares_memory_between_cpu_and_gpu` on the hardware device. This is a probe: nothing outside the test calls `unified_buffer`, so it has no effect on a run. The arena itself (one placed buffer over a 256 MiB CUSTOM/WRITE_BACK/L0 heap, mapped once, bump-allocated at 256-byte alignment with checked arithmetic) looks right. Findings: 1. **State mismatch in the test (host.rs, the dispatch in `placed_custom_heap_shares_memory_between_cpu_and_gpu`).** `source` and `destination` are two offsets in the same `ID3D12Resource`, so there is one state for both. The test moves it to `UNORDERED_ACCESS` and then reads `source` through a root SRV. A shader-resource read needs `NON_PIXEL_SHADER_RESOURCE`, and that can't be combined with `UNORDERED_ACCESS`. It works on hardware, but it is outside the resource-state rules, and GPU-based validation flags it. Fix: read the source through a second root UAV (`RWByteAddressBuffer source : register(u1)`, root signature `UAV(u0), UAV(u1)`). 2. **Design point for the follow-ups (worth stating in #407).** Because the arena is one resource, every suballocation shares one state. Anything that later binds title memory from it as SRV, index, vertex or indirect arguments has to switch the state of the whole arena between uses, or keep it in `COMMON` and rely on promotion and decay. That constrains how title allocations can be routed here. 3. Nit: the aliasing barrier isn't needed. Nothing else is placed in this heap, and buffers need no initialization. It is harmless. 4. Nit: the test asserts exact offsets (`world_heap.offset == 2 * SLOT`), so it relies on being the first user of the process-wide host's arena. Once anything else allocates from it, this test breaks. Compare offsets relative to the first allocation instead. It conflicts with current main in `host.rs` (2 hunks), so it isn't merged into our fork. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 00:05:32 +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!501
No description provided.