Files
NX2navi/tools/xlate/patches/0027-fragment-output-nan-guard.patch
chrg6 29cab01da7 Guard float colour outputs against NaN, start mesh counts at zero, and read XInput pads SDL misses.
Patch 0027: a float colour output turns NaN into 0 and clamps the rest to +-1e30 before it reaches its target, so one
bad texel cannot spread through bloom, blur and downsample passes as black or white blocks; integer targets keep their
bits. Task and mesh shaders start their mesh and primitive counts at 0 behind a barrier, and a task emits at most one
mesh group per thread, so a task that culls everything no longer launches what the shared memory last held. Without a
gamepad SDL can open, the first connected XInput controller (slots 0-3, empty slots asked once a second) is read
directly. Kokiri Forest: 60 fps, GPU 5.5 ms a frame, unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 05:04:39 -05:00

19 lines
1.2 KiB
Diff

--- a/src/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs
@@ -495,6 +495,15 @@
Operand src = Register(regIndexBase + component, RegisterType.Gpr);
+ // NX2NAVI: a float colour output carries no NaN or infinity on to its target: one NaN texel spreads
+ // through the averages of bloom, blur and downsample passes into blocks of black or white. NaN
+ // becomes 0 and the rest is clamped to +-1e30; integer targets keep their bits.
+ if ((TranslatorContext.Definitions.GetFragmentOutputColorType(rtIndex) & AggregateType.ElementTypeMask) == AggregateType.FP32)
+ {
+ Operand clamped = this.FPMinimum(this.FPMaximum(src, ConstF(-1e30f)), ConstF(1e30f));
+ src = this.ConditionalSelect(this.IsNan(src), ConstF(0f), clamped);
+ }
+
// Perform B <-> R swap if needed, for BGRA formats (not supported on OpenGL).
if (!supportsBgra && (component == 0 || component == 2))
{