aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs25
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs5
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs10
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Varying.cs69
4 files changed, 97 insertions, 12 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
index f9d61928..efd30143 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
@@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
public static void Declare(CodeGenContext context, StructuredProgramInfo info)
{
- context.AppendLine("#version 430 core");
+ context.AppendLine("#version 440 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");
@@ -234,7 +234,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
string stage = OperandManager.GetShaderStagePrefix(context.Config.Stage);
int scaleElements = context.TextureDescriptors.Count;
-
+
if (context.Config.Stage == ShaderStage.Fragment)
{
scaleElements++; // Also includes render target scale, for gl_FragCoord.
@@ -424,7 +424,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
};
}
- context.AppendLine($"layout (location = {attr}) {iq}in vec4 {DefaultNames.IAttributePrefix}{attr}{suffix};");
+ for (int c = 0; c < 4; c++)
+ {
+ char swzMask = "xyzw"[c];
+
+ context.AppendLine($"layout (location = {attr}, component = {c}) {iq}in float {DefaultNames.IAttributePrefix}{attr}_{swzMask}{suffix};");
+ }
}
}
@@ -452,12 +457,22 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
{
for (int attr = 0; attr < MaxAttributes; attr++)
{
- context.AppendLine($"layout (location = {attr}) out vec4 {DefaultNames.OAttributePrefix}{attr};");
+ for (int c = 0; c < 4; c++)
+ {
+ char swzMask = "xyzw"[c];
+
+ context.AppendLine($"layout (location = {attr}, component = {c}) out float {DefaultNames.OAttributePrefix}{attr}_{swzMask};");
+ }
}
foreach (int attr in info.OAttributes.OrderBy(x => x).Where(x => x >= MaxAttributes))
{
- context.AppendLine($"layout (location = {attr}) out vec4 {DefaultNames.OAttributePrefix}{attr};");
+ for (int c = 0; c < 4; c++)
+ {
+ char swzMask = "xyzw"[c];
+
+ context.AppendLine($"layout (location = {attr}, component = {c}) out float {DefaultNames.OAttributePrefix}{attr}_{swzMask};");
+ }
}
}
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs
index 1465338e..2105560a 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs
@@ -56,7 +56,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
continue;
}
- context.AppendLine($"{DefaultNames.OAttributePrefix}{attr} = vec4(0);");
+ context.AppendLine($"{DefaultNames.OAttributePrefix}{attr}_x = 0;");
+ context.AppendLine($"{DefaultNames.OAttributePrefix}{attr}_y = 0;");
+ context.AppendLine($"{DefaultNames.OAttributePrefix}{attr}_z = 0;");
+ context.AppendLine($"{DefaultNames.OAttributePrefix}{attr}_w = 0;");
}
}
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
index 971284f4..8801fc11 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
@@ -147,7 +147,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
{
int value = attr.Value;
- string swzMask = GetSwizzleMask((value >> 2) & 3);
+ char swzMask = GetSwizzleMask((value >> 2) & 3);
if (value >= AttributeConsts.UserAttributeBase &&
value < AttributeConsts.UserAttributeEnd)
@@ -158,15 +158,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
? DefaultNames.OAttributePrefix
: DefaultNames.IAttributePrefix;
- string name = $"{prefix}{(value >> 4)}";
+ string name = $"{prefix}{(value >> 4)}_{swzMask}";
if (stage == ShaderStage.Geometry && !isOutAttr)
{
name += $"[{indexExpr}]";
}
- name += "." + swzMask;
-
return name;
}
else
@@ -264,9 +262,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
return _stagePrefixes[index];
}
- private static string GetSwizzleMask(int value)
+ private static char GetSwizzleMask(int value)
{
- return "xyzw".Substring(value, 1);
+ return "xyzw"[value];
}
public static VariableType GetNodeDestType(IAstNode node)
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Varying.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Varying.cs
new file mode 100644
index 00000000..b9b2afb4
--- /dev/null
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Varying.cs
@@ -0,0 +1,69 @@
+using Ryujinx.Graphics.Shader.Translation;
+
+namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
+{
+ public static class Varying
+ {
+ public static string GetName(int offset)
+ {
+ offset <<= 2;
+
+ if (offset >= AttributeConsts.UserAttributeBase &&
+ offset < AttributeConsts.UserAttributeEnd)
+ {
+ offset -= AttributeConsts.UserAttributeBase;
+
+ string name = $"{ DefaultNames.OAttributePrefix}{(offset >> 4)}";
+
+ name += "_" + "xyzw"[(offset >> 2) & 3];
+
+ return name;
+ }
+
+ switch (offset)
+ {
+ case AttributeConsts.PositionX:
+ case AttributeConsts.PositionY:
+ case AttributeConsts.PositionZ:
+ case AttributeConsts.PositionW:
+ return "gl_Position";
+ case AttributeConsts.PointSize:
+ return "gl_PointSize";
+ case AttributeConsts.ClipDistance0:
+ return "gl_ClipDistance[0]";
+ case AttributeConsts.ClipDistance1:
+ return "gl_ClipDistance[1]";
+ case AttributeConsts.ClipDistance2:
+ return "gl_ClipDistance[2]";
+ case AttributeConsts.ClipDistance3:
+ return "gl_ClipDistance[3]";
+ case AttributeConsts.ClipDistance4:
+ return "gl_ClipDistance[4]";
+ case AttributeConsts.ClipDistance5:
+ return "gl_ClipDistance[5]";
+ case AttributeConsts.ClipDistance6:
+ return "gl_ClipDistance[6]";
+ case AttributeConsts.ClipDistance7:
+ return "gl_ClipDistance[7]";
+ case AttributeConsts.VertexId:
+ return "gl_VertexID";
+ }
+
+ return null;
+ }
+
+ public static int GetSize(int offset)
+ {
+ switch (offset << 2)
+ {
+ case AttributeConsts.PositionX:
+ case AttributeConsts.PositionY:
+ case AttributeConsts.PositionZ:
+ case AttributeConsts.PositionW:
+ return 4;
+ }
+
+ return 1;
+ }
+ }
+} \ No newline at end of file