Skip to content

Run pixel shader wave operations over helper lanes, as the console does - #2373

Open
Vyto-Line wants to merge 1 commit into
Marvisak:mainfrom
Vyto-Line:helper-lane-waves
Open

Vyto-Line wants to merge 1 commit into
Marvisak:mainfrom
Vyto-Line:helper-lane-waves

Conversation

@Vyto-Line

Copy link
Copy Markdown

The console's wave operations include a pixel shader's helper lanes; the host's leave them out. A loop that serves one lane's value per pass (v_readfirstlane, then the lanes with that value) never serves a helper lane whose value no live lane shares, and a loop over a range taken from a whole-wave min/max gives a helper lane an unreliable range. Such a lane runs to the loop limit; on an RTX 3080 that made single draws of Grand Theft Auto VI's world (PS_VehicleLiveryOff..., PS_Textured_Eight) take longer than the driver allows, which reset the GPU. Each was found with every draw and dispatch made to finish before the next.

Where the host runs shader model 6.7, pixel shaders with wave operations are now emitted as 6.7 with the entry attribute
"waveops-include-helper-lanes" (DXC's [WaveOpsIncludeHelperLanes]); the attribute group is written only into modules that use it, so other shaders' bytes are unchanged. Without 6.7, v_readfirstlane in a pixel shader gives a helper lane its own value: what the console gives it on the pass that serves it.

The setting is part of the translation, so the shader cache keys on it. The RTX 3080 reports 6.7; all of the title's vertex and pixel pipelines build with it. With it, the vehicle draw no longer hangs; another draw (MSR_VS_CascadeShadows_drawskinned) still does.

The console's wave operations include a pixel shader's helper lanes; the
host's leave them out. A loop that serves one lane's value per pass
(v_readfirstlane, then the lanes with that value) never serves a helper
lane whose value no live lane shares, and a loop over a range taken
from a whole-wave min/max gives a helper lane an unreliable range. Such
a lane runs to the loop limit; on an RTX 3080 that made single draws of
Grand Theft Auto VI's world (PS_VehicleLiveryOff..., PS_Textured_Eight)
take longer than the driver allows, which reset the GPU. Each was found
with every draw and dispatch made to finish before the next.

Where the host runs shader model 6.7, pixel shaders with wave operations
are now emitted as 6.7 with the entry attribute
"waveops-include-helper-lanes" (DXC's [WaveOpsIncludeHelperLanes]); the
attribute group is written only into modules that use it, so other
shaders' bytes are unchanged. Without 6.7, v_readfirstlane in a pixel
shader gives a helper lane its own value: what the console gives it on
the pass that serves it.

The setting is part of the translation, so the shader cache keys on it.
The RTX 3080 reports 6.7; all of the title's vertex and pixel pipelines
build with it. With it, the vehicle draw no longer hangs; another draw
(MSR_VS_CascadeShadows_drawskinned) still does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Melow-code Melow-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two points block this PR. Two points are questions. One point is context.

Blocking: the cache key freezes a value that can be set later

build() builds the key once in a OnceLock. The key now includes helper_lane_waves(). set_helper_lane_waves() runs in Host::create(), after D3D12CreateDevice. Nothing makes create() run before the first build(). If build() runs first, the key freezes with helper_lane_waves() == false. The cache then serves 6.6 translations on a 6.7 host, or the reverse. This is the same OnceLock race that PR #2369 addresses. Fix: set the value before the first key is built, or read the value when the key is used, not when it is frozen.

Blocking: no test

The PR adds 107 lines and no test. Nothing covers the DXIL group-5 attribute (waveops-include-helper-lanes), the 6.7 header (version and shader model), or the select(isHelperLane, a, r) fallback. The repo requires a test that fails before the fix and passes after. Please add one for each change, or say why a test is not possible.

Question: set_function_attr overwrites the attribute

set_function_attr writes funcs[i].attr = Some(attr) with no check. main is created with attr = None, so this is safe today. If main ever carries another attribute, this overwrites it. Should the setter reject an already-set attribute?

Question: two call sites for set_helper_lane_waves

victory-gpu/src/host.rs::create() and victory-shader/src/emit/host.rs both call set_helper_lane_waves(). The two crates share one global AtomicBool. Could the two hosts disagree in one process? Are both call sites needed?

Context: the remaining hang is a vertex shader

The PR notes that MSR_VS_CascadeShadows_drawskinned still hangs. That is a vertex shader, outside this pixel-only fix. This is context, not a defect in this PR.

Assisted-by: DeepSeek V4 Pro (OpenCode)
Generated with Claude Code

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR conflicts with current main (940d32f) in crates/victory-gpu/src/shader_cache.rs and crates/victory-shader/src/emit/lower.rs. Its content will be reviewed once it is rebased.


Generated by Claude Code

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helper-lane wave operations gated on SM 6.7 (CheckFeatureSupport), mergeable=False against main 940d32f — needs a rebase. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Note SM 6.7 requires Agility SDK 1.7x — ties to #2383.

@YaBulochka

Copy link
Copy Markdown

Regression data point on the full retail dump: this PR gains 808 programs but loses 3,002, so the net is -2,194 validated.

Method: victory translate shaders.rpf --validate --list, Linux/Wine, dxil.dll 1.9.2609.5, x86_64-pc-windows-gnu release.

Build validated
940d32f (baseline) 23,918
this PR 21,724

Program-by-program (comm on the sorted validated lists):

  • lost 3,002, gained 808, net -2,194;
  • every lost program I sampled now fails with emit: a scalar memory read as data - e.g. MSNC_VS_MirrorReflectionPedTransformSkinD_907647ea_Wrapped at 0x22dc, MS_VS_MirrorReflectionPedTransformDecalsD_db76baa6_Wrapped at 0x1474;
  • the lost set is dominated by MSNC_VS_* / MS_VS_* (mesh and vertex stage), not pixel.

So the helper-lane pixel work does what it says for its own stage (that is presumably the +808), but something in the same tree makes scalar memory reads fail to trace in the mesh/vertex lowering. Worth running this exact command before merging; if you want, I can also bisect the PR's commits to say which one introduces the scalar memory read as data path.

Baseline command and dump are the same as in the #1458 reports.

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 25, 2026
…lude helper lanes

In Vulkan/SPIR-V fragment shaders, OpGroupNonUniformBallot and OpGroupNonUniformShuffle exclude helper invocations, whereas OpGroupNonUniformQuadSwap and OpGroupNonUniformQuadBroadcast (core Vulkan 1.1+) include all four invocations of every 2x2 quad, helpers included.

- Lower quad-scoped pixel-shader ds_swizzle_b32 (QUAD_PERM, SWAP 1/2/3, REVERSE 2/4, BROADCAST 2/4, quad BITMASK_PERM) and pixel-shader DPP quad_perm through Gen.ps_quad_perm using OpGroupNonUniformQuadSwap / constant-index OpGroupNonUniformQuadBroadcast (eagerly stored per SHADER-529). Covers 6,141 retail PS (101,421 ds_swizzle_b32) and 2,414 retail PS (29,716 DPP quad_perm).
- Fix wave64 pixel-shader v_readfirstlane_b32 when EXEC == 0 to fall back to the first running non-helper lane (OpGroupNonUniformBallot %true -> BallotFindLSB) instead of helper lane 0 (SHADER-1016 parity).
- Audited Marvisak/VIctory#2373 (GPL-3.0): DXIL SM 6.7 [WaveOpsIncludeHelperLanes] maps to SPV_KHR_quad_control + SPV_KHR_maximal_reconvergence (not enabled on vulkan1.2 / runtime), while HEAD already has its non-SM6.7 v_readfirstlane helper-lane self-read fallback.
- Add GroupNonUniformQuadSwap/Broadcast (helper-inclusive) to tests/semantic/spirv_mini_interp.py, add tests/semantic/test_ps_quad_helper_lanes.py, update tests/semantic/test_ds_permute.py, and document the contract in docs/design.md.

Adapted from Belobug/VIctory-Belobug-AMD@03629f3f0d (Belobug, GPL-3.0); audited against Marvisak/VIctory#2373 (Vyto-Line, GPL-3.0).
@YaBulochka

Copy link
Copy Markdown

Correction to my comment above - the regression is not in this PR, and I compared against the wrong baseline.

The PR's merge-base is ffe310e, not 940d32f. Numbers on the same dump, same command:

Build validated
ffe310e (this PR's base) 21,724
this PR (58f0be9) 21,724
940d32f (current main, unrelated to this PR) 23,918

So on its own base this PR is neutral: 21,724 before, 21,724 after, same lost set (emit: a scalar memory read as data on MSNC_VS_*/MS_VS_*). The 3,002 programs I attributed to this PR were already failing at its base; something between ffe310e and 940d32f fixes them.

Apologies for the noise - the fix is to rebase the PR on current main and re-run, where the expected number is 23,918.

notquiteog added a commit to notquiteog/VIctory that referenced this pull request Nov 25, 2026
…me and shader validation (by gomeaw)

Takes the place of the adapter selection hand-ported earlier on this
branch: the pull request also makes the offline pipeline check use the
selected adapter and its wave width, wants shader model 6.6 of it, and
adds VICTORY_D3D12_ADAPTER to pick one by index or name. Kept beside it:
Host::max_wave_lanes (DexNom DexNom#16) and the shader model 6.7 query
(Marvisak Marvisak#2373). README hunk left out.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants