Bind translated vertex streams to bounded live placed buffers #1309

Merged
R0Y00 merged 3 commits from upstream-pr/1316 into main 2026-11-24 08:13:43 +00:00
R0Y00 commented 2026-11-24 07:45:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T07:45:41Z.


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)_'
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6577086974 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1316). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T07:45:41Z. --- 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)_' ```
tedin7 commented 2026-11-24 07:51:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:51:58Z.

Review: COMMENTED


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).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6035505584 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1316#pullrequestreview-6035505584). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:51:58Z. **Review:** COMMENTED --- 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`).
R0Y00 commented 2026-11-24 08:01:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T07:54:27Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125504114 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1316#issuecomment-7125504114). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T07:54:27Z. --- 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.
upstream-sync closed this pull request 2026-11-24 09:04:27 +00:00
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
R0Y00/Xbox2Windows!1309
No description provided.