From c30c609624461abe136f0cbbbe29720c3c2d9209 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 1 Aug 2024 11:52:14 +0100 Subject: [PATCH] Image Constant Fixes Allows Mario Party Superstars to boot --- src/Ryujinx.Graphics.Metal/Constants.cs | 3 +++ src/Ryujinx.Graphics.Metal/EncoderState.cs | 4 ++-- .../EncoderStateManager.cs | 14 ++++++------- src/Ryujinx.Graphics.Metal/MetalRenderer.cs | 2 +- src/Ryujinx.Graphics.Metal/Pipeline.cs | 20 ++++++------------- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/Constants.cs b/src/Ryujinx.Graphics.Metal/Constants.cs index 133925e2d..43baf722a 100644 --- a/src/Ryujinx.Graphics.Metal/Constants.cs +++ b/src/Ryujinx.Graphics.Metal/Constants.cs @@ -7,9 +7,12 @@ namespace Ryujinx.Graphics.Metal public const int MaxUniformBuffersPerStage = 18; public const int MaxStorageBuffersPerStage = 16; public const int MaxTexturesPerStage = 64; + public const int MaxImagesPerStage = 16; + public const int MaxUniformBufferBindings = MaxUniformBuffersPerStage * MaxShaderStages; public const int MaxStorageBufferBindings = MaxStorageBuffersPerStage * MaxShaderStages; public const int MaxTextureBindings = MaxTexturesPerStage * MaxShaderStages; + public const int MaxImageBindings = MaxImagesPerStage * MaxShaderStages; public const int MaxColorAttachments = 8; public const int MaxViewports = 16; // TODO: Check this value diff --git a/src/Ryujinx.Graphics.Metal/EncoderState.cs b/src/Ryujinx.Graphics.Metal/EncoderState.cs index 8d408d847..a99a6f35a 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderState.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderState.cs @@ -106,8 +106,8 @@ namespace Ryujinx.Graphics.Metal public readonly BufferRef[] UniformBufferRefs = new BufferRef[Constants.MaxUniformBufferBindings]; public readonly BufferRef[] StorageBufferRefs = new BufferRef[Constants.MaxStorageBufferBindings]; - public readonly TextureRef[] TextureRefs = new TextureRef[Constants.MaxTextureBindings]; - public readonly ImageRef[] ImageRefs = new ImageRef[Constants.MaxTextureBindings]; + public readonly TextureRef[] TextureRefs = new TextureRef[Constants.MaxTextureBindings * 2]; + public readonly ImageRef[] ImageRefs = new ImageRef[Constants.MaxImageBindings * 2]; public ArrayRef[] TextureArrayRefs = []; public ArrayRef[] ImageArrayRefs = []; diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index 41a4140fd..0d3df86c7 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -802,7 +802,7 @@ namespace Ryujinx.Graphics.Metal SignalDirty(DirtyFlags.StencilRef); } - public readonly void UpdateTextureAndSampler(ShaderStage stage, ulong binding, TextureBase texture, Sampler sampler) + public readonly void UpdateTextureAndSampler(ShaderStage stage, int binding, TextureBase texture, Sampler sampler) { if (texture != null) { @@ -816,9 +816,9 @@ namespace Ryujinx.Graphics.Metal SignalDirty(DirtyFlags.Textures); } - public readonly void UpdateImage(ShaderStage stage, ulong binding, TextureBase texture) + public readonly void UpdateImage(ShaderStage stage, int binding, TextureBase image) { - if (texture is Texture view) + if (image is Texture view) { _currentState.ImageRefs[binding] = new(stage, view); } @@ -830,9 +830,9 @@ namespace Ryujinx.Graphics.Metal SignalDirty(DirtyFlags.Images); } - public void UpdateTextureArray(ShaderStage stage, ulong binding, TextureArray array) + public void UpdateTextureArray(ShaderStage stage, int binding, TextureArray array) { - ref EncoderState.ArrayRef arrayRef = ref GetArrayRef(ref _currentState.TextureArrayRefs, (int)binding, ArrayGrowthSize); + ref EncoderState.ArrayRef arrayRef = ref GetArrayRef(ref _currentState.TextureArrayRefs, binding, ArrayGrowthSize); if (arrayRef.Stage != stage || arrayRef.Array != array) { @@ -854,9 +854,9 @@ namespace Ryujinx.Graphics.Metal } } - public void UpdateImageArray(ShaderStage stage, ulong binding, ImageArray array) + public void UpdateImageArray(ShaderStage stage, int binding, ImageArray array) { - ref EncoderState.ArrayRef arrayRef = ref GetArrayRef(ref _currentState.ImageArrayRefs, (int)binding, ArrayGrowthSize); + ref EncoderState.ArrayRef arrayRef = ref GetArrayRef(ref _currentState.ImageArrayRefs, binding, ArrayGrowthSize); if (arrayRef.Stage != stage || arrayRef.Array != array) { diff --git a/src/Ryujinx.Graphics.Metal/MetalRenderer.cs b/src/Ryujinx.Graphics.Metal/MetalRenderer.cs index 35e721e94..6bdc043bf 100644 --- a/src/Ryujinx.Graphics.Metal/MetalRenderer.cs +++ b/src/Ryujinx.Graphics.Metal/MetalRenderer.cs @@ -197,7 +197,7 @@ namespace Ryujinx.Graphics.Metal maximumUniformBuffersPerStage: Constants.MaxUniformBuffersPerStage, maximumStorageBuffersPerStage: Constants.MaxStorageBuffersPerStage, maximumTexturesPerStage: Constants.MaxTexturesPerStage, - maximumImagesPerStage: Constants.MaxTextureBindings, + maximumImagesPerStage: Constants.MaxImagesPerStage, maximumComputeSharedMemorySize: (int)_device.MaxThreadgroupMemoryLength, maximumSupportedAnisotropy: 0, shaderSubgroupSize: 256, diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 15b87fb46..a4654d36a 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -540,13 +540,11 @@ namespace Ryujinx.Graphics.Metal _encoderStateManager.UpdateIndexBuffer(buffer, type); } - public void SetImage(ShaderStage stage, int binding, ITexture texture, Format imageFormat) + public void SetImage(ShaderStage stage, int binding, ITexture image, Format imageFormat) { - if (texture is TextureBase tex) + if (image is TextureBase img) { - var index = (ulong)binding; - - _encoderStateManager.UpdateImage(stage, index, tex); + _encoderStateManager.UpdateImage(stage, binding, img); } } @@ -554,9 +552,7 @@ namespace Ryujinx.Graphics.Metal { if (array is ImageArray imageArray) { - var index = (ulong)binding; - - _encoderStateManager.UpdateImageArray(stage, index, imageArray); + _encoderStateManager.UpdateImageArray(stage, binding, imageArray); } } @@ -665,9 +661,7 @@ namespace Ryujinx.Graphics.Metal { if (sampler == null || sampler is Sampler) { - var index = (ulong)binding; - - _encoderStateManager.UpdateTextureAndSampler(stage, index, tex, (Sampler)sampler); + _encoderStateManager.UpdateTextureAndSampler(stage, binding, tex, (Sampler)sampler); } } } @@ -676,9 +670,7 @@ namespace Ryujinx.Graphics.Metal { if (array is TextureArray textureArray) { - var index = (ulong)binding; - - _encoderStateManager.UpdateTextureArray(stage, index, textureArray); + _encoderStateManager.UpdateTextureArray(stage, binding, textureArray); } }