aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2022-12-05 16:11:32 -0300
committerGitHub <noreply@github.com>2022-12-05 19:11:32 +0000
commitbbb24d8c7e6ccc61ceda1f4223fd68feee3b2f20 (patch)
tree955a54494cda71a9f816a08773886e5168980c59
parent4da44e09cb2a32f69b4a6b47221117b78e4618dc (diff)
Restrict shader storage buffer search when match fails (#4011)1.1.427
* Restrict storage buffer search when match fails * Shader cache version bump
-rw-r--r--Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs2
-rw-r--r--Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs17
-rw-r--r--Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs6
-rw-r--r--Ryujinx.Graphics.Shader/Translation/Rewriter.cs9
-rw-r--r--Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs9
5 files changed, 38 insertions, 5 deletions
diff --git a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs
index 5c1b638b7..d2eb5ccff 100644
--- a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs
+++ b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs
@@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
22 private const ushort FileFormatVersionMajor = 1; 22 private const ushort FileFormatVersionMajor = 1;
23 private const ushort FileFormatVersionMinor = 2; 23 private const ushort FileFormatVersionMinor = 2;
24 private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; 24 private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
25 private const uint CodeGenVersion = 3957; 25 private const uint CodeGenVersion = 4011;
26 26
27 private const string SharedTocFileName = "shared.toc"; 27 private const string SharedTocFileName = "shared.toc";
28 private const string SharedDataFileName = "shared.data"; 28 private const string SharedDataFileName = "shared.data";
diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs
index 7aabcc9e6..ec8fca1da 100644
--- a/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs
+++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs
@@ -8,14 +8,25 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
8{ 8{
9 static class GlobalToStorage 9 static class GlobalToStorage
10 { 10 {
11 public static void RunPass(BasicBlock block, ShaderConfig config) 11 public static void RunPass(BasicBlock block, ShaderConfig config, ref int sbUseMask)
12 { 12 {
13 int sbStart = GetStorageBaseCbOffset(config.Stage); 13 int sbStart = GetStorageBaseCbOffset(config.Stage);
14
15 int sbEnd = sbStart + StorageDescsSize; 14 int sbEnd = sbStart + StorageDescsSize;
16 15
17 for (LinkedListNode<INode> node = block.Operations.First; node != null; node = node.Next) 16 for (LinkedListNode<INode> node = block.Operations.First; node != null; node = node.Next)
18 { 17 {
18 for (int index = 0; index < node.Value.SourcesCount; index++)
19 {
20 Operand src = node.Value.GetSource(index);
21
22 int storageIndex = GetStorageIndex(src, sbStart, sbEnd);
23
24 if (storageIndex >= 0)
25 {
26 sbUseMask |= 1 << storageIndex;
27 }
28 }
29
19 if (!(node.Value is Operation operation)) 30 if (!(node.Value is Operation operation))
20 { 31 {
21 continue; 32 continue;
@@ -52,6 +63,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
52 } 63 }
53 } 64 }
54 } 65 }
66
67 config.SetAccessibleStorageBuffersMask(sbUseMask);
55 } 68 }
56 69
57 private static LinkedListNode<INode> ReplaceGlobalWithStorage(BasicBlock block, LinkedListNode<INode> node, ShaderConfig config, int storageIndex) 70 private static LinkedListNode<INode> ReplaceGlobalWithStorage(BasicBlock block, LinkedListNode<INode> node, ShaderConfig config, int storageIndex)
diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs
index 47963eacc..a1a2054c0 100644
--- a/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs
+++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs
@@ -11,14 +11,18 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
11 { 11 {
12 RunOptimizationPasses(blocks); 12 RunOptimizationPasses(blocks);
13 13
14 int sbUseMask = 0;
15
14 // Those passes are looking for specific patterns and only needs to run once. 16 // Those passes are looking for specific patterns and only needs to run once.
15 for (int blkIndex = 0; blkIndex < blocks.Length; blkIndex++) 17 for (int blkIndex = 0; blkIndex < blocks.Length; blkIndex++)
16 { 18 {
17 GlobalToStorage.RunPass(blocks[blkIndex], config); 19 GlobalToStorage.RunPass(blocks[blkIndex], config, ref sbUseMask);
18 BindlessToIndexed.RunPass(blocks[blkIndex], config); 20 BindlessToIndexed.RunPass(blocks[blkIndex], config);
19 BindlessElimination.RunPass(blocks[blkIndex], config); 21 BindlessElimination.RunPass(blocks[blkIndex], config);
20 } 22 }
21 23
24 config.SetAccessibleStorageBuffersMask(sbUseMask);
25
22 // Run optimizations one last time to remove any code that is now optimizable after above passes. 26 // Run optimizations one last time to remove any code that is now optimizable after above passes.
23 RunOptimizationPasses(blocks); 27 RunOptimizationPasses(blocks);
24 } 28 }
diff --git a/Ryujinx.Graphics.Shader/Translation/Rewriter.cs b/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
index bdd9b791b..c8dab9de3 100644
--- a/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
+++ b/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
@@ -2,6 +2,7 @@ using Ryujinx.Graphics.Shader.IntermediateRepresentation;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Diagnostics; 3using System.Diagnostics;
4using System.Linq; 4using System.Linq;
5using System.Numerics;
5 6
6using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper; 7using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
7using static Ryujinx.Graphics.Shader.Translation.GlobalMemory; 8using static Ryujinx.Graphics.Shader.Translation.GlobalMemory;
@@ -88,8 +89,14 @@ namespace Ryujinx.Graphics.Shader.Translation
88 Operand sbBaseAddrLow = Const(0); 89 Operand sbBaseAddrLow = Const(0);
89 Operand sbSlot = Const(0); 90 Operand sbSlot = Const(0);
90 91
91 for (int slot = 0; slot < StorageMaxCount; slot++) 92 int sbUseMask = config.AccessibleStorageBuffersMask;
93
94 while (sbUseMask != 0)
92 { 95 {
96 int slot = BitOperations.TrailingZeroCount(sbUseMask);
97
98 sbUseMask &= ~(1 << slot);
99
93 config.SetUsedStorageBuffer(slot, isWrite); 100 config.SetUsedStorageBuffer(slot, isWrite);
94 101
95 int cbOffset = GetStorageCbOffset(config.Stage, slot); 102 int cbOffset = GetStorageCbOffset(config.Stage, slot);
diff --git a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
index 12cd4cd18..85b56b51f 100644
--- a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
+++ b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
@@ -65,6 +65,8 @@ namespace Ryujinx.Graphics.Shader.Translation
65 public UInt128 NextInputAttributesComponents { get; private set; } 65 public UInt128 NextInputAttributesComponents { get; private set; }
66 public UInt128 ThisInputAttributesComponents { get; private set; } 66 public UInt128 ThisInputAttributesComponents { get; private set; }
67 67
68 public int AccessibleStorageBuffersMask { get; private set; }
69
68 private int _usedConstantBuffers; 70 private int _usedConstantBuffers;
69 private int _usedStorageBuffers; 71 private int _usedStorageBuffers;
70 private int _usedStorageBuffersWrite; 72 private int _usedStorageBuffersWrite;
@@ -98,6 +100,8 @@ namespace Ryujinx.Graphics.Shader.Translation
98 GpuAccessor = gpuAccessor; 100 GpuAccessor = gpuAccessor;
99 Options = options; 101 Options = options;
100 102
103 AccessibleStorageBuffersMask = (1 << GlobalMemory.StorageMaxCount) - 1;
104
101 UsedInputAttributesPerPatch = new HashSet<int>(); 105 UsedInputAttributesPerPatch = new HashSet<int>();
102 UsedOutputAttributesPerPatch = new HashSet<int>(); 106 UsedOutputAttributesPerPatch = new HashSet<int>();
103 107
@@ -400,6 +404,11 @@ namespace Ryujinx.Graphics.Shader.Translation
400 UsedFeatures |= flags; 404 UsedFeatures |= flags;
401 } 405 }
402 406
407 public void SetAccessibleStorageBuffersMask(int mask)
408 {
409 AccessibleStorageBuffersMask = mask;
410 }
411
403 public void SetUsedConstantBuffer(int slot) 412 public void SetUsedConstantBuffer(int slot)
404 { 413 {
405 _usedConstantBuffers |= 1 << slot; 414 _usedConstantBuffers |= 1 << slot;