Pick the discrete GPU on laptops; fix driver-dependent and wrong shader lowering #1483
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!1483
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1483"
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?
@spy0eye-beep on GitHub · 2026-11-24 18:20 UTC · original
spy0eye-beep:fix/hybrid-gpu-and-driver-portable-shaders→main· +486 −66 · 8 files · 1 commits · openWhat
Found on a hybrid laptop (Intel UHD Graphics + NVIDIA GeForce RTX 4060 Laptop GPU). One GPU-selection fix and six shader/runtime fixes. Each fix has a test that fails on
mainand passes here.1. GPU: use the discrete GPU on laptops (
victory-gpu, shader test host)The host device was created with a null adapter, i.e. adapter 0, which on a laptop is the integrated GPU unless the user set a per-app preference in Windows. On this machine VIctory (and every "hardware" GPU test) ran on Intel UHD Graphics.
Now the first hardware adapter in
DXGI_GPU_PREFERENCE_HIGH_PERFORMANCEorder that creates a D3D12 device is used, and its name is logged. Falls back to the old behaviour if DXGI cannot order adapters. Note: this overrides a user's "power saving" choice for VIctory in Windows graphics settings, which is the usual behaviour for games.The shader test host does the same, and
VICTORY_TEST_ADAPTER=npicks the n-th hardware adapter so the suite can be run on each GPU of a machine.2. Shaders: SCC of
s_min_*/s_max_*/s_lshlN_add_u32SCC was set to
result != 0. Fors_min/s_maxit is the comparison that picked the result (RDNA2 ISA);s_lshlN_addsets it to a carry, which is nowMissing(fails loudly if read) instead of silently wrong.Test:
scalar_min_max_set_scc_to_the_comparison(onmain:s_min_i32(2, 1)gives SCC = 1, want 0).3. Shaders: a loop stopped by
LOOP_LIMITthrough a conditional back edge kept runningThe limit was folded into the branch condition, so a lane at the limit took the loop's exit and continued through the program with unfinished values, possibly storing/exporting them, contrary to
LOOP_LIMIT's doc ("leaves the program as killed"). Conditional back edges now go through a latch block that branches to the header below the limit and to the abort block at it (asJumpback edges already did); header phis take this edge's values from the latch viaedges.Test:
loop_stopped_by_the_limit_stores_nothing(onmain: stores0x100000).4. Shaders: NaN handling in
v_cmp_*_f32/f16independent of the driverOn Intel UHD Graphics,
v_cmp_eq_f32 v1, v1with a NaN gives true (the driver foldsx == x). NaN operands are now found from the bits (|x| > 0x7F800000) and the float compare only orders numbers: ordered compares are false with a NaN, unordered ones true. Noxorof a compare is emitted (see the old comment about the AMD driver hang): "not NaN" is its own compare (is_number). This also replaces thev_cmp_lgspecial case.Test:
v_cmp_f32_all_predicates_with_nan(all 13 non-constant predicates, two registers and one register against itself).5. Shaders:
v_med3_f32/f16v_med3_f32(1.0, 2.0, NaN)gave 2 (the existingv_med3_f32_matches_rdna2_with_nanfails there onmain).max_min, so -0 orders below +0 like the hardware's min/max. OnmainWARP givesmed3(+0, -0, 1) = -0, and Intelmed3(+0, NaN, -0) = +0(want -0).Test:
v_med3_f32_orders_negative_zero_below_positive_zero.v_cvt_u16/i16_f16also uses the bit test for NaN now (no failure observed; same pattern).6. Shaders: comparison samplers
s.filter |= 0x80on a filter that already holds a reduction in bits 7-8 turned a minimum sampler (0x100) into a maximum one (0x180).StaticSampler::make_comparisonreplaces the reduction.Test:
comparison_replaces_the_reduction.7. HLE:
XAsyncCompleteraceFor a call that ends (failure or no result) the call was unregistered before the status was published. A status check starting in between found no call, did not wait, and returned
E_PENDINGfor a call that had ended. Status and unregistering are now done together under theCALLSlock (the call is removed only if it is still the sameArc, so a reused block is never touched). Behaviour change to note: the provider'sOP_CLEANUPnow runs while the call is still registered, before the status is published.Test:
waiting_never_sees_a_failed_call_still_pending(onmain: returnsE_PENDING).Testing
Windows 11 Pro 26200, i7-13620H, 16 GB, NVIDIA GeForce RTX 4060 Laptop GPU + Intel UHD Graphics, Rust 1.98.1, MSVC 14.44.
VICTORY_TEST_ADAPTER=0)VICTORY_TEST_ADAPTER=1)cargo test --workspace --all-featurescargo clippy --workspace --all-features --all-targets -- -D warnings: cleancargo xtask policy: 154 files okcargo build --release -p victory: okNot tested: an AMD GPU, and the title (no game data used).
AI-assisted (Claude).
🤖 Generated with Claude Code
@matheusfermiano-source on GitHub · 2026-11-24 18:24 UTC · original
A Linux/Proton data point on AMD. With this PR, a
maintest makes the AMD driver crash under the vkd3d-proton that Proton Experimental ships today. A newer vkd3d-proton fixes it, and the PR's own tests pass.Radeon 660M (RDNA2, RADV Mesa 26.3.1, waves 32..64), head
0daabcc:mainffe310ewaterfall_tests::lanes_load_from_the_buffer_their_nested_arms_chose, vkd3d-proton 3.1.0 (Proton Experimental 11.0-20261027b)libvulkan_radeon.soduringvkCreateComputePipelinescae8353)victory-shadersuite, vkd3d-proton 3.2.0emit::tests::stub_pipeline_is_created, as onmain: vkd3d-proton accepts a zeroed DXIL hash (see #1218).maindoes not, and anyone testing this branch on Linux should use vkd3d-proton 3.2.Built on Linux with llvm-mingw for
x86_64-pc-windows-gnullvm(Rust 1.98.1);dxil.dllfrom DXC 1.9.2609 was loaded. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.@wwwwwwww3333333 on GitHub · 2026-11-24 19:16 UTC · original
Native Windows run on AMD RDNA2: RX 6750 XT (RDNA2, gfx1031), AMD driver 32.0.21045.29003, i5-13400F, Windows 11, Rust 1.98.1 MSVC. Head
0daabccon mainffe310e(clean merge). Desktop with this one GPU, so the adapter pick has a single candidate.All the new tests pass, including
high_performance_adapter_is_hardware,v_med3_f32_orders_negative_zero_below_positive_zero,v_cmp_f32_all_predicates_with_nan,loop_stopped_by_the_limit_stores_nothingandwaiting_never_sees_a_failed_call_still_pending.On @matheusfermiano-source's RADV crash:
waterfall_tests::lanes_load_from_the_buffer_their_nested_arms_chosepasses here with this PR, on AMD's own D3D12 driver. So on Windows AMD this PR doesn't crash the driver. That fits the crash being the vkd3d-proton 3.1 / RADV issue rather than something in this PR's DXIL.Synthetic tests only, no game files. AI-assisted (Claude picked the PRs and wrote the batch script; I ran it on my machine).
@sinan-cmyk on GitHub · 2026-11-24 20:13 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
0daabccontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 21,724 with this PR.No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on
main. The count shows that the change rejects nothing. It does not show whether the output is right.Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 126, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@aycow on GitHub · 2026-11-24 20:57 UTC · original
An independent Windows Agility 1.620 full-GBV test reproduced the MED3 signed-zero defect. The upstream original f32/f16 tests passed on both AMD Radeon Graphics and WARP. Across 90 operand/permutation rows, upstream WARP failed 11 asserted signed-zero cases, including (+0, -0, 1) returning -0. I extracted only the MED3 portion of your
0daabccchange ontoffe310ewith your authorship. It passed the full asserted matrix on both devices and kept the signaling-NaN result classes identical to baseline. NVIDIA is currently absent from this machine's DXGI enumeration, so there is no result for the reported NVIDIA failure. The focused extraction is local; your existing work covers the fix.AI-assisted using Codex.
@KevinPratap on GitHub · 2026-11-24 21:18 UTC · original
Tested on NVIDIA: an RTX 4050 Laptop on Windows 11, with this pull request merged onto
main(ffe310e).cargo test -p victory-shader: 126 passed, 0 failed.v_med3_f32_matches_rdna2_with_nanfails onmainon this card:v_med3_f32(1.0, 2.0, NaN) = 2, where RDNA2 gives 1, because the driver folds thefcmp unoNaN test away. With this PR it passes, along withv_med3_f16_matches_rdna2_with_nanandv_med3_f32_orders_negative_zero_below_positive_zero.I had opened #1689 with only the
med3part of this. I'm closing it in favour of this PR. AI-assisted.@KevinPratap on GitHub · 2026-11-24 21:20 UTC · original
Driver for the result above: NVIDIA GeForce RTX 4050 Laptop GPU, driver 621.24. In #1633, an RTX 4090 and an RTX 5070 Ti (driver 32.0.16.1742) did not reproduce the
med3failure onmain. The folding seems to depend on the driver or the GPU, and this laptop shows it. Testing NaN from the bits, as this PR does, avoids it on all of them. AI-assisted.@tumbubu on GitHub · 2026-11-24 21:51 UTC · original
RX 7900 XT (RDNA3, driver 32.0.31036.15, the machine's only GPU): green.
0daabcc,cargo test -p victory-shader -p victory-gpu -p victory-hle --locked -- --test-threads=1:0daabccmain(ffe310e)victory-shadervictory-gpuvictory-hlev_cmp/v_med3NaN tests pass on the 7900 XT and on WARP.high_performance_adapter_is_hardwarepasses. With one GPU there is nothing else for it to pick, so this run does not test the laptop case.AI-assisted (Claude Code); every run was on this machine.
@Marvisak on GitHub · 2026-11-25 01:29 UTC · original · edited 2026-11-25 22:23 UTC
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-gpu/src/host.rs,crates/victory-hle/src/modules/xasync.rs,crates/victory-shader/src/emit/host.rs,crates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/emit/sampler.rs). It will be reviewed once it is rebased onto the currentmain.On your reply: splitting it into one PR per fix is the right call, thanks. #2812 (comparison sampler reduction) and #2813 (
s_lshlN_addSCC) are separate PRs and will be triaged on their own. This PR stays as needs-rebase until you close it once the remaining parts (LOOP_LIMIT latch,is_nanpart, xasync oncomplete_call, adapter selection) are up.Generated by Claude Code
@rminzao on GitHub · 2026-11-25 12:14 UTC · original
Thanks, the tests that fail on
mainmake each change easy to check. A few things from reading the head (0daabcc):Adapter choice,
crates/victory-gpu/src/host.rs:183-187: on currentmainthe default branch also runscrate::tdr::log(). When rebasing, the new high-performance branch needs it too, or the TDR warning goes away on almost every machine.:236-259: onlyDXGI_ADAPTER_FLAG_SOFTWAREis filtered out.main's shader host (hardware_adapter,ccfb029) documents that GitHub's runner listsMicrosoft Basic Render Driverwithout that flag. The probe here only checks FL 12_0 device creation. It does not check SM 6.6 orD3D12_OPTIONS1.WaveLaneCountMin/Max. So "first adapter that makes a device" may be one that later refuses the console's wave32 pipelines, while a capable adapter further down the list is skipped. Checking SM 6.6 andWaveLaneCountMax >= 32(andWaveOps) before accepting would make the fallback meaningful.:255: the probe device is created, dropped, then recreated at:184. Returning the probe device (or passing a null out pointer to test support) avoids the second creation.:185: only the name is logged, and the fallback branch (:187) logs nothing. Vendor/device id, LUID, driver (UMD) version and the wave lane range would make bug reports from hybrid machines easy to read. #2053 adds that log on its own, without changing the selection, so it composes with whichever selector lands.VICTORY_TEST_ADAPTERapplies to the shader test host only. As the description says, this also overrides a user's per-app "power saving" choice in Windows. An env override (index or name substring, as #1630/#967 discuss) would let a user go back.:289-298,high_performance_adapter_is_hardware: the function already drops software adapters, so the assertion cannot fail. It doesn't check that the high-performance adapter is the one picked.Shader test host,
crates/victory-shader/src/emit/host.rs:82-111:mainnow hashardware_adapter()with theDedicatedVideoMemory > 0check (CI's unflagged Basic Render Driver). This version filters on the software flag only, so a straight rebase would bring back the CI failureccfb029fixed.:97-103: the n-th adapter is taken without probing. If it failsD3D12CreateDeviceor lacks SM 6.6, the whole hardware suite errors instead of trying the next one. An unparsableVICTORY_TEST_ADAPTERsilently becomes 0. #1487 and #1889 change the same function; one shape would be easier for the maintainer.LOOP_LIMIT latch,
crates/victory-shader/src/emit/lower.rs:6900-6908with:6911-6922: every conditional back edge now gets a latch whose limit branch goes to the single, memoizedabort_block. Before, onlyJumpback edges did that. Now nearly every loop in a program shares one exit block (a critical edge from each latch), and each latch is a second exit out of all enclosing loops. That is not the dedicated-exit shape the comment at:6844aims for. It may be what trips RADV under vkd3d-proton 3.1 (matheusfermiano-source's comment) inwaterfall_tests::lanes_load_from_the_buffer_their_nested_arms_chose. A fresh abort block per latch (discard + ret, so cheap) would keep exits dedicated. The SSA itself looks right:nextand the compare are computed in the branching block, which dominates the latch, and the data, lane-mask and descriptor phis all look upedgesfor(b, header).NaN from the bits (
:1474-1511,:5366-5417,:4652)o/u/f/tru. f16 operands arrive as f32 throughlegacyF16ToF32, so the i32 mask is valid there. On rebase,main's med3 now goes throughftz+max_min_flushed(77053a0), so only theis_nanpart of this change is still new.Comparison sampler
sampler.rs:79:filter & !0x180 | 0x80is right for D3D12's reduction bits 7-8.main'simmediate_sampler_slots_distinguish_comparison_uses(mod.rs:779) still builds its expectation with| 0x80, so it should usemake_comparisontoo.XAsync (
crates/victory-hle/src/modules/xasync.rs:605-624)OP_CLEANUPnow runs while the call is still registered (and withcall.doneheld). A provider whose cleanup callsXAsyncGetStatus(block, true)on its own block now finds the call and waits on thedonelock its own thread holds, which deadlocks. Before,release()had already removed the call, so the wait returned. That is unlikely from a title, butrelease()'s comment ("it may call back into us") shows re-entry was considered. TheArc::ptr_eqguard is redundant onmain(a call that is not done is always the registered one), though harmless.mainnow routes this throughcomplete_call(&call, …)(#122/#1098/#247), so the change has to be redone there.Scope: one commit with seven independent fixes across three crates, and five of the files conflict with
main. Split into one PR per fix (each keeping its failing-on-maintest), these would be much easier to review and land. Several are a few lines each (make_comparison,s_lshlN_addSCC).Static review (AI-assisted), read against the PR head
0daabccbde; nothing was run on a GPU.@spy0eye-beep on GitHub · 2026-11-25 21:14 UTC · original
Thanks for the thorough review. Splitting this up on current main as asked:
s_lshlN_addSCC → #2813 (s_min/s_max is already fixed on main, so only this part is left)Still to come, each as its own PR: the LOOP_LIMIT latch with a fresh abort block per latch, so dedicated exits are kept; the
is_nanpart only, since med3 now hasmax_min_flushed; xasync rebuilt oncomplete_callso cleanup never runs whiledoneis held; and adapter selection with the SM 6.6 and wave-lane checks,tdr::log, and an env override, coordinated with #967 and #2053. I'll close this one once those are up.🤖 Generated with Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.