startup: repair invalid D3D12 calls that flood the debug layer #3197

Open
tedin7 wants to merge 7 commits from upstream-pr/3197 into main
tedin7 commented 2026-11-27 21:27:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T21:27:58Z.


Part of #870

What this unblocks: runs with X2W_D3D12_DEBUG=1 keep the debug-layer log for real errors instead of filling it with repeated rejections of invalid calls the shim forwards.

The startup device shim forwards several console requests that desktop D3D12 rejects, each with a debug-layer error (and the log budget of 400 lines ran out on them). This change repairs them before the desktop call:

  • Optimized clear values (ID3D12Device::CreateCommittedResource / CreatePlacedResource, D3D12_CLEAR_VALUE): dropped for buffers, for textures without render-target or depth-stencil use, for typeless formats and for a colour/depth kind mismatch; a depth clear outside [0, 1] is clamped. Applied at device slots 27/29, the committed-resource path and the title-memory texture path (optimized_clear_value.h).
  • ID3D12Resource::Map on a DEFAULT heap, or a CUSTOM heap with D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE, answers E_INVALIDARG without the call. Unmap is forwarded only against a counted successful desktop Map of that subresource.
  • Descriptor heaps (descriptor_heap_rules.h): shader-visible CBV/SRV/UAV heaps are clamped to 1,000,000 descriptors and sampler heaps to 2048, the counts every Resource Binding tier guarantees ("Hardware Tiers"); the rest uses the existing CPU-only tail heap and title memory. RTV/DSV heaps drop SHADER_VISIBLE ("Descriptor Heaps Overview"). The driver probe now starts at 1,000,000.
  • Debug drain budget (debug_drain_budget.h): 4000 error/corruption lines plus 400 others, at most 32 lines per message id, then one "repeated N times" line at each power of two.

Tests:

  • startup_debug_noise_check (pure): Map counting, every clear-value drop/clamp case, heap repairs, drain budget.
  • startup_debug_noise_device_warp / _hardware (debug layer on, ID3D12InfoQueue1 callback): creates a non-target texture with a clear value, a D32 target with depth 2.0, a buffer with a clear value, maps/unmaps a DEFAULT-heap texture, and creates a 1,048,577-descriptor view heap, a 4096 sampler heap and a shader-visible RTV heap through the shim. Passes only with zero debug-layer errors and no device removal; on main the invalid calls reach the runtime.

Verification:

  • cmake -S . -B /tmp/up-debug-noise-cfg -G Ninja -DDXC_EXECUTABLE=/bin/true -> configure OK
  • x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_debug_noise_check.cpp -> OK
  • x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_debug_noise_device.cpp -> OK
  • python3 tests/bidi_controls_check.py -> OK; python3 tests/startup_build_rev_check.py -> OK
  • Win2025 WARP, exact head 99cc8de8 (pull/3197/head), dev and release legs in parallel: x2w_pipe.py win2025 3197 --targets startup_debug_noise_check,startup_debug_noise_device,startup_view_heap_check,startup_descriptor_increment,startup_title_heap_check,startup_resource_desc,startup_clear_depth_stencil,startup_clear_uav,startup_committed_heap_state_check,startup_descriptor_heap_type_check --regex '^startup_(debug_noise_.*|view_heap_.*|descriptor_.*|title_heap.*|resource_desc_.*|clear_depth_stencil_.*|clear_uav_.*|committed_heap_state.*)$' --force
    • dev: 21/23 passed, startup_view_heap_warp / _hardware skipped (77: this adapter accepts the oversized heap directly)
    • release /O2: 21/23 passed, same two skips
  • Mutant (Map forwarded on a DEFAULT heap again), dev: startup_debug_noise_device_warp fails with errors: 1 as required

Draft until an independent peer review and the Win2025 WARP gate pass.

Thanks to @Makto94 for the testing that found this.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5533306623 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:27:58Z. --- Part of #870 What this unblocks: runs with `X2W_D3D12_DEBUG=1` keep the debug-layer log for real errors instead of filling it with repeated rejections of invalid calls the shim forwards. The startup device shim forwards several console requests that desktop D3D12 rejects, each with a debug-layer error (and the log budget of 400 lines ran out on them). This change repairs them before the desktop call: - Optimized clear values (`ID3D12Device::CreateCommittedResource` / `CreatePlacedResource`, `D3D12_CLEAR_VALUE`): dropped for buffers, for textures without render-target or depth-stencil use, for typeless formats and for a colour/depth kind mismatch; a depth clear outside [0, 1] is clamped. Applied at device slots 27/29, the committed-resource path and the title-memory texture path (`optimized_clear_value.h`). - `ID3D12Resource::Map` on a DEFAULT heap, or a CUSTOM heap with `D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE`, answers `E_INVALIDARG` without the call. `Unmap` is forwarded only against a counted successful desktop `Map` of that subresource. - Descriptor heaps (`descriptor_heap_rules.h`): shader-visible CBV/SRV/UAV heaps are clamped to 1,000,000 descriptors and sampler heaps to 2048, the counts every Resource Binding tier guarantees ("Hardware Tiers"); the rest uses the existing CPU-only tail heap and title memory. RTV/DSV heaps drop `SHADER_VISIBLE` ("Descriptor Heaps Overview"). The driver probe now starts at 1,000,000. - Debug drain budget (`debug_drain_budget.h`): 4000 error/corruption lines plus 400 others, at most 32 lines per message id, then one "repeated N times" line at each power of two. Tests: - `startup_debug_noise_check` (pure): Map counting, every clear-value drop/clamp case, heap repairs, drain budget. - `startup_debug_noise_device_warp` / `_hardware` (debug layer on, `ID3D12InfoQueue1` callback): creates a non-target texture with a clear value, a D32 target with depth 2.0, a buffer with a clear value, maps/unmaps a DEFAULT-heap texture, and creates a 1,048,577-descriptor view heap, a 4096 sampler heap and a shader-visible RTV heap through the shim. Passes only with zero debug-layer errors and no device removal; on main the invalid calls reach the runtime. Verification: - `cmake -S . -B /tmp/up-debug-noise-cfg -G Ninja -DDXC_EXECUTABLE=/bin/true` -> configure OK - `x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_debug_noise_check.cpp` -> OK - `x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_debug_noise_device.cpp` -> OK - `python3 tests/bidi_controls_check.py` -> OK; `python3 tests/startup_build_rev_check.py` -> OK - Win2025 WARP, exact head `99cc8de8` (`pull/3197/head`), dev and release legs in parallel: `x2w_pipe.py win2025 3197 --targets startup_debug_noise_check,startup_debug_noise_device,startup_view_heap_check,startup_descriptor_increment,startup_title_heap_check,startup_resource_desc,startup_clear_depth_stencil,startup_clear_uav,startup_committed_heap_state_check,startup_descriptor_heap_type_check --regex '^startup_(debug_noise_.*|view_heap_.*|descriptor_.*|title_heap.*|resource_desc_.*|clear_depth_stencil_.*|clear_uav_.*|committed_heap_state.*)$' --force` - dev: 21/23 passed, `startup_view_heap_warp` / `_hardware` skipped (77: this adapter accepts the oversized heap directly) - release `/O2`: 21/23 passed, same two skips - Mutant (Map forwarded on a DEFAULT heap again), dev: `startup_debug_noise_device_warp` fails with `errors: 1` as required Draft until an independent peer review and the Win2025 WARP gate pass. Thanks to @Makto94 for the testing that found this. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-27 21:39:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T21:39:43Z.

Review: COMMENTED


Draft review: the new resource_maps entries are removed only after matching Unmaps. D3D12 permits a CPU-accessible resource to stay mapped until its final release. This shim keeps wrapper addresses registered, so a successful persistent Map followed by Release leaves a nested map entry for the rest of the run. Please retire the entry at final resource release and cover a mapped-resource lifetime in the fixture. Also consider the allocation in ++resource_maps[self][subresource] under a manually held SRW lock: an allocation failure after a successful desktop Map currently escapes the wrapper and leaves the lock held.

The clear-value call sites overlap #3194. When refreshing the drafts, preserve the ordering of console-to-desktop format mapping before safe_clear, including the distinct reserved-resource slot 30 clear-argument index. The existing format-118 fixture should still preserve a valid clear value after the two changes are combined.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6093554659 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#pullrequestreview-6093554659). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T21:39:43Z. **Review:** COMMENTED --- Draft review: the new `resource_maps` entries are removed only after matching Unmaps. D3D12 permits a CPU-accessible resource to stay mapped until its final release. This shim keeps wrapper addresses registered, so a successful persistent Map followed by Release leaves a nested map entry for the rest of the run. Please retire the entry at final resource release and cover a mapped-resource lifetime in the fixture. Also consider the allocation in `++resource_maps[self][subresource]` under a manually held SRW lock: an allocation failure after a successful desktop Map currently escapes the wrapper and leaves the lock held. The clear-value call sites overlap #3194. When refreshing the drafts, preserve the ordering of console-to-desktop format mapping before `safe_clear`, including the distinct reserved-resource slot 30 clear-argument index. The existing format-118 fixture should still preserve a valid clear value after the two changes are combined.
tedin7 commented 2026-11-27 23:20:24 +00:00 (Migrated from github.com)

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


Pushed 2b71e99a5 for both findings.

  • Map counts are now retired at the resource's final release, so a persistent Map with no Unmap leaves no entry behind. The count logic moved into a small helper (ResourceMapCounts).
  • A failed allocation after a successful desktop Map now undoes the Map and returns E_OUTOFMEMORY, with the lock released.
  • The fixtures cover Map, release without Unmap, and fresh accounting at a reused wrapper address. The clear-value ordering is unchanged; I will keep the format mapping before safe_clear and the slot 30 argument index when the draft is refreshed after #3194.

Verification:

  • Win2025 (Build 26100, MSVC 14.44), exact head 2b71e99a: x2w_pipe.py win2025 3197 --regex '^startup_debug_noise' --force
  • Debug ctest --preset dev 3/3 passed; Release /O2 3/3 passed (startup_debug_noise_check, _device_warp, _device_hardware on WARP).
  • Linux: cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true, public_guard.py.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7230063788 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#issuecomment-7230063788). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T23:20:24Z. --- Pushed `2b71e99a5` for both findings. - Map counts are now retired at the resource's final release, so a persistent Map with no Unmap leaves no entry behind. The count logic moved into a small helper (`ResourceMapCounts`). - A failed allocation after a successful desktop Map now undoes the Map and returns `E_OUTOFMEMORY`, with the lock released. - The fixtures cover Map, release without Unmap, and fresh accounting at a reused wrapper address. The clear-value ordering is unchanged; I will keep the format mapping before `safe_clear` and the slot 30 argument index when the draft is refreshed after #3194. Verification: - Win2025 (Build 26100, MSVC 14.44), exact head 2b71e99a: `x2w_pipe.py win2025 3197 --regex '^startup_debug_noise' --force` - Debug `ctest --preset dev` 3/3 passed; Release /O2 3/3 passed (`startup_debug_noise_check`, `_device_warp`, `_device_hardware` on WARP). - Linux: `cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true`, `public_guard.py`. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-27 23:38:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T23:38:49Z.

Review: COMMENTED


I independently retested the revised 2b71e99a over main fad97f47 (clean trial tree 0a8a1993). The previous Map lifetime findings are addressed: final resource release retires the tracked entries, and an allocation failure after a successful desktop Map now unmaps, returns E_OUTOFMEMORY, and releases the lock. The helper fixture covers retirement and reuse of the same address, and the device fixture releases a persistently mapped upload resource without an explicit Unmap.

I built startup_debug_noise_check startup_debug_noise_device d3d12_xs_shim and ran ctest --test-dir <build> --no-tests=error -j1 -V -R '^startup_debug_noise_(check|device_(warp|hardware))$' in Debug and Release /O2: 3/3 each, no skips. WARP 10.0.26100.9818 and RTX 4060 Laptop (32.0.16.1656) on Windows 11 26200.9974 both reported zero debug-layer errors and no device removal. The separate clear-value coordination with #3194 still applies when that draft changes the shared call sites.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6094334152 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#pullrequestreview-6094334152). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T23:38:49Z. **Review:** COMMENTED --- I independently retested the revised `2b71e99a` over `main` `fad97f47` (clean trial tree `0a8a1993`). The previous Map lifetime findings are addressed: final resource release retires the tracked entries, and an allocation failure after a successful desktop Map now unmaps, returns `E_OUTOFMEMORY`, and releases the lock. The helper fixture covers retirement and reuse of the same address, and the device fixture releases a persistently mapped upload resource without an explicit Unmap. I built `startup_debug_noise_check startup_debug_noise_device d3d12_xs_shim` and ran `ctest --test-dir <build> --no-tests=error -j1 -V -R '^startup_debug_noise_(check|device_(warp|hardware))$'` in Debug and Release /O2: 3/3 each, no skips. WARP 10.0.26100.9818 and RTX 4060 Laptop (32.0.16.1656) on Windows 11 26200.9974 both reported zero debug-layer errors and no device removal. The separate clear-value coordination with #3194 still applies when that draft changes the shared call sites.
KelboLive commented 2026-11-27 23:51:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T23:51:52Z.


Review of 2b71e99a (integrated over main):

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7230465621 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#issuecomment-7230465621). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T23:51:52Z. --- Review of `2b71e99a` (integrated over main):
tedin7 commented 2026-11-28 10:49:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T10:49:18Z.


Real-GPU verification (NVIDIA RTX 3070 Ti, driver 32.0.16.2101, Windows 11):

Tested at 99cc8de. The current head is 2b71e99, so commits pushed after the tested sha are not covered by this run. dev preset, ctest run one test at a time:

  • ctest on the touched block: 100% tests passed, 0 tests failed out of 23 (startup_view_heap_warp skipped; startup_view_heap_hardware, startup_debug_noise_device_hardware and startup_title_heap_device_hardware passed).
  • Mutant patch applied: 91% passed, 2 of 23 failed, exactly the expected ones: startup_debug_noise_device_warp, startup_debug_noise_device_hardware.

These complement the existing WARP runs.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7238143899 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#issuecomment-7238143899). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T10:49:18Z. --- Real-GPU verification (NVIDIA RTX 3070 Ti, driver 32.0.16.2101, Windows 11): Tested at 99cc8de. The current head is 2b71e99, so commits pushed after the tested sha are not covered by this run. dev preset, ctest run one test at a time: - ctest on the touched block: 100% tests passed, 0 tests failed out of 23 (startup_view_heap_warp skipped; startup_view_heap_hardware, startup_debug_noise_device_hardware and startup_title_heap_device_hardware passed). - Mutant patch applied: 91% passed, 2 of 23 failed, exactly the expected ones: startup_debug_noise_device_warp, startup_debug_noise_device_hardware. These complement the existing WARP runs. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot] commented 2026-11-28 10:49:30 +00:00 (Migrated from github.com)

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


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-28T10:56:48.763756Z 2b71e99 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:7238145959 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#issuecomment-7238145959). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:49:30Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"2b71e99a5e885c4feb92439559acb1972c3ef009","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-28T10:56:48.763756Z">2026-11-28T10:56:48.763756Z</relative-time> | `2b71e99` | 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-28 10:56:45 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b71e99a5e

ℹ️ 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:6097334983 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#pullrequestreview-6097334983). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:56:45Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `2b71e99a5e` <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-28 10:56:45 +00:00 (Migrated from github.com)

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

Code review location: src/startup_stubs/descriptor_heap_rules.h; line 15

@@ -0,0 +1,24 @@
+// Descriptor heap requests repaired before the first desktop call, so the debug layer sees a valid one.
+// D3D12 "Hardware Tiers" (Resource Binding): every tier guarantees 1,000,000 descriptors in a shader-visible
+// CBV/SRV/UAV heap and 2048 in a shader-visible sampler heap; larger requests are driver-dependent and the
+// debug layer reports them. RTV and DSV heaps cannot be shader visible ("Descriptor Heaps Overview").
+// Descriptors past the clamped count stay in the CPU-only tail heap made by the device shim.
+#pragma once
+#include <d3d12.h>
+namespace x2w_startup {
+constexpr UINT max_shader_visible_view_descriptors = 1000000;
+constexpr UINT max_shader_visible_sampler_descriptors = 2048;
+inline D3D12_DESCRIPTOR_HEAP_DESC safe_heap_desc(const D3D12_DESCRIPTOR_HEAP_DESC& input) {
+    auto result = input;
+    if (input.Flags & D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE) {
+        if (input.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && input.NumDescriptors > max_shader_visible_view_descriptors)
+            result.NumDescriptors = max_shader_visible_view_descriptors;

P2 Badge Preserve UAV clears when clamping otherwise supported heaps

With X2W_D3D12_RENDER=1 on an adapter that accepts the full request, this unconditional clamp breaks previously supported UAV clears, even with debugging disabled. Such adapters are recorded in docs/startup-runtime.md:2714-2715. In d3d12_xs_device.cpp, owning_view_heap() recognizes only heap.count physical descriptors, and list_clear_uav() refuses GPU handles outside that range. Consequently, a clear at descriptor index 1,000,000 or above is now dropped even when its matching CPU descriptor is in a valid staging heap. The CPU-only tail preserves descriptor writes but cannot service this GPU operation; tail descriptors need a shader-visible clear path before applying the clamp unconditionally.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726660422 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#discussion_r4726660422). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:56:45Z. **Code review location:** `src/startup_stubs/descriptor_heap_rules.h`; line 15 ~~~~diff @@ -0,0 +1,24 @@ +// Descriptor heap requests repaired before the first desktop call, so the debug layer sees a valid one. +// D3D12 "Hardware Tiers" (Resource Binding): every tier guarantees 1,000,000 descriptors in a shader-visible +// CBV/SRV/UAV heap and 2048 in a shader-visible sampler heap; larger requests are driver-dependent and the +// debug layer reports them. RTV and DSV heaps cannot be shader visible ("Descriptor Heaps Overview"). +// Descriptors past the clamped count stay in the CPU-only tail heap made by the device shim. +#pragma once +#include <d3d12.h> +namespace x2w_startup { +constexpr UINT max_shader_visible_view_descriptors = 1000000; +constexpr UINT max_shader_visible_sampler_descriptors = 2048; +inline D3D12_DESCRIPTOR_HEAP_DESC safe_heap_desc(const D3D12_DESCRIPTOR_HEAP_DESC& input) { + auto result = input; + if (input.Flags & D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE) { + if (input.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && input.NumDescriptors > max_shader_visible_view_descriptors) + result.NumDescriptors = max_shader_visible_view_descriptors; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve UAV clears when clamping otherwise supported heaps** With `X2W_D3D12_RENDER=1` on an adapter that accepts the full request, this unconditional clamp breaks previously supported UAV clears, even with debugging disabled. Such adapters are recorded in `docs/startup-runtime.md:2714-2715`. In `d3d12_xs_device.cpp`, `owning_view_heap()` recognizes only `heap.count` physical descriptors, and `list_clear_uav()` refuses GPU handles outside that range. Consequently, a clear at descriptor index 1,000,000 or above is now dropped even when its matching CPU descriptor is in a valid staging heap. The CPU-only tail preserves descriptor writes but cannot service this GPU operation; tail descriptors need a shader-visible clear path before applying the clamp unconditionally. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot] commented 2026-11-28 10:56:45 +00:00 (Migrated from github.com)

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

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

@@ -439,22 +444,38 @@ void check_device(const char* context, int slot)
     if (!info_queue) return;
     AcquireSRWLockExclusive(&debug_lock);
     const UINT64 count = info_queue->GetNumStoredMessages();
-    for (UINT64 i = 0; i < count && debug_lines < 400; ++i) {
+    for (UINT64 i = 0; i < count; ++i) {
         SIZE_T size = 0;
         info_queue->GetMessage(i, nullptr, &size);
         if (!size || size > 8192) continue;
         alignas(16) char storage[8192];
         auto* message = reinterpret_cast<D3D12_MESSAGE*>(storage);
         if (SUCCEEDED(info_queue->GetMessage(i, message, &size))) {
-            ++debug_lines;
-            log("x2w-d3d12-debug [%s %d] sev=%d id=%d %.900s", context, slot, message->Severity, message->ID,
-                message->pDescription);
+            const auto decision = debug_budget.record(message->Severity, message->ID);

P2 Badge Keep debug draining non-throwing on allocation failure

With X2W_D3D12_DEBUG=1, recording a previously unseen message ID now allocates through DebugDrainBudget::counts_[id]. If that allocation fails, std::bad_alloc escapes this call while debug_lock is held, bypassing its release and the normal HRESULT return from the shim. This can terminate the caller, or permanently block subsequent drains if an outer handler catches the exception. Allocation failure was reproduced against the new helper; the previous fixed-size drain required no bookkeeping allocation. Make budget recording best-effort and ensure the lock is released on failure.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726660424 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#discussion_r4726660424). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:56:45Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 454 ~~~~diff @@ -439,22 +444,38 @@ void check_device(const char* context, int slot) if (!info_queue) return; AcquireSRWLockExclusive(&debug_lock); const UINT64 count = info_queue->GetNumStoredMessages(); - for (UINT64 i = 0; i < count && debug_lines < 400; ++i) { + for (UINT64 i = 0; i < count; ++i) { SIZE_T size = 0; info_queue->GetMessage(i, nullptr, &size); if (!size || size > 8192) continue; alignas(16) char storage[8192]; auto* message = reinterpret_cast<D3D12_MESSAGE*>(storage); if (SUCCEEDED(info_queue->GetMessage(i, message, &size))) { - ++debug_lines; - log("x2w-d3d12-debug [%s %d] sev=%d id=%d %.900s", context, slot, message->Severity, message->ID, - message->pDescription); + const auto decision = debug_budget.record(message->Severity, message->ID); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Keep debug draining non-throwing on allocation failure** With `X2W_D3D12_DEBUG=1`, recording a previously unseen message ID now allocates through `DebugDrainBudget::counts_[id]`. If that allocation fails, `std::bad_alloc` escapes this call while `debug_lock` is held, bypassing its release and the normal HRESULT return from the shim. This can terminate the caller, or permanently block subsequent drains if an outer handler catches the exception. Allocation failure was reproduced against the new helper; the previous fixed-size drain required no bookkeeping allocation. Make budget recording best-effort and ensure the lock is released on failure. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot] commented 2026-11-28 10:56:45 +00:00 (Migrated from github.com)

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

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

@@ -327,7 +330,8 @@ std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mas
     // Halve from the documented ceiling, testing the floor too: a driver whose maximum is below the
     // floor must not be recorded as accepting it, or the retry would ask for a size it rejects again.
     std::uint64_t accepted = 0;
-    for (std::uint64_t size = 1048576; size >= view_heap_probe_floor; size /= 2) {
+    constexpr std::uint64_t ceiling = x2w_startup::max_shader_visible_view_descriptors;
+    for (std::uint64_t size = ceiling; size >= view_heap_probe_floor; size /= 2) {

P2 Badge Probe the floor explicitly after changing the ceiling

If the fallback can create a heap with 65,536–124,999 descriptors but not 125,000, the new halving sequence never discovers that usable capacity: it probes 1,000,000, 500,000, 250,000 and 125,000, then exits because 62,500 is below view_heap_probe_floor. It consequently caches a zero limit and leaves heap creation failing for subsequent requests. The parent sequence explicitly reached 65,536, so this is a regression caused by changing the ceiling away from a power of two. Probe the floor separately or clamp the last halving step to it before recording failure.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726660427 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#discussion_r4726660427). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:56:45Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 334 ~~~~diff @@ -327,7 +330,8 @@ std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mas // Halve from the documented ceiling, testing the floor too: a driver whose maximum is below the // floor must not be recorded as accepting it, or the retry would ask for a size it rejects again. std::uint64_t accepted = 0; - for (std::uint64_t size = 1048576; size >= view_heap_probe_floor; size /= 2) { + constexpr std::uint64_t ceiling = x2w_startup::max_shader_visible_view_descriptors; + for (std::uint64_t size = ceiling; size >= view_heap_probe_floor; size /= 2) { ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Probe the floor explicitly after changing the ceiling** If the fallback can create a heap with 65,536–124,999 descriptors but not 125,000, the new halving sequence never discovers that usable capacity: it probes 1,000,000, 500,000, 250,000 and 125,000, then exits because 62,500 is below `view_heap_probe_floor`. It consequently caches a zero limit and leaves heap creation failing for subsequent requests. The parent sequence explicitly reached 65,536, so this is a regression caused by changing the ceiling away from a power of two. Probe the floor separately or clamp the last halving step to it before recording failure. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot] commented 2026-11-28 10:56:46 +00:00 (Migrated from github.com)

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

Code review location: CMakeLists.txt; line 1776

@@ -1759,6 +1765,18 @@ foreach(backend IN ITEMS warp hardware)
         ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=1")
 endforeach()
 
+# Device slots 14/27 and resource slots 8/9 with the debug layer on: invalid optimized clears, Map/Unmap on a
+# DEFAULT heap and oversized or shader-visible RTV descriptor heaps raise no debug-layer error.
+add_executable(startup_debug_noise_device tests/startup_debug_noise_device.cpp)
+target_compile_features(startup_debug_noise_device PRIVATE cxx_std_17)
+target_link_libraries(startup_debug_noise_device PRIVATE d3d12_xs_shim d3d12 dxgi)
+foreach(backend IN ITEMS warp hardware)
+    add_test(NAME startup_debug_noise_device_${backend} COMMAND startup_debug_noise_device ${backend})
+    set_tests_properties(startup_debug_noise_device_${backend} PROPERTIES TIMEOUT 60
+        ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_DEBUG=1")

P2 Badge Put the new registrations in a test-family fragment

These new registrations bypass the layout documented in AGENTS.md: “One <family>.cmake file per test family or pull request.” The referenced tests/cmake/README.md explicitly requires new add_test and set_tests_properties calls to go in a family fragment so independent changes do not edit the same central registration file. Move both new debug-noise registrations and their properties into tests/cmake/startup_debug_noise.cmake, which the existing glob automatically includes; the executable target definitions can remain here.

AGENTS.md reference: AGENTS.md:L302-L302

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726660428 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#discussion_r4726660428). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:56:46Z. **Code review location:** `CMakeLists.txt`; line 1776 ~~~~diff @@ -1759,6 +1765,18 @@ foreach(backend IN ITEMS warp hardware) ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=1") endforeach() +# Device slots 14/27 and resource slots 8/9 with the debug layer on: invalid optimized clears, Map/Unmap on a +# DEFAULT heap and oversized or shader-visible RTV descriptor heaps raise no debug-layer error. +add_executable(startup_debug_noise_device tests/startup_debug_noise_device.cpp) +target_compile_features(startup_debug_noise_device PRIVATE cxx_std_17) +target_link_libraries(startup_debug_noise_device PRIVATE d3d12_xs_shim d3d12 dxgi) +foreach(backend IN ITEMS warp hardware) + add_test(NAME startup_debug_noise_device_${backend} COMMAND startup_debug_noise_device ${backend}) + set_tests_properties(startup_debug_noise_device_${backend} PROPERTIES TIMEOUT 60 + ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_DEBUG=1") ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Put the new registrations in a test-family fragment** These new registrations bypass the layout documented in `AGENTS.md`: “One `<family>.cmake` file per test family or pull request.” The referenced `tests/cmake/README.md` explicitly requires new `add_test` and `set_tests_properties` calls to go in a family fragment so independent changes do not edit the same central registration file. Move both new debug-noise registrations and their properties into `tests/cmake/startup_debug_noise.cmake`, which the existing glob automatically includes; the executable target definitions can remain here. AGENTS.md reference: [AGENTS.md:L302-L302](https://github.com/R0Y00/Xbox2Windows/blob/2b71e99a5e885c4feb92439559acb1972c3ef009/AGENTS.md#L302-L302) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-28 11:11:23 +00:00 (Migrated from github.com)

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

Code review location: src/startup_stubs/descriptor_heap_rules.h; line 15

@@ -0,0 +1,24 @@
+// Descriptor heap requests repaired before the first desktop call, so the debug layer sees a valid one.
+// D3D12 "Hardware Tiers" (Resource Binding): every tier guarantees 1,000,000 descriptors in a shader-visible
+// CBV/SRV/UAV heap and 2048 in a shader-visible sampler heap; larger requests are driver-dependent and the
+// debug layer reports them. RTV and DSV heaps cannot be shader visible ("Descriptor Heaps Overview").
+// Descriptors past the clamped count stay in the CPU-only tail heap made by the device shim.
+#pragma once
+#include <d3d12.h>
+namespace x2w_startup {
+constexpr UINT max_shader_visible_view_descriptors = 1000000;
+constexpr UINT max_shader_visible_sampler_descriptors = 2048;
+inline D3D12_DESCRIPTOR_HEAP_DESC safe_heap_desc(const D3D12_DESCRIPTOR_HEAP_DESC& input) {
+    auto result = input;
+    if (input.Flags & D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE) {
+        if (input.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && input.NumDescriptors > max_shader_visible_view_descriptors)
+            result.NumDescriptors = max_shader_visible_view_descriptors;

Valid, fixed in 2bc79c94b on up-debug-noise. The clamp to 1,000,000 now applies only below resource binding tier 3. The D3D12 resource binding spec lists tier 3 as 1000000+, so on a tier 3 device (CheckFeatureSupport OPTIONS, ResourceBindingTier) a request up to 2^20 = 1,048,576 is kept as asked, the physical heap keeps its descriptors past 1,000,000, and list_clear_uav still resolves them. If the driver refuses the size, the existing probe still shortens it. Larger requests are still clamped (to 1,048,576 on tier 3). Test: startup_debug_noise_check covers the limit parameter of safe_heap_desc (1,000,000 default, 1,048,576 for tier 3).

Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head 2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726721114 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#discussion_r4726721114). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T11:11:23Z. **Code review location:** `src/startup_stubs/descriptor_heap_rules.h`; line 15 ~~~~diff @@ -0,0 +1,24 @@ +// Descriptor heap requests repaired before the first desktop call, so the debug layer sees a valid one. +// D3D12 "Hardware Tiers" (Resource Binding): every tier guarantees 1,000,000 descriptors in a shader-visible +// CBV/SRV/UAV heap and 2048 in a shader-visible sampler heap; larger requests are driver-dependent and the +// debug layer reports them. RTV and DSV heaps cannot be shader visible ("Descriptor Heaps Overview"). +// Descriptors past the clamped count stay in the CPU-only tail heap made by the device shim. +#pragma once +#include <d3d12.h> +namespace x2w_startup { +constexpr UINT max_shader_visible_view_descriptors = 1000000; +constexpr UINT max_shader_visible_sampler_descriptors = 2048; +inline D3D12_DESCRIPTOR_HEAP_DESC safe_heap_desc(const D3D12_DESCRIPTOR_HEAP_DESC& input) { + auto result = input; + if (input.Flags & D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE) { + if (input.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && input.NumDescriptors > max_shader_visible_view_descriptors) + result.NumDescriptors = max_shader_visible_view_descriptors; ~~~~ --- Valid, fixed in 2bc79c94b on up-debug-noise. The clamp to 1,000,000 now applies only below resource binding tier 3. The D3D12 resource binding spec lists tier 3 as 1000000+, so on a tier 3 device (CheckFeatureSupport OPTIONS, ResourceBindingTier) a request up to 2^20 = 1,048,576 is kept as asked, the physical heap keeps its descriptors past 1,000,000, and list_clear_uav still resolves them. If the driver refuses the size, the existing probe still shortens it. Larger requests are still clamped (to 1,048,576 on tier 3). Test: startup_debug_noise_check covers the limit parameter of safe_heap_desc (1,000,000 default, 1,048,576 for tier 3). Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head 2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-28 11:11:25 +00:00 (Migrated from github.com)

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

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

@@ -439,22 +444,38 @@ void check_device(const char* context, int slot)
     if (!info_queue) return;
     AcquireSRWLockExclusive(&debug_lock);
     const UINT64 count = info_queue->GetNumStoredMessages();
-    for (UINT64 i = 0; i < count && debug_lines < 400; ++i) {
+    for (UINT64 i = 0; i < count; ++i) {
         SIZE_T size = 0;
         info_queue->GetMessage(i, nullptr, &size);
         if (!size || size > 8192) continue;
         alignas(16) char storage[8192];
         auto* message = reinterpret_cast<D3D12_MESSAGE*>(storage);
         if (SUCCEEDED(info_queue->GetMessage(i, message, &size))) {
-            ++debug_lines;
-            log("x2w-d3d12-debug [%s %d] sev=%d id=%d %.900s", context, slot, message->Severity, message->ID,
-                message->pDescription);
+            const auto decision = debug_budget.record(message->Severity, message->ID);

Valid, fixed in 2bc79c94b. DebugDrainBudget::record is now noexcept and best effort: if the per-id counter cannot be allocated it catches std::bad_alloc and drops the line (Decision::suppress), so nothing is thrown while debug_lock is held. Test: startup_debug_noise_check replaces operator new, makes it fail while a new message id is recorded, and checks that the call returns suppress and that the id is counted normally afterwards.

Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head 2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726721408 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#discussion_r4726721408). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T11:11:25Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 454 ~~~~diff @@ -439,22 +444,38 @@ void check_device(const char* context, int slot) if (!info_queue) return; AcquireSRWLockExclusive(&debug_lock); const UINT64 count = info_queue->GetNumStoredMessages(); - for (UINT64 i = 0; i < count && debug_lines < 400; ++i) { + for (UINT64 i = 0; i < count; ++i) { SIZE_T size = 0; info_queue->GetMessage(i, nullptr, &size); if (!size || size > 8192) continue; alignas(16) char storage[8192]; auto* message = reinterpret_cast<D3D12_MESSAGE*>(storage); if (SUCCEEDED(info_queue->GetMessage(i, message, &size))) { - ++debug_lines; - log("x2w-d3d12-debug [%s %d] sev=%d id=%d %.900s", context, slot, message->Severity, message->ID, - message->pDescription); + const auto decision = debug_budget.record(message->Severity, message->ID); ~~~~ --- Valid, fixed in 2bc79c94b. DebugDrainBudget::record is now noexcept and best effort: if the per-id counter cannot be allocated it catches std::bad_alloc and drops the line (Decision::suppress), so nothing is thrown while debug_lock is held. Test: startup_debug_noise_check replaces operator new, makes it fail while a new message id is recorded, and checks that the call returns suppress and that the id is counted normally afterwards. Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head 2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-28 11:11:27 +00:00 (Migrated from github.com)

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

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

@@ -327,7 +330,8 @@ std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mas
     // Halve from the documented ceiling, testing the floor too: a driver whose maximum is below the
     // floor must not be recorded as accepting it, or the retry would ask for a size it rejects again.
     std::uint64_t accepted = 0;
-    for (std::uint64_t size = 1048576; size >= view_heap_probe_floor; size /= 2) {
+    constexpr std::uint64_t ceiling = x2w_startup::max_shader_visible_view_descriptors;
+    for (std::uint64_t size = ceiling; size >= view_heap_probe_floor; size /= 2) {

Valid, fixed in 2bc79c94b. The halving now goes through largest_halving_size() in descriptor_heap_rules.h, which clamps the last step to the floor and probes it explicitly, so a driver whose limit lies between 65,536 and 124,999 is found (1,000,000, 500,000, 250,000, 125,000, then 65,536). Test: startup_debug_noise_check checks limits of 100,000 (found as 65,536), 300,000 (250,000), a driver that refuses everything (0) and exactly 65,536.

Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head 2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726721612 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#discussion_r4726721612). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T11:11:27Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 334 ~~~~diff @@ -327,7 +330,8 @@ std::uint64_t accepted_view_heap_descriptors(ID3D12Device* device, UINT node_mas // Halve from the documented ceiling, testing the floor too: a driver whose maximum is below the // floor must not be recorded as accepting it, or the retry would ask for a size it rejects again. std::uint64_t accepted = 0; - for (std::uint64_t size = 1048576; size >= view_heap_probe_floor; size /= 2) { + constexpr std::uint64_t ceiling = x2w_startup::max_shader_visible_view_descriptors; + for (std::uint64_t size = ceiling; size >= view_heap_probe_floor; size /= 2) { ~~~~ --- Valid, fixed in 2bc79c94b. The halving now goes through largest_halving_size() in descriptor_heap_rules.h, which clamps the last step to the floor and probes it explicitly, so a driver whose limit lies between 65,536 and 124,999 is found (1,000,000, 500,000, 250,000, 125,000, then 65,536). Test: startup_debug_noise_check checks limits of 100,000 (found as 65,536), 300,000 (250,000), a driver that refuses everything (0) and exactly 65,536. Gate on aws-1 with WARP (x2w_pipe.py win2025 3197 --host aws-1 --regex startup_debug_noise --force, head 2bc79c94): dev and release 3/3 passed. Mutant of the floor probe (the old halving that stops before the floor), run after the main gate: startup_debug_noise_check fails. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-28 11:11:29 +00:00 (Migrated from github.com)

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

Code review location: CMakeLists.txt; line 1776

@@ -1759,6 +1765,18 @@ foreach(backend IN ITEMS warp hardware)
         ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=1")
 endforeach()
 
+# Device slots 14/27 and resource slots 8/9 with the debug layer on: invalid optimized clears, Map/Unmap on a
+# DEFAULT heap and oversized or shader-visible RTV descriptor heaps raise no debug-layer error.
+add_executable(startup_debug_noise_device tests/startup_debug_noise_device.cpp)
+target_compile_features(startup_debug_noise_device PRIVATE cxx_std_17)
+target_link_libraries(startup_debug_noise_device PRIVATE d3d12_xs_shim d3d12 dxgi)
+foreach(backend IN ITEMS warp hardware)
+    add_test(NAME startup_debug_noise_device_${backend} COMMAND startup_debug_noise_device ${backend})
+    set_tests_properties(startup_debug_noise_device_${backend} PROPERTIES TIMEOUT 60
+        ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_DEBUG=1")

Valid, fixed in 2bc79c94b. The add_test calls for startup_debug_noise_check and startup_debug_noise_device_{warp,hardware}, with their set_tests_properties, moved to tests/cmake/startup_debug_noise.cmake. CMakeLists.txt keeps the executable targets and a pointer comment. cmake -S . -B -DDXC_EXECUTABLE=/bin/true configures and the three tests are registered; the gate above ran them from the fragment.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726721838 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#discussion_r4726721838). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T11:11:29Z. **Code review location:** `CMakeLists.txt`; line 1776 ~~~~diff @@ -1759,6 +1765,18 @@ foreach(backend IN ITEMS warp hardware) ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=1") endforeach() +# Device slots 14/27 and resource slots 8/9 with the debug layer on: invalid optimized clears, Map/Unmap on a +# DEFAULT heap and oversized or shader-visible RTV descriptor heaps raise no debug-layer error. +add_executable(startup_debug_noise_device tests/startup_debug_noise_device.cpp) +target_compile_features(startup_debug_noise_device PRIVATE cxx_std_17) +target_link_libraries(startup_debug_noise_device PRIVATE d3d12_xs_shim d3d12 dxgi) +foreach(backend IN ITEMS warp hardware) + add_test(NAME startup_debug_noise_device_${backend} COMMAND startup_debug_noise_device ${backend}) + set_tests_properties(startup_debug_noise_device_${backend} PROPERTIES TIMEOUT 60 + ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_DEBUG=1") ~~~~ --- Valid, fixed in 2bc79c94b. The add_test calls for startup_debug_noise_check and startup_debug_noise_device_{warp,hardware}, with their set_tests_properties, moved to tests/cmake/startup_debug_noise.cmake. CMakeLists.txt keeps the executable targets and a pointer comment. cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true configures and the three tests are registered; the gate above ran them from the fragment. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-28 21:58:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T21:58:17Z.


Merged current main into this branch (merge commit, no force push); head is now a46c69db8. One conflict in resource_unmap: main added a compute-output trace call at the top, this PR the guarded unmap; both are kept, the trace first.

The four review findings were already fixed in 2bc79c94b (see the thread replies).

Verification (Windows Server 2025, D3D12 WARP, head a46c69db8): x2w_pipe.py win2025 3197 --regex '^startup_(debug_noise_.*|view_heap_.*|descriptor_.*|title_heap.*|resource_desc_.*|clear_depth_stencil_.*|clear_uav_.*|committed_heap_state.*)$' -> 23/23 passed.

@MasterDomino ready for review and merge when you have time.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7246403915 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#issuecomment-7246403915). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T21:58:17Z. --- Merged current `main` into this branch (merge commit, no force push); head is now `a46c69db8`. One conflict in `resource_unmap`: main added a compute-output trace call at the top, this PR the guarded unmap; both are kept, the trace first. The four review findings were already fixed in `2bc79c94b` (see the thread replies). Verification (Windows Server 2025, D3D12 WARP, head `a46c69db8`): `x2w_pipe.py win2025 3197 --regex '^startup_(debug_noise_.*|view_heap_.*|descriptor_.*|title_heap.*|resource_desc_.*|clear_depth_stencil_.*|clear_uav_.*|committed_heap_state.*)$'` -> 23/23 passed. @MasterDomino ready for review and merge when you have time. AI-assisted; commands listed were executed locally.
pigalot commented 2026-11-29 12:07:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-29T12:07:06Z.

Review: CHANGES_REQUESTED


Reviewed a46c69db against main a30437f7. The branch no longer merges: #3194 (ae45c4ff) landed on main after this head was pushed and changed the same clear-value call sites. GitHub reports the PR as CONFLICTING.

git merge --no-ff --no-commit of a46c69db onto a30437f7 conflicts in src/startup_stubs/d3d12_xs_device.cpp in four places; every other file merges cleanly and git diff --check is clean.

  1. The include block: main adds clear_value_format.h; this PR adds packed_target_format.h, debug_drain_budget.h, descriptor_heap_rules.h and optimized_clear_value.h.
  2. create_slot: main now handles slots 27, 29 and 30 with x2w_startup::desktop_clear_value(...) and a per-slot clear argument index (N == 30 ? 2 : 4); this PR handles 27 and 29 only, through packed_clear_value(...) and args[4].
  3. device_place_resource (the title-memory texture path): desktop_clear_value(clear, desc->Format, texture.Format, ...) on main against packed_clear_value(clear, desktop_format(desc->Format), texture.Format, ...) followed by safe_clear here.
  4. create_committed: the same pair of calls.

Taking this PR's side of the hunks would not build either: packed_clear_value no longer exists on main (no match under src/ or tests/); desktop_clear_value in clear_value_format.h replaced it and takes the title's unmapped desc format.

Requested change: merge main and resolve these so the format mapping from #3194 runs first and safe_clear is applied to its result, as asked in the review of 99cc8de8. Concretely:

  • Keep desktop_clear_value(...) at all three sites and pass its result to safe_clear(...) with the desc that is really created.
  • In create_slot, keep main's slot 30 case and its clear index 2. Slot 30 (CreateReservedResource) takes the same D3D12_CLEAR_VALUE, so it should go through safe_clear as well, or the PR should say why it is left out. A device-fixture case for a reserved resource with an invalid clear value would cover it.
  • The format-118 fixture from #3194 (startup_clear_depth_stencil) has to keep a valid clear value after the two changes are combined. optimized_clear_value treats D24_UNORM_S8_UINT as a depth format, so I expect it to, but I have not run it.

What I did not do: because the branch cannot be built on current main, I did not build it, run its tests, run mutants, or ask for a title run at this head. I will do those on the next head. I read optimized_clear_value.h and clear_value_format.h for the notes above, and nothing else in the diff in depth.

The four inline threads (tier 3 heap sizes, non-throwing drain budget, capacity floor probe, registrations in a fragment) were answered with 2bc79c94; I have not verified those fixes yet and they are still open on the PR.

Environment: Windows 11 25H2 build 26200.9974; git trial merge only, nothing built.
CI: Build and test on Windows passed on a46c69db, before #3194 landed.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6102796600 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#pullrequestreview-6102796600). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-29T12:07:06Z. **Review:** CHANGES_REQUESTED --- Reviewed `a46c69db` against `main` `a30437f7`. The branch no longer merges: #3194 (`ae45c4ff`) landed on `main` after this head was pushed and changed the same clear-value call sites. GitHub reports the PR as `CONFLICTING`. `git merge --no-ff --no-commit` of `a46c69db` onto `a30437f7` conflicts in `src/startup_stubs/d3d12_xs_device.cpp` in four places; every other file merges cleanly and `git diff --check` is clean. 1. The include block: `main` adds `clear_value_format.h`; this PR adds `packed_target_format.h`, `debug_drain_budget.h`, `descriptor_heap_rules.h` and `optimized_clear_value.h`. 2. `create_slot`: `main` now handles slots 27, 29 and 30 with `x2w_startup::desktop_clear_value(...)` and a per-slot clear argument index (`N == 30 ? 2 : 4`); this PR handles 27 and 29 only, through `packed_clear_value(...)` and `args[4]`. 3. `device_place_resource` (the title-memory texture path): `desktop_clear_value(clear, desc->Format, texture.Format, ...)` on `main` against `packed_clear_value(clear, desktop_format(desc->Format), texture.Format, ...)` followed by `safe_clear` here. 4. `create_committed`: the same pair of calls. Taking this PR's side of the hunks would not build either: `packed_clear_value` no longer exists on `main` (no match under `src/` or `tests/`); `desktop_clear_value` in `clear_value_format.h` replaced it and takes the title's unmapped desc format. Requested change: merge `main` and resolve these so the format mapping from #3194 runs first and `safe_clear` is applied to its result, as asked in the review of `99cc8de8`. Concretely: - Keep `desktop_clear_value(...)` at all three sites and pass its result to `safe_clear(...)` with the desc that is really created. - In `create_slot`, keep `main`'s slot 30 case and its clear index 2. Slot 30 (`CreateReservedResource`) takes the same `D3D12_CLEAR_VALUE`, so it should go through `safe_clear` as well, or the PR should say why it is left out. A device-fixture case for a reserved resource with an invalid clear value would cover it. - The format-118 fixture from #3194 (`startup_clear_depth_stencil`) has to keep a valid clear value after the two changes are combined. `optimized_clear_value` treats `D24_UNORM_S8_UINT` as a depth format, so I expect it to, but I have not run it. What I did not do: because the branch cannot be built on current `main`, I did not build it, run its tests, run mutants, or ask for a title run at this head. I will do those on the next head. I read `optimized_clear_value.h` and `clear_value_format.h` for the notes above, and nothing else in the diff in depth. The four inline threads (tier 3 heap sizes, non-throwing drain budget, capacity floor probe, registrations in a fragment) were answered with `2bc79c94`; I have not verified those fixes yet and they are still open on the PR. Environment: Windows 11 25H2 build 26200.9974; git trial merge only, nothing built. CI: `Build and test on Windows` passed on `a46c69db`, before #3194 landed. This reply was AI-assisted.
JohnConnorNPC commented 2026-11-29 13:05:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T13:05:05Z.


Review of head a46c69db against main 94b679e7. I read the source and ran trial merges only; I did not build or run anything.

MUST

  1. Merge main. git merge-tree --write-tree origin/main a46c69db exits 1 with CONFLICT (content): Merge conflict in src/startup_stubs/d3d12_xs_device.cpp, 4 hunks. These are the four hunks pigalot lists, and pigalot's review already gives the resolution (#3194's desktop_clear_value first, then safe_clear, slot 30 included). I have nothing to add to it.

On the default launcher path

  • run.sh and run.ps1 do not set X2W_D3D12_DEBUG: git grep -l X2W_D3D12_DEBUG origin/main -- tools/ finds no file. So the drain budget only changes opt-in debug runs. The Map/Unmap guard, the clear-value drops and the heap repairs are on with no switch.
  • In a local start-up run on main, the first 16 logged CreateDescriptorHeap calls hold one shader-visible CBV/SRV/UAV heap of 1,245,184 descriptors. The rest are CPU-only heaps and one 128-entry shader-visible sampler heap. None is a shader-visible RTV/DSV heap or a sampler heap above 2048. On a tier 3 device that accepts 1,048,576, this PR's clamp gives the same size as main's probe path. A driver that takes only 1,000,000 also ends at the same size. On this path the heap change just removes the failed first create. That matches what the body says.

NIT

  1. resource_map_lock is one exclusive lock held across every desktop Map: AcquireSRWLockExclusive(&resource_map_lock); hr = !real ? E_FAIL : cpu_hidden ? E_INVALIDARG : real->Map(subresource, range, &mapped);. That serializes Map calls from all threads. Only the count needs the lock. Map could run first, then the lock could cover just record, with the existing Unmap on bad_alloc. A title cannot Unmap a subresource before its Map has returned, so nothing races.
  2. safe_clear logs x2w-d3d12 optimized clear dropped reason=%u once per reason, with no clear format, desc format or dimension. Printing those once per reason would show which console clear values are being dropped.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7256276694 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#issuecomment-7256276694). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-29T13:05:05Z. --- Review of head `a46c69db` against `main` `94b679e7`. I read the source and ran trial merges only; I did not build or run anything. **MUST** 1. **Merge `main`.** `git merge-tree --write-tree origin/main a46c69db` exits 1 with `CONFLICT (content): Merge conflict in src/startup_stubs/d3d12_xs_device.cpp`, 4 hunks. These are the four hunks pigalot lists, and pigalot's review already gives the resolution (#3194's `desktop_clear_value` first, then `safe_clear`, slot 30 included). I have nothing to add to it. **On the default launcher path** - `run.sh` and `run.ps1` do not set `X2W_D3D12_DEBUG`: `git grep -l X2W_D3D12_DEBUG origin/main -- tools/` finds no file. So the drain budget only changes opt-in debug runs. The `Map`/`Unmap` guard, the clear-value drops and the heap repairs are on with no switch. - In a local start-up run on `main`, the first 16 logged `CreateDescriptorHeap` calls hold one shader-visible CBV/SRV/UAV heap of 1,245,184 descriptors. The rest are CPU-only heaps and one 128-entry shader-visible sampler heap. None is a shader-visible RTV/DSV heap or a sampler heap above 2048. On a tier 3 device that accepts 1,048,576, this PR's clamp gives the same size as `main`'s probe path. A driver that takes only 1,000,000 also ends at the same size. On this path the heap change just removes the failed first create. That matches what the body says. **NIT** 2. `resource_map_lock` is one exclusive lock held across every desktop `Map`: `AcquireSRWLockExclusive(&resource_map_lock); hr = !real ? E_FAIL : cpu_hidden ? E_INVALIDARG : real->Map(subresource, range, &mapped);`. That serializes `Map` calls from all threads. Only the count needs the lock. `Map` could run first, then the lock could cover just `record`, with the existing `Unmap` on `bad_alloc`. A title cannot `Unmap` a subresource before its `Map` has returned, so nothing races. 3. `safe_clear` logs `x2w-d3d12 optimized clear dropped reason=%u` once per reason, with no clear format, desc format or dimension. Printing those once per reason would show which console clear values are being dropped. AI-assisted.
tedin7 commented 2026-11-30 13:58:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-30T13:58:56Z.


Merged current main (077bff3ac) and addressed the map-lock and clear-value comments. Ready for CI and re-review.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7280654571 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#issuecomment-7280654571). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-30T13:58:56Z. --- Merged current `main` (`077bff3ac`) and addressed the map-lock and clear-value comments. Ready for CI and re-review.
R0Y00 commented 2026-12-03 03:49:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T03:49:27Z.

Review: CHANGES_REQUESTED


The four clear-value conflicts are resolved at fe1af87b. In a clean trial merge with main 41a83a9a, desktop_clear_value runs before safe_clear on the creation paths, and slot 30 keeps clear argument index 2. startup_debug_noise_check and both startup_clear_depth_stencil cases passed, including format 118 mapped to DXGI 45 and depth readback of 0.25/0.75 with zero debug errors on WARP and RTX 4060 Laptop.

One current blocker: startup_debug_noise_device_warp passes, but startup_debug_noise_device_hardware fails on the RTX 4060 Laptop. The fixture requests 1,048,577 shader-visible CBV/SRV/UAV descriptors. device_create_descriptor_heap uses the Tier 3 shortcut and sends 1,048,576 to the first desktop CreateDescriptorHeap call. Its debug callback reports NumDescriptors 1048576, but the limit for shader visible view heaps is 1000000. The retry succeeds at 1,000,000 and the device remains healthy, but the first error is exactly what this PR's fixture requires to avoid. A local diagnostic changing only the fixture request to 1,000,000 passed with zero errors. Please keep the oversized fixture and ensure the first call respects adapters whose effective limit is 1,000,000, while preserving the larger path where support is established.

MSVC Debug: ctest --preset dev --no-tests=error -j 1 -V -R '^(startup_debug_noise_(check|device_(warp|hardware))|startup_clear_depth_stencil_(warp|hardware))$', four passed, one failed, no skips. Windows 11 build 26300, WARP 10.0.26100.9818, RTX 4060 Laptop 32.0.16.1656, debug layer enabled for the device cases.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6163387934 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3197#pullrequestreview-6163387934). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T03:49:27Z. **Review:** CHANGES_REQUESTED --- The four clear-value conflicts are resolved at `fe1af87b`. In a clean trial merge with `main` `41a83a9a`, `desktop_clear_value` runs before `safe_clear` on the creation paths, and slot 30 keeps clear argument index 2. `startup_debug_noise_check` and both `startup_clear_depth_stencil` cases passed, including format 118 mapped to DXGI 45 and depth readback of 0.25/0.75 with zero debug errors on WARP and RTX 4060 Laptop. One current blocker: `startup_debug_noise_device_warp` passes, but `startup_debug_noise_device_hardware` fails on the RTX 4060 Laptop. The fixture requests 1,048,577 shader-visible CBV/SRV/UAV descriptors. `device_create_descriptor_heap` uses the Tier 3 shortcut and sends 1,048,576 to the first desktop `CreateDescriptorHeap` call. Its debug callback reports `NumDescriptors 1048576, but the limit for shader visible view heaps is 1000000`. The retry succeeds at 1,000,000 and the device remains healthy, but the first error is exactly what this PR's fixture requires to avoid. A local diagnostic changing only the fixture request to 1,000,000 passed with zero errors. Please keep the oversized fixture and ensure the first call respects adapters whose effective limit is 1,000,000, while preserving the larger path where support is established. MSVC Debug: `ctest --preset dev --no-tests=error -j 1 -V -R '^(startup_debug_noise_(check|device_(warp|hardware))|startup_clear_depth_stencil_(warp|hardware))$'`, four passed, one failed, no skips. Windows 11 build 26300, WARP 10.0.26100.9818, RTX 4060 Laptop 32.0.16.1656, debug layer enabled for the device cases.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3197:upstream-pr/3197'
git switch 'upstream-pr/3197'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3197'
git switch 'upstream-pr/3197'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3197'
git switch 'upstream-pr/3197'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3197'
git switch 'main'
git merge --squash 'upstream-pr/3197'
git switch 'main'
git merge --ff-only 'upstream-pr/3197'
git switch 'main'
git merge 'upstream-pr/3197'
git push origin 'main'
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!3197
No description provided.