Files
NX2navi/tools/xlate/patches/0029-more-storage-buffer-slots.patch
chrg6 f76d896ed5 Give the translator 64 storage buffer slots and keep it converting a block after a store it cannot place.
Ocarina's NVN2 compute programs reach more than 16 buffers through their pushed pointers and pointer tables; past the 16th the translator found no slot, dropped the store, and its loop then read the next node of a node it had just removed, so every later global access in the block stayed global and the whole program failed with "Invalid storage kind GlobalMemory". Ten compute programs of Kokiri Forest were skipped on every dispatch and retried on every one, which also cost 10-25 ms frames. Now one program still fails (an Ampere MATCH instruction the lowering does not handle). NX2NAVI_XLATE_KEEP=2 keeps every translated job with its code for running the translator by hand.

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

61 lines
3.3 KiB
Diff

--- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs
@@ -281,7 +281,15 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
}
else
{
- Utils.DeleteNode(node, operation);
+ // NX2NAVI: the store becomes an unused copy in place instead of leaving the list: the
+ // loop goes on from node.Next, which a removed node no longer has, so every global
+ // access after it in the block stayed global and failed the whole translation.
+ for (int srcIndex = 0; srcIndex < operation.SourcesCount; srcIndex++)
+ {
+ operation.SetSource(srcIndex, null);
+ }
+
+ node.Value = new Operation(Instruction.Copy, Local(), Const(0));
}
}
else
--- a/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs
@@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Shader.Translation
private readonly SetBindingPair[] _cbSlotToBindingMap;
private readonly SetBindingPair[] _sbSlotToBindingMap;
- private uint _sbSlotWritten;
+ private ulong _sbSlotWritten;
private readonly Dictionary<int, int> _sbSlots;
private readonly Dictionary<int, int> _sbSlotsReverse;
@@ -66,7 +66,10 @@ namespace Ryujinx.Graphics.Shader.Translation
_stagePrefix = GetShaderStagePrefix(stage);
_cbSlotToBindingMap = new SetBindingPair[32]; // NX2NAVI: slots 18-31 for Transforms/MotionPrevious.cs
- _sbSlotToBindingMap = new SetBindingPair[16];
+ // NX2NAVI: 64 storage buffer slots (the width of _sbSlotWritten), not 16: Ocarina's NVN2 compute programs
+ // reach more than 16 buffers through their pushed pointers and pointer tables, and every access to a buffer
+ // past the 16th found no slot.
+ _sbSlotToBindingMap = new SetBindingPair[64];
_cbSlotToBindingMap.AsSpan().Fill(new(-1, -1));
_sbSlotToBindingMap.AsSpan().Fill(new(-1, -1));
@@ -193,7 +196,7 @@ namespace Ryujinx.Graphics.Shader.Translation
if (write)
{
- _sbSlotWritten |= 1u << slot;
+ _sbSlotWritten |= 1ul << slot;
}
binding = setAndBinding.Binding;
@@ -503,7 +506,7 @@ namespace Ryujinx.Graphics.Shader.Translation
if (setAndBinding.Binding >= 0)
{
(int sbCbSlot, int sbCbOffset) = UnpackSbCbInfo(key);
- BufferUsageFlags flags = (_sbSlotWritten & (1u << slot)) != 0 ? BufferUsageFlags.Write : BufferUsageFlags.None;
+ BufferUsageFlags flags = (_sbSlotWritten & (1ul << slot)) != 0 ? BufferUsageFlags.Write : BufferUsageFlags.None;
descriptors[descriptorIndex++] = new BufferDescriptor(setAndBinding.SetIndex, setAndBinding.Binding, slot, sbCbSlot, sbCbOffset, flags);
}
}