Files
totk-pc-recomp/tools/xlate/patches/0013-funnel-shift-by-zero.patch
T
Valiantsin DzerakhandClaude Opus 5.5 c0e66fe4c1 Shader translator: Maxwell results where SPIR-V leaves bitfields, funnel shifts and unwritten registers undefined
- BFE / BFI (patch 0012): a field past bit 31 is cut there, one that starts past it extracts 0 (signed: bit 31
  repeated) and inserts nothing, as PTX bfe / bfi. Clamped only where the field is not a constant inside the word.
  1.4.3's Depths terrain vertex shaders (42 variants, 134 extracts) compute the position as ((2y + x) * 8) & 0xff,
  up to 248; AMD's bitfield instructions take it modulo 32. UltraTears saw the Depths walls and ground missing on
  RADV (Steam Deck, RX 570).
- SHF by 0 (patch 0013) gives the unshifted word instead of shifting the other one by 32. Every register SHF of
  1.4.3 pairs its word with 0, so 1.4.3 results do not change.
- Function-local variables start at 0 (patch 0014): a register read on a path that never wrote it is no longer an
  undefined value Mesa may fold.

All 12,454 1.4.3 shaders translate and pass spirv-val. RX 9070, Depths save: the same picture before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 10:19:26 +03:00

33 lines
1.5 KiB
Diff

--- a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitShift.cs
+++ b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitShift.cs
@@ -119,6 +119,10 @@ namespace Ryujinx.Graphics.Shader.Instructions
bool signedShift = maxShift == MaxShift.S64;
int maxShiftConst = isLongShift ? 64 : 32;
+ // TOTK: the shift amount as a constant, when it is one (taken before the mask makes it an operation).
+ bool constantShift = srcB.Type == OperandType.Constant;
+ int shiftValue = constantShift ? (mask ? srcB.Value & (maxShiftConst - 1) : srcB.Value) : 0;
+
if (mask)
{
srcB = context.BitwiseAnd(srcB, Const(maxShiftConst - 1));
@@ -159,6 +163,18 @@ namespace Ryujinx.Graphics.Shader.Instructions
}
}
+ // TOTK: a shift by 0 shifts the other word by 32, which SPIR-V leaves undefined; AMD's shift instructions take
+ // the amount's low 5 bits and give A | C. Maxwell gives the unshifted word: C for SHF.L, A for SHF.R, 32- and
+ // 64-bit alike. TOTK's Depths terrain vertex shaders shift by registers (SHF.L.R, SHF.R.R).
+ if (!constantShift)
+ {
+ res = context.ConditionalSelect(context.ICompareEqual(srcB, Const(0)), left ? srcC : srcA, res);
+ }
+ else if (shiftValue == 0)
+ {
+ res = left ? srcC : srcA;
+ }
+
if (!mask)
{
// Clamped shift value.