Skip to content

Recompiler: VS inputs packed into one ISG1 register are members of their own (#105) - #297

Open
TG0000 wants to merge 1 commit into
ivall:mainfrom
TG0000:fix/vs-packed-isg1-inputs
Open

TG0000 wants to merge 1 commit into
ivall:mainfrom
TG0000:fix/vs-packed-isg1-inputs

Conversation

@TG0000

@TG0000 TG0000 commented Nov 23, 2026 •

Copy link
Copy Markdown

Part of #105 (item 4, "packed ISG1 vertex inputs sharing a register emit duplicate XclIn field names (a{e.register}) in Mode::Vertex").

A console vertex shader can have two input elements packed into one register, for example TEXCOORD0 in .xy and TEXCOORD1 in .zw of r1. Mode::Vertex declared float4 a1 once per element, so XclIn had the same member twice. DXC rejects that (error: duplicate member 'a1'), so the pipeline ended up with no VS. Now each packed element gets its own member, a{register}_{first}, sized to the components in its mask. Fetch-shader VGPR v[b + c] reads the element that covers component c, so TEXCOORD1.x lands in the register's z, as on the console. A component that no element covers reads 0u. An element alone in its register keeps float4 a{register}, so every other shader's HLSL stays the same.

The other leftovers of #105 are covered elsewhere: items 1 and 4 by #134 and #202, item 2 by #117 and #149 (merged), item 3 by #123 (merged). The Geometry-mode xcl_vin note in item 3 is by design in #215, which puts the pre-fetched GS vertices in window 0.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: vs_input_fields / VsInputField name the XclIn members and the component range each one covers. The Mode::Vertex struct and the VGPR initialisers use them.
  • crates/xcl/src/gpu/recomp/tests.rs:
    • vs_packed_isg1_inputs_are_members_of_their_own: checks the HLSL members and VGPR reads (masks 0x3 + 0xC, and 0x3 + 0x4 where .w is uncovered) and compiles both with DXC.
    • gpu_vs_packed_isg1_inputs: draws on the GPU with an input layout of three separate R32G32_FLOAT elements. Every pixel must be (TEXCOORD0.xy, TEXCOORD1.xy).

Tested

  • AMD Radeon RX 6800, driver 32.0.21045.29003, AMD Ryzen 9 5900X, Windows 10.0.26300, rustc 1.100.0 (stable-x86_64-pc-windows-gnu with llvm-mingw clang), debug, DXC 1.9.2609.5 (dxcompiler + dxil from the GitHub release).
  • Before the fix (the new tests on origin/main's emit.rs): both new tests FAIL. gpu_vs_packed_isg1_inputs panics with dxc: hlsl.hlsl:466:12: error: duplicate member 'a1'.
  • After the fix: vs_packed_isg1_inputs_are_members_of_their_own, gpu_vs_packed_isg1_inputs, gpu_graphics_vs_ps_draw and vs_system_values_in_isg1_registers pass on the RX 6800.
  • cargo test --workspace --exclude testgame-mw --no-fail-fast -- --test-threads=4: 651 passed, 2 failed, 40 ignored, no SKIPPED GPU tests. Both failures also fail on unmodified main with this toolchain:
    • pe::tests::parses_own_test_binary_tls: the gnu/llvm-mingw test binary has no TLS directory.
    • e2e::test_title_runs_and_game_folder_is_untouched: it needs testgame_mw.dll, and testgame-mw is excluded because it doesn't build with this toolchain.
  • cargo clippy -p xcl --all-targets: no warnings on the added lines.

Regression run
Windows 11, Ryzen 9 5900X, AMD Radeon RX 6800, Rust stable x86_64-pc-windows-msvc (VS 2022 Build Tools, link.exe), cargo build --release -p xcl, scripts/smoke.ps1 -Seconds 45, one run at a time under a RAM watchdog.

main (a6f5f7a, current origin/main, this PR's base):

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 828 (PresentX 828)
presents per 2 s (last 3): 59 60 60
device removals: 0
crashes: 0
peak commit: 15144 MB

PR (head commit, no local changes):

xcl-smoke v1
commit: 34f1386939d5ae50cb17fe30ba4570beb4d5818f
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 728 (PresentX 728)
presents per 2 s (last 3): 54 55 53
device removals: 0
crashes: 0
peak commit: 15154 MB

No regression: 728 frames against 828 on its base, no device removals or crashes, peak commit 15154 MB against 15144 MB. Frame counts move by about 10 % between runs of the same commit on this machine (earlier runs of main gave 843, 709 and 828).

Rebased onto current main (a6f5f7a): the one conflict, in gpu/recomp/tests.rs, is resolved by keeping both tests. On the rebased head, built with stable-x86_64-pc-windows-msvc, cargo test -p xcl --lib recomp passes: 184 passed, 0 failed, 18 ignored, including vs_packed_isg1_inputs_are_members_of_their_own and gpu_vs_packed_isg1_inputs on the RX 6800.

Not tested

  • Whether a retail title has VS signatures with packed inputs: the regression run above shows no regression but doesn't count them.
  • NVIDIA, Intel and RDNA4 GPUs, and the split-wave64 / wave32-only path (the GPU test uses runner::options, which picks it on such adapters).

AI use

  • Claude Code with Claude Opus 5.5 picked the sub-item, wrote the change and the tests, ran the builds and tests on the RX 6800, and wrote this description.

🤖 Generated with Claude Code

@ethandepstein-del

Copy link
Copy Markdown

Independent static code audit of a5b78258d (code inspection only — cargo test not run on macOS; no game files):

Summary: Looks clean

  • For contiguous packed ISG1 masks (.xy + .zw, single-component .z, etc.), emitting a{register}_{first} sized to count = 32 - mask.leading_zeros() - first avoids duplicate XclIn member names and maps fetch-shader VGPRs input_vgpr + c to xi.a{reg}_{first}[c - first], leaving uncovered components 0u.

Minor defensive edge cases (emit.rs:vs_input_fields)

  • Non-contiguous masks: If two elements in the same register ever had interleaved masks (e.g. 0b0101 and 0b0010), first..first + count spans the gap and could shadow the second element in find_map. Checking (f.elem.mask >> c) & 1 != 0 prevents misattribution.
  • Zero mask: If two elements sharing a register both had mask == 0, .max(1) forces first = 0 on both, recreating a duplicate a{reg}_0 member name.

(AI-assisted)

@likecrank-dotcom

Copy link
Copy Markdown

Independent native Windows/MSVC + NVIDIA validation at a5b78258dad506fdb60e377bcecdccd7f754514a.

Tested

  • Ryzen 5 3600, RTX 5060 Ti, NVIDIA 621.14 / 32.0.16.2114; Windows 11 Pro 10.0.26300, 32 GB RAM; Rust 1.100.0 MSVC, MSVC 19.44, SDK 10.0.26100.0, DXC 1.9.2602.17; debug build.
  • cargo build --workspace: exit 0. cargo test --workspace -- --test-threads=4 --nocapture: 653 passed, 0 failed, 40 ignored (lib: 613/0/20). Both new packed-input tests, parses_own_test_binary_tls, and the synthetic-title end-to-end test pass on MSVC/NVIDIA.
  • Negative control, same new tests on main@0e946cf with unchanged runtime: cargo test -p xcl --lib packed_isg1_inputs -- --nocapture --test-threads=1: 0 passed, 2 failed, exit 101. GPU case reports DXC duplicate member 'a1'; the source-structure case fails its new-member assertion.

Additional measured interleaved-mask case and fix
With TEXCOORD0.xz (mask 0x5) and TEXCOORD1.y (mask 0x2) sharing r1, a synthetic GPU draw adapted from this PR's test produced pixel [0.25, -0.4, 0.75, 0] instead of [0.25, 0.5, 0.75, 0] on this head (1 failed, exit 101). Selecting a field by its actual component mask instead of its first-to-last span fixes the draw (1 passed, exit 0). Unshared register inputs still retain all four components.

The fix and GPU regression are in #309, stacked on this PR; your implementation and authorship are preserved in the first commit. Its clean head a039d336837920a2bdbf028ff207b4cab3181916 passes the whole suite: 654 passed, 0 failed, 40 ignored. Draft pending retail regression runs. No claim that a retail shader uses this synthetic layout.

SKIPPED / Not tested
Four explicit skips in both full suites: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64); test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll); uploads_start_from_each_subresources_state (no D3D12 debug layer). No XCL_SAMPLE variables, retail title/smoke run, AMD/Intel/Wine or debug-layer verification. The zero-mask edge case remains outside this fix. The existing fetch_update deprecation warning remains.

AI use
Codex ran the commands, adapted the synthetic GPU regression, wrote the follow-up fix and summarized actual logs. Exact deployed model identifier is not exposed in this session.

…eir own (ivall#105)

A console vertex shader whose input signature packs two elements into one register
(TEXCOORD0 in .xy and TEXCOORD1 in .zw of r1) declared `float4 a1` once per element in
`XclIn`: a member declared twice, which DXC rejects (duplicate member 'a1'), so the
pipeline had no VS. Each packed element now gets its own member, `a{register}_{first}`,
with the components of its mask; the fetch-shader VGPRs v[b + c] read the element that
covers component c (TEXCOORD1.x in the register's z), and a component no element covers
reads 0. An element alone in its register keeps `a{register}` as a 4-vector, so the HLSL
of every other shader is unchanged.

Tests: vs_packed_isg1_inputs_are_members_of_their_own (HLSL, DXC compile) and
gpu_vs_packed_isg1_inputs (draw on the GPU with an input layout of separate R32G32
elements).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TG0000
TG0000 force-pushed the fix/vs-packed-isg1-inputs branch from a5b7825 to 34f1386 Compare November 24, 2026 00:19
@thehollowedone

thehollowedone commented Nov 24, 2026 •

Copy link
Copy Markdown

Tested

  • Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (NVIDIA 621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11, debug. Commit 34f13869
  • cargo build --locked --workspace passed. cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture exited 0. Cargo reported 678 passed, 0 failed and 41 ignored.
  • Four tests counted as passes by Cargo reported runtime skips. gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware require wave64. test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state require the D3D12 debug layer.
  • Both packed-input tests ran in the workspace suite and passed, including the synthetic GPU draw and DXC compilation check. The focused packed_isg1_inputs run also passed both tests with zero skips.

Not tested

AMD and retail titles on this machine. The author reports separate RX 6800 tests and retail smoke results at the same head. Author’s results

AI use

Codex with GPT-6.2 Sol ran the tests and drafted this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants