Skip to content

shaders: two kinds of invalid SPIR-V the recompiler fuzzer still finds #209

Open

Description

@simnJS

Context

The Kyty shader recompiler has a libFuzzer target, kyty_shader_recompiler_fuzzer. With KYTY_FUZZ_SPIRV set, its harness runs spirv-val (Vulkan 1.3) on every module the recompiler produces. Earlier rounds found decoder over-reads, a use after free and several kinds of invalid SPIR-V, all fixed and locked by kyty_shim_recompiler_robustness and kyty_shim_recompiler_valid_spirv. Two kinds of invalid modules are still produced:

  1. a call graph that the execution model does not allow (spirv-val: "callgraph contains function … which cannot be used with the current execution model");
  2. atomic operations (OpAtomicLoad, OpAtomicUMin, OpAtomicUMax) on a storage class that Vulkan does not allow for them (VUID-StandaloneSpirv-None-…), seen on vertex, compute and pixel shaders.

A driver may crash or miscompile on an invalid module, so the recompiler must either produce a valid one or refuse the shader with a clear reason.

How to reproduce

Linux, with the Kyty core's Clang and AddressSanitizer:

cmake -S . -B build-fuzz -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON \
  -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14 \
  -DANYPS5_ENABLE_ASAN=ON -DANYPS5_KYTY_FUZZERS=ON
cmake --build build-fuzz --target kyty_shader_recompiler_fuzzer
mkdir -p corpus invalid
KYTY_FUZZ_SPIRV=log KYTY_FUZZ_SPIRV_DIR=invalid ASAN_OPTIONS=detect_leaks=0 \
  "$(find build-fuzz -name kyty_shader_recompiler_fuzzer -type f | head -1)" corpus -max_total_time=3600

Each distinct refused module is written as invalid/invalid-<n>.bin (a 4-byte header, then the shader words, little-endian). The fuzzer works from an empty corpus; never commit inputs taken from a game's shaders.

What to do

For each kind: find the pass or emitter that produces it, fix it or refuse the shader with a reason (as KytyFuzz::Run reports for the existing refusals), and add a minimal hand-written case to KytyShim/tests/RecompilerRobustness.cpp, as for the five refusal cases there.

Acceptance

  • The new cases pass, and kyty_shim_recompiler_valid_spirv (which reruns every case with KYTY_FUZZ_SPIRV=abort) passes.
  • One hour of fuzzing finds neither kind again.

Size

Medium; one pull request per kind.

Activity

  1. added
    bug
    area: shaders
    medium
    on Nov 22, 2026
  2. relativespace2K commented on Nov 24, 2026

    @relativespace2K

    Implemented the atomic storage-class kind: LDS atomics in a stage without workgroup storage are lowered to a load, the operation and a store (the LDS variable is per invocation there), so the module no longer contains OpAtomic* on Function/Private. Workgroup and storage-buffer LDS keep their atomics. The new ds_add_u32 pixel and ds_min_u32 vertex cases pass under KYTY_FUZZ_SPIRV=abort; kyty_shim_recompiler_valid_spirv passes. The call-graph kind is still open. PR: #291

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: shadersbugmedium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions