gpu: select high-performance hardware adapter on multi-GPU systems #3073
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3073
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3073"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AdvaitPalve11 on GitHub · 2026-11-26 06:26 UTC · original
AdvaitPalve11:feat/gpu-high-performance-adapter→main· +211 −0 · 2 files · 3 commits · openOn hybrid laptops and multi-GPU systems, passing None to D3D12CreateDevice defaults to the display adapter (often integrated Intel/AMD graphics) instead of the discrete high-performance GPU (NVIDIA/AMD), leading to shader/pipeline failures and memory limits.
Query IDXGIFactory6::EnumAdapterByGpuPreference with DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE to select discrete GPU.
Fall back to enumerating non-software adapters by largest dedicated video memory.
Support optional VICTORY_D3D12_ADAPTER= for explicit adapter filtering.
Add unit tests verifying adapter description parsing and software adapter exclusion.
15b54e36d8to98253adb64@kotekompotek on GitHub · 2026-11-26 06:34 UTC · original · approved these changes
Verified: env substring filter uses full enum (user's explicit choice, even software); GpuPreference enum skips SOFTWARE flag so WARP is never picked implicitly; VRAM-max fallback also skips software; device-creation failure on the chosen adapter warns and falls back to default with tdr::log() preserved in both branches; WARP env keeps priority. adapter_name handles missing terminator.
@Marvisak on GitHub · 2026-11-26 08:23 UTC · original
Automated triage for the maintainers.
Verdict: needs work. Choosing the discrete GPU on hybrid machines could be useful, but
hardware_adapterincrates/victory-gpu/src/host.rschanges which device every non-WARP run gets, and the PR gives no run showing the problem or the fix.What it needs:
D3D12CreateDevice(None, …)lands on the integrated GPU, and that this change picks the discrete one and the title runs there.EnumAdapterByGpuPreference(HIGH_PERFORMANCE)may override the GPU the user picked for the exe in Windows' per-app graphics settings. Either keep the default adapter unless asked (theVICTORY_D3D12_ADAPTERfilter, or an opt-in switch), or show that per-app settings still apply.hardware_adapter_selects_non_softwareonly checks what the function itself filters for, and it does nothing on machines where nothing is returned. IfVICTORY_D3D12_ADAPTERis set and matches the software adapter, it fails. A test that checks the selection order on a fixed list of adapter descriptions would be more useful.victory-shader'semit::host::hardware_adapterwith different rules. One rule for both would keep the translator's checks and the runtime on the same adapter.CI:
checkpassing.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 08:25 UTC · original · requested changes
Tested on a dual-GPU Windows 11 system (
NVIDIA GeForce RTX 50900x10de+AMD Radeon(TM) Graphics0x1002+ WARP):VICTORY_D3D12_ADAPTER="RTX 5090", and an unmatched filter (nonexistent_gpu_xyz) all selectNVIDIA GeForce RTX 5090.VICTORY_D3D12_ADAPTER=RadeonselectsAMD Radeon(TM) Graphicsand genuinely switches the host D3D12 device end-to-end (confirmed by runningpresent_compositor_builds_both_pipeline_statesanddynamic_slots_are_held_until_released, which passes on the AMD iGPU's >1M descriptor heap while failing on NVIDIA's 1M cap).VICTORY_D3D12_WARP=1(--features diagnostics) still takes precedence viawarp_adapter(), andvideo_memory()already queriesdevice.GetAdapterLuid(), so VRAM reporting follows the selected adapter automatically.cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features) andcargo xtask policyare clean.A few small issues showed up during source review and testing that should be addressed before merging:
1.
VICTORY_D3D12_ADAPTERdoes not ignore empty/whitespace values or skip software adapters (crates/victory-gpu/src/host.rs:46-60)VICTORY_D3D12_ADAPTERis set to""or whitespace (e.g., from a launcher/wrapper script),name.to_lowercase().contains(&filter_lower)matchesEnumAdapters1(0)unconditionally — on hybrid laptops where adapter 0 is the iGPU, that silently bypassesDXGI_GPU_PREFERENCE_HIGH_PERFORMANCE. Please.trim()the value and ignore it when empty.VICTORY_D3D12_ADAPTERloop also doesn't skipDXGI_ADAPTER_FLAG_SOFTWARE. TestingVICTORY_D3D12_ADAPTER=BasicreturnsMicrosoft Basic Render Driver(vendor=0x1414, flags=0x2), logs"selected hardware adapter via VICTORY_D3D12_ADAPTER", bypasses thediagnostics-only gate onVICTORY_D3D12_WARP=1, and makes this PR's ownhardware_adapter_selects_non_softwaretest panic (left: 2, right: 0). SkippingDXGI_ADAPTER_FLAG_SOFTWAREhere keeps the function consistent with its name, log message, and unit test.2. Probe D3D12
FEATURE_LEVEL_12_0support before returning a candidate (crates/victory-gpu/src/host.rs:16-24, 63-105)hardware_adapter()returns the first non-software adapter without probingD3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, std::ptr::null_mut::<Option<ID3D12Device>>()).is_ok(). If the first enumerated hardware adapter lacks D3D12 FL 12.0 support (or is a virtual/headless display driver that rejects device creation),create()immediately falls back toD3D12CreateDevice(None, ...)instead of continuing to the next hardware adapter in theIDXGIFactory6/ VRAM-fallback loops.3.
README.mdtable placement (README.md:215)VICTORY_D3D12_ADAPTER=<name>is currently added inside the--features victory-gpu/diagnosticstable next toVICTORY_D3D12_WARP=1, even thoughhost.rshonors it in all builds. Please move it to the always-available environment variables section above (around lines 155-166), or explicitly note that it does not requirediagnostics.@smaxxey on GitHub · 2026-11-26 10:13 UTC · original
Evidence from a hybrid laptop, which the triage asked for: i7-13620H with an RTX 4060 Laptop GPU and Intel UHD, Windows 11 26300, Rust 1.98.1. No game files.
EnumAdapters1order here: 0 = RTX 4060 Laptop GPU, 1 = Intel UHD Graphics, 2 = Microsoft Basic Render Driver. The only active output,\\.\DISPLAY5(the primary, at 0,0), is on the RTX 4060; the Intel adapter has no outputs. So onmain,D3D12CreateDevice(None, …)already lands on the RTX here.98253admerged locally ontomain63bcca4),hardware_adapter()picks the same one:hardware_adapter: description=NVIDIA GeForce RTX 4060 Laptop GPU, vendor=0x10de, flags=0x0.mainlands on the iGPU depends on which GPU drives the primary display, not on the machine model.cargo test -p victory-gpu --lib --lockedwith this PR: 231 passed, 2 failed, same asmain63bcca4on this card: only the two NVIDIA failures of #1835 (descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views), nothing new.Not shown by this run: the iGPU-first case itself, which this machine is not in right now.
Tested with Claude Code's help.
@AdvaitPalve11 on GitHub · 2026-11-26 16:32 UTC · original
Thanks for the thorough review and testing! I've updated the PR (commit
710c326) to address all review comments and triage items:VICTORY_D3D12_ADAPTERstring handling & software rejection:.trim()) and ignored if empty or whitespace-only, avoiding unconditional matching on adapter 0.desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE == 0within the filter loop so software adapters like Microsoft Basic Render Driver are never returned as a hardware adapter.D3D12 Feature Level 12.0 probing:
supports_d3d12()to probeD3D12CreateDevice(..., D3D_FEATURE_LEVEL_12_0, NULL)across all candidate loops (substring filter,EnumAdapterByGpuPreference, and VRAM fallback). If an enumerated adapter lacks FL 12.0 or is a virtual adapter that rejects device creation, enumeration continues to the next hardware adapter instead of aborting.Harmonized fallback rule:
victory-shader'semit::host::hardware_adapter(desc.DedicatedVideoMemory > 0).Deterministic unit tests:
select_adapter_fixed_list_rulestesting candidate filtering, whitespace trimming, software adapter rejection, and VRAM ranking against a mock list of adapter descriptions without requiring physical hardware.README.mdplacement:VICTORY_D3D12_ADAPTERfrom the--features diagnosticstable to the general environment variables section since it is honored in all builds.Regarding hybrid laptop evidence:
\\.\DISPLAY1.D3D12CreateDevice(None, ...)selects adapter 0 by default, forcing the title onto the iGPU unlesshardware_adapter()queriesEnumAdapterByGpuPreference(HIGH_PERFORMANCE).EnumAdapterByGpuPreferencerespects those preferences.@fuzeofficlal on GitHub · 2026-11-26 18:11 UTC · original · approved these changes
All previous review items are resolved in
710c326— approving to clear the earlier change request.Re-verified merged onto
main(63bcca43) on a dual-GPU Windows 11 system (NVIDIA GeForce RTX 50900x10de+AMD Radeon(TM) Graphics0x1002+ WARP):cargo xtask policy(191 files ok),cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--all-features), and all 4 adapter unit tests (adapter_name_handles_null_terminator,hardware_adapter_selects_non_software,select_adapter_fixed_list_rules,warp_adapter_accepts_only_software) pass.VICTORY_D3D12_ADAPTERlive matrix across fresh processes:""," "," rtx 5090 ", and"nonexistent_gpu_xyz"all selectNVIDIA GeForce RTX 5090(0x10de, flags=0x0)."Basic"now skipsMicrosoft Basic Render Driver(DXGI_ADAPTER_FLAG_SOFTWARE) and falls back toNVIDIA GeForce RTX 5090(flags=0x0), fixing the previous panic."Radeon"selectsAMD Radeon(TM) Graphics(0x1002, flags=0x0) and passes end-to-end D3D12 device tests (present_compositor_builds_both_pipeline_states,read_marks_of_both_bitmaps_are_taken) on the AMD iGPU.VICTORY_D3D12_WARP=1(--features diagnostics) still takes priority even whenVICTORY_D3D12_ADAPTER=Radeonis set.supports_d3d12()(crates/victory-gpu/src/host.rs:399) probesD3D_FEATURE_LEVEL_12_0across all three selection loops, andREADME.md:166-168now documentsVICTORY_D3D12_ADAPTERoutside the diagnostics-only table.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.