startup: implement SetPredication command-list slot 59 (Part of #870) #2048
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2048
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2048/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@tedin7 on GitHub · 2026-11-24 23:37 UTC · original
tedin7:x2w-870-pred-event→main· +118 −0 · 5 files · 5 commits · closed without mergingPart 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:
g++ -std=c++17 -Wall tests/startup_predication_args.cpp && ./a.out->startup_predication_args: okg++ -std=c++17 tests/startup_command_list_slot_names.cpp && ./a.out-> passesx86_64-w64-mingw32-g++ -std=c++17 -fsyntax-onlyond3d12_xs_device.cpp-> no errors from the new code (the only errors are the existing SEH__tryones, which this compiler does not support)git diff --check-> cleanWhat 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_predicationon 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.cppplus 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] on GitHub · 2026-11-24 23:39 UTC · original · edited 2026-11-24 23:44 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
6c5a575ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@ -3065,0 +3105,4 @@self->own().predication_buffer = resource;self->own().predication_offset = offset;self->own().predication_operation = operation;list->SetPredication(resource, offset, static_cast<D3D12_PREDICATION_OP>(operation));@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:44 UTC · original
When a predicated-off translated draw first uses a CPU-backed sampled texture, this persistent desktop predicate also suppresses the
CopyTextureRegioncalls emitted byupload_texturethroughSliceFootprints::upload. However,upload_texturestill caches the content hash and setsstate.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 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:44 UTC · original
For buffers created through device slot 127, this guard does not establish that the resource uses COMMON tracking:
device_create_committed_xcreates UPLOAD buffers inGENERIC_READand READBACK buffers inCOPY_DEST, but itsnote_resourcecall records aResourceInfowhoseinitial_statedefaults to COMMON. Both heap types consequently pass this check, andrequire_stateemits aCOMMON -> PREDICATIONbarrier 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 👍 / 👎.
@ChazY11 on GitHub · 2026-11-24 23:56 UTC · original
Ran both host tests under MSVC, broke the argument checks six ways — all caught
Your
g++commands also work withcl, so this review needed no Windows device:predication_args.hif (!has_buffer) return clear;removedoperation > 1→> 2(allows op 2)outside_bufferreduced tooffset > buffer_bytesvalue_bytes8 → 4 (alignment and length together)% value_bytes→% 4The fourth is the interesting one:
offset > buffer_bytes || buffer_bytes - offset < value_bytesneeds both terms, because a value that startsinside 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_predicationadds four refusals that the header never sees:Check the ordering here, because it matters in one case: the
clearverdict callsSetPredication(nullptr, 0, EQUAL_ZERO)before theCOMMON-state check, which is correct for a null buffer — but it means a title that passes a valid buffer with
operation0/1 and a non-COMMON stateis refused after
x2w_predication::checkalready saidset. That is intended, and the switch'sset: break;falls through to it on purpose; it isworth 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.Widthis the buffer size in bytes forD3D12_RESOURCE_DIMENSION_BUFFER, which is why it can be passed straightto
check(...)— true for buffers, and the Dimension check immediately above is what makes it safe. Two lines apart, so the reasoning is local, butbinding them ("Width is the byte size only for a buffer, hence the Dimension check") would prevent someone from lifting the
check()call above itlater.
What is still unverified
git diff --checkclean and-fsyntax-onlyunder 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, theCOMMON-state transition is the piece nobody has executed.
Notes
@ -3065,0 +3105,4 @@self->own().predication_buffer = resource;self->own().predication_offset = offset;self->own().predication_operation = operation;list->SetPredication(resource, offset, static_cast<D3D12_PREDICATION_OP>(operation));@tedin7 on GitHub · 2026-11-25 00:58 UTC · original
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 on GitHub · 2026-11-25 00:58 UTC · original
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.
@tedin7 on GitHub · 2026-11-25 12:05 UTC · original
Thanks for the MSVC run and the mutation table.
Added two comment lines in
list_set_predication(new head93e1edd4, one commit on top of4db5bff8, comments only):Verdict::setcase:setmeans 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.check():Widthis the byte size only for a buffer, so the Dimension check must stay abovecheck().The
COMMONcheck you quoted is now a DEFAULT-heap check, followed byrequire_state. The ordering is the same.You are right that
require_state,resource_infoandrecordingare 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: okgit diff --check-> cleanAI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-25 13:34 UTC · original
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 now1efad269(main merged in).Windows Server 2025 WARP at
1efad269:AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-25 18:30 UTC · original
@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.
@tedin7 on GitHub · 2026-11-25 21:33 UTC · original
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.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:44 UTC · original · reviewed
💡 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
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".
@R0Y00 on GitHub · 2026-11-25 12:34 UTC · original · requested changes
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
Pull request closed