startup: validate clear format in d3d12_xs_device (Part of #870) #2012

Closed
tedin7 wants to merge 4 commits from upstream-pr/2019 into main
tedin7 commented 2026-11-24 23:11:22 +00:00 (Migrated from github.com)

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


Part of #870

What this unblocks: clear values for console formats 116-118 are now mapped to the same format as their resource, so the clear no longer uses a mismatched format.

Changes:

  • src/startup_stubs/clear_value_format.h (new): maps the clear value format like its resource.
  • src/startup_stubs/d3d12_xs_device.cpp: uses the mapping.
  • tests/startup_clear_format.cpp, tests/startup_clear_value_format_check.cpp (new, registered in CMake).
  • docs/startup-runtime.md: names the three desktop-order creators correctly.

Verification:

  • Local Linux: git merge-tree --write-tree origin/main x2w-frontier-dl816-clearfmt-rebased is clean (origin/main 66423e45).
  • GitHub CI, head cd3008fb: Build and test on Windows PASS (31/31). That job does not run startup_clear_format_*.
  • Win2025: python3 x2w_pipe.py win2025 2019 --force (default 3-slot pool), dev and release /O2, 26 selected tests each:
    • 25 passed, 0 failed, including startup_clear_value_format, startup_clear_value_format_d16_control and startup_clear_value_format_values_control.
    • 1 skipped, not counted as a pass: startup_clear_format_warp returns 77 because the VM has no D3D12 debug layer. The debug layer check (messages 816/817) is not yet confirmed on a host that has the layer.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593285134 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:11:22Z. --- Part of #870 What this unblocks: clear values for console formats 116-118 are now mapped to the same format as their resource, so the clear no longer uses a mismatched format. Changes: - `src/startup_stubs/clear_value_format.h` (new): maps the clear value format like its resource. - `src/startup_stubs/d3d12_xs_device.cpp`: uses the mapping. - `tests/startup_clear_format.cpp`, `tests/startup_clear_value_format_check.cpp` (new, registered in CMake). - `docs/startup-runtime.md`: names the three desktop-order creators correctly. Verification: - Local Linux: `git merge-tree --write-tree origin/main x2w-frontier-dl816-clearfmt-rebased` is clean (origin/main 66423e45). - GitHub CI, head `cd3008fb`: `Build and test on Windows` PASS (31/31). That job does not run `startup_clear_format_*`. - Win2025: `python3 x2w_pipe.py win2025 2019 --force` (default 3-slot pool), dev and release `/O2`, 26 selected tests each: - 25 passed, 0 failed, including `startup_clear_value_format`, `startup_clear_value_format_d16_control` and `startup_clear_value_format_values_control`. - 1 skipped, not counted as a pass: `startup_clear_format_warp` returns 77 because the VM has no D3D12 debug layer. The debug layer check (messages 816/817) is not yet confirmed on a host that has the layer. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 11:02:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T11:00:46Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cd3008fb48

ℹ️ 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:6056354840 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019#pullrequestreview-6056354840). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T11:00:46Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `cd3008fb48` <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>
tedin7 commented 2026-11-25 11:02:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:57:15Z.


Verification for head cd3008fb:

  • Audit: diff and body checked; no AI model names, no co-author trailers, no local-probe mentions.
  • GitHub CI: Build and test on Windows PASS (31/31). That job does not run startup_clear_format_*.
  • Win2025 (python3 x2w_pipe.py win2025 2019 --force, default 3-slot pool), dev and release /O2, 26 selected tests each:
    • 25 passed, 0 failed: startup_clear_value_format, startup_clear_value_format_d16_control, startup_clear_value_format_values_control, plus the WARP suites for cpu_shim, d3d12x and startup stubs.
    • 1 skipped (not a pass): startup_clear_format_warp returns 77 because the VM has no D3D12 debug layer. The debug-layer check (messages 816/817) is therefore not yet confirmed on a host that has the layer.
  • The earlier "Win2025 NOT run yet" line in the body is superseded by this comment.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7160392691 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019#issuecomment-7160392691). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T10:57:15Z. --- Verification for head `cd3008fb`: - Audit: diff and body checked; no AI model names, no co-author trailers, no local-probe mentions. - GitHub CI: `Build and test on Windows` PASS (31/31). That job does not run `startup_clear_format_*`. - Win2025 (`python3 x2w_pipe.py win2025 2019 --force`, default 3-slot pool), dev and release `/O2`, 26 selected tests each: - 25 passed, 0 failed: `startup_clear_value_format`, `startup_clear_value_format_d16_control`, `startup_clear_value_format_values_control`, plus the WARP suites for cpu_shim, d3d12x and startup stubs. - 1 skipped (not a pass): `startup_clear_format_warp` returns 77 because the VM has no D3D12 debug layer. The debug-layer check (messages 816/817) is therefore not yet confirmed on a host that has the layer. - The earlier "Win2025 NOT run yet" line in the body is superseded by this comment. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 11:02:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T10:57:28Z.


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-25T11:00:48.778295Z cd3008f 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:7160397397 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019#issuecomment-7160397397). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T10:57:28Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"cd3008fb489242a57c2ae8e39fa345bf8c20d9f9","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-25T11:00:48.778295Z">2026-11-25T11:00:48.778295Z</relative-time> | `cd3008f` | 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>
chatgpt-codex-connector[bot commented 2026-11-25 11:02:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T11:00:46Z.

Code review location: tests/startup_clear_format.cpp; line 105

@@ -0,0 +1,122 @@
+// A depth texture of console format 118 (D16_UNORM_S8_UINT) created with a clear value, through device slots
+// 133 and 27, must be accepted by desktop D3D12 on the first attempt: the clear value carries the mapped format,
+// so the debug layer stores no message for an invalid clear value (ids 816 and 817).
+//
+//   startup_clear_format <warp|hardware>     (X2W_D3D12_PERMISSIVE=1 X2W_D3D12_LIST_NOOP=1 X2W_D3D12_RENDER=1 X2W_D3D12_DEBUG=1)
+//
+// Both creations must return success and an object. Then the debug layer's stored messages are read: none may
+// be an error, and none may carry id 816 or 817. When the debug layer is not installed the creations are still
+// checked and the test reports a skip (77) for the message part.
+//
+// Exit codes: 0 pass, 77 no physical adapter or no debug layer, other values name the failing step.
+#include <d3d12.h>
+#include <d3d12sdklayers.h>
+#include <dxgi1_6.h>
+#include <wrl/client.h>
+
+#include <array>
+#include <cstdint>
+#include <cstdio>
+#include <cstring>
+#include <vector>
+
+using Microsoft::WRL::ComPtr;
+extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**);
+
+namespace {
+using Word = std::uint64_t;
+template <class T> Word arg(T* value) { return reinterpret_cast<Word>(value); }
+Word invoke(void* object, unsigned index, Word a = 0, Word b = 0, Word c = 0, Word d = 0, Word e = 0, Word f = 0, Word g = 0)
+{
+    using Slot = Word (WINAPI*)(void*, Word, Word, Word, Word, Word, Word, Word);
+    return reinterpret_cast<Slot>((*static_cast<void***>(object))[index])(object, a, b, c, d, e, f, g);
+}
+bool ok(Word hr) { return SUCCEEDED(static_cast<HRESULT>(hr)); }
+
+constexpr UINT console_d16_s8 = 118;
+}  // namespace
+
+int main(int argc, char** argv)
+{
+    if (argc != 2) return 2;
+    ComPtr<IDXGIFactory6> factory;
+    if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 3;
+    ComPtr<IDXGIAdapter> adapter;
+    if (std::strcmp(argv[1], "hardware") == 0) {
+        for (UINT n = 0;; ++n) {
+            ComPtr<IDXGIAdapter1> candidate;
+            const HRESULT hr = factory->EnumAdapterByGpuPreference(n, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&candidate));
+            if (hr == DXGI_ERROR_NOT_FOUND) return 77;
+            if (FAILED(hr)) return 3;
+            DXGI_ADAPTER_DESC1 desc{};
+            if (FAILED(candidate->GetDesc1(&desc))) return 3;
+            if (!(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) &&
+                SUCCEEDED(D3D12CreateDevice(candidate.Get(), D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), nullptr))) {
+                adapter = candidate;
+                break;
+            }
+        }
+    } else if (std::strcmp(argv[1], "warp") != 0 || FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter)))) {
+        return 3;
+    }
+    DXGI_ADAPTER_DESC adapter_desc{};
+    if (FAILED(adapter->GetDesc(&adapter_desc))) return 3;
+    std::printf("adapter=%ls\n", adapter_desc.Description);
+
+    std::array<unsigned char, 64> parameters{};
+    void* device = nullptr;
+    if (FAILED(D3D12XboxCreateDevice(adapter.Get(), parameters.data(), __uuidof(ID3D12Device), &device))) return 4;
+    ComPtr<ID3D12Device> desktop;
+    if (FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&desktop)))) return 4;
+
+    ComPtr<ID3D12InfoQueue> info;
+    const bool has_layer = SUCCEEDED(desktop.As(&info));
+    if (has_layer) info->ClearStoredMessages();
+
+    const D3D12_RESOURCE_DESC depth_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 16, 16, 1, 1, static_cast<DXGI_FORMAT>(console_d16_s8),
+                                         {1, 0}, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL};
+    D3D12_CLEAR_VALUE clear{};
+    clear.Format = static_cast<DXGI_FORMAT>(console_d16_s8);
+    clear.DepthStencil.Depth = 1.0f;
+
+    // Slot 133, placed on title memory: a texture is a committed stand-in.
+    static std::array<std::uint8_t, 65536 + 4096> memory{};
+    const Word address = (reinterpret_cast<Word>(memory.data()) + 0xffff) & ~Word{0xffff};
+    void* placed = nullptr;
+    if (!ok(invoke(device, 133, address, arg(&depth_desc), D3D12_RESOURCE_STATE_COMMON, arg(&clear), arg(&__uuidof(ID3D12Resource)),
+                   arg(&placed))) || !placed)
+        return 10;
+    std::printf("slot 133: depth texture with a clear value created\n");
+
+    // Slot 27, desktop order (props, flags, desc, state, clear, riid, ppv).
+    const D3D12_HEAP_PROPERTIES props{D3D12_HEAP_TYPE_DEFAULT};
+    void* committed = nullptr;
+    if (!ok(invoke(device, 27, arg(&props), D3D12_HEAP_FLAG_NONE, arg(&depth_desc), D3D12_RESOURCE_STATE_COMMON, arg(&clear),
+                   arg(&__uuidof(ID3D12Resource)), arg(&committed))) || !committed)
+        return 11;
+    std::printf("slot 27: depth texture with a clear value created\n");
+
+    if (desktop->GetDeviceRemovedReason() != S_OK) return 12;
+    if (!has_layer) {
+        std::printf("debug layer not installed: message check skipped\n");
+        return 77;
+    }
+    UINT64 errors = 0, clear_value_messages = 0;
+    for (UINT64 i = 0, n = info->GetNumStoredMessages(); i < n; ++i) {

P2 Badge Check slot-133 diagnostics before slot 27 drains the queue

With X2W_D3D12_DEBUG=1 enabled by these CTests, the preceding slot-27 call runs create_slot() → check_device() (d3d12_xs_device.cpp:747), which clears the shared info queue at line 373 before this inspection. If the slot-133 mapping is removed or bypassed, its existing retry without a clear value still succeeds, slot 27 erases the resulting 816/817 diagnostics, and this fixture incorrectly passes. Inspect the messages immediately after slot 133 or capture them through a callback, and add an unmapped-clear negative control to verify that the fallback cannot satisfy the test.

AGENTS.md reference: AGENTS.md:L235-L235

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4693910198 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019#discussion_r4693910198). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T11:00:46Z. **Code review location:** `tests/startup_clear_format.cpp`; line 105 ~~~~diff @@ -0,0 +1,122 @@ +// A depth texture of console format 118 (D16_UNORM_S8_UINT) created with a clear value, through device slots +// 133 and 27, must be accepted by desktop D3D12 on the first attempt: the clear value carries the mapped format, +// so the debug layer stores no message for an invalid clear value (ids 816 and 817). +// +// startup_clear_format <warp|hardware> (X2W_D3D12_PERMISSIVE=1 X2W_D3D12_LIST_NOOP=1 X2W_D3D12_RENDER=1 X2W_D3D12_DEBUG=1) +// +// Both creations must return success and an object. Then the debug layer's stored messages are read: none may +// be an error, and none may carry id 816 or 817. When the debug layer is not installed the creations are still +// checked and the test reports a skip (77) for the message part. +// +// Exit codes: 0 pass, 77 no physical adapter or no debug layer, other values name the failing step. +#include <d3d12.h> +#include <d3d12sdklayers.h> +#include <dxgi1_6.h> +#include <wrl/client.h> + +#include <array> +#include <cstdint> +#include <cstdio> +#include <cstring> +#include <vector> + +using Microsoft::WRL::ComPtr; +extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**); + +namespace { +using Word = std::uint64_t; +template <class T> Word arg(T* value) { return reinterpret_cast<Word>(value); } +Word invoke(void* object, unsigned index, Word a = 0, Word b = 0, Word c = 0, Word d = 0, Word e = 0, Word f = 0, Word g = 0) +{ + using Slot = Word (WINAPI*)(void*, Word, Word, Word, Word, Word, Word, Word); + return reinterpret_cast<Slot>((*static_cast<void***>(object))[index])(object, a, b, c, d, e, f, g); +} +bool ok(Word hr) { return SUCCEEDED(static_cast<HRESULT>(hr)); } + +constexpr UINT console_d16_s8 = 118; +} // namespace + +int main(int argc, char** argv) +{ + if (argc != 2) return 2; + ComPtr<IDXGIFactory6> factory; + if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 3; + ComPtr<IDXGIAdapter> adapter; + if (std::strcmp(argv[1], "hardware") == 0) { + for (UINT n = 0;; ++n) { + ComPtr<IDXGIAdapter1> candidate; + const HRESULT hr = factory->EnumAdapterByGpuPreference(n, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&candidate)); + if (hr == DXGI_ERROR_NOT_FOUND) return 77; + if (FAILED(hr)) return 3; + DXGI_ADAPTER_DESC1 desc{}; + if (FAILED(candidate->GetDesc1(&desc))) return 3; + if (!(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) && + SUCCEEDED(D3D12CreateDevice(candidate.Get(), D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), nullptr))) { + adapter = candidate; + break; + } + } + } else if (std::strcmp(argv[1], "warp") != 0 || FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter)))) { + return 3; + } + DXGI_ADAPTER_DESC adapter_desc{}; + if (FAILED(adapter->GetDesc(&adapter_desc))) return 3; + std::printf("adapter=%ls\n", adapter_desc.Description); + + std::array<unsigned char, 64> parameters{}; + void* device = nullptr; + if (FAILED(D3D12XboxCreateDevice(adapter.Get(), parameters.data(), __uuidof(ID3D12Device), &device))) return 4; + ComPtr<ID3D12Device> desktop; + if (FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&desktop)))) return 4; + + ComPtr<ID3D12InfoQueue> info; + const bool has_layer = SUCCEEDED(desktop.As(&info)); + if (has_layer) info->ClearStoredMessages(); + + const D3D12_RESOURCE_DESC depth_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 16, 16, 1, 1, static_cast<DXGI_FORMAT>(console_d16_s8), + {1, 0}, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL}; + D3D12_CLEAR_VALUE clear{}; + clear.Format = static_cast<DXGI_FORMAT>(console_d16_s8); + clear.DepthStencil.Depth = 1.0f; + + // Slot 133, placed on title memory: a texture is a committed stand-in. + static std::array<std::uint8_t, 65536 + 4096> memory{}; + const Word address = (reinterpret_cast<Word>(memory.data()) + 0xffff) & ~Word{0xffff}; + void* placed = nullptr; + if (!ok(invoke(device, 133, address, arg(&depth_desc), D3D12_RESOURCE_STATE_COMMON, arg(&clear), arg(&__uuidof(ID3D12Resource)), + arg(&placed))) || !placed) + return 10; + std::printf("slot 133: depth texture with a clear value created\n"); + + // Slot 27, desktop order (props, flags, desc, state, clear, riid, ppv). + const D3D12_HEAP_PROPERTIES props{D3D12_HEAP_TYPE_DEFAULT}; + void* committed = nullptr; + if (!ok(invoke(device, 27, arg(&props), D3D12_HEAP_FLAG_NONE, arg(&depth_desc), D3D12_RESOURCE_STATE_COMMON, arg(&clear), + arg(&__uuidof(ID3D12Resource)), arg(&committed))) || !committed) + return 11; + std::printf("slot 27: depth texture with a clear value created\n"); + + if (desktop->GetDeviceRemovedReason() != S_OK) return 12; + if (!has_layer) { + std::printf("debug layer not installed: message check skipped\n"); + return 77; + } + UINT64 errors = 0, clear_value_messages = 0; + for (UINT64 i = 0, n = info->GetNumStoredMessages(); i < n; ++i) { ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Check slot-133 diagnostics before slot 27 drains the queue** With `X2W_D3D12_DEBUG=1` enabled by these CTests, the preceding slot-27 call runs `create_slot()` → `check_device()` (`d3d12_xs_device.cpp:747`), which clears the shared info queue at line 373 before this inspection. If the slot-133 mapping is removed or bypassed, its existing retry without a clear value still succeeds, slot 27 erases the resulting 816/817 diagnostics, and this fixture incorrectly passes. Inspect the messages immediately after slot 133 or capture them through a callback, and add an unmapped-clear negative control to verify that the fallback cannot satisfy the test. AGENTS.md reference: [AGENTS.md:L235-L235](https://github.com/R0Y00/Xbox2Windows/blob/cd3008fb489242a57c2ae8e39fa345bf8c20d9f9/AGENTS.md#L235-L235) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 12:01:23 +00:00 (Migrated from github.com)

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

Review: COMMENTED


No description provided.

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

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

Code review location: tests/startup_clear_format.cpp; line 105

@@ -0,0 +1,122 @@
+// A depth texture of console format 118 (D16_UNORM_S8_UINT) created with a clear value, through device slots
+// 133 and 27, must be accepted by desktop D3D12 on the first attempt: the clear value carries the mapped format,
+// so the debug layer stores no message for an invalid clear value (ids 816 and 817).
+//
+//   startup_clear_format <warp|hardware>     (X2W_D3D12_PERMISSIVE=1 X2W_D3D12_LIST_NOOP=1 X2W_D3D12_RENDER=1 X2W_D3D12_DEBUG=1)
+//
+// Both creations must return success and an object. Then the debug layer's stored messages are read: none may
+// be an error, and none may carry id 816 or 817. When the debug layer is not installed the creations are still
+// checked and the test reports a skip (77) for the message part.
+//
+// Exit codes: 0 pass, 77 no physical adapter or no debug layer, other values name the failing step.
+#include <d3d12.h>
+#include <d3d12sdklayers.h>
+#include <dxgi1_6.h>
+#include <wrl/client.h>
+
+#include <array>
+#include <cstdint>
+#include <cstdio>
+#include <cstring>
+#include <vector>
+
+using Microsoft::WRL::ComPtr;
+extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**);
+
+namespace {
+using Word = std::uint64_t;
+template <class T> Word arg(T* value) { return reinterpret_cast<Word>(value); }
+Word invoke(void* object, unsigned index, Word a = 0, Word b = 0, Word c = 0, Word d = 0, Word e = 0, Word f = 0, Word g = 0)
+{
+    using Slot = Word (WINAPI*)(void*, Word, Word, Word, Word, Word, Word, Word);
+    return reinterpret_cast<Slot>((*static_cast<void***>(object))[index])(object, a, b, c, d, e, f, g);
+}
+bool ok(Word hr) { return SUCCEEDED(static_cast<HRESULT>(hr)); }
+
+constexpr UINT console_d16_s8 = 118;
+}  // namespace
+
+int main(int argc, char** argv)
+{
+    if (argc != 2) return 2;
+    ComPtr<IDXGIFactory6> factory;
+    if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 3;
+    ComPtr<IDXGIAdapter> adapter;
+    if (std::strcmp(argv[1], "hardware") == 0) {
+        for (UINT n = 0;; ++n) {
+            ComPtr<IDXGIAdapter1> candidate;
+            const HRESULT hr = factory->EnumAdapterByGpuPreference(n, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&candidate));
+            if (hr == DXGI_ERROR_NOT_FOUND) return 77;
+            if (FAILED(hr)) return 3;
+            DXGI_ADAPTER_DESC1 desc{};
+            if (FAILED(candidate->GetDesc1(&desc))) return 3;
+            if (!(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) &&
+                SUCCEEDED(D3D12CreateDevice(candidate.Get(), D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), nullptr))) {
+                adapter = candidate;
+                break;
+            }
+        }
+    } else if (std::strcmp(argv[1], "warp") != 0 || FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter)))) {
+        return 3;
+    }
+    DXGI_ADAPTER_DESC adapter_desc{};
+    if (FAILED(adapter->GetDesc(&adapter_desc))) return 3;
+    std::printf("adapter=%ls\n", adapter_desc.Description);
+
+    std::array<unsigned char, 64> parameters{};
+    void* device = nullptr;
+    if (FAILED(D3D12XboxCreateDevice(adapter.Get(), parameters.data(), __uuidof(ID3D12Device), &device))) return 4;
+    ComPtr<ID3D12Device> desktop;
+    if (FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&desktop)))) return 4;
+
+    ComPtr<ID3D12InfoQueue> info;
+    const bool has_layer = SUCCEEDED(desktop.As(&info));
+    if (has_layer) info->ClearStoredMessages();
+
+    const D3D12_RESOURCE_DESC depth_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 16, 16, 1, 1, static_cast<DXGI_FORMAT>(console_d16_s8),
+                                         {1, 0}, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL};
+    D3D12_CLEAR_VALUE clear{};
+    clear.Format = static_cast<DXGI_FORMAT>(console_d16_s8);
+    clear.DepthStencil.Depth = 1.0f;
+
+    // Slot 133, placed on title memory: a texture is a committed stand-in.
+    static std::array<std::uint8_t, 65536 + 4096> memory{};
+    const Word address = (reinterpret_cast<Word>(memory.data()) + 0xffff) & ~Word{0xffff};
+    void* placed = nullptr;
+    if (!ok(invoke(device, 133, address, arg(&depth_desc), D3D12_RESOURCE_STATE_COMMON, arg(&clear), arg(&__uuidof(ID3D12Resource)),
+                   arg(&placed))) || !placed)
+        return 10;
+    std::printf("slot 133: depth texture with a clear value created\n");
+
+    // Slot 27, desktop order (props, flags, desc, state, clear, riid, ppv).
+    const D3D12_HEAP_PROPERTIES props{D3D12_HEAP_TYPE_DEFAULT};
+    void* committed = nullptr;
+    if (!ok(invoke(device, 27, arg(&props), D3D12_HEAP_FLAG_NONE, arg(&depth_desc), D3D12_RESOURCE_STATE_COMMON, arg(&clear),
+                   arg(&__uuidof(ID3D12Resource)), arg(&committed))) || !committed)
+        return 11;
+    std::printf("slot 27: depth texture with a clear value created\n");
+
+    if (desktop->GetDeviceRemovedReason() != S_OK) return 12;
+    if (!has_layer) {
+        std::printf("debug layer not installed: message check skipped\n");
+        return 77;
+    }
+    UINT64 errors = 0, clear_value_messages = 0;
+    for (UINT64 i = 0, n = info->GetNumStoredMessages(); i < n; ++i) {

Addressed at 745d2ffcfc, in tests/startup_clear_format.cpp:

  • The debug layer messages are now read and cleared right after the slot 133 creation, before slot 27 runs (which clears the shared queue). Slot 27 is read right after its own creation. Both results are checked for ids 816/817 and for errors.
  • A negative control sends the unmapped clear value (console format 118) straight to desktop D3D12 and requires it to be rejected with a debug layer message; otherwise the test exits 14. So the checks can fail on the defect and the retry without a clear value cannot hide it.

Verification (Win2025, default 3-slot pool): python3 x2w_pipe.py win2025 2019 --force on 745d2ffc, dev and release ctest phases both 26/26 passed. Capability skip, reported separately and not a pass: startup_clear_format_warp returned 77 in both phases, because the debug layer is not installed on that machine, so the new message checks and the negative control did not execute there. Linux: git diff --check clean.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4694275537 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019#discussion_r4694275537). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:34:23Z. **Code review location:** `tests/startup_clear_format.cpp`; line 105 ~~~~diff @@ -0,0 +1,122 @@ +// A depth texture of console format 118 (D16_UNORM_S8_UINT) created with a clear value, through device slots +// 133 and 27, must be accepted by desktop D3D12 on the first attempt: the clear value carries the mapped format, +// so the debug layer stores no message for an invalid clear value (ids 816 and 817). +// +// startup_clear_format <warp|hardware> (X2W_D3D12_PERMISSIVE=1 X2W_D3D12_LIST_NOOP=1 X2W_D3D12_RENDER=1 X2W_D3D12_DEBUG=1) +// +// Both creations must return success and an object. Then the debug layer's stored messages are read: none may +// be an error, and none may carry id 816 or 817. When the debug layer is not installed the creations are still +// checked and the test reports a skip (77) for the message part. +// +// Exit codes: 0 pass, 77 no physical adapter or no debug layer, other values name the failing step. +#include <d3d12.h> +#include <d3d12sdklayers.h> +#include <dxgi1_6.h> +#include <wrl/client.h> + +#include <array> +#include <cstdint> +#include <cstdio> +#include <cstring> +#include <vector> + +using Microsoft::WRL::ComPtr; +extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**); + +namespace { +using Word = std::uint64_t; +template <class T> Word arg(T* value) { return reinterpret_cast<Word>(value); } +Word invoke(void* object, unsigned index, Word a = 0, Word b = 0, Word c = 0, Word d = 0, Word e = 0, Word f = 0, Word g = 0) +{ + using Slot = Word (WINAPI*)(void*, Word, Word, Word, Word, Word, Word, Word); + return reinterpret_cast<Slot>((*static_cast<void***>(object))[index])(object, a, b, c, d, e, f, g); +} +bool ok(Word hr) { return SUCCEEDED(static_cast<HRESULT>(hr)); } + +constexpr UINT console_d16_s8 = 118; +} // namespace + +int main(int argc, char** argv) +{ + if (argc != 2) return 2; + ComPtr<IDXGIFactory6> factory; + if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return 3; + ComPtr<IDXGIAdapter> adapter; + if (std::strcmp(argv[1], "hardware") == 0) { + for (UINT n = 0;; ++n) { + ComPtr<IDXGIAdapter1> candidate; + const HRESULT hr = factory->EnumAdapterByGpuPreference(n, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&candidate)); + if (hr == DXGI_ERROR_NOT_FOUND) return 77; + if (FAILED(hr)) return 3; + DXGI_ADAPTER_DESC1 desc{}; + if (FAILED(candidate->GetDesc1(&desc))) return 3; + if (!(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) && + SUCCEEDED(D3D12CreateDevice(candidate.Get(), D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), nullptr))) { + adapter = candidate; + break; + } + } + } else if (std::strcmp(argv[1], "warp") != 0 || FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter)))) { + return 3; + } + DXGI_ADAPTER_DESC adapter_desc{}; + if (FAILED(adapter->GetDesc(&adapter_desc))) return 3; + std::printf("adapter=%ls\n", adapter_desc.Description); + + std::array<unsigned char, 64> parameters{}; + void* device = nullptr; + if (FAILED(D3D12XboxCreateDevice(adapter.Get(), parameters.data(), __uuidof(ID3D12Device), &device))) return 4; + ComPtr<ID3D12Device> desktop; + if (FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&desktop)))) return 4; + + ComPtr<ID3D12InfoQueue> info; + const bool has_layer = SUCCEEDED(desktop.As(&info)); + if (has_layer) info->ClearStoredMessages(); + + const D3D12_RESOURCE_DESC depth_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 16, 16, 1, 1, static_cast<DXGI_FORMAT>(console_d16_s8), + {1, 0}, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL}; + D3D12_CLEAR_VALUE clear{}; + clear.Format = static_cast<DXGI_FORMAT>(console_d16_s8); + clear.DepthStencil.Depth = 1.0f; + + // Slot 133, placed on title memory: a texture is a committed stand-in. + static std::array<std::uint8_t, 65536 + 4096> memory{}; + const Word address = (reinterpret_cast<Word>(memory.data()) + 0xffff) & ~Word{0xffff}; + void* placed = nullptr; + if (!ok(invoke(device, 133, address, arg(&depth_desc), D3D12_RESOURCE_STATE_COMMON, arg(&clear), arg(&__uuidof(ID3D12Resource)), + arg(&placed))) || !placed) + return 10; + std::printf("slot 133: depth texture with a clear value created\n"); + + // Slot 27, desktop order (props, flags, desc, state, clear, riid, ppv). + const D3D12_HEAP_PROPERTIES props{D3D12_HEAP_TYPE_DEFAULT}; + void* committed = nullptr; + if (!ok(invoke(device, 27, arg(&props), D3D12_HEAP_FLAG_NONE, arg(&depth_desc), D3D12_RESOURCE_STATE_COMMON, arg(&clear), + arg(&__uuidof(ID3D12Resource)), arg(&committed))) || !committed) + return 11; + std::printf("slot 27: depth texture with a clear value created\n"); + + if (desktop->GetDeviceRemovedReason() != S_OK) return 12; + if (!has_layer) { + std::printf("debug layer not installed: message check skipped\n"); + return 77; + } + UINT64 errors = 0, clear_value_messages = 0; + for (UINT64 i = 0, n = info->GetNumStoredMessages(); i < n; ++i) { ~~~~ --- Addressed at 745d2ffcfccd79cec55dc3a4a223fddcf4bacabc, in tests/startup_clear_format.cpp: - The debug layer messages are now read and cleared right after the slot 133 creation, before slot 27 runs (which clears the shared queue). Slot 27 is read right after its own creation. Both results are checked for ids 816/817 and for errors. - A negative control sends the unmapped clear value (console format 118) straight to desktop D3D12 and requires it to be rejected with a debug layer message; otherwise the test exits 14. So the checks can fail on the defect and the retry without a clear value cannot hide it. Verification (Win2025, default 3-slot pool): `python3 x2w_pipe.py win2025 2019 --force` on 745d2ffc, dev and release ctest phases both 26/26 passed. Capability skip, reported separately and not a pass: `startup_clear_format_warp` returned 77 in both phases, because the debug layer is not installed on that machine, so the new message checks and the negative control did not execute there. Linux: `git diff --check` clean. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 14:04:26 +00:00
Makto94 commented 2026-11-25 14:05:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T13:17:50Z.


Debug-layer run for head 745d2ffc, on a host that has the D3D12 debug layer (the Win2025 VM did not, so startup_clear_format_warp returned 77 there).

Environment: NVIDIA GeForce RTX 3070 Ti (10de:2482), driver 32.0.16.2101, Windows 11 build 26300.9974, Debug build, x2w-d3d12 debug layer: 0x00000000 enabled in the logs, serial (-j1); the hardware run was on an idle machine; 0 capability skips (77).

Commands: ctest --preset dev --no-tests=error -j1 -R 'clear_format|clear_value_format' -E '_hardware$' -V (4/4 passed) and ctest --preset dev --no-tests=error -j1 -R '^startup_clear_format_hardware$' -V (passed). The four non-hardware tests: startup_clear_value_format, startup_clear_value_format_d16_control, startup_clear_value_format_values_control, startup_clear_format_warp.

Both startup_clear_format_warp and startup_clear_format_hardware (RTX) print the lines below; the 817 text names feature level 12_1 in the WARP log and 12_2 in the RTX log:

  • negative control (unmapped clear value): clear value messages (816, 817): 2, debug layer errors: 2, with debug layer 816: ... D3D12_CLEAR_VALUE::Format is unrecognized. The value is 118. and debug layer 817: ... D3D12_CLEAR_VALUE::Format is not supported at the current feature level. Format = Unrecognized ...
  • slot 133: clear value messages (816, 817): 0, debug layer errors: 0
  • slot 27: clear value messages (816, 817): 0, debug layer errors: 0

So the checks run with the layer on, the unmapped format raises 816 and 817, and the mapped slots 133 and 27 produce no 816/817. This provides the previously unconfirmed debug-layer message check on a host with the layer. The author's reply says the slot-27 queue-drain point was addressed at 745d2ffc; this run shows the fixture passes at that head, not that it fails without the change. It is one adapter and one driver.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163572771 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019#issuecomment-7163572771). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-25T13:17:50Z. --- Debug-layer run for head `745d2ffc`, on a host that has the D3D12 debug layer (the Win2025 VM did not, so `startup_clear_format_warp` returned 77 there). Environment: NVIDIA GeForce RTX 3070 Ti (`10de:2482`), driver 32.0.16.2101, Windows 11 build 26300.9974, Debug build, `x2w-d3d12 debug layer: 0x00000000 enabled` in the logs, serial (`-j1`); the hardware run was on an idle machine; 0 capability skips (77). Commands: `ctest --preset dev --no-tests=error -j1 -R 'clear_format|clear_value_format' -E '_hardware$' -V` (4/4 passed) and `ctest --preset dev --no-tests=error -j1 -R '^startup_clear_format_hardware$' -V` (passed). The four non-hardware tests: `startup_clear_value_format`, `startup_clear_value_format_d16_control`, `startup_clear_value_format_values_control`, `startup_clear_format_warp`. Both `startup_clear_format_warp` and `startup_clear_format_hardware` (RTX) print the lines below; the 817 text names feature level 12_1 in the WARP log and 12_2 in the RTX log: - `negative control (unmapped clear value): clear value messages (816, 817): 2, debug layer errors: 2`, with `debug layer 816: ... D3D12_CLEAR_VALUE::Format is unrecognized. The value is 118.` and `debug layer 817: ... D3D12_CLEAR_VALUE::Format is not supported at the current feature level. Format = Unrecognized ...` - `slot 133: clear value messages (816, 817): 0, debug layer errors: 0` - `slot 27: clear value messages (816, 817): 0, debug layer errors: 0` So the checks run with the layer on, the unmapped format raises 816 and 817, and the mapped slots 133 and 27 produce no 816/817. This provides the previously unconfirmed debug-layer message check on a host with the layer. The author's reply says the slot-27 queue-drain point was addressed at `745d2ffc`; this run shows the fixture passes at that head, not that it fails without the change. It is one adapter and one driver.
tedin7 commented 2026-11-25 14:05:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:45:09Z.


Thanks for the debug-layer run.

You ran head 745d2ffc, which is also the current head of this PR. All 4 non-hardware tests and startup_clear_format_hardware passed, with no capability skips (77).

What it means for the PR:

  • The 816/817 check now has real evidence on a host with the D3D12 debug layer (the Win2025 VM has no layer, so startup_clear_format_warp returns 77 there).
  • The unmapped clear value raises 816 and 817, and the mapped slots 133 and 27 raise none.
  • As you noted, this shows the fixture passes at this head. It does not show it fails without the change. It is also one adapter and one driver.

No code change is needed. No new commit.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164237205 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019#issuecomment-7164237205). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:45:09Z. --- Thanks for the debug-layer run. You ran head `745d2ffc`, which is also the current head of this PR. All 4 non-hardware tests and `startup_clear_format_hardware` passed, with no capability skips (77). What it means for the PR: - The 816/817 check now has real evidence on a host with the D3D12 debug layer (the Win2025 VM has no layer, so `startup_clear_format_warp` returns 77 there). - The unmapped clear value raises 816 and 817, and the mapped slots 133 and 27 raise none. - As you noted, this shows the fixture passes at this head. It does not show it fails without the change. It is also one adapter and one driver. No code change is needed. No new commit. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 14:05:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:51:13Z.


Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164385378 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2019#issuecomment-7164385378). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:51:13Z. --- Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is. We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here. AI-assisted; commands listed were executed locally.

Pull request closed

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!2012
No description provided.