aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-11-08 17:29:41 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit769c02235f489f02b1791e6e76dc8b3ab18028ee (patch)
treeef0a2ffc5030360d5cef78e7c67e131e44348d50 /Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
parent1e8bc29f32cde08616175f8f87405dfa7b8c4025 (diff)
Add ATOMS, LDS, POPC, RED, STS and VOTE shader instructions, start changing the way how global memory is handled
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs70
1 files changed, 59 insertions, 11 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
index 6c4ba949..a8cabaaf 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
@@ -16,7 +16,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
public static void Declare(CodeGenContext context, StructuredProgramInfo info)
{
context.AppendLine("#version 420 core");
+ context.AppendLine("#extension GL_ARB_gpu_shader_int64 : enable");
context.AppendLine("#extension GL_ARB_shader_ballot : enable");
+ context.AppendLine("#extension GL_ARB_shader_group_vote : enable");
context.AppendLine("#extension GL_ARB_shader_storage_buffer_object : enable");
if (context.Config.Stage == ShaderStage.Compute)
@@ -66,9 +68,15 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine();
- context.AppendLine($"precise float {DefaultNames.LocalMemoryName}[0x100];");
+ context.AppendLine($"uint {DefaultNames.LocalMemoryName}[0x100];");
context.AppendLine();
+ if (context.Config.Stage == ShaderStage.Compute)
+ {
+ context.AppendLine($"shared uint {DefaultNames.SharedMemoryName}[0x100];");
+ context.AppendLine();
+ }
+
if (info.CBuffers.Count != 0)
{
DeclareUniforms(context, info);
@@ -78,7 +86,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
if (info.SBuffers.Count != 0)
{
- DeclareStorage(context, info);
+ DeclareUsedStorage(context, info);
context.AppendLine();
}
@@ -168,6 +176,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine(GetVarTypeName(decl.VarType) + " " + name + ";");
}
+
+ if ((info.HelperFunctionsMask & HelperFunctionsMask.GlobalMemory) != 0)
+ {
+ context.AppendLine($"ivec2 {DefaultNames.GmemOffsetName};");
+ }
}
private static string GetVarTypeName(VariableType type)
@@ -205,24 +218,59 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
}
- private static void DeclareStorage(CodeGenContext context, StructuredProgramInfo info)
+ private static void DeclareAllStorage(CodeGenContext context, StructuredProgramInfo info)
{
- foreach (int sbufSlot in info.SBuffers.OrderBy(x => x))
+ string sbName = OperandManager.GetShaderStagePrefix(context.Config.Stage);
+
+ sbName += "_" + DefaultNames.StorageNamePrefix;
+
+ string blockName = $"{sbName}_{DefaultNames.BlockSuffix}";
+
+ context.AppendLine("layout (std430) buffer " + blockName);
+
+ context.EnterScope();
+
+ context.AppendLine("uint " + DefaultNames.DataName + "[];");
+
+ string arraySize = NumberFormatter.FormatInt(Constants.MaxShaderStorageBuffers);
+
+ context.LeaveScope($" {sbName}[{arraySize}];");
+
+ for (int sbufSlot = 0; sbufSlot < Constants.MaxShaderStorageBuffers; sbufSlot++)
{
- string sbName = OperandManager.GetShaderStagePrefix(context.Config.Stage);
+ context.SBufferDescriptors.Add(new BufferDescriptor($"{blockName}[{sbufSlot}]", sbufSlot));
+ }
+ }
- sbName += "_" + DefaultNames.StorageNamePrefix + sbufSlot;
+ private static void DeclareUsedStorage(CodeGenContext context, StructuredProgramInfo info)
+ {
+ string sbName = OperandManager.GetShaderStagePrefix(context.Config.Stage);
- context.SBufferDescriptors.Add(new BufferDescriptor(sbName, sbufSlot));
+ sbName += "_" + DefaultNames.StorageNamePrefix;
- context.AppendLine("layout (std430) buffer " + sbName);
+ string blockName = $"{sbName}_{DefaultNames.BlockSuffix}";
- context.EnterScope();
+ int maxSlot = 0;
- context.AppendLine("precise float " + OperandManager.GetSbName(context.Config.Stage, sbufSlot) + "[];");
+ foreach (int sbufSlot in info.SBuffers)
+ {
+ context.SBufferDescriptors.Add(new BufferDescriptor($"{blockName}[{sbufSlot}]", sbufSlot));
- context.LeaveScope(";");
+ if (maxSlot < sbufSlot)
+ {
+ maxSlot = sbufSlot;
+ }
}
+
+ context.AppendLine("layout (std430) buffer " + blockName);
+
+ context.EnterScope();
+
+ context.AppendLine("uint " + DefaultNames.DataName + "[];");
+
+ string arraySize = NumberFormatter.FormatInt(maxSlot + 1);
+
+ context.LeaveScope($" {sbName}[{arraySize}];");
}
private static void DeclareSamplers(CodeGenContext context, StructuredProgramInfo info)