startup: draw a pipeline without depth state without the bound depth view #3818

Merged
Leyukaka merged 2 commits from upstream-pr/3818 into main 2026-12-02 18:39:06 +00:00
Leyukaka commented 2026-12-02 02:52:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T02:52:23Z.


Problem

Since #3535, a translated pipeline that carries no depth-stencil state (no stream DEPTH_STENCIL subobject and no decoded registers) declares DSVFormat = DXGI_FORMAT_UNKNOWN. Declaring the bound view's format there is debug-layer message 1477, so that part is correct and stays.

The guest's depth view, however, stays bound on the desktop command list while such a pipeline draws. D3D12 compares the bound DSV with the pipeline's DSVFormat when the draw is issued, and the mismatch is message 615:

DrawInstanced: The depth stencil format does not match that specified by the current pipeline state

The result of that draw is undefined: it can be accepted and still leave its render targets unchanged.

Change

For those draws only, draw_translated records the draw with the same render targets and no depth view, then restores the guest's bind right after the draw, so later draws see the depth view again.

  • depth_target_unbind applies when a depth view is bound, the bind has at least one render target, and pipeline_for declares DXGI_FORMAT_UNKNOWN for the pipeline. It uses the same condition as pipeline_for, so the two cannot disagree.
  • A bind without render targets keeps its depth view: that draw has nothing else to write.
  • Pass now keeps the desktop descriptor handles of the last accepted bind (desktop_targets, desktop_depth), filled in list_targets, so the draw can bind the same targets again.
  • Pipelines that carry a depth-stencil state are not affected, including those that disable depth and stencil but declare a format (the case discussed in #3535).

The render target formats already come from the bound views, so they cannot mismatch in the same way.

Refs #3535.

Validation

Windows, MSVC. startup_stream_depth gains two cases. The fixture runs with the D3D12 debug layer on and rejects messages of severity 0 to 2, so message 615 fails it.

  1. A pipeline without depth state draws while a depth view is bound: its red triangle must overwrite the green one. The check also requires the new log line drawn without the bound depth view.
  2. The same draw first, then two depth-tested draws: the near triangle must still occlude the far one. This passes only if the depth view is bound again after the draw that went without it.
ctest --preset dev -R startup_stream_depth --no-tests=error

startup_stream_depth_warp and startup_stream_depth_hardware pass, on WARP and on a physical adapter.

A 300 s run of a guest application on this branch showed no device loss. The new log line appeared 8 times, which is its limit (it is written for the first 8 such draws only), so the path is exercised in a real run and the count is a lower bound. The frame rate was unchanged, at about 12 fps.

On this exact head, with MSVC: startup_stream_depth, startup_frame_copy and startup_packed_target_draw pass on WARP and on hardware. The full suite will run in Build and test on Windows.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5598856125 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3818). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T02:52:23Z. --- ## Problem Since #3535, a translated pipeline that carries no depth-stencil state (no stream `DEPTH_STENCIL` subobject and no decoded registers) declares `DSVFormat = DXGI_FORMAT_UNKNOWN`. Declaring the bound view's format there is debug-layer message 1477, so that part is correct and stays. The guest's depth view, however, stays bound on the desktop command list while such a pipeline draws. D3D12 compares the bound DSV with the pipeline's `DSVFormat` when the draw is issued, and the mismatch is message 615: ``` DrawInstanced: The depth stencil format does not match that specified by the current pipeline state ``` The result of that draw is undefined: it can be accepted and still leave its render targets unchanged. ## Change For those draws only, `draw_translated` records the draw with the same render targets and no depth view, then restores the guest's bind right after the draw, so later draws see the depth view again. - `depth_target_unbind` applies when a depth view is bound, the bind has at least one render target, and `pipeline_for` declares `DXGI_FORMAT_UNKNOWN` for the pipeline. It uses the same condition as `pipeline_for`, so the two cannot disagree. - A bind without render targets keeps its depth view: that draw has nothing else to write. - `Pass` now keeps the desktop descriptor handles of the last accepted bind (`desktop_targets`, `desktop_depth`), filled in `list_targets`, so the draw can bind the same targets again. - Pipelines that carry a depth-stencil state are not affected, including those that disable depth and stencil but declare a format (the case discussed in #3535). The render target formats already come from the bound views, so they cannot mismatch in the same way. Refs #3535. ## Validation Windows, MSVC. `startup_stream_depth` gains two cases. The fixture runs with the D3D12 debug layer on and rejects messages of severity 0 to 2, so message 615 fails it. 1. A pipeline without depth state draws while a depth view is bound: its red triangle must overwrite the green one. The check also requires the new log line `drawn without the bound depth view`. 2. The same draw first, then two depth-tested draws: the near triangle must still occlude the far one. This passes only if the depth view is bound again after the draw that went without it. ```powershell ctest --preset dev -R startup_stream_depth --no-tests=error ``` `startup_stream_depth_warp` and `startup_stream_depth_hardware` pass, on WARP and on a physical adapter. A 300 s run of a guest application on this branch showed no device loss. The new log line appeared 8 times, which is its limit (it is written for the first 8 such draws only), so the path is exercised in a real run and the count is a lower bound. The frame rate was unchanged, at about 12 fps. On this exact head, with MSVC: startup_stream_depth, startup_frame_copy and startup_packed_target_draw pass on WARP and on hardware. The full suite will run in `Build and test on Windows`.
R0Y00 commented 2026-12-02 03:05:06 +00:00 (Migrated from github.com)

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


There is a descriptor lifetime gap in the new unbind/rebind path. OMSetRenderTargets consumes CPU RTV/DSV descriptors when recorded; an application can reuse those slots before its next draw. Pass::desktop_targets and desktop_depth retain only the handles, so the later calls can load overwritten views while the pass still tracks the original resources and formats. Please preserve the original accepted views (or use recording-owned descriptor copies) and test rewriting both a bound RTV slot and the DSV slot after OMSetRenderTargets, before the no-depth draw and the subsequent depth-tested draw.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7333514216 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3818#issuecomment-7333514216). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T03:05:06Z. --- There is a descriptor lifetime gap in the new unbind/rebind path. `OMSetRenderTargets` consumes CPU RTV/DSV descriptors when recorded; an application can reuse those slots before its next draw. `Pass::desktop_targets` and `desktop_depth` retain only the handles, so the later calls can load overwritten views while the pass still tracks the original resources and formats. Please preserve the original accepted views (or use recording-owned descriptor copies) and test rewriting both a bound RTV slot and the DSV slot after OMSetRenderTargets, before the no-depth draw and the subsequent depth-tested draw.
R0Y00 commented 2026-12-02 15:41:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T15:41:18Z.

Review: CHANGES_REQUESTED


list_targets saves raw RTV and DSV CPU handles, then the translated draw dereferences them in both extra OM binds. D3D12 consumes those descriptors during the original OMSetRenderTargets call, so their slots can be overwritten or their heap released immediately afterwards (Microsoft descriptor lifetime documentation). If a guest binds RTV A, overwrites that CPU slot with RTV B, and draws without another OM bind, the translated path binds B while pass.bound_targets and tracked resource states still describe A. The same applies to the restored DSV. Please use bind-time descriptor snapshots with a lifetime that covers the extra binds, and add a regression that overwrites the original slot after binding and verifies the original target and depth view are still used.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6154099493 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3818#pullrequestreview-6154099493). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T15:41:18Z. **Review:** CHANGES_REQUESTED --- `list_targets` saves raw RTV and DSV CPU handles, then the translated draw dereferences them in both extra OM binds. D3D12 consumes those descriptors during the original `OMSetRenderTargets` call, so their slots can be overwritten or their heap released immediately afterwards ([Microsoft descriptor lifetime documentation](https://learn.microsoft.com/en-us/windows/win32/direct3d12/descriptors-overview)). If a guest binds RTV A, overwrites that CPU slot with RTV B, and draws without another OM bind, the translated path binds B while `pass.bound_targets` and tracked resource states still describe A. The same applies to the restored DSV. Please use bind-time descriptor snapshots with a lifetime that covers the extra binds, and add a regression that overwrites the original slot after binding and verifies the original target and depth view are still used.
Leyukaka commented 2026-12-02 17:48:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T17:48:56Z.


Thanks, fixed in 45b45bd4f. list_targets now copies the bound RTVs and DSV into list-owned CPU-only heaps at bind time, and both extra binds use those copies. startup_stream_depth gains a case that overwrites both slots after the bind; it passes on WARP and hardware.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7353670634 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3818#issuecomment-7353670634). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T17:48:56Z. --- Thanks, fixed in `45b45bd4f`. `list_targets` now copies the bound RTVs and DSV into list-owned CPU-only heaps at bind time, and both extra binds use those copies. `startup_stream_depth` gains a case that overwrites both slots after the bind; it passes on WARP and hardware.
R0Y00 commented 2026-12-02 18:05:01 +00:00 (Migrated from github.com)

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

Review: APPROVED


Re-reviewed 45b45bd4. The list copies both descriptors at the original bind, and the extra draws read the list-owned views. The new case overwrites both guest slots with decoys before any draw and still reads back the original target with the original depth result. Independent Windows 11 build 26300/MSVC Debug ctest --preset dev --no-tests=error -j 1 -R '^startup_stream_depth' passed 2/2 on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, debug layer enabled.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6156131920 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3818#pullrequestreview-6156131920). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T18:05:01Z. **Review:** APPROVED --- Re-reviewed 45b45bd4. The list copies both descriptors at the original bind, and the extra draws read the list-owned views. The new case overwrites both guest slots with decoys before any draw and still reads back the original target with the original depth result. Independent Windows 11 build 26300/MSVC Debug `ctest --preset dev --no-tests=error -j 1 -R '^startup_stream_depth'` passed 2/2 on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, debug layer enabled.
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!3818
No description provided.