startup: validate title UAV, RTV and DSV views before forwarding #3200

Open
tedin7 wants to merge 5 commits from upstream-pr/3200 into main
tedin7 commented 2026-11-27 21:29:55 +00:00 (Migrated from github.com)

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


Part of #870

What this unblocks: title UAV, RTV and DSV views that D3D12 would reject are repaired or refused before they reach the desktop device, so real GPUs and the debug layer stop failing on them.

Console view descriptions can name a MipSlice past the resource, an array or W range longer than what remains, a PlaneSlice on a single-plane format, a view format outside the resource's format family, a DSV with a color or UNKNOWN format, a read-only-stencil DSV on a format without stencil, a multisample dimension on a single-sample resource (or the reverse), a multisample UAV, or a UAV counter on a resource or offset D3D12 does not allow (see "ID3D12Device::CreateUnorderedAccessView", "ID3D12Device::CreateRenderTargetView", "ID3D12Device::CreateDepthStencilView" and "D3D12_UNORDERED_ACCESS_VIEW_DESC" on Microsoft Learn). Forwarding these breaks the debug layer and can remove the device on hardware.

The new header src/startup_stubs/target_view_check.h checks device slots 19-21 after the existing dimension and format checks in view_slot:

  • repaired on a copy: array/W size clamped to what remains (W size ~0 kept), PlaneSlice 0 on single-plane formats, view format replaced by the resource format when the cast is not allowed (typed casts follow CastingFullyTypedFormatSupported), DSV format replaced by the resource's depth format, read-only-stencil flag dropped without a stencil plane, a counter offset without a counter resource reset to 0,
  • refused through the existing skip path: MipSlice or first slice outside the resource, null resource with no description, wrong or multisample-mismatched dimension, a format with no typed fallback, a counter on anything but a structured buffer at an aligned in-range offset, plane slice > 1.

The depth-format and format-cast helpers are local to this header; if the sibling SRV validation draft lands first, the two share one copy.

Tests:

  • startup_target_view_check (CPU): valid descriptions stay byte-identical; each repair and each refusal above.
  • startup_target_views_warp (title view calls through the shim on a WARP device with the debug layer on; passes only with zero debug-layer errors and no device removal; without the new check in view_slot the bad MipSlice RTV reaches the debug layer and removes the WARP device, see Verification). startup_target_views_hardware skips (77) without a hardware adapter.

Verification:

  • x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Wall -Isrc tests/startup_target_view_check.cpp -> OK
  • x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_target_views_device.cpp -> OK
  • cmake -S . -B <tmp> -G Ninja -DDXC_EXECUTABLE=/bin/true -> configure OK
  • python3 tests/bidi_controls_check.py -> passed
  • Win2025 (Build 26100, MSVC 14.44, D3D12 WARP) at 9e6d28f7, targets d3d12_xs_device_obj d3d12_xs_shim startup_target_view_check startup_target_views_device startup_view_dimension startup_null_views_check startup_resource_retire_views:
    • dev: ctest --preset dev -R '^(startup_target_view_check|startup_target_views_|startup_view_dimension|startup_null_views_|startup_resource_retire_views_)' -> 18/18 passed
    • release (/O2): same regex -> 18/18 passed
    • fails before: the same head with only the view_slot check reverted (tests kept), ctest --preset dev -R '^startup_target_views_warp$' -> 0/1 passed (debug layer: CreateRenderTargetView ... MipSlice (value = 9), then device removed 0x887a0001)

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:5533324852 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:29:55Z. --- Part of #870 What this unblocks: title UAV, RTV and DSV views that D3D12 would reject are repaired or refused before they reach the desktop device, so real GPUs and the debug layer stop failing on them. Console view descriptions can name a MipSlice past the resource, an array or W range longer than what remains, a PlaneSlice on a single-plane format, a view format outside the resource's format family, a DSV with a color or UNKNOWN format, a read-only-stencil DSV on a format without stencil, a multisample dimension on a single-sample resource (or the reverse), a multisample UAV, or a UAV counter on a resource or offset D3D12 does not allow (see "ID3D12Device::CreateUnorderedAccessView", "ID3D12Device::CreateRenderTargetView", "ID3D12Device::CreateDepthStencilView" and "D3D12_UNORDERED_ACCESS_VIEW_DESC" on Microsoft Learn). Forwarding these breaks the debug layer and can remove the device on hardware. The new header `src/startup_stubs/target_view_check.h` checks device slots 19-21 after the existing dimension and format checks in `view_slot`: - repaired on a copy: array/W size clamped to what remains (W size ~0 kept), PlaneSlice 0 on single-plane formats, view format replaced by the resource format when the cast is not allowed (typed casts follow `CastingFullyTypedFormatSupported`), DSV format replaced by the resource's depth format, read-only-stencil flag dropped without a stencil plane, a counter offset without a counter resource reset to 0, - refused through the existing skip path: MipSlice or first slice outside the resource, null resource with no description, wrong or multisample-mismatched dimension, a format with no typed fallback, a counter on anything but a structured buffer at an aligned in-range offset, plane slice > 1. The depth-format and format-cast helpers are local to this header; if the sibling SRV validation draft lands first, the two share one copy. Tests: - `startup_target_view_check` (CPU): valid descriptions stay byte-identical; each repair and each refusal above. - `startup_target_views_warp` (title view calls through the shim on a WARP device with the debug layer on; passes only with zero debug-layer errors and no device removal; without the new check in `view_slot` the bad MipSlice RTV reaches the debug layer and removes the WARP device, see Verification). `startup_target_views_hardware` skips (77) without a hardware adapter. Verification: - `x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Wall -Isrc tests/startup_target_view_check.cpp` -> OK - `x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -Isrc tests/startup_target_views_device.cpp` -> OK - `cmake -S . -B <tmp> -G Ninja -DDXC_EXECUTABLE=/bin/true` -> configure OK - `python3 tests/bidi_controls_check.py` -> passed - Win2025 (Build 26100, MSVC 14.44, D3D12 WARP) at `9e6d28f7`, targets `d3d12_xs_device_obj d3d12_xs_shim startup_target_view_check startup_target_views_device startup_view_dimension startup_null_views_check startup_resource_retire_views`: - dev: `ctest --preset dev -R '^(startup_target_view_check|startup_target_views_|startup_view_dimension|startup_null_views_|startup_resource_retire_views_)'` -> 18/18 passed - release (`/O2`): same regex -> 18/18 passed - fails before: the same head with only the `view_slot` check reverted (tests kept), `ctest --preset dev -R '^startup_target_views_warp$'` -> 0/1 passed (debug layer: `CreateRenderTargetView ... MipSlice (value = 9)`, then device removed `0x887a0001`) 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:44:52 +00:00 (Migrated from github.com)

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

Review: APPROVED


Review of PR #3200 — startup: validate title UAV, RTV and DSV views before forwarding

Summary

This PR adds src/startup_stubs/target_view_check.h — a device-independent validation library for D3D12 target views (UAV, RTV, DSV). It validates view descriptors against their underlying resources, repairing invalid fields when possible and refusing when fundamentally incompatible.

Changes reviewed

  • src/startup_stubs/target_view_check.h: New 167-line header with check() template function for UAV/RTV/DSV validation. Includes format cast fitting logic (respecting typeless casting rules), planar video format handling, depth-stencil aspect selection, mip/array bounds checking, counter placement validation (check_uav), and repair callback pattern.
  • Integration: d3d12_xs_device.cpp applies this validation before forwarding views to the desktop device, with refusal counting for diagnostics.

Assessment

The implementation is thorough and well-designed:

  • The template-based approach cleanly handles all three view types (UAV/RTV/DSV) with compile-time dispatch via constexpr if.
  • Format cast fitting respects D3D12's casting rules: typeless resources can be viewed as any compatible format, typed resources require fully-typed-casting support and can't mix float/non-float or snorm/unorm.
  • Planar video format handling (NV12, P010, P016) correctly validates plane slice bounds.
  • Counter placement validation in check_uav ensures proper alignment and size for structured buffer counters.
  • The repair callback pattern allows callers to observe what changed while keeping the view valid.

Verdict: Approve

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6094384805 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#pullrequestreview-6094384805). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T23:44:52Z. **Review:** APPROVED --- ## Review of PR #3200 — startup: validate title UAV, RTV and DSV views before forwarding ### Summary This PR adds `src/startup_stubs/target_view_check.h` — a device-independent validation library for D3D12 target views (UAV, RTV, DSV). It validates view descriptors against their underlying resources, repairing invalid fields when possible and refusing when fundamentally incompatible. ### Changes reviewed - **`src/startup_stubs/target_view_check.h`**: New 167-line header with `check()` template function for UAV/RTV/DSV validation. Includes format cast fitting logic (respecting typeless casting rules), planar video format handling, depth-stencil aspect selection, mip/array bounds checking, counter placement validation (`check_uav`), and repair callback pattern. - **Integration**: `d3d12_xs_device.cpp` applies this validation before forwarding views to the desktop device, with refusal counting for diagnostics. ### Assessment The implementation is thorough and well-designed: - The template-based approach cleanly handles all three view types (UAV/RTV/DSV) with compile-time dispatch via `constexpr if`. - Format cast fitting respects D3D12's casting rules: typeless resources can be viewed as any compatible format, typed resources require fully-typed-casting support and can't mix float/non-float or snorm/unorm. - Planar video format handling (NV12, P010, P016) correctly validates plane slice bounds. - Counter placement validation in `check_uav` ensures proper alignment and size for structured buffer counters. - The repair callback pattern allows callers to observe what changed while keeping the view valid. ### Verdict: Approve
tedin7 commented 2026-11-28 10:49:23 +00:00 (Migrated from github.com)

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


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

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

  • ctest on the touched block: 100% tests passed, 0 tests failed out of 18.
  • Mutant patch applied: 89% passed, 2 of 18 failed, exactly the expected ones: startup_target_views_warp, startup_target_views_hardware.

These complement the existing WARP runs.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7238144799 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#issuecomment-7238144799). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T10:49:23Z. --- Real-GPU verification (NVIDIA RTX 3070 Ti, driver 32.0.16.2101, Windows 11): Tested at 9e6d28f (current head). dev preset, ctest run one test at a time: - ctest on the touched block: 100% tests passed, 0 tests failed out of 18. - Mutant patch applied: 89% passed, 2 of 18 failed, exactly the expected ones: startup_target_views_warp, startup_target_views_hardware. These complement the existing WARP runs. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot] commented 2026-11-28 10:49:36 +00:00 (Migrated from github.com)

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


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:55:12.970262Z 9e6d28f 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:7238146987 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#issuecomment-7238146987). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:49:36Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"9e6d28f7bf1f5ec9b10755bc2867451f98376f5a","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:55:12.970262Z">2026-11-28T10:55:12.970262Z</relative-time> | `9e6d28f` | 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:55:10 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e6d28f7bf

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

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

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

@@ -5181,6 +5182,61 @@ __declspec(noinline) u64 view_slot(Wrapper* self, u64 a, u64 b, u64 c, u64 d)
             args[1] = reinterpret_cast<u64>(&null_rtv);
     }
     if (default_view) args[desc_index] = 0;
+    // UAV, RTV and DSV descriptions are checked against the resource before they are forwarded
+    // (target_view_check.h): repairable fields are clamped on a copy, a description D3D12 rejects is refused.
+    if constexpr (N >= 19 && N <= 21) {
+        using namespace x2w_startup::target_view;
+        auto* resource = reinterpret_cast<ID3D12Resource*>(args[0]);
+        D3D12_RESOURCE_DESC backing{};
+        if (resource) backing = resource->GetDesc();
+        D3D12_RESOURCE_DESC counter_desc{};
+        auto* counter = N == 19 ? reinterpret_cast<ID3D12Resource*>(args[1]) : nullptr;
+        if (counter) counter_desc = counter->GetDesc();
+        using Desc = std::conditional_t<N == 19, D3D12_UNORDERED_ACCESS_VIEW_DESC,
+            std::conditional_t<N == 20, D3D12_RENDER_TARGET_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC>>;
+        Desc checked{};
+        Desc* view = nullptr;
+        if (args[desc_index]) {
+            auto* input = reinterpret_cast<const Desc*>(args[desc_index]);
+            if (!x2w_local::readable(input, sizeof(*input))) {
+                refuse_view();
+                return 0;
+            }
+            std::memcpy(&checked, input, sizeof(checked));
+            view = &checked;
+        }
+        D3D12_FEATURE_DATA_D3D12_OPTIONS3 options{};
+        if (resource && view && view->Format != backing.Format && !x2w_startup::is_typeless(backing.Format))
+            device_of(self)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &options, sizeof(options));
+        const auto repair = [&](const char* field, UINT64 old_value, UINT64 new_value) {
+            static LONG counts[6]{};
+            const unsigned index = !std::strcmp(field, "ArraySize") ? 0 : !std::strcmp(field, "WSize") ? 1 :
+                !std::strcmp(field, "PlaneSlice") ? 2 : !std::strcmp(field, "Flags") ? 3 :
+                !std::strcmp(field, "Format") ? 4 : 5;
+            if (first_calls(counts[index], 6))
+                log("x2w-d3d12 view repaired: slot%d %s %llu -> %llu (resource %llux%u mips %u fmt %u)", N, field,
+                    static_cast<unsigned long long>(old_value), static_cast<unsigned long long>(new_value),
+                    static_cast<unsigned long long>(backing.Width), backing.Height, backing.MipLevels,
+                    static_cast<unsigned>(backing.Format));
+        };
+        Refusal refusal;
+        if constexpr (N == 19)
+            refusal = check_uav(view, resource ? &backing : nullptr, counter ? &counter_desc : nullptr, repair,
+                                options.CastingFullyTypedFormatSupported != FALSE);
+        else
+            refusal = check(view, resource ? &backing : nullptr, repair, options.CastingFullyTypedFormatSupported != FALSE);
+        if (refusal != Refusal::none) {
+            static LONG counts[static_cast<unsigned>(Refusal::plane) + 1]{};
+            if (first_calls(counts[static_cast<unsigned>(refusal)], 6))
+                log("x2w-d3d12 view refused: slot%d %s", N, reason(refusal));
+            refuse_view();
+            return 0;
+        }
+        if (view) {
+            std::memcpy(desc_copy, view, sizeof(*view));
+            args[desc_index] = reinterpret_cast<u64>(desc_copy);

P1 Badge Persist repaired descriptions in materialized view records

When a UAV is repaired, record_view(created) still calls note_view with the original c, not the repaired description. record_translated_dispatch() reads that record in d3d12_compute_dispatch.inl:473–520 and recreates the UAV at lines 622–623 without this validation. For example, an R32_FLOAT view on an R8G8B8A8_UNORM resource is repaired initially, but the incompatible R32_FLOAT description is forwarded again during dispatch, reintroducing the debug-layer/device-removal failure. Repaired array sizes and plane slices can instead cause the dispatch to be refused. Store the effective description for downstream consumers rather than changing only the initial native-call arguments.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726656364 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#discussion_r4726656364). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:55:10Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 5237 ~~~~diff @@ -5181,6 +5182,61 @@ __declspec(noinline) u64 view_slot(Wrapper* self, u64 a, u64 b, u64 c, u64 d) args[1] = reinterpret_cast<u64>(&null_rtv); } if (default_view) args[desc_index] = 0; + // UAV, RTV and DSV descriptions are checked against the resource before they are forwarded + // (target_view_check.h): repairable fields are clamped on a copy, a description D3D12 rejects is refused. + if constexpr (N >= 19 && N <= 21) { + using namespace x2w_startup::target_view; + auto* resource = reinterpret_cast<ID3D12Resource*>(args[0]); + D3D12_RESOURCE_DESC backing{}; + if (resource) backing = resource->GetDesc(); + D3D12_RESOURCE_DESC counter_desc{}; + auto* counter = N == 19 ? reinterpret_cast<ID3D12Resource*>(args[1]) : nullptr; + if (counter) counter_desc = counter->GetDesc(); + using Desc = std::conditional_t<N == 19, D3D12_UNORDERED_ACCESS_VIEW_DESC, + std::conditional_t<N == 20, D3D12_RENDER_TARGET_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC>>; + Desc checked{}; + Desc* view = nullptr; + if (args[desc_index]) { + auto* input = reinterpret_cast<const Desc*>(args[desc_index]); + if (!x2w_local::readable(input, sizeof(*input))) { + refuse_view(); + return 0; + } + std::memcpy(&checked, input, sizeof(checked)); + view = &checked; + } + D3D12_FEATURE_DATA_D3D12_OPTIONS3 options{}; + if (resource && view && view->Format != backing.Format && !x2w_startup::is_typeless(backing.Format)) + device_of(self)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &options, sizeof(options)); + const auto repair = [&](const char* field, UINT64 old_value, UINT64 new_value) { + static LONG counts[6]{}; + const unsigned index = !std::strcmp(field, "ArraySize") ? 0 : !std::strcmp(field, "WSize") ? 1 : + !std::strcmp(field, "PlaneSlice") ? 2 : !std::strcmp(field, "Flags") ? 3 : + !std::strcmp(field, "Format") ? 4 : 5; + if (first_calls(counts[index], 6)) + log("x2w-d3d12 view repaired: slot%d %s %llu -> %llu (resource %llux%u mips %u fmt %u)", N, field, + static_cast<unsigned long long>(old_value), static_cast<unsigned long long>(new_value), + static_cast<unsigned long long>(backing.Width), backing.Height, backing.MipLevels, + static_cast<unsigned>(backing.Format)); + }; + Refusal refusal; + if constexpr (N == 19) + refusal = check_uav(view, resource ? &backing : nullptr, counter ? &counter_desc : nullptr, repair, + options.CastingFullyTypedFormatSupported != FALSE); + else + refusal = check(view, resource ? &backing : nullptr, repair, options.CastingFullyTypedFormatSupported != FALSE); + if (refusal != Refusal::none) { + static LONG counts[static_cast<unsigned>(Refusal::plane) + 1]{}; + if (first_calls(counts[static_cast<unsigned>(refusal)], 6)) + log("x2w-d3d12 view refused: slot%d %s", N, reason(refusal)); + refuse_view(); + return 0; + } + if (view) { + std::memcpy(desc_copy, view, sizeof(*view)); + args[desc_index] = reinterpret_cast<u64>(desc_copy); ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Persist repaired descriptions in materialized view records** When a UAV is repaired, `record_view(created)` still calls `note_view` with the original `c`, not the repaired description. `record_translated_dispatch()` reads that record in `d3d12_compute_dispatch.inl:473–520` and recreates the UAV at lines 622–623 without this validation. For example, an `R32_FLOAT` view on an `R8G8B8A8_UNORM` resource is repaired initially, but the incompatible `R32_FLOAT` description is forwarded again during dispatch, reintroducing the debug-layer/device-removal failure. Repaired array sizes and plane slices can instead cause the dispatch to be refused. Store the effective description for downstream consumers rather than changing only the initial native-call arguments. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot] commented 2026-11-28 10:55:10 +00:00 (Migrated from github.com)

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

Code review location: src/startup_stubs/target_view_check.h; line 131

@@ -0,0 +1,166 @@
+// Device-independent checks for UAV, RTV and DSV descriptions.
+#pragma once
+#include "startup_stubs/list_copy.h"
+#include "startup_stubs/view_dimension.h"
+
+#include <d3d12.h>
+
+#include <algorithm>
+#include <type_traits>
+
+namespace x2w_startup::target_view {
+// DXGI depth formats a DSV may name (CreateDepthStencilView).
+inline bool depth_format(DXGI_FORMAT format)
+{
+    return format == DXGI_FORMAT_D16_UNORM || format == DXGI_FORMAT_D32_FLOAT ||
+        format == DXGI_FORMAT_D24_UNORM_S8_UINT || format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
+}
+// Depth-stencil families with a stencil plane (plane slice 1).
+inline bool planar_depth_stencil(DXGI_FORMAT format)
+{
+    const auto family = format_family(format);
+    return family == DXGI_FORMAT_R24G8_TYPELESS || family == DXGI_FORMAT_R32G8X24_TYPELESS;
+}
+enum class NumericFormat { other, floating, snorm, unorm };
+inline NumericFormat numeric_format(DXGI_FORMAT format)
+{
+    switch (format) {
+    case DXGI_FORMAT_R32G32B32A32_FLOAT: case DXGI_FORMAT_R32G32B32_FLOAT:
+    case DXGI_FORMAT_R32G32_FLOAT: case DXGI_FORMAT_R32_FLOAT:
+    case DXGI_FORMAT_R16G16B16A16_FLOAT: case DXGI_FORMAT_R16G16_FLOAT: case DXGI_FORMAT_R16_FLOAT:
+        return NumericFormat::floating;
+    case DXGI_FORMAT_R16G16B16A16_SNORM: case DXGI_FORMAT_R16G16_SNORM: case DXGI_FORMAT_R16_SNORM:
+    case DXGI_FORMAT_R8G8B8A8_SNORM: case DXGI_FORMAT_R8G8_SNORM: case DXGI_FORMAT_R8_SNORM:
+        return NumericFormat::snorm;
+    case DXGI_FORMAT_R16G16B16A16_UNORM: case DXGI_FORMAT_R16G16_UNORM: case DXGI_FORMAT_R16_UNORM:
+    case DXGI_FORMAT_R8G8B8A8_UNORM: case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
+    case DXGI_FORMAT_R8G8_UNORM: case DXGI_FORMAT_R8_UNORM:
+        return NumericFormat::unorm;
+    default:
+        return NumericFormat::other;
+    }
+}
+// A view may name another member of the resource's format family when the resource is typeless; a typed resource
+// needs D3D12_FEATURE_DATA_D3D12_OPTIONS3::CastingFullyTypedFormatSupported, never for depth, and the cast keeps
+// float/non-float and snorm/unorm apart.
+inline bool format_cast_fits(DXGI_FORMAT resource, DXGI_FORMAT view, bool fully_typed_casting)
+{
+    if (resource == view) return true;
+    if (!compatible_formats(resource, view)) return false;
+    if (is_typeless(resource)) return true;
+    if (!fully_typed_casting || depth_format(resource)) return false;
+    const auto from = numeric_format(resource);
+    const auto to = numeric_format(view);
+    if ((from == NumericFormat::floating) != (to == NumericFormat::floating)) return false;
+    return !((from == NumericFormat::snorm && to == NumericFormat::unorm) ||
+             (from == NumericFormat::unorm && to == NumericFormat::snorm));
+}
+enum class Refusal { none, null_desc, dimension, mip, array, format, counter, plane };
+inline const char* reason(Refusal r) {
+    switch (r) {
+    case Refusal::null_desc: return "null resource and description";
+    case Refusal::dimension: return "ViewDimension/SampleDesc.Count";
+    case Refusal::mip: return "MipSlice";
+    case Refusal::array: return "FirstArraySlice/ArraySize or FirstWSlice/WSize";
+    case Refusal::format: return "Format";
+    case Refusal::counter: return "counter resource/offset";
+    case Refusal::plane: return "PlaneSlice";
+    default: return "none";
+    }
+}
+struct Parts { UINT* mip = nullptr; UINT* first = nullptr; UINT* count = nullptr; UINT* plane = nullptr; bool volume = false; bool ms = false; bool buffer = false; };
+inline bool parts(D3D12_UNORDERED_ACCESS_VIEW_DESC& v, Parts& p) {
+    switch (v.ViewDimension) {
+    case D3D12_UAV_DIMENSION_BUFFER: p.buffer = true; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE1D: p.mip = &v.Texture1D.MipSlice; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; p.plane=&v.Texture2D.PlaneSlice; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; p.plane=&v.Texture2DArray.PlaneSlice; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE3D: p.mip=&v.Texture3D.MipSlice; p.first=&v.Texture3D.FirstWSlice; p.count=&v.Texture3D.WSize; p.volume=true; return true;
+    default: return false;
+    }
+}
+inline bool parts(D3D12_RENDER_TARGET_VIEW_DESC& v, Parts& p) {
+    switch (v.ViewDimension) {
+    case D3D12_RTV_DIMENSION_BUFFER: p.buffer=true; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE1D: p.mip=&v.Texture1D.MipSlice; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; p.plane=&v.Texture2D.PlaneSlice; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; p.plane=&v.Texture2DArray.PlaneSlice; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE2DMS: p.ms=true; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY: p.ms=true; p.first=&v.Texture2DMSArray.FirstArraySlice; p.count=&v.Texture2DMSArray.ArraySize; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE3D: p.mip=&v.Texture3D.MipSlice; p.first=&v.Texture3D.FirstWSlice; p.count=&v.Texture3D.WSize; p.volume=true; return true;
+    default: return false;
+    }
+}
+inline bool parts(D3D12_DEPTH_STENCIL_VIEW_DESC& v, Parts& p) {
+    switch (v.ViewDimension) {
+    case D3D12_DSV_DIMENSION_TEXTURE1D: p.mip=&v.Texture1D.MipSlice; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE2DMS: p.ms=true; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY: p.ms=true; p.first=&v.Texture2DMSArray.FirstArraySlice; p.count=&v.Texture2DMSArray.ArraySize; return true;
+    default: return false;
+    }
+}
+// D3D12_UNORDERED_ACCESS_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC.
+template<class Desc, class Repair>
+Refusal check(Desc* v, const D3D12_RESOURCE_DESC* r, Repair repair, bool typed_cast = false) {
+    constexpr bool dsv = std::is_same_v<Desc, D3D12_DEPTH_STENCIL_VIEW_DESC>;
+    constexpr bool uav = std::is_same_v<Desc, D3D12_UNORDERED_ACCESS_VIEW_DESC>;
+    // ID3D12Device::CreateRenderTargetView / CreateDepthStencilView: a default view needs a typed format.
+    if (!v) {
+        if (!r) return Refusal::null_desc;
+        if (r->Format == DXGI_FORMAT_UNKNOWN || is_typeless(r->Format) ||
+            (dsv ? !depth_format(r->Format) : depth_format(r->Format))) return Refusal::format;
+        if constexpr (uav) if (r->SampleDesc.Count > 1) return Refusal::dimension;
+        return Refusal::none;
+    }
+    Parts p;
+    if (!parts(*v, p)) return Refusal::dimension;
+    if (r && !x2w_view_dimension::fits(uav ? 19 : dsv ? 21 : 20, static_cast<unsigned>(v->ViewDimension), static_cast<unsigned>(r->Dimension))) return Refusal::dimension;
+    if (r && ((uav && r->SampleDesc.Count > 1) || (!uav && p.ms != (r->SampleDesc.Count > 1)))) return Refusal::dimension;
+    auto allowed = [&](DXGI_FORMAT f) { return dsv ? depth_format(f) : f != DXGI_FORMAT_UNKNOWN && !is_typeless(f) && !depth_format(f); };
+    // A DSV format that is not a depth format (UNKNOWN included) takes the resource's typed depth format below, else
+    // the view is refused; a typeless depth family member (R32_TYPELESS) is cast by format_cast_fits.
+    bool special_buffer = false;
+    if constexpr (uav) special_buffer = p.buffer && (v->Buffer.StructureByteStride || v->Buffer.Flags == D3D12_BUFFER_UAV_FLAG_RAW);
+    if ((!allowed(v->Format) && !special_buffer) || (r && !p.buffer && !format_cast_fits(r->Format, v->Format, typed_cast))) {
+        if (!r || !allowed(r->Format)) return Refusal::format;
+        repair("Format", static_cast<UINT64>(v->Format), static_cast<UINT64>(r->Format)); v->Format = r->Format;

P1 Badge Preserve legal planar-resource view formats

On hardware supporting NV12 RTV/UAVs, legal plane views use R8_UNORM for plane 0 or R8G8_UNORM for plane 1, not NV12. Those formats are not in the resource's typeless format family, so format_cast_fits() returns false and this branch replaces a legal view format with NV12. The resulting invalid view is then forwarded to D3D12, introducing a device-removal path for descriptions that previously passed through unchanged; P010/P016 plane views have the same problem. Account for resource/plane/view-format compatibility before applying the generic format-family fallback.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726656368 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#discussion_r4726656368). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:55:10Z. **Code review location:** `src/startup_stubs/target_view_check.h`; line 131 ~~~~diff @@ -0,0 +1,166 @@ +// Device-independent checks for UAV, RTV and DSV descriptions. +#pragma once +#include "startup_stubs/list_copy.h" +#include "startup_stubs/view_dimension.h" + +#include <d3d12.h> + +#include <algorithm> +#include <type_traits> + +namespace x2w_startup::target_view { +// DXGI depth formats a DSV may name (CreateDepthStencilView). +inline bool depth_format(DXGI_FORMAT format) +{ + return format == DXGI_FORMAT_D16_UNORM || format == DXGI_FORMAT_D32_FLOAT || + format == DXGI_FORMAT_D24_UNORM_S8_UINT || format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT; +} +// Depth-stencil families with a stencil plane (plane slice 1). +inline bool planar_depth_stencil(DXGI_FORMAT format) +{ + const auto family = format_family(format); + return family == DXGI_FORMAT_R24G8_TYPELESS || family == DXGI_FORMAT_R32G8X24_TYPELESS; +} +enum class NumericFormat { other, floating, snorm, unorm }; +inline NumericFormat numeric_format(DXGI_FORMAT format) +{ + switch (format) { + case DXGI_FORMAT_R32G32B32A32_FLOAT: case DXGI_FORMAT_R32G32B32_FLOAT: + case DXGI_FORMAT_R32G32_FLOAT: case DXGI_FORMAT_R32_FLOAT: + case DXGI_FORMAT_R16G16B16A16_FLOAT: case DXGI_FORMAT_R16G16_FLOAT: case DXGI_FORMAT_R16_FLOAT: + return NumericFormat::floating; + case DXGI_FORMAT_R16G16B16A16_SNORM: case DXGI_FORMAT_R16G16_SNORM: case DXGI_FORMAT_R16_SNORM: + case DXGI_FORMAT_R8G8B8A8_SNORM: case DXGI_FORMAT_R8G8_SNORM: case DXGI_FORMAT_R8_SNORM: + return NumericFormat::snorm; + case DXGI_FORMAT_R16G16B16A16_UNORM: case DXGI_FORMAT_R16G16_UNORM: case DXGI_FORMAT_R16_UNORM: + case DXGI_FORMAT_R8G8B8A8_UNORM: case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_R8G8_UNORM: case DXGI_FORMAT_R8_UNORM: + return NumericFormat::unorm; + default: + return NumericFormat::other; + } +} +// A view may name another member of the resource's format family when the resource is typeless; a typed resource +// needs D3D12_FEATURE_DATA_D3D12_OPTIONS3::CastingFullyTypedFormatSupported, never for depth, and the cast keeps +// float/non-float and snorm/unorm apart. +inline bool format_cast_fits(DXGI_FORMAT resource, DXGI_FORMAT view, bool fully_typed_casting) +{ + if (resource == view) return true; + if (!compatible_formats(resource, view)) return false; + if (is_typeless(resource)) return true; + if (!fully_typed_casting || depth_format(resource)) return false; + const auto from = numeric_format(resource); + const auto to = numeric_format(view); + if ((from == NumericFormat::floating) != (to == NumericFormat::floating)) return false; + return !((from == NumericFormat::snorm && to == NumericFormat::unorm) || + (from == NumericFormat::unorm && to == NumericFormat::snorm)); +} +enum class Refusal { none, null_desc, dimension, mip, array, format, counter, plane }; +inline const char* reason(Refusal r) { + switch (r) { + case Refusal::null_desc: return "null resource and description"; + case Refusal::dimension: return "ViewDimension/SampleDesc.Count"; + case Refusal::mip: return "MipSlice"; + case Refusal::array: return "FirstArraySlice/ArraySize or FirstWSlice/WSize"; + case Refusal::format: return "Format"; + case Refusal::counter: return "counter resource/offset"; + case Refusal::plane: return "PlaneSlice"; + default: return "none"; + } +} +struct Parts { UINT* mip = nullptr; UINT* first = nullptr; UINT* count = nullptr; UINT* plane = nullptr; bool volume = false; bool ms = false; bool buffer = false; }; +inline bool parts(D3D12_UNORDERED_ACCESS_VIEW_DESC& v, Parts& p) { + switch (v.ViewDimension) { + case D3D12_UAV_DIMENSION_BUFFER: p.buffer = true; return true; + case D3D12_UAV_DIMENSION_TEXTURE1D: p.mip = &v.Texture1D.MipSlice; return true; + case D3D12_UAV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true; + case D3D12_UAV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; p.plane=&v.Texture2D.PlaneSlice; return true; + case D3D12_UAV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; p.plane=&v.Texture2DArray.PlaneSlice; return true; + case D3D12_UAV_DIMENSION_TEXTURE3D: p.mip=&v.Texture3D.MipSlice; p.first=&v.Texture3D.FirstWSlice; p.count=&v.Texture3D.WSize; p.volume=true; return true; + default: return false; + } +} +inline bool parts(D3D12_RENDER_TARGET_VIEW_DESC& v, Parts& p) { + switch (v.ViewDimension) { + case D3D12_RTV_DIMENSION_BUFFER: p.buffer=true; return true; + case D3D12_RTV_DIMENSION_TEXTURE1D: p.mip=&v.Texture1D.MipSlice; return true; + case D3D12_RTV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true; + case D3D12_RTV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; p.plane=&v.Texture2D.PlaneSlice; return true; + case D3D12_RTV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; p.plane=&v.Texture2DArray.PlaneSlice; return true; + case D3D12_RTV_DIMENSION_TEXTURE2DMS: p.ms=true; return true; + case D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY: p.ms=true; p.first=&v.Texture2DMSArray.FirstArraySlice; p.count=&v.Texture2DMSArray.ArraySize; return true; + case D3D12_RTV_DIMENSION_TEXTURE3D: p.mip=&v.Texture3D.MipSlice; p.first=&v.Texture3D.FirstWSlice; p.count=&v.Texture3D.WSize; p.volume=true; return true; + default: return false; + } +} +inline bool parts(D3D12_DEPTH_STENCIL_VIEW_DESC& v, Parts& p) { + switch (v.ViewDimension) { + case D3D12_DSV_DIMENSION_TEXTURE1D: p.mip=&v.Texture1D.MipSlice; return true; + case D3D12_DSV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true; + case D3D12_DSV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; return true; + case D3D12_DSV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; return true; + case D3D12_DSV_DIMENSION_TEXTURE2DMS: p.ms=true; return true; + case D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY: p.ms=true; p.first=&v.Texture2DMSArray.FirstArraySlice; p.count=&v.Texture2DMSArray.ArraySize; return true; + default: return false; + } +} +// D3D12_UNORDERED_ACCESS_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC. +template<class Desc, class Repair> +Refusal check(Desc* v, const D3D12_RESOURCE_DESC* r, Repair repair, bool typed_cast = false) { + constexpr bool dsv = std::is_same_v<Desc, D3D12_DEPTH_STENCIL_VIEW_DESC>; + constexpr bool uav = std::is_same_v<Desc, D3D12_UNORDERED_ACCESS_VIEW_DESC>; + // ID3D12Device::CreateRenderTargetView / CreateDepthStencilView: a default view needs a typed format. + if (!v) { + if (!r) return Refusal::null_desc; + if (r->Format == DXGI_FORMAT_UNKNOWN || is_typeless(r->Format) || + (dsv ? !depth_format(r->Format) : depth_format(r->Format))) return Refusal::format; + if constexpr (uav) if (r->SampleDesc.Count > 1) return Refusal::dimension; + return Refusal::none; + } + Parts p; + if (!parts(*v, p)) return Refusal::dimension; + if (r && !x2w_view_dimension::fits(uav ? 19 : dsv ? 21 : 20, static_cast<unsigned>(v->ViewDimension), static_cast<unsigned>(r->Dimension))) return Refusal::dimension; + if (r && ((uav && r->SampleDesc.Count > 1) || (!uav && p.ms != (r->SampleDesc.Count > 1)))) return Refusal::dimension; + auto allowed = [&](DXGI_FORMAT f) { return dsv ? depth_format(f) : f != DXGI_FORMAT_UNKNOWN && !is_typeless(f) && !depth_format(f); }; + // A DSV format that is not a depth format (UNKNOWN included) takes the resource's typed depth format below, else + // the view is refused; a typeless depth family member (R32_TYPELESS) is cast by format_cast_fits. + bool special_buffer = false; + if constexpr (uav) special_buffer = p.buffer && (v->Buffer.StructureByteStride || v->Buffer.Flags == D3D12_BUFFER_UAV_FLAG_RAW); + if ((!allowed(v->Format) && !special_buffer) || (r && !p.buffer && !format_cast_fits(r->Format, v->Format, typed_cast))) { + if (!r || !allowed(r->Format)) return Refusal::format; + repair("Format", static_cast<UINT64>(v->Format), static_cast<UINT64>(r->Format)); v->Format = r->Format; ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Preserve legal planar-resource view formats** On hardware supporting NV12 RTV/UAVs, legal plane views use `R8_UNORM` for plane 0 or `R8G8_UNORM` for plane 1, not `NV12`. Those formats are not in the resource's typeless format family, so `format_cast_fits()` returns false and this branch replaces a legal view format with `NV12`. The resulting invalid view is then forwarded to D3D12, introducing a device-removal path for descriptions that previously passed through unchanged; P010/P016 plane views have the same problem. Account for resource/plane/view-format compatibility before applying the generic format-family fallback. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-28 11:05:59 +00:00 (Migrated from github.com)

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

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

@@ -5181,6 +5182,61 @@ __declspec(noinline) u64 view_slot(Wrapper* self, u64 a, u64 b, u64 c, u64 d)
             args[1] = reinterpret_cast<u64>(&null_rtv);
     }
     if (default_view) args[desc_index] = 0;
+    // UAV, RTV and DSV descriptions are checked against the resource before they are forwarded
+    // (target_view_check.h): repairable fields are clamped on a copy, a description D3D12 rejects is refused.
+    if constexpr (N >= 19 && N <= 21) {
+        using namespace x2w_startup::target_view;
+        auto* resource = reinterpret_cast<ID3D12Resource*>(args[0]);
+        D3D12_RESOURCE_DESC backing{};
+        if (resource) backing = resource->GetDesc();
+        D3D12_RESOURCE_DESC counter_desc{};
+        auto* counter = N == 19 ? reinterpret_cast<ID3D12Resource*>(args[1]) : nullptr;
+        if (counter) counter_desc = counter->GetDesc();
+        using Desc = std::conditional_t<N == 19, D3D12_UNORDERED_ACCESS_VIEW_DESC,
+            std::conditional_t<N == 20, D3D12_RENDER_TARGET_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC>>;
+        Desc checked{};
+        Desc* view = nullptr;
+        if (args[desc_index]) {
+            auto* input = reinterpret_cast<const Desc*>(args[desc_index]);
+            if (!x2w_local::readable(input, sizeof(*input))) {
+                refuse_view();
+                return 0;
+            }
+            std::memcpy(&checked, input, sizeof(checked));
+            view = &checked;
+        }
+        D3D12_FEATURE_DATA_D3D12_OPTIONS3 options{};
+        if (resource && view && view->Format != backing.Format && !x2w_startup::is_typeless(backing.Format))
+            device_of(self)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &options, sizeof(options));
+        const auto repair = [&](const char* field, UINT64 old_value, UINT64 new_value) {
+            static LONG counts[6]{};
+            const unsigned index = !std::strcmp(field, "ArraySize") ? 0 : !std::strcmp(field, "WSize") ? 1 :
+                !std::strcmp(field, "PlaneSlice") ? 2 : !std::strcmp(field, "Flags") ? 3 :
+                !std::strcmp(field, "Format") ? 4 : 5;
+            if (first_calls(counts[index], 6))
+                log("x2w-d3d12 view repaired: slot%d %s %llu -> %llu (resource %llux%u mips %u fmt %u)", N, field,
+                    static_cast<unsigned long long>(old_value), static_cast<unsigned long long>(new_value),
+                    static_cast<unsigned long long>(backing.Width), backing.Height, backing.MipLevels,
+                    static_cast<unsigned>(backing.Format));
+        };
+        Refusal refusal;
+        if constexpr (N == 19)
+            refusal = check_uav(view, resource ? &backing : nullptr, counter ? &counter_desc : nullptr, repair,
+                                options.CastingFullyTypedFormatSupported != FALSE);
+        else
+            refusal = check(view, resource ? &backing : nullptr, repair, options.CastingFullyTypedFormatSupported != FALSE);
+        if (refusal != Refusal::none) {
+            static LONG counts[static_cast<unsigned>(Refusal::plane) + 1]{};
+            if (first_calls(counts[static_cast<unsigned>(refusal)], 6))
+                log("x2w-d3d12 view refused: slot%d %s", N, reason(refusal));
+            refuse_view();
+            return 0;
+        }
+        if (view) {
+            std::memcpy(desc_copy, view, sizeof(*view));
+            args[desc_index] = reinterpret_cast<u64>(desc_copy);

Valid, fixed in f67d16272 on up-target-view-check. record_view() now stores the description that was actually forwarded (the repaired copy) for slots 19, 20 and 21, so the translated dispatch (d3d12_compute_dispatch.inl) recreates the UAV from the repaired description and no longer sends the original one again.

Test: startup_compute_dispatch_texture_check.py has a new case texture-store-viewfmt (a UAV with an incompatible R32_FLOAT view format over an RGBA16_FLOAT texture, then a translated dispatch). It checks the readback and that the debug layer stays silent.
Gate on aws-1 with WARP (x2w_pipe.py win2025 3200 --host aws-1 --regex 'startup_target_view|startup_compute_dispatch_texture' --force, head f67d1627): dev 5/5 and release 5/5 passed. Mutants run after the main gate: reverting the record fix fails startup_compute_dispatch_texture_warp and _hardware (dev and release); removing the planar rule fails startup_target_view_check (NV12 plane 0, NV12 plane 1, P010 plane 1).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726701478 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#discussion_r4726701478). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T11:05:59Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 5237 ~~~~diff @@ -5181,6 +5182,61 @@ __declspec(noinline) u64 view_slot(Wrapper* self, u64 a, u64 b, u64 c, u64 d) args[1] = reinterpret_cast<u64>(&null_rtv); } if (default_view) args[desc_index] = 0; + // UAV, RTV and DSV descriptions are checked against the resource before they are forwarded + // (target_view_check.h): repairable fields are clamped on a copy, a description D3D12 rejects is refused. + if constexpr (N >= 19 && N <= 21) { + using namespace x2w_startup::target_view; + auto* resource = reinterpret_cast<ID3D12Resource*>(args[0]); + D3D12_RESOURCE_DESC backing{}; + if (resource) backing = resource->GetDesc(); + D3D12_RESOURCE_DESC counter_desc{}; + auto* counter = N == 19 ? reinterpret_cast<ID3D12Resource*>(args[1]) : nullptr; + if (counter) counter_desc = counter->GetDesc(); + using Desc = std::conditional_t<N == 19, D3D12_UNORDERED_ACCESS_VIEW_DESC, + std::conditional_t<N == 20, D3D12_RENDER_TARGET_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC>>; + Desc checked{}; + Desc* view = nullptr; + if (args[desc_index]) { + auto* input = reinterpret_cast<const Desc*>(args[desc_index]); + if (!x2w_local::readable(input, sizeof(*input))) { + refuse_view(); + return 0; + } + std::memcpy(&checked, input, sizeof(checked)); + view = &checked; + } + D3D12_FEATURE_DATA_D3D12_OPTIONS3 options{}; + if (resource && view && view->Format != backing.Format && !x2w_startup::is_typeless(backing.Format)) + device_of(self)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &options, sizeof(options)); + const auto repair = [&](const char* field, UINT64 old_value, UINT64 new_value) { + static LONG counts[6]{}; + const unsigned index = !std::strcmp(field, "ArraySize") ? 0 : !std::strcmp(field, "WSize") ? 1 : + !std::strcmp(field, "PlaneSlice") ? 2 : !std::strcmp(field, "Flags") ? 3 : + !std::strcmp(field, "Format") ? 4 : 5; + if (first_calls(counts[index], 6)) + log("x2w-d3d12 view repaired: slot%d %s %llu -> %llu (resource %llux%u mips %u fmt %u)", N, field, + static_cast<unsigned long long>(old_value), static_cast<unsigned long long>(new_value), + static_cast<unsigned long long>(backing.Width), backing.Height, backing.MipLevels, + static_cast<unsigned>(backing.Format)); + }; + Refusal refusal; + if constexpr (N == 19) + refusal = check_uav(view, resource ? &backing : nullptr, counter ? &counter_desc : nullptr, repair, + options.CastingFullyTypedFormatSupported != FALSE); + else + refusal = check(view, resource ? &backing : nullptr, repair, options.CastingFullyTypedFormatSupported != FALSE); + if (refusal != Refusal::none) { + static LONG counts[static_cast<unsigned>(Refusal::plane) + 1]{}; + if (first_calls(counts[static_cast<unsigned>(refusal)], 6)) + log("x2w-d3d12 view refused: slot%d %s", N, reason(refusal)); + refuse_view(); + return 0; + } + if (view) { + std::memcpy(desc_copy, view, sizeof(*view)); + args[desc_index] = reinterpret_cast<u64>(desc_copy); ~~~~ --- Valid, fixed in f67d16272 on `up-target-view-check`. `record_view()` now stores the description that was actually forwarded (the repaired copy) for slots 19, 20 and 21, so the translated dispatch (`d3d12_compute_dispatch.inl`) recreates the UAV from the repaired description and no longer sends the original one again. Test: `startup_compute_dispatch_texture_check.py` has a new case `texture-store-viewfmt` (a UAV with an incompatible `R32_FLOAT` view format over an RGBA16_FLOAT texture, then a translated dispatch). It checks the readback and that the debug layer stays silent. Gate on aws-1 with WARP (`x2w_pipe.py win2025 3200 --host aws-1 --regex 'startup_target_view|startup_compute_dispatch_texture' --force`, head f67d1627): dev 5/5 and release 5/5 passed. Mutants run after the main gate: reverting the record fix fails `startup_compute_dispatch_texture_warp` and `_hardware` (dev and release); removing the planar rule fails `startup_target_view_check` (NV12 plane 0, NV12 plane 1, P010 plane 1). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-28 11:06:00 +00:00 (Migrated from github.com)

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

Code review location: src/startup_stubs/target_view_check.h; line 131

@@ -0,0 +1,166 @@
+// Device-independent checks for UAV, RTV and DSV descriptions.
+#pragma once
+#include "startup_stubs/list_copy.h"
+#include "startup_stubs/view_dimension.h"
+
+#include <d3d12.h>
+
+#include <algorithm>
+#include <type_traits>
+
+namespace x2w_startup::target_view {
+// DXGI depth formats a DSV may name (CreateDepthStencilView).
+inline bool depth_format(DXGI_FORMAT format)
+{
+    return format == DXGI_FORMAT_D16_UNORM || format == DXGI_FORMAT_D32_FLOAT ||
+        format == DXGI_FORMAT_D24_UNORM_S8_UINT || format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
+}
+// Depth-stencil families with a stencil plane (plane slice 1).
+inline bool planar_depth_stencil(DXGI_FORMAT format)
+{
+    const auto family = format_family(format);
+    return family == DXGI_FORMAT_R24G8_TYPELESS || family == DXGI_FORMAT_R32G8X24_TYPELESS;
+}
+enum class NumericFormat { other, floating, snorm, unorm };
+inline NumericFormat numeric_format(DXGI_FORMAT format)
+{
+    switch (format) {
+    case DXGI_FORMAT_R32G32B32A32_FLOAT: case DXGI_FORMAT_R32G32B32_FLOAT:
+    case DXGI_FORMAT_R32G32_FLOAT: case DXGI_FORMAT_R32_FLOAT:
+    case DXGI_FORMAT_R16G16B16A16_FLOAT: case DXGI_FORMAT_R16G16_FLOAT: case DXGI_FORMAT_R16_FLOAT:
+        return NumericFormat::floating;
+    case DXGI_FORMAT_R16G16B16A16_SNORM: case DXGI_FORMAT_R16G16_SNORM: case DXGI_FORMAT_R16_SNORM:
+    case DXGI_FORMAT_R8G8B8A8_SNORM: case DXGI_FORMAT_R8G8_SNORM: case DXGI_FORMAT_R8_SNORM:
+        return NumericFormat::snorm;
+    case DXGI_FORMAT_R16G16B16A16_UNORM: case DXGI_FORMAT_R16G16_UNORM: case DXGI_FORMAT_R16_UNORM:
+    case DXGI_FORMAT_R8G8B8A8_UNORM: case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
+    case DXGI_FORMAT_R8G8_UNORM: case DXGI_FORMAT_R8_UNORM:
+        return NumericFormat::unorm;
+    default:
+        return NumericFormat::other;
+    }
+}
+// A view may name another member of the resource's format family when the resource is typeless; a typed resource
+// needs D3D12_FEATURE_DATA_D3D12_OPTIONS3::CastingFullyTypedFormatSupported, never for depth, and the cast keeps
+// float/non-float and snorm/unorm apart.
+inline bool format_cast_fits(DXGI_FORMAT resource, DXGI_FORMAT view, bool fully_typed_casting)
+{
+    if (resource == view) return true;
+    if (!compatible_formats(resource, view)) return false;
+    if (is_typeless(resource)) return true;
+    if (!fully_typed_casting || depth_format(resource)) return false;
+    const auto from = numeric_format(resource);
+    const auto to = numeric_format(view);
+    if ((from == NumericFormat::floating) != (to == NumericFormat::floating)) return false;
+    return !((from == NumericFormat::snorm && to == NumericFormat::unorm) ||
+             (from == NumericFormat::unorm && to == NumericFormat::snorm));
+}
+enum class Refusal { none, null_desc, dimension, mip, array, format, counter, plane };
+inline const char* reason(Refusal r) {
+    switch (r) {
+    case Refusal::null_desc: return "null resource and description";
+    case Refusal::dimension: return "ViewDimension/SampleDesc.Count";
+    case Refusal::mip: return "MipSlice";
+    case Refusal::array: return "FirstArraySlice/ArraySize or FirstWSlice/WSize";
+    case Refusal::format: return "Format";
+    case Refusal::counter: return "counter resource/offset";
+    case Refusal::plane: return "PlaneSlice";
+    default: return "none";
+    }
+}
+struct Parts { UINT* mip = nullptr; UINT* first = nullptr; UINT* count = nullptr; UINT* plane = nullptr; bool volume = false; bool ms = false; bool buffer = false; };
+inline bool parts(D3D12_UNORDERED_ACCESS_VIEW_DESC& v, Parts& p) {
+    switch (v.ViewDimension) {
+    case D3D12_UAV_DIMENSION_BUFFER: p.buffer = true; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE1D: p.mip = &v.Texture1D.MipSlice; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; p.plane=&v.Texture2D.PlaneSlice; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; p.plane=&v.Texture2DArray.PlaneSlice; return true;
+    case D3D12_UAV_DIMENSION_TEXTURE3D: p.mip=&v.Texture3D.MipSlice; p.first=&v.Texture3D.FirstWSlice; p.count=&v.Texture3D.WSize; p.volume=true; return true;
+    default: return false;
+    }
+}
+inline bool parts(D3D12_RENDER_TARGET_VIEW_DESC& v, Parts& p) {
+    switch (v.ViewDimension) {
+    case D3D12_RTV_DIMENSION_BUFFER: p.buffer=true; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE1D: p.mip=&v.Texture1D.MipSlice; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; p.plane=&v.Texture2D.PlaneSlice; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; p.plane=&v.Texture2DArray.PlaneSlice; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE2DMS: p.ms=true; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY: p.ms=true; p.first=&v.Texture2DMSArray.FirstArraySlice; p.count=&v.Texture2DMSArray.ArraySize; return true;
+    case D3D12_RTV_DIMENSION_TEXTURE3D: p.mip=&v.Texture3D.MipSlice; p.first=&v.Texture3D.FirstWSlice; p.count=&v.Texture3D.WSize; p.volume=true; return true;
+    default: return false;
+    }
+}
+inline bool parts(D3D12_DEPTH_STENCIL_VIEW_DESC& v, Parts& p) {
+    switch (v.ViewDimension) {
+    case D3D12_DSV_DIMENSION_TEXTURE1D: p.mip=&v.Texture1D.MipSlice; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE2DMS: p.ms=true; return true;
+    case D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY: p.ms=true; p.first=&v.Texture2DMSArray.FirstArraySlice; p.count=&v.Texture2DMSArray.ArraySize; return true;
+    default: return false;
+    }
+}
+// D3D12_UNORDERED_ACCESS_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC.
+template<class Desc, class Repair>
+Refusal check(Desc* v, const D3D12_RESOURCE_DESC* r, Repair repair, bool typed_cast = false) {
+    constexpr bool dsv = std::is_same_v<Desc, D3D12_DEPTH_STENCIL_VIEW_DESC>;
+    constexpr bool uav = std::is_same_v<Desc, D3D12_UNORDERED_ACCESS_VIEW_DESC>;
+    // ID3D12Device::CreateRenderTargetView / CreateDepthStencilView: a default view needs a typed format.
+    if (!v) {
+        if (!r) return Refusal::null_desc;
+        if (r->Format == DXGI_FORMAT_UNKNOWN || is_typeless(r->Format) ||
+            (dsv ? !depth_format(r->Format) : depth_format(r->Format))) return Refusal::format;
+        if constexpr (uav) if (r->SampleDesc.Count > 1) return Refusal::dimension;
+        return Refusal::none;
+    }
+    Parts p;
+    if (!parts(*v, p)) return Refusal::dimension;
+    if (r && !x2w_view_dimension::fits(uav ? 19 : dsv ? 21 : 20, static_cast<unsigned>(v->ViewDimension), static_cast<unsigned>(r->Dimension))) return Refusal::dimension;
+    if (r && ((uav && r->SampleDesc.Count > 1) || (!uav && p.ms != (r->SampleDesc.Count > 1)))) return Refusal::dimension;
+    auto allowed = [&](DXGI_FORMAT f) { return dsv ? depth_format(f) : f != DXGI_FORMAT_UNKNOWN && !is_typeless(f) && !depth_format(f); };
+    // A DSV format that is not a depth format (UNKNOWN included) takes the resource's typed depth format below, else
+    // the view is refused; a typeless depth family member (R32_TYPELESS) is cast by format_cast_fits.
+    bool special_buffer = false;
+    if constexpr (uav) special_buffer = p.buffer && (v->Buffer.StructureByteStride || v->Buffer.Flags == D3D12_BUFFER_UAV_FLAG_RAW);
+    if ((!allowed(v->Format) && !special_buffer) || (r && !p.buffer && !format_cast_fits(r->Format, v->Format, typed_cast))) {
+        if (!r || !allowed(r->Format)) return Refusal::format;
+        repair("Format", static_cast<UINT64>(v->Format), static_cast<UINT64>(r->Format)); v->Format = r->Format;

Valid, fixed in f67d16272. target_view_check.h has a new planar_view_fits(): for NV12 plane 0 R8_UNORM and plane 1 R8G8_UNORM, for P010/P016 plane 0 R16_UNORM and plane 1 R16G16_UNORM are kept as they are. This is the plane-format rule in the D3D12 resource binding spec (planar formats). Any other format on a planar resource is still repaired to the resource format. The format check now allows a view when either format_cast_fits() or planar_view_fits() is true.

Test: startup_target_view_check.cpp covers NV12 plane 0 and 1, plane 1 with the plane 0 format (repaired), P010 plane 1, and an unrelated P010 format (repaired).
Gate on aws-1 with WARP (x2w_pipe.py win2025 3200 --host aws-1 --regex 'startup_target_view|startup_compute_dispatch_texture' --force, head f67d1627): dev 5/5 and release 5/5 passed. Mutants run after the main gate: reverting the record fix fails startup_compute_dispatch_texture_warp and _hardware (dev and release); removing the planar rule fails startup_target_view_check (NV12 plane 0, NV12 plane 1, P010 plane 1).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726701612 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#discussion_r4726701612). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T11:06:00Z. **Code review location:** `src/startup_stubs/target_view_check.h`; line 131 ~~~~diff @@ -0,0 +1,166 @@ +// Device-independent checks for UAV, RTV and DSV descriptions. +#pragma once +#include "startup_stubs/list_copy.h" +#include "startup_stubs/view_dimension.h" + +#include <d3d12.h> + +#include <algorithm> +#include <type_traits> + +namespace x2w_startup::target_view { +// DXGI depth formats a DSV may name (CreateDepthStencilView). +inline bool depth_format(DXGI_FORMAT format) +{ + return format == DXGI_FORMAT_D16_UNORM || format == DXGI_FORMAT_D32_FLOAT || + format == DXGI_FORMAT_D24_UNORM_S8_UINT || format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT; +} +// Depth-stencil families with a stencil plane (plane slice 1). +inline bool planar_depth_stencil(DXGI_FORMAT format) +{ + const auto family = format_family(format); + return family == DXGI_FORMAT_R24G8_TYPELESS || family == DXGI_FORMAT_R32G8X24_TYPELESS; +} +enum class NumericFormat { other, floating, snorm, unorm }; +inline NumericFormat numeric_format(DXGI_FORMAT format) +{ + switch (format) { + case DXGI_FORMAT_R32G32B32A32_FLOAT: case DXGI_FORMAT_R32G32B32_FLOAT: + case DXGI_FORMAT_R32G32_FLOAT: case DXGI_FORMAT_R32_FLOAT: + case DXGI_FORMAT_R16G16B16A16_FLOAT: case DXGI_FORMAT_R16G16_FLOAT: case DXGI_FORMAT_R16_FLOAT: + return NumericFormat::floating; + case DXGI_FORMAT_R16G16B16A16_SNORM: case DXGI_FORMAT_R16G16_SNORM: case DXGI_FORMAT_R16_SNORM: + case DXGI_FORMAT_R8G8B8A8_SNORM: case DXGI_FORMAT_R8G8_SNORM: case DXGI_FORMAT_R8_SNORM: + return NumericFormat::snorm; + case DXGI_FORMAT_R16G16B16A16_UNORM: case DXGI_FORMAT_R16G16_UNORM: case DXGI_FORMAT_R16_UNORM: + case DXGI_FORMAT_R8G8B8A8_UNORM: case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_R8G8_UNORM: case DXGI_FORMAT_R8_UNORM: + return NumericFormat::unorm; + default: + return NumericFormat::other; + } +} +// A view may name another member of the resource's format family when the resource is typeless; a typed resource +// needs D3D12_FEATURE_DATA_D3D12_OPTIONS3::CastingFullyTypedFormatSupported, never for depth, and the cast keeps +// float/non-float and snorm/unorm apart. +inline bool format_cast_fits(DXGI_FORMAT resource, DXGI_FORMAT view, bool fully_typed_casting) +{ + if (resource == view) return true; + if (!compatible_formats(resource, view)) return false; + if (is_typeless(resource)) return true; + if (!fully_typed_casting || depth_format(resource)) return false; + const auto from = numeric_format(resource); + const auto to = numeric_format(view); + if ((from == NumericFormat::floating) != (to == NumericFormat::floating)) return false; + return !((from == NumericFormat::snorm && to == NumericFormat::unorm) || + (from == NumericFormat::unorm && to == NumericFormat::snorm)); +} +enum class Refusal { none, null_desc, dimension, mip, array, format, counter, plane }; +inline const char* reason(Refusal r) { + switch (r) { + case Refusal::null_desc: return "null resource and description"; + case Refusal::dimension: return "ViewDimension/SampleDesc.Count"; + case Refusal::mip: return "MipSlice"; + case Refusal::array: return "FirstArraySlice/ArraySize or FirstWSlice/WSize"; + case Refusal::format: return "Format"; + case Refusal::counter: return "counter resource/offset"; + case Refusal::plane: return "PlaneSlice"; + default: return "none"; + } +} +struct Parts { UINT* mip = nullptr; UINT* first = nullptr; UINT* count = nullptr; UINT* plane = nullptr; bool volume = false; bool ms = false; bool buffer = false; }; +inline bool parts(D3D12_UNORDERED_ACCESS_VIEW_DESC& v, Parts& p) { + switch (v.ViewDimension) { + case D3D12_UAV_DIMENSION_BUFFER: p.buffer = true; return true; + case D3D12_UAV_DIMENSION_TEXTURE1D: p.mip = &v.Texture1D.MipSlice; return true; + case D3D12_UAV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true; + case D3D12_UAV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; p.plane=&v.Texture2D.PlaneSlice; return true; + case D3D12_UAV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; p.plane=&v.Texture2DArray.PlaneSlice; return true; + case D3D12_UAV_DIMENSION_TEXTURE3D: p.mip=&v.Texture3D.MipSlice; p.first=&v.Texture3D.FirstWSlice; p.count=&v.Texture3D.WSize; p.volume=true; return true; + default: return false; + } +} +inline bool parts(D3D12_RENDER_TARGET_VIEW_DESC& v, Parts& p) { + switch (v.ViewDimension) { + case D3D12_RTV_DIMENSION_BUFFER: p.buffer=true; return true; + case D3D12_RTV_DIMENSION_TEXTURE1D: p.mip=&v.Texture1D.MipSlice; return true; + case D3D12_RTV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true; + case D3D12_RTV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; p.plane=&v.Texture2D.PlaneSlice; return true; + case D3D12_RTV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; p.plane=&v.Texture2DArray.PlaneSlice; return true; + case D3D12_RTV_DIMENSION_TEXTURE2DMS: p.ms=true; return true; + case D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY: p.ms=true; p.first=&v.Texture2DMSArray.FirstArraySlice; p.count=&v.Texture2DMSArray.ArraySize; return true; + case D3D12_RTV_DIMENSION_TEXTURE3D: p.mip=&v.Texture3D.MipSlice; p.first=&v.Texture3D.FirstWSlice; p.count=&v.Texture3D.WSize; p.volume=true; return true; + default: return false; + } +} +inline bool parts(D3D12_DEPTH_STENCIL_VIEW_DESC& v, Parts& p) { + switch (v.ViewDimension) { + case D3D12_DSV_DIMENSION_TEXTURE1D: p.mip=&v.Texture1D.MipSlice; return true; + case D3D12_DSV_DIMENSION_TEXTURE1DARRAY: p.mip=&v.Texture1DArray.MipSlice; p.first=&v.Texture1DArray.FirstArraySlice; p.count=&v.Texture1DArray.ArraySize; return true; + case D3D12_DSV_DIMENSION_TEXTURE2D: p.mip=&v.Texture2D.MipSlice; return true; + case D3D12_DSV_DIMENSION_TEXTURE2DARRAY: p.mip=&v.Texture2DArray.MipSlice; p.first=&v.Texture2DArray.FirstArraySlice; p.count=&v.Texture2DArray.ArraySize; return true; + case D3D12_DSV_DIMENSION_TEXTURE2DMS: p.ms=true; return true; + case D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY: p.ms=true; p.first=&v.Texture2DMSArray.FirstArraySlice; p.count=&v.Texture2DMSArray.ArraySize; return true; + default: return false; + } +} +// D3D12_UNORDERED_ACCESS_VIEW_DESC, D3D12_DEPTH_STENCIL_VIEW_DESC. +template<class Desc, class Repair> +Refusal check(Desc* v, const D3D12_RESOURCE_DESC* r, Repair repair, bool typed_cast = false) { + constexpr bool dsv = std::is_same_v<Desc, D3D12_DEPTH_STENCIL_VIEW_DESC>; + constexpr bool uav = std::is_same_v<Desc, D3D12_UNORDERED_ACCESS_VIEW_DESC>; + // ID3D12Device::CreateRenderTargetView / CreateDepthStencilView: a default view needs a typed format. + if (!v) { + if (!r) return Refusal::null_desc; + if (r->Format == DXGI_FORMAT_UNKNOWN || is_typeless(r->Format) || + (dsv ? !depth_format(r->Format) : depth_format(r->Format))) return Refusal::format; + if constexpr (uav) if (r->SampleDesc.Count > 1) return Refusal::dimension; + return Refusal::none; + } + Parts p; + if (!parts(*v, p)) return Refusal::dimension; + if (r && !x2w_view_dimension::fits(uav ? 19 : dsv ? 21 : 20, static_cast<unsigned>(v->ViewDimension), static_cast<unsigned>(r->Dimension))) return Refusal::dimension; + if (r && ((uav && r->SampleDesc.Count > 1) || (!uav && p.ms != (r->SampleDesc.Count > 1)))) return Refusal::dimension; + auto allowed = [&](DXGI_FORMAT f) { return dsv ? depth_format(f) : f != DXGI_FORMAT_UNKNOWN && !is_typeless(f) && !depth_format(f); }; + // A DSV format that is not a depth format (UNKNOWN included) takes the resource's typed depth format below, else + // the view is refused; a typeless depth family member (R32_TYPELESS) is cast by format_cast_fits. + bool special_buffer = false; + if constexpr (uav) special_buffer = p.buffer && (v->Buffer.StructureByteStride || v->Buffer.Flags == D3D12_BUFFER_UAV_FLAG_RAW); + if ((!allowed(v->Format) && !special_buffer) || (r && !p.buffer && !format_cast_fits(r->Format, v->Format, typed_cast))) { + if (!r || !allowed(r->Format)) return Refusal::format; + repair("Format", static_cast<UINT64>(v->Format), static_cast<UINT64>(r->Format)); v->Format = r->Format; ~~~~ --- Valid, fixed in f67d16272. `target_view_check.h` has a new `planar_view_fits()`: for NV12 plane 0 `R8_UNORM` and plane 1 `R8G8_UNORM`, for P010/P016 plane 0 `R16_UNORM` and plane 1 `R16G16_UNORM` are kept as they are. This is the plane-format rule in the D3D12 resource binding spec (planar formats). Any other format on a planar resource is still repaired to the resource format. The format check now allows a view when either `format_cast_fits()` or `planar_view_fits()` is true. Test: `startup_target_view_check.cpp` covers NV12 plane 0 and 1, plane 1 with the plane 0 format (repaired), P010 plane 1, and an unrelated P010 format (repaired). Gate on aws-1 with WARP (`x2w_pipe.py win2025 3200 --host aws-1 --regex 'startup_target_view|startup_compute_dispatch_texture' --force`, head f67d1627): dev 5/5 and release 5/5 passed. Mutants run after the main gate: reverting the record fix fails `startup_compute_dispatch_texture_warp` and `_hardware` (dev and release); removing the planar rule fails `startup_target_view_check` (NV12 plane 0, NV12 plane 1, P010 plane 1). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-28 21:53:59 +00:00 (Migrated from github.com)

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


Merged current main into this branch (merge commit, no force push); head is now 78c320f56. One conflict in src/startup_stubs/d3d12_xs_device.cpp (record_view): kept main's ViewRecord::srv_desc_bytes / uav_desc_bytes sizes and this PR's repaired-description pointer passed to note_view.

Both automated review findings were already fixed in f67d16272 (see the replies in the threads: the record keeps the repaired description, and planar_view_fits() allows the legal plane formats).

Verification (Windows Server 2025, D3D12 WARP, PR head 78c320f56, dev and release):
x2w_pipe.py win2025 3200 --regex '^(startup_target_view_check|startup_target_views_|startup_view_dimension|startup_null_views_|startup_resource_retire_views_)' -> 18/18 passed in both legs.

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

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7246353877 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#issuecomment-7246353877). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T21:53:59Z. --- Merged current `main` into this branch (merge commit, no force push); head is now `78c320f56`. One conflict in `src/startup_stubs/d3d12_xs_device.cpp` (`record_view`): kept main's `ViewRecord::srv_desc_bytes` / `uav_desc_bytes` sizes and this PR's repaired-description pointer passed to `note_view`. Both automated review findings were already fixed in `f67d16272` (see the replies in the threads: the record keeps the repaired description, and `planar_view_fits()` allows the legal plane formats). Verification (Windows Server 2025, D3D12 WARP, PR head `78c320f56`, dev and release): `x2w_pipe.py win2025 3200 --regex '^(startup_target_view_check|startup_target_views_|startup_view_dimension|startup_null_views_|startup_resource_retire_views_)'` -> 18/18 passed in both legs. @MasterDomino ready for review and merge when you have time. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-28 22:22:52 +00:00 (Migrated from github.com)

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


Merged current main into this branch (merge commit, no force push); head is now 78c320f56. One conflict in src/startup_stubs/d3d12_xs_device.cpp (record_view): kept main's ViewRecord::srv_desc_bytes / uav_desc_bytes sizes and this PR's repaired-description pointer passed to note_view.

Both automated review findings were already fixed in f67d16272 (see the replies in the threads: the record keeps the repaired description, and planar_view_fits() allows the legal plane formats).

Verification (Windows Server 2025, D3D12 WARP, PR head 78c320f56, dev and release):
x2w_pipe.py win2025 3200 --regex '^(startup_target_view_check|startup_target_views_|startup_view_dimension|startup_null_views_|startup_resource_retire_views_)' -> 18/18 passed in both legs.

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

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7246694878 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#issuecomment-7246694878). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T22:22:52Z. --- Merged current `main` into this branch (merge commit, no force push); head is now `78c320f56`. One conflict in `src/startup_stubs/d3d12_xs_device.cpp` (`record_view`): kept main's `ViewRecord::srv_desc_bytes` / `uav_desc_bytes` sizes and this PR's repaired-description pointer passed to `note_view`. Both automated review findings were already fixed in `f67d16272` (see the replies in the threads: the record keeps the repaired description, and `planar_view_fits()` allows the legal plane formats). Verification (Windows Server 2025, D3D12 WARP, PR head `78c320f56`, dev and release): `x2w_pipe.py win2025 3200 --regex '^(startup_target_view_check|startup_target_views_|startup_view_dimension|startup_null_views_|startup_resource_retire_views_)'` -> 18/18 passed in both legs. @MasterDomino ready for review and merge when you have time. AI-assisted; commands listed were executed locally.
pigalot commented 2026-11-29 08:50:03 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Independently reviewed 78c320f5 integrated over main 7c123092 (tree 01e2b13c). The trial merge is clean and git diff --check is clean.

I read target_view_check.h against the view_slot path and the record consumers (view_format_of, resolve_view, the translated dispatch), and compared its verdicts with what desktop D3D12 accepts, using a standalone probe that creates each view on a fresh debug-layer device and calls check / check_uav on the same description.

Blocking: legal 32-bit UAV casts are refused or rewritten. D3D12 lets a UAV name R32_UINT, R32_SINT or R32_FLOAT over a 32-bit texture of another format family. format_cast_fits() starts with compatible_formats(), which is family equality, so these never fit. On main they are forwarded unchanged (slot 19 has no format check there).

Resource (Texture2D, ALLOW_UNORDERED_ACCESS) UAV format Desktop D3D12, debug layer on check_uav at 78c320f5
R8G8B8A8_TYPELESS R32_UINT 0 errors, device not removed Refusal::format
R8G8B8A8_TYPELESS R32_FLOAT 0 errors, device not removed Refusal::format
R10G10B10A2_TYPELESS R32_UINT 0 errors, device not removed Refusal::format
R16G16_TYPELESS R32_UINT 0 errors, device not removed Refusal::format
B8G8R8A8_TYPELESS R32_UINT 0 errors, device not removed Refusal::format
R8G8B8A8_UNORM (CastingFullyTypedFormatSupported = 1) R32_UINT 0 errors, device not removed repaired, Format 42 -> 28
R8G8B8A8_TYPELESS (control) R8G8B8A8_UNORM 0 errors forwarded
R8G8B8A8_TYPELESS (control) R16G16B16A16_FLOAT 2 errors, removed 0x887a0001 Refusal::format

The results are the same on WARP and on the hardware adapter below. So a view that works today is skipped (first five rows), and in the typed case the title's R32_UINT view silently becomes an R8G8B8A8_UNORM one, which changes what a shader reads and writes through it.

To reproduce without a device, add to tests/startup_target_view_check.cpp:

D3D12_RESOURCE_DESC t{}; t.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; t.Width = 32; t.Height = 32;
t.DepthOrArraySize = 1; t.MipLevels = 1; t.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS; t.SampleDesc.Count = 1;
D3D12_UNORDERED_ACCESS_VIEW_DESC w{}; w.Format = DXGI_FORMAT_R32_UINT; w.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
auto kept = w;
expect(check_uav(&w, &t, nullptr, repair) == Refusal::none && !std::memcmp(&w, &kept, sizeof(w)), "R32 UAV over a 32-bit family");

It fails at 78c320f5 with FAIL: R32 UAV over a 32-bit family. Suggested direction (unconfirmed beyond the rows above): for UAVs, let R32_UINT / R32_SINT / R32_FLOAT pass over the 32-bit families D3D12 allows, next to planar_view_fits(), with a device case in startup_target_views_device.cpp so the debug layer confirms it. I did not test B8G8R8X8_TYPELESS or R32_SINT.

What I ran. Built all targets in dev and release, then
ctest --test-dir out/build/<preset> --no-tests=error -j 4 -E '_hardware$|startup_audio' -R '^(startup_target_view_check|startup_target_views_warp|startup_view_dimension.*|startup_null_views_.*|startup_resource_retire_views_.*|startup_compute_dispatch_texture_warp|startup_compute_dispatch_warp|startup_packed.*)$':
28/28 passed in Debug and Release /O2, no skips. Under the GPU lock with -j 1 and X2W_TEST_DEBUG_LAYER=1, startup_target_views_hardware and startup_compute_dispatch_texture_hardware passed in both presets, no skips.

Negative control: with the refusal in view_slot disabled (if (false && refusal != Refusal::none)), startup_target_views_warp fails (the debug layer reports the views and the device is removed with 0x887a0001; the process then exits 0xc0000409).

The record change is sound as far as I traced it: the record now holds the description that was forwarded (desktop format, repaired fields), and the consumers that map the format again (view_format_of, the dispatch) are unaffected because desktop_format() maps its outputs to themselves.

Mutants (dev; CPU test, plus startup_target_views_warp and startup_compute_dispatch_texture_warp where marked "device"):

Killed (13):

  • *p.mip >= r->MipLevels -> > (device; the CPU test does not catch it, only the mip-4 UAV in the WARP test does)
  • *p.first >= limit -> >
  • WSize ~0 exception removed
  • volume limit ignores the mip
  • counter alignment check removed
  • counter end bound Width - 4 -> Width
  • multisample UAV allowed
  • multisample mismatch allowed for RTV/DSV
  • view_slot ignores the refusal (device)
  • record keeps the original description (device, startup_compute_dispatch_texture_warp)
  • repaired copy not forwarded (device)
  • counter offset not reset
  • default DSV allowed on a colour format

Surviving (5), all with the device tests included; none blocks on its own, but they are untested rules:

  • zero ArraySize / WSize refusal removed (!*p.count)
  • *p.plane > 1 -> > 2 (no plane-2 case on a planar resource)
  • read-only-stencil flag dropped on D32_FLOAT_S8X24_UINT (only D24_UNORM_S8_UINT is covered)
  • typed cast allowed without CastingFullyTypedFormatSupported (no test passes typed_cast)
  • typed cast allows snorm <-> unorm (same reason)

Equivalent: none found.

Smaller notes, not blocking:

  • The PR body still says "Draft until an independent peer review"; the PR is not a draft.
  • The comment above check() names only the UAV and DSV descriptions; it also handles RTVs.

Real-title run of this head merged onto the baseline commit: flaky. It was judged worse than the baseline on the first run ([fail] judgement: Judged worse than the baseline: black-frame) and passed on the re-run ([warn] repeat: Failed on the first run and passed on a re-run (job 28).). That does not block on its own.

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; WARP for the _warp tests.
CI: Build and test on Windows passed on 78c320f5.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6102153053 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#pullrequestreview-6102153053). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-29T08:50:03Z. **Review:** CHANGES_REQUESTED --- Independently reviewed `78c320f5` integrated over `main` `7c123092` (tree `01e2b13c`). The trial merge is clean and `git diff --check` is clean. I read `target_view_check.h` against the `view_slot` path and the record consumers (`view_format_of`, `resolve_view`, the translated dispatch), and compared its verdicts with what desktop D3D12 accepts, using a standalone probe that creates each view on a fresh debug-layer device and calls `check` / `check_uav` on the same description. **Blocking: legal 32-bit UAV casts are refused or rewritten.** D3D12 lets a UAV name `R32_UINT`, `R32_SINT` or `R32_FLOAT` over a 32-bit texture of another format family. `format_cast_fits()` starts with `compatible_formats()`, which is family equality, so these never fit. On `main` they are forwarded unchanged (slot 19 has no format check there). | Resource (Texture2D, `ALLOW_UNORDERED_ACCESS`) | UAV format | Desktop D3D12, debug layer on | `check_uav` at `78c320f5` | |---|---|---|---| | `R8G8B8A8_TYPELESS` | `R32_UINT` | 0 errors, device not removed | `Refusal::format` | | `R8G8B8A8_TYPELESS` | `R32_FLOAT` | 0 errors, device not removed | `Refusal::format` | | `R10G10B10A2_TYPELESS` | `R32_UINT` | 0 errors, device not removed | `Refusal::format` | | `R16G16_TYPELESS` | `R32_UINT` | 0 errors, device not removed | `Refusal::format` | | `B8G8R8A8_TYPELESS` | `R32_UINT` | 0 errors, device not removed | `Refusal::format` | | `R8G8B8A8_UNORM` (`CastingFullyTypedFormatSupported` = 1) | `R32_UINT` | 0 errors, device not removed | repaired, Format 42 -> 28 | | `R8G8B8A8_TYPELESS` (control) | `R8G8B8A8_UNORM` | 0 errors | forwarded | | `R8G8B8A8_TYPELESS` (control) | `R16G16B16A16_FLOAT` | 2 errors, removed `0x887a0001` | `Refusal::format` | The results are the same on WARP and on the hardware adapter below. So a view that works today is skipped (first five rows), and in the typed case the title's `R32_UINT` view silently becomes an `R8G8B8A8_UNORM` one, which changes what a shader reads and writes through it. To reproduce without a device, add to `tests/startup_target_view_check.cpp`: ```cpp D3D12_RESOURCE_DESC t{}; t.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; t.Width = 32; t.Height = 32; t.DepthOrArraySize = 1; t.MipLevels = 1; t.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS; t.SampleDesc.Count = 1; D3D12_UNORDERED_ACCESS_VIEW_DESC w{}; w.Format = DXGI_FORMAT_R32_UINT; w.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D; auto kept = w; expect(check_uav(&w, &t, nullptr, repair) == Refusal::none && !std::memcmp(&w, &kept, sizeof(w)), "R32 UAV over a 32-bit family"); ``` It fails at `78c320f5` with `FAIL: R32 UAV over a 32-bit family`. Suggested direction (unconfirmed beyond the rows above): for UAVs, let `R32_UINT` / `R32_SINT` / `R32_FLOAT` pass over the 32-bit families D3D12 allows, next to `planar_view_fits()`, with a device case in `startup_target_views_device.cpp` so the debug layer confirms it. I did not test `B8G8R8X8_TYPELESS` or `R32_SINT`. **What I ran.** Built all targets in `dev` and `release`, then `ctest --test-dir out/build/<preset> --no-tests=error -j 4 -E '_hardware$|startup_audio' -R '^(startup_target_view_check|startup_target_views_warp|startup_view_dimension.*|startup_null_views_.*|startup_resource_retire_views_.*|startup_compute_dispatch_texture_warp|startup_compute_dispatch_warp|startup_packed.*)$'`: 28/28 passed in Debug and Release `/O2`, no skips. Under the GPU lock with `-j 1` and `X2W_TEST_DEBUG_LAYER=1`, `startup_target_views_hardware` and `startup_compute_dispatch_texture_hardware` passed in both presets, no skips. Negative control: with the refusal in `view_slot` disabled (`if (false && refusal != Refusal::none)`), `startup_target_views_warp` fails (the debug layer reports the views and the device is removed with `0x887a0001`; the process then exits `0xc0000409`). The record change is sound as far as I traced it: the record now holds the description that was forwarded (desktop format, repaired fields), and the consumers that map the format again (`view_format_of`, the dispatch) are unaffected because `desktop_format()` maps its outputs to themselves. **Mutants** (dev; CPU test, plus `startup_target_views_warp` and `startup_compute_dispatch_texture_warp` where marked "device"): Killed (13): - `*p.mip >= r->MipLevels` -> `>` (device; the CPU test does not catch it, only the mip-4 UAV in the WARP test does) - `*p.first >= limit` -> `>` - WSize `~0` exception removed - volume limit ignores the mip - counter alignment check removed - counter end bound `Width - 4` -> `Width` - multisample UAV allowed - multisample mismatch allowed for RTV/DSV - `view_slot` ignores the refusal (device) - record keeps the original description (device, `startup_compute_dispatch_texture_warp`) - repaired copy not forwarded (device) - counter offset not reset - default DSV allowed on a colour format Surviving (5), all with the device tests included; none blocks on its own, but they are untested rules: - zero `ArraySize` / `WSize` refusal removed (`!*p.count`) - `*p.plane > 1` -> `> 2` (no plane-2 case on a planar resource) - read-only-stencil flag dropped on `D32_FLOAT_S8X24_UINT` (only `D24_UNORM_S8_UINT` is covered) - typed cast allowed without `CastingFullyTypedFormatSupported` (no test passes `typed_cast`) - typed cast allows snorm <-> unorm (same reason) Equivalent: none found. Smaller notes, not blocking: - The PR body still says "Draft until an independent peer review"; the PR is not a draft. - The comment above `check()` names only the UAV and DSV descriptions; it also handles RTVs. Real-title run of this head merged onto the baseline commit: flaky. It was judged worse than the baseline on the first run (`[fail] judgement: Judged worse than the baseline: black-frame`) and passed on the re-run (`[warn] repeat: Failed on the first run and passed on a re-run (job 28).`). That does not block on its own. 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; WARP for the `_warp` tests. CI: `Build and test on Windows` passed on `78c320f5`. This reply was AI-assisted.
JohnConnorNPC commented 2026-11-29 13:05:08 +00:00 (Migrated from github.com)

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


Review of head 78c320f5 against main 94b679e7. I read the source and ran trial merges only; I did not build or run anything. git merge-tree --write-tree origin/main 78c320f5 exits 0.

Status: pigalot's change request on this head is still open, with no push or reply since. In that finding, legal R32_* UAV casts are refused, or rewritten to the resource format. That holds the merge, so I am not merging. I have nothing to add to the cast rule itself.

SHOULD

  1. A refused RTV, DSV or UAV keeps the slot's previous view. refuse_view writes a null view only for slot 18. The comment above it says: "A skipped UAV, RTV or DSV does not write a replacement to the desktop heap, so its previous descriptor record must stay live." This PR sends many more slot 19-21 calls down that path, with no switch on the default launcher path.

    • For an RTV or DSV, the title then passes that handle to OMSetRenderTargets and draws into whatever view was there before. The only trace is the first 6 x2w-d3d12 view refused: slot%d %s lines per reason.
    • Pigalot's table shows that views which work on main today reach this path, so a wrong refusal costs more than an empty target.
    • #3214 writes a null view of the same dimension for every refused SRV for exactly this reason ("so it never keeps a stale view").

    Could the refusals this PR adds write a null RTV, DSV or UAV of the requested dimension too? If keeping the old view is the safer choice for one of them, the body could say why.

NIT

  1. CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, ...) runs on each slot 19-21 call whose format differs from a typed resource's format. CastingFullyTypedFormatSupported does not change for a device, so one query per device would do.
  2. Merge order within this group (trial merges onto main): with this PR in, #3199 conflicts in d3d12_xs_device.cpp (view_slot). #3214 then conflicts in CMakeLists.txt, d3d12_xs_device.cpp and d3d12_draw.inl, where the last is its existing conflict with main. The body already says the depth-format and cast helpers should be shared with the SRV draft. Settling the order now would also settle which PR keeps those helpers.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7256277409 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#issuecomment-7256277409). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-29T13:05:08Z. --- Review of head `78c320f5` against `main` `94b679e7`. I read the source and ran trial merges only; I did not build or run anything. `git merge-tree --write-tree origin/main 78c320f5` exits 0. Status: pigalot's change request on this head is still open, with no push or reply since. In that finding, legal `R32_*` UAV casts are refused, or rewritten to the resource format. That holds the merge, so I am not merging. I have nothing to add to the cast rule itself. **SHOULD** 1. **A refused RTV, DSV or UAV keeps the slot's previous view.** `refuse_view` writes a null view only for slot 18. The comment above it says: "A skipped UAV, RTV or DSV does not write a replacement to the desktop heap, so its previous descriptor record must stay live." This PR sends many more slot 19-21 calls down that path, with no switch on the default launcher path. - For an RTV or DSV, the title then passes that handle to `OMSetRenderTargets` and draws into whatever view was there before. The only trace is the first 6 `x2w-d3d12 view refused: slot%d %s` lines per reason. - Pigalot's table shows that views which work on `main` today reach this path, so a wrong refusal costs more than an empty target. - #3214 writes a null view of the same dimension for every refused SRV for exactly this reason ("so it never keeps a stale view"). Could the refusals this PR adds write a null RTV, DSV or UAV of the requested dimension too? If keeping the old view is the safer choice for one of them, the body could say why. **NIT** 2. `CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, ...)` runs on each slot 19-21 call whose format differs from a typed resource's format. `CastingFullyTypedFormatSupported` does not change for a device, so one query per device would do. 3. Merge order within this group (trial merges onto `main`): with this PR in, #3199 conflicts in `d3d12_xs_device.cpp` (`view_slot`). #3214 then conflicts in `CMakeLists.txt`, `d3d12_xs_device.cpp` and `d3d12_draw.inl`, where the last is its existing conflict with `main`. The body already says the depth-format and cast helpers should be shared with the SRV draft. Settling the order now would also settle which PR keeps those helpers. AI-assisted.
tedin7 commented 2026-11-30 14:05:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-30T14:05:14Z.


Merged current main (077bff3ac) and fixed the cross-family R32 UAV typeless cast check (with a regression test covering legal R32 UAV casts while keeping invalid casts refused). Ready for CI and re-review.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7280812582 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3200#issuecomment-7280812582). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-30T14:05:14Z. --- Merged current `main` (`077bff3ac`) and fixed the cross-family R32 UAV typeless cast check (with a regression test covering legal R32 UAV casts while keeping invalid casts refused). Ready for CI and re-review.
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/3200:upstream-pr/3200'
git switch 'upstream-pr/3200'

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