Skip to content

GPU: choose an adapter that can run the title, and name the ones that cannot - #967

Open
zzm1234560621-prog wants to merge 1 commit into
Marvisak:mainfrom
zzm1234560621-prog:gpu/adapter-selection
Open

zzm1234560621-prog wants to merge 1 commit into
Marvisak:mainfrom
zzm1234560621-prog:gpu/adapter-selection

Conversation

@zzm1234560621-prog

Copy link
Copy Markdown

GPU: choose an adapter that can run the title, and name the ones that cannot

What

victory_gpu::host::create now picks the host adapter instead of taking
D3D12CreateDevice(None, …). New module crates/victory-gpu/src/adapter.rs:

  • enumerate() walks IDXGIFactory4::EnumAdapters1 and probes each adapter:
    its description, whether a D3D12 device can be created on it,
    SHADER_MODEL, D3D12_OPTIONS7::MeshShaderTier, and the software flag.
  • choose() is a pure function over those facts and is where the policy lives.
  • report() renders one line per adapter, for the error below.
  • open() creates the device on the chosen adapter.

create() keeps its WARP branch unchanged (VICTORY_D3D12_WARP, diagnostics
builds) and returns anyhow::Result instead of windows::core::Result, so a
failure can carry the adapter list rather than a bare E_FAIL.

Why

D3D12CreateDevice(None, …) means "whatever DXGI calls the default adapter",
which is the adapter driving the primary output. That is the wrong adapter in
two common configurations:

  • Hybrid laptops (Intel iGPU + discrete GPU): the default is the
    integrated GPU. It may create a device and still not be what runs the
    world; the old code would either use it or fail the SM 6.6 check with
    the device supports SM 0x65 only and no hint that a capable GPU is in
    the machine.
  • Machines with a remote-desktop or emulator display driver: those add
    adapters that enumerate like any other and cannot create a D3D12 device.
    When one of them ends up as the default, the failure was an E_FAIL with
    no name attached.

The title needs shader model 6.6 (README) and, for the world, mesh shaders,
so "the default adapter" is not a safe default.

How the choice is made

  1. Hardware only. A software adapter is never chosen — Microsoft Basic Render Driver reports SM 6.6 and mesh shaders too (measured below), and
    silently running the title on the CPU is worse than a failure that names
    the reason. WARP stays the explicit VICTORY_D3D12_WARP switch.
  2. A device must exist and report SM 6.6.
  3. Mesh shaders first — the world's draws are mesh dispatches.
  4. Then the most DedicatedVideoMemory.
  5. Then the lowest LUID, so the same machine makes the same choice whatever
    order the driver enumerates in.

When nothing qualifies, the error lists every adapter with its LUID, vendor,
dedicated memory, shader model, mesh support and whether it is software.

Measured

enumerate() + choose() on the machine this was written on (Windows 11,
Core Ultra 9 185H, one Intel Arc iGPU, plus a remote-desktop display driver
and an emulator display driver installed):

adapters on this machine:
  Intel(R) Arc(TM) Graphics        [LUID 00000000:0001060b, vendor 8086, 128 MiB, SM 0x66, mesh]
  Intel(R) Arc(TM) Graphics        [LUID 00000000:00018b29, vendor 8086, 128 MiB, SM 0x66, mesh]
  Intel(R) Arc(TM) Graphics        [LUID 00000000:000163a9, vendor 8086, 128 MiB, SM 0x66, mesh]
  Microsoft Basic Render Driver    [LUID 00000000:00010a2a, vendor 1414,   0 MiB, SM 0x66, mesh, software]
chosen: Some("Intel(R) Arc(TM) Graphics")

Two things this shows that the old code could not:

  • The same physical GPU appears three times, once per display path. Which of
    the three is "the default" is not stable across runs; the LUID tie-break is.
  • The Basic Render Driver passes a naive SM 6.6 + mesh test. That is the
    reason for rule 1.

Not verified

  • No game files, no console hardware: nothing here was run against the title.
  • No frame-time or image comparison; this changes which adapter is used, not
    what is drawn.
  • One machine, one adapter family. The mesh-first rule is a reading of the
    README ("mesh shaders for the world"), not something measured on a GPU
    without mesh support.
  • The 32-lane/64-lane behaviour of whatever adapter gets chosen is not
    touched by this PR; it is the same host the old code would have used
    whenever the default adapter was the right one.

Tested

cargo test -p victory-gpu --locked: 50 passed, 1 ignored, 0 failed
(8 of them new; they drive choose and report over synthetic facts and
need neither a GPU nor a display).

CI's commands, on Windows 11 with MSVC 14.51 and Rust 1.98.1 (the pinned
toolchain):

  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo xtask policy: ok
  • cargo test --workspace --locked: see the run below

One caveat for anyone re-running the suite: victory-core's two
policy::tests and victory-gpu's shader_cache / watch tests create
directories under %TEMP%. They pass on a normal machine; a run whose
%TEMP% is not writable fails them with PermissionDenied, which is not a
code failure.

Relation to open PRs

… cannot

D3D12CreateDevice(None, …) takes the adapter DXGI calls the default, which
is the one driving the primary output: the integrated GPU on a hybrid
laptop, and on a machine with a remote-desktop or emulator display driver
an adapter that cannot create a device at all. The title needs shader model
6.6 and, for the world, mesh shaders, so neither is a safe default, and
when none of them worked the failure was a bare E_FAIL that named nothing.

Enumerate and probe every adapter — a device, SHADER_MODEL,
D3D12_OPTIONS7's mesh tier, the software flag — then choose: hardware,
SM 6.6, mesh shaders first, then the most dedicated memory, then the
lowest LUID so the choice does not depend on enumeration order. Software
adapters are never chosen (Microsoft Basic Render Driver reports SM 6.6
and mesh shaders too), and WARP stays the explicit VICTORY_D3D12_WARP
switch. When nothing qualifies, the error lists every adapter with what
it offers.

Measured on the machine this was written on (Core Ultra 9 185H, Intel Arc
iGPU, plus a remote-desktop and an emulator display driver): four
adapters, the same GPU listed three times — once per display path, so
which is the default is not stable — and the Basic Render Driver passing a
naive SM 6.6 + mesh test.

cargo test -p victory-gpu: 57 passed, 0 failed, 1 ignored.
cargo clippy --workspace --all-targets --all-features -- -D warnings: clean.
cargo xtask policy: ok.

@mercuryVM mercuryVM 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 66d97ee on Windows 11, RTX 5070, MSVC: cargo test -p victory-gpu -- --test-threads=1 57 passed, and with --features diagnostics 60 passed, including the seven choose tests. cargo clippy -p victory-gpu --all-targets is clean. This machine has the RTX 5070, an AMD integrated GPU and two virtual display adapters, so it's a realistic multi-adapter host. The selection itself isn't exercised by a test against the real adapters, and the title wasn't run.

  • choose as a pure function over probed facts (device creatable, SM 6.6, mesh tier, software flag, VRAM, LUID) is easy to reason about. Excluding software adapters keeps WARP an explicit switch, and the LUID tiebreak makes the result stable for a given machine.
  • Two suggestions:
    • There's no user override. With "mesh, then most VRAM" a user can't force a specific GPU, for example to compare iGPU against dGPU behaviour, short of disabling the other in Device Manager. A VICTORY_ADAPTER=<LUID or index> escape hatch, listed in report()'s output, would cover that.
    • Probing creates a D3D12 device on every adapter at startup, including virtual display adapters (Parsec and Meta here) that have no device. That's harmless, but it's worth a debug! per probe so a slow driver at startup is attributable.

AI-assisted (Claude Code).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…he title, and name the ones that cannot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 66d97ee: cargo test -p victory-gpu passes, 57 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@heromike405-arch

Copy link
Copy Markdown
Contributor

Independent DXGI/D3D12 probe on a hybrid Windows 11 laptop (build 26100). I created a feature-level 12.0 D3D12 device per enumerated adapter and made the same SM 6.6 and OPTIONS7 mesh-tier queries used in 66d97ee.

Adapter Dedicated VRAM SM 6.6 Mesh tier DXGI software
NVIDIA GeForce RTX 5060 Laptop GPU 7899 MiB Yes 1 No
AMD Radeon 610M 461 MiB Yes None No
Microsoft Basic Render Driver 0 MiB Yes 1 Yes

Applying the PR's selection rules to the measured facts picks the RTX 5060. In this configuration, D3D12CreateDevice(NULL, ...) also returned the RTX device, so this run does not reproduce the default-adapter mismatch. The software adapter did report mesh support despite being flagged as software.

Standalone probe of the Windows APIs and the selection criteria. The PR binary and game were not run. AI-assisted with Codex.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/lib.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

@Coderlord

Copy link
Copy Markdown

A suggestion from testing #967: skip software adapters in probe().

probe() makes a D3D12 device on every enumerated adapter, the Microsoft Basic Render Driver included, though runs_the_title() never picks a software adapter. A WARP device is one per adapter and process, so the probe makes and drops the very device that code asking for WARP on purpose holds. In a fork with a WARP-based test (fxceless/victory-gta6's inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset), that test failed in 2 of 2 full cargo test --workspace runs with #967 applied (a VirtualFree(MEM_DECOMMIT) of memory that a just-dropped WARP placed buffer covered was refused), and in 1 of 4 full runs with the change below (so the change makes it rarer, not gone; the test itself races WARP releasing the placed buffer late). Run alone, it passes either way. The main point stands on its own: the probe makes a device no choice can use.

The change, in crates/victory-gpu/src/adapter.rs: return early from probe() for software adapters, and have report() say not probed for them instead of no D3D12 device:

    // Software adapters are never chosen (`runs_the_title`), so no device is
    // made on them: a WARP device in every process costs time and memory, and
    // it is the very device (one per adapter and process) that code and tests
    // asking for WARP on purpose get.
    if facts.software {
        return facts;
    }

The choice does not change: on Windows 11 with an RTX 5080, an AMD integrated GPU and the Basic Render Driver, #967 with this change picks the RTX 5080 (host adapter chosen adapter=NVIDIA GeForce RTX 5080 shader_model=0x66 mesh_shaders=true adapters=3), and it no longer makes a WARP device at every start.

AI use: found, written and tested with Claude Code (Claude Opus 5.5).

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.

6 participants