startup: implement SetPredication command-list slot 59 (Part of #870) #2041

Closed
tedin7 wants to merge 5 commits from upstream-pr/2048 into main
tedin7 commented 2026-11-24 23:37:57 +00:00 (Migrated from github.com)

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


Part of #870

What this unblocks: command list slot 59 (SetPredication) forwards to the desktop list instead of being a no-op, so titles that predicate draws no longer lose the condition.

Verification:

  • Linux (not Win2025): g++ -std=c++17 -Wall tests/startup_predication_args.cpp && ./a.out -> startup_predication_args: ok
  • Linux: g++ -std=c++17 tests/startup_command_list_slot_names.cpp && ./a.out -> passes
  • Linux: x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only on d3d12_xs_device.cpp -> no errors from the new code (the only errors are the existing SEH __try ones, which this compiler does not support)
  • git diff --check -> clean
  • NOT run: the Win2025 build and ctest. They still need to run.

What changed:

  • src/startup_stubs/predication_args.h: pure check of (buffer, offset, operation, buffer size). Refuses an operation above 1, an offset not a multiple of 8, and a value outside the buffer.
  • list_set_predication on slot 59 (desktop 55 + 4, inside the confirmed shifted run). Null buffer clears predication. A buffer must be a COMMON-tracked buffer and is moved to the predication state first. Bad calls are dropped and logged (first 16).
  • tests/startup_predication_args.cpp plus CMake entry.

Not done: BeginEvent / EndEvent. The desktop order plus four would put them at 61 and 62, but 61 is already ExecuteIndirect on this list, so the console slots are not known. Wiring a guess would hide a real method. They need a call-site log (x2w-noop) to confirm the slots first.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593642939 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:37:57Z. --- Part of #870 What this unblocks: command list slot 59 (SetPredication) forwards to the desktop list instead of being a no-op, so titles that predicate draws no longer lose the condition. Verification: - Linux (not Win2025): `g++ -std=c++17 -Wall tests/startup_predication_args.cpp && ./a.out` -> `startup_predication_args: ok` - Linux: `g++ -std=c++17 tests/startup_command_list_slot_names.cpp && ./a.out` -> passes - Linux: `x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only` on `d3d12_xs_device.cpp` -> no errors from the new code (the only errors are the existing SEH `__try` ones, which this compiler does not support) - `git diff --check` -> clean - NOT run: the Win2025 build and ctest. They still need to run. What changed: - `src/startup_stubs/predication_args.h`: pure check of (buffer, offset, operation, buffer size). Refuses an operation above 1, an offset not a multiple of 8, and a value outside the buffer. - `list_set_predication` on slot 59 (desktop 55 + 4, inside the confirmed shifted run). Null buffer clears predication. A buffer must be a COMMON-tracked buffer and is moved to the predication state first. Bad calls are dropped and logged (first 16). - `tests/startup_predication_args.cpp` plus CMake entry. Not done: BeginEvent / EndEvent. The desktop order plus four would put them at 61 and 62, but 61 is already ExecuteIndirect on this list, so the console slots are not known. Wiring a guess would hide a real method. They need a call-site log (x2w-noop) to confirm the slots first. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 01:01:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:44:00Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c5a575929

ℹ️ 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:6049240385 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#pullrequestreview-6049240385). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:44:00Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `6c5a575929` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-25 01:01:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:01Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049917219 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#pullrequestreview-6049917219). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:58:01Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 01:01:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:03Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049917523 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#pullrequestreview-6049917523). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:58:03Z. **Review:** COMMENTED --- _No description provided._
chatgpt-codex-connector[bot commented 2026-11-25 01:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:39:09Z.


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-24T23:44:02.568170Z 6c5a575 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:7147643537 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#issuecomment-7147643537). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:39:09Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"6c5a5759299eb0d9ad20dc44d787bf2b7c7716d9","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-24T23:44:02.568170Z">2026-11-24T23:44:02.568170Z</relative-time> | `6c5a575` | 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>
ChazY11 commented 2026-11-25 01:02:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:56:13Z.


Ran both host tests under MSVC, broke the argument checks six ways — all caught

Your g++ commands also work with cl, so this review needed no Windows device:

cl /nologo /std:c++17 /EHsc tests/startup_predication_args.cpp /I src/startup_stubs
startup_predication_args: ok            exit 0

cl /nologo /std:c++17 /EHsc tests/startup_command_list_slot_names.cpp /I src/startup_stubs
command list slot name checks passed    exit 0
mutation in predication_args.h result
if (!has_buffer) return clear; removed caught
operation > 1 → > 2 (allows op 2) caught
the 8-byte alignment check removed caught
outside_buffer reduced to offset > buffer_bytes caught
value_bytes 8 → 4 (alignment and length together) caught
alignment check % value_bytes → % 4 caught

The fourth is the interesting one: offset > buffer_bytes || buffer_bytes - offset < value_bytes needs both terms, because a value that starts
inside the buffer but runs past its end must be refused, and dropping the second term turns the aliasing case into a driver error. It is pinned.

The part your two tests cannot reach, and where I would look next

list_set_predication adds four refusals that the header never sees:

if (!list) return refuse("list is closed");
if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real))
    return refuse("buffer has no desktop resource");
if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer");
const auto* info = resource_info(buffer);
if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON)
    return refuse("buffer does not use COMMON state tracking");

Check the ordering here, because it matters in one case: the clear verdict calls SetPredication(nullptr, 0, EQUAL_ZERO) before the
COMMON-state check, which is correct for a null buffer — but it means a title that passes a valid buffer with operation 0/1 and a non-COMMON state
is refused after x2w_predication::check already said set. That is intended, and the switch's set: break; falls through to it on purpose; it is
worth one comment line, because the apparent flow ("check said ok, then we refuse anyway") looks like a bug to a reader in a hurry.

The other thing I would state: desc.Width is the buffer size in bytes for D3D12_RESOURCE_DIMENSION_BUFFER, which is why it can be passed straight
to check(...) — true for buffers, and the Dimension check immediately above is what makes it safe. Two lines apart, so the reasoning is local, but
binding them ("Width is the byte size only for a buffer, hence the Dimension check") would prevent someone from lifting the check() call above it
later.

What is still unverified

git diff --check clean and -fsyntax-only under mingw are not a Windows build; you say so, and I can add that the device-side paths here
(require_state, resource_info, recording) are exactly the ones a host test cannot cover. If the Win2025 ctest does not run before merge, the
COMMON-state transition is the piece nobody has executed.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147957588 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#issuecomment-7147957588). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:56:13Z. --- ## Ran both host tests under MSVC, broke the argument checks six ways — all caught Your `g++` commands also work with `cl`, so this review needed no Windows device: ```powershell cl /nologo /std:c++17 /EHsc tests/startup_predication_args.cpp /I src/startup_stubs startup_predication_args: ok exit 0 cl /nologo /std:c++17 /EHsc tests/startup_command_list_slot_names.cpp /I src/startup_stubs command list slot name checks passed exit 0 ``` | mutation in `predication_args.h` | result | |---|---| | `if (!has_buffer) return clear;` removed | **caught** | | `operation > 1` → `> 2` (allows op 2) | **caught** | | the 8-byte alignment check removed | **caught** | | `outside_buffer` reduced to `offset > buffer_bytes` | **caught** | | `value_bytes` 8 → 4 (alignment and length together) | **caught** | | alignment check `% value_bytes` → `% 4` | **caught** | The fourth is the interesting one: `offset > buffer_bytes || buffer_bytes - offset < value_bytes` needs **both** terms, because a value that starts inside the buffer but runs past its end must be refused, and dropping the second term turns the aliasing case into a driver error. It is pinned. ## The part your two tests cannot reach, and where I would look next `list_set_predication` adds four refusals that the header never sees: ```cpp if (!list) return refuse("list is closed"); if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real)) return refuse("buffer has no desktop resource"); if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer"); const auto* info = resource_info(buffer); if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON) return refuse("buffer does not use COMMON state tracking"); ``` Check the **ordering** here, because it matters in one case: the `clear` verdict calls `SetPredication(nullptr, 0, EQUAL_ZERO)` **before** the COMMON-state check, which is correct for a null buffer — but it means a title that passes a valid buffer with `operation` 0/1 and a non-COMMON state is refused *after* `x2w_predication::check` already said `set`. That is intended, and the switch's `set: break;` falls through to it on purpose; it is worth one comment line, because the apparent flow ("check said ok, then we refuse anyway") looks like a bug to a reader in a hurry. The other thing I would state: `desc.Width` is the buffer size in bytes for `D3D12_RESOURCE_DIMENSION_BUFFER`, which is why it can be passed straight to `check(...)` — true for buffers, and the Dimension check immediately above is what makes it safe. Two lines apart, so the reasoning is local, but binding them ("Width is the byte size only for a buffer, hence the Dimension check") would prevent someone from lifting the `check()` call above it later. ## What is still unverified `git diff --check` clean and `-fsyntax-only` under mingw are not a Windows build; you say so, and I can add that the **device-side** paths here (`require_state`, `resource_info`, `recording`) are exactly the ones a host test cannot cover. If the Win2025 ctest does not run before merge, the COMMON-state transition is the piece nobody has executed. ## Notes - AI-assisted review.
chatgpt-codex-connector[bot commented 2026-11-25 01:02:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:44:00Z.

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

@@ -2297,6 +2298,38 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference)
 {
     if (auto* list = recording(self)) list->OMSetStencilRef(reference);
 }
+// List slot 59 (desktop 55 + 4), SetPredication(buffer, offset, operation). A null buffer turns predication off.
+// A buffer must be a COMMON-tracked desktop buffer; it is moved to the predication state before the call.
+void __stdcall list_set_predication(Wrapper* self, void* buffer_arg, u64 offset, UINT operation)
+{
+    const auto refuse = [](const char* reason) {
+        static LONG refusals;
+        if (first_calls(refusals, 16)) log("x2w-render SetPredication refused: %s", reason);
+    };
+    auto* list = recording(self);
+    if (!list) return refuse("list is closed");
+    Wrapper* buffer = as_wrapper(buffer_arg);
+    const bool has_buffer = buffer_arg != nullptr;
+    if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real))
+        return refuse("buffer has no desktop resource");
+    auto* resource = has_buffer ? static_cast<ID3D12Resource*>(buffer->own().real) : nullptr;
+    const auto desc = has_buffer ? resource->GetDesc() : D3D12_RESOURCE_DESC{};
+    if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer");
+    switch (x2w_predication::check(has_buffer, offset, operation, desc.Width)) {
+    case x2w_predication::Verdict::clear:
+        list->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO);
+        return;
+    case x2w_predication::Verdict::set: break;
+    case x2w_predication::Verdict::bad_operation: return refuse("operation is not 0 or 1");
+    case x2w_predication::Verdict::bad_offset: return refuse("offset is not a multiple of 8");
+    case x2w_predication::Verdict::outside_buffer: return refuse("value is outside the buffer");
+    }
+    const auto* info = resource_info(buffer);
+    if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON)
+        return refuse("buffer does not use COMMON state tracking");
+    require_state(self, resource, D3D12_RESOURCE_STATE_PREDICATION);
+    list->SetPredication(resource, offset, static_cast<D3D12_PREDICATION_OP>(operation));

P1 Badge Exclude internal texture uploads from guest predication

When a predicated-off translated draw first uses a CPU-backed sampled texture, this persistent desktop predicate also suppresses the CopyTextureRegion calls emitted by upload_texture through SliceFootprints::upload. However, upload_texture still caches the content hash and sets state.done = true (d3d12_draw.inl:793–796). A later unpredicated draw using unchanged contents therefore skips the upload and samples an uninitialized or stale texture, so the corruption persists beyond the predicated draw. Track the guest predicate and temporarily disable/restore it around shim-internal texture uploads.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688127134 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#discussion_r4688127134). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:44:00Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 2331 ~~~~diff @@ -2297,6 +2298,38 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference) { if (auto* list = recording(self)) list->OMSetStencilRef(reference); } +// List slot 59 (desktop 55 + 4), SetPredication(buffer, offset, operation). A null buffer turns predication off. +// A buffer must be a COMMON-tracked desktop buffer; it is moved to the predication state before the call. +void __stdcall list_set_predication(Wrapper* self, void* buffer_arg, u64 offset, UINT operation) +{ + const auto refuse = [](const char* reason) { + static LONG refusals; + if (first_calls(refusals, 16)) log("x2w-render SetPredication refused: %s", reason); + }; + auto* list = recording(self); + if (!list) return refuse("list is closed"); + Wrapper* buffer = as_wrapper(buffer_arg); + const bool has_buffer = buffer_arg != nullptr; + if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real)) + return refuse("buffer has no desktop resource"); + auto* resource = has_buffer ? static_cast<ID3D12Resource*>(buffer->own().real) : nullptr; + const auto desc = has_buffer ? resource->GetDesc() : D3D12_RESOURCE_DESC{}; + if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer"); + switch (x2w_predication::check(has_buffer, offset, operation, desc.Width)) { + case x2w_predication::Verdict::clear: + list->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + return; + case x2w_predication::Verdict::set: break; + case x2w_predication::Verdict::bad_operation: return refuse("operation is not 0 or 1"); + case x2w_predication::Verdict::bad_offset: return refuse("offset is not a multiple of 8"); + case x2w_predication::Verdict::outside_buffer: return refuse("value is outside the buffer"); + } + const auto* info = resource_info(buffer); + if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON) + return refuse("buffer does not use COMMON state tracking"); + require_state(self, resource, D3D12_RESOURCE_STATE_PREDICATION); + list->SetPredication(resource, offset, static_cast<D3D12_PREDICATION_OP>(operation)); ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Exclude internal texture uploads from guest predication** When a predicated-off translated draw first uses a CPU-backed sampled texture, this persistent desktop predicate also suppresses the `CopyTextureRegion` calls emitted by `upload_texture` through `SliceFootprints::upload`. However, `upload_texture` still caches the content hash and sets `state.done = true` (`d3d12_draw.inl:793–796`). A later unpredicated draw using unchanged contents therefore skips the upload and samples an uninitialized or stale texture, so the corruption persists beyond the predicated draw. Track the guest predicate and temporarily disable/restore it around shim-internal texture uploads. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:44:00Z.

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

@@ -2297,6 +2298,38 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference)
 {
     if (auto* list = recording(self)) list->OMSetStencilRef(reference);
 }
+// List slot 59 (desktop 55 + 4), SetPredication(buffer, offset, operation). A null buffer turns predication off.
+// A buffer must be a COMMON-tracked desktop buffer; it is moved to the predication state before the call.
+void __stdcall list_set_predication(Wrapper* self, void* buffer_arg, u64 offset, UINT operation)
+{
+    const auto refuse = [](const char* reason) {
+        static LONG refusals;
+        if (first_calls(refusals, 16)) log("x2w-render SetPredication refused: %s", reason);
+    };
+    auto* list = recording(self);
+    if (!list) return refuse("list is closed");
+    Wrapper* buffer = as_wrapper(buffer_arg);
+    const bool has_buffer = buffer_arg != nullptr;
+    if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real))
+        return refuse("buffer has no desktop resource");
+    auto* resource = has_buffer ? static_cast<ID3D12Resource*>(buffer->own().real) : nullptr;
+    const auto desc = has_buffer ? resource->GetDesc() : D3D12_RESOURCE_DESC{};
+    if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer");
+    switch (x2w_predication::check(has_buffer, offset, operation, desc.Width)) {
+    case x2w_predication::Verdict::clear:
+        list->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO);
+        return;
+    case x2w_predication::Verdict::set: break;
+    case x2w_predication::Verdict::bad_operation: return refuse("operation is not 0 or 1");
+    case x2w_predication::Verdict::bad_offset: return refuse("offset is not a multiple of 8");
+    case x2w_predication::Verdict::outside_buffer: return refuse("value is outside the buffer");
+    }
+    const auto* info = resource_info(buffer);
+    if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON)
+        return refuse("buffer does not use COMMON state tracking");
+    require_state(self, resource, D3D12_RESOURCE_STATE_PREDICATION);

P2 Badge Check the actual heap state before using COMMON tracking

For buffers created through device slot 127, this guard does not establish that the resource uses COMMON tracking: device_create_committed_x creates UPLOAD buffers in GENERIC_READ and READBACK buffers in COPY_DEST, but its note_resource call records a ResourceInfo whose initial_state defaults to COMMON. Both heap types consequently pass this check, and require_state emits a COMMON -> PREDICATION barrier followed by a return to COMMON at Close. Those transitions violate the fixed-state requirements of upload/readback heaps and introduce D3D12 validation errors. Record or query the actual heap/state before routing these buffers through the COMMON-state tracker.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688127137 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#discussion_r4688127137). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:44:00Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 2330 ~~~~diff @@ -2297,6 +2298,38 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference) { if (auto* list = recording(self)) list->OMSetStencilRef(reference); } +// List slot 59 (desktop 55 + 4), SetPredication(buffer, offset, operation). A null buffer turns predication off. +// A buffer must be a COMMON-tracked desktop buffer; it is moved to the predication state before the call. +void __stdcall list_set_predication(Wrapper* self, void* buffer_arg, u64 offset, UINT operation) +{ + const auto refuse = [](const char* reason) { + static LONG refusals; + if (first_calls(refusals, 16)) log("x2w-render SetPredication refused: %s", reason); + }; + auto* list = recording(self); + if (!list) return refuse("list is closed"); + Wrapper* buffer = as_wrapper(buffer_arg); + const bool has_buffer = buffer_arg != nullptr; + if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real)) + return refuse("buffer has no desktop resource"); + auto* resource = has_buffer ? static_cast<ID3D12Resource*>(buffer->own().real) : nullptr; + const auto desc = has_buffer ? resource->GetDesc() : D3D12_RESOURCE_DESC{}; + if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer"); + switch (x2w_predication::check(has_buffer, offset, operation, desc.Width)) { + case x2w_predication::Verdict::clear: + list->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + return; + case x2w_predication::Verdict::set: break; + case x2w_predication::Verdict::bad_operation: return refuse("operation is not 0 or 1"); + case x2w_predication::Verdict::bad_offset: return refuse("offset is not a multiple of 8"); + case x2w_predication::Verdict::outside_buffer: return refuse("value is outside the buffer"); + } + const auto* info = resource_info(buffer); + if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON) + return refuse("buffer does not use COMMON state tracking"); + require_state(self, resource, D3D12_RESOURCE_STATE_PREDICATION); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Check the actual heap state before using COMMON tracking** For buffers created through device slot 127, this guard does not establish that the resource uses COMMON tracking: `device_create_committed_x` creates UPLOAD buffers in `GENERIC_READ` and READBACK buffers in `COPY_DEST`, but its `note_resource` call records a `ResourceInfo` whose `initial_state` defaults to COMMON. Both heap types consequently pass this check, and `require_state` emits a `COMMON -> PREDICATION` barrier followed by a return to COMMON at Close. Those transitions violate the fixed-state requirements of upload/readback heaps and introduce D3D12 validation errors. Record or query the actual heap/state before routing these buffers through the COMMON-state tracker. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 01:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:00Z.

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

@@ -2297,6 +2298,38 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference)
 {
     if (auto* list = recording(self)) list->OMSetStencilRef(reference);
 }
+// List slot 59 (desktop 55 + 4), SetPredication(buffer, offset, operation). A null buffer turns predication off.
+// A buffer must be a COMMON-tracked desktop buffer; it is moved to the predication state before the call.
+void __stdcall list_set_predication(Wrapper* self, void* buffer_arg, u64 offset, UINT operation)
+{
+    const auto refuse = [](const char* reason) {
+        static LONG refusals;
+        if (first_calls(refusals, 16)) log("x2w-render SetPredication refused: %s", reason);
+    };
+    auto* list = recording(self);
+    if (!list) return refuse("list is closed");
+    Wrapper* buffer = as_wrapper(buffer_arg);
+    const bool has_buffer = buffer_arg != nullptr;
+    if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real))
+        return refuse("buffer has no desktop resource");
+    auto* resource = has_buffer ? static_cast<ID3D12Resource*>(buffer->own().real) : nullptr;
+    const auto desc = has_buffer ? resource->GetDesc() : D3D12_RESOURCE_DESC{};
+    if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer");
+    switch (x2w_predication::check(has_buffer, offset, operation, desc.Width)) {
+    case x2w_predication::Verdict::clear:
+        list->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO);
+        return;
+    case x2w_predication::Verdict::set: break;
+    case x2w_predication::Verdict::bad_operation: return refuse("operation is not 0 or 1");
+    case x2w_predication::Verdict::bad_offset: return refuse("offset is not a multiple of 8");
+    case x2w_predication::Verdict::outside_buffer: return refuse("value is outside the buffer");
+    }
+    const auto* info = resource_info(buffer);
+    if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON)
+        return refuse("buffer does not use COMMON state tracking");
+    require_state(self, resource, D3D12_RESOURCE_STATE_PREDICATION);
+    list->SetPredication(resource, offset, static_cast<D3D12_PREDICATION_OP>(operation));

Fixed in dad8bf5d (local rebase, push pending): internal texture uploads now lift the guest predicate and restore it afterwards, so the upload cache never marks a texture done without the copy.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688734886 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#discussion_r4688734886). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:58:00Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 2331 ~~~~diff @@ -2297,6 +2298,38 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference) { if (auto* list = recording(self)) list->OMSetStencilRef(reference); } +// List slot 59 (desktop 55 + 4), SetPredication(buffer, offset, operation). A null buffer turns predication off. +// A buffer must be a COMMON-tracked desktop buffer; it is moved to the predication state before the call. +void __stdcall list_set_predication(Wrapper* self, void* buffer_arg, u64 offset, UINT operation) +{ + const auto refuse = [](const char* reason) { + static LONG refusals; + if (first_calls(refusals, 16)) log("x2w-render SetPredication refused: %s", reason); + }; + auto* list = recording(self); + if (!list) return refuse("list is closed"); + Wrapper* buffer = as_wrapper(buffer_arg); + const bool has_buffer = buffer_arg != nullptr; + if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real)) + return refuse("buffer has no desktop resource"); + auto* resource = has_buffer ? static_cast<ID3D12Resource*>(buffer->own().real) : nullptr; + const auto desc = has_buffer ? resource->GetDesc() : D3D12_RESOURCE_DESC{}; + if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer"); + switch (x2w_predication::check(has_buffer, offset, operation, desc.Width)) { + case x2w_predication::Verdict::clear: + list->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + return; + case x2w_predication::Verdict::set: break; + case x2w_predication::Verdict::bad_operation: return refuse("operation is not 0 or 1"); + case x2w_predication::Verdict::bad_offset: return refuse("offset is not a multiple of 8"); + case x2w_predication::Verdict::outside_buffer: return refuse("value is outside the buffer"); + } + const auto* info = resource_info(buffer); + if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON) + return refuse("buffer does not use COMMON state tracking"); + require_state(self, resource, D3D12_RESOURCE_STATE_PREDICATION); + list->SetPredication(resource, offset, static_cast<D3D12_PREDICATION_OP>(operation)); ~~~~ --- Fixed in dad8bf5d (local rebase, push pending): internal texture uploads now lift the guest predicate and restore it afterwards, so the upload cache never marks a texture done without the copy. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 01:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:58:03Z.

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

@@ -2297,6 +2298,38 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference)
 {
     if (auto* list = recording(self)) list->OMSetStencilRef(reference);
 }
+// List slot 59 (desktop 55 + 4), SetPredication(buffer, offset, operation). A null buffer turns predication off.
+// A buffer must be a COMMON-tracked desktop buffer; it is moved to the predication state before the call.
+void __stdcall list_set_predication(Wrapper* self, void* buffer_arg, u64 offset, UINT operation)
+{
+    const auto refuse = [](const char* reason) {
+        static LONG refusals;
+        if (first_calls(refusals, 16)) log("x2w-render SetPredication refused: %s", reason);
+    };
+    auto* list = recording(self);
+    if (!list) return refuse("list is closed");
+    Wrapper* buffer = as_wrapper(buffer_arg);
+    const bool has_buffer = buffer_arg != nullptr;
+    if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real))
+        return refuse("buffer has no desktop resource");
+    auto* resource = has_buffer ? static_cast<ID3D12Resource*>(buffer->own().real) : nullptr;
+    const auto desc = has_buffer ? resource->GetDesc() : D3D12_RESOURCE_DESC{};
+    if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer");
+    switch (x2w_predication::check(has_buffer, offset, operation, desc.Width)) {
+    case x2w_predication::Verdict::clear:
+        list->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO);
+        return;
+    case x2w_predication::Verdict::set: break;
+    case x2w_predication::Verdict::bad_operation: return refuse("operation is not 0 or 1");
+    case x2w_predication::Verdict::bad_offset: return refuse("offset is not a multiple of 8");
+    case x2w_predication::Verdict::outside_buffer: return refuse("value is outside the buffer");
+    }
+    const auto* info = resource_info(buffer);
+    if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON)
+        return refuse("buffer does not use COMMON state tracking");
+    require_state(self, resource, D3D12_RESOURCE_STATE_PREDICATION);

Fixed in dad8bf5d (local rebase, push pending): the predicate buffer must now be in a DEFAULT heap (checked with GetHeapProperties); upload and readback heaps are refused.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688735238 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#discussion_r4688735238). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:58:03Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 2330 ~~~~diff @@ -2297,6 +2298,38 @@ void __stdcall list_stencil_ref(Wrapper* self, UINT reference) { if (auto* list = recording(self)) list->OMSetStencilRef(reference); } +// List slot 59 (desktop 55 + 4), SetPredication(buffer, offset, operation). A null buffer turns predication off. +// A buffer must be a COMMON-tracked desktop buffer; it is moved to the predication state before the call. +void __stdcall list_set_predication(Wrapper* self, void* buffer_arg, u64 offset, UINT operation) +{ + const auto refuse = [](const char* reason) { + static LONG refusals; + if (first_calls(refusals, 16)) log("x2w-render SetPredication refused: %s", reason); + }; + auto* list = recording(self); + if (!list) return refuse("list is closed"); + Wrapper* buffer = as_wrapper(buffer_arg); + const bool has_buffer = buffer_arg != nullptr; + if (has_buffer && (!buffer || buffer->own().kind != resource_kind || !buffer->own().real)) + return refuse("buffer has no desktop resource"); + auto* resource = has_buffer ? static_cast<ID3D12Resource*>(buffer->own().real) : nullptr; + const auto desc = has_buffer ? resource->GetDesc() : D3D12_RESOURCE_DESC{}; + if (has_buffer && desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return refuse("predication needs a buffer"); + switch (x2w_predication::check(has_buffer, offset, operation, desc.Width)) { + case x2w_predication::Verdict::clear: + list->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + return; + case x2w_predication::Verdict::set: break; + case x2w_predication::Verdict::bad_operation: return refuse("operation is not 0 or 1"); + case x2w_predication::Verdict::bad_offset: return refuse("offset is not a multiple of 8"); + case x2w_predication::Verdict::outside_buffer: return refuse("value is outside the buffer"); + } + const auto* info = resource_info(buffer); + if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON) + return refuse("buffer does not use COMMON state tracking"); + require_state(self, resource, D3D12_RESOURCE_STATE_PREDICATION); ~~~~ --- Fixed in dad8bf5d (local rebase, push pending): the predicate buffer must now be in a DEFAULT heap (checked with GetHeapProperties); upload and readback heaps are refused. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-25 13:00:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T12:34:35Z.

Review: CHANGES_REQUESTED


The texture upload's PredicationLift changes the predicate snapshot. Desktop SetPredication samples the buffer when the GPU reaches the recorded command. Disabling it for an upload and reapplying the original buffer and offset samples again, so a write between those two points can make a later draw take the opposite path. Please keep the original snapshot across internal work or refuse the affected combination. Add a source-built DIRECT-list readback that changes the predicate after the initial snapshot, first with native SetPredication and then through the shim with an internal upload. Compare the draw decision and the uploaded bytes. Microsoft D3D12 predication

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057677471 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#pullrequestreview-6057677471). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T12:34:35Z. **Review:** CHANGES_REQUESTED --- The texture upload's PredicationLift changes the predicate snapshot. Desktop SetPredication samples the buffer when the GPU reaches the recorded command. Disabling it for an upload and reapplying the original buffer and offset samples again, so a write between those two points can make a later draw take the opposite path. Please keep the original snapshot across internal work or refuse the affected combination. Add a source-built DIRECT-list readback that changes the predicate after the initial snapshot, first with native SetPredication and then through the shim with an internal upload. Compare the draw decision and the uploaded bytes. [Microsoft D3D12 predication](https://learn.microsoft.com/en-us/windows/win32/direct3d12/predication)
tedin7 commented 2026-11-25 13:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:05:39Z.


Thanks for the MSVC run and the mutation table.

Added two comment lines in list_set_predication (new head 93e1edd4, one commit on top of 4db5bff8, comments only):

  • Above the Verdict::set case: set means the arguments are valid, but the heap and state checks below can still refuse. A refusal returns before any list call, so the list keeps its previous predication.
  • Above check(): Width is the byte size only for a buffer, so the Dimension check must stay above check().

The COMMON check you quoted is now a DEFAULT-heap check, followed by require_state. The ordering is the same.

You are right that require_state, resource_info and recording are device-side and not reachable from the host tests. They are covered only by the Win2025 ctest run, not by what I ran here.

Commands run locally (Linux):

  • g++ -std=c++17 tests/startup_predication_args.cpp -I src/startup_stubs -o /tmp/pa6 && /tmp/pa6 -> startup_predication_args: ok
  • git diff --check -> clean

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161910185 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#issuecomment-7161910185). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:05:39Z. --- Thanks for the MSVC run and the mutation table. Added two comment lines in `list_set_predication` (new head 93e1edd4, one commit on top of 4db5bff8, comments only): - Above the `Verdict::set` case: `set` means the arguments are valid, but the heap and state checks below can still refuse. A refusal returns before any list call, so the list keeps its previous predication. - Above `check()`: `Width` is the byte size only for a buffer, so the Dimension check must stay above `check()`. The `COMMON` check you quoted is now a DEFAULT-heap check, followed by `require_state`. The ordering is the same. You are right that `require_state`, `resource_info` and `recording` are device-side and not reachable from the host tests. They are covered only by the Win2025 ctest run, not by what I ran here. Commands run locally (Linux): - `g++ -std=c++17 tests/startup_predication_args.cpp -I src/startup_stubs -o /tmp/pa6 && /tmp/pa6` -> `startup_predication_args: ok` - `git diff --check` -> clean AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 14:05:10 +00:00 (Migrated from github.com)

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


Fixed in 7d6b46b1: an internal texture upload is now refused while a guest predicate is active, so the upload can no longer change the predicate snapshot that the next draw samples. Head is now 1efad269 (main merged in).

Windows Server 2025 WARP at 1efad269:

x2w_pipe.py win2025 2048
dev:     100% tests passed out of 23
release: 100% tests passed out of 23

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163963242 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#issuecomment-7163963242). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:34:02Z. --- Fixed in 7d6b46b1: an internal texture upload is now refused while a guest predicate is active, so the upload can no longer change the predicate snapshot that the next draw samples. Head is now 1efad269 (main merged in). Windows Server 2025 WARP at 1efad269: ``` x2w_pipe.py win2025 2048 dev: 100% tests passed out of 23 release: 100% tests passed out of 23 ``` AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 19:04:13 +00:00 (Migrated from github.com)

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


@R0Y00 the changes you requested are addressed on the current head 1efad2698bd0bf1872afbf78e7e4cf2dd2e75949 (see our reply above). Could you re-review, or dismiss the change request if it is resolved? Under the new scope, MasterDomino can then review and merge it.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7170999756 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#issuecomment-7170999756). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T18:30:23Z. --- @R0Y00 the changes you requested are addressed on the current head `1efad2698bd0bf1872afbf78e7e4cf2dd2e75949` (see our reply above). Could you re-review, or dismiss the change request if it is resolved? Under the new scope, MasterDomino can then review and merge it. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 22:01:50 +00:00
tedin7 commented 2026-11-25 22:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T21:33:40Z.


Closing this PR for now so we can focus on the test-speed work. The branch stays as it is, and review comments here remain valid.

We will reopen it later, bring it up to date with main, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7175239696 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2048#issuecomment-7175239696). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T21:33:40Z. --- Closing this PR for now so we can focus on the test-speed work. The branch stays as it is, and review comments here remain valid. We will reopen it later, bring it up to date with `main`, re-run the Win2025 WARP checks at its head, and post the result here. AI-assisted; commands listed were executed locally.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2041
No description provided.