0
0
Fork 0
mirror of https://github.com/ryujinx-mirror/ryujinx.git synced 2024-12-23 17:25:50 +00:00

Use correct offset for storage constant buffer elimination (#4821)

This commit is contained in:
riperiperi 2023-05-05 22:59:36 +01:00 committed by GitHub
parent 7df4fcada7
commit 332891b5ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View file

@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
private const ushort FileFormatVersionMajor = 1; private const ushort FileFormatVersionMajor = 1;
private const ushort FileFormatVersionMinor = 2; private const ushort FileFormatVersionMinor = 2;
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
private const uint CodeGenVersion = 2237; private const uint CodeGenVersion = 4821;
private const string SharedTocFileName = "shared.toc"; private const string SharedTocFileName = "shared.toc";
private const string SharedDataFileName = "shared.data"; private const string SharedDataFileName = "shared.data";

View file

@ -161,12 +161,12 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
Operand addrLow, Operand addrLow,
bool isStg16Or8) bool isStg16Or8)
{ {
int baseAddressCbOffset = GetStorageCbOffset(config.Stage, storageIndex); (int sbCbSlot, int sbCbOffset) = config.GetSbCbInfo(storageIndex);
bool storageAligned = !(config.GpuAccessor.QueryHasUnalignedStorageBuffer() || config.GpuAccessor.QueryHostStorageBufferOffsetAlignment() > Constants.StorageAlignment); bool storageAligned = !(config.GpuAccessor.QueryHasUnalignedStorageBuffer() || config.GpuAccessor.QueryHostStorageBufferOffsetAlignment() > Constants.StorageAlignment);
(Operand byteOffset, int constantOffset) = storageAligned ? (Operand byteOffset, int constantOffset) = storageAligned ?
GetStorageOffset(block, Utils.FindLastOperation(addrLow, block), baseAddressCbOffset) : GetStorageOffset(block, Utils.FindLastOperation(addrLow, block), sbCbSlot, sbCbOffset) :
(null, 0); (null, 0);
if (byteOffset != null) if (byteOffset != null)
@ -176,8 +176,6 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
if (byteOffset == null) if (byteOffset == null)
{ {
(int sbCbSlot, int sbCbOffset) = config.GetSbCbInfo(storageIndex);
Operand baseAddrLow = Cbuf(sbCbSlot, sbCbOffset); Operand baseAddrLow = Cbuf(sbCbSlot, sbCbOffset);
Operand baseAddrTrunc = Local(); Operand baseAddrTrunc = Local();
@ -217,9 +215,9 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
return wordOffset; return wordOffset;
} }
private static bool IsCb0Offset(Operand operand, int offset) private static bool IsCbOffset(Operand operand, int slot, int offset)
{ {
return operand.Type == OperandType.ConstantBuffer && operand.GetCbufSlot() == 0 && operand.GetCbufOffset() == offset; return operand.Type == OperandType.ConstantBuffer && operand.GetCbufSlot() == slot && operand.GetCbufOffset() == offset;
} }
private static void ReplaceAddressAlignment(LinkedList<INode> list, Operand address, Operand byteOffset, int constantOffset) private static void ReplaceAddressAlignment(LinkedList<INode> list, Operand address, Operand byteOffset, int constantOffset)
@ -263,9 +261,9 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
} }
} }
private static (Operand, int) GetStorageOffset(BasicBlock block, Operand address, int baseAddressCbOffset) private static (Operand, int) GetStorageOffset(BasicBlock block, Operand address, int cbSlot, int baseAddressCbOffset)
{ {
if (IsCb0Offset(address, baseAddressCbOffset)) if (IsCbOffset(address, cbSlot, baseAddressCbOffset))
{ {
// Direct offset: zero. // Direct offset: zero.
return (Const(0), 0); return (Const(0), 0);
@ -275,7 +273,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
address = Utils.FindLastOperation(address, block); address = Utils.FindLastOperation(address, block);
if (IsCb0Offset(address, baseAddressCbOffset)) if (IsCbOffset(address, cbSlot, baseAddressCbOffset))
{ {
// Only constant offset // Only constant offset
return (Const(0), constantOffset); return (Const(0), constantOffset);
@ -289,11 +287,11 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
Operand src1 = offsetAdd.GetSource(0); Operand src1 = offsetAdd.GetSource(0);
Operand src2 = Utils.FindLastOperation(offsetAdd.GetSource(1), block); Operand src2 = Utils.FindLastOperation(offsetAdd.GetSource(1), block);
if (IsCb0Offset(src2, baseAddressCbOffset)) if (IsCbOffset(src2, cbSlot, baseAddressCbOffset))
{ {
return (src1, constantOffset); return (src1, constantOffset);
} }
else if (IsCb0Offset(src1, baseAddressCbOffset)) else if (IsCbOffset(src1, cbSlot, baseAddressCbOffset))
{ {
return (src2, constantOffset); return (src2, constantOffset);
} }