diff options
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs')
-rw-r--r-- | src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs | 76 |
1 files changed, 54 insertions, 22 deletions
diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs index 2433aeb2..0f043f77 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs @@ -205,7 +205,12 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } } - public static void RunPass(HelperFunctionManager hfm, BasicBlock[] blocks, ShaderConfig config) + public static void RunPass( + HelperFunctionManager hfm, + BasicBlock[] blocks, + ResourceManager resourceManager, + IGpuAccessor gpuAccessor, + TargetLanguage targetLanguage) { GtsContext gtsContext = new(hfm); @@ -220,14 +225,20 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations if (IsGlobalMemory(operation.StorageKind)) { - LinkedListNode<INode> nextNode = ReplaceGlobalMemoryWithStorage(gtsContext, config, block, node); + LinkedListNode<INode> nextNode = ReplaceGlobalMemoryWithStorage( + gtsContext, + resourceManager, + gpuAccessor, + targetLanguage, + block, + node); if (nextNode == null) { // The returned value being null means that the global memory replacement failed, // so we just make loads read 0 and stores do nothing. - config.GpuAccessor.Log($"Failed to reserve storage buffer for global memory operation \"{operation.Inst}\"."); + gpuAccessor.Log($"Failed to reserve storage buffer for global memory operation \"{operation.Inst}\"."); if (operation.Dest != null) { @@ -286,7 +297,9 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations private static LinkedListNode<INode> ReplaceGlobalMemoryWithStorage( GtsContext gtsContext, - ShaderConfig config, + ResourceManager resourceManager, + IGpuAccessor gpuAccessor, + TargetLanguage targetLanguage, BasicBlock block, LinkedListNode<INode> node) { @@ -303,7 +316,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations Operand offset = result.Offset; - bool storageUnaligned = config.GpuAccessor.QueryHasUnalignedStorageBuffer(); + bool storageUnaligned = gpuAccessor.QueryHasUnalignedStorageBuffer(); if (storageUnaligned) { @@ -312,7 +325,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations Operand baseAddressMasked = Local(); Operand hostOffset = Local(); - int alignment = config.GpuAccessor.QueryHostStorageBufferOffsetAlignment(); + int alignment = gpuAccessor.QueryHostStorageBufferOffsetAlignment(); Operation maskOp = new(Instruction.BitwiseAnd, baseAddressMasked, baseAddress, Const(-alignment)); Operation subOp = new(Instruction.Subtract, hostOffset, globalAddress, baseAddressMasked); @@ -333,13 +346,19 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations offset = newOffset; } - if (CanUseInlineStorageOp(operation, config.Options.TargetLanguage)) + if (CanUseInlineStorageOp(operation, targetLanguage)) { - return GenerateInlineStorageOp(config, node, operation, offset, result); + return GenerateInlineStorageOp(resourceManager, node, operation, offset, result); } else { - if (!TryGenerateSingleTargetStorageOp(gtsContext, config, operation, result, out int functionId)) + if (!TryGenerateSingleTargetStorageOp( + gtsContext, + resourceManager, + targetLanguage, + operation, + result, + out int functionId)) { return null; } @@ -354,7 +373,14 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations // the base address might be stored. // Generate a helper function that will check all possible storage buffers and use the right one. - if (!TryGenerateMultiTargetStorageOp(gtsContext, config, block, operation, out int functionId)) + if (!TryGenerateMultiTargetStorageOp( + gtsContext, + resourceManager, + gpuAccessor, + targetLanguage, + block, + operation, + out int functionId)) { return null; } @@ -375,14 +401,14 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } private static LinkedListNode<INode> GenerateInlineStorageOp( - ShaderConfig config, + ResourceManager resourceManager, LinkedListNode<INode> node, Operation operation, Operand offset, SearchResult result) { bool isStore = operation.Inst == Instruction.Store || operation.Inst.IsAtomic(); - if (!config.ResourceManager.TryGetStorageBufferBinding(result.SbCbSlot, result.SbCbOffset, isStore, out int binding)) + if (!resourceManager.TryGetStorageBufferBinding(result.SbCbSlot, result.SbCbOffset, isStore, out int binding)) { return null; } @@ -474,7 +500,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations private static bool TryGenerateSingleTargetStorageOp( GtsContext gtsContext, - ShaderConfig config, + ResourceManager resourceManager, + TargetLanguage targetLanguage, Operation operation, SearchResult result, out int functionId) @@ -514,7 +541,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } if (!TryGenerateStorageOp( - config, + resourceManager, + targetLanguage, context, operation.Inst, operation.StorageKind, @@ -555,7 +583,9 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations private static bool TryGenerateMultiTargetStorageOp( GtsContext gtsContext, - ShaderConfig config, + ResourceManager resourceManager, + IGpuAccessor gpuAccessor, + TargetLanguage targetLanguage, BasicBlock block, Operation operation, out int functionId) @@ -624,7 +654,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations if (targetCbs.Count == 0) { - config.GpuAccessor.Log($"Failed to find storage buffer for global memory operation \"{operation.Inst}\"."); + gpuAccessor.Log($"Failed to find storage buffer for global memory operation \"{operation.Inst}\"."); } if (gtsContext.TryGetFunctionId(operation, isMultiTarget: true, targetCbs, out functionId)) @@ -685,13 +715,14 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations SearchResult result = new(sbCbSlot, sbCbOffset); - int alignment = config.GpuAccessor.QueryHostStorageBufferOffsetAlignment(); + int alignment = gpuAccessor.QueryHostStorageBufferOffsetAlignment(); Operand baseAddressMasked = context.BitwiseAnd(baseAddrLow, Const(-alignment)); Operand hostOffset = context.ISubtract(globalAddressLow, baseAddressMasked); if (!TryGenerateStorageOp( - config, + resourceManager, + targetLanguage, context, operation.Inst, operation.StorageKind, @@ -781,7 +812,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } private static bool TryGenerateStorageOp( - ShaderConfig config, + ResourceManager resourceManager, + TargetLanguage targetLanguage, EmitterContext context, Instruction inst, StorageKind storageKind, @@ -794,7 +826,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations resultValue = null; bool isStore = inst.IsAtomic() || inst == Instruction.Store; - if (!config.ResourceManager.TryGetStorageBufferBinding(result.SbCbSlot, result.SbCbOffset, isStore, out int binding)) + if (!resourceManager.TryGetStorageBufferBinding(result.SbCbSlot, result.SbCbOffset, isStore, out int binding)) { return false; } @@ -820,7 +852,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations resultValue = context.AtomicCompareAndSwap(StorageKind.StorageBuffer, binding, Const(0), wordOffset, compare, value); break; case Instruction.AtomicMaxS32: - if (config.Options.TargetLanguage == TargetLanguage.Spirv) + if (targetLanguage == TargetLanguage.Spirv) { resultValue = context.AtomicMaxS32(StorageKind.StorageBuffer, binding, Const(0), wordOffset, value); } @@ -836,7 +868,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations resultValue = context.AtomicMaxU32(StorageKind.StorageBuffer, binding, Const(0), wordOffset, value); break; case Instruction.AtomicMinS32: - if (config.Options.TargetLanguage == TargetLanguage.Spirv) + if (targetLanguage == TargetLanguage.Spirv) { resultValue = context.AtomicMinS32(StorageKind.StorageBuffer, binding, Const(0), wordOffset, value); } |