From b34de74f81ef73a78d43d169b9f1ce7f175035b5 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sat, 23 Jul 2022 11:15:58 -0300 Subject: [PATCH] Avoid adding shader buffer descriptors for constant buffers that are not used (#3478) * Avoid adding shader buffer descriptors for constant buffers that are not used * Shader cache version --- .../Shader/DiskCache/DiskCacheHostStorage.cs | 2 +- Ryujinx.Graphics.Shader/Instructions/InstEmitHelper.cs | 6 +++--- .../StructuredIr/StructuredProgramContext.cs | 5 +++++ .../Translation/Optimizations/GlobalToStorage.cs | 4 ++-- Ryujinx.Graphics.Shader/Translation/Rewriter.cs | 6 +++--- Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs | 6 ------ 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs index c332e2df6..b76d82261 100644 --- a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs +++ b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache private const ushort FileFormatVersionMajor = 1; private const ushort FileFormatVersionMinor = 1; private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; - private const uint CodeGenVersion = 3457; + private const uint CodeGenVersion = 3478; private const string SharedTocFileName = "shared.toc"; private const string SharedDataFileName = "shared.data"; diff --git a/Ryujinx.Graphics.Shader/Instructions/InstEmitHelper.cs b/Ryujinx.Graphics.Shader/Instructions/InstEmitHelper.cs index dd6ff8e92..0ba4667ea 100644 --- a/Ryujinx.Graphics.Shader/Instructions/InstEmitHelper.cs +++ b/Ryujinx.Graphics.Shader/Instructions/InstEmitHelper.cs @@ -45,12 +45,12 @@ namespace Ryujinx.Graphics.Shader.Instructions if (isFP64) { return context.PackDouble2x32( - context.Config.CreateCbuf(cbufSlot, cbufOffset), - context.Config.CreateCbuf(cbufSlot, cbufOffset + 1)); + Cbuf(cbufSlot, cbufOffset), + Cbuf(cbufSlot, cbufOffset + 1)); } else { - return context.Config.CreateCbuf(cbufSlot, cbufOffset); + return Cbuf(cbufSlot, cbufOffset); } } diff --git a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramContext.cs b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramContext.cs index 2a39d0210..053251441 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramContext.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramContext.cs @@ -300,6 +300,11 @@ namespace Ryujinx.Graphics.Shader.StructuredIr if (operand.Type != OperandType.LocalVariable) { + if (operand.Type == OperandType.ConstantBuffer) + { + Config.SetUsedConstantBuffer(operand.GetCbufSlot()); + } + return new AstOperand(operand); } diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs index 1cf43e5d3..d2200d0b8 100644 --- a/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs +++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs @@ -68,7 +68,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations { Operand addrLow = operation.GetSource(0); - Operand baseAddrLow = config.CreateCbuf(0, GetStorageCbOffset(config.Stage, storageIndex)); + Operand baseAddrLow = Cbuf(0, GetStorageCbOffset(config.Stage, storageIndex)); Operand baseAddrTrunc = Local(); @@ -152,7 +152,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations { Operand addrLow = operation.GetSource(0); - Operand baseAddrLow = config.CreateCbuf(0, UbeBaseOffset + storageIndex * StorageDescSize); + Operand baseAddrLow = Cbuf(0, UbeBaseOffset + storageIndex * StorageDescSize); Operand baseAddrTrunc = Local(); diff --git a/Ryujinx.Graphics.Shader/Translation/Rewriter.cs b/Ryujinx.Graphics.Shader/Translation/Rewriter.cs index e9b073ab2..d59da0191 100644 --- a/Ryujinx.Graphics.Shader/Translation/Rewriter.cs +++ b/Ryujinx.Graphics.Shader/Translation/Rewriter.cs @@ -75,9 +75,9 @@ namespace Ryujinx.Graphics.Shader.Translation int cbOffset = GetStorageCbOffset(config.Stage, slot); - Operand baseAddrLow = config.CreateCbuf(0, cbOffset); - Operand baseAddrHigh = config.CreateCbuf(0, cbOffset + 1); - Operand size = config.CreateCbuf(0, cbOffset + 2); + Operand baseAddrLow = Cbuf(0, cbOffset); + Operand baseAddrHigh = Cbuf(0, cbOffset + 1); + Operand size = Cbuf(0, cbOffset + 2); Operand offset = PrependOperation(Instruction.Subtract, addrLow, baseAddrLow); Operand borrow = PrependOperation(Instruction.CompareLessU32, addrLow, baseAddrLow); diff --git a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs index 27d72cd53..bac838615 100644 --- a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs +++ b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs @@ -360,12 +360,6 @@ namespace Ryujinx.Graphics.Shader.Translation UsedFeatures |= flags; } - public Operand CreateCbuf(int slot, int offset) - { - SetUsedConstantBuffer(slot); - return OperandHelper.Cbuf(slot, offset); - } - public void SetUsedConstantBuffer(int slot) { _usedConstantBuffers |= 1 << slot;