diff --git a/Ryujinx.Graphics.Gpu/Engine/Compute.cs b/Ryujinx.Graphics.Gpu/Engine/Compute.cs index f0daac678..61e6b3260 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Compute.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Compute.cs @@ -22,6 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Engine ComputeShader cs = _shaderCache.GetComputeShader( shaderGpuVa, + dispatchParams.SharedMemorySize & 0xffff, dispatchParams.UnpackBlockSizeX(), dispatchParams.UnpackBlockSizeY(), dispatchParams.UnpackBlockSizeZ()); diff --git a/Ryujinx.Graphics.Gpu/Engine/ComputeParams.cs b/Ryujinx.Graphics.Gpu/Engine/ComputeParams.cs index 77e60aa48..5644ca818 100644 --- a/Ryujinx.Graphics.Gpu/Engine/ComputeParams.cs +++ b/Ryujinx.Graphics.Gpu/Engine/ComputeParams.cs @@ -39,7 +39,7 @@ namespace Ryujinx.Graphics.Gpu.Engine public int Unknown14; public int Unknown15; public int Unknown16; - public int Unknown17; + public int SharedMemorySize; public int BlockSizeX; public int BlockSizeYZ; public int UniformBuffersConfig; diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index 027757980..7b9c20eb1 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -32,7 +32,7 @@ namespace Ryujinx.Graphics.Gpu.Shader _gpPrograms = new Dictionary>(); } - public ComputeShader GetComputeShader(ulong gpuVa, int localSizeX, int localSizeY, int localSizeZ) + public ComputeShader GetComputeShader(ulong gpuVa, int sharedMemorySize, int localSizeX, int localSizeY, int localSizeZ) { bool isCached = _cpPrograms.TryGetValue(gpuVa, out List list); @@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.Gpu.Shader } } - CachedShader shader = TranslateComputeShader(gpuVa, localSizeX, localSizeY, localSizeZ); + CachedShader shader = TranslateComputeShader(gpuVa, sharedMemorySize, localSizeX, localSizeY, localSizeZ); IShader hostShader = _context.Renderer.CompileShader(shader.Program); @@ -192,7 +192,7 @@ namespace Ryujinx.Graphics.Gpu.Shader return false; } - private CachedShader TranslateComputeShader(ulong gpuVa, int localSizeX, int localSizeY, int localSizeZ) + private CachedShader TranslateComputeShader(ulong gpuVa, int sharedMemorySize, int localSizeX, int localSizeY, int localSizeZ) { if (gpuVa == 0) { @@ -212,6 +212,8 @@ namespace Ryujinx.Graphics.Gpu.Shader int[] codeCached = MemoryMarshal.Cast(code.Slice(0, program.Size)).ToArray(); + program.Replace(DefineNames.SharedMemorySize, sharedMemorySize.ToString(CultureInfo.InvariantCulture)); + program.Replace(DefineNames.LocalSizeX, localSizeX.ToString(CultureInfo.InvariantCulture)); program.Replace(DefineNames.LocalSizeY, localSizeY.ToString(CultureInfo.InvariantCulture)); program.Replace(DefineNames.LocalSizeZ, localSizeZ.ToString(CultureInfo.InvariantCulture)); diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs index 1c3cf2459..b96aa1aeb 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs @@ -75,7 +75,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl if (context.Config.Stage == ShaderStage.Compute) { - string size = NumberFormatter.FormatInt(context.Config.Capabilities.MaximumComputeSharedMemorySize / 4); + string size; + + if ((context.Config.Flags & TranslationFlags.Unspecialized) != 0) + { + size = DefineNames.SharedMemorySize; + } + else + { + size = NumberFormatter.FormatInt(context.Config.Capabilities.MaximumComputeSharedMemorySize / 4); + } context.AppendLine($"shared uint {DefaultNames.SharedMemoryName}[{size}];"); context.AppendLine(); diff --git a/Ryujinx.Graphics.Shader/DefineNames.cs b/Ryujinx.Graphics.Shader/DefineNames.cs index f55cbd0cc..67e8e1ee3 100644 --- a/Ryujinx.Graphics.Shader/DefineNames.cs +++ b/Ryujinx.Graphics.Shader/DefineNames.cs @@ -6,6 +6,8 @@ namespace Ryujinx.Graphics.Shader public const string OutQualifierPrefixName = "S_OUT_QUALIFIER"; + public const string SharedMemorySize = "S_SHARED_MEMORY_SIZE"; + public const string LocalSizeX = "S_LOCAL_SIZE_X"; public const string LocalSizeY = "S_LOCAL_SIZE_Y"; public const string LocalSizeZ = "S_LOCAL_SIZE_Z";