GPU: implement ClearState on command lists #2982

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/2984 into main
fuzeofficlal commented 2026-11-26 02:12:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:12:50Z.


Problem

ID3D12GraphicsCommandList::ClearState (slot 11 / 0x58) was missing from METHODS in crates/victory-gpu/src/list.rs and fell through to the generic unimplemented stub. Because ClearState returns void, calling ClearState(pso_b) silently left State.pipeline pointing to the previous pipeline along with stale root arguments, descriptor heaps, render/depth targets, vertex/index views, topology, depth bounds, and Fixed replay state, and never cleared the host command list.

Fix

  • Register clear_state at slot 11 (0x58) in METHODS (preserving the same slot in both LIST_FUNCTIONS and NEWER_LIST_FUNCTIONS).
  • On open DIRECT and COMPUTE lists, call host.list.ClearState(None), clear all guest and cached host bindings plus Fixed replay state via State::clear_state(pipeline) while preserving resources needed by previously recorded commands (dynamic, fresh_tables, root_slots, root_run, memory, deferred uploads/copies), and record pipeline::bound(pipeline).
  • Track explicit guest closed state on List (distinct from internal segment cuts at waits) so ClearState on a closed list is safely ignored.

Verification

  • Added draw::tests::clear_state_switches_compute_pipeline_without_losing_recorded_work (executes two Wave32 compute pipelines across ClearState(b) in a single list and reads back both title buffers), draw::tests::clear_state_clears_graphics_bindings_before_a_segment_cut (verifies all bindings and Fixed state clear before a wait64 segment cut while retaining recorded dynamic/memory/deferred work), and list::tests::clear_state_has_the_same_slot_in_both_layouts.
  • cargo test --locked -p victory-gpu --lib -- list:: draw:: --test-threads=1 (VICTORY_D3D12_DEBUG=1): 27/27 passed on both hardware D3D12 (RTX 5090) and WARP.
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings (default & --features diagnostics): 0 warnings.
  • cargo xtask policy: 191 files ok.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6617988740 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2984). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:12:50Z. --- ## Problem `ID3D12GraphicsCommandList::ClearState` (slot 11 / `0x58`) was missing from `METHODS` in `crates/victory-gpu/src/list.rs` and fell through to the generic unimplemented stub. Because `ClearState` returns `void`, calling `ClearState(pso_b)` silently left `State.pipeline` pointing to the previous pipeline along with stale root arguments, descriptor heaps, render/depth targets, vertex/index views, topology, depth bounds, and `Fixed` replay state, and never cleared the host command list. ## Fix - Register `clear_state` at slot 11 (`0x58`) in `METHODS` (preserving the same slot in both `LIST_FUNCTIONS` and `NEWER_LIST_FUNCTIONS`). - On open `DIRECT` and `COMPUTE` lists, call `host.list.ClearState(None)`, clear all guest and cached host bindings plus `Fixed` replay state via `State::clear_state(pipeline)` while preserving resources needed by previously recorded commands (`dynamic`, `fresh_tables`, `root_slots`, `root_run`, `memory`, deferred uploads/copies), and record `pipeline::bound(pipeline)`. - Track explicit guest `closed` state on `List` (distinct from internal segment cuts at waits) so `ClearState` on a closed list is safely ignored. ## Verification - Added `draw::tests::clear_state_switches_compute_pipeline_without_losing_recorded_work` (executes two Wave32 compute pipelines across `ClearState(b)` in a single list and reads back both title buffers), `draw::tests::clear_state_clears_graphics_bindings_before_a_segment_cut` (verifies all bindings and `Fixed` state clear before a `wait64` segment cut while retaining recorded `dynamic`/`memory`/deferred work), and `list::tests::clear_state_has_the_same_slot_in_both_layouts`. - `cargo test --locked -p victory-gpu --lib -- list:: draw:: --test-threads=1` (`VICTORY_D3D12_DEBUG=1`): **27/27 passed** on both hardware D3D12 (RTX 5090) and WARP. - `cargo clippy --locked -p victory-gpu --tests -- -D warnings` (default & `--features diagnostics`): 0 warnings. - `cargo xtask policy`: 191 files ok.
kotekompotek commented 2026-11-26 03:04:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:32:28Z.

Review: COMMENTED


Verified: ClearState lands at vtable slot 0x58 in both list layouts, gates on direct/compute kind and !closed (matching D3D12 where it's invalid on bundles and after Close — silent no-op is a fair emulation choice). The important part is what state.clear_state keeps: fresh_tables, root_slots, root_run, dynamic entries and the memory map all survive since already-recorded work still references them — the tests assert exactly that, plus that a wait-cut segment boundary doesn't resurrect cleared bindings.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067784273 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2984#pullrequestreview-6067784273). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:32:28Z. **Review:** COMMENTED --- Verified: ClearState lands at vtable slot 0x58 in both list layouts, gates on direct/compute kind and !closed (matching D3D12 where it's invalid on bundles and after Close — silent no-op is a fair emulation choice). The important part is what state.clear_state keeps: fresh_tables, root_slots, root_run, dynamic entries and the memory map all survive since already-recorded work still references them — the tests assert exactly that, plus that a wait-cut segment boundary doesn't resurrect cleared bindings.
oni-swr commented 2026-11-26 03:05:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T03:02:29Z.


Independent Windows WARP test run of 3cdfd5f875c44e2249fa46abee76ff57ab5d9187, compared with its exact parent 63bcca43c6a00a758510398fa43096ce7e4f7df0. This reports test results only, not a review verdict.

Setup. Software only. VICTORY_D3D12_WARP=1 and VICTORY_WARP=1, built with --features diagnostics. VICTORY_DXIL pointed at the Windows SDK 10.0.26100.0 x64 dxil.dll, but the victory-gpu lib tests never loaded it: a probe found no dxil.dll module in the process after creating the translated pipelines. Before any dispatch, each probe checked that the host device's adapter LUID matches EnumWarpAdapter: Microsoft Basic Render Driver, vendor 0x1414, device 0x8c, software flag set. No hardware GPU was used. No game files, dumps or shader data, only synthetic state and programs.

Command. cargo test --locked -j 4 -p victory-gpu --features diagnostics --lib -- --test-threads=1, plus filtered runs (probe_attest, probe_, list::).

Local probes (not pushed). Each one calls vtable slot 0x58 on a title list:

Probe Parent 63bcca4 Head 3cdfd5f8
Open direct list with pipeline, heaps, graphics and compute roots, vertex/index views, targets, depth, depth bounds, topology, host cache, table_failed and fixed topology/stencil set. After ClearState(null) all 16 are cleared, and fresh_tables, root_slots and root_run are kept fails: none cleared (the slot goes to the E_NOTIMPL stub) passes
ClearState after Close leaves state untouched. After Reset it clears again. On a bundle it leaves state untouched fails at the reopened case (no clear) passes
One compute list (type 2) created with A: dispatch A, ClearState(B), dispatch, ClearState(A), dispatch, each into its own page. Expected [A,B,A] fails: [A,A,A] passes: [0x0badc0de, 0x5eed1234, 0x0badc0de], one segment
The same on a direct list (type 0) fails: [A,A,A] passes

The synthetic Wave32 store program in the GPU probes uses the packet layout from this PR's test, with different values. The sequence checked is independent of the PR's tests.

Counts.

  • list:: on the head: 5 passed (including clear_state_has_the_same_slot_in_both_layouts).
  • Full victory-gpu lib suite on the head: 249 of the tree's 250 tests passed, 1 ignored (benchmark_private_data_release), including draw::tests::clear_state_switches_compute_pipeline_without_losing_recorded_work and draw::tests::clear_state_clears_graphics_bindings_before_a_segment_cut. The suite total also included the WARP attestation probe and 4 unrelated local mesh-clamp probes for #2996; 3 of those fail here as they do on the parent.
  • Parent: 246 passed, 1 ignored. All 4 ClearState probes failed as shown above.

AI-assisted: Claude Code (Claude Opus 5.5), coordinated by Codex (gpt-6.2-sol).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181342190 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2984#issuecomment-7181342190). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T03:02:29Z. --- Independent Windows WARP test run of `3cdfd5f875c44e2249fa46abee76ff57ab5d9187`, compared with its exact parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. This reports test results only, not a review verdict. **Setup.** Software only. `VICTORY_D3D12_WARP=1` and `VICTORY_WARP=1`, built with `--features diagnostics`. `VICTORY_DXIL` pointed at the Windows SDK 10.0.26100.0 x64 `dxil.dll`, but the victory-gpu lib tests never loaded it: a probe found no `dxil.dll` module in the process after creating the translated pipelines. Before any dispatch, each probe checked that the host device's adapter LUID matches `EnumWarpAdapter`: `Microsoft Basic Render Driver`, vendor `0x1414`, device `0x8c`, software flag set. No hardware GPU was used. No game files, dumps or shader data, only synthetic state and programs. **Command.** `cargo test --locked -j 4 -p victory-gpu --features diagnostics --lib -- --test-threads=1`, plus filtered runs (`probe_attest`, `probe_`, `list::`). **Local probes (not pushed).** Each one calls vtable slot `0x58` on a title list: | Probe | Parent `63bcca4` | Head `3cdfd5f8` | |---|---|---| | Open direct list with pipeline, heaps, graphics and compute roots, vertex/index views, targets, depth, depth bounds, topology, host cache, `table_failed` and fixed topology/stencil set. After `ClearState(null)` all 16 are cleared, and `fresh_tables`, `root_slots` and `root_run` are kept | fails: none cleared (the slot goes to the E_NOTIMPL stub) | passes | | `ClearState` after `Close` leaves state untouched. After `Reset` it clears again. On a bundle it leaves state untouched | fails at the reopened case (no clear) | passes | | One compute list (type 2) created with A: dispatch A, `ClearState(B)`, dispatch, `ClearState(A)`, dispatch, each into its own page. Expected `[A,B,A]` | fails: `[A,A,A]` | passes: `[0x0badc0de, 0x5eed1234, 0x0badc0de]`, one segment | | The same on a direct list (type 0) | fails: `[A,A,A]` | passes | The synthetic Wave32 store program in the GPU probes uses the packet layout from this PR's test, with different values. The sequence checked is independent of the PR's tests. **Counts.** - `list::` on the head: 5 passed (including `clear_state_has_the_same_slot_in_both_layouts`). - Full victory-gpu lib suite on the head: 249 of the tree's 250 tests passed, 1 ignored (`benchmark_private_data_release`), including `draw::tests::clear_state_switches_compute_pipeline_without_losing_recorded_work` and `draw::tests::clear_state_clears_graphics_bindings_before_a_segment_cut`. The suite total also included the WARP attestation probe and 4 unrelated local mesh-clamp probes for #2996; 3 of those fail here as they do on the parent. - Parent: 246 passed, 1 ignored. All 4 ClearState probes failed as shown above. AI-assisted: Claude Code (Claude Opus 5.5), coordinated by Codex (gpt-6.2-sol).
Marvisak commented 2026-11-26 06:03:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:26:23Z.


Automated triage for the maintainers.

Merge candidate (recommending a look, not approving). On main, slot 11 (0x58) of the list vtable in crates/victory-gpu/src/list.rs falls to the unimplemented stub. This PR adds clear_state, which follows the public D3D12 ClearState contract: it acts only on open direct and compute lists, sets the given pipeline, clears the host list, and resets the title-side bindings through the new State::clear_state in draw.rs. It keeps what already-recorded work still needs (dynamic slots, fresh tables, root views, the memory map). The new closed flag is set by close and cleared by reset, so segment cuts at waits do not count as closed. The compute test runs two pipelines across a ClearState in one list and reads back both results, and the graphics test checks each field. A separate WARP run posted here shows the probes fail on main and pass on this head. CI check passes.

One thing worth confirming: whether the title calls ClearState at all. That would decide how much this matters, not whether it is correct.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183486318 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2984#issuecomment-7183486318). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:26:23Z. --- <!-- victory-triage v1 head=3cdfd5f875c44e2249fa46abee76ff57ab5d9187 verdict=merge-candidate at=2026-11-26T05:28:00Z --> Automated triage for the maintainers. **Merge candidate** (recommending a look, not approving). On `main`, slot 11 (`0x58`) of the list vtable in `crates/victory-gpu/src/list.rs` falls to the unimplemented stub. This PR adds `clear_state`, which follows the public D3D12 `ClearState` contract: it acts only on open direct and compute lists, sets the given pipeline, clears the host list, and resets the title-side bindings through the new `State::clear_state` in `draw.rs`. It keeps what already-recorded work still needs (dynamic slots, fresh tables, root views, the memory map). The new `closed` flag is set by `close` and cleared by `reset`, so segment cuts at waits do not count as closed. The compute test runs two pipelines across a `ClearState` in one list and reads back both results, and the graphics test checks each field. A separate WARP run posted here shows the probes fail on `main` and pass on this head. CI `check` passes. One thing worth confirming: whether the title calls `ClearState` at all. That would decide how much this matters, not whether it is correct. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 07:00:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:57:34Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • cargo test -p victory-gpu draw::tests -- --test-threads=1 (RTX 5090 & WARP): all tests passed on both (including the new ClearState tests).
  • cargo test -p victory-gpu list::tests -- --test-threads=1 (RTX 5090): all tests passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6069753930 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2984#pullrequestreview-6069753930). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:57:34Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - `cargo test -p victory-gpu draw::tests -- --test-threads=1` (RTX 5090 & WARP): all tests passed on both (including the new `ClearState` tests). - `cargo test -p victory-gpu list::tests -- --test-threads=1` (RTX 5090): all tests passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/2984:upstream-pr/2984'
git switch 'upstream-pr/2984'

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