Skip to content

feat(recompiler): add WGSL with native cache compatibility - #341

Draft
Thimo188 wants to merge 14 commits into
mainfrom
upstream-pr/16391
Draft

Thimo188 wants to merge 14 commits into
mainfrom
upstream-pr/16391

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#16391, originally opened by SteelCrab.

Source commit: 6f9c4ff1d06ea0704866c80a22742e9e8fb1d884. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Add a WGSL backend and anyps5-wgsl tools for WebGPU while preserving main's native cache keys, SPIR-V and disk-cache encoding. WGSL requests use distinct keys. Production compiler source-version stamps still change when compiler sources change.

This is the WGSL prerequisite of boykopovar#6879, replacing closed boykopovar#9094. The relinker fix boykopovar#10017 and Emscripten library portability boykopovar#11341 have merged. Unsupported WGSL cases are recorded in docs/dev/debt/changes/wgsl-native-cache.md. wasm-aot and runtime delivery remain separate follow-ups.

Main 75b480e9c78ea1f13a7079f8f8457b990ea9f28d was merged on 2026-12-01, preserving the reviewed commits and bringing in the upstream macOS replay fix dde92d5b17. The native target fields remain before the WGSL-only key suffix, with main's NaN-failure checks and native serialization. The existing fixture references passed on the refreshed main.

The cache-key review is addressed by including all WGSL emission inputs in WgslSource::Module's key. The key records input presence, compute workgroup and LDS sizes, pixel render-target modes and interpolation settings, and vertex embedded-fetch and clip-space settings. Float fields use their bit patterns. Existing specialization constant/binding keys are preserved, and requests with the same input values still reuse modules. This is confined to the WGSL module cache.

Tested

Ubuntu 26.04.1 x86-64, GCC 15.2, Node 22.22.1 and Chromium 151.0.7922.34; baseline main 75b480e9c78ea1f13a7079f8f8457b990ea9f28d, tested head 6f9c4ff1d06ea0704866c80a22742e9e8fb1d884.

  • Negative control: the new cache tests on the reviewed code 48938a5a32 failed with integer render target: reused stale WGSL module when changing a pixel shader from float to integer output with identical constants and bindings. On the corrected head the tests pass for pixel render-target type, interpolation slot/mode/default and custom mask, vertex embedded fetch and clip-space transform (including +0/-0), compute workgroup dimensions and LDS size, missing/unsupported inputs, repeated identical inputs and restored inputs. Equal input values at different addresses also reuse the module.
  • Independent Release shader-tools builds passed. Main's shader_native_snapshot passed 1/1; the change's shader_native_snapshot and wgsl_native_compat passed 2/2. Three public compute fixtures produced 9/9 byte-identical native files: cache keys, SPIR-V and encoded artifacts. Native-to-WGSL-to-native cache reuse and separate target keys passed.
  • The same external qualification harness, linked independently against each tree, created 3/3 native Vulkan compute pipelines on main and 3/3 on the change. It also built and ran the respective trees' existing shader_cache_file_read, shader_cache_native_paths and request_serializer tests: the four CTests passed 4/4 on each tree. Two Windows-only Python subcases skipped on each Linux run.
  • Both trees used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer with verbose CTest, on the same Mesa lavapipe / llvmpipe device (vendor 10005, LLVM 21.1.8, Mesa 26.0.8-1ubuntu0.3). Both native Vulkan logs confirm validation-layer insertion, with 0 VUID errors and no missing-layer diagnostic. The installed validation layer is 1.4.341, newer than pinned Vulkan headers 1.4.335. Snapshot and cache tests themselves are CPU-only.
  • Chromium WebGPU created 3/3 WGSL compute pipelines; malformed WGSL was rejected with shader 0:. The checker selects Chromium's SwiftShader backend. The browser check used the four validation variables above; its log confirms layer insertion, without missing-layer or VUID diagnostics. Runtime format placeholders were set to representative values. This checks pipeline creation, not shader dispatch results.
  • The previous head e71ac2f18e passed the full native libs build, including the production shader recompiler, AGC driver and NID patching, from recorded submodule source. Configuration: Release, BUILD_TESTING=ON, ANYPS5_USE_SYSTEM_DEPS=OFF, ANYPS5_ENABLE_SPIRV_TOOLS=OFF. That full project build also passed shader_cache_file_read, shader_cache_native_paths and request_serializer 3/3 with the four validation variables above; the same two Windows-only Python subcases skipped. This is not the complete product/runtime CTest suite.
  • Local code Conventions and the PR diff whitespace check passed. The independent Windows report covers historical head 2125187a95. Full product runtime suites, title execution, vertex/pixel WGSL pipeline validation and physical GPU testing have not run.

CI claim ownership:

Claim Workflow / job
Independent native builds, nine-file comparison, cache reuse, stage-input cache regression cases, three browser compute pipelines, invalid-WGSL rejection and validation-log checks WGSL backend / native-compatibility-and-wgsl
Full native libraries and existing runtime/cache tests on the PR merged into current main Maintainer-dispatched Build / linux and windows
Repository and PR-template rules Conventions / conventions
Replay-process cleanup regression on macOS Build / relinker (macos-latest, clang++)

The dedicated WGSL job tests the submitted head against its shared ancestor with main. The Build workflow tests the current merge. The external native Vulkan qualification is local evidence. The checker uses Node built-ins and Chromium with no new third-party source or Cargo packages.

The previous macOS relinker job failed frame_capture_minimize_replay when killpg(pid, 0) returned EPERM during process-group shutdown. The upstream fix retries that macOS condition within the existing timeout while still requiring the group to disappear. It adds regression tests covering both temporary and persistent errors. On Linux, the updated 22-case replay suite passed on main and prior head 48938a5a32 with 6 platform-specific cases skipped. On main's macOS runner, the replay test passed on the first attempt and the suite passed 1,026/1,026.

On head 48938a5a32, the macOS relinker job passed 1,026/1,026. The previously failing replay test passed on the first attempt. The WGSL job, Conventions, Linux relinker and relinker ASan also passed. The automatic Windows build and tests and Windows relinker jobs passed. The automatic full Linux job was skipped and requires separate maintainer dispatch.

Current head 6f9c4ff1d06 passed local validation above and the WGSL backend job. Its log identifies the pinned baseline and exact candidate, passes the new pixel/vertex/compute cache regression, compares all nine native outputs, and creates 3/3 WebGPU compute pipelines. Conventions, macOS relinker, Linux relinker, Windows relinker and relinker ASan passed. The automatic Windows job passed. The full Linux job was skipped and requires maintainer dispatch.

Landing order and overlap:

Checklist

@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

2 participants