Carry 20 upstream VIctory fixes (shaders, samplers, textures) and a mesh wave-ops flag fix #142

Open
github-bot wants to merge 22 commits from github-bot/gh-142 into main AGit
Owner

@⁠YisusOnDev on GitHub · 2026-11-25 16:32 UTC · original
YisusOnDev:upstream-carry → main · +1753 −112 · 23 files · 22 commits · open

Carries 20 commits from upstream Marvisak/VIctory that this fork does not have yet, plus two fixes needed to make them build and test here. All of them are small fixes to shaders, samplers, textures and pipelines.

A full git merge upstream/main gave about 450 conflicts, so these were cherry-picked one by one, with -x to keep the upstream hash. The upstream changes to memory copies (cd94d35, 940d32f, ed0dbfd) and the pipeline pre-build (c47b529, 9c58a1c) are left out, because the fork's shadow.rs and host.rs have diverged too far for a clean pick.

Commits:

  • GPU: copy into title memory without asking for its region first
  • GPU: fix CreateSamplerX mip-none base level, LOD range, bias clamp, and invalid enum values
  • Inline uniform micro-tile runs in texture copies
  • Shaders: reuse lane guards for unchanged EXEC within a block
  • fix(pipeline): retry collisions when creating cache staging files
  • Formats: share immutable texture swizzle tables
  • GPU: pipelines of different names load from the library at the same time
  • Shaders: fold conditional branches to their fallthrough
  • Shaders: compress replaced phi chains in remove_trivial_phis
  • GPU: keep A8_UNORM out of the R8 typeless family
  • Shaders: preserve mip point filtering in anisotropic static samplers
  • GPU: honor anisotropic point-mip device support
  • GPU list: bind initial pipeline state in create_list and create_list_x
  • Shaders: fold empty loop latches containing only dead phis
  • Shaders: precompute MD5 round constants and avoid per-block Vec in md5_block
  • Shaders: key immediate sampler slots by descriptor words and comparison mode
  • Shaders: GFX10 FLAT offsets ignore bit 11
  • victory-shader: mask mesh primitive vertex indices to 9 bits (drop edge flags)
  • Shaders: gate anisotropic point-mip host filters
  • Tests of the picked upstream commits use the fork's signatures
  • Mesh lanes from the thread id declare no wave ops; GPU tests share one lock
  • GPU: align appended input-element offsets like D3D12

Notes:

  • Mesh shader fix (Mesh lanes from the thread id declare no wave ops). Mesh programs that read their lane index from the thread id declared WAVE_OPS without using any wave operation, and the DXIL validator rejects that. The new upstream mesh test found it.
  • GPU: align appended input-element offsets like D3D12. Its one conflict, in pipeline/host.rs, was resolved by keeping both test modules: the fork's integer-blend tests and upstream's input-offset tests.
  • One test in victory-shader and victory-gpu adapts the picked tests to the fork's function signatures.

Testing, on an RX 9070 XT with Windows 11:

  • cargo build --profile diag -p victory --features diagnostics builds.
  • cargo test --release -p victory-shader -p victory-gpu -p victory-formats: all pass except list::tests::lists_are_cut_at_waits_that_follow_work, which fails the same way on this fork's main (f870d80) without these commits. cargo fmt --check also fails on main already.
  • In game, the intro cutscene and the first cell scene render correctly (lit, textured, other inmates visible). Frame time there was ~250–273 ms, against ~340 ms measured before rebasing on this fork's newer main. Most of that gain comes from main itself (PR #18 and others), not from these picks.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XT2tTx3gzfkPGgizfErPrL

**@⁠YisusOnDev** on GitHub · 2026-11-25 16:32 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/142) `YisusOnDev:upstream-carry` → `main` · +1753 −112 · 23 files · 22 commits · open Carries 20 commits from upstream Marvisak/VIctory that this fork does not have yet, plus two fixes needed to make them build and test here. All of them are small fixes to shaders, samplers, textures and pipelines. A full `git merge upstream/main` gave about 450 conflicts, so these were cherry-picked one by one, with `-x` to keep the upstream hash. The upstream changes to memory copies (cd94d35, 940d32f, ed0dbfd) and the pipeline pre-build (c47b529, 9c58a1c) are left out, because the fork's `shadow.rs` and `host.rs` have diverged too far for a clean pick. Commits: - GPU: copy into title memory without asking for its region first - GPU: fix CreateSamplerX mip-none base level, LOD range, bias clamp, and invalid enum values - Inline uniform micro-tile runs in texture copies - Shaders: reuse lane guards for unchanged EXEC within a block - fix(pipeline): retry collisions when creating cache staging files - Formats: share immutable texture swizzle tables - GPU: pipelines of different names load from the library at the same time - Shaders: fold conditional branches to their fallthrough - Shaders: compress replaced phi chains in remove_trivial_phis - GPU: keep A8_UNORM out of the R8 typeless family - Shaders: preserve mip point filtering in anisotropic static samplers - GPU: honor anisotropic point-mip device support - GPU list: bind initial pipeline state in create_list and create_list_x - Shaders: fold empty loop latches containing only dead phis - Shaders: precompute MD5 round constants and avoid per-block Vec in md5_block - Shaders: key immediate sampler slots by descriptor words and comparison mode - Shaders: GFX10 FLAT offsets ignore bit 11 - victory-shader: mask mesh primitive vertex indices to 9 bits (drop edge flags) - Shaders: gate anisotropic point-mip host filters - Tests of the picked upstream commits use the fork's signatures - Mesh lanes from the thread id declare no wave ops; GPU tests share one lock - GPU: align appended input-element offsets like D3D12 Notes: - **Mesh shader fix (`Mesh lanes from the thread id declare no wave ops`).** Mesh programs that read their lane index from the thread id declared `WAVE_OPS` without using any wave operation, and the DXIL validator rejects that. The new upstream mesh test found it. - **`GPU: align appended input-element offsets like D3D12`.** Its one conflict, in `pipeline/host.rs`, was resolved by keeping both test modules: the fork's integer-blend tests and upstream's input-offset tests. - **One test** in `victory-shader` and `victory-gpu` adapts the picked tests to the fork's function signatures. Testing, on an RX 9070 XT with Windows 11: - `cargo build --profile diag -p victory --features diagnostics` builds. - `cargo test --release -p victory-shader -p victory-gpu -p victory-formats`: all pass except `list::tests::lists_are_cut_at_waits_that_follow_work`, which fails the same way on this fork's `main` (f870d80) without these commits. `cargo fmt --check` also fails on `main` already. - In game, the intro cutscene and the first cell scene render correctly (lit, textured, other inmates visible). Frame time there was ~250–273 ms, against ~340 ms measured before rebasing on this fork's newer `main`. Most of that gain comes from `main` itself (PR #18 and others), not from these picks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XT2tTx3gzfkPGgizfErPrL
Two copies into title memory asked the host about the destination before
every copy. copy_mapped's own comment tells what that costs: asking
VirtualQuery about the source took about 2 ms per copy in the title's big
pools, because the query walks the page tables to the end of the region
with the same state, whatever the size of the copy.

- A list's copy into title memory checked that the whole destination was
  committed first, with VirtualQuery. The destinations were private pools
  of about 600 MiB.
- The copy-back of what shaders wrote used WriteProcessMemory, which asks
  for the destination's region before it writes: the same walk for every
  64 KiB piece.

Both now rely on the kernel copy the other copies already use
(ReadProcessMemory on our own process). It fails on a destination page
that is not mapped writable as it does on a source page it cannot read,
without faulting. A title destination is asked for its region only after
its copy has failed, which keeps the page retries (they write their zeros
themselves) off unmapped memory. write_mapped does what it did: mapped
pages are written, unmapped and read-only ones are not.

One difference: a title destination that was not all mapped used to be
left alone, and the bytes before its first unmapped page may now arrive
(the kernel copy stops at that page). No title copy of the run below had
such a destination, and none failed.

Measured in the world (first mission's intro; i7-13650HX, RTX 4060
Laptop, diagnostics build), with the old and the new call timed on the
same copies of one run, 41 frames of about 1.15 s each:

  title copies, 80 per frame (0.45 MB): the check alone 59.5 ms per
  frame; the whole copy now 0.56 ms
  copy-back, 110 pieces per frame (4.9 MB): 38.6 ms per frame; now
  0.55 ms

That is 98 ms of a frame (8.6 %) down to about 1 ms. In stacks of the
submitting thread sampled at 10 Hz, VirtualQuery under these two calls
was 47 of 462 samples before and 0 of 189 after.

Two tests run both copies against reserved memory with a committed block
on each side of a hole (no GPU, no game data).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
(cherry picked from commit b58d198d954e63f3aa7e2a8e856bf70fbb0af291)
(cherry picked from commit 36ce003f3187b718ce4574306d406e5956c39dbe)
(cherry picked from commit e6fe8ecbf83e763e18e1abdcbccd7332e97c4ef1)
(cherry picked from commit 3df7309f20cdb63ecb4073b80b4edb79815a7c40)
(cherry picked from commit 705a2f634d1c3ada825922a6a1c5befca15d599b)
(cherry picked from commit f8feea9cc4a20665a609269160bc4b57c4436ba3)
An instruction guard depends on its EXEC and the reachability of its block. Keep the most recent result, including an elided guard, rather than repeating the same BDD queries for consecutive vector instructions. Scalar instructions still bypass guard selection.

Cover EXEC changes across and within a branch with a synthetic shader. Add a CPU-only guard_runs benchmark for unmasked, short, and long masked runs.

(cherry picked from commit 81b81df351437c50f4321286c725de51664c7b1b)
(cherry picked from commit 688b844ed40d3d01fc1154a2e16503fae3011197)
Preserve stale staging files left by interrupted writers and retry a bounded number of atomic create_new attempts. Propagate unrelated I/O errors immediately. Add deterministic CPU regressions. AI-assisted.

(cherry picked from commit a32eacdd5e0f2e55b5c0cddeb0d44d5fa93f9bb9)
(cherry picked from commit ceb364e6efa221552f1150468bba131f995e6d1d)
Co-Authored-By: GPT 6.2 Sol <[email protected]>
(cherry picked from commit 64b80c310941c8c105c9ac78fe4c29004f5e88a4)
(cherry picked from commit 63e833aa2f7a1aadca943e181ccc26cda074d96c)
The pipeline workers held the library's lock while a pipeline loaded. A
load is not always a lookup: an AMD driver's library holds about 140 bytes
per pipeline, and what the driver's own cache lacks is compiled inside the
load, for up to seconds. All eight workers then waited for the one that
held the lock.

The library is documented as thread-safe but for loads of one pipeline on
several threads (ID3D12Device1::CreatePipelineLibrary, "Thread Safety"),
so only those exclude each other now: a name is held by one thread at a
time, and loads run without the library's lock. Stores and serialising
keep it.

Measured on an RX 6800 and a Ryzen 9 5900X (sampled stacks, diagnostics
build, the same start from a kept pipeline library):
- worker CPU while a backlog is made: 1.05 cores -> 7.8; samples blocked on
  the lock: 481 -> 0
- in the world, two runs each: pipelines still being made 1219-1315 -> 43-54,
  draws run per frame 3-20 -> 1860-2086, time per frame outside preparing,
  GPU and copy-back 196-303 ms -> 24-37 ms

The frame itself is not shorter on its own: the draws that used to be
dropped now run (750-799 -> 1090-1379 ms per frame).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit f821cb9d7550180d7fb1bd8f7318174e3a680041)
(cherry picked from commit 623245a01d8445230ca9291207fc61f7dfc26e3f)
(cherry picked from commit 1ed26e50d860f328cd42c640bc12486f65603995)
(cherry picked from commit 09618374c17a3b0f82c07e884e776b8973f971eb)
(cherry picked from commit 5c44562868df4c33cce60488132d83cf5ff02f30)
(cherry picked from commit e579f10eda240a0fc01079fb5112a8bf7e1ac4ef)
DXGI's R8 typeless family is R8_UNORM/UINT/SNORM/SINT (formats 61..=64). The
family() table folded A8_UNORM (65) into R8_TYPELESS (60), so an R8 view of an
A8 host texture passed the family(view) != family(own) check in fits() and was
silently rewritten to A8's format. A8 cannot be cast to R8 in D3D12, so such a
view must be rejected instead. Drop 65 from the range; it now maps to itself.

(cherry picked from commit 97c8783f4a260996b602b75cabfe17568b1d1a26)
(cherry picked from commit 899e3bb8663eaec04b0c6b2db9bf60013d16966e)
(cherry picked from commit e45bacd12fd320077a5dfcd421361a51efcd8a3c)
(cherry picked from commit 1182ec505502644c0a24e53f04e421f89ed62316)
Apply the same OPTIONS19 capability check and filter fallback in the production GPU pipeline as in the shader host. Unsupported or older runtimes retain the prior linear-mip approximation instead of receiving an unsupported static-sampler filter.

Validated together with the shader-side changes: 123 all-feature shader tests passed (1 benchmark ignored), shader/GPU all-target/all-feature Clippy with warnings denied, and asset policy.

(cherry picked from commit 7dfa86fa39ec77ff12df9b44f4e0bd436442d236)
(cherry picked from commit 1a39dccdb5a96b04bd5ab1d2f08f0b71bde170ce)
(cherry picked from commit e52777af5b771e291616e5d3d462620ee696f357)
(cherry picked from commit 4c5753a97cf4996ae7e01e7dfdcdc7e55d650372)
(cherry picked from commit be3202de393b71c9385f74b587256b01b48f7f63)
(cherry picked from commit 80111d171c5c4fa718a77c29b303d63228adaaaa)
(cherry picked from commit 711d651ccab7673e5ab4365bd692294e954c845f)
(cherry picked from commit 1153d19558cabfe06c5366d5e1e77b7d5a003323)
(cherry picked from commit 2286e038cc606809869a7d7d577c470d059bc268)
(cherry picked from commit e6570b58678cd06c3e81f73f7abf0a29b593684a)
(cherry picked from commit 40f30be0b52ff0866fbdafb7944bb595ceae4e98)
(cherry picked from commit 306829ec91644524c4fd39a33acc7da748e3ca08)
(cherry picked from commit c0228d939ec1c206313f7e8cb44c922081b6f538)
(cherry picked from commit 3f46efc4eae5c4357491c39f36cee6eb7a09f5d3)
Query OPTIONS19 in the shader host and retain the previous linear-mip approximation when anisotropic point-mip filtering is unavailable. Preserve comparison/min/max reduction and LOD bounds. Add tests for supported and unsupported capabilities, all reduction modes, and unrelated filters.

Validated with 4 sampler tests, 123 all-feature shader tests (1 benchmark ignored), shader/GPU all-target/all-feature Clippy with warnings denied, and asset policy. No in-game validation claimed.

(cherry picked from commit 23fc8a55e803b5721076f59f27c019441af1f2bd)
(cherry picked from commit e3c11b48273172a8c6fe9d446c52f9a8e006c06d)
new_list takes a pipeline, resource::track no structure and emit a
target here; the mesh test takes a lock of its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XT2tTx3gzfkPGgizfErPrL
(cherry picked from commit 0c910ebd7126d7892b344a69533f64e2deeabc5c)
The lane index of a mesh program comes from its thread id, but v_mbcnt
declared wave ops anyway, which dxil.dll refuses (upstream's 9-bit mesh
index test showed it). The mesh draw test takes the VALU tests' lock, as
upstream's does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XT2tTx3gzfkPGgizfErPrL
(cherry picked from commit aff427b1a0120c8684bd58d9726b0325b6126129)
`GraphicsState::elements()` placed an element with
`D3D12_APPEND_ALIGNED_ELEMENT` right after the previous one. D3D12 (and
vkd3d) start it at the next multiple of min(4, its size), so after a 1- or
2-byte element (R8, R16, R8G8...) the offset was too small. The host
pipeline gets the title's descriptions unchanged, so only the offsets
read here were wrong: the rectangle-list expansion read the fourth
vertex's attributes from the wrong bytes.

An explicit offset near 4 GiB also overflowed the next appended offset
(a panic in debug builds); it now saturates.

Tests: `appended_elements_are_aligned` and
`a_huge_explicit_offset_does_not_overflow` fail without the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 691236d606b9de8cbccfa8540e2b27ca6070f8ae)
(cherry picked from commit 38fbcd1bec39486d15bddda7de9fcf3aaa4ab199)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:34 +00:00
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 19:52 UTC · original

Corpus data from the game's shaders.rpf on an RX 7900 XT (Windows 11 build 26300, dxil.dll 10.0.26100.0), head aadd4c8 on 01aadd1, victory translate --validate --list --host-lanes 32-64, comparing a hash of each program's DXIL with 01aadd1:

  • The DXIL of all 8,694 emitted mesh programs changes, as expected from the primitive index mask, and all of them validate. No vertex, pixel or compute program changes, and the counts are the same (VS/PS 14,247, CS 2,682, MS 8,694 of 8,765; the 71 over-budget mesh programs are still refused).
  • cargo test -p victory-shader --lib -- --test-threads=1: 279 passed, 0 failed, 6 ignored.

Pipelines were not created and the game was not run here.

**@⁠adrianmjim** on GitHub · 2026-11-25 19:52 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/142#issuecomment-7172890784) Corpus data from the game's `shaders.rpf` on an RX 7900 XT (Windows 11 build 26300, dxil.dll 10.0.26100.0), head `aadd4c8` on `01aadd1`, `victory translate --validate --list --host-lanes 32-64`, comparing a hash of each program's DXIL with `01aadd1`: - The DXIL of all 8,694 emitted mesh programs changes, as expected from the primitive index mask, and all of them validate. No vertex, pixel or compute program changes, and the counts are the same (VS/PS 14,247, CS 2,682, MS 8,694 of 8,765; the 71 over-budget mesh programs are still refused). - `cargo test -p victory-shader --lib -- --test-threads=1`: 279 passed, 0 failed, 6 ignored. Pipelines were not created and the game was not run here.
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 22:53 UTC · original

RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2 (19045), Agility SDK 1.620 (#44). PR aadd4c8 merged on a7fa35e (main + #44).

  • stub_pipeline_is_created fails in the full victory-shader run with the PR ("digest [00, ...] accepted"): 289 passed, 1 failed. It passes on the base, and with the PR it passes on its own (10 of 10) and with --test-threads=1.
  • Narrowed down by halving the test list: the trigger is the new edge_flagged_triangles_draw_as_unflagged_ones running at the same time (3 of 3 runs with only those two tests). That test holds ONE_AT_A_TIME, the stub test doesn't, and both build pipelines from constant_color() on the same adapter. Holding the same lock in the stub test would keep them apart (not tried).
  • victory-gpu in release: lists_are_cut_at_waits_that_follow_work fails with and without the PR, as you saw on the 9070 XT. The test binary also exits now and then with 0xc0000005 (2 of 5 runs on the base, 1 of 5 with the PR), so neither comes from this PR.
**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 22:53 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/142#issuecomment-7176900169) RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2 (19045), Agility SDK 1.620 (#44). PR `aadd4c8` merged on `a7fa35e` (main + #44). - `stub_pipeline_is_created` fails in the full `victory-shader` run with the PR ("digest [00, ...] accepted"): 289 passed, 1 failed. It passes on the base, and with the PR it passes on its own (10 of 10) and with `--test-threads=1`. - Narrowed down by halving the test list: the trigger is the new `edge_flagged_triangles_draw_as_unflagged_ones` running at the same time (3 of 3 runs with only those two tests). That test holds `ONE_AT_A_TIME`, the stub test doesn't, and both build pipelines from `constant_color()` on the same adapter. Holding the same lock in the stub test would keep them apart (not tried). - `victory-gpu` in release: `lists_are_cut_at_waits_that_follow_work` fails with and without the PR, as you saw on the 9070 XT. The test binary also exits now and then with 0xc0000005 (2 of 5 runs on the base, 1 of 5 with the PR), so neither comes from this 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/142/head:github-bot/gh-142'
git switch 'github-bot/gh-142'

Merge

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