Use the discrete GPU on laptops instead of the integrated one #22

Open
github-bot wants to merge 1 commit from github-bot/gh-22 into beta AGit
Owner

@⁠spy0eye-beep on GitHub · 2026-11-25 17:03 UTC · original
spy0eye-beep:klbf-discrete-gpu → beta · +71 −15 · 2 files · 1 commits · open

What

On a laptop with two GPUs, KLBF Lab made its D3D12 device on the default adapter, which Windows lists as the integrated GPU unless the user sets a per-app preference. So on a hybrid laptop the game, and every "hardware" shader test, run on the integrated GPU.

Found on an RTX 4060 Laptop GPU + Intel UHD Graphics (i7-13620H, Windows 11 24H2): adapter 0 is the Intel UHD, adapter 1 the RTX 4060.

Change

  • victory-gpu host: the first hardware adapter in DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE order that creates a D3D12 device is used, and its name is logged (host device adapter=...). If DXGI cannot order adapters it falls back to the default, as before. Software adapters (WARP, the Basic Render Driver) are never picked.
  • Shader test host (emit/host.rs): the same choice, so GPU tests run on the discrete GPU. VICTORY_TEST_ADAPTER=n takes the n-th hardware adapter in that order, to run the suite on each GPU of a machine. The adapter name is printed in test output only.
  • New test high_performance_adapter_is_hardware.

Note: this overrides a "power saving" choice made for victory.exe in Windows graphics settings, which is the usual behaviour for games.

Testing

cargo test --workspace --all-features on beta (c71c7d6), RTX 4060 Laptop + Intel UHD, Windows 11 24H2, Rust 1.98.1:

Build GPU the tests ran on Result
beta as published Intel UHD (default adapter) 580 passed, 9 failed
this PR RTX 4060 Laptop 587 passed, 2 failed
this PR, VICTORY_TEST_ADAPTER=1 Intel UHD 580 passed, the same 9 failed

7 of the 9 failures are Intel UHD driver behaviour (intersect_tests ×4, ds_min_max_f32..., v_permlane16..., whole_wave_f64...). The 2 left (emit::rect::tests::*) fail on beta too and are not touched here.

Also seen: in one run of beta as published on the Intel UHD, the victory-gpu test binary exited with STATUS_ACCESS_VIOLATION after watch::mapping_tests::reads_in_place_and_remappings_wait_for_each_other. It did not happen with this PR, but I did not look into it.

  • cargo check / cargo build --release -p victory: OK. cargo clippy -D warnings reports the same two errors with and without this PR (draw.rs sort_unstable_by_key, indirect.rs depth_written); none are new.
  • Not run with the title.

The same fix is open upstream as Marvisak/VIctory#1483.

AI-assisted (Claude).

🤖 Generated with Claude Code

**@⁠spy0eye-beep** on GitHub · 2026-11-25 17:03 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/22) `spy0eye-beep:klbf-discrete-gpu` → `beta` · +71 −15 · 2 files · 1 commits · open ## What On a laptop with two GPUs, KLBF Lab made its D3D12 device on the **default adapter**, which Windows lists as the **integrated GPU** unless the user sets a per-app preference. So on a hybrid laptop the game, and every "hardware" shader test, run on the integrated GPU. Found on an **RTX 4060 Laptop GPU + Intel UHD Graphics** (i7-13620H, Windows 11 24H2): adapter 0 is the Intel UHD, adapter 1 the RTX 4060. ## Change - `victory-gpu` host: the first hardware adapter in `DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE` order that creates a D3D12 device is used, and its name is logged (`host device adapter=...`). If DXGI cannot order adapters it falls back to the default, as before. Software adapters (WARP, the Basic Render Driver) are never picked. - Shader test host (`emit/host.rs`): the same choice, so GPU tests run on the discrete GPU. `VICTORY_TEST_ADAPTER=n` takes the n-th hardware adapter in that order, to run the suite on each GPU of a machine. The adapter name is printed in test output only. - New test `high_performance_adapter_is_hardware`. Note: this overrides a "power saving" choice made for victory.exe in Windows graphics settings, which is the usual behaviour for games. ## Testing `cargo test --workspace --all-features` on `beta` (`c71c7d6`), RTX 4060 Laptop + Intel UHD, Windows 11 24H2, Rust 1.98.1: | Build | GPU the tests ran on | Result | |---|---|---| | `beta` as published | Intel UHD (default adapter) | 580 passed, **9 failed** | | this PR | **RTX 4060 Laptop** | **587 passed, 2 failed** | | this PR, `VICTORY_TEST_ADAPTER=1` | Intel UHD | 580 passed, the same 9 failed | 7 of the 9 failures are Intel UHD driver behaviour (`intersect_tests` ×4, `ds_min_max_f32...`, `v_permlane16...`, `whole_wave_f64...`). The 2 left (`emit::rect::tests::*`) fail on `beta` too and are not touched here. Also seen: in one run of `beta` as published on the Intel UHD, the `victory-gpu` test binary exited with `STATUS_ACCESS_VIOLATION` after `watch::mapping_tests::reads_in_place_and_remappings_wait_for_each_other`. It did not happen with this PR, but I did not look into it. - `cargo check` / `cargo build --release -p victory`: OK. `cargo clippy -D warnings` reports the same two errors with and without this PR (`draw.rs` `sort_unstable_by_key`, `indirect.rs` `depth_written`); none are new. - Not run with the title. The same fix is open upstream as Marvisak/VIctory#1483. AI-assisted (Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The host device and the shader test host were made on the default adapter,
which on a laptop with two GPUs is the integrated one (adapter 0) unless the
user set a per-app preference in Windows. On an RTX 4060 Laptop + Intel UHD
machine the game and every "hardware" test ran on the Intel UHD.

Now the first hardware adapter in DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE order
that makes a D3D12 device is used, and its name is logged ("host device").
Falls back to the default adapter if DXGI cannot order them. Software
adapters (WARP, the Basic Render Driver) are never picked. For the tests,
VICTORY_TEST_ADAPTER=n takes the n-th hardware adapter in that order, so a
suite can be run on each GPU of a machine.

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

@⁠PastiiJay on GitHub · 2026-11-25 18:38 UTC · original

Thanks a lot @⁠spy0eye-beep! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.

**@⁠PastiiJay** on GitHub · 2026-11-25 18:38 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/22#issuecomment-7171179556) Thanks a lot @⁠spy0eye-beep! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-26 04:38 UTC · original

On a Windows runner with no physical GPU, high_performance_adapter() at 6b4569b returned Microsoft Basic Render Driver as the preferred hardware adapter. Its DXGI descriptor was 1414:008c, flags 0x0. Explicit WARP had the same IDs, flags 0x2, and a different LUID. The PR’s shader host already recognizes both forms and correctly reports no hardware adapter. Original result

I tested a three-line change on top of this PR that gives the runtime selector the same PCI-ID check. It then returns None on this machine. The normal runtime still starts through its existing default fallback, and forcing WARP still selects the explicit software adapter. All three checks passed. The original laptop results remain the test of discrete-versus-integrated selection. Cherry-pick 7786134 · Windows verification

**@⁠HandshakeHackin** on GitHub · 2026-11-26 04:38 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/22#issuecomment-7182766923) On a Windows runner with no physical GPU, `high_performance_adapter()` at `6b4569b` returned Microsoft Basic Render Driver as the preferred hardware adapter. Its DXGI descriptor was `1414:008c`, flags `0x0`. Explicit WARP had the same IDs, flags `0x2`, and a different LUID. The PR’s shader host already recognizes both forms and correctly reports `no hardware adapter`. [Original result](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45755433039/job/139692843019) I tested a three-line change on top of this PR that gives the runtime selector the same PCI-ID check. It then returns `None` on this machine. The normal runtime still starts through its existing default fallback, and forcing WARP still selects the explicit software adapter. All three checks passed. The original laptop results remain the test of discrete-versus-integrated selection. [Cherry-pick `7786134`](https://github.com/HandshakeHackin/klbf-lab/commit/7786134055dd4a98ff641fdd4dd642d63b3c362d) · [Windows verification](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45755988929/job/139694601075)
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-26 10:42 UTC · original

Thanks for catching the Basic Render Driver case on GPU-less runners. We'll try it on a laptop before merging.

**@⁠PastiiJay** on GitHub · 2026-11-26 10:42 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/22#issuecomment-7189729533) Thanks for catching the Basic Render Driver case on GPU-less runners. We'll try it on a laptop before merging.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/22/head:github-bot/gh-22'
git switch 'github-bot/gh-22'

Merge

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