GPU, HLE, loader and shader: 14 bug fixes, built and tested on Windows (replaces #460) #469

Open
github-bot wants to merge 17 commits from github-bot/gh-469 into main AGit
Owner

@⁠GiovanniFadanelli on GitHub · 2026-11-27 14:22 UTC · original
GiovanniFadanelli:fixes/stability-tested → main · +571 −54 · 18 files · 17 commits · open

Replaces #460 (zocram4cc). The same 14 cherry-picked commits with their original authors (davutsimsekk, avt0m4t, AscilCH ×3, Peppacodes ×2, Vax, mynzjerko, libslibslibslibslibslibs), plus three fix-ups found by building and testing them:

  1. HLE/audio tests: the APU use-after-free test takes the module's test lock. heap_bytes_retains_allocation_across_apu_free was the only ApuAlloc test without CONTEXT_TESTS. After ApuFree, a parallel test could take the same APU address, so ApuMapApuAddress(apu).is_null() failed now and then (1 run in 8 here; also seen in a parallel workspace run on klbf-lab beta). CI runs tests in parallel.
  2. shader: the readfirstlane helper-lane select obeys VICTORY_HELPER_OWN (zocram4cc, cherry-picked). Answers the review point that the new select bypassed VICTORY_HELPER_OWN=0, which the shader cache keys on. The select now follows the switch, and it still covers the two-host-wave exchange path, where first_lane's result can come from the other half.
  3. Shader translator version 2. Five of the commits change the translation, and TRANSLATOR_VERSION's own comment asks for a bump. Without it, existing installs keep serving cached translations (the other review point).

One default-on behaviour change, as in #460: "GPU/resource: preserve 4 KiB texture alignment" keeps 4 KiB alignments in GetResourceAllocationInfo(2) instead of raising them to 64 KiB, so the title spaces its small textures as on the console. resource::tests::sizes_cover_every_mip covers it. Not measured in game.

Testing (Windows 11, RX 9070 XT, native MSVC toolchain 1.98.1; base 126acb35 vs this head)

Gate base 126acb35 this head
cargo check -p victory-gpu -p victory-hle -p victory-loader -p victory-shader -p victory --all-targets rc 0 rc 0
cargo test -p victory-shader (lib, one test skipped, see below) 301 / 0 / 4 ign 305 / 0 / 4 ign
victory-gpu lib, --test-threads 1 384 / 0 / 34 ign 386 / 0 / 34 ign
victory-hle lib, --test-threads 1 155 / 0 / 2 ign 157 / 0 / 2 ign
victory-loader lib + tests 52 + 4 52 + 5
victory (app) 21 / 0 21 / 0
cargo check -p victory-gpu --features diagnostics --all-targets rc 0 rc 0
cargo test --workspace --all-features -- --test-threads=1: victory-gpu 436 / 0 / 34 ign 438 / 0 / 34 ign
clippy -D warnings (default and --all-features, --keep-going) fails fails with the same errors as base: the loader transmute lints, plus list.rs open and watch.rs totals in victory-gpu, as #409 fixes

Red first: 11 of the 12 new or extended tests fail with their fix reverted and pass with it (for the queue use-after-free and the 16-bit gradient fix, by a hand revert of the fix itself). The exception is the APU heap test: its use-after-free half cannot be reverted without breaking the test's build, and its overflow assertion cannot fail at offset 0. For example: sizes_cover_every_mip left: AllocationInfo { size: 352256, alignment: 65536 }, release_waits_for_release_held_before_freeing_waiting_queue "queue::release freed queue while release_held lock was held", and float_compares_that_are_always_false_or_true WARP "device removed". Not red-first-able: the snapshot retry and the helper-lane readfirstlane commits carry no test.

Pre-existing on main and not from this PR: CI is red on every main run, both clippy steps fail (fixed by #409), and on an RX 9070 XT (RDNA 4) emit::size_tests::the_record_count_of_a_structured_buffer_read_by_index crashes the shader test process with an access violation (base and head alike, which ends cargo test --workspace early). That is the RDNA 4 compiler crash #55 addresses: on #55's head (whose base is the same 126acb35) the test passes on this card.

Not verified: in-game behaviour (no game runs) and the layout change in game.

AI-assisted (build, tests, red-first, the three fix-ups); the code of the 14 is the original authors'.

🤖 Generated with Claude Code

**@⁠GiovanniFadanelli** on GitHub · 2026-11-27 14:22 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/469) `GiovanniFadanelli:fixes/stability-tested` → `main` · +571 −54 · 18 files · 17 commits · open Replaces #460 (zocram4cc). The same 14 cherry-picked commits with their original authors (davutsimsekk, avt0m4t, AscilCH ×3, Peppacodes ×2, Vax, mynzjerko, libslibslibslibslibslibs), plus three fix-ups found by building and testing them: 1. **HLE/audio tests: the APU use-after-free test takes the module's test lock.** `heap_bytes_retains_allocation_across_apu_free` was the only `ApuAlloc` test without `CONTEXT_TESTS`. After `ApuFree`, a parallel test could take the same APU address, so `ApuMapApuAddress(apu).is_null()` failed now and then (1 run in 8 here; also seen in a parallel workspace run on klbf-lab beta). CI runs tests in parallel. 2. **shader: the readfirstlane helper-lane select obeys `VICTORY_HELPER_OWN`** (zocram4cc, cherry-picked). Answers the review point that the new select bypassed `VICTORY_HELPER_OWN=0`, which the shader cache keys on. The select now follows the switch, and it still covers the two-host-wave exchange path, where `first_lane`'s result can come from the other half. 3. **Shader translator version 2.** Five of the commits change the translation, and `TRANSLATOR_VERSION`'s own comment asks for a bump. Without it, existing installs keep serving cached translations (the other review point). One default-on behaviour change, as in #460: "GPU/resource: preserve 4 KiB texture alignment" keeps 4 KiB alignments in `GetResourceAllocationInfo(2)` instead of raising them to 64 KiB, so the title spaces its small textures as on the console. `resource::tests::sizes_cover_every_mip` covers it. Not measured in game. ### Testing (Windows 11, RX 9070 XT, native MSVC toolchain 1.98.1; base 126acb35 vs this head) | Gate | base 126acb35 | this head | |---|---|---| | `cargo check -p victory-gpu -p victory-hle -p victory-loader -p victory-shader -p victory --all-targets` | rc 0 | rc 0 | | `cargo test -p victory-shader` (lib, one test skipped, see below) | 301 / 0 / 4 ign | 305 / 0 / 4 ign | | victory-gpu lib, `--test-threads 1` | 384 / 0 / 34 ign | 386 / 0 / 34 ign | | victory-hle lib, `--test-threads 1` | 155 / 0 / 2 ign | 157 / 0 / 2 ign | | victory-loader lib + tests | 52 + 4 | 52 + 5 | | victory (app) | 21 / 0 | 21 / 0 | | `cargo check -p victory-gpu --features diagnostics --all-targets` | rc 0 | rc 0 | | `cargo test --workspace --all-features -- --test-threads=1`: victory-gpu | 436 / 0 / 34 ign | 438 / 0 / 34 ign | | clippy `-D warnings` (default and `--all-features`, `--keep-going`) | fails | fails with the same errors as base: the loader `transmute` lints, plus `list.rs` `open` and `watch.rs` `totals` in victory-gpu, as #409 fixes | Red first: 11 of the 12 new or extended tests fail with their fix reverted and pass with it (for the queue use-after-free and the 16-bit gradient fix, by a hand revert of the fix itself). The exception is the APU heap test: its use-after-free half cannot be reverted without breaking the test's build, and its overflow assertion cannot fail at offset 0. For example: `sizes_cover_every_mip` `left: AllocationInfo { size: 352256, alignment: 65536 }`, `release_waits_for_release_held_before_freeing_waiting_queue` "queue::release freed queue while release_held lock was held", and `float_compares_that_are_always_false_or_true` WARP "device removed". Not red-first-able: the snapshot retry and the helper-lane readfirstlane commits carry no test. Pre-existing on main and not from this PR: CI is red on every main run, both clippy steps fail (fixed by #409), and on an RX 9070 XT (RDNA 4) `emit::size_tests::the_record_count_of_a_structured_buffer_read_by_index` crashes the shader test process with an access violation (base and head alike, which ends `cargo test --workspace` early). That is the RDNA 4 compiler crash #55 addresses: on #55's head (whose base is the same 126acb35) the test passes on this card. Not verified: in-game behaviour (no game runs) and the layout change in game. AI-assisted (build, tests, red-first, the three fix-ups); the code of the 14 is the original authors'. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
heap_bytes_retains_allocation_across_apu_free (from "HLE/audio: refcount APU
heap allocations in heap_bytes to prevent UAF on ApuFree") was the one test
in modules::audio that allocates APU heap memory without holding
CONTEXT_TESTS. After its ApuFree it asserts that the freed APU address maps
to nothing, but a test running in parallel could allocate that same address
in between, and the assertion failed: once in eight `cargo test -p
victory-hle --lib` runs here, and in a parallel `cargo test --workspace` run
on klbf-lab beta. The CI jobs run tests in parallel. Now it takes the lock
like the other ApuAlloc tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
78381eee added a helper-lane select after first_lane(), which already makes
a helper lane read its own value unless VICTORY_HELPER_OWN=0 (upstream #908,
and the shader cache keys on that switch). The new select ignored the switch,
so =0 still made helper lanes read their own value under a key that says it
does not. Now both follow it; the new select still covers the two-host-wave
exchange path, where first_lane's result can come from the other half.

(cherry picked from commit ce2ce632c04ae0e9b4a8d31e86b4f35a1b10a132)
TRANSLATOR_VERSION 1 -> 2. Five commits of this series change what the
translator makes ("a helper lane's v_readfirstlane reads its own value",
"always-false and always-true float compares lower as constants", "pack
16-bit gradients ... image_sample_*_g16", "keep annotateHandle local to its
block", "export target 16 is pos4"). TRANSLATOR_VERSION's own comment asks
for a bump with any change of a shader's translation; without it, installs
keep serving the old translations from the shader cache (raised in review
of avatarmanz/VIctory-7900XTX#460). Adapted from zocram4cc/victory-linux-perf
774e5221 (4 -> 5 there).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:27:28 +00:00
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/469/head:github-bot/gh-469'
git switch 'github-bot/gh-469'

Merge

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