mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 20:09:57 -04:00
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>
This commit is contained in:
@@ -99,8 +99,8 @@ def prepare_sources() -> Path:
|
||||
for junk in list(src.glob("src/*/obj")) + list(src.glob("src/*/bin")):
|
||||
shutil.rmtree(junk)
|
||||
patches = sorted((XLATE / "patches").glob("*.patch"))
|
||||
if len(patches) != 25:
|
||||
sys.exit(f"expected 25 patches, found {len(patches)}")
|
||||
if len(patches) != 26:
|
||||
sys.exit(f"expected 26 patches, found {len(patches)}")
|
||||
for patch in patches:
|
||||
# git apply works outside a repository when given a directory; --check first so a failure names the patch.
|
||||
for extra in (["--check"], []):
|
||||
|
||||
@@ -252,13 +252,20 @@ static class MeshSpirv
|
||||
body.Add(new Insn(OpFunction, new[] { tVoid, entryFn, 0u, tFnVoid }));
|
||||
Label();
|
||||
uint tid = Emit(OpLoad, tUint, lii);
|
||||
if (m.Stage == 7 && m.HasTask) { CopyPayload(tid, true); Barrier(); }
|
||||
// The counts start at 0: a task that culls everything never writes its mesh count, and the word then held what
|
||||
// the workgroup's shared memory last had, up to tens of thousands of mesh groups and a lost device; a mesh
|
||||
// shader that emits nothing leaves its primitive count the same way.
|
||||
uint countWord = C((uint)(m.Stage == 6 ? (m.Pay + 4) / 4 : m.Map / 4));
|
||||
If(tid, C(1), () => Do(OpStore, Emit(OpAccessChain, pSharedUint, sharedVar, countWord), C(0)));
|
||||
if (m.Stage == 7 && m.HasTask) CopyPayload(tid, true);
|
||||
Barrier();
|
||||
Emit(OpFunctionCall, tVoid, mainFn);
|
||||
Barrier();
|
||||
var modes = new List<Insn>();
|
||||
if (m.Stage == 6)
|
||||
{
|
||||
uint count = SharedWord(C((uint)(m.Pay + 4) / 4));
|
||||
// one mesh group per task thread at most: a garbage count cannot launch more than the task could fill
|
||||
uint count = UMin(SharedWord(C((uint)(m.Pay + 4) / 4)), C((uint)Math.Max(1, m.Threads)));
|
||||
CopyPayload(tid, false);
|
||||
Do(OpEmitMeshTasksEXT, count, C(1), C(1), payloadVar);
|
||||
}
|
||||
|
||||
18
tools/xlate/patches/0027-fragment-output-nan-guard.patch
Normal file
18
tools/xlate/patches/0027-fragment-output-nan-guard.patch
Normal file
@@ -0,0 +1,18 @@
|
||||
--- 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))
|
||||
{
|
||||
Reference in New Issue
Block a user