aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs')
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs75
1 files changed, 31 insertions, 44 deletions
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
index 958f1cef..08e8eb19 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
@@ -71,40 +71,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine($"const int {DefaultNames.UndefinedName} = 0;");
context.AppendLine();
- if (context.Config.Stage == ShaderStage.Compute)
- {
- int localMemorySize = BitUtils.DivRoundUp(context.Config.GpuAccessor.QueryComputeLocalMemorySize(), 4);
-
- if (localMemorySize != 0)
- {
- string localMemorySizeStr = NumberFormatter.FormatInt(localMemorySize);
-
- context.AppendLine($"uint {DefaultNames.LocalMemoryName}[{localMemorySizeStr}];");
- context.AppendLine();
- }
-
- int sharedMemorySize = BitUtils.DivRoundUp(context.Config.GpuAccessor.QueryComputeSharedMemorySize(), 4);
-
- if (sharedMemorySize != 0)
- {
- string sharedMemorySizeStr = NumberFormatter.FormatInt(sharedMemorySize);
-
- context.AppendLine($"shared uint {DefaultNames.SharedMemoryName}[{sharedMemorySizeStr}];");
- context.AppendLine();
- }
- }
- else if (context.Config.LocalMemorySize != 0)
- {
- int localMemorySize = BitUtils.DivRoundUp(context.Config.LocalMemorySize, 4);
-
- string localMemorySizeStr = NumberFormatter.FormatInt(localMemorySize);
-
- context.AppendLine($"uint {DefaultNames.LocalMemoryName}[{localMemorySizeStr}];");
- context.AppendLine();
- }
-
DeclareConstantBuffers(context, context.Config.Properties.ConstantBuffers.Values);
DeclareStorageBuffers(context, context.Config.Properties.StorageBuffers.Values);
+ DeclareMemories(context, context.Config.Properties.LocalMemories.Values, isShared: false);
+ DeclareMemories(context, context.Config.Properties.SharedMemories.Values, isShared: true);
var textureDescriptors = context.Config.GetTextureDescriptors();
if (textureDescriptors.Length != 0)
@@ -238,11 +208,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine();
}
- if ((info.HelperFunctionsMask & HelperFunctionsMask.AtomicMinMaxS32Shared) != 0)
- {
- AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Shared.glsl");
- }
-
if ((info.HelperFunctionsMask & HelperFunctionsMask.MultiplyHighS32) != 0)
{
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/MultiplyHighS32.glsl");
@@ -273,11 +238,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/ShuffleXor.glsl");
}
- if ((info.HelperFunctionsMask & HelperFunctionsMask.StoreSharedSmallInt) != 0)
- {
- AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreSharedSmallInt.glsl");
- }
-
if ((info.HelperFunctionsMask & HelperFunctionsMask.SwizzleAdd) != 0)
{
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/SwizzleAdd.glsl");
@@ -358,7 +318,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
_ => "std430"
};
- context.AppendLine($"layout (binding = {buffer.Binding}, {layout}) {declType} _{buffer.Name}");
+ string set = string.Empty;
+
+ if (context.Config.Options.TargetApi == TargetApi.Vulkan)
+ {
+ set = $"set = {buffer.Set}, ";
+ }
+
+ context.AppendLine($"layout ({set}binding = {buffer.Binding}, {layout}) {declType} _{buffer.Name}");
context.EnterScope();
foreach (StructureField field in buffer.Type.Fields)
@@ -391,6 +358,27 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
}
+ private static void DeclareMemories(CodeGenContext context, IEnumerable<MemoryDefinition> memories, bool isShared)
+ {
+ string prefix = isShared ? "shared " : string.Empty;
+
+ foreach (MemoryDefinition memory in memories)
+ {
+ string typeName = GetVarTypeName(context, memory.Type & ~AggregateType.Array);
+
+ if (memory.ArrayLength > 0)
+ {
+ string arraySize = memory.ArrayLength.ToString(CultureInfo.InvariantCulture);
+
+ context.AppendLine($"{prefix}{typeName} {memory.Name}[{arraySize}];");
+ }
+ else
+ {
+ context.AppendLine($"{prefix}{typeName} {memory.Name}[];");
+ }
+ }
+ }
+
private static void DeclareSamplers(CodeGenContext context, TextureDescriptor[] descriptors)
{
int arraySize = 0;
@@ -717,7 +705,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
string code = EmbeddedResources.ReadAllText(filename);
code = code.Replace("\t", CodeGenContext.Tab);
- code = code.Replace("$SHARED_MEM$", DefaultNames.SharedMemoryName);
if (context.Config.GpuAccessor.QueryHostSupportsShaderBallot())
{