startup: map the optimized clear value of console-only formats to the desktop format #3194

Merged
tedin7 merged 3 commits from upstream-pr/3194 into main 2026-11-29 08:07:05 +00:00
tedin7 commented 2026-11-27 21:22:20 +00:00 (Migrated from github.com)

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


Part of #870

What this unblocks: depth/stencil and 10-bit float targets made with a console-only format keep their optimized clear value on desktop D3D12, so the title's clears match it.

The shim already maps the console-only DXGI values 116-120 (two 10-bit float formats, D16_UNORM_S8_UINT and its two typed views) to the nearest desktop formats when it creates a resource. The optimized clear value passed with that resource kept the console format, so desktop D3D12 got a clear format that no longer matched the created resource (ID3D12Device::CreateCommittedResource / CreatePlacedResource / CreateReservedResource, pOptimizedClearValue), and later clears were reported as mismatching.

This change:

  • moves the 116-120 mapping into one header, src/startup_stubs/clear_value_format.h (desktop_format, desktop_clear_value), used by the device shim and by xg_xs.cpp instead of two copies;
  • maps the clear value format through the same table on committed, placed and reserved creation (slot 30 takes its clear value in the third argument), and still swaps it to the stand-in format when a packed target was substituted.

Tests:

  • startup_clear_depth_stencil_warp: new case D creates a 1x1 console-format-118 depth target with a matching clear value through slot 76 and clears it; the run fails on a debug-layer CLEARDEPTHSTENCILVIEW_MISMATCHINGCLEARVALUE message or a dropped clear in the log.
  • startup_packed_target + new startup_packed_target_raw-clear_control (WILL_FAIL): CPU check of desktop_clear_value for console formats 116, 117 and 118 and for the packed stand-in; the control forwards format 118 unchanged and must fail.

Verification:

  • x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -x c++ -Isrc -Isrc/startup_stubs src/startup_stubs/clear_value_format.h -> OK
  • cmake -S . -B /tmp/cfg -G Ninja -DDXC_EXECUTABLE=/bin/true -> configure OK
  • Win2025 (Windows Server 2025, WARP) on head f35405a5, x2w_pipe.py win2025 3194 --targets startup_clear_depth_stencil,startup_packed_target_check --regex '^startup_(clear_depth_stencil|packed_target)' --force:
    • dev (Debug): 13/13 passed (startup_clear_depth_stencil_warp, _hardware, startup_packed_target, its 8 WILL_FAIL controls including raw-clear_control, startup_packed_target_draw_warp, _hardware)
    • release: 13/13 passed (same set)
  • The first Stage-2 run on a8f19ac9 did not build: MSVC rejected a constexpr local used inside a capture-less lambda in tests/startup_packed_target_check.cpp; f35405a5 inlines the offsetof.

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:5533253966 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3194). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:22:20Z. --- Part of #870 What this unblocks: depth/stencil and 10-bit float targets made with a console-only format keep their optimized clear value on desktop D3D12, so the title's clears match it. The shim already maps the console-only DXGI values 116-120 (two 10-bit float formats, D16_UNORM_S8_UINT and its two typed views) to the nearest desktop formats when it creates a resource. The optimized clear value passed with that resource kept the console format, so desktop D3D12 got a clear format that no longer matched the created resource (ID3D12Device::CreateCommittedResource / CreatePlacedResource / CreateReservedResource, `pOptimizedClearValue`), and later clears were reported as mismatching. This change: - moves the 116-120 mapping into one header, `src/startup_stubs/clear_value_format.h` (`desktop_format`, `desktop_clear_value`), used by the device shim and by `xg_xs.cpp` instead of two copies; - maps the clear value format through the same table on committed, placed and reserved creation (slot 30 takes its clear value in the third argument), and still swaps it to the stand-in format when a packed target was substituted. Tests: - `startup_clear_depth_stencil_warp`: new case D creates a 1x1 console-format-118 depth target with a matching clear value through slot 76 and clears it; the run fails on a debug-layer `CLEARDEPTHSTENCILVIEW_MISMATCHINGCLEARVALUE` message or a dropped clear in the log. - `startup_packed_target` + new `startup_packed_target_raw-clear_control` (WILL_FAIL): CPU check of `desktop_clear_value` for console formats 116, 117 and 118 and for the packed stand-in; the control forwards format 118 unchanged and must fail. Verification: - `x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -x c++ -Isrc -Isrc/startup_stubs src/startup_stubs/clear_value_format.h` -> OK - `cmake -S . -B /tmp/cfg -G Ninja -DDXC_EXECUTABLE=/bin/true` -> configure OK - Win2025 (Windows Server 2025, WARP) on head f35405a5, `x2w_pipe.py win2025 3194 --targets startup_clear_depth_stencil,startup_packed_target_check --regex '^startup_(clear_depth_stencil|packed_target)' --force`: - dev (Debug): 13/13 passed (`startup_clear_depth_stencil_warp`, `_hardware`, `startup_packed_target`, its 8 WILL_FAIL controls including `raw-clear_control`, `startup_packed_target_draw_warp`, `_hardware`) - release: 13/13 passed (same set) - The first Stage-2 run on a8f19ac9 did not build: MSVC rejected a `constexpr` local used inside a capture-less lambda in `tests/startup_packed_target_check.cpp`; f35405a5 inlines the `offsetof`. 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.
KelboLive commented 2026-11-27 23:53:04 +00:00 (Migrated from github.com)

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


Review of f35405a5 (two commits):

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7230480554 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3194#issuecomment-7230480554). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T23:53:04Z. --- Review of `f35405a5` (two commits):
tedin7 commented 2026-11-28 10:49:12 +00:00 (Migrated from github.com)

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


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

Tested at f35405a (current head). dev preset, ctest run one test at a time:

  • ctest on the touched block: 100% tests passed, 0 tests failed out of 13 (includes startup_clear_depth_stencil_hardware and startup_packed_target_draw_hardware).
  • Mutant patch: none for this PR.

These complement the existing WARP runs.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7238142807 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3194#issuecomment-7238142807). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T10:49:12Z. --- Real-GPU verification (NVIDIA RTX 3070 Ti, driver 32.0.16.2101, Windows 11): Tested at f35405a (current head). dev preset, ctest run one test at a time: - ctest on the touched block: 100% tests passed, 0 tests failed out of 13 (includes startup_clear_depth_stencil_hardware and startup_packed_target_draw_hardware). - Mutant patch: none for this PR. These complement the existing WARP runs. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot] commented 2026-11-28 10:49:25 +00:00 (Migrated from github.com)

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


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:51:37.566297Z f35405a 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:7238145168 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3194#issuecomment-7238145168). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:49:25Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"f35405a5b49f78f52d6bafbe99c820c5a24cbad7","has_any_findings":false,"has_unresolved_findings":false,"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:51:37.566297Z">2026-11-28T10:51:37.566297Z</relative-time> | `f35405a` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
tedin7 commented 2026-11-28 22:07:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T22:07:56Z.


Merged current main into this branch (merge commit, no force push, no conflicts); head is now 637a102b2. No change to the PR's own files.

Verification (Windows Server 2025, D3D12 WARP, head 637a102b2): x2w_pipe.py win2025 3194 --regex '^startup_(packed_target|clear)' -> 15/15 passed.

@MasterDomino ready for review and merge when you have time. KelboLive's review of f35405a5 has no open asks.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7246518110 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3194#issuecomment-7246518110). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T22:07:56Z. --- Merged current `main` into this branch (merge commit, no force push, no conflicts); head is now `637a102b2`. No change to the PR's own files. Verification (Windows Server 2025, D3D12 WARP, head `637a102b2`): `x2w_pipe.py win2025 3194 --regex '^startup_(packed_target|clear)'` -> 15/15 passed. @MasterDomino ready for review and merge when you have time. KelboLive's review of `f35405a5` has no open asks. AI-assisted; commands listed were executed locally.
pigalot commented 2026-11-29 08:05:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-29T08:05:22Z.

Review: APPROVED


Independently reviewed 637a102b integrated over main 212d4b5f (tree ca374ec7). The trial merge is clean and git diff --check is clean. The branch's merge of main (637a102b, by the author) has no conflict resolution in it.

What I traced

  • desktop_format in the new clear_value_format.h is the same 116-120 table that d3d12_xs_device.cpp and xg_xs.cpp each carried; the device shim keeps its logging wrapper around it.
  • desktop_clear_value against the old packed_clear_value: for the packed stand-in case the condition is the same (packed_target_mapping only returns a mapping whose requested equals the mapped description format). The new part is that the clear format goes through the 116-120 table first, and a copy is made whenever the format changes.
  • Clear-value argument positions in create_slot: slot 27 CreateCommittedResource(props, flags, desc, state, clear, …) and slot 29 CreatePlacedResource(heap, offset, desc, state, clear, …) take it as argument 4, slot 30 CreateReservedResource(desc, state, clear, …) as argument 2. That matches the vtable order and the enable_create<device_kind, 30, 3, 0> registration.
  • Test changes: A and B now get optimized clear values equal to what they are cleared with (0.25 and 0.75), which is needed once the callback ignores filters. A missing message callback is now a skip (77) instead of a pass without validation. Neither weakens the test; here the callback registered and nothing skipped.

Results

Built startup_clear_depth_stencil, startup_packed_target_check and the shim in dev and release, then ran
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_(clear_depth_stencil_warp|packed_target)' -E '_hardware$':
11 of 11 passed in Debug and in Release /O2, no skips (startup_clear_depth_stencil_warp, startup_packed_target, its 8 WILL_FAIL controls including raw-clear_control, startup_packed_target_draw_warp).
startup_clear_depth_stencil_hardware and startup_packed_target_draw_hardware passed in both presets with the debug layer on, no skips. The slot 76 log line shows fmt=118 with the clear kept (no (dropped)).

Negative control: with main's d3d12_xs_device.cpp and this PR's tests, startup_clear_depth_stencil_warp fails on the (dropped) log marker.

Mutants (Debug, ctest -R '^startup_(packed_target|clear)' -E '_hardware$', 12 tests):

  • Killed:
    • slot 76 forwards the title's clear value unchanged: startup_clear_depth_stencil_warp fails on the (dropped) marker.
    • the helper does not map the clear format: startup_clear_depth_stencil_warp and startup_packed_target fail.
    • the helper never switches to the stand-in format: startup_packed_target fails.
    • the helper drops the format == mapping->requested condition: startup_packed_target fails.
    • the helper drops copy = *clear: both fail.
  • Survived:
    • slot 30 reads the clear value from argument 4 instead of 2.
    • slot 30 removed from the N == 27 || N == 29 || N == 30 condition.
    • slots 27 and 29 removed from that condition.
    • slot 133 (device_place_resource_x) forwards the title's clear value unchanged.
  • Equivalent:
    • dropping created_format == mapping->replacement: at every call site the created format is either the replacement or the requested format, so the result is the same.
    • dropping desktop_format around title_desc_format: no packed format is in 116-120.

Notes (not blocking)

  1. The survivors mean only slot 76 and the CPU helper are exercised. The slot 27, 29, 30 and 133 call sites, including the new slot 30 argument index, are covered by reading only; the 27, 29 and 133 gap for the stand-in case was already there on main. A follow-up case that creates a format-118 target through slot 30 (and one of 27 or 29) would close it.
  2. A clear value given as format 119 or 120 maps to R24_UNORM_X8_TYPELESS or X24_TYPELESS_G8_UINT, which desktop D3D12 does not accept as a clear format. Slot 76 then retries without the clear value; the other slots do not. That was already so on main (the raw value was refused the same way), so it is not a regression.

Wider runs

  • Full dev build, then ctest --test-dir out/build/dev --no-tests=error -j 6 -E '(_hardware$|^startup_audio_)': two failures, startup_compute_dispatch_output_warp and startup_compute_half_buffer_uav_controls. Both fail the same way alone at -j 1, and both still fail with main's d3d12_xs_device.cpp and xg_xs.cpp swapped in, so they do not come from this PR.
  • The xg_xs.cpp users startup_ui_texture_bands_warp and startup_nv12_draw_warp pass in Release.
  • A local real-title startup run of this head merged onto main 212d4b5f was judged no worse than the baseline run of main.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; NVIDIA GeForce RTX 5090, driver 32.0.16.1088, D3D12 debug layer on for the hardware runs; WARP for the _warp tests.
CI: Build and test on Windows passed on 637a102b; its test subset does not include the tests this PR changes.

Approving 637a102b.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6102015261 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3194#pullrequestreview-6102015261). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-29T08:05:22Z. **Review:** APPROVED --- Independently reviewed `637a102b` integrated over `main` `212d4b5f` (tree `ca374ec7`). The trial merge is clean and `git diff --check` is clean. The branch's merge of `main` (`637a102b`, by the author) has no conflict resolution in it. **What I traced** - `desktop_format` in the new `clear_value_format.h` is the same 116-120 table that `d3d12_xs_device.cpp` and `xg_xs.cpp` each carried; the device shim keeps its logging wrapper around it. - `desktop_clear_value` against the old `packed_clear_value`: for the packed stand-in case the condition is the same (`packed_target_mapping` only returns a mapping whose `requested` equals the mapped description format). The new part is that the clear format goes through the 116-120 table first, and a copy is made whenever the format changes. - Clear-value argument positions in `create_slot`: slot 27 `CreateCommittedResource(props, flags, desc, state, clear, …)` and slot 29 `CreatePlacedResource(heap, offset, desc, state, clear, …)` take it as argument 4, slot 30 `CreateReservedResource(desc, state, clear, …)` as argument 2. That matches the vtable order and the `enable_create<device_kind, 30, 3, 0>` registration. - Test changes: A and B now get optimized clear values equal to what they are cleared with (0.25 and 0.75), which is needed once the callback ignores filters. A missing message callback is now a skip (77) instead of a pass without validation. Neither weakens the test; here the callback registered and nothing skipped. **Results** Built `startup_clear_depth_stencil`, `startup_packed_target_check` and the shim in `dev` and `release`, then ran `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_(clear_depth_stencil_warp|packed_target)' -E '_hardware$'`: 11 of 11 passed in Debug and in Release `/O2`, no skips (`startup_clear_depth_stencil_warp`, `startup_packed_target`, its 8 `WILL_FAIL` controls including `raw-clear_control`, `startup_packed_target_draw_warp`). `startup_clear_depth_stencil_hardware` and `startup_packed_target_draw_hardware` passed in both presets with the debug layer on, no skips. The slot 76 log line shows `fmt=118` with the clear kept (no `(dropped)`). Negative control: with `main`'s `d3d12_xs_device.cpp` and this PR's tests, `startup_clear_depth_stencil_warp` fails on the `(dropped)` log marker. Mutants (Debug, `ctest -R '^startup_(packed_target|clear)' -E '_hardware$'`, 12 tests): - Killed: - slot 76 forwards the title's clear value unchanged: `startup_clear_depth_stencil_warp` fails on the `(dropped)` marker. - the helper does not map the clear format: `startup_clear_depth_stencil_warp` and `startup_packed_target` fail. - the helper never switches to the stand-in format: `startup_packed_target` fails. - the helper drops the `format == mapping->requested` condition: `startup_packed_target` fails. - the helper drops `copy = *clear`: both fail. - Survived: - slot 30 reads the clear value from argument 4 instead of 2. - slot 30 removed from the `N == 27 || N == 29 || N == 30` condition. - slots 27 and 29 removed from that condition. - slot 133 (`device_place_resource_x`) forwards the title's clear value unchanged. - Equivalent: - dropping `created_format == mapping->replacement`: at every call site the created format is either the replacement or the requested format, so the result is the same. - dropping `desktop_format` around `title_desc_format`: no packed format is in 116-120. **Notes (not blocking)** 1. The survivors mean only slot 76 and the CPU helper are exercised. The slot 27, 29, 30 and 133 call sites, including the new slot 30 argument index, are covered by reading only; the 27, 29 and 133 gap for the stand-in case was already there on `main`. A follow-up case that creates a format-118 target through slot 30 (and one of 27 or 29) would close it. 2. A clear value given as format 119 or 120 maps to `R24_UNORM_X8_TYPELESS` or `X24_TYPELESS_G8_UINT`, which desktop D3D12 does not accept as a clear format. Slot 76 then retries without the clear value; the other slots do not. That was already so on `main` (the raw value was refused the same way), so it is not a regression. **Wider runs** - Full `dev` build, then `ctest --test-dir out/build/dev --no-tests=error -j 6 -E '(_hardware$|^startup_audio_)'`: two failures, `startup_compute_dispatch_output_warp` and `startup_compute_half_buffer_uav_controls`. Both fail the same way alone at `-j 1`, and both still fail with `main`'s `d3d12_xs_device.cpp` and `xg_xs.cpp` swapped in, so they do not come from this PR. - The `xg_xs.cpp` users `startup_ui_texture_bands_warp` and `startup_nv12_draw_warp` pass in Release. - A local real-title startup run of this head merged onto `main` `212d4b5f` was judged no worse than the baseline run of `main`. Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; NVIDIA GeForce RTX 5090, driver 32.0.16.1088, D3D12 debug layer on for the hardware runs; WARP for the `_warp` tests. CI: `Build and test on Windows` passed on `637a102b`; its test subset does not include the tests this PR changes. Approving `637a102b`. This reply was AI-assisted.
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!3194
No description provided.