d3d12_xs: wire slot 50 DSV binding, view_slot<21> tracking, and stream PSO depth-stencil #1423

Merged
tedin7 merged 8 commits from upstream-pr/1430 into main 2026-11-24 12:31:06 +00:00
tedin7 commented 2026-11-24 11:22:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:22:38Z.


Implements GPU-1A from proven console ABI facts:

  • Track DSV targets in view_slot<21, 2> via note_view_target().
  • Bind the 5th argument (depth handle) in list_targets (slot 50 OMSetRenderTargets), transition the backing resource to D3D12_RESOURCE_STATE_DEPTH_WRITE, track DSVFormat on Pass, and allow count == 0 depth-only passes when a valid DSV is bound.
  • Decode stream PSO subobjects 11 (DEPTH_STENCIL), 21 (DEPTH_STENCIL1), and 16 (DEPTH_STENCIL_FORMAT) in stream_translation() and include depth-stencil state + DSVFormat in pipeline_for() PSO cache keys.
  • Add startup_stream_depth + startup_stream_depth_check.py (WARP + hardware) testing depth occlusion, DepthEnable=FALSE negative control, and count=0 depth-only pass.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6580653976 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:22:38Z. --- Implements GPU-1A from proven console ABI facts: - Track DSV targets in view_slot<21, 2> via note_view_target(). - Bind the 5th argument (depth handle) in list_targets (slot 50 OMSetRenderTargets), transition the backing resource to D3D12_RESOURCE_STATE_DEPTH_WRITE, track DSVFormat on Pass, and allow count == 0 depth-only passes when a valid DSV is bound. - Decode stream PSO subobjects 11 (DEPTH_STENCIL), 21 (DEPTH_STENCIL1), and 16 (DEPTH_STENCIL_FORMAT) in stream_translation() and include depth-stencil state + DSVFormat in pipeline_for() PSO cache keys. - Add startup_stream_depth + startup_stream_depth_check.py (WARP + hardware) testing depth occlusion, DepthEnable=FALSE negative control, and count=0 depth-only pass. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 12:02:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:38:55Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7dbe516170

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038517311 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#pullrequestreview-6038517311). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:38:55Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `7dbe516170` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
R0Y00 commented 2026-11-24 12:02:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:40:13Z.

Review: CHANGES_REQUESTED


The DSV registry needs to preserve view kind and flags. Slot 50 resolves the depth handle in the same untyped registry as RTV handles, then always requests DEPTH_WRITE, including for a read-only DSV. Validate DSV versus RTV on lookup and either model read-only planes or explicitly refuse them. Also check the trailing DepthBoundsTestEnable on DEPTH_STENCIL1: copying the base fields alone silently drops the bounds test. Please add source-built controls for those cases.

Independent Windows Release at 7dbe516: the six stream/MRT regressions passed. Both new depth tests failed on RTX 4060 Laptop and WARP with D3D12 diagnostic 679 in the count-zero pass: the pixel shader declares RTV 0 even though the pass binds no color target. Please use a depth-only shader for that control and retain the debug-layer assertion.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038533519 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#pullrequestreview-6038533519). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T11:40:13Z. **Review:** CHANGES_REQUESTED --- The DSV registry needs to preserve view kind and flags. Slot 50 resolves the depth handle in the same untyped registry as RTV handles, then always requests DEPTH_WRITE, including for a read-only DSV. Validate DSV versus RTV on lookup and either model read-only planes or explicitly refuse them. Also check the trailing DepthBoundsTestEnable on DEPTH_STENCIL1: copying the base fields alone silently drops the bounds test. Please add source-built controls for those cases. Independent Windows Release at 7dbe516: the six stream/MRT regressions passed. Both new depth tests failed on RTX 4060 Laptop and WARP with D3D12 diagnostic 679 in the count-zero pass: the pixel shader declares RTV 0 even though the pass binds no color target. Please use a depth-only shader for that control and retain the debug-layer assertion.
tedin7 commented 2026-11-24 12:02:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:47:25Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038626817 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#pullrequestreview-6038626817). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:47:25Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 12:02:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:47:27Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038627215 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#pullrequestreview-6038627215). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:47:27Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 12:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:47:29Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038627636 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#pullrequestreview-6038627636). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:47:29Z. **Review:** COMMENTED --- _No description provided._
R0Y00 commented 2026-11-24 12:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:58:07Z.

Review: CHANGES_REQUESTED


At 1a36111 the previous wrong-kind and depth-bounds controls are present. Windows Release still reports D3D12 warning 679 for the zero-RTV pass on both WARP and RTX 4060 Laptop, so both new depth CTests fail and the six older stream/MRT draws pass. Please make the depth-only PSO stop declaring SV_Target0 and retain the assertion on warning severity.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038764538 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#pullrequestreview-6038764538). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T11:58:07Z. **Review:** CHANGES_REQUESTED --- At 1a36111 the previous wrong-kind and depth-bounds controls are present. Windows Release still reports D3D12 warning 679 for the zero-RTV pass on both WARP and RTX 4060 Laptop, so both new depth CTests fail and the six older stream/MRT draws pass. Please make the depth-only PSO stop declaring SV_Target0 and retain the assertion on warning severity.
tedin7 commented 2026-11-24 12:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:29:07Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 7dbe5161:

  • Debug (--preset dev): ctest --preset dev -R '^(startup_stream_depth_warp|startup_stream_draw_warp|startup_cb_blend_warp|startup_mrt_fxc_warp|startup_mrt_dxc_warp)$' --no-tests=error --output-on-failure — 5/5 passed (4.89s)
  • Release /O2 (--preset release): ctest --preset release -R '^(startup_stream_depth_warp|startup_stream_draw_warp|startup_cb_blend_warp|startup_mrt_fxc_warp|startup_mrt_dxc_warp)$' --no-tests=error --output-on-failure — 5/5 passed (4.96s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130157443 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#issuecomment-7130157443). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:29:07Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `7dbe5161`: - **Debug (`--preset dev`)**: `ctest --preset dev -R '^(startup_stream_depth_warp|startup_stream_draw_warp|startup_cb_blend_warp|startup_mrt_fxc_warp|startup_mrt_dxc_warp)$' --no-tests=error --output-on-failure` — **5/5 passed** (4.89s) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^(startup_stream_depth_warp|startup_stream_draw_warp|startup_cb_blend_warp|startup_mrt_fxc_warp|startup_mrt_dxc_warp)$' --no-tests=error --output-on-failure` — **5/5 passed** (4.96s)
chatgpt-codex-connector[bot commented 2026-11-24 12:03:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:29:17Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T11:38:58.656581Z 7dbe516 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130160999 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#issuecomment-7130160999). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:29:17Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7dbe51617081949aabc9fe2c0ea880c0ab9fbb51","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T11:38:58.656581Z">2026-11-24T11:38:58.656581Z</relative-time> | `7dbe516` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
tedin7 commented 2026-11-24 12:03:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:47:33Z.


@R0Y00 Addressed in 1a361114 (Win2025 WARP Debug and Release /O2: startup_stream_depth, startup_stream_draw, startup_cb_blend, startup_mrt_fxc, startup_mrt_dxc 5/5 pass each).

  • Slot 50 resolves RTV/DSV handles from the descriptor's current view record (kind and flags preserved, copies followed). A handle of the wrong kind refuses the whole bind, so nothing draws.
  • Read-only depth views bind as DEPTH_READ (kept when the texture is also sampled). A view with only one plane read-only is refused, since it needs per-plane states.
  • DEPTH_STENCIL1 with DepthBoundsTestEnable set is refused instead of dropping the bounds test.
  • New source-built controls in startup_stream_depth: RTV passed as depth, DSV passed as target, and bounds-enabled DEPTH_STENCIL1 each draw nothing. A read-only DSV does not occlude. The fixture now prints adapter, driver and ids.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130555458 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#issuecomment-7130555458). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:47:33Z. --- @R0Y00 Addressed in 1a361114 (Win2025 WARP Debug and Release /O2: startup_stream_depth, startup_stream_draw, startup_cb_blend, startup_mrt_fxc, startup_mrt_dxc 5/5 pass each). - Slot 50 resolves RTV/DSV handles from the descriptor's current view record (kind and flags preserved, copies followed). A handle of the wrong kind refuses the whole bind, so nothing draws. - Read-only depth views bind as DEPTH_READ (kept when the texture is also sampled). A view with only one plane read-only is refused, since it needs per-plane states. - DEPTH_STENCIL1 with DepthBoundsTestEnable set is refused instead of dropping the bounds test. - New source-built controls in startup_stream_depth: RTV passed as depth, DSV passed as target, and bounds-enabled DEPTH_STENCIL1 each draw nothing. A read-only DSV does not occlude. The fixture now prints adapter, driver and ids.
chatgpt-codex-connector[bot commented 2026-11-24 12:03:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:38:55Z.

Code review location: src/startup_stubs/d3d12_xs_device.cpp; line 1756

@@ -1699,32 +1700,63 @@ void __stdcall list_graphics_root(Wrapper* self, void* root)
     if (auto* list = recording(self); list && w && w->own().kind == root_signature_kind && w->own().real)
         list->SetGraphicsRootSignature(static_cast<ID3D12RootSignature*>(w->own().real));
 }
-// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). Depth is not bound yet.
-void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, const void*)
+DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target)
+{
+    DXGI_FORMAT format = target->GetDesc().Format;
+    if (const std::uint32_t id = shadow_id(desktop_handle)) {
+        AcquireSRWLockShared(&note_lock);
+        DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN;
+        if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4)
+            std::memcpy(&view_format, view_records()[id - 1].desc, 4);
+        ReleaseSRWLockShared(&note_lock);
+        if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format);
+    }
+    return format;
+}
+// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth).
+void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range,
+                            const D3D12_CPU_DESCRIPTOR_HANDLE* depth)
 {
     auto* list = recording(self);
     Pass& pass = pass_of(self);
     pass.targets_bound = false;
-    if (!list || !count || count > 8 || single_range || !x2w_local::readable(handles, count * sizeof(*handles))) return;
+    pass.target_count = 0;
+    pass.target0 = nullptr;
+    pass.dsv_format = DXGI_FORMAT_UNKNOWN;
+    if (!list || count > 8 || single_range) return;
+    if (count && !x2w_local::readable(handles, count * sizeof(*handles))) return;
     D3D12_CPU_DESCRIPTOR_HANDLE desktop[8];
+    ID3D12Resource* targets[8]{};
+    DXGI_FORMAT formats[8]{};
     for (UINT i = 0; i < count; ++i) {
         desktop[i].ptr = static_cast<SIZE_T>(desktop_cpu_handle(handles[i].ptr));
-        ID3D12Resource* target = view_target(desktop[i].ptr);
-        if (!target) return;
-        use_as_target(self, target);
-        DXGI_FORMAT format = target->GetDesc().Format;
-        if (const std::uint32_t id = shadow_id(desktop[i].ptr)) {
-            AcquireSRWLockShared(&note_lock);
-            DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN;
-            if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) std::memcpy(&view_format, view_records()[id - 1].desc, 4);
-            ReleaseSRWLockShared(&note_lock);
-            if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format);
+        targets[i] = view_target(desktop[i].ptr);
+        if (!targets[i]) return;
+        formats[i] = view_format_of(desktop[i].ptr, targets[i]);
+    }
+    D3D12_CPU_DESCRIPTOR_HANDLE desktop_dsv{};
+    const D3D12_CPU_DESCRIPTOR_HANDLE* dsv_ptr = nullptr;
+    ID3D12Resource* dsv_target = nullptr;
+    DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN;
+    if (depth && x2w_local::readable(depth, sizeof(*depth))) {
+        const u64 resolved = desktop_cpu_handle(depth->ptr);
+        dsv_target = resolved ? view_target(resolved) : nullptr;
+        if (dsv_target) {
+            desktop_dsv.ptr = static_cast<SIZE_T>(resolved);
+            dsv_ptr = &desktop_dsv;
+            dsv_format = view_format_of(resolved, dsv_target);
         }
-        pass.target_formats[i] = format;
-        if (i == 0) pass.target0 = target;
     }
+    if (!count && !dsv_ptr) return;
+    for (UINT i = 0; i < count; ++i) {
+        use_as_target(self, targets[i]);
+        pass.target_formats[i] = formats[i];
+        if (i == 0) pass.target0 = targets[i];
+    }
+    if (dsv_target) require_state(self, dsv_target, D3D12_RESOURCE_STATE_DEPTH_WRITE);

P1 Badge Preserve depth-read state when a read-only DSV is also sampled

When a depth texture is bound through a D3D12_DSV_FLAG_READ_ONLY_DEPTH DSV with depth writes disabled and is also sampled by the pixel shader, this unconditionally requests DEPTH_WRITE. The SRV handling in draw_translated() then replaces that state with only PIXEL_SHADER_RESOURCE, while the DSV remains bound. The resulting draw lacks the required DEPTH_READ state and violates D3D12 resource-state requirements. Track the DSV flags and preserve DEPTH_READ | PIXEL_SHADER_RESOURCE for this valid simultaneous-use case.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679428124 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#discussion_r4679428124). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:38:55Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 1756 ~~~~diff @@ -1699,32 +1700,63 @@ void __stdcall list_graphics_root(Wrapper* self, void* root) if (auto* list = recording(self); list && w && w->own().kind == root_signature_kind && w->own().real) list->SetGraphicsRootSignature(static_cast<ID3D12RootSignature*>(w->own().real)); } -// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). Depth is not bound yet. -void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, const void*) +DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target) +{ + DXGI_FORMAT format = target->GetDesc().Format; + if (const std::uint32_t id = shadow_id(desktop_handle)) { + AcquireSRWLockShared(&note_lock); + DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN; + if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) + std::memcpy(&view_format, view_records()[id - 1].desc, 4); + ReleaseSRWLockShared(&note_lock); + if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format); + } + return format; +} +// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). +void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, + const D3D12_CPU_DESCRIPTOR_HANDLE* depth) { auto* list = recording(self); Pass& pass = pass_of(self); pass.targets_bound = false; - if (!list || !count || count > 8 || single_range || !x2w_local::readable(handles, count * sizeof(*handles))) return; + pass.target_count = 0; + pass.target0 = nullptr; + pass.dsv_format = DXGI_FORMAT_UNKNOWN; + if (!list || count > 8 || single_range) return; + if (count && !x2w_local::readable(handles, count * sizeof(*handles))) return; D3D12_CPU_DESCRIPTOR_HANDLE desktop[8]; + ID3D12Resource* targets[8]{}; + DXGI_FORMAT formats[8]{}; for (UINT i = 0; i < count; ++i) { desktop[i].ptr = static_cast<SIZE_T>(desktop_cpu_handle(handles[i].ptr)); - ID3D12Resource* target = view_target(desktop[i].ptr); - if (!target) return; - use_as_target(self, target); - DXGI_FORMAT format = target->GetDesc().Format; - if (const std::uint32_t id = shadow_id(desktop[i].ptr)) { - AcquireSRWLockShared(&note_lock); - DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN; - if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) std::memcpy(&view_format, view_records()[id - 1].desc, 4); - ReleaseSRWLockShared(&note_lock); - if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format); + targets[i] = view_target(desktop[i].ptr); + if (!targets[i]) return; + formats[i] = view_format_of(desktop[i].ptr, targets[i]); + } + D3D12_CPU_DESCRIPTOR_HANDLE desktop_dsv{}; + const D3D12_CPU_DESCRIPTOR_HANDLE* dsv_ptr = nullptr; + ID3D12Resource* dsv_target = nullptr; + DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN; + if (depth && x2w_local::readable(depth, sizeof(*depth))) { + const u64 resolved = desktop_cpu_handle(depth->ptr); + dsv_target = resolved ? view_target(resolved) : nullptr; + if (dsv_target) { + desktop_dsv.ptr = static_cast<SIZE_T>(resolved); + dsv_ptr = &desktop_dsv; + dsv_format = view_format_of(resolved, dsv_target); } - pass.target_formats[i] = format; - if (i == 0) pass.target0 = target; } + if (!count && !dsv_ptr) return; + for (UINT i = 0; i < count; ++i) { + use_as_target(self, targets[i]); + pass.target_formats[i] = formats[i]; + if (i == 0) pass.target0 = targets[i]; + } + if (dsv_target) require_state(self, dsv_target, D3D12_RESOURCE_STATE_DEPTH_WRITE); ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Preserve depth-read state when a read-only DSV is also sampled** When a depth texture is bound through a `D3D12_DSV_FLAG_READ_ONLY_DEPTH` DSV with depth writes disabled and is also sampled by the pixel shader, this unconditionally requests `DEPTH_WRITE`. The SRV handling in `draw_translated()` then replaces that state with only `PIXEL_SHADER_RESOURCE`, while the DSV remains bound. The resulting draw lacks the required `DEPTH_READ` state and violates D3D12 resource-state requirements. Track the DSV flags and preserve `DEPTH_READ | PIXEL_SHADER_RESOURCE` for this valid simultaneous-use case. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 12:03:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:38:55Z.

Code review location: src/startup_stubs/d3d12_xs_device.cpp; line 1743

@@ -1699,32 +1700,63 @@ void __stdcall list_graphics_root(Wrapper* self, void* root)
     if (auto* list = recording(self); list && w && w->own().kind == root_signature_kind && w->own().real)
         list->SetGraphicsRootSignature(static_cast<ID3D12RootSignature*>(w->own().real));
 }
-// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). Depth is not bound yet.
-void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, const void*)
+DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target)
+{
+    DXGI_FORMAT format = target->GetDesc().Format;
+    if (const std::uint32_t id = shadow_id(desktop_handle)) {
+        AcquireSRWLockShared(&note_lock);
+        DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN;
+        if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4)
+            std::memcpy(&view_format, view_records()[id - 1].desc, 4);
+        ReleaseSRWLockShared(&note_lock);
+        if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format);
+    }
+    return format;
+}
+// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth).
+void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range,
+                            const D3D12_CPU_DESCRIPTOR_HANDLE* depth)
 {
     auto* list = recording(self);
     Pass& pass = pass_of(self);
     pass.targets_bound = false;
-    if (!list || !count || count > 8 || single_range || !x2w_local::readable(handles, count * sizeof(*handles))) return;
+    pass.target_count = 0;
+    pass.target0 = nullptr;
+    pass.dsv_format = DXGI_FORMAT_UNKNOWN;
+    if (!list || count > 8 || single_range) return;
+    if (count && !x2w_local::readable(handles, count * sizeof(*handles))) return;
     D3D12_CPU_DESCRIPTOR_HANDLE desktop[8];
+    ID3D12Resource* targets[8]{};
+    DXGI_FORMAT formats[8]{};
     for (UINT i = 0; i < count; ++i) {
         desktop[i].ptr = static_cast<SIZE_T>(desktop_cpu_handle(handles[i].ptr));
-        ID3D12Resource* target = view_target(desktop[i].ptr);
-        if (!target) return;
-        use_as_target(self, target);
-        DXGI_FORMAT format = target->GetDesc().Format;
-        if (const std::uint32_t id = shadow_id(desktop[i].ptr)) {
-            AcquireSRWLockShared(&note_lock);
-            DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN;
-            if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) std::memcpy(&view_format, view_records()[id - 1].desc, 4);
-            ReleaseSRWLockShared(&note_lock);
-            if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format);
+        targets[i] = view_target(desktop[i].ptr);
+        if (!targets[i]) return;
+        formats[i] = view_format_of(desktop[i].ptr, targets[i]);
+    }
+    D3D12_CPU_DESCRIPTOR_HANDLE desktop_dsv{};
+    const D3D12_CPU_DESCRIPTOR_HANDLE* dsv_ptr = nullptr;
+    ID3D12Resource* dsv_target = nullptr;
+    DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN;
+    if (depth && x2w_local::readable(depth, sizeof(*depth))) {
+        const u64 resolved = desktop_cpu_handle(depth->ptr);
+        dsv_target = resolved ? view_target(resolved) : nullptr;

P2 Badge Resolve DSV targets from current descriptor contents after copies

When a guest copies DSV A over a descriptor previously created for resource B using device slots 23 or 24, copy_descriptor_run() updates the desktop descriptor and note_copy() updates its shadow ID, but neither updates view_targets(). This lookup therefore still returns B: the code transitions B to DEPTH_WRITE while binding the copied descriptor for A, leaving the actual depth resource untransitioned. Copying into a fresh destination instead produces no target and skips depth-only passes. Resolve the resource through the current shadow record or propagate target tracking during descriptor copies.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679428133 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#discussion_r4679428133). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:38:55Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 1743 ~~~~diff @@ -1699,32 +1700,63 @@ void __stdcall list_graphics_root(Wrapper* self, void* root) if (auto* list = recording(self); list && w && w->own().kind == root_signature_kind && w->own().real) list->SetGraphicsRootSignature(static_cast<ID3D12RootSignature*>(w->own().real)); } -// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). Depth is not bound yet. -void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, const void*) +DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target) +{ + DXGI_FORMAT format = target->GetDesc().Format; + if (const std::uint32_t id = shadow_id(desktop_handle)) { + AcquireSRWLockShared(&note_lock); + DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN; + if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) + std::memcpy(&view_format, view_records()[id - 1].desc, 4); + ReleaseSRWLockShared(&note_lock); + if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format); + } + return format; +} +// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). +void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, + const D3D12_CPU_DESCRIPTOR_HANDLE* depth) { auto* list = recording(self); Pass& pass = pass_of(self); pass.targets_bound = false; - if (!list || !count || count > 8 || single_range || !x2w_local::readable(handles, count * sizeof(*handles))) return; + pass.target_count = 0; + pass.target0 = nullptr; + pass.dsv_format = DXGI_FORMAT_UNKNOWN; + if (!list || count > 8 || single_range) return; + if (count && !x2w_local::readable(handles, count * sizeof(*handles))) return; D3D12_CPU_DESCRIPTOR_HANDLE desktop[8]; + ID3D12Resource* targets[8]{}; + DXGI_FORMAT formats[8]{}; for (UINT i = 0; i < count; ++i) { desktop[i].ptr = static_cast<SIZE_T>(desktop_cpu_handle(handles[i].ptr)); - ID3D12Resource* target = view_target(desktop[i].ptr); - if (!target) return; - use_as_target(self, target); - DXGI_FORMAT format = target->GetDesc().Format; - if (const std::uint32_t id = shadow_id(desktop[i].ptr)) { - AcquireSRWLockShared(&note_lock); - DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN; - if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) std::memcpy(&view_format, view_records()[id - 1].desc, 4); - ReleaseSRWLockShared(&note_lock); - if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format); + targets[i] = view_target(desktop[i].ptr); + if (!targets[i]) return; + formats[i] = view_format_of(desktop[i].ptr, targets[i]); + } + D3D12_CPU_DESCRIPTOR_HANDLE desktop_dsv{}; + const D3D12_CPU_DESCRIPTOR_HANDLE* dsv_ptr = nullptr; + ID3D12Resource* dsv_target = nullptr; + DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN; + if (depth && x2w_local::readable(depth, sizeof(*depth))) { + const u64 resolved = desktop_cpu_handle(depth->ptr); + dsv_target = resolved ? view_target(resolved) : nullptr; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Resolve DSV targets from current descriptor contents after copies** When a guest copies DSV A over a descriptor previously created for resource B using device slots 23 or 24, `copy_descriptor_run()` updates the desktop descriptor and `note_copy()` updates its shadow ID, but neither updates `view_targets()`. This lookup therefore still returns B: the code transitions B to `DEPTH_WRITE` while binding the copied descriptor for A, leaving the actual depth resource untransitioned. Copying into a fresh destination instead produces no target and skips depth-only passes. Resolve the resource through the current shadow record or propagate target tracking during descriptor copies. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 12:03:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:38:55Z.

Code review location: tests/startup_stream_depth.cpp; line 186

@@ -0,0 +1,295 @@
+#include <d3d12.h>
+#include <dxgi1_6.h>
+#include <wrl/client.h>
+
+#include <array>
+#include <cstdint>
+#include <cstdio>
+#include <cstring>
+#include <fstream>
+#include <iterator>
+#include <vector>
+
+#include "startup_stream_setup.h"
+
+using Microsoft::WRL::ComPtr;
+extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**);
+
+namespace {
+
+struct alignas(8) StageSubobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    D3D12_SHADER_BYTECODE shader;
+};
+struct alignas(8) RootSubobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    ID3D12RootSignature* signature;
+};
+struct alignas(8) DepthStencilSubobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    D3D12_DEPTH_STENCIL_DESC desc;
+};
+static_assert(sizeof(DepthStencilSubobject) == 56);
+
+struct alignas(8) DepthStencil1Subobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    D3D12_DEPTH_STENCIL_DESC desc;
+    BOOL depth_bounds_test;
+};
+static_assert(sizeof(DepthStencil1Subobject) == 64);
+
+struct alignas(8) DsvFormatSubobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    DXGI_FORMAT format;
+};
+static_assert(sizeof(DsvFormatSubobject) == 8);
+
+struct DepthStream {
+    StageSubobject ps;
+    RootSubobject root;
+    StageSubobject vs;
+    DepthStencilSubobject ds;
+    DsvFormatSubobject dsv_format;
+};
+
+struct DepthStream1 {
+    StageSubobject ps;
+    RootSubobject root;
+    StageSubobject vs;
+    DepthStencil1Subobject ds1;
+    DsvFormatSubobject dsv_format;
+};
+
+using Word = std::uint64_t;
+template<class T> Word ptr_arg(T* p) { return reinterpret_cast<Word>(p); }
+
+bool read_bytes(const char* path, std::vector<char>& out)
+{
+    std::ifstream file(path, std::ios::binary);
+    out.assign(std::istreambuf_iterator<char>(file), {});
+    return !out.empty();
+}
+
+int pick_adapter(bool hardware, ComPtr<IDXGIAdapter>& adapter)
+{
+    ComPtr<IDXGIFactory4> factory;
+    if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 4;
+    if (!hardware) return SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter))) ? 0 : 4;
+    ComPtr<IDXGIFactory6> factory6;
+    if (FAILED(factory.As(&factory6))) return 77;
+    for (UINT n = 0;; ++n) {
+        ComPtr<IDXGIAdapter1> candidate;
+        const HRESULT hr = factory6->EnumAdapterByGpuPreference(n, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&candidate));
+        if (hr == DXGI_ERROR_NOT_FOUND) return 77;
+        if (FAILED(hr)) return 4;
+        DXGI_ADAPTER_DESC1 desc{};
+        if (FAILED(candidate->GetDesc1(&desc))) return 4;
+        if (!(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) &&
+            SUCCEEDED(D3D12CreateDevice(candidate.Get(), D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), nullptr))) {
+            adapter = candidate;
+            return 0;
+        }
+    }
+}
+
+void* create_stream_pso(void* device, ID3D12RootSignature* root, const std::vector<char>& vs,
+                        const std::vector<char>& ps, const D3D12_DEPTH_STENCIL_DESC& ds, bool use_ds1)
+{
+    using CreateStream = HRESULT (WINAPI*)(void*, const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**);
+    auto create = reinterpret_cast<CreateStream>((*static_cast<void***>(device))[86]);
+    void* pso = nullptr;
+    if (use_ds1) {
+        DepthStream1 stream{
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {ps.data(), ps.size()}},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, {vs.data(), vs.size()}},
+            {static_cast<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE>(21), ds, FALSE},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT_D32_FLOAT},
+        };
+        const D3D12_PIPELINE_STATE_STREAM_DESC desc{sizeof(stream), &stream};
+        if (FAILED(create(device, &desc, __uuidof(ID3D12PipelineState), &pso))) return nullptr;
+    } else {
+        DepthStream stream{
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {ps.data(), ps.size()}},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, {vs.data(), vs.size()}},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, ds},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT_D32_FLOAT},
+        };
+        const D3D12_PIPELINE_STATE_STREAM_DESC desc{sizeof(stream), &stream};
+        if (FAILED(create(device, &desc, __uuidof(ID3D12PipelineState), &pso))) return nullptr;
+    }
+    return pso;
+}
+
+int clear_depth_desktop(ID3D12Device* desktop, ID3D12Resource* depth_tex)
+{
+    D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1};
+    ComPtr<ID3D12DescriptorHeap> heap;
+    if (FAILED(desktop->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap)))) return 40;
+    const D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc{DXGI_FORMAT_D32_FLOAT, D3D12_DSV_DIMENSION_TEXTURE2D, D3D12_DSV_FLAG_NONE, {}};
+    const D3D12_CPU_DESCRIPTOR_HANDLE handle = heap->GetCPUDescriptorHandleForHeapStart();
+    desktop->CreateDepthStencilView(depth_tex, &dsv_desc, handle);
+
+    D3D12_COMMAND_QUEUE_DESC qd{};
+    ComPtr<ID3D12CommandQueue> queue;
+    ComPtr<ID3D12CommandAllocator> alloc;
+    ComPtr<ID3D12GraphicsCommandList> list;
+    ComPtr<ID3D12Fence> fence;
+    if (FAILED(desktop->CreateCommandQueue(&qd, IID_PPV_ARGS(&queue))) ||
+        FAILED(desktop->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&alloc))) ||
+        FAILED(desktop->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, alloc.Get(), nullptr, IID_PPV_ARGS(&list))) ||
+        FAILED(desktop->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)))) return 41;
+
+    D3D12_RESOURCE_BARRIER b{};
+    b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+    b.Transition = {depth_tex, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_DEPTH_WRITE};
+    list->ResourceBarrier(1, &b);
+    list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);
+    b.Transition.StateBefore = D3D12_RESOURCE_STATE_DEPTH_WRITE;
+    b.Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
+    list->ResourceBarrier(1, &b);
+    if (FAILED(list->Close())) return 42;
+
+    ID3D12CommandList* lists[] = {list.Get()};
+    queue->ExecuteCommandLists(1, lists);
+    if (FAILED(queue->Signal(fence.Get(), 1))) return 43;
+    HANDLE ev = CreateEventW(nullptr, FALSE, FALSE, nullptr);
+    if (!ev) return 44;
+    const bool ok = SUCCEEDED(fence->SetEventOnCompletion(1, ev)) && WaitForSingleObject(ev, 10000) == WAIT_OBJECT_0;
+    CloseHandle(ev);
+    return ok ? 0 : 45;
+}
+
+int execute_guest_list(void* queue, void* list, void* fence, UINT64 fence_value)
+{
+    if (FAILED(static_cast<HRESULT>(invoke(list, 9)))) return 50;
+    void* lists[] = {list};
+    invoke(queue, 10, 1, ptr_arg(lists));
+    if (FAILED(static_cast<HRESULT>(invoke(queue, 14, ptr_arg(fence), fence_value)))) return 51;
+    const auto deadline = GetTickCount64() + 10000;
+    while (invoke(fence, 8) < fence_value && GetTickCount64() < deadline) Sleep(1);
+    return invoke(fence, 8) >= fence_value ? 0 : 53;
+}
+
+}  // namespace
+
+int main(int argc, char** argv)
+{
+    if (argc != 7 && argc != 10) return 2;
+    std::vector<char> vs_front, vs_back, ps_green, ps_red;
+    if (!read_bytes(argv[1], vs_front) || !read_bytes(argv[2], vs_back) ||
+        !read_bytes(argv[3], ps_green) || !read_bytes(argv[4], ps_red)) return 3;
+    const bool hardware = std::strcmp(argv[6], "hardware") == 0;
+
+    ComPtr<IDXGIAdapter> adapter;
+    if (const int rc = pick_adapter(hardware, adapter)) return rc;

P1 Badge Emit the required hardware metadata from the new fixture

For startup_stream_depth_hardware, the fixture selects an adapter but never reports its identity or driver; the Python wrapper ultimately prints only debug messages and the backend/result summary. Unlike the existing prepare_stream_pipeline() helper, this path therefore produces GPU evidence that cannot be attributed to the selected adapter, especially on multi-GPU systems. AGENTS.md requires GPU reports to identify the adapter, driver, Windows build, commit, and debug-layer status, so emit and preserve that metadata with these results.

AGENTS.md reference: AGENTS.md:L95-L96

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679428139 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#discussion_r4679428139). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:38:55Z. **Code review location:** `tests/startup_stream_depth.cpp`; line 186 ~~~~diff @@ -0,0 +1,295 @@ +#include <d3d12.h> +#include <dxgi1_6.h> +#include <wrl/client.h> + +#include <array> +#include <cstdint> +#include <cstdio> +#include <cstring> +#include <fstream> +#include <iterator> +#include <vector> + +#include "startup_stream_setup.h" + +using Microsoft::WRL::ComPtr; +extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**); + +namespace { + +struct alignas(8) StageSubobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + D3D12_SHADER_BYTECODE shader; +}; +struct alignas(8) RootSubobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + ID3D12RootSignature* signature; +}; +struct alignas(8) DepthStencilSubobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + D3D12_DEPTH_STENCIL_DESC desc; +}; +static_assert(sizeof(DepthStencilSubobject) == 56); + +struct alignas(8) DepthStencil1Subobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + D3D12_DEPTH_STENCIL_DESC desc; + BOOL depth_bounds_test; +}; +static_assert(sizeof(DepthStencil1Subobject) == 64); + +struct alignas(8) DsvFormatSubobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + DXGI_FORMAT format; +}; +static_assert(sizeof(DsvFormatSubobject) == 8); + +struct DepthStream { + StageSubobject ps; + RootSubobject root; + StageSubobject vs; + DepthStencilSubobject ds; + DsvFormatSubobject dsv_format; +}; + +struct DepthStream1 { + StageSubobject ps; + RootSubobject root; + StageSubobject vs; + DepthStencil1Subobject ds1; + DsvFormatSubobject dsv_format; +}; + +using Word = std::uint64_t; +template<class T> Word ptr_arg(T* p) { return reinterpret_cast<Word>(p); } + +bool read_bytes(const char* path, std::vector<char>& out) +{ + std::ifstream file(path, std::ios::binary); + out.assign(std::istreambuf_iterator<char>(file), {}); + return !out.empty(); +} + +int pick_adapter(bool hardware, ComPtr<IDXGIAdapter>& adapter) +{ + ComPtr<IDXGIFactory4> factory; + if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 4; + if (!hardware) return SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter))) ? 0 : 4; + ComPtr<IDXGIFactory6> factory6; + if (FAILED(factory.As(&factory6))) return 77; + for (UINT n = 0;; ++n) { + ComPtr<IDXGIAdapter1> candidate; + const HRESULT hr = factory6->EnumAdapterByGpuPreference(n, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&candidate)); + if (hr == DXGI_ERROR_NOT_FOUND) return 77; + if (FAILED(hr)) return 4; + DXGI_ADAPTER_DESC1 desc{}; + if (FAILED(candidate->GetDesc1(&desc))) return 4; + if (!(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) && + SUCCEEDED(D3D12CreateDevice(candidate.Get(), D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), nullptr))) { + adapter = candidate; + return 0; + } + } +} + +void* create_stream_pso(void* device, ID3D12RootSignature* root, const std::vector<char>& vs, + const std::vector<char>& ps, const D3D12_DEPTH_STENCIL_DESC& ds, bool use_ds1) +{ + using CreateStream = HRESULT (WINAPI*)(void*, const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**); + auto create = reinterpret_cast<CreateStream>((*static_cast<void***>(device))[86]); + void* pso = nullptr; + if (use_ds1) { + DepthStream1 stream{ + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {ps.data(), ps.size()}}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, {vs.data(), vs.size()}}, + {static_cast<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE>(21), ds, FALSE}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT_D32_FLOAT}, + }; + const D3D12_PIPELINE_STATE_STREAM_DESC desc{sizeof(stream), &stream}; + if (FAILED(create(device, &desc, __uuidof(ID3D12PipelineState), &pso))) return nullptr; + } else { + DepthStream stream{ + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {ps.data(), ps.size()}}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, {vs.data(), vs.size()}}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, ds}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT_D32_FLOAT}, + }; + const D3D12_PIPELINE_STATE_STREAM_DESC desc{sizeof(stream), &stream}; + if (FAILED(create(device, &desc, __uuidof(ID3D12PipelineState), &pso))) return nullptr; + } + return pso; +} + +int clear_depth_desktop(ID3D12Device* desktop, ID3D12Resource* depth_tex) +{ + D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1}; + ComPtr<ID3D12DescriptorHeap> heap; + if (FAILED(desktop->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap)))) return 40; + const D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc{DXGI_FORMAT_D32_FLOAT, D3D12_DSV_DIMENSION_TEXTURE2D, D3D12_DSV_FLAG_NONE, {}}; + const D3D12_CPU_DESCRIPTOR_HANDLE handle = heap->GetCPUDescriptorHandleForHeapStart(); + desktop->CreateDepthStencilView(depth_tex, &dsv_desc, handle); + + D3D12_COMMAND_QUEUE_DESC qd{}; + ComPtr<ID3D12CommandQueue> queue; + ComPtr<ID3D12CommandAllocator> alloc; + ComPtr<ID3D12GraphicsCommandList> list; + ComPtr<ID3D12Fence> fence; + if (FAILED(desktop->CreateCommandQueue(&qd, IID_PPV_ARGS(&queue))) || + FAILED(desktop->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&alloc))) || + FAILED(desktop->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, alloc.Get(), nullptr, IID_PPV_ARGS(&list))) || + FAILED(desktop->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)))) return 41; + + D3D12_RESOURCE_BARRIER b{}; + b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + b.Transition = {depth_tex, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_DEPTH_WRITE}; + list->ResourceBarrier(1, &b); + list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr); + b.Transition.StateBefore = D3D12_RESOURCE_STATE_DEPTH_WRITE; + b.Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON; + list->ResourceBarrier(1, &b); + if (FAILED(list->Close())) return 42; + + ID3D12CommandList* lists[] = {list.Get()}; + queue->ExecuteCommandLists(1, lists); + if (FAILED(queue->Signal(fence.Get(), 1))) return 43; + HANDLE ev = CreateEventW(nullptr, FALSE, FALSE, nullptr); + if (!ev) return 44; + const bool ok = SUCCEEDED(fence->SetEventOnCompletion(1, ev)) && WaitForSingleObject(ev, 10000) == WAIT_OBJECT_0; + CloseHandle(ev); + return ok ? 0 : 45; +} + +int execute_guest_list(void* queue, void* list, void* fence, UINT64 fence_value) +{ + if (FAILED(static_cast<HRESULT>(invoke(list, 9)))) return 50; + void* lists[] = {list}; + invoke(queue, 10, 1, ptr_arg(lists)); + if (FAILED(static_cast<HRESULT>(invoke(queue, 14, ptr_arg(fence), fence_value)))) return 51; + const auto deadline = GetTickCount64() + 10000; + while (invoke(fence, 8) < fence_value && GetTickCount64() < deadline) Sleep(1); + return invoke(fence, 8) >= fence_value ? 0 : 53; +} + +} // namespace + +int main(int argc, char** argv) +{ + if (argc != 7 && argc != 10) return 2; + std::vector<char> vs_front, vs_back, ps_green, ps_red; + if (!read_bytes(argv[1], vs_front) || !read_bytes(argv[2], vs_back) || + !read_bytes(argv[3], ps_green) || !read_bytes(argv[4], ps_red)) return 3; + const bool hardware = std::strcmp(argv[6], "hardware") == 0; + + ComPtr<IDXGIAdapter> adapter; + if (const int rc = pick_adapter(hardware, adapter)) return rc; ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Emit the required hardware metadata from the new fixture** For `startup_stream_depth_hardware`, the fixture selects an adapter but never reports its identity or driver; the Python wrapper ultimately prints only debug messages and the backend/result summary. Unlike the existing `prepare_stream_pipeline()` helper, this path therefore produces GPU evidence that cannot be attributed to the selected adapter, especially on multi-GPU systems. `AGENTS.md` requires GPU reports to identify the adapter, driver, Windows build, commit, and debug-layer status, so emit and preserve that metadata with these results. AGENTS.md reference: [AGENTS.md:L95-L96](https://github.com/R0Y00/Xbox2Windows/blob/7dbe51617081949aabc9fe2c0ea880c0ab9fbb51/AGENTS.md#L95-L96) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 12:03:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:47:25Z.

Code review location: src/startup_stubs/d3d12_xs_device.cpp; line 1756

@@ -1699,32 +1700,63 @@ void __stdcall list_graphics_root(Wrapper* self, void* root)
     if (auto* list = recording(self); list && w && w->own().kind == root_signature_kind && w->own().real)
         list->SetGraphicsRootSignature(static_cast<ID3D12RootSignature*>(w->own().real));
 }
-// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). Depth is not bound yet.
-void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, const void*)
+DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target)
+{
+    DXGI_FORMAT format = target->GetDesc().Format;
+    if (const std::uint32_t id = shadow_id(desktop_handle)) {
+        AcquireSRWLockShared(&note_lock);
+        DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN;
+        if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4)
+            std::memcpy(&view_format, view_records()[id - 1].desc, 4);
+        ReleaseSRWLockShared(&note_lock);
+        if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format);
+    }
+    return format;
+}
+// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth).
+void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range,
+                            const D3D12_CPU_DESCRIPTOR_HANDLE* depth)
 {
     auto* list = recording(self);
     Pass& pass = pass_of(self);
     pass.targets_bound = false;
-    if (!list || !count || count > 8 || single_range || !x2w_local::readable(handles, count * sizeof(*handles))) return;
+    pass.target_count = 0;
+    pass.target0 = nullptr;
+    pass.dsv_format = DXGI_FORMAT_UNKNOWN;
+    if (!list || count > 8 || single_range) return;
+    if (count && !x2w_local::readable(handles, count * sizeof(*handles))) return;
     D3D12_CPU_DESCRIPTOR_HANDLE desktop[8];
+    ID3D12Resource* targets[8]{};
+    DXGI_FORMAT formats[8]{};
     for (UINT i = 0; i < count; ++i) {
         desktop[i].ptr = static_cast<SIZE_T>(desktop_cpu_handle(handles[i].ptr));
-        ID3D12Resource* target = view_target(desktop[i].ptr);
-        if (!target) return;
-        use_as_target(self, target);
-        DXGI_FORMAT format = target->GetDesc().Format;
-        if (const std::uint32_t id = shadow_id(desktop[i].ptr)) {
-            AcquireSRWLockShared(&note_lock);
-            DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN;
-            if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) std::memcpy(&view_format, view_records()[id - 1].desc, 4);
-            ReleaseSRWLockShared(&note_lock);
-            if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format);
+        targets[i] = view_target(desktop[i].ptr);
+        if (!targets[i]) return;
+        formats[i] = view_format_of(desktop[i].ptr, targets[i]);
+    }
+    D3D12_CPU_DESCRIPTOR_HANDLE desktop_dsv{};
+    const D3D12_CPU_DESCRIPTOR_HANDLE* dsv_ptr = nullptr;
+    ID3D12Resource* dsv_target = nullptr;
+    DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN;
+    if (depth && x2w_local::readable(depth, sizeof(*depth))) {
+        const u64 resolved = desktop_cpu_handle(depth->ptr);
+        dsv_target = resolved ? view_target(resolved) : nullptr;
+        if (dsv_target) {
+            desktop_dsv.ptr = static_cast<SIZE_T>(resolved);
+            dsv_ptr = &desktop_dsv;
+            dsv_format = view_format_of(resolved, dsv_target);
         }
-        pass.target_formats[i] = format;
-        if (i == 0) pass.target0 = target;
     }
+    if (!count && !dsv_ptr) return;
+    for (UINT i = 0; i < count; ++i) {
+        use_as_target(self, targets[i]);
+        pass.target_formats[i] = formats[i];
+        if (i == 0) pass.target0 = targets[i];
+    }
+    if (dsv_target) require_state(self, dsv_target, D3D12_RESOURCE_STATE_DEPTH_WRITE);

Fixed in 1a361114: DSV flags are read from the view record; a read-only depth view binds as DEPTH_READ, and a draw that samples the same texture keeps DEPTH_READ|PIXEL_SHADER_RESOURCE (sampled_state).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679520230 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#discussion_r4679520230). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:47:25Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 1756 ~~~~diff @@ -1699,32 +1700,63 @@ void __stdcall list_graphics_root(Wrapper* self, void* root) if (auto* list = recording(self); list && w && w->own().kind == root_signature_kind && w->own().real) list->SetGraphicsRootSignature(static_cast<ID3D12RootSignature*>(w->own().real)); } -// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). Depth is not bound yet. -void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, const void*) +DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target) +{ + DXGI_FORMAT format = target->GetDesc().Format; + if (const std::uint32_t id = shadow_id(desktop_handle)) { + AcquireSRWLockShared(&note_lock); + DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN; + if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) + std::memcpy(&view_format, view_records()[id - 1].desc, 4); + ReleaseSRWLockShared(&note_lock); + if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format); + } + return format; +} +// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). +void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, + const D3D12_CPU_DESCRIPTOR_HANDLE* depth) { auto* list = recording(self); Pass& pass = pass_of(self); pass.targets_bound = false; - if (!list || !count || count > 8 || single_range || !x2w_local::readable(handles, count * sizeof(*handles))) return; + pass.target_count = 0; + pass.target0 = nullptr; + pass.dsv_format = DXGI_FORMAT_UNKNOWN; + if (!list || count > 8 || single_range) return; + if (count && !x2w_local::readable(handles, count * sizeof(*handles))) return; D3D12_CPU_DESCRIPTOR_HANDLE desktop[8]; + ID3D12Resource* targets[8]{}; + DXGI_FORMAT formats[8]{}; for (UINT i = 0; i < count; ++i) { desktop[i].ptr = static_cast<SIZE_T>(desktop_cpu_handle(handles[i].ptr)); - ID3D12Resource* target = view_target(desktop[i].ptr); - if (!target) return; - use_as_target(self, target); - DXGI_FORMAT format = target->GetDesc().Format; - if (const std::uint32_t id = shadow_id(desktop[i].ptr)) { - AcquireSRWLockShared(&note_lock); - DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN; - if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) std::memcpy(&view_format, view_records()[id - 1].desc, 4); - ReleaseSRWLockShared(&note_lock); - if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format); + targets[i] = view_target(desktop[i].ptr); + if (!targets[i]) return; + formats[i] = view_format_of(desktop[i].ptr, targets[i]); + } + D3D12_CPU_DESCRIPTOR_HANDLE desktop_dsv{}; + const D3D12_CPU_DESCRIPTOR_HANDLE* dsv_ptr = nullptr; + ID3D12Resource* dsv_target = nullptr; + DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN; + if (depth && x2w_local::readable(depth, sizeof(*depth))) { + const u64 resolved = desktop_cpu_handle(depth->ptr); + dsv_target = resolved ? view_target(resolved) : nullptr; + if (dsv_target) { + desktop_dsv.ptr = static_cast<SIZE_T>(resolved); + dsv_ptr = &desktop_dsv; + dsv_format = view_format_of(resolved, dsv_target); } - pass.target_formats[i] = format; - if (i == 0) pass.target0 = target; } + if (!count && !dsv_ptr) return; + for (UINT i = 0; i < count; ++i) { + use_as_target(self, targets[i]); + pass.target_formats[i] = formats[i]; + if (i == 0) pass.target0 = targets[i]; + } + if (dsv_target) require_state(self, dsv_target, D3D12_RESOURCE_STATE_DEPTH_WRITE); ~~~~ --- Fixed in 1a361114: DSV flags are read from the view record; a read-only depth view binds as DEPTH_READ, and a draw that samples the same texture keeps DEPTH_READ|PIXEL_SHADER_RESOURCE (sampled_state).
tedin7 commented 2026-11-24 12:03:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:47:27Z.

Code review location: src/startup_stubs/d3d12_xs_device.cpp; line 1743

@@ -1699,32 +1700,63 @@ void __stdcall list_graphics_root(Wrapper* self, void* root)
     if (auto* list = recording(self); list && w && w->own().kind == root_signature_kind && w->own().real)
         list->SetGraphicsRootSignature(static_cast<ID3D12RootSignature*>(w->own().real));
 }
-// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). Depth is not bound yet.
-void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, const void*)
+DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target)
+{
+    DXGI_FORMAT format = target->GetDesc().Format;
+    if (const std::uint32_t id = shadow_id(desktop_handle)) {
+        AcquireSRWLockShared(&note_lock);
+        DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN;
+        if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4)
+            std::memcpy(&view_format, view_records()[id - 1].desc, 4);
+        ReleaseSRWLockShared(&note_lock);
+        if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format);
+    }
+    return format;
+}
+// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth).
+void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range,
+                            const D3D12_CPU_DESCRIPTOR_HANDLE* depth)
 {
     auto* list = recording(self);
     Pass& pass = pass_of(self);
     pass.targets_bound = false;
-    if (!list || !count || count > 8 || single_range || !x2w_local::readable(handles, count * sizeof(*handles))) return;
+    pass.target_count = 0;
+    pass.target0 = nullptr;
+    pass.dsv_format = DXGI_FORMAT_UNKNOWN;
+    if (!list || count > 8 || single_range) return;
+    if (count && !x2w_local::readable(handles, count * sizeof(*handles))) return;
     D3D12_CPU_DESCRIPTOR_HANDLE desktop[8];
+    ID3D12Resource* targets[8]{};
+    DXGI_FORMAT formats[8]{};
     for (UINT i = 0; i < count; ++i) {
         desktop[i].ptr = static_cast<SIZE_T>(desktop_cpu_handle(handles[i].ptr));
-        ID3D12Resource* target = view_target(desktop[i].ptr);
-        if (!target) return;
-        use_as_target(self, target);
-        DXGI_FORMAT format = target->GetDesc().Format;
-        if (const std::uint32_t id = shadow_id(desktop[i].ptr)) {
-            AcquireSRWLockShared(&note_lock);
-            DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN;
-            if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) std::memcpy(&view_format, view_records()[id - 1].desc, 4);
-            ReleaseSRWLockShared(&note_lock);
-            if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format);
+        targets[i] = view_target(desktop[i].ptr);
+        if (!targets[i]) return;
+        formats[i] = view_format_of(desktop[i].ptr, targets[i]);
+    }
+    D3D12_CPU_DESCRIPTOR_HANDLE desktop_dsv{};
+    const D3D12_CPU_DESCRIPTOR_HANDLE* dsv_ptr = nullptr;
+    ID3D12Resource* dsv_target = nullptr;
+    DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN;
+    if (depth && x2w_local::readable(depth, sizeof(*depth))) {
+        const u64 resolved = desktop_cpu_handle(depth->ptr);
+        dsv_target = resolved ? view_target(resolved) : nullptr;

Fixed in 1a361114: the DSV (and RTV) is resolved from the descriptor's current shadow record, which note_copy carries across CopyDescriptors/CopyDescriptorsSimple, instead of the creation-time handle map.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679520528 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#discussion_r4679520528). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:47:27Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 1743 ~~~~diff @@ -1699,32 +1700,63 @@ void __stdcall list_graphics_root(Wrapper* self, void* root) if (auto* list = recording(self); list && w && w->own().kind == root_signature_kind && w->own().real) list->SetGraphicsRootSignature(static_cast<ID3D12RootSignature*>(w->own().real)); } -// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). Depth is not bound yet. -void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, const void*) +DXGI_FORMAT view_format_of(u64 desktop_handle, ID3D12Resource* target) +{ + DXGI_FORMAT format = target->GetDesc().Format; + if (const std::uint32_t id = shadow_id(desktop_handle)) { + AcquireSRWLockShared(&note_lock); + DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN; + if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) + std::memcpy(&view_format, view_records()[id - 1].desc, 4); + ReleaseSRWLockShared(&note_lock); + if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format); + } + return format; +} +// List slot 50 (desktop 46 + 4), OMSetRenderTargets(count, handles, single range, depth). +void __stdcall list_targets(Wrapper* self, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, BOOL single_range, + const D3D12_CPU_DESCRIPTOR_HANDLE* depth) { auto* list = recording(self); Pass& pass = pass_of(self); pass.targets_bound = false; - if (!list || !count || count > 8 || single_range || !x2w_local::readable(handles, count * sizeof(*handles))) return; + pass.target_count = 0; + pass.target0 = nullptr; + pass.dsv_format = DXGI_FORMAT_UNKNOWN; + if (!list || count > 8 || single_range) return; + if (count && !x2w_local::readable(handles, count * sizeof(*handles))) return; D3D12_CPU_DESCRIPTOR_HANDLE desktop[8]; + ID3D12Resource* targets[8]{}; + DXGI_FORMAT formats[8]{}; for (UINT i = 0; i < count; ++i) { desktop[i].ptr = static_cast<SIZE_T>(desktop_cpu_handle(handles[i].ptr)); - ID3D12Resource* target = view_target(desktop[i].ptr); - if (!target) return; - use_as_target(self, target); - DXGI_FORMAT format = target->GetDesc().Format; - if (const std::uint32_t id = shadow_id(desktop[i].ptr)) { - AcquireSRWLockShared(&note_lock); - DXGI_FORMAT view_format = DXGI_FORMAT_UNKNOWN; - if (id - 1 < view_records().size() && view_records()[id - 1].desc_bytes >= 4) std::memcpy(&view_format, view_records()[id - 1].desc, 4); - ReleaseSRWLockShared(&note_lock); - if (view_format != DXGI_FORMAT_UNKNOWN) format = desktop_format(view_format); + targets[i] = view_target(desktop[i].ptr); + if (!targets[i]) return; + formats[i] = view_format_of(desktop[i].ptr, targets[i]); + } + D3D12_CPU_DESCRIPTOR_HANDLE desktop_dsv{}; + const D3D12_CPU_DESCRIPTOR_HANDLE* dsv_ptr = nullptr; + ID3D12Resource* dsv_target = nullptr; + DXGI_FORMAT dsv_format = DXGI_FORMAT_UNKNOWN; + if (depth && x2w_local::readable(depth, sizeof(*depth))) { + const u64 resolved = desktop_cpu_handle(depth->ptr); + dsv_target = resolved ? view_target(resolved) : nullptr; ~~~~ --- Fixed in 1a361114: the DSV (and RTV) is resolved from the descriptor's current shadow record, which note_copy carries across CopyDescriptors/CopyDescriptorsSimple, instead of the creation-time handle map.
tedin7 commented 2026-11-24 12:03:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:47:29Z.

Code review location: tests/startup_stream_depth.cpp; line 186

@@ -0,0 +1,295 @@
+#include <d3d12.h>
+#include <dxgi1_6.h>
+#include <wrl/client.h>
+
+#include <array>
+#include <cstdint>
+#include <cstdio>
+#include <cstring>
+#include <fstream>
+#include <iterator>
+#include <vector>
+
+#include "startup_stream_setup.h"
+
+using Microsoft::WRL::ComPtr;
+extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**);
+
+namespace {
+
+struct alignas(8) StageSubobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    D3D12_SHADER_BYTECODE shader;
+};
+struct alignas(8) RootSubobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    ID3D12RootSignature* signature;
+};
+struct alignas(8) DepthStencilSubobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    D3D12_DEPTH_STENCIL_DESC desc;
+};
+static_assert(sizeof(DepthStencilSubobject) == 56);
+
+struct alignas(8) DepthStencil1Subobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    D3D12_DEPTH_STENCIL_DESC desc;
+    BOOL depth_bounds_test;
+};
+static_assert(sizeof(DepthStencil1Subobject) == 64);
+
+struct alignas(8) DsvFormatSubobject {
+    D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag;
+    DXGI_FORMAT format;
+};
+static_assert(sizeof(DsvFormatSubobject) == 8);
+
+struct DepthStream {
+    StageSubobject ps;
+    RootSubobject root;
+    StageSubobject vs;
+    DepthStencilSubobject ds;
+    DsvFormatSubobject dsv_format;
+};
+
+struct DepthStream1 {
+    StageSubobject ps;
+    RootSubobject root;
+    StageSubobject vs;
+    DepthStencil1Subobject ds1;
+    DsvFormatSubobject dsv_format;
+};
+
+using Word = std::uint64_t;
+template<class T> Word ptr_arg(T* p) { return reinterpret_cast<Word>(p); }
+
+bool read_bytes(const char* path, std::vector<char>& out)
+{
+    std::ifstream file(path, std::ios::binary);
+    out.assign(std::istreambuf_iterator<char>(file), {});
+    return !out.empty();
+}
+
+int pick_adapter(bool hardware, ComPtr<IDXGIAdapter>& adapter)
+{
+    ComPtr<IDXGIFactory4> factory;
+    if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 4;
+    if (!hardware) return SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter))) ? 0 : 4;
+    ComPtr<IDXGIFactory6> factory6;
+    if (FAILED(factory.As(&factory6))) return 77;
+    for (UINT n = 0;; ++n) {
+        ComPtr<IDXGIAdapter1> candidate;
+        const HRESULT hr = factory6->EnumAdapterByGpuPreference(n, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&candidate));
+        if (hr == DXGI_ERROR_NOT_FOUND) return 77;
+        if (FAILED(hr)) return 4;
+        DXGI_ADAPTER_DESC1 desc{};
+        if (FAILED(candidate->GetDesc1(&desc))) return 4;
+        if (!(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) &&
+            SUCCEEDED(D3D12CreateDevice(candidate.Get(), D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), nullptr))) {
+            adapter = candidate;
+            return 0;
+        }
+    }
+}
+
+void* create_stream_pso(void* device, ID3D12RootSignature* root, const std::vector<char>& vs,
+                        const std::vector<char>& ps, const D3D12_DEPTH_STENCIL_DESC& ds, bool use_ds1)
+{
+    using CreateStream = HRESULT (WINAPI*)(void*, const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**);
+    auto create = reinterpret_cast<CreateStream>((*static_cast<void***>(device))[86]);
+    void* pso = nullptr;
+    if (use_ds1) {
+        DepthStream1 stream{
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {ps.data(), ps.size()}},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, {vs.data(), vs.size()}},
+            {static_cast<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE>(21), ds, FALSE},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT_D32_FLOAT},
+        };
+        const D3D12_PIPELINE_STATE_STREAM_DESC desc{sizeof(stream), &stream};
+        if (FAILED(create(device, &desc, __uuidof(ID3D12PipelineState), &pso))) return nullptr;
+    } else {
+        DepthStream stream{
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {ps.data(), ps.size()}},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, {vs.data(), vs.size()}},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, ds},
+            {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT_D32_FLOAT},
+        };
+        const D3D12_PIPELINE_STATE_STREAM_DESC desc{sizeof(stream), &stream};
+        if (FAILED(create(device, &desc, __uuidof(ID3D12PipelineState), &pso))) return nullptr;
+    }
+    return pso;
+}
+
+int clear_depth_desktop(ID3D12Device* desktop, ID3D12Resource* depth_tex)
+{
+    D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1};
+    ComPtr<ID3D12DescriptorHeap> heap;
+    if (FAILED(desktop->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap)))) return 40;
+    const D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc{DXGI_FORMAT_D32_FLOAT, D3D12_DSV_DIMENSION_TEXTURE2D, D3D12_DSV_FLAG_NONE, {}};
+    const D3D12_CPU_DESCRIPTOR_HANDLE handle = heap->GetCPUDescriptorHandleForHeapStart();
+    desktop->CreateDepthStencilView(depth_tex, &dsv_desc, handle);
+
+    D3D12_COMMAND_QUEUE_DESC qd{};
+    ComPtr<ID3D12CommandQueue> queue;
+    ComPtr<ID3D12CommandAllocator> alloc;
+    ComPtr<ID3D12GraphicsCommandList> list;
+    ComPtr<ID3D12Fence> fence;
+    if (FAILED(desktop->CreateCommandQueue(&qd, IID_PPV_ARGS(&queue))) ||
+        FAILED(desktop->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&alloc))) ||
+        FAILED(desktop->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, alloc.Get(), nullptr, IID_PPV_ARGS(&list))) ||
+        FAILED(desktop->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)))) return 41;
+
+    D3D12_RESOURCE_BARRIER b{};
+    b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+    b.Transition = {depth_tex, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_DEPTH_WRITE};
+    list->ResourceBarrier(1, &b);
+    list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);
+    b.Transition.StateBefore = D3D12_RESOURCE_STATE_DEPTH_WRITE;
+    b.Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
+    list->ResourceBarrier(1, &b);
+    if (FAILED(list->Close())) return 42;
+
+    ID3D12CommandList* lists[] = {list.Get()};
+    queue->ExecuteCommandLists(1, lists);
+    if (FAILED(queue->Signal(fence.Get(), 1))) return 43;
+    HANDLE ev = CreateEventW(nullptr, FALSE, FALSE, nullptr);
+    if (!ev) return 44;
+    const bool ok = SUCCEEDED(fence->SetEventOnCompletion(1, ev)) && WaitForSingleObject(ev, 10000) == WAIT_OBJECT_0;
+    CloseHandle(ev);
+    return ok ? 0 : 45;
+}
+
+int execute_guest_list(void* queue, void* list, void* fence, UINT64 fence_value)
+{
+    if (FAILED(static_cast<HRESULT>(invoke(list, 9)))) return 50;
+    void* lists[] = {list};
+    invoke(queue, 10, 1, ptr_arg(lists));
+    if (FAILED(static_cast<HRESULT>(invoke(queue, 14, ptr_arg(fence), fence_value)))) return 51;
+    const auto deadline = GetTickCount64() + 10000;
+    while (invoke(fence, 8) < fence_value && GetTickCount64() < deadline) Sleep(1);
+    return invoke(fence, 8) >= fence_value ? 0 : 53;
+}
+
+}  // namespace
+
+int main(int argc, char** argv)
+{
+    if (argc != 7 && argc != 10) return 2;
+    std::vector<char> vs_front, vs_back, ps_green, ps_red;
+    if (!read_bytes(argv[1], vs_front) || !read_bytes(argv[2], vs_back) ||
+        !read_bytes(argv[3], ps_green) || !read_bytes(argv[4], ps_red)) return 3;
+    const bool hardware = std::strcmp(argv[6], "hardware") == 0;
+
+    ComPtr<IDXGIAdapter> adapter;
+    if (const int rc = pick_adapter(hardware, adapter)) return rc;

Fixed in 1a361114: startup_stream_depth prints adapter, vendor/device ids and driver version, which the check script preserves in its output.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679520880 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#discussion_r4679520880). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:47:29Z. **Code review location:** `tests/startup_stream_depth.cpp`; line 186 ~~~~diff @@ -0,0 +1,295 @@ +#include <d3d12.h> +#include <dxgi1_6.h> +#include <wrl/client.h> + +#include <array> +#include <cstdint> +#include <cstdio> +#include <cstring> +#include <fstream> +#include <iterator> +#include <vector> + +#include "startup_stream_setup.h" + +using Microsoft::WRL::ComPtr; +extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**); + +namespace { + +struct alignas(8) StageSubobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + D3D12_SHADER_BYTECODE shader; +}; +struct alignas(8) RootSubobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + ID3D12RootSignature* signature; +}; +struct alignas(8) DepthStencilSubobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + D3D12_DEPTH_STENCIL_DESC desc; +}; +static_assert(sizeof(DepthStencilSubobject) == 56); + +struct alignas(8) DepthStencil1Subobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + D3D12_DEPTH_STENCIL_DESC desc; + BOOL depth_bounds_test; +}; +static_assert(sizeof(DepthStencil1Subobject) == 64); + +struct alignas(8) DsvFormatSubobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE tag; + DXGI_FORMAT format; +}; +static_assert(sizeof(DsvFormatSubobject) == 8); + +struct DepthStream { + StageSubobject ps; + RootSubobject root; + StageSubobject vs; + DepthStencilSubobject ds; + DsvFormatSubobject dsv_format; +}; + +struct DepthStream1 { + StageSubobject ps; + RootSubobject root; + StageSubobject vs; + DepthStencil1Subobject ds1; + DsvFormatSubobject dsv_format; +}; + +using Word = std::uint64_t; +template<class T> Word ptr_arg(T* p) { return reinterpret_cast<Word>(p); } + +bool read_bytes(const char* path, std::vector<char>& out) +{ + std::ifstream file(path, std::ios::binary); + out.assign(std::istreambuf_iterator<char>(file), {}); + return !out.empty(); +} + +int pick_adapter(bool hardware, ComPtr<IDXGIAdapter>& adapter) +{ + ComPtr<IDXGIFactory4> factory; + if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 4; + if (!hardware) return SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter))) ? 0 : 4; + ComPtr<IDXGIFactory6> factory6; + if (FAILED(factory.As(&factory6))) return 77; + for (UINT n = 0;; ++n) { + ComPtr<IDXGIAdapter1> candidate; + const HRESULT hr = factory6->EnumAdapterByGpuPreference(n, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&candidate)); + if (hr == DXGI_ERROR_NOT_FOUND) return 77; + if (FAILED(hr)) return 4; + DXGI_ADAPTER_DESC1 desc{}; + if (FAILED(candidate->GetDesc1(&desc))) return 4; + if (!(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) && + SUCCEEDED(D3D12CreateDevice(candidate.Get(), D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), nullptr))) { + adapter = candidate; + return 0; + } + } +} + +void* create_stream_pso(void* device, ID3D12RootSignature* root, const std::vector<char>& vs, + const std::vector<char>& ps, const D3D12_DEPTH_STENCIL_DESC& ds, bool use_ds1) +{ + using CreateStream = HRESULT (WINAPI*)(void*, const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**); + auto create = reinterpret_cast<CreateStream>((*static_cast<void***>(device))[86]); + void* pso = nullptr; + if (use_ds1) { + DepthStream1 stream{ + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {ps.data(), ps.size()}}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, {vs.data(), vs.size()}}, + {static_cast<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE>(21), ds, FALSE}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT_D32_FLOAT}, + }; + const D3D12_PIPELINE_STATE_STREAM_DESC desc{sizeof(stream), &stream}; + if (FAILED(create(device, &desc, __uuidof(ID3D12PipelineState), &pso))) return nullptr; + } else { + DepthStream stream{ + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {ps.data(), ps.size()}}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, root}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, {vs.data(), vs.size()}}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, ds}, + {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT_D32_FLOAT}, + }; + const D3D12_PIPELINE_STATE_STREAM_DESC desc{sizeof(stream), &stream}; + if (FAILED(create(device, &desc, __uuidof(ID3D12PipelineState), &pso))) return nullptr; + } + return pso; +} + +int clear_depth_desktop(ID3D12Device* desktop, ID3D12Resource* depth_tex) +{ + D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1}; + ComPtr<ID3D12DescriptorHeap> heap; + if (FAILED(desktop->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap)))) return 40; + const D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc{DXGI_FORMAT_D32_FLOAT, D3D12_DSV_DIMENSION_TEXTURE2D, D3D12_DSV_FLAG_NONE, {}}; + const D3D12_CPU_DESCRIPTOR_HANDLE handle = heap->GetCPUDescriptorHandleForHeapStart(); + desktop->CreateDepthStencilView(depth_tex, &dsv_desc, handle); + + D3D12_COMMAND_QUEUE_DESC qd{}; + ComPtr<ID3D12CommandQueue> queue; + ComPtr<ID3D12CommandAllocator> alloc; + ComPtr<ID3D12GraphicsCommandList> list; + ComPtr<ID3D12Fence> fence; + if (FAILED(desktop->CreateCommandQueue(&qd, IID_PPV_ARGS(&queue))) || + FAILED(desktop->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&alloc))) || + FAILED(desktop->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, alloc.Get(), nullptr, IID_PPV_ARGS(&list))) || + FAILED(desktop->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)))) return 41; + + D3D12_RESOURCE_BARRIER b{}; + b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + b.Transition = {depth_tex, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_DEPTH_WRITE}; + list->ResourceBarrier(1, &b); + list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr); + b.Transition.StateBefore = D3D12_RESOURCE_STATE_DEPTH_WRITE; + b.Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON; + list->ResourceBarrier(1, &b); + if (FAILED(list->Close())) return 42; + + ID3D12CommandList* lists[] = {list.Get()}; + queue->ExecuteCommandLists(1, lists); + if (FAILED(queue->Signal(fence.Get(), 1))) return 43; + HANDLE ev = CreateEventW(nullptr, FALSE, FALSE, nullptr); + if (!ev) return 44; + const bool ok = SUCCEEDED(fence->SetEventOnCompletion(1, ev)) && WaitForSingleObject(ev, 10000) == WAIT_OBJECT_0; + CloseHandle(ev); + return ok ? 0 : 45; +} + +int execute_guest_list(void* queue, void* list, void* fence, UINT64 fence_value) +{ + if (FAILED(static_cast<HRESULT>(invoke(list, 9)))) return 50; + void* lists[] = {list}; + invoke(queue, 10, 1, ptr_arg(lists)); + if (FAILED(static_cast<HRESULT>(invoke(queue, 14, ptr_arg(fence), fence_value)))) return 51; + const auto deadline = GetTickCount64() + 10000; + while (invoke(fence, 8) < fence_value && GetTickCount64() < deadline) Sleep(1); + return invoke(fence, 8) >= fence_value ? 0 : 53; +} + +} // namespace + +int main(int argc, char** argv) +{ + if (argc != 7 && argc != 10) return 2; + std::vector<char> vs_front, vs_back, ps_green, ps_red; + if (!read_bytes(argv[1], vs_front) || !read_bytes(argv[2], vs_back) || + !read_bytes(argv[3], ps_green) || !read_bytes(argv[4], ps_red)) return 3; + const bool hardware = std::strcmp(argv[6], "hardware") == 0; + + ComPtr<IDXGIAdapter> adapter; + if (const int rc = pick_adapter(hardware, adapter)) return rc; ~~~~ --- Fixed in 1a361114: startup_stream_depth prints adapter, vendor/device ids and driver version, which the check script preserves in its output.
upstream-sync closed this pull request 2026-11-24 13:00:23 +00:00
R0Y00 commented 2026-11-24 13:00:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:30:22Z.

Review: APPROVED


Re-reviewed this exact revision. Windows Release stream depth and adjacent stream/MRT checks passed 8/8 on RTX and WARP. The depth-only shader no longer emits an RTV output, and the read-only depth, invalid view-role, and bounds controls remain covered.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039213722 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#pullrequestreview-6039213722). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T12:30:22Z. **Review:** APPROVED --- Re-reviewed this exact revision. Windows Release stream depth and adjacent stream/MRT checks passed 8/8 on RTX and WARP. The depth-only shader no longer emits an RTV output, and the read-only depth, invalid view-role, and bounds controls remain covered.
tedin7 commented 2026-11-24 13:00:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:18:27Z.


@R0Y00 Fixed in addc99c2: the depth-only PSO now uses a pixel shader that exports nothing, so it no longer declares SV_Target0 for the zero-RTV pass. The translator (tools/startup/gfx2hlsl.py) emits a void main for an export-less pixel shader. The warning-severity assertion in startup_stream_depth_check.py is unchanged. Win2025 (MSVC, D3D12 WARP): Debug (--preset dev) and Release /O2 (--preset release) both pass startup_stream_depth_warp and startup_stream_depth_hardware, 2/2 each. The VM has only WARP, so the _hardware test also ran on WARP there and the RTX 4060 Laptop result still needs your run. AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7131254306 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#issuecomment-7131254306). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:18:27Z. --- @R0Y00 Fixed in addc99c2: the depth-only PSO now uses a pixel shader that exports nothing, so it no longer declares SV_Target0 for the zero-RTV pass. The translator (tools/startup/gfx2hlsl.py) emits a void main for an export-less pixel shader. The warning-severity assertion in startup_stream_depth_check.py is unchanged. Win2025 (MSVC, D3D12 WARP): Debug (--preset dev) and Release /O2 (--preset release) both pass startup_stream_depth_warp and startup_stream_depth_hardware, 2/2 each. The VM has only WARP, so the _hardware test also ran on WARP there and the RTX 4060 Laptop result still needs your run. AI-assisted; commands listed were executed locally.
thepatrickworld commented 2026-11-24 13:00:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T12:20:09Z.


Measured addc99c2 merged onto 03d4c69d (my merge dfb441a1, tree e67ec184, working tree clean), Windows 11 25H2 (26200.9974), DXC 1.9.2602.17.

startup_stream_depth_hardware and startup_stream_depth_warp both passed, three runs out of three:

  • hardware: adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550 driver=32.0.32029.2010
  • warp: adapter=Microsoft Basic Render Driver vendor=1414 device=008c driver=10.0.26100.9818

With all three readbacks reported on the hardware backend:

hardware: depth LESS occluded far red (green), DepthEnable=FALSE overwrote (red), count=0 depth-only occluded far red (clear)

So the depth path holds on real hardware (AMD RX 9070 XT), not just WARP, including the DepthEnable=FALSE negative control and the count == 0 depth-only pass.

For context on the intermediate step: 883bc706 (the PS-less depth-only PSO) failed three runs out of three on both backends — the depth-only readback came back red on the left half (ff0000ff × 16) instead of all clear, so the far quad was no longer occluded. WARP failing too is what made it a fixture/shim question rather than an adapter one. The export-less pixel shader in the current head passes on both.

Your own verification and the CI both stay on WARP (_hardware$ is excluded), so as far as I can see in this thread this is the first real-adapter run of the entry.

One limitation, so the result is not read as more than it is: the D3D12 debug layer is not installed on this machine (0x887a002d, SDK component missing; the Graphics Tools optional feature is absent and its install is refused from my remote session with 0x80070005). The x2w-d3d12-debug sev=[012] assertion therefore had nothing to inspect. What passed is the pixel path — exact bytes on all three readbacks — not API validation.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7131294718 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#issuecomment-7131294718). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-24T12:20:09Z. --- Measured `addc99c2` merged onto `03d4c69d` (my merge `dfb441a1`, tree `e67ec184`, working tree clean), Windows 11 25H2 (26200.9974), DXC 1.9.2602.17. `startup_stream_depth_hardware` and `startup_stream_depth_warp` both passed, three runs out of three: - hardware: `adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550 driver=32.0.32029.2010` - warp: `adapter=Microsoft Basic Render Driver vendor=1414 device=008c driver=10.0.26100.9818` With all three readbacks reported on the hardware backend: ``` hardware: depth LESS occluded far red (green), DepthEnable=FALSE overwrote (red), count=0 depth-only occluded far red (clear) ``` So the depth path holds on real hardware (AMD RX 9070 XT), not just WARP, including the `DepthEnable=FALSE` negative control and the `count == 0` depth-only pass. For context on the intermediate step: `883bc706` (the PS-less depth-only PSO) failed three runs out of three on **both** backends — the depth-only readback came back red on the left half (`ff0000ff` × 16) instead of all clear, so the far quad was no longer occluded. WARP failing too is what made it a fixture/shim question rather than an adapter one. The export-less pixel shader in the current head passes on both. Your own verification and the CI both stay on WARP (`_hardware$` is excluded), so as far as I can see in this thread this is the first real-adapter run of the entry. One limitation, so the result is not read as more than it is: the D3D12 debug layer is not installed on this machine (`0x887a002d`, SDK component missing; the Graphics Tools optional feature is absent and its install is refused from my remote session with `0x80070005`). The `x2w-d3d12-debug sev=[012]` assertion therefore had nothing to inspect. What passed is the pixel path — exact bytes on all three readbacks — not API validation.
tedin7 commented 2026-11-24 13:00:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:23:04Z.


Thanks @thepatrickworld for testing addc99c2 on physical AMD Radeon RX 9070 XT hardware (3/3 pass across all three depth readbacks, including the DepthEnable=FALSE control and count=0 depth-only pass). Together with the Win2025 WARP runs (where the D3D12 debug layer is active and checked for zero sev=[012] messages), both the real-adapter pixel path and API validation are now covered.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7131362520 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#issuecomment-7131362520). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:23:04Z. --- Thanks @thepatrickworld for testing `addc99c2` on physical AMD Radeon RX 9070 XT hardware (3/3 pass across all three depth readbacks, including the `DepthEnable=FALSE` control and `count=0` depth-only pass). Together with the Win2025 WARP runs (where the D3D12 debug layer is active and checked for zero `sev=[012]` messages), both the real-adapter pixel path and API validation are now covered.
ChazY11 commented 2026-11-24 13:00:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T12:53:28Z.


The depth negative control is genuinely sensitive — verified by forcing DepthEnable = TRUE

Independent reviewer, not the author. Reviewed addc99c2; nothing pushed to the branch. The mutation below was made
locally, rebuilt, reverted; working tree is clean.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11, RTX 5080 Laptop
(32.0.15.8142) for the hardware variant, in-box WARP 10.0.26100.9818 for warp.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^(startup_stream_depth|startup_stream_draw|startup_stream_setup)' -V

Unmodified branch — 4 of 4 pass, with the intended line on both backends:

warp:     depth LESS occluded far red (green), DepthEnable=FALSE overwrote (red), count=0 depth-only occluded far red (clear)
hardware: depth LESS occluded far red (green), DepthEnable=FALSE overwrote (red), count=0 depth-only occluded far red (clear)

and startup_stream_draw_{warp,hardware} still reports the same 32-pixel and swapped-shader numbers, so the PSO cache
key change did not disturb the existing draws.

Mutation — DepthEnable forced on after the DEPTH_STENCIL copy

     std::memcpy(&depth_stencil, stream + at + sizeof(type), sizeof(depth_stencil));
+    depth_stencil.DepthEnable = TRUE;  // injected fault for review
     has_depth_stencil = true;
startup_stream_depth_warp ........ ***Failed
startup_stream_depth_hardware .... ***Failed

Both fail. That is the property I wanted to check: the DepthEnable=FALSE case is not passing by accident, it really
depends on the decoded subobject reaching pso_for. A negative control that stayed green here would have meant the
case was testing something else.

One practical note from doing this: the recompile of d3d12_xs_device.cpp (which pulls in the .inl) is what makes the
mutation take effect, and the x2w-draw desktop pipeline ... (dsv %d, depth %d) line you added is exactly what made it
possible to confirm the fault reached the pipeline. Please keep that line.

Limits of my run

The hardware variant selects the first non-software adapter through X2W_SHIM_DRAW_ADAPTER, so on this machine it is
the NVIDIA RTX, not an Intel adapter — no Intel datapoint from me here.

Verdict

Reviewed addc99c2. Build clean, both new cases pass on WARP and on a physical adapter, the existing stream draws are
unchanged, and the depth negative control fails when the decoded state is forced. No objection from me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132058926 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1430#issuecomment-7132058926). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T12:53:28Z. --- ## The depth negative control is genuinely sensitive — verified by forcing `DepthEnable = TRUE` Independent reviewer, not the author. Reviewed `addc99c2`; nothing pushed to the branch. The mutation below was made locally, rebuilt, reverted; working tree is clean. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11, RTX 5080 Laptop (32.0.15.8142) for the `hardware` variant, in-box WARP 10.0.26100.9818 for `warp`. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^(startup_stream_depth|startup_stream_draw|startup_stream_setup)' -V ``` Unmodified branch — 4 of 4 pass, with the intended line on both backends: ```text warp: depth LESS occluded far red (green), DepthEnable=FALSE overwrote (red), count=0 depth-only occluded far red (clear) hardware: depth LESS occluded far red (green), DepthEnable=FALSE overwrote (red), count=0 depth-only occluded far red (clear) ``` and `startup_stream_draw_{warp,hardware}` still reports the same 32-pixel and swapped-shader numbers, so the PSO cache key change did not disturb the existing draws. ### Mutation — `DepthEnable` forced on after the DEPTH_STENCIL copy ```diff std::memcpy(&depth_stencil, stream + at + sizeof(type), sizeof(depth_stencil)); + depth_stencil.DepthEnable = TRUE; // injected fault for review has_depth_stencil = true; ``` ```text startup_stream_depth_warp ........ ***Failed startup_stream_depth_hardware .... ***Failed ``` Both fail. That is the property I wanted to check: the `DepthEnable=FALSE` case is not passing by accident, it really depends on the decoded subobject reaching `pso_for`. A negative control that stayed green here would have meant the case was testing something else. One practical note from doing this: the recompile of `d3d12_xs_device.cpp` (which pulls in the `.inl`) is what makes the mutation take effect, and the `x2w-draw desktop pipeline ... (dsv %d, depth %d)` line you added is exactly what made it possible to confirm the fault reached the pipeline. Please keep that line. ### Limits of my run The `hardware` variant selects the first non-software adapter through `X2W_SHIM_DRAW_ADAPTER`, so on this machine it is the NVIDIA RTX, not an Intel adapter — no Intel datapoint from me here. ### Verdict Reviewed `addc99c2`. Build clean, both new cases pass on WARP and on a physical adapter, the existing stream draws are unchanged, and the depth negative control fails when the decoded state is forced. No objection from me.
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!1423
No description provided.