feat: VICTORY_INDIRECT_RAW=3 clamps in the prelude what it can and draws only the rest raw #308

Open
github-bot wants to merge 1 commit from github-bot/gh-308 into main AGit
Owner

@⁠Skyfrye on GitHub · 2026-11-26 02:05 UTC · original
Skyfrye:nep/indirect-raw-ahead → main · +80 −12 · 1 files · 1 commits · open

Change

A new value of an existing switch: VICTORY_INDIRECT_RAW=3. With 2 (the launcher's set) every single indirect record goes to the card as the title wrote it. With 3, a record that the list's prelude can clamp (a single record without a count buffer, which nothing the list recorded before may write: the existing clamp_ahead path) is clamped there, and only the others are drawn raw. Without the switch, and with 1 and 2, records go as before.

The way a record goes is now one small function, draw::route(raw, raw_ahead, rawable, aheadable) → Raw, Ahead or InPlace, used by State::execute_indirect. Where a record is drawn raw whatever the answer (2), the prelude check is not asked, so 2 costs nothing more than before.

Why: with 2, the card hung as the title entered the world in about half the runs of main here: host GPU device removed after 35 submissions sent ahead (VICTORY_RELAY=1) of 275 lists, the same numbers every time, DXGI_ERROR_DEVICE_HUNG, NVIDIA event 153. Device-removed data (DRED) showed a list stopped at command 102 of 283, inside a run of 75 ExecuteIndirect commands between two barriers. With no VICTORY_INDIRECT_RAW (every record clamped) no run hung, but the frame rate fell to about 10 fps: some 2,200 records a frame were clamped ahead in the lists' preludes (one pass for many records) and 4,300 in place (a dispatch of ours between two waits each), the second kind being the cost.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), RTX 5080, Ryzen 7 9800X3D, on upstream main at c4c93bd, from third_party/victory:

cargo build --locked --release -p victory              -> Finished, no new warning
cargo test --locked -p victory-gpu --lib -- route_tests -> 2 passed
cargo test --locked -p victory-gpu --lib               -> 3 failed, the rest passed

The 3 failures are the same on main without this change: descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others.

New tests: with_3_records_clamped_ahead_are_not_drawn_raw (fails without this change: route and its mode do not exist) and with_2_and_without_the_switch_records_go_as_before (the old routes).

In the world, my copy of the game, launcher fast set, runs of 240 s with the window left alone (the player moves), all on 2026-11-26:

Indirect records Runs Device lost Frame rate (median of the last minute)
VICTORY_INDIRECT_RAW=2 (launcher) 20 11 16-18 fps in the runs that went on
no switch (all clamped) 4 0 8.9-10.1 fps
VICTORY_INDIRECT_RAW=3, with PRs #278, #279, #291, #292, #307 4 0 13.9, 10.2 (one stall), 14.1 fps; the first run, which rebuilt the pipeline library after the translator changes of #277, at 0.2
the same, later (pipeline library and the driver's shader cache warm) 4 0 17.8, 17.4, 17.2, 17.8 fps

In the 3 runs, per frame: 585-1,714 records clamped ahead, 363-390 in place, 2,581-4,060 drawn raw. The first four 3 runs came right after the translator changes of #277: the pipeline library was rebuilt and the driver recompiled the new shaders in the background (#307), which is what held them at 10-14 fps. The next four, with both caches warm, ran at 17.2-17.8 fps, the frame rate of 2 in the runs that did not hang. In all, 3 hung in 0 of 8 runs, where 2 hung in 11 of 20; no run of either had an exception in the title.

What this does not do: say why the records are garbage at that moment. Whatever writes them, a record clamped ahead is bounded before the card reads it.

Not changed here: the launcher's set (2). If this holds up, a launcher PR can move it to 3.

Oracle and test data

No game file. The device-removed report and counts come from my own runs of my copy of the game; no game code, address or dump is in this PR.

Checklist

  • The PR covers a single reviewable behaviour (a mode that clamps ahead what it can and draws the rest raw).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Nothing unimplemented here.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: counts of the title's indirect records and where the card stopped; no title code.
  • Code taken from another project: none.

AI assistance: written with Claude Code. Claude Opus 5.5 ran the crash bisection and the device-removed captures, wrote the change and its tests, and wrote this description.

🤖 Generated with Claude Code

**@⁠Skyfrye** on GitHub · 2026-11-26 02:05 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/308) `Skyfrye:nep/indirect-raw-ahead` → `main` · +80 −12 · 1 files · 1 commits · open ## Change A new value of an existing switch: `VICTORY_INDIRECT_RAW=3`. With `2` (the launcher's set) every single indirect record goes to the card as the title wrote it. With `3`, a record that the list's prelude can clamp (a single record without a count buffer, which nothing the list recorded before may write: the existing `clamp_ahead` path) is clamped there, and only the others are drawn raw. Without the switch, and with `1` and `2`, records go as before. The way a record goes is now one small function, `draw::route(raw, raw_ahead, rawable, aheadable)` → `Raw`, `Ahead` or `InPlace`, used by `State::execute_indirect`. Where a record is drawn raw whatever the answer (`2`), the prelude check is not asked, so `2` costs nothing more than before. Why: with `2`, the card hung as the title entered the world in about half the runs of `main` here: `host GPU device removed after 35 submissions sent ahead (VICTORY_RELAY=1) of 275 lists`, the same numbers every time, `DXGI_ERROR_DEVICE_HUNG`, NVIDIA event 153. Device-removed data (DRED) showed a list stopped at command 102 of 283, inside a run of 75 `ExecuteIndirect` commands between two barriers. With no `VICTORY_INDIRECT_RAW` (every record clamped) no run hung, but the frame rate fell to about 10 fps: some 2,200 records a frame were clamped ahead in the lists' preludes (one pass for many records) and 4,300 in place (a dispatch of ours between two waits each), the second kind being the cost. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), RTX 5080, Ryzen 7 9800X3D, on upstream `main` at `c4c93bd`, from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished, no new warning cargo test --locked -p victory-gpu --lib -- route_tests -> 2 passed cargo test --locked -p victory-gpu --lib -> 3 failed, the rest passed ``` The 3 failures are the same on `main` without this change: `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. New tests: `with_3_records_clamped_ahead_are_not_drawn_raw` (fails without this change: `route` and its mode do not exist) and `with_2_and_without_the_switch_records_go_as_before` (the old routes). In the world, my copy of the game, launcher fast set, runs of 240 s with the window left alone (the player moves), all on 2026-11-26: | Indirect records | Runs | Device lost | Frame rate (median of the last minute) | |---|---|---|---| | `VICTORY_INDIRECT_RAW=2` (launcher) | 20 | 11 | 16-18 fps in the runs that went on | | no switch (all clamped) | 4 | 0 | 8.9-10.1 fps | | `VICTORY_INDIRECT_RAW=3`, with PRs #278, #279, #291, #292, #307 | 4 | 0 | 13.9, 10.2 (one stall), 14.1 fps; the first run, which rebuilt the pipeline library after the translator changes of #277, at 0.2 | | the same, later (pipeline library and the driver's shader cache warm) | 4 | 0 | 17.8, 17.4, 17.2, 17.8 fps | In the `3` runs, per frame: 585-1,714 records clamped ahead, 363-390 in place, 2,581-4,060 drawn raw. The first four `3` runs came right after the translator changes of #277: the pipeline library was rebuilt and the driver recompiled the new shaders in the background (#307), which is what held them at 10-14 fps. The next four, with both caches warm, ran at 17.2-17.8 fps, the frame rate of `2` in the runs that did not hang. In all, `3` hung in 0 of 8 runs, where `2` hung in 11 of 20; no run of either had an exception in the title. What this does not do: say why the records are garbage at that moment. Whatever writes them, a record clamped ahead is bounded before the card reads it. Not changed here: the launcher's set (`2`). If this holds up, a launcher PR can move it to `3`. ## Oracle and test data No game file. The device-removed report and counts come from my own runs of my copy of the game; no game code, address or dump is in this PR. ## Checklist - [x] The PR covers a single reviewable behaviour (a mode that clamps ahead what it can and draws the rest raw). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Nothing unimplemented here.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: counts of the title's indirect records and where the card stopped; no title code. - [x] Code taken from another project: none. AI assistance: written with Claude Code. Claude Opus 5.5 ran the crash bisection and the device-removed captures, wrote the change and its tests, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With VICTORY_INDIRECT_RAW=2 (the launcher's set) every single indirect
record goes to the card as the title wrote it, and in about half the runs
of the world on main the card hung as the title entered it (device
removed, always with 35 submissions of 275 lists in the air), stopped in a
run of indirect commands. With every record clamped no run of four hung,
at about 10 fps against 16-18: 2,200 records a frame were clamped ahead in
their lists' preludes (one pass for many) and 4,300 in place (a dispatch
of ours between two waits each).

With 3 a record the prelude can clamp is clamped there, and only the
others are drawn raw. The way a record goes is one small function
(`route`); 2 and no switch go as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:36 +00:00
Author
Owner

@⁠mauroalvare on GitHub · 2026-11-26 02:35 UTC · original

Independent NVIDIA and WARP validation

I ran the same synthetic test-only patch at base c4c93bdc413191a9dc909998d2d53080a3f0c880 and exact PR head 1afeb0e24533e4838693114a899803f20fabd3d5. Windows x64 build 26300, Rust 1.98.1 MSVC, RTX 5070 Ti driver 621.40. The probe verified DXGI vendor 0x10de on the RTX and 0x1414 plus the software flag on WARP.

The probe registers a CPU-populated indirect argument buffer and calls VIctory's draw::State::execute_indirect twice. The first call is a single non-indexed draw. The second uses a count buffer of 1 with room for 2 valid records. Host::execute submits the runtime prelude and command list. The probe checks CLAMPS per call, then resolves D3D12 pipeline statistics after the fence.

Mode Base routes, single / counted PR head routes, single / counted
3 Prelude clamp / in-place clamp. Fails the new routing assertion. Prelude clamp / raw. Pass.
2 (launcher default) Raw / raw. Pass. Raw / raw. Pass.
Unset Prelude clamp / in-place clamp. Pass. Prelude clamp / in-place clamp. Pass.

Both adapters produced identical results. Across all 12 runs, the two queries returned 3 and 6 IA vertices and 1 and 2 primitives. The count buffer therefore limited the second call to its first record. No cases skipped. The PR's two route_tests also passed. GitHub Actions tests passed at this head (run #685). The evidence here covers synthetic routing and draw output.

Reproduce with the synthetic test patch

Save the diff below as pr308-probe.patch and apply it from the repository root with git apply pr308-probe.patch. Run from third_party/victory.

$env:VICTORY_INDIRECT_RAW = '3'
cargo test --locked --offline -j 2 -p victory-gpu --lib --features diagnostics draw::qa_indirect::mixed_indirect_draws_reach_the_adapter -- --exact --nocapture --test-threads=1

For WARP set $env:VICTORY_D3D12_WARP = '1'. For the controls, set VICTORY_INDIRECT_RAW to 2 or clear it, with a fresh process per run.

diff --git a/third_party/victory/crates/victory-gpu/src/draw.rs b/third_party/victory/crates/victory-gpu/src/draw.rs
index 52aff49..af847d4 100644
--- a/third_party/victory/crates/victory-gpu/src/draw.rs
+++ b/third_party/victory/crates/victory-gpu/src/draw.rs
@@ -10,6 +10,9 @@
 
 mod root_slots;
 
+#[cfg(all(test, feature = "diagnostics"))]
+mod qa_indirect;
+
 use std::sync::atomic::{AtomicU64, Ordering};
 
 use victory_shader::resource::RootIndexedView;
diff --git a/third_party/victory/crates/victory-gpu/src/draw/qa_indirect.rs b/third_party/victory/crates/victory-gpu/src/draw/qa_indirect.rs
new file mode 100644
index 0000000..1b4f2ba
--- /dev/null
+++ b/third_party/victory/crates/victory-gpu/src/draw/qa_indirect.rs
@@ -0,0 +1,212 @@
+use std::{mem::size_of, ptr::null_mut, sync::atomic::Ordering::Relaxed};
+
+use windows::Win32::Foundation::RECT;
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::Win32::Graphics::Dxgi::*;
+use windows::core::s;
+use windows_sys::Win32::System::Memory::{
+    MEM_COMMIT, MEM_RELEASE, MEM_RESERVE, PAGE_READWRITE, VirtualAlloc, VirtualFree,
+};
+
+use super::{CLAMPS, State};
+use crate::host::{compile, host};
+use crate::pipeline::host::HostPipeline;
+
+struct Registered(u64);
+
+impl Drop for Registered {
+    fn drop(&mut self) {
+        crate::shadow::unregister(1, self.0);
+        // SAFETY: the registered allocation was reserved by this test.
+        assert_ne!(unsafe { VirtualFree(self.0 as *mut _, 0, MEM_RELEASE) }, 0);
+    }
+}
+
+fn pipeline(device: &ID3D12Device) -> HostPipeline {
+    let vs = compile(
+        r#"
+[RootSignature("")]
+float4 vertex(uint i : SV_VertexID) : SV_Position {
+    return float4(float(i & 1) * 2.0 - 1.0, float((i >> 1) & 1) * 2.0 - 1.0, 0.5, 1.0);
+}
+"#,
+        s!("vertex"),
+        s!("vs_5_1"),
+    )
+    .unwrap();
+    // SAFETY: compiled bytecode remains live throughout native pipeline creation.
+    let (root, pso) = unsafe {
+        let root: ID3D12RootSignature = device.CreateRootSignature(0, &vs).unwrap();
+        let d = D3D12_GRAPHICS_PIPELINE_STATE_DESC {
+            pRootSignature: std::mem::transmute_copy(&root),
+            VS: D3D12_SHADER_BYTECODE {
+                pShaderBytecode: vs.as_ptr().cast(),
+                BytecodeLength: vs.len(),
+            },
+            SampleMask: u32::MAX,
+            RasterizerState: D3D12_RASTERIZER_DESC {
+                FillMode: D3D12_FILL_MODE_SOLID,
+                CullMode: D3D12_CULL_MODE_NONE,
+                DepthClipEnable: true.into(),
+                ..Default::default()
+            },
+            PrimitiveTopologyType: D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE,
+            SampleDesc: windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC {
+                Count: 1,
+                Quality: 0,
+            },
+            ..Default::default()
+        };
+        (root, device.CreateGraphicsPipelineState(&d).unwrap())
+    };
+    HostPipeline {
+        compute: false,
+        mesh: false,
+        pso,
+        root,
+        stages: vec![],
+        slots: 0,
+        inputs: vec![],
+        rects: false,
+        name: "synthetic indirect QA".into(),
+        state: String::new(),
+    }
+}
+
+#[test]
+fn mixed_indirect_draws_reach_the_adapter() {
+    eprintln!("creating D3D12 device");
+    let host = host().expect("a D3D12 adapter");
+    // SAFETY: querying the identity of the runtime's live device.
+    let adapter = unsafe {
+        let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
+        let adapter: IDXGIAdapter1 = factory
+            .EnumAdapterByLuid(host.device.GetAdapterLuid())
+            .unwrap();
+        adapter.GetDesc1().unwrap()
+    };
+    let name = String::from_utf16_lossy(&adapter.Description);
+    let name = name.trim_end_matches('\0');
+    let software = adapter.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0;
+    let warp = std::env::var_os("VICTORY_D3D12_WARP").is_some();
+    eprintln!(
+        "adapter={name}, vendor={:#06x}, software={software}",
+        adapter.VendorId
+    );
+    assert_eq!(software, warp);
+    if warp {
+        assert_eq!(adapter.VendorId, 0x1414);
+    } else {
+        assert_eq!(adapter.VendorId, 0x10de);
+        assert!(name.contains("RTX 5070 Ti"));
+    }
+
+    // An eligible single draw, then two valid records restricted to one by a count buffer.
+    let args = [3u32, 1, 0, 0, 6, 1, 0, 0, 9, 1, 0, 0, 1, 0, 0, 0];
+    // SAFETY: this fresh 64 KiB allocation can hold the synthetic argument words.
+    let data = unsafe { VirtualAlloc(null_mut(), 65536, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) }
+        .cast::<u32>();
+    assert!(!data.is_null());
+    unsafe { data.copy_from_nonoverlapping(args.as_ptr(), args.len()) };
+    let registered = Registered(data as u64);
+    crate::shadow::register(1, registered.0, 65536);
+    let list = host.new_list().unwrap();
+    let bytes = size_of::<D3D12_QUERY_DATA_PIPELINE_STATISTICS>();
+    let back = host.read_back_buffer((bytes * 2) as u64).unwrap();
+    // SAFETY: creating a query heap owned through submission and completion.
+    let mut queries: Option<ID3D12QueryHeap> = None;
+    unsafe {
+        host.device
+            .CreateQueryHeap(
+                &D3D12_QUERY_HEAP_DESC {
+                    Type: D3D12_QUERY_HEAP_TYPE_PIPELINE_STATISTICS,
+                    Count: 2,
+                    NodeMask: 0,
+                },
+                &mut queries,
+            )
+            .unwrap();
+    }
+    let queries = queries.unwrap();
+    let kind = D3D12_QUERY_TYPE_PIPELINE_STATISTICS;
+    let clamps = || CLAMPS.each_ref().map(|n| n.load(Relaxed));
+    let before = clamps();
+    eprintln!("creating synthetic graphics pipeline");
+    crate::pipeline::with_qa_indirect_pipeline(pipeline(&host.device), |p| {
+        let mut state = State::default();
+        state.set_pipeline(p);
+        state.set_topology(&list, 4);
+        // SAFETY: recording on the open list with valid extents and query indices.
+        unsafe {
+            list.list.RSSetViewports(&[D3D12_VIEWPORT {
+                Width: 1.0,
+                Height: 1.0,
+                MaxDepth: 1.0,
+                ..Default::default()
+            }]);
+            list.list.RSSetScissorRects(&[RECT {
+                left: 0,
+                top: 0,
+                right: 1,
+                bottom: 1,
+            }]);
+            list.list.BeginQuery(&queries, kind, 0);
+        }
+        assert!(state.execute_indirect(&list, (0, 16, 1), registered.0, None));
+        let first = clamps();
+        // SAFETY: ending the first query and recording the second on the same list.
+        unsafe {
+            list.list.EndQuery(&queries, kind, 0);
+            list.list.BeginQuery(&queries, kind, 1);
+        }
+        assert!(state.execute_indirect(
+            &list,
+            (0, 16, 2),
+            registered.0 + 16,
+            Some(registered.0 + 48)
+        ));
+        let second = clamps();
+        // SAFETY: both queries ended before resolving into a live readback buffer.
+        unsafe {
+            list.list.EndQuery(&queries, kind, 1);
+            list.list.ResolveQueryData(&queries, kind, 0, 2, &back, 0);
+        }
+        list.close();
+        eprintln!("submitting synthetic indirect draws");
+        host.execute(&[&list]);
+        let mut mapped = null_mut();
+        // SAFETY: execute has waited for the resolve, and the buffer holds both statistics.
+        let stats = unsafe {
+            host.device.GetDeviceRemovedReason().unwrap();
+            back.Map(
+                0,
+                Some(&D3D12_RANGE {
+                    Begin: 0,
+                    End: bytes * 2,
+                }),
+                Some(&mut mapped),
+            )
+            .unwrap();
+            let data = mapped.cast::<D3D12_QUERY_DATA_PIPELINE_STATISTICS>();
+            let stats = [data.read_unaligned(), data.add(1).read_unaligned()];
+            back.Unmap(0, Some(&D3D12_RANGE::default()));
+            stats
+        };
+        let vertices = stats.map(|s| s.IAVertices);
+        let primitives = stats.map(|s| s.IAPrimitives);
+        let diff = |a: [u64; 3], b: [u64; 3]| std::array::from_fn::<_, 3, _>(|i| b[i] - a[i]);
+        let routes = [diff(before, first), diff(first, second)];
+        eprintln!(
+            "mode={:?} [ahead,in-place,raw]={routes:?}; IA vertices={vertices:?}, primitives={primitives:?}",
+            std::env::var("VICTORY_INDIRECT_RAW").ok()
+        );
+        assert_eq!(vertices, [3, 6]);
+        assert_eq!(primitives, [1, 2]);
+        let expected = match std::env::var("VICTORY_INDIRECT_RAW").as_deref() {
+            Ok("3") => [[1, 0, 0], [0, 0, 1]],
+            Ok("2") => [[0, 0, 1], [0, 0, 1]],
+            _ => [[1, 0, 0], [0, 1, 0]],
+        };
+        assert_eq!(routes, expected);
+    });
+}
diff --git a/third_party/victory/crates/victory-gpu/src/pipeline.rs b/third_party/victory/crates/victory-gpu/src/pipeline.rs
index b05c590..436e777 100644
--- a/third_party/victory/crates/victory-gpu/src/pipeline.rs
+++ b/third_party/victory/crates/victory-gpu/src/pipeline.rs
@@ -932,3 +932,16 @@ mod tests {
         }
     }
 }
+
+#[cfg(all(windows, test, feature = "diagnostics"))]
+pub(crate) fn with_qa_indirect_pipeline(pso: host::HostPipeline, run: impl FnOnce(This)) {
+    let pipeline = Pipeline {
+        object: Object::new(&FUNCTIONS),
+        packet: [0; 8],
+        shaders: vec![],
+        bound: std::sync::atomic::AtomicBool::new(false),
+        host: Arc::new(make::Pending::qa_ready(pso)),
+        builder: false,
+    };
+    run((&raw const pipeline).cast());
+}
diff --git a/third_party/victory/crates/victory-gpu/src/pipeline/make.rs b/third_party/victory/crates/victory-gpu/src/pipeline/make.rs
index 70c880e..6f60549 100644
--- a/third_party/victory/crates/victory-gpu/src/pipeline/make.rs
+++ b/third_party/victory/crates/victory-gpu/src/pipeline/make.rs
@@ -750,3 +750,12 @@ mod tests {
         assert!(queue.pop().is_none());
     }
 }
+
+#[cfg(all(test, feature = "diagnostics"))]
+impl Pending {
+    pub(crate) fn qa_ready(pso: HostPipeline) -> Self {
+        let pending = Self::new(vec![], None);
+        assert!(pending.made.set(Some(pso)).is_ok());
+        pending
+    }
+}

QA and the synthetic reproduction were prepared with OpenAI Codex assistance.

**@⁠mauroalvare** on GitHub · 2026-11-26 02:35 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/308#issuecomment-7180942171) ## Independent NVIDIA and WARP validation I ran the same synthetic test-only patch at base `c4c93bdc413191a9dc909998d2d53080a3f0c880` and exact PR head `1afeb0e24533e4838693114a899803f20fabd3d5`. Windows x64 build 26300, Rust 1.98.1 MSVC, RTX 5070 Ti driver 621.40. The probe verified DXGI vendor `0x10de` on the RTX and `0x1414` plus the software flag on WARP. The probe registers a CPU-populated indirect argument buffer and calls VIctory's `draw::State::execute_indirect` twice. The first call is a single non-indexed draw. The second uses a count buffer of 1 with room for 2 valid records. `Host::execute` submits the runtime prelude and command list. The probe checks `CLAMPS` per call, then resolves D3D12 pipeline statistics after the fence. | Mode | Base routes, single / counted | PR head routes, single / counted | | --- | --- | --- | | `3` | Prelude clamp / in-place clamp. Fails the new routing assertion. | Prelude clamp / raw. Pass. | | `2` (launcher default) | Raw / raw. Pass. | Raw / raw. Pass. | | Unset | Prelude clamp / in-place clamp. Pass. | Prelude clamp / in-place clamp. Pass. | Both adapters produced identical results. Across all 12 runs, the two queries returned 3 and 6 IA vertices and 1 and 2 primitives. The count buffer therefore limited the second call to its first record. No cases skipped. The PR's two `route_tests` also passed. GitHub Actions `tests` passed at this head ([run #685](https://github.com/LooperSalty/AnyXboxX/actions/runs/45740142299)). The evidence here covers synthetic routing and draw output. <details> <summary>Reproduce with the synthetic test patch</summary> Save the diff below as `pr308-probe.patch` and apply it from the repository root with `git apply pr308-probe.patch`. Run from `third_party/victory`. ```powershell $env:VICTORY_INDIRECT_RAW = '3' cargo test --locked --offline -j 2 -p victory-gpu --lib --features diagnostics draw::qa_indirect::mixed_indirect_draws_reach_the_adapter -- --exact --nocapture --test-threads=1 ``` For WARP set `$env:VICTORY_D3D12_WARP = '1'`. For the controls, set `VICTORY_INDIRECT_RAW` to `2` or clear it, with a fresh process per run. ```diff diff --git a/third_party/victory/crates/victory-gpu/src/draw.rs b/third_party/victory/crates/victory-gpu/src/draw.rs index 52aff49..af847d4 100644 --- a/third_party/victory/crates/victory-gpu/src/draw.rs +++ b/third_party/victory/crates/victory-gpu/src/draw.rs @@ -10,6 +10,9 @@ mod root_slots; +#[cfg(all(test, feature = "diagnostics"))] +mod qa_indirect; + use std::sync::atomic::{AtomicU64, Ordering}; use victory_shader::resource::RootIndexedView; diff --git a/third_party/victory/crates/victory-gpu/src/draw/qa_indirect.rs b/third_party/victory/crates/victory-gpu/src/draw/qa_indirect.rs new file mode 100644 index 0000000..1b4f2ba --- /dev/null +++ b/third_party/victory/crates/victory-gpu/src/draw/qa_indirect.rs @@ -0,0 +1,212 @@ +use std::{mem::size_of, ptr::null_mut, sync::atomic::Ordering::Relaxed}; + +use windows::Win32::Foundation::RECT; +use windows::Win32::Graphics::Direct3D12::*; +use windows::Win32::Graphics::Dxgi::*; +use windows::core::s; +use windows_sys::Win32::System::Memory::{ + MEM_COMMIT, MEM_RELEASE, MEM_RESERVE, PAGE_READWRITE, VirtualAlloc, VirtualFree, +}; + +use super::{CLAMPS, State}; +use crate::host::{compile, host}; +use crate::pipeline::host::HostPipeline; + +struct Registered(u64); + +impl Drop for Registered { + fn drop(&mut self) { + crate::shadow::unregister(1, self.0); + // SAFETY: the registered allocation was reserved by this test. + assert_ne!(unsafe { VirtualFree(self.0 as *mut _, 0, MEM_RELEASE) }, 0); + } +} + +fn pipeline(device: &ID3D12Device) -> HostPipeline { + let vs = compile( + r#" +[RootSignature("")] +float4 vertex(uint i : SV_VertexID) : SV_Position { + return float4(float(i & 1) * 2.0 - 1.0, float((i >> 1) & 1) * 2.0 - 1.0, 0.5, 1.0); +} +"#, + s!("vertex"), + s!("vs_5_1"), + ) + .unwrap(); + // SAFETY: compiled bytecode remains live throughout native pipeline creation. + let (root, pso) = unsafe { + let root: ID3D12RootSignature = device.CreateRootSignature(0, &vs).unwrap(); + let d = D3D12_GRAPHICS_PIPELINE_STATE_DESC { + pRootSignature: std::mem::transmute_copy(&root), + VS: D3D12_SHADER_BYTECODE { + pShaderBytecode: vs.as_ptr().cast(), + BytecodeLength: vs.len(), + }, + SampleMask: u32::MAX, + RasterizerState: D3D12_RASTERIZER_DESC { + FillMode: D3D12_FILL_MODE_SOLID, + CullMode: D3D12_CULL_MODE_NONE, + DepthClipEnable: true.into(), + ..Default::default() + }, + PrimitiveTopologyType: D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, + SampleDesc: windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC { + Count: 1, + Quality: 0, + }, + ..Default::default() + }; + (root, device.CreateGraphicsPipelineState(&d).unwrap()) + }; + HostPipeline { + compute: false, + mesh: false, + pso, + root, + stages: vec![], + slots: 0, + inputs: vec![], + rects: false, + name: "synthetic indirect QA".into(), + state: String::new(), + } +} + +#[test] +fn mixed_indirect_draws_reach_the_adapter() { + eprintln!("creating D3D12 device"); + let host = host().expect("a D3D12 adapter"); + // SAFETY: querying the identity of the runtime's live device. + let adapter = unsafe { + let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap(); + let adapter: IDXGIAdapter1 = factory + .EnumAdapterByLuid(host.device.GetAdapterLuid()) + .unwrap(); + adapter.GetDesc1().unwrap() + }; + let name = String::from_utf16_lossy(&adapter.Description); + let name = name.trim_end_matches('\0'); + let software = adapter.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0; + let warp = std::env::var_os("VICTORY_D3D12_WARP").is_some(); + eprintln!( + "adapter={name}, vendor={:#06x}, software={software}", + adapter.VendorId + ); + assert_eq!(software, warp); + if warp { + assert_eq!(adapter.VendorId, 0x1414); + } else { + assert_eq!(adapter.VendorId, 0x10de); + assert!(name.contains("RTX 5070 Ti")); + } + + // An eligible single draw, then two valid records restricted to one by a count buffer. + let args = [3u32, 1, 0, 0, 6, 1, 0, 0, 9, 1, 0, 0, 1, 0, 0, 0]; + // SAFETY: this fresh 64 KiB allocation can hold the synthetic argument words. + let data = unsafe { VirtualAlloc(null_mut(), 65536, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) } + .cast::<u32>(); + assert!(!data.is_null()); + unsafe { data.copy_from_nonoverlapping(args.as_ptr(), args.len()) }; + let registered = Registered(data as u64); + crate::shadow::register(1, registered.0, 65536); + let list = host.new_list().unwrap(); + let bytes = size_of::<D3D12_QUERY_DATA_PIPELINE_STATISTICS>(); + let back = host.read_back_buffer((bytes * 2) as u64).unwrap(); + // SAFETY: creating a query heap owned through submission and completion. + let mut queries: Option<ID3D12QueryHeap> = None; + unsafe { + host.device + .CreateQueryHeap( + &D3D12_QUERY_HEAP_DESC { + Type: D3D12_QUERY_HEAP_TYPE_PIPELINE_STATISTICS, + Count: 2, + NodeMask: 0, + }, + &mut queries, + ) + .unwrap(); + } + let queries = queries.unwrap(); + let kind = D3D12_QUERY_TYPE_PIPELINE_STATISTICS; + let clamps = || CLAMPS.each_ref().map(|n| n.load(Relaxed)); + let before = clamps(); + eprintln!("creating synthetic graphics pipeline"); + crate::pipeline::with_qa_indirect_pipeline(pipeline(&host.device), |p| { + let mut state = State::default(); + state.set_pipeline(p); + state.set_topology(&list, 4); + // SAFETY: recording on the open list with valid extents and query indices. + unsafe { + list.list.RSSetViewports(&[D3D12_VIEWPORT { + Width: 1.0, + Height: 1.0, + MaxDepth: 1.0, + ..Default::default() + }]); + list.list.RSSetScissorRects(&[RECT { + left: 0, + top: 0, + right: 1, + bottom: 1, + }]); + list.list.BeginQuery(&queries, kind, 0); + } + assert!(state.execute_indirect(&list, (0, 16, 1), registered.0, None)); + let first = clamps(); + // SAFETY: ending the first query and recording the second on the same list. + unsafe { + list.list.EndQuery(&queries, kind, 0); + list.list.BeginQuery(&queries, kind, 1); + } + assert!(state.execute_indirect( + &list, + (0, 16, 2), + registered.0 + 16, + Some(registered.0 + 48) + )); + let second = clamps(); + // SAFETY: both queries ended before resolving into a live readback buffer. + unsafe { + list.list.EndQuery(&queries, kind, 1); + list.list.ResolveQueryData(&queries, kind, 0, 2, &back, 0); + } + list.close(); + eprintln!("submitting synthetic indirect draws"); + host.execute(&[&list]); + let mut mapped = null_mut(); + // SAFETY: execute has waited for the resolve, and the buffer holds both statistics. + let stats = unsafe { + host.device.GetDeviceRemovedReason().unwrap(); + back.Map( + 0, + Some(&D3D12_RANGE { + Begin: 0, + End: bytes * 2, + }), + Some(&mut mapped), + ) + .unwrap(); + let data = mapped.cast::<D3D12_QUERY_DATA_PIPELINE_STATISTICS>(); + let stats = [data.read_unaligned(), data.add(1).read_unaligned()]; + back.Unmap(0, Some(&D3D12_RANGE::default())); + stats + }; + let vertices = stats.map(|s| s.IAVertices); + let primitives = stats.map(|s| s.IAPrimitives); + let diff = |a: [u64; 3], b: [u64; 3]| std::array::from_fn::<_, 3, _>(|i| b[i] - a[i]); + let routes = [diff(before, first), diff(first, second)]; + eprintln!( + "mode={:?} [ahead,in-place,raw]={routes:?}; IA vertices={vertices:?}, primitives={primitives:?}", + std::env::var("VICTORY_INDIRECT_RAW").ok() + ); + assert_eq!(vertices, [3, 6]); + assert_eq!(primitives, [1, 2]); + let expected = match std::env::var("VICTORY_INDIRECT_RAW").as_deref() { + Ok("3") => [[1, 0, 0], [0, 0, 1]], + Ok("2") => [[0, 0, 1], [0, 0, 1]], + _ => [[1, 0, 0], [0, 1, 0]], + }; + assert_eq!(routes, expected); + }); +} diff --git a/third_party/victory/crates/victory-gpu/src/pipeline.rs b/third_party/victory/crates/victory-gpu/src/pipeline.rs index b05c590..436e777 100644 --- a/third_party/victory/crates/victory-gpu/src/pipeline.rs +++ b/third_party/victory/crates/victory-gpu/src/pipeline.rs @@ -932,3 +932,16 @@ mod tests { } } } + +#[cfg(all(windows, test, feature = "diagnostics"))] +pub(crate) fn with_qa_indirect_pipeline(pso: host::HostPipeline, run: impl FnOnce(This)) { + let pipeline = Pipeline { + object: Object::new(&FUNCTIONS), + packet: [0; 8], + shaders: vec![], + bound: std::sync::atomic::AtomicBool::new(false), + host: Arc::new(make::Pending::qa_ready(pso)), + builder: false, + }; + run((&raw const pipeline).cast()); +} diff --git a/third_party/victory/crates/victory-gpu/src/pipeline/make.rs b/third_party/victory/crates/victory-gpu/src/pipeline/make.rs index 70c880e..6f60549 100644 --- a/third_party/victory/crates/victory-gpu/src/pipeline/make.rs +++ b/third_party/victory/crates/victory-gpu/src/pipeline/make.rs @@ -750,3 +750,12 @@ mod tests { assert!(queue.pop().is_none()); } } + +#[cfg(all(test, feature = "diagnostics"))] +impl Pending { + pub(crate) fn qa_ready(pso: HostPipeline) -> Self { + let pending = Self::new(vec![], None); + assert!(pending.made.set(Some(pso)).is_ok()); + pending + } +} ``` </details> QA and the synthetic reproduction were prepared with OpenAI Codex assistance.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/308/head:github-bot/gh-308'
git switch 'github-bot/gh-308'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-308'
git switch 'github-bot/gh-308'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-308'
git switch 'github-bot/gh-308'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-308'
git switch 'main'
git merge --squash 'github-bot/gh-308'
git switch 'main'
git merge --ff-only 'github-bot/gh-308'
git switch 'main'
git merge 'github-bot/gh-308'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.