Files
NX2navi/tools/xlate/patches/0019-fragment-depth-register.patch
chrg6 77d0c0b84e Port Ocarina of Time (Switch 2) to the recomp host
The NVN2 front end and the SM86 to Maxwell shader lowering (tools/xlate/AmpereLowering.cs, mesh and task stages,
bindless texture pools, BRX jump tables, the NVN2 compute c0 layout) with four translator patches (0017-0020) bring the
opening of the game to 58-60 fps on the Vulkan renderer.

This round fixes the haze: SM86 IPA is lowered as a plain Maxwell IPA.PASS (texture coordinates were corrected for
perspective twice); LDSM, TXD, both F2IP byte forms, HMMA, MOVM and HFMA2.RELU are lowered and spill mode has eight
uniform register groups; conditional rendering keeps the newest counter report per address and treats a report as
pending until its value is in guest memory, so occlusion tests and the depth clears around the depth copy behave; and
the upscaler stand-in decodes the post pass's sRGB picture before writing the linear target. Tensor-core programs keep
the stand-in unless NX2NAVI_NATIVE_TENSOR=1, because their lowering does not match the hardware yet.

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

28 lines
1.3 KiB
Diff

--- a/src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
@@ -159,8 +159,22 @@
internal int GetDepthRegister()
{
- // The depth register is always two registers after the last color output.
- return BitOperations.PopCount((uint)Definitions.OmapTargets) + 1;
+ // NX2NAVI: every render target with any component enabled takes four registers (the colour outputs above), then
+ // the sample mask when written, then one register is skipped. The component count was used, which matches
+ // only when every enabled target writes all four: Ocarina's depth downsample (targets 0 and 2, .x each) read
+ // its depth from R3, never written, and wrote 0 (all its fog then sat at the near plane). As the hardware's
+ // ExitFragment counts.
+ int targets = 0;
+
+ for (int rtIndex = 0; rtIndex < 8; rtIndex++)
+ {
+ if ((Definitions.OmapTargets & (0xf << (rtIndex * 4))) != 0)
+ {
+ targets++;
+ }
+ }
+
+ return targets * 4 + (Definitions.OmapSampleMask ? 1 : 0) + 1;
}
public void SetLayerOutputAttribute(int attr)