Skip to content

fix(kyty): select valid compute derivative groups - #321

Closed
mjnhbg3 wants to merge 1 commit into
simnJS:AnyKytyfrom
mjnhbg3:fix/kyty-compute-derivative-local-size
Closed

mjnhbg3 wants to merge 1 commit into
simnJS:AnyKytyfrom
mjnhbg3:fix/kyty-compute-derivative-local-size

Conversation

@mjnhbg3

@mjnhbg3 mjnhbg3 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What

Compute shaders that query image LOD can emit invalid SPIR-V when DerivativeGroupQuadsKHR is paired with a local size whose X or Y dimension is odd. Choose DerivativeGroupQuadsKHR for compatible final 2D workgroups and DerivativeGroupLinearKHR for other complete four-lane groups. Refuse incomplete guest groups or a group for which the device enables neither valid feature. Query and enable both Vulkan features, include them in the shader profile and cache header, and keep kyty_spirv_match able to read the previous store header. Synthetic reduced shaders cover both modes and refusal; the patch contains no title data. The Vulkan SPIR-V environment defines the workgroup requirements.

Rebased on AnyKyty ea03d75c73b65039a7acfdee424b8cb95771995b, the tip when this head was pushed.

Tested

  • On the pre-rebase 007a98c12a4 base with only the reduced shader fixture, 2×2 and 4×2 emitted validator-accepted SPIR-V, while 8×1 emitted a module rejected by spirv-val with VUID-StandaloneSpirv-DerivativeGroupQuadsKHR-10151. On the change, 2×2 and 4×2 select Quads; 8×1 selects Linear; 2×2 falls back to Linear if Quads is unavailable; wave64 on a host subgroup of 32 reshapes 8×1 to a valid 2×16 Quads layout; 1×1, 3×1, and 8×1 without Linear refuse explicitly. The emitted modules pass spirv-val.
  • Windows 11 Pro build 26200: the focused recompiler and shader-profile CTests passed 3/3. kyty_spirv_match passed 1/1, including the immediately previous store-header fixture. vulkaninfo reports both compute derivative features on Intel(R) Graphics, driver 32.0.101.8331.
  • On the same Intel GPU, the exact rebased base ea03d75c73b and the rebased change each passed kyty_shim_cross_queue_label_order and kyty_shim_recompiler_valid_spirv 2/2 with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, and VK_LOADER_DEBUG=layer. Both logs show Insert instance layer "VK_LAYER_KHRONOS_validation" from SDK 1.4.350, no missing-layer warning, and zero VUID- errors. The pre-rebase base and change passed the same pair with the same validation result.
  • Ubuntu 24.04 WSL2, GCC 14 and LLVM 21: rebased focused release targets built and focused CTests passed 3/3. No physical Vulkan GPU was used in the Linux run.
  • The rebased Linux Kyty CI job passed 115 tests. Its PGO warning matches the exact-base Linux Kyty CI log byte for byte after removing timestamps: 423 functions losing profile counts, 18.95% of profile weight, and four of the ten hottest.
  • The rebased Windows Kyty CI job passed 104 shim tests and the replay tool tests, with no CI warning or error lines. Linux ASan, Linux TSan, relinker fuzzers, conventions, and portability jobs passed. The rebased lavapipe job passed 95 tests with no VUID- lines, and its offline summary passed. The pre-rebase lavapipe job stopped during Ubuntu package installation, before compilation or tests, when the security mirror returned HTTP 404 for two libasound2 packages; the rerun was denied with HTTP 403 for this contributor account.
  • Genuine PGO advisory fixtures 7/7, relinker warning fixtures 9/9, and Kyty settings fixtures 19/19 passed. All 87 live KYTY_* settings are documented.
  • tools/check_conventions.py --base origin/AnyKyty, tools/check_kyty_settings.py, tools/debt_fold.py --check, git diff --check, and tools/pr_overlap.py --branch fix/kyty-compute-derivative-local-size passed. The requested origin/main convention check could not run because this fork has no main branch.
  • No console or title run was available. The synthetic Linear shader was validated as SPIR-V; no Linear pipeline was dispatched on a GPU. No speed claim is made.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Intel(R) Graphics, driver 32.0.101.8331, Windows 11 Pro build 26200
  • AI-assisted: yes

@simnJS

simnJS commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thanks, the diagnosis is right: DerivativeGroupQuadsKHR with an odd local X or Y is invalid SPIR-V, and the 2×2 and 4×2 fixtures are a good guard.

Before merging, one change on the fix itself. Refusing the shader means the dispatch never runs, while an 8×1 workgroup is perfectly valid on the console. In a compute wave, the console forms derivative quads from four consecutive lanes, not from a 2×2 block of local IDs. That is what DerivativeGroupLinearKHR describes: quads of four consecutive invocations, valid whenever the workgroup size is a multiple of 4 (8×1 is). So:

  1. When the final local size is not 2×2-compatible but its total is a multiple of 4, emit DerivativeGroupLinearKHR instead of refusing. It needs computeDerivativeGroupLinear; today the device setup only checks computeDerivativeGroupQuads (vulkanWindow.cpp), so read and enable the linear feature too.
  2. Refuse only when neither mode is valid (total not a multiple of 4), or when the device lacks the needed feature.
  3. Turn the 8×1 refusal fixture into a case that must emit validator-accepted SPIR-V with the linear mode, and keep a refusal fixture for an odd total such as 3×1.

It would also be worth checking whether linear is the better mode for every compute shader, since it matches the hardware lane order; that can be a separate PR.

@simnJS simnJS added bug Something isn't working area: shaders Shader recompiler, SPIR-V, pipeline creation and compile stalls medium A few days of work; needs some knowledge of the code labels Nov 26, 2026
@mjnhbg3
mjnhbg3 force-pushed the fix/kyty-compute-derivative-local-size branch from 06e5d83 to 52ad1ff Compare November 26, 2026 11:11
@mjnhbg3 mjnhbg3 changed the title fix(kyty): refuse odd compute derivative workgroups fix(kyty): select valid compute derivative groups Nov 26, 2026
@mjnhbg3
mjnhbg3 force-pushed the fix/kyty-compute-derivative-local-size branch from 52ad1ff to 7924d81 Compare November 26, 2026 11:35
@simnJS

simnJS commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Merged into AnyKyty (your commit, cherry-picked onto the current head; all checks were green). This is the fix I hoped for: Quads where the layout allows it, Linear for other four-lane groups, a refusal only when neither is valid, and both features in the profile. Thanks @mjnhbg3.

@simnJS simnJS closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: shaders Shader recompiler, SPIR-V, pipeline creation and compile stalls bug Something isn't working medium A few days of work; needs some knowledge of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants