--- 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). This + // counts the way the hardware's fragment exit does. + 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)