runtime: refresh large placed Mesh86 material SRVs #3725

Merged
lambirou merged 9 commits from upstream-pr/3725 into main 2026-12-02 19:14:20 +00:00
lambirou commented 2026-12-01 11:12:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-12-01T11:12:27Z.


Problem

A native Mesh86 material view on a placed buffer was refused when the placed desktop backing did not alias title memory and no GPU copy had filled the range. The representative view is mesh t0, root parameter 0, table byte offset 0xAC0: a raw SRV over the whole 45,613,056-dword placed buffer. It passes the desktop raw-SRV limit, but the binder cannot use the committed default backing as it stands (it starts at zeros) and cannot copy the full view per draw.

Change

  • The Mesh86 material path now adopts the placed buffer's existing committed desktop backing in the linear-buffer refresh machinery. No second default-heap resource is allocated: the first submission before a consumer refreshes the title range, and later submissions copy only changed 4 KiB runs (runs separated by at most one block are merged; more than 1024 runs fall back to one span).
  • The consumer queue waits for the refresh fence and refreshes wait for earlier tracked submissions. A submitted copy or bound UAV marks the backing GPU-written and stops further refreshes; a discarded recording leaves it refreshed from title memory.
  • Adoption validates the range against the desktop resource, probes the title range once, and keeps the existing named refusal when no coherent backing can be established. It is default-on; X2W_D3D12_LINEAR_BUFFERS is not required.
  • Added a source-built fixture and registered it in tests/cmake and the PR preset: two raw SRVs at distinct offsets, one GPU dispatch reading both, a stale token, a UAV token, out-of-range and oversized records, sentinels outside the placed range, refresh-byte checks, a budget check, and a skip-refresh mutant.

Evidence

Build: cmake --preset release; cmake --build --preset release (all targets).

New tests:

ctest --preset release --no-tests=error -R '^startup_mesh86_material_backing_(warp|hardware)$' --output-on-failure
  2/2 passed (WARP, hardware)
ctest --preset release --no-tests=error -R '^startup_mesh86_material_backing_mutant_(warp|hardware)$' --output-on-failure
  2/2 passed (WILL_FAIL: both normal tests pass and both stale-refresh mutants fail)

The fixture prints, on WARP and hardware:

material backing: first 65536 bytes, one-word change 4 bytes, second one-word change 4 bytes, two disjoint words 8 bytes; adopted 1, linear placements 0
budget buffer: 1 objects / 65536 bytes before and after adoption

Existing focused checks:

ctest --preset release -j1 -R '^linear_buffer_backing_(copy|stale|contention)_warp$|^linear_buffer_backing_skip_refresh_control$' --output-on-failure
  4/4 passed
ctest --preset release -j1 -R '^startup_mesh86_srv_proof$|^runtime_mesh86_cache_cli_check$|^startup_indirect_mesh_cache_(warp|heap_warp|texture_map_warp|heap_wide_warp|constants_wide_warp)$' --output-on-failure
  7/7 passed
ctest --preset release -j1 -R '^native_direct_mesh$|^startup_indirect_draw_indexed_warp$|^startup_indirect_draw_warp$' --output-on-failure
  3/3 passed

The full linear-buffer WARP family and its 14 negative controls also passed (22/22). startup_tools_lint passed, and tests/docs_links_check.py checked 208 Markdown files and 803 links.

Hardware: AMD Radeon RX 9060 XT (vendor 0x1002, device 0x7590), driver 32.0.32029.2010, Windows 11 build 26300 (26H2), debug layer off. The WARP run used the software adapter.

Chain and remaining refusal

The fixture's correlated chain is: material table record resolved through the production indirect_table_buffer(..., InputBufferUse::mesh86_material) path, backing adopted, list recorded, list closed and submitted through the queue wrapper, refresh fence waited, then the two-SRV GPU dispatch read back. The adoption log is x2w-d3d12 linear buffer <resource>: adopted its existing placed backing for material refresh, <bytes> bytes.

No local title scene or package was run in this worktree, so the next title refusal is not reported here. On a native run, X2W_D3D12_TRACE_DIRECT_MESH=1 reports the first remaining material refusal with stage, register, root parameter, table offset and reason; the adoption line above identifies whether this view bound.

Limits

  • Adoption only observes GPU writes recorded on the current recording or tracked through a submitted copy/bound UAV. A GPU write submitted before the first material bind is not seen; such a range must keep the desktop bytes authoritative and is documented in linear_buffer_backing.h.
  • The changed-run comparison runs at every submit over the whole placed resource, and the first refresh copies it whole. A 174 MiB resource therefore still costs a 174 MiB compare per submission even when few bytes changed; no frame time or peak VRAM against the DXGI budget was measured on a title scene.
  • The fixture drives the production material resolver and queue wrapper, not a full native Mesh86 PSO (that needs a captured guest shader). The PSO creation and dispatch path itself is unchanged.

Refs #3640, #3638, #3545.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5584492603 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3725). Originally posted by [lambirou](https://github.com/lambirou) on 2026-12-01T11:12:27Z. --- ## Problem A native Mesh86 material view on a placed buffer was refused when the placed desktop backing did not alias title memory and no GPU copy had filled the range. The representative view is mesh `t0`, root parameter 0, table byte offset `0xAC0`: a raw SRV over the whole 45,613,056-dword placed buffer. It passes the desktop raw-SRV limit, but the binder cannot use the committed default backing as it stands (it starts at zeros) and cannot copy the full view per draw. ## Change - The Mesh86 material path now adopts the placed buffer's existing committed desktop backing in the linear-buffer refresh machinery. No second default-heap resource is allocated: the first submission before a consumer refreshes the title range, and later submissions copy only changed 4 KiB runs (runs separated by at most one block are merged; more than 1024 runs fall back to one span). - The consumer queue waits for the refresh fence and refreshes wait for earlier tracked submissions. A submitted copy or bound UAV marks the backing GPU-written and stops further refreshes; a discarded recording leaves it refreshed from title memory. - Adoption validates the range against the desktop resource, probes the title range once, and keeps the existing named refusal when no coherent backing can be established. It is default-on; `X2W_D3D12_LINEAR_BUFFERS` is not required. - Added a source-built fixture and registered it in `tests/cmake` and the PR preset: two raw SRVs at distinct offsets, one GPU dispatch reading both, a stale token, a UAV token, out-of-range and oversized records, sentinels outside the placed range, refresh-byte checks, a budget check, and a `skip-refresh` mutant. ## Evidence Build: `cmake --preset release`; `cmake --build --preset release` (all targets). New tests: ```text ctest --preset release --no-tests=error -R '^startup_mesh86_material_backing_(warp|hardware)$' --output-on-failure 2/2 passed (WARP, hardware) ctest --preset release --no-tests=error -R '^startup_mesh86_material_backing_mutant_(warp|hardware)$' --output-on-failure 2/2 passed (WILL_FAIL: both normal tests pass and both stale-refresh mutants fail) ``` The fixture prints, on WARP and hardware: ```text material backing: first 65536 bytes, one-word change 4 bytes, second one-word change 4 bytes, two disjoint words 8 bytes; adopted 1, linear placements 0 budget buffer: 1 objects / 65536 bytes before and after adoption ``` Existing focused checks: ```text ctest --preset release -j1 -R '^linear_buffer_backing_(copy|stale|contention)_warp$|^linear_buffer_backing_skip_refresh_control$' --output-on-failure 4/4 passed ctest --preset release -j1 -R '^startup_mesh86_srv_proof$|^runtime_mesh86_cache_cli_check$|^startup_indirect_mesh_cache_(warp|heap_warp|texture_map_warp|heap_wide_warp|constants_wide_warp)$' --output-on-failure 7/7 passed ctest --preset release -j1 -R '^native_direct_mesh$|^startup_indirect_draw_indexed_warp$|^startup_indirect_draw_warp$' --output-on-failure 3/3 passed ``` The full linear-buffer WARP family and its 14 negative controls also passed (22/22). `startup_tools_lint` passed, and `tests/docs_links_check.py` checked 208 Markdown files and 803 links. Hardware: AMD Radeon RX 9060 XT (vendor `0x1002`, device `0x7590`), driver `32.0.32029.2010`, Windows 11 build `26300` (26H2), debug layer off. The WARP run used the software adapter. ## Chain and remaining refusal The fixture's correlated chain is: material table record resolved through the production `indirect_table_buffer(..., InputBufferUse::mesh86_material)` path, backing adopted, list recorded, list closed and submitted through the queue wrapper, refresh fence waited, then the two-SRV GPU dispatch read back. The adoption log is `x2w-d3d12 linear buffer <resource>: adopted its existing placed backing for material refresh, <bytes> bytes`. No local title scene or package was run in this worktree, so the next title refusal is not reported here. On a native run, `X2W_D3D12_TRACE_DIRECT_MESH=1` reports the first remaining material refusal with stage, register, root parameter, table offset and reason; the adoption line above identifies whether this view bound. ## Limits - Adoption only observes GPU writes recorded on the current recording or tracked through a submitted copy/bound UAV. A GPU write submitted before the first material bind is not seen; such a range must keep the desktop bytes authoritative and is documented in `linear_buffer_backing.h`. - The changed-run comparison runs at every submit over the whole placed resource, and the first refresh copies it whole. A 174 MiB resource therefore still costs a 174 MiB compare per submission even when few bytes changed; no frame time or peak VRAM against the DXGI budget was measured on a title scene. - The fixture drives the production material resolver and queue wrapper, not a full native Mesh86 PSO (that needs a captured guest shader). The PSO creation and dispatch path itself is unchanged. Refs #3640, #3638, #3545.
R0Y00 commented 2026-12-01 11:22:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-01T11:22:19Z.

Review: CHANGES_REQUESTED


The first adoption can overwrite GPU-produced data. The lookup adopts a non-aliased placement when the current recording has no covering copy and written_by_gpu is false, but written_by_gpu only has evidence for an already tracked backing. With tracking off, a copy or UAV submission before the first material bind can leave valid bytes only in its desktop resource. The first refresh then overwrites that resource from stale title memory. Please preserve producer provenance before adoption or fail closed when earlier use is unknown. Add a control that submits a GPU write while tracking is off, then resolves the first Mesh86 material view and verifies the GPU bytes survive.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6130223059 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3725#pullrequestreview-6130223059). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-01T11:22:19Z. **Review:** CHANGES_REQUESTED --- The first adoption can overwrite GPU-produced data. The lookup adopts a non-aliased placement when the current recording has no covering copy and written_by_gpu is false, but written_by_gpu only has evidence for an already tracked backing. With tracking off, a copy or UAV submission before the first material bind can leave valid bytes only in its desktop resource. The first refresh then overwrites that resource from stale title memory. Please preserve producer provenance before adoption or fail closed when earlier use is unknown. Add a control that submits a GPU write while tracking is off, then resolves the first Mesh86 material view and verifies the GPU bytes survive.
lambirou commented 2026-12-01 11:50:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-12-01T11:50:02Z.


Addressed the provenance review in 715b84f0.

A submitted GPU write on a backing that was not tracked yet is now remembered by note_gpu_write; adopt fails closed with the existing a placed material buffer has no coherent desktop backing refusal instead of refreshing the GPU bytes from stale title memory. The new startup_mesh86_material_backing_provenance_{warp,hardware} control seeds a real GPU copy while linear tracking is off, resolves the first material view (refused) and reads the injected word back intact while the untouched word stays zero.

ctest --preset release --no-tests=error -R 'startup_mesh86_material_backing' --output-on-failure
→ 6/6 passed (normal, skip-refresh mutants, provenance) on WARP and RX 9060 XT
startup_triage_run_check.py → 0 failed

The title scene is still not claimed; #3641/#3727 covers the source-built presentation proof. Ready for re-review.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7310212852 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3725#issuecomment-7310212852). Originally posted by [lambirou](https://github.com/lambirou) on 2026-12-01T11:50:02Z. --- Addressed the provenance review in `715b84f0`. A submitted GPU write on a backing that was not tracked yet is now remembered by `note_gpu_write`; `adopt` fails closed with the existing `a placed material buffer has no coherent desktop backing` refusal instead of refreshing the GPU bytes from stale title memory. The new `startup_mesh86_material_backing_provenance_{warp,hardware}` control seeds a real GPU copy while linear tracking is off, resolves the first material view (refused) and reads the injected word back intact while the untouched word stays zero. ```text ctest --preset release --no-tests=error -R 'startup_mesh86_material_backing' --output-on-failure → 6/6 passed (normal, skip-refresh mutants, provenance) on WARP and RX 9060 XT startup_triage_run_check.py → 0 failed ``` The title scene is still not claimed; #3641/#3727 covers the source-built presentation proof. Ready for re-review.
Leyukaka commented 2026-12-01 18:12:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T18:12:30Z.


Result from one local 900 s run of the application with this PR (715b84f0) merged onto main 959306d4, native Mesh86 enabled, X2W_D3D12_TRACE_DIRECT_MESH on.

Without the PR, the same configuration reported every material refusal with the placed-buffer reason (an input in a placed buffer that does not alias guest memory). With the PR that reason no longer appears. The four Mesh86 pipelines are still created and selected (24 selections), and the material binding now stops on three other reasons. The trace reports each shape once and each attempt stops at its first failure, so these are 5 distinct shapes, not a count of refused binds:

  • 3 × "material buffer is smaller than the shader's minimum read": mesh stage, root 1, table offset 0x80, SRVs t4 and t7. Each is a raw view (format 39, flags 1, stride 0) of 16 elements, so 64 bytes, against a minimum read of 128 bytes. The 64 bytes are the descriptor's own size, so the open point is the 128-byte minimum or which record these registers read.
  • 1 × "an input buffer descriptor has zero records": t6, table offset 0xc0, minimum read 16 bytes.
  • 1 × an input in guest memory outside any placed buffer: t3, table offset 0x40, minimum read 8 bytes.

None of this is in the scope of this PR; it is only what the path reaches next. The minimum-read check predates this PR (#3638); I'll look at it separately and link it here. If it helps, I can rerun with another trace option you name.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7320572974 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3725#issuecomment-7320572974). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-01T18:12:30Z. --- Result from one local 900 s run of the application with this PR (`715b84f0`) merged onto `main` `959306d4`, native Mesh86 enabled, `X2W_D3D12_TRACE_DIRECT_MESH` on. Without the PR, the same configuration reported every material refusal with the placed-buffer reason (an input in a placed buffer that does not alias guest memory). With the PR that reason no longer appears. The four Mesh86 pipelines are still created and selected (24 selections), and the material binding now stops on three other reasons. The trace reports each shape once and each attempt stops at its first failure, so these are 5 distinct shapes, not a count of refused binds: - 3 × "material buffer is smaller than the shader's minimum read": mesh stage, root 1, table offset `0x80`, SRVs `t4` and `t7`. Each is a raw view (format 39, flags 1, stride 0) of 16 elements, so 64 bytes, against a minimum read of 128 bytes. The 64 bytes are the descriptor's own size, so the open point is the 128-byte minimum or which record these registers read. - 1 × "an input buffer descriptor has zero records": `t6`, table offset `0xc0`, minimum read 16 bytes. - 1 × an input in guest memory outside any placed buffer: `t3`, table offset `0x40`, minimum read 8 bytes. None of this is in the scope of this PR; it is only what the path reaches next. The minimum-read check predates this PR (#3638); I'll look at it separately and link it here. If it helps, I can rerun with another trace option you name.
lambirou commented 2026-12-02 14:47:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-12-02T14:47:06Z.

Review: COMMENTED


Re-reviewed 715b84f0 after the provenance fix. Read the delta, not built here.

Verdict: approve. The submitted-GPU-write case is now remembered even when linear tracking is off: note_gpu_write records a resource with no tracked backing, adoption fails closed, and the provenance control verifies the GPU bytes survive the refused adoption. The overflow flag makes the failure conservative rather than unbounded.

  • Checked, no finding: retire and erase remove the untracked entry; the set is bounded to 65,536 resources; adopt checks the untracked set before any title refresh; the normal tracked path is unchanged; the new fixture seeds a copy while tracking is off, resolves the first material view (refused) and reads the desktop bytes back.
  • NIT The refusal uses E_INVALIDARG for a GPU-provenance conflict. A dedicated HRESULT or a named reason-flag would make the diagnostic distinguish "not supported" from "refused because the GPU owns the bytes"; the current text does distinguish it.

The PR remains DIRTY against main; rebase before merge.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6153095657 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3725#pullrequestreview-6153095657). Originally posted by [lambirou](https://github.com/lambirou) on 2026-12-02T14:47:06Z. **Review:** COMMENTED --- Re-reviewed `715b84f0` after the provenance fix. Read the delta, not built here. **Verdict: approve.** The submitted-GPU-write case is now remembered even when linear tracking is off: `note_gpu_write` records a resource with no tracked backing, adoption fails closed, and the provenance control verifies the GPU bytes survive the refused adoption. The overflow flag makes the failure conservative rather than unbounded. - Checked, no finding: `retire` and `erase` remove the untracked entry; the set is bounded to 65,536 resources; `adopt` checks the untracked set before any title refresh; the normal tracked path is unchanged; the new fixture seeds a copy while tracking is off, resolves the first material view (refused) and reads the desktop bytes back. - **NIT** The refusal uses `E_INVALIDARG` for a GPU-provenance conflict. A dedicated HRESULT or a named reason-flag would make the diagnostic distinguish "not supported" from "refused because the GPU owns the bytes"; the current text does distinguish it. The PR remains `DIRTY` against main; rebase before merge.
R0Y00 commented 2026-12-02 19:05:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:05:20Z.

Review: APPROVED


Re-reviewed 459fe3aa. Existing GPU writes are tracked before a backing is adopted, and the provenance case verifies that a pre-existing GPU write survives refusal of adoption. The new mesh86_material use keeps the truncation, provenance checks and adoption out of the Mesh57 caller. Independent MSVC Debug ctest --preset dev --no-tests=error -V -j 1 -R '^startup_mesh86_material_backing_' passed 6/6 on Windows 11 build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the fixture's debug layer off. This includes the two stale-refresh mutation checks and the two provenance checks. #3810 overlaps this code, so please carry any distinct fixture coverage there as a follow-up.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6157059693 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3725#pullrequestreview-6157059693). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T19:05:20Z. **Review:** APPROVED --- Re-reviewed 459fe3aa. Existing GPU writes are tracked before a backing is adopted, and the provenance case verifies that a pre-existing GPU write survives refusal of adoption. The new `mesh86_material` use keeps the truncation, provenance checks and adoption out of the Mesh57 caller. Independent MSVC Debug `ctest --preset dev --no-tests=error -V -j 1 -R '^startup_mesh86_material_backing_'` passed 6/6 on Windows 11 build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the fixture's debug layer off. This includes the two stale-refresh mutation checks and the two provenance checks. #3810 overlaps this code, so please carry any distinct fixture coverage there as a follow-up.
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!3725
No description provided.