eden/src/shader_recompiler
xbzk 73918d23d5
[video_core, maxwell] fixes for homebrew games that use MESA compiler (#4012)
two main issues:

shader_environment.cpp

Support Mesa nv50_ir-compiled homebrew fragment shaders
Mesa nv50_ir (used by NZP-Switch via libdrm_nouveau) emits Maxwell SASS that differs from NVN in two ways our shader pipeline didn't account for, causing "infinite" loops during shader scanning.

How?  TryFindSize() previously detected end-of-shader only via NVN's "BRA $-1" self-branch trailer (SELF_BRANCH_A/B). Mesa-compiled shaders end with an unconditional @PT EXIT and emit no trailer, so scanning ran past the shader and looped to MAXIMUM_SIZE.

Fix: Added a secondary match against @PT EXIT T (opcode 0xE30, predicate PT, flow T) as a fallback terminator. The mask is estrictive enough to reject predicated EXITs, conditional-flow EXITs, and sched control words, so well-formed NVN shaders see no ehavior change (their single @PT EXIT immediately precedes BRA $-1, and both detections return the same size).

load_store_attribute.cpp + attribute.h

IPA's is_perspective check only applied the ×position_w correction for IR::IsGeneric() attributes, and used a per-component SPH lookup. Two failure modes followed:

1. Mesa fragment shaders read varyings via legacy attribute slots
(ColorFrontDiffuse, FixedFncTexture, FogCoordinate) which are
remapped to generic varyings later by ConvertLegacyToGeneric. At
IPA-translation time they're still legacy, so IsGeneric() was
false and the inject was skipped — but the resulting GLSL/SPIR-V
varying was Smooth (perspective-correct), and the SASS still
issued its manual perspective dance via MUFU.RCP(ATTR_W)+FMUL,
compounding an extra ×clip_w factor. NZP fog (eye_z distance
varying) ended up as eye_z⁴×density² instead of eye_z²×density²,
saturating fog to white everywhere.

2. Even for legacy attrs that should inject, Mesa stores them in two formats selected by the IPA's interpolation_mode field:
Pass/Multiply/Constant → attr/w (perspective); inject ×position_w
Sc (ScreenLinear)      → raw attr; do NOT inject
Unconditionally injecting for Sc dims vertex colors by 1/clip_w because there's no SASS multiplier to round-trip it back.

Fix: extend the IPA correction path to also fire on IsLegacyAttribute(), gated on interpolation_mode != Sc. While here, the generic-path check is widened from per-component to vector-level (first non-Unused PixelImap, with all-Unused fallthrough treated as Perspective) so it matches the GLSL interpolation qualifier picked by CollectInterpolationInfo — this fixes the same all-zeroed-imap case Mesa exposes for explicit generics. IsLegacyAttribute moved from translate_program.cpp's anonymous namespace into attribute.h next to IsGeneric so IPA can reach it.

Tested on NaziZombies:Portable (Switch homebrew): fog now matches real
hardware, vertex-colored geometry (hand, gun, decals) renders correctly.

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4012
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
2026-06-15 03:05:11 +02:00
..
backend [*] basic in-house cpp linting (#4039) 2026-06-04 05:49:07 +02:00
frontend [video_core, maxwell] fixes for homebrew games that use MESA compiler (#4012) 2026-06-15 03:05:11 +02:00
ir_opt [vulkan] Fix regressions found in last stable release (#3953) 2026-06-02 01:06:12 +02:00
CMakeLists.txt [spirv] nuke spirv-opt (#3877) 2026-04-25 21:54:27 +02:00
environment.h [*] change all std::unordered_map and std::unordered_set into ankerl::unordered_dense::map/set variants (#3442) 2026-02-10 03:34:07 +01:00
exception.h [common/logging] Simplify logging logic and fix issues when logging before system is created (#3688) 2026-03-12 18:29:15 +01:00
host_translate_info.h [shader_recompiler] handle dynamic texture descriptor strides (#3898) 2026-05-04 18:15:55 +02:00
object_pool.h Move to Clang Format 15 2023-01-29 17:49:42 -07:00
profile.h [spirv] mark sampled image descriptor indices non-uniform (#3900) 2026-05-04 18:16:11 +02:00
program_header.h general: Convert source file copyright comments over to SPDX 2022-04-23 05:55:32 -04:00
runtime_info.h [vulkan] 2nd Vulkan Global Maintenance (#3853) 2026-04-24 16:37:18 +02:00
shader_info.h [android, feat] add "Fix Bloom Effects" toggle (#3359) 2026-01-26 06:59:59 +01:00
stage.h general: Convert source file copyright comments over to SPDX 2022-04-23 05:55:32 -04:00
varying_state.h MacroHLE: Add HLE replacement for base vertex and base instance. 2023-01-01 16:43:57 -05:00