From 3fab752a215021713ec334106c2adae6439354e2 Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Wed, 4 Nov 2026 13:35:46 +0100 Subject: [PATCH] Take out translator patch 0014 so DLSS stops shaking the picture on NVIDIA Patch 0014 gave every function-local variable of a translated shader an OpConstantNull initializer. On an RTX 4080 SUPER with game 1.4.3 that made the whole picture move by about 0.9 output pixels a frame whenever DLSS or DLAA runs, with a still camera (#612). The shake follows the DLAA jitter (TOTK_DLAA_JITTER=0 removes it) and goes away with the v0.3.7 runtime and a translator built without this one patch. Patches 0012, 0013 and 0015 stay. docs/maxwell.md 3.12 now says that registers read before any write have no fix for now; a zero start for Mesa only, or for the shaders that need it, is still open. Co-Authored-By: Claude Opus 5.5 --- docs/maxwell.md | 2 +- tools/build_xlate.py | 6 +++--- .../patches/0014-zero-initialised-locals.patch | 18 ------------------ 3 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 tools/xlate/patches/0014-zero-initialised-locals.patch diff --git a/docs/maxwell.md b/docs/maxwell.md index a02c4787..e8eba067 100644 --- a/docs/maxwell.md +++ b/docs/maxwell.md @@ -88,7 +88,7 @@ Source shorthands: | 3.9 | **Integer vertex inputs read as raw bits** (bone indices `R8UI`). | Float-declared inputs convert integers. | NXN Mario: stretched characters; re-translated with `uint` inputs. Ours: attribute types passed to `QueryGraphicsState` (`Program.cs`). | NXN | | 3.10 | **BFE / BFI fields past bit 31** (as PTX `bfe` / `bfi`): a field that runs past bit 31 is cut there; one that starts past it extracts 0 (signed: bit 31 repeated) and inserts nothing. TotK 1.4.3's Depths terrain vertex shaders (42 variants) take the position from a register, `((2y + x) * 8) & 0xff` with 5-bit x and y, so up to 248. | `OpBitField*Extract` / `OpBitFieldInsert` undefined when offset or offset + count exceeds 32; AMD's bitfield instructions take offset and width modulo 32. | Ryujinx passes the fields through. UltraTears saw the Depths walls and ground missing on the Steam Deck and a Linux RX 570 (RADV). Ours: clamped where the field is not a constant inside the word (translator patch 0012). RX 9070 on Windows drew the Depths the same before and after. | PTX ISA `bfe`, `bfi` | | 3.11 | **SHF by 0** gives the unshifted word (C for `SHF.L`, A for `SHF.R`). | Ryujinx's funnel shifts the other word by 32: undefined in SPIR-V; AMD shifts take the low 5 bits and give A \| C. | yuzu fixed Depths terrain gaps in its funnel shift (PR 10459). Ours: a select on a zero amount (translator patch 0013). In 1.4.3 every register SHF pairs its word with 0, so the result was right already. | — | -| 3.12 | **Registers read before any write** on a path (paths the structurizer adds included) have no defined value in the game's code; UltraTears reports 0 from the NVIDIA driver. | An `OpVariable` without an initializer loads an undefined value; Mesa folds undefined values freely. | Ours: every function-local variable starts at 0 (`OpConstantNull`, translator patch 0014). | — | +| 3.12 | **Registers read before any write** on a path (paths the structurizer adds included) have no defined value in the game's code; UltraTears reports 0 from the NVIDIA driver. | An `OpVariable` without an initializer loads an undefined value; Mesa folds undefined values freely. | Ours: none for now. Translator patch 0014 started every function-local variable at 0 (`OpConstantNull`); on NVIDIA (RTX 4080 SUPER, 1.4.3) that made the whole picture shake by about 0.9 output pixels a frame with DLSS or DLAA (#612; no shake with `TOTK_DLAA_JITTER=0` or without the patch), so it was taken out. A zero start for Mesa only, or for the shaders that need it, is still open. | — | ## 4. Memory model diff --git a/tools/build_xlate.py b/tools/build_xlate.py index 210c1acf..c13ed192 100644 --- a/tools/build_xlate.py +++ b/tools/build_xlate.py @@ -1,7 +1,7 @@ """Build the shader translator: build/xlate/totk_xlate.exe (Ryujinx 1.3.2 + patches, NativeAOT, SPIR-V for Vulkan). Copies tools/vendor/ryujinx to build/xlate/ryujinx, applies tools/xlate/patches/*.patch there (tools/vendor stays -byte-identical; 0001-0004 are MNG's, 0005-0014 are ours), then runs `dotnet publish`. Needs the .NET 10 SDK, the MSVC build +byte-identical; 0001-0004 are MNG's, 0005-0013 and 0015 are ours), then runs `dotnet publish`. Needs the .NET 10 SDK, the MSVC build tools and vswhere.exe (docs/building.md). Run with .venv. On Linux it builds build/xlate/totk_xlate for linux-x64, which NativeAOT links with the system's clang (no MSVC); NativeAOT builds for the OS it runs on only. @@ -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) != 15: - sys.exit(f"expected 15 patches, found {len(patches)}") + if len(patches) != 14: + sys.exit(f"expected 14 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"], []): diff --git a/tools/xlate/patches/0014-zero-initialised-locals.patch b/tools/xlate/patches/0014-zero-initialised-locals.patch deleted file mode 100644 index 3ffc7a9b..00000000 --- a/tools/xlate/patches/0014-zero-initialised-locals.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs -+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs -@@ -33,8 +33,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv - { - foreach (AstOperand local in function.Locals) - { -- SpvInstruction localPointerType = context.TypePointer(StorageClass.Function, context.GetType(local.VarType)); -- SpvInstruction spvLocal = context.Variable(localPointerType, StorageClass.Function); -+ SpvInstruction localType = context.GetType(local.VarType); -+ SpvInstruction localPointerType = context.TypePointer(StorageClass.Function, localType); -+ -+ // TOTK: a register read on a path that did not write it reads 0. Without an initializer the load is -+ // undefined, and a compiler that folds undefined values (Mesa's, on the Steam Deck) may compute anything -+ // from it. -+ SpvInstruction spvLocal = context.Variable(localPointerType, StorageClass.Function, context.ConstantNull(localType)); - - context.AddLocalVariable(spvLocal); - context.DeclareLocal(local, spvLocal);