Bind translated vertex streams to bounded live placed buffers #1316

Manually merged
github merged 3 commits from gh-pr/1316/head into gh-pr/1316/base 2026-11-26 22:57:30 +00:00
Owner

@⁠R0Y00 on GitHub · 2026-11-24 07:45 UTC · original
R0Y00:codex/materialize-placed-vertex-view → main · +391 −20 · 12 files · 3 commits · merged 2026-11-24 08:13 UTC

Refs #874, #1305 and #1307.

Slot 133 already records each placed resource. The translated vertex-stream path previously read the supplied CPU address into a transient upload ring during command recording. For a live aliased GPU buffer, that changes what a draw sees if the application updates a valid vertex before queue submission.

Slot 48 now resolves the full guest vertex address and the declared view length against the existing resource records for the command list's creating device. Final release retires the active placement. Eligible views bind the desktop resource as a bounded raw SRV. A declared range spanning the registered end or multiple placements is rejected before staging. The translated draw uses its existing single render device and descriptor heap and checks list/heap ownership. CPU-backed committed fallbacks still stage their data.

The new EXE/DLL fixture opens two CPU-visible buffers with guest bases 1 TiB apart, reads the last valid DWORD, and changes both words after recording and before submission. The GPU sees the new values. An eight-byte view starting at the last DWORD is rejected; the shader reads only offset zero of a null descriptor. After a fence, the EXE releases the high resource, registers a larger buffer at the same address, and checks the new endpoint as well as the overlapping original endpoint. Both passes also verify the low range.

Windows 11 26200.9974, MSVC x64 Release, debug layer off, candidate fc547dd7. RTX 4060 Laptop driver 32.0.16.1656 and Microsoft WARP 10.0.26100.9818 each returned all 64 expected RGBA pixels. Ten tests passed, zero failed, zero skipped.

cmake --build --preset release --target startup_stream_consumer
ctest --preset release --no-tests=error --output-on-failure -R '^startup_(placed_vertex|address_srv|address_bc_view|stream_draw|xg_bc_chain)_'
**@⁠R0Y00** on GitHub · 2026-11-24 07:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1316) `R0Y00:codex/materialize-placed-vertex-view` → `main` · +391 −20 · 12 files · 3 commits · merged 2026-11-24 08:13 UTC Refs #874, #1305 and #1307. Slot 133 already records each placed resource. The translated vertex-stream path previously read the supplied CPU address into a transient upload ring during command recording. For a live aliased GPU buffer, that changes what a draw sees if the application updates a valid vertex before queue submission. Slot 48 now resolves the full guest vertex address and the declared view length against the existing resource records for the command list's creating device. Final release retires the active placement. Eligible views bind the desktop resource as a bounded raw SRV. A declared range spanning the registered end or multiple placements is rejected before staging. The translated draw uses its existing single render device and descriptor heap and checks list/heap ownership. CPU-backed committed fallbacks still stage their data. The new EXE/DLL fixture opens two CPU-visible buffers with guest bases 1 TiB apart, reads the last valid DWORD, and changes both words after recording and before submission. The GPU sees the new values. An eight-byte view starting at the last DWORD is rejected; the shader reads only offset zero of a null descriptor. After a fence, the EXE releases the high resource, registers a larger buffer at the same address, and checks the new endpoint as well as the overlapping original endpoint. Both passes also verify the low range. Windows 11 26200.9974, MSVC x64 Release, debug layer off, candidate fc547dd7. RTX 4060 Laptop driver 32.0.16.1656 and Microsoft WARP 10.0.26100.9818 each returned all 64 expected RGBA pixels. Ten tests passed, zero failed, zero skipped. ```powershell cmake --build --preset release --target startup_stream_consumer ctest --preset release --no-tests=error --output-on-failure -R '^startup_(placed_vertex|address_srv|address_bc_view|stream_draw|xg_bc_chain)_' ```
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:57:29 +00:00
github manually merged commit 54ecfced7f into gh-pr/1316/base 2026-11-26 22:57:30 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 07:54 UTC · original

Updated in a0e6ca94. Slot 133 now publishes the resource record and address index under one scope-held lock. If either allocation fails, the caller receives E_OUTOFMEMORY and a null output. Existing placements remain usable, and the same guest address can be retried.

The checked-in startup_placement_alloc test failed both allocations in turn and verified rollback, immediate lock acquisition, and retry. Windows Release ran 11 tests with 11 passes and zero skips:

ctest --test-dir out/test --no-tests=error --output-on-failure -R '^startup_(placement_alloc|placed_vertex|address_srv|address_bc_view|stream_draw|xg_bc_chain)'

I also injected each failure separately in a local test-only shim and called slot 133 through its normal vtable. Both the RTX 4060 Laptop (32.0.16.1656) and WARP (10.0.26100.9818) returned E_OUTOFMEMORY and cleared a non-null output sentinel. The same-address retry then matched all 64 expected pixels in each of the four runs. Windows 11 build 26200.9974, debug layer off.

**@⁠R0Y00** on GitHub · 2026-11-24 07:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1316#issuecomment-7125504114) Updated in a0e6ca94. Slot 133 now publishes the resource record and address index under one scope-held lock. If either allocation fails, the caller receives E_OUTOFMEMORY and a null output. Existing placements remain usable, and the same guest address can be retried. The checked-in startup_placement_alloc test failed both allocations in turn and verified rollback, immediate lock acquisition, and retry. Windows Release ran 11 tests with 11 passes and zero skips: ```powershell ctest --test-dir out/test --no-tests=error --output-on-failure -R '^startup_(placement_alloc|placed_vertex|address_srv|address_bc_view|stream_draw|xg_bc_chain)' ``` I also injected each failure separately in a local test-only shim and called slot 133 through its normal vtable. Both the RTX 4060 Laptop (32.0.16.1656) and WARP (10.0.26100.9818) returned E_OUTOFMEMORY and cleared a non-null output sentinel. The same-address retry then matched all 64 expected pixels in each of the four runs. Windows 11 build 26200.9974, debug layer off.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 07:51 UTC · original · reviewed

Peer review at commit fc547dd7c38e7d3cd66b237ce0715ba1e6f8849f:

Checks

  • Linux:
    • git diff --check origin/main...HEAD: passed
    • tests/docs_links_check.py: passed (16 Markdown files, 289 links)
    • tests/bidi_controls_check.py: passed (1092 tracked files)
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): cmake --build --preset dev --target startup_stream_consumer -- -j 6 (27.13s), ctest --preset dev -R '^startup_placed_vertex_warp$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (0.74s)
    • Release /O2 (--preset release): cmake --build --preset release --target startup_stream_consumer -- -j 6 (38.53s), ctest --preset release -R '^startup_placed_vertex_warp$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (0.86s)

Findings

  • src/startup_stubs/d3d12_xs_device.cpp (device_place_resource_x): note_resource(w, desc, desc->Width, aliased ? Placement::aliased_buffer : Placement::copied_buffer, self) registers Placement and desc->Width unconditionally, removing the prior desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? desc->Width : 0 check. If a placed non-buffer resource (e.g. a 2D texture) is created at an address that overlaps a vertex buffer view, placed_vertex_view will treat desc->Width (pixel width) as a byte extent, and buffer_view could attempt CreateShaderResourceView with D3D12_SRV_DIMENSION_BUFFER on a non-buffer resource. Gating Placement (and bytes) on desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER would prevent non-buffer placements from entering placement_index.
  • src/startup_stubs/d3d12_capture.inl (retire_placement): group.max_width is not shrunk when a placement is retired; this is safe as a conservative upper bound (since the loop stops at it->first < end), though retiring an unusually large buffer leaves max_width wide for group 1 (> 64 KiB).
**@⁠tedin7** on GitHub · 2026-11-24 07:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1316#pullrequestreview-6035505584) · **reviewed** Peer review at commit `fc547dd7c38e7d3cd66b237ce0715ba1e6f8849f`: ### Checks - **Linux**: - `git diff --check origin/main...HEAD`: passed - `tests/docs_links_check.py`: passed (16 Markdown files, 289 links) - `tests/bidi_controls_check.py`: passed (1092 tracked files) - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - **Debug (`--preset dev`)**: `cmake --build --preset dev --target startup_stream_consumer -- -j 6` (`27.13s`), `ctest --preset dev -R '^startup_placed_vertex_warp$' --parallel 4 --no-tests=error --output-on-failure`: **1/1 passed** (`0.74s`) - **Release `/O2` (`--preset release`)**: `cmake --build --preset release --target startup_stream_consumer -- -j 6` (`38.53s`), `ctest --preset release -R '^startup_placed_vertex_warp$' --parallel 4 --no-tests=error --output-on-failure`: **1/1 passed** (`0.86s`) ### Findings - **`src/startup_stubs/d3d12_xs_device.cpp` (`device_place_resource_x`)**: `note_resource(w, desc, desc->Width, aliased ? Placement::aliased_buffer : Placement::copied_buffer, self)` registers `Placement` and `desc->Width` unconditionally, removing the prior `desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? desc->Width : 0` check. If a placed non-buffer resource (e.g. a 2D texture) is created at an address that overlaps a vertex buffer view, `placed_vertex_view` will treat `desc->Width` (pixel width) as a byte extent, and `buffer_view` could attempt `CreateShaderResourceView` with `D3D12_SRV_DIMENSION_BUFFER` on a non-buffer resource. Gating `Placement` (and `bytes`) on `desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER` would prevent non-buffer placements from entering `placement_index`. - **`src/startup_stubs/d3d12_capture.inl` (`retire_placement`)**: `group.max_width` is not shrunk when a placement is retired; this is safe as a conservative upper bound (since the loop stops at `it->first < end`), though retiring an unusually large buffer leaves `max_width` wide for group 1 (`> 64 KiB`).
This discussion has been locked. Commenting is limited to contributors.
No description provided.