Skip to content

GPU: implement ClearState on command lists - #2984

Open
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/gpu-list-clear-state
Open

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/gpu-list-clear-state

Conversation

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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 kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

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 GPU: number bounded indirect mesh groups consecutively #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).

Copy link
Copy Markdown
Owner

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

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants