startup: guard out-of-range descriptor heap type in slot 15 GetDescriptorHandleIncrementSize #1952

Merged
tedin7 merged 4 commits from upstream-pr/1959 into main 2026-11-24 22:49:22 +00:00
tedin7 commented 2026-11-24 22:09:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:09:32Z.


Part of #870

What this unblocks: startup device slot 15 (GetDescriptorHandleIncrementSize) answers 0 for heap types desktop does not have, instead of tripping the debug layer, so startup gets past descriptor heap setup.

Changes:

  • src/startup_stubs/d3d12_xs_device.cpp: new slot 15 handler. Valid types are forwarded as before. Out-of-range types are logged once and return 0.
  • src/startup_stubs/descriptor_heap_type.h: valid desktop heap type check.
  • tests/startup_descriptor_heap_type_check.cpp, tests/startup_descriptor_increment.cpp: tests for both.

Verification:

  • git diff --check origin/main: clean (executed locally on Linux).
  • Win2025 build and test commands: NOT yet run for this branch. To be added here before review.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6592399962 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1959). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:09:32Z. --- Part of #870 What this unblocks: startup device slot 15 (`GetDescriptorHandleIncrementSize`) answers 0 for heap types desktop does not have, instead of tripping the debug layer, so startup gets past descriptor heap setup. Changes: - `src/startup_stubs/d3d12_xs_device.cpp`: new slot 15 handler. Valid types are forwarded as before. Out-of-range types are logged once and return 0. - `src/startup_stubs/descriptor_heap_type.h`: valid desktop heap type check. - `tests/startup_descriptor_heap_type_check.cpp`, `tests/startup_descriptor_increment.cpp`: tests for both. Verification: - `git diff --check origin/main`: clean (executed locally on Linux). - Win2025 build and test commands: NOT yet run for this branch. To be added here before review. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 23:03:16 +00:00
R0Y00 commented 2026-11-24 23:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T22:19:12Z.

Review: CHANGES_REQUESTED


The slot handler keeps normal D3D12 values on the existing forward path. I found two new test sources, but neither is registered in CMake. Please wire the helper and its negative controls, and register the guest-device comparison with the existing WARP/hardware conventions. That should exercise all four native increments and the zero result for an out-of-range UINT on the actual slot.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048304266 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1959#pullrequestreview-6048304266). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T22:19:12Z. **Review:** CHANGES_REQUESTED --- The slot handler keeps normal D3D12 values on the existing forward path. I found two new test sources, but neither is registered in CMake. Please wire the helper and its negative controls, and register the guest-device comparison with the existing WARP/hardware conventions. That should exercise all four native increments and the zero result for an out-of-range UINT on the actual slot.
R0Y00 commented 2026-11-24 23:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T22:48:47Z.

Review: APPROVED


The missing CMake registrations are in place. On 5ac154f9 the Windows Release run passed all five cases, including WARP, physical NVIDIA and both control tests.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048617085 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1959#pullrequestreview-6048617085). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T22:48:47Z. **Review:** APPROVED --- The missing CMake registrations are in place. On 5ac154f9 the Windows Release run passed all five cases, including WARP, physical NVIDIA and both control tests.
chatgpt-codex-connector[bot commented 2026-11-24 23:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T22:53:30Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ac154f9ff

ℹ️ 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:6048665884 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1959#pullrequestreview-6048665884). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T22:53:30Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `5ac154f9ff` <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>
chatgpt-codex-connector[bot commented 2026-11-24 23:03:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T22:48:45Z.


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-24T22:53:32.302200Z 5ac154f 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:7146672669 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1959#issuecomment-7146672669). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T22:48:45Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"5ac154f9ffe75871a71b765fbfada3bb42e04faa","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-24T22:53:32.302200Z">2026-11-24T22:53:32.302200Z</relative-time> | `5ac154f` | 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-24 23:03:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T22:53:30Z.

Code review location: tests/startup_descriptor_increment.cpp; line 91

@@ -0,0 +1,107 @@
+// Device slot 15, GetDescriptorHandleIncrementSize (#870), through D3D12XboxCreateDevice.
+//
+//   startup_descriptor_increment <warp|hardware>     (X2W_D3D12_PERMISSIVE=1 X2W_D3D12_DEBUG=1)
+//
+// The four types desktop has (0 to 3) must answer what a desktop device answers on the same adapter, and each answer
+// must be above zero. A value past them (4, and 0xFFFFFFFF with the upper register bits set) must answer 0, as desktop
+// does, and the desktop debug layer must store no error for any of the calls: desktop itself reports an error for such
+// a value, so a stand-in that forwards it fails here.
+//
+// Exit codes: 0 pass, 77 no physical adapter, 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;
+// Slot 15 of the device with the type in the first argument word; the upper word bits are set on purpose, as a
+// caller leaves the top half of a 32-bit argument undefined.
+UINT increment_size(void* device, std::uint32_t type, Word upper)
+{
+    using Slot = UINT(WINAPI*)(void*, Word);
+    return reinterpret_cast<Slot>((*static_cast<void***>(device))[15])(device, upper | type);
+}
+}  // 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;
+    desktop.As(&info);
+    if (info) info->ClearStoredMessages();
+
+    int failed = 0;
+    for (std::uint32_t type = 0; type < D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++type) {
+        const UINT want = desktop->GetDescriptorHandleIncrementSize(static_cast<D3D12_DESCRIPTOR_HEAP_TYPE>(type));
+        const UINT got = increment_size(device, type, 0xFFFFFFFF00000000ull);
+        std::printf("type %u: %u (desktop %u)\n", type, got, want);
+        if (got != want || got == 0) {
+            std::printf("FAIL type %u\n", type);
+            failed |= 1;
+        }
+    }
+    for (std::uint32_t type : {4u, 0xFFFFFFFFu}) {
+        const UINT got = increment_size(device, type, 0);
+        std::printf("type 0x%x: %u (expected 0)\n", type, got);
+        if (got != 0) {
+            std::printf("FAIL type 0x%x\n", type);
+            failed |= 2;
+        }
+    }
+    if (info) {
+        for (UINT64 i = 0, n = info->GetNumStoredMessages(); i < n; ++i) {

P1 Badge Capture debug errors before the shim clears the queue

If slot 15 regresses to the original forwarder, the configured X2W_D3D12_DEBUG=1 (CMakeLists.txt:426-427) causes forward_slot() to invoke check_device(), which logs and clears the debug queue before returning (src/startup_stubs/d3d12_xs_device.cpp:359,636). The invalid types still return 0, and this loop sees an empty queue, so the integration test reports success for the exact pre-fix behavior it claims to reject. Observe errors through a message callback or the shim log, and add a forwarding negative control, following the new-fixture confirmation requirement in AGENTS.md, to demonstrate that the pre-fix behavior fails.

AGENTS.md reference: AGENTS.md:L192-L192

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4687636587 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1959#discussion_r4687636587). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T22:53:30Z. **Code review location:** `tests/startup_descriptor_increment.cpp`; line 91 ~~~~diff @@ -0,0 +1,107 @@ +// Device slot 15, GetDescriptorHandleIncrementSize (#870), through D3D12XboxCreateDevice. +// +// startup_descriptor_increment <warp|hardware> (X2W_D3D12_PERMISSIVE=1 X2W_D3D12_DEBUG=1) +// +// The four types desktop has (0 to 3) must answer what a desktop device answers on the same adapter, and each answer +// must be above zero. A value past them (4, and 0xFFFFFFFF with the upper register bits set) must answer 0, as desktop +// does, and the desktop debug layer must store no error for any of the calls: desktop itself reports an error for such +// a value, so a stand-in that forwards it fails here. +// +// Exit codes: 0 pass, 77 no physical adapter, 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; +// Slot 15 of the device with the type in the first argument word; the upper word bits are set on purpose, as a +// caller leaves the top half of a 32-bit argument undefined. +UINT increment_size(void* device, std::uint32_t type, Word upper) +{ + using Slot = UINT(WINAPI*)(void*, Word); + return reinterpret_cast<Slot>((*static_cast<void***>(device))[15])(device, upper | type); +} +} // 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; + desktop.As(&info); + if (info) info->ClearStoredMessages(); + + int failed = 0; + for (std::uint32_t type = 0; type < D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++type) { + const UINT want = desktop->GetDescriptorHandleIncrementSize(static_cast<D3D12_DESCRIPTOR_HEAP_TYPE>(type)); + const UINT got = increment_size(device, type, 0xFFFFFFFF00000000ull); + std::printf("type %u: %u (desktop %u)\n", type, got, want); + if (got != want || got == 0) { + std::printf("FAIL type %u\n", type); + failed |= 1; + } + } + for (std::uint32_t type : {4u, 0xFFFFFFFFu}) { + const UINT got = increment_size(device, type, 0); + std::printf("type 0x%x: %u (expected 0)\n", type, got); + if (got != 0) { + std::printf("FAIL type 0x%x\n", type); + failed |= 2; + } + } + if (info) { + for (UINT64 i = 0, n = info->GetNumStoredMessages(); i < n; ++i) { ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Capture debug errors before the shim clears the queue** If slot 15 regresses to the original forwarder, the configured `X2W_D3D12_DEBUG=1` (`CMakeLists.txt:426-427`) causes `forward_slot()` to invoke `check_device()`, which logs and clears the debug queue before returning (`src/startup_stubs/d3d12_xs_device.cpp:359,636`). The invalid types still return 0, and this loop sees an empty queue, so the integration test reports success for the exact pre-fix behavior it claims to reject. Observe errors through a message callback or the shim log, and add a forwarding negative control, following the new-fixture confirmation requirement in `AGENTS.md`, to demonstrate that the pre-fix behavior fails. AGENTS.md reference: [AGENTS.md:L192-L192](https://github.com/R0Y00/Xbox2Windows/blob/5ac154f9ffe75871a71b765fbfada3bb42e04faa/AGENTS.md#L192-L192) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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!1952
No description provided.