GPU, HLE, loader and shader: 14 bug fixes that apply cleanly to main #460

Open
github-bot wants to merge 14 commits from github-bot/gh-460 into main AGit
Owner

@⁠zocram4cc on GitHub · 2026-11-27 12:36 UTC · original
zocram4cc:up/pr-fixes-stability → main · +567 −53 · 17 files · 14 commits · open

Fourteen bug fixes cherry-picked from a third-party Proton/RADV port (zocram4cc/victory-linux-perf, main) onto 126acb35. They apply cleanly one by one; original authors and commit messages are kept.

What they are: GPU stability (query heap, CPU snapshot retry, 4 KiB texture alignment, APU heap use-after-free, command-queue release use-after-free, DirectStorage out-pointer, loader DLL case and clzero-loop decoding, gamepad output), plus five shader fixes (helper-lane v_readfirstlane, always-true/false float compares, gfx10 _g16 gradient packing, an AMD compiler crash, a pos4 export).

Authors: davutsimsekk, avt0m4t, AscilCH (×3), Peppacodes (×2), Vax, mynzjerko, libslibslibslibslibslibs.

Provenance: curated from the RYUKI-7900XT / LibsMQG hle-d3d12-7900xtx fork line and contributor PRs; none of the fourteen is in main or in any open PR I could find (checked the open list against each commit).

One default-on behaviour change, stated plainly: "GPU/resource: preserve 4 KiB texture alignment" (ce422300, AscilCH) changes how the title spaces its small textures — 4 KiB alignments are kept instead of being raised to 64 KiB in GetResourceAllocationInfo(2). It fixes the contradictory allocation info and the unaligned MSAA sizes that caused it, but it does move the title-memory layout. Our own Proton tree can restore the old layout with VICTORY_SMALL_ALIGN=0 (default = 4 KiB kept). We have not measured this fix in isolation — in our runs it always shipped with other switches — so treat the layout change as unmeasured, and drop just this commit if you want the old behaviour.

Testing — honest: this port applies cleanly to main commit by commit. It has NOT been compiled or run by the submitter (Linux, no Windows target, no game runs in this environment), so treat CI as the gate. No commit adds an environment variable, changes a default, or touches the shader translator version; every behavior change is a bug fix with its own tests inside the commit where the original added tests.

AI-assisted selection/verification (cherry-pick dry-run, author attribution, redundancy check); all code is the original authors'.

**@⁠zocram4cc** on GitHub · 2026-11-27 12:36 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/460) `zocram4cc:up/pr-fixes-stability` → `main` · +567 −53 · 17 files · 14 commits · open Fourteen bug fixes cherry-picked from a third-party Proton/RADV port (zocram4cc/victory-linux-perf, `main`) onto `126acb35`. They apply cleanly one by one; original authors and commit messages are kept. **What they are:** GPU stability (query heap, CPU snapshot retry, 4 KiB texture alignment, APU heap use-after-free, command-queue release use-after-free, DirectStorage out-pointer, loader DLL case and `clzero`-loop decoding, gamepad output), plus five shader fixes (helper-lane `v_readfirstlane`, always-true/false float compares, gfx10 `_g16` gradient packing, an AMD compiler crash, a pos4 export). **Authors:** davutsimsekk, avt0m4t, AscilCH (×3), Peppacodes (×2), Vax, mynzjerko, libslibslibslibslibslibs. **Provenance:** curated from the RYUKI-7900XT / LibsMQG hle-d3d12-7900xtx fork line and contributor PRs; none of the fourteen is in `main` or in any open PR I could find (checked the open list against each commit). **One default-on behaviour change, stated plainly:** "GPU/resource: preserve 4 KiB texture alignment" (`ce422300`, AscilCH) changes how the title spaces its small textures — 4 KiB alignments are kept instead of being raised to 64 KiB in `GetResourceAllocationInfo(2)`. It fixes the contradictory allocation info and the unaligned MSAA sizes that caused it, but it does move the title-memory layout. Our own Proton tree can restore the old layout with `VICTORY_SMALL_ALIGN=0` (default = 4 KiB kept). We have not measured this fix in isolation — in our runs it always shipped with other switches — so treat the layout change as unmeasured, and drop just this commit if you want the old behaviour. **Testing — honest:** this port applies cleanly to `main` commit by commit. It has NOT been compiled or run by the submitter (Linux, no Windows target, no game runs in this environment), so treat CI as the gate. No commit adds an environment variable, changes a default, or touches the shader translator version; every behavior change is a bug fix with its own tests inside the commit where the original added tests. AI-assisted selection/verification (cherry-pick dry-run, author attribution, redundancy check); all code is the original authors'.
Fix two resource allocation-info bugs in `crates/victory-gpu/src/resource.rs`:

1. `place()` initialized `total.alignment = KIB_64` and took `max(one.alignment)`,
   clobbering 4 KiB console texture alignments (e.g., 512x512 BC7 10 mips ->
   `{ size: 0x56000, alignment: 0x1000 }`) up to 64 KiB in
   `GetResourceAllocationInfo` / `GetResourceAllocationInfo2` (and producing
   contradictory `total.alignment = 64 KiB` vs `each[0].alignment = 4 KiB` in
   `GetResourceAllocationInfo2`). Start with `alignment: 0` and default to
   `KIB_64` only for empty descriptor lists.
2. `footprint()`'s fallback path rounded `size` to `KIB_64` instead of
   `alignment`, leaving `SizeInBytes` unaligned to `Alignment` for MSAA
   (`MIB_4`) or custom-aligned resources. Round to `alignment`.

Extend `resource::tests::sizes_cover_every_mip` to verify both fixes.
`audio::heap_bytes` previously returned a raw `&'a mut [u8]` slice after
releasing the `HEAP` mutex, while `ApuFree` (`heap_free`) immediately
called `std::alloc::dealloc`. Because the background XMA decoder thread
reads input buffers and writes output ring blocks via `heap_bytes`
without holding `HEAP`, a concurrent `ApuFree` freed the backing buffer
out from under the active decoder (and similarly for `submit`'s
notification write via `heap_unmap`).

Wrap each heap block's raw allocation in an `Arc<Allocation>` whose
`Drop` calls `std::alloc::dealloc`, and return an owned `HeapSlice`
(implementing `Deref`/`DerefMut<Target = [u8]>`) from `heap_bytes` that
retains the `Arc<Allocation>` until dropped (using checked addition for
`offset + len`). Use `heap_bytes(notification, 4)` in `submit`.

Add `audio::tests::heap_bytes_retains_allocation_across_apu_free`.
Fix a double use-after-free in `crates/victory-gpu/src/queue.rs`:

1. `queue::release` called `object::release_boxed::<Queue>(this)` (freeing
   the `Box<Queue>`) *before* removing `this` from `WAITING`, leaving a
   dangling pointer in `WAITING` between those two statements.
2. `release_held()` cloned `WAITING`, dropped the `WAITING` lock, and
   dereferenced each `Queue` pointer across its entire loop without
   synchronizing with `queue::release`, allowing a concurrent `Release()` on
   another thread to free a waiting queue while `release_held()` still held
   its raw pointer.

Add `object::release_boxed_with` in `crates/victory-gpu/src/object.rs` so
the cleanup callback runs before `Box::from_raw`, hoist `RELEASING` to module
scope in `queue.rs`, and lock `RELEASING` -> `WAITING` in `queue::release`
before freeing `Queue`. Add unit test
`queue::tests::release_waits_for_release_held_before_freeing_waiting_queue`.

Adapted onto RYUKI (line B): release_held keeps its ASYNC_SUBMIT hand-off to
queue/behind.rs and its `all` parameter; only the lock moves to module scope.
map_dll lowercased the DLL's name and joined that to the title folder.
On a case-sensitive folder (WSL creates them so, and new subfolders
inherit the flag) GameLib.dll is not gamelib.dll: is_file() was false
and the DLL was skipped without an error, so its imports went to stubs
and a title's own LoadLibrary saw "not a title image".

The lowercased name stays the key (seen, wanted, the returned list).
The file is the name as written or, failing that, the folder's entry
that matches it ignoring ASCII case, as the Windows loader ignores case.

Test: a case-sensitive temp folder (fsutil setCaseSensitiveInfo, no
admin) holding Late.dll, loaded as Late.dll, LATE.DLL and late.dll.
Skipped where Windows cannot make such a folder.
From AscilCH's bbd2408 ("loader: fix ClzeroLoop ModRM decoding, >=2 GiB
skip, unaligned/empty bounds, and EFlags"), the decoder part only:
`decode` did not check that `48/4C 39 modrm` is register to register with
rax as the destination, so `cmp rcx, rdx`, `cmp [rax], rdx` or `cmp rax,
rax` after `clzero; add rax, 0x40` decoded as a ClzeroLoop. With the check
those are a plain clzero, stepped one at a time.

The emulation parts (>= 2 GiB, end <= start, unaligned, EFlags) are not
taken: RYUKI rewrote the loop's emulation (passes capped at 2 GiB and
continued, one pass for an end not above the start, flags from cmp_flags,
a stub patched in on the first fault), which covers them.
On the console, whole-quad mode puts a pixel shader's helper lanes in
EXEC, so a waterfall loop (read the first lane's value, run the lanes
with that value, take them out of EXEC) serves them too. On the host,
wave operations leave helper lanes out: once only helper lanes are left
in such a loop, WaveReadLaneFirst reads no lane, no lane matches, and the
loop runs to the iteration limit in each of them. In a retail title's
world, draws took 0.3 to 1.3 s each until a submission passed the host's
2 s limit: DEVICE_HUNG about 200 s into the world.

A helper lane now takes its own value, so it matches in the first pass
and leaves. What it computes only feeds derivatives; its stores are
dropped already. Waterfall reads the proof already turns into per-lane
reads are unchanged.
v_cmp_f_{f32,f16} and v_cmp_tru_{f32,f16} lowered to fcmp false and
fcmp true (predicates 0 and 15). DXC folds those away, so drivers never
see them from it, and WARP removes its device at the first dispatch of
a pipeline that has one ("The GPU device instance has been suspended").
The hardware adapter (RTX 5080) runs them. A removed WARP device stays
removed for the process, so everything after it fails too.

They are false and true whatever the operands, NaNs included (RDNA2
ISA), so they now lower as constants, as the integer v_cmp_f/v_cmp_t
already do. FALSE and TRUE stay in the predicate table, unused.

Found with a sweep of every 32-bit VALU instruction on the hardware
adapter against WARP: all 62 compares now run and agree on both.

Test: float_compares_that_are_always_false_or_true, f32 and f16 with
ordinary and NaN operands, on the hardware adapter and WARP. On main
WARP's dispatch fails with the device suspended.
In `gfx10/fields.rs`, `image_addr_dwords` only packed derivative dwords (`2 * derivs.div_ceil(2)`) when `a16` was set, ignoring the `_g16` suffix on all 8 RDNA2 `image_sample_*_g16` opcodes (`0x0a2..=0x0bb`). On RDNA2, `_g16` opcodes always pack gradients into 16-bit pairs regardless of `a16`, while coordinates/clamp remain controlled by `a16`.

When `a16 == false`, 2D/3D/Cube/2D_ARRAY `image_sample_*_g16` instructions decoded 2 extra address VGPRs — adding bogus register reads in sequential mode and reading past `self.words.len()` (injecting bogus `v0` operands) in NSA mode. Track `"g16"` in `image_addr_dwords` and add synthetic sequential and NSA decode unit tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:45:05 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-27 12:49 UTC · original

Two things I noticed while checking this against the Wine tree.

  • On the parent of b1d8db01, first_lane() already returns a pixel helper lane’s own value by default. The extra selection after that call repeats the same work and bypasses VICTORY_HELPER_OWN=0. Is there a case the existing path misses?
  • The shader cache still keys on TRANSLATOR_VERSION = 1 by default. A new source digest records that an entry is old, and normal runs still serve it unless refresh is enabled. The gradient and compare changes should bump the translator version so existing installs pick them up.
**@⁠UwUCammie** on GitHub · 2026-11-27 12:49 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/460#issuecomment-7218712203) Two things I noticed while checking this against the Wine tree. - On the parent of `b1d8db01`, `first_lane()` already returns a pixel helper lane’s own value by default. The extra selection after that call repeats the same work and bypasses `VICTORY_HELPER_OWN=0`. Is there a case the existing path misses? - The shader cache still keys on `TRANSLATOR_VERSION = 1` by default. A new source digest records that an entry is old, and normal runs still serve it unless refresh is enabled. The gradient and compare changes should bump the translator version so existing installs pick them up.
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-27 12:52 UTC · original

I ran Peppacodes’s constant float compare test on the Wine branch. All 16 f16 and f32 cases passed on an RX 7900 XT with RADV 26.3.1 and vkd3d-proton 71cae091b06571e. The Wine port includes the cache version bump. Wine PR #8

**@⁠UwUCammie** on GitHub · 2026-11-27 12:52 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/460#issuecomment-7218773303) I ran Peppacodes’s constant float compare test on the Wine branch. All 16 f16 and f32 cases passed on an RX 7900 XT with RADV 26.3.1 and vkd3d-proton `71cae091b06571e`. The Wine port includes the cache version bump. [Wine PR #8](https://github.com/borntofrag34/VIctory-7900XTX/pull/8)
Author
Owner

@⁠GiovanniFadanelli on GitHub · 2026-11-27 14:24 UTC · original

Superseded by #469: the same 14 commits plus three fix-ups (a test-isolation fix for the APU use-after-free test, the readfirstlane select obeying VICTORY_HELPER_OWN, translator version 1 → 2), built and tested on Windows with an RX 9070 XT. Results are in that PR.

**@⁠GiovanniFadanelli** on GitHub · 2026-11-27 14:24 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/460#issuecomment-7220745107) Superseded by #469: the same 14 commits plus three fix-ups (a test-isolation fix for the APU use-after-free test, the readfirstlane select obeying VICTORY_HELPER_OWN, translator version 1 → 2), built and tested on Windows with an RX 9070 XT. Results are in that PR.
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/460/head:github-bot/gh-460'
git switch 'github-bot/gh-460'

Merge

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