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.cs341
1 files changed, 167 insertions, 174 deletions
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
index 2a45e23d..e181ae98 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
@@ -1,4 +1,5 @@
using Ryujinx.Common;
+using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using Ryujinx.Graphics.Shader.StructuredIr;
using Ryujinx.Graphics.Shader.Translation;
using System;
@@ -13,10 +14,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
{
public static void Declare(CodeGenContext context, StructuredProgramInfo info)
{
- context.AppendLine(context.Config.Options.TargetApi == TargetApi.Vulkan ? "#version 460 core" : "#version 450 core");
+ context.AppendLine(context.TargetApi == TargetApi.Vulkan ? "#version 460 core" : "#version 450 core");
context.AppendLine("#extension GL_ARB_gpu_shader_int64 : enable");
- if (context.Config.GpuAccessor.QueryHostSupportsShaderBallot())
+ if (context.HostCapabilities.SupportsShaderBallot)
{
context.AppendLine("#extension GL_ARB_shader_ballot : enable");
}
@@ -30,24 +31,24 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine("#extension GL_EXT_shader_image_load_formatted : enable");
context.AppendLine("#extension GL_EXT_texture_shadow_lod : enable");
- if (context.Config.Stage == ShaderStage.Compute)
+ if (context.Definitions.Stage == ShaderStage.Compute)
{
context.AppendLine("#extension GL_ARB_compute_shader : enable");
}
- else if (context.Config.Stage == ShaderStage.Fragment)
+ else if (context.Definitions.Stage == ShaderStage.Fragment)
{
- if (context.Config.GpuAccessor.QueryHostSupportsFragmentShaderInterlock())
+ if (context.HostCapabilities.SupportsFragmentShaderInterlock)
{
context.AppendLine("#extension GL_ARB_fragment_shader_interlock : enable");
}
- else if (context.Config.GpuAccessor.QueryHostSupportsFragmentShaderOrderingIntel())
+ else if (context.HostCapabilities.SupportsFragmentShaderOrderingIntel)
{
context.AppendLine("#extension GL_INTEL_fragment_shader_ordering : enable");
}
}
else
{
- if (context.Config.Stage == ShaderStage.Vertex)
+ if (context.Definitions.Stage == ShaderStage.Vertex)
{
context.AppendLine("#extension GL_ARB_shader_draw_parameters : enable");
}
@@ -55,12 +56,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine("#extension GL_ARB_shader_viewport_layer_array : enable");
}
- if (context.Config.GpPassthrough && context.Config.GpuAccessor.QueryHostSupportsGeometryShaderPassthrough())
+ if (context.Definitions.GpPassthrough && context.HostCapabilities.SupportsGeometryShaderPassthrough)
{
context.AppendLine("#extension GL_NV_geometry_shader_passthrough : enable");
}
- if (context.Config.GpuAccessor.QueryHostSupportsViewportMask())
+ if (context.HostCapabilities.SupportsViewportMask)
{
context.AppendLine("#extension GL_NV_viewport_array2 : enable");
}
@@ -71,23 +72,22 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine($"const int {DefaultNames.UndefinedName} = 0;");
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);
- DeclareSamplers(context, context.Config.Properties.Textures.Values);
- DeclareImages(context, context.Config.Properties.Images.Values);
+ DeclareConstantBuffers(context, context.Properties.ConstantBuffers.Values);
+ DeclareStorageBuffers(context, context.Properties.StorageBuffers.Values);
+ DeclareMemories(context, context.Properties.LocalMemories.Values, isShared: false);
+ DeclareMemories(context, context.Properties.SharedMemories.Values, isShared: true);
+ DeclareSamplers(context, context.Properties.Textures.Values);
+ DeclareImages(context, context.Properties.Images.Values);
- if (context.Config.Stage != ShaderStage.Compute)
+ if (context.Definitions.Stage != ShaderStage.Compute)
{
- if (context.Config.Stage == ShaderStage.Geometry)
+ if (context.Definitions.Stage == ShaderStage.Geometry)
{
- InputTopology inputTopology = context.Config.GpuAccessor.QueryPrimitiveTopology();
- string inPrimitive = inputTopology.ToGlslString();
+ string inPrimitive = context.Definitions.InputTopology.ToGlslString();
- context.AppendLine($"layout (invocations = {context.Config.ThreadsPerInputPrimitive}, {inPrimitive}) in;");
+ context.AppendLine($"layout (invocations = {context.Definitions.ThreadsPerInputPrimitive}, {inPrimitive}) in;");
- if (context.Config.GpPassthrough && context.Config.GpuAccessor.QueryHostSupportsGeometryShaderPassthrough())
+ if (context.Definitions.GpPassthrough && context.HostCapabilities.SupportsGeometryShaderPassthrough)
{
context.AppendLine($"layout (passthrough) in gl_PerVertex");
context.EnterScope();
@@ -98,87 +98,75 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
else
{
- string outPrimitive = context.Config.OutputTopology.ToGlslString();
+ string outPrimitive = context.Definitions.OutputTopology.ToGlslString();
- int maxOutputVertices = context.Config.GpPassthrough
- ? inputTopology.ToInputVertices()
- : context.Config.MaxOutputVertices;
+ int maxOutputVertices = context.Definitions.GpPassthrough
+ ? context.Definitions.InputTopology.ToInputVertices()
+ : context.Definitions.MaxOutputVertices;
context.AppendLine($"layout ({outPrimitive}, max_vertices = {maxOutputVertices}) out;");
}
context.AppendLine();
}
- else if (context.Config.Stage == ShaderStage.TessellationControl)
+ else if (context.Definitions.Stage == ShaderStage.TessellationControl)
{
- int threadsPerInputPrimitive = context.Config.ThreadsPerInputPrimitive;
+ int threadsPerInputPrimitive = context.Definitions.ThreadsPerInputPrimitive;
context.AppendLine($"layout (vertices = {threadsPerInputPrimitive}) out;");
context.AppendLine();
}
- else if (context.Config.Stage == ShaderStage.TessellationEvaluation)
+ else if (context.Definitions.Stage == ShaderStage.TessellationEvaluation)
{
- bool tessCw = context.Config.GpuAccessor.QueryTessCw();
+ bool tessCw = context.Definitions.TessCw;
- if (context.Config.Options.TargetApi == TargetApi.Vulkan)
+ if (context.TargetApi == TargetApi.Vulkan)
{
// We invert the front face on Vulkan backend, so we need to do that here aswell.
tessCw = !tessCw;
}
- string patchType = context.Config.GpuAccessor.QueryTessPatchType().ToGlsl();
- string spacing = context.Config.GpuAccessor.QueryTessSpacing().ToGlsl();
+ string patchType = context.Definitions.TessPatchType.ToGlsl();
+ string spacing = context.Definitions.TessSpacing.ToGlsl();
string windingOrder = tessCw ? "cw" : "ccw";
context.AppendLine($"layout ({patchType}, {spacing}, {windingOrder}) in;");
context.AppendLine();
}
- if (context.Config.UsedInputAttributes != 0 || context.Config.GpPassthrough)
+ static bool IsUserDefined(IoDefinition ioDefinition, StorageKind storageKind)
{
- DeclareInputAttributes(context, info);
-
- context.AppendLine();
+ return ioDefinition.StorageKind == storageKind && ioDefinition.IoVariable == IoVariable.UserDefined;
}
- if (context.Config.UsedOutputAttributes != 0 || context.Config.Stage != ShaderStage.Fragment)
+ static bool IsUserDefinedOutput(ShaderStage stage, IoDefinition ioDefinition)
{
- DeclareOutputAttributes(context, info);
-
- context.AppendLine();
+ IoVariable ioVariable = stage == ShaderStage.Fragment ? IoVariable.FragmentOutputColor : IoVariable.UserDefined;
+ return ioDefinition.StorageKind == StorageKind.Output && ioDefinition.IoVariable == ioVariable;
}
- if (context.Config.UsedInputAttributesPerPatch.Count != 0)
- {
- DeclareInputAttributesPerPatch(context, context.Config.UsedInputAttributesPerPatch);
-
- context.AppendLine();
- }
-
- if (context.Config.UsedOutputAttributesPerPatch.Count != 0)
- {
- DeclareUsedOutputAttributesPerPatch(context, context.Config.UsedOutputAttributesPerPatch);
-
- context.AppendLine();
- }
+ DeclareInputAttributes(context, info.IoDefinitions.Where(x => IsUserDefined(x, StorageKind.Input)));
+ DeclareOutputAttributes(context, info.IoDefinitions.Where(x => IsUserDefinedOutput(context.Definitions.Stage, x)));
+ DeclareInputAttributesPerPatch(context, info.IoDefinitions.Where(x => IsUserDefined(x, StorageKind.InputPerPatch)));
+ DeclareOutputAttributesPerPatch(context, info.IoDefinitions.Where(x => IsUserDefined(x, StorageKind.OutputPerPatch)));
- if (context.Config.TransformFeedbackEnabled && context.Config.LastInVertexPipeline)
+ if (context.Definitions.TransformFeedbackEnabled && context.Definitions.LastInVertexPipeline)
{
- var tfOutput = context.Config.GetTransformFeedbackOutput(AttributeConsts.PositionX);
+ var tfOutput = context.Definitions.GetTransformFeedbackOutput(AttributeConsts.PositionX);
if (tfOutput.Valid)
{
context.AppendLine($"layout (xfb_buffer = {tfOutput.Buffer}, xfb_offset = {tfOutput.Offset}, xfb_stride = {tfOutput.Stride}) out gl_PerVertex");
context.EnterScope();
context.AppendLine("vec4 gl_Position;");
- context.LeaveScope(context.Config.Stage == ShaderStage.TessellationControl ? " gl_out[];" : ";");
+ context.LeaveScope(context.Definitions.Stage == ShaderStage.TessellationControl ? " gl_out[];" : ";");
}
}
}
else
{
- string localSizeX = NumberFormatter.FormatInt(context.Config.GpuAccessor.QueryComputeLocalSizeX());
- string localSizeY = NumberFormatter.FormatInt(context.Config.GpuAccessor.QueryComputeLocalSizeY());
- string localSizeZ = NumberFormatter.FormatInt(context.Config.GpuAccessor.QueryComputeLocalSizeZ());
+ string localSizeX = NumberFormatter.FormatInt(context.Definitions.ComputeLocalSizeX);
+ string localSizeY = NumberFormatter.FormatInt(context.Definitions.ComputeLocalSizeY);
+ string localSizeZ = NumberFormatter.FormatInt(context.Definitions.ComputeLocalSizeZ);
context.AppendLine(
"layout (" +
@@ -188,15 +176,15 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine();
}
- if (context.Config.Stage == ShaderStage.Fragment)
+ if (context.Definitions.Stage == ShaderStage.Fragment)
{
- if (context.Config.GpuAccessor.QueryEarlyZForce())
+ if (context.Definitions.EarlyZForce)
{
context.AppendLine("layout (early_fragment_tests) in;");
context.AppendLine();
}
- if (context.Config.Properties.OriginUpperLeft)
+ if (context.Definitions.OriginUpperLeft)
{
context.AppendLine("layout (origin_upper_left) in vec4 gl_FragCoord;");
context.AppendLine();
@@ -251,7 +239,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
public static string GetVarTypeName(CodeGenContext context, AggregateType type, bool precise = true)
{
- if (context.Config.GpuAccessor.QueryHostReducedPrecision())
+ if (context.HostCapabilities.ReducedPrecision)
{
precise = false;
}
@@ -305,7 +293,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
string set = string.Empty;
- if (context.Config.Options.TargetApi == TargetApi.Vulkan)
+ if (context.TargetApi == TargetApi.Vulkan)
{
set = $"set = {buffer.Set}, ";
}
@@ -390,7 +378,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
string layout = string.Empty;
- if (context.Config.Options.TargetApi == TargetApi.Vulkan)
+ if (context.TargetApi == TargetApi.Vulkan)
{
layout = $", set = {definition.Set}";
}
@@ -435,7 +423,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
layout = ", " + layout;
}
- if (context.Config.Options.TargetApi == TargetApi.Vulkan)
+ if (context.TargetApi == TargetApi.Vulkan)
{
layout = $", set = {definition.Set}{layout}";
}
@@ -444,42 +432,50 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
}
- private static void DeclareInputAttributes(CodeGenContext context, StructuredProgramInfo info)
+ private static void DeclareInputAttributes(CodeGenContext context, IEnumerable<IoDefinition> inputs)
{
- if (context.Config.UsedFeatures.HasFlag(FeatureFlags.IaIndexing))
+ if (context.Definitions.IaIndexing)
{
- string suffix = context.Config.Stage == ShaderStage.Geometry ? "[]" : string.Empty;
+ string suffix = context.Definitions.Stage == ShaderStage.Geometry ? "[]" : string.Empty;
context.AppendLine($"layout (location = 0) in vec4 {DefaultNames.IAttributePrefix}{suffix}[{Constants.MaxAttributes}];");
+ context.AppendLine();
}
else
{
- int usedAttributes = context.Config.UsedInputAttributes | context.Config.PassthroughAttributes;
- while (usedAttributes != 0)
+ foreach (var ioDefinition in inputs.OrderBy(x => x.Location))
{
- int index = BitOperations.TrailingZeroCount(usedAttributes);
- DeclareInputAttribute(context, info, index);
- usedAttributes &= ~(1 << index);
+ DeclareInputAttribute(context, ioDefinition.Location, ioDefinition.Component);
+ }
+
+ if (inputs.Any())
+ {
+ context.AppendLine();
}
}
}
- private static void DeclareInputAttributesPerPatch(CodeGenContext context, HashSet<int> attrs)
+ private static void DeclareInputAttributesPerPatch(CodeGenContext context, IEnumerable<IoDefinition> inputs)
{
- foreach (int attr in attrs.Order())
+ foreach (var ioDefinition in inputs.OrderBy(x => x.Location))
{
- DeclareInputAttributePerPatch(context, attr);
+ DeclareInputAttributePerPatch(context, ioDefinition.Location);
+ }
+
+ if (inputs.Any())
+ {
+ context.AppendLine();
}
}
- private static void DeclareInputAttribute(CodeGenContext context, StructuredProgramInfo info, int attr)
+ private static void DeclareInputAttribute(CodeGenContext context, int location, int component)
{
- string suffix = IsArrayAttributeGlsl(context.Config.Stage, isOutAttr: false) ? "[]" : string.Empty;
+ string suffix = IsArrayAttributeGlsl(context.Definitions.Stage, isOutAttr: false) ? "[]" : string.Empty;
string iq = string.Empty;
- if (context.Config.Stage == ShaderStage.Fragment)
+ if (context.Definitions.Stage == ShaderStage.Fragment)
{
- iq = context.Config.ImapTypes[attr].GetFirstUsedType() switch
+ iq = context.Definitions.ImapTypes[location].GetFirstUsedType() switch
{
PixelImap.Constant => "flat ",
PixelImap.ScreenLinear => "noperspective ",
@@ -487,14 +483,22 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
};
}
- string name = $"{DefaultNames.IAttributePrefix}{attr}";
+ string name = $"{DefaultNames.IAttributePrefix}{location}";
- if (context.Config.TransformFeedbackEnabled && context.Config.Stage == ShaderStage.Fragment)
+ if (context.Definitions.TransformFeedbackEnabled && context.Definitions.Stage == ShaderStage.Fragment)
{
- int components = context.Config.GetTransformFeedbackOutputComponents(attr, 0);
+ bool hasComponent = context.Definitions.HasPerLocationInputOrOutputComponent(IoVariable.UserDefined, location, component, isOutput: false);
- if (components > 1)
+ if (hasComponent)
{
+ char swzMask = "xyzw"[component];
+
+ context.AppendLine($"layout (location = {location}, component = {component}) {iq}in float {name}_{swzMask}{suffix};");
+ }
+ else
+ {
+ int components = context.Definitions.GetTransformFeedbackOutputComponents(location, 0);
+
string type = components switch
{
2 => "vec2",
@@ -503,147 +507,152 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
_ => "float",
};
- context.AppendLine($"layout (location = {attr}) in {type} {name};");
- }
-
- for (int c = components > 1 ? components : 0; c < 4; c++)
- {
- char swzMask = "xyzw"[c];
-
- context.AppendLine($"layout (location = {attr}, component = {c}) {iq}in float {name}_{swzMask}{suffix};");
+ context.AppendLine($"layout (location = {location}) in {type} {name};");
}
}
else
{
- bool passthrough = (context.Config.PassthroughAttributes & (1 << attr)) != 0;
- string pass = passthrough && context.Config.GpuAccessor.QueryHostSupportsGeometryShaderPassthrough() ? "passthrough, " : string.Empty;
- string type;
+ bool passthrough = (context.AttributeUsage.PassthroughAttributes & (1 << location)) != 0;
+ string pass = passthrough && context.HostCapabilities.SupportsGeometryShaderPassthrough ? "passthrough, " : string.Empty;
+ string type = GetVarTypeName(context, context.Definitions.GetUserDefinedType(location, isOutput: false), false);
- if (context.Config.Stage == ShaderStage.Vertex)
- {
- type = context.Config.GpuAccessor.QueryAttributeType(attr).ToVec4Type();
- }
- else
- {
- type = AttributeType.Float.ToVec4Type();
- }
-
- context.AppendLine($"layout ({pass}location = {attr}) {iq}in {type} {name}{suffix};");
+ context.AppendLine($"layout ({pass}location = {location}) {iq}in {type} {name}{suffix};");
}
}
- private static void DeclareInputAttributePerPatch(CodeGenContext context, int attr)
+ private static void DeclareInputAttributePerPatch(CodeGenContext context, int patchLocation)
{
- int location = context.Config.GetPerPatchAttributeLocation(attr);
- string name = $"{DefaultNames.PerPatchAttributePrefix}{attr}";
+ int location = context.AttributeUsage.GetPerPatchAttributeLocation(patchLocation);
+ string name = $"{DefaultNames.PerPatchAttributePrefix}{patchLocation}";
context.AppendLine($"layout (location = {location}) patch in vec4 {name};");
}
- private static void DeclareOutputAttributes(CodeGenContext context, StructuredProgramInfo info)
+ private static void DeclareOutputAttributes(CodeGenContext context, IEnumerable<IoDefinition> outputs)
{
- if (context.Config.UsedFeatures.HasFlag(FeatureFlags.OaIndexing))
+ if (context.Definitions.OaIndexing)
{
context.AppendLine($"layout (location = 0) out vec4 {DefaultNames.OAttributePrefix}[{Constants.MaxAttributes}];");
+ context.AppendLine();
}
else
{
- int usedAttributes = context.Config.UsedOutputAttributes;
+ outputs = outputs.OrderBy(x => x.Location);
- if (context.Config.Stage == ShaderStage.Fragment && context.Config.GpuAccessor.QueryDualSourceBlendEnable())
+ if (context.Definitions.Stage == ShaderStage.Fragment && context.Definitions.DualSourceBlend)
{
- int firstOutput = BitOperations.TrailingZeroCount(usedAttributes);
- int mask = 3 << firstOutput;
+ IoDefinition firstOutput = outputs.ElementAtOrDefault(0);
+ IoDefinition secondOutput = outputs.ElementAtOrDefault(1);
- if ((usedAttributes & mask) == mask)
+ if (firstOutput.Location + 1 == secondOutput.Location)
{
- usedAttributes &= ~mask;
- DeclareOutputDualSourceBlendAttribute(context, firstOutput);
+ DeclareOutputDualSourceBlendAttribute(context, firstOutput.Location);
+ outputs = outputs.Skip(2);
}
}
- while (usedAttributes != 0)
+ foreach (var ioDefinition in outputs)
{
- int index = BitOperations.TrailingZeroCount(usedAttributes);
- DeclareOutputAttribute(context, index);
- usedAttributes &= ~(1 << index);
+ DeclareOutputAttribute(context, ioDefinition.Location, ioDefinition.Component);
+ }
+
+ if (outputs.Any())
+ {
+ context.AppendLine();
}
}
}
- private static void DeclareOutputAttribute(CodeGenContext context, int attr)
+ private static void DeclareOutputAttribute(CodeGenContext context, int location, int component)
{
- string suffix = IsArrayAttributeGlsl(context.Config.Stage, isOutAttr: true) ? "[]" : string.Empty;
- string name = $"{DefaultNames.OAttributePrefix}{attr}{suffix}";
+ string suffix = IsArrayAttributeGlsl(context.Definitions.Stage, isOutAttr: true) ? "[]" : string.Empty;
+ string name = $"{DefaultNames.OAttributePrefix}{location}{suffix}";
- if (context.Config.TransformFeedbackEnabled && context.Config.LastInVertexPipeline)
+ if (context.Definitions.TransformFeedbackEnabled && context.Definitions.LastInVertexPipeline)
{
- int components = context.Config.GetTransformFeedbackOutputComponents(attr, 0);
+ bool hasComponent = context.Definitions.HasPerLocationInputOrOutputComponent(IoVariable.UserDefined, location, component, isOutput: true);
- if (components > 1)
+ if (hasComponent)
{
- string type = components switch
- {
- 2 => "vec2",
- 3 => "vec3",
- 4 => "vec4",
- _ => "float",
- };
+ char swzMask = "xyzw"[component];
string xfb = string.Empty;
- var tfOutput = context.Config.GetTransformFeedbackOutput(attr, 0);
+ var tfOutput = context.Definitions.GetTransformFeedbackOutput(location, component);
if (tfOutput.Valid)
{
xfb = $", xfb_buffer = {tfOutput.Buffer}, xfb_offset = {tfOutput.Offset}, xfb_stride = {tfOutput.Stride}";
}
- context.AppendLine($"layout (location = {attr}{xfb}) out {type} {name};");
+ context.AppendLine($"layout (location = {location}, component = {component}{xfb}) out float {name}_{swzMask};");
}
-
- for (int c = components > 1 ? components : 0; c < 4; c++)
+ else
{
- char swzMask = "xyzw"[c];
+ int components = context.Definitions.GetTransformFeedbackOutputComponents(location, 0);
+
+ string type = components switch
+ {
+ 2 => "vec2",
+ 3 => "vec3",
+ 4 => "vec4",
+ _ => "float",
+ };
string xfb = string.Empty;
- var tfOutput = context.Config.GetTransformFeedbackOutput(attr, c);
+ var tfOutput = context.Definitions.GetTransformFeedbackOutput(location, 0);
if (tfOutput.Valid)
{
xfb = $", xfb_buffer = {tfOutput.Buffer}, xfb_offset = {tfOutput.Offset}, xfb_stride = {tfOutput.Stride}";
}
- context.AppendLine($"layout (location = {attr}, component = {c}{xfb}) out float {name}_{swzMask};");
+ context.AppendLine($"layout (location = {location}{xfb}) out {type} {name};");
}
}
else
{
- string type = context.Config.Stage != ShaderStage.Fragment ? "vec4" :
- context.Config.GpuAccessor.QueryFragmentOutputType(attr) switch
- {
- AttributeType.Sint => "ivec4",
- AttributeType.Uint => "uvec4",
- _ => "vec4",
- };
+ string type = context.Definitions.Stage != ShaderStage.Fragment ? "vec4" :
+ GetVarTypeName(context, context.Definitions.GetFragmentOutputColorType(location), false);
- if (context.Config.GpuAccessor.QueryHostReducedPrecision() && context.Config.Stage == ShaderStage.Vertex && attr == 0)
+ if (context.HostCapabilities.ReducedPrecision && context.Definitions.Stage == ShaderStage.Vertex && location == 0)
{
- context.AppendLine($"layout (location = {attr}) invariant out {type} {name};");
+ context.AppendLine($"layout (location = {location}) invariant out {type} {name};");
}
else
{
- context.AppendLine($"layout (location = {attr}) out {type} {name};");
+ context.AppendLine($"layout (location = {location}) out {type} {name};");
}
}
}
- private static void DeclareOutputDualSourceBlendAttribute(CodeGenContext context, int attr)
+ private static void DeclareOutputDualSourceBlendAttribute(CodeGenContext context, int location)
+ {
+ string name = $"{DefaultNames.OAttributePrefix}{location}";
+ string name2 = $"{DefaultNames.OAttributePrefix}{(location + 1)}";
+
+ context.AppendLine($"layout (location = {location}, index = 0) out vec4 {name};");
+ context.AppendLine($"layout (location = {location}, index = 1) out vec4 {name2};");
+ }
+
+ private static void DeclareOutputAttributesPerPatch(CodeGenContext context, IEnumerable<IoDefinition> outputs)
+ {
+ foreach (var ioDefinition in outputs)
+ {
+ DeclareOutputAttributePerPatch(context, ioDefinition.Location);
+ }
+
+ if (outputs.Any())
+ {
+ context.AppendLine();
+ }
+ }
+
+ private static void DeclareOutputAttributePerPatch(CodeGenContext context, int patchLocation)
{
- string name = $"{DefaultNames.OAttributePrefix}{attr}";
- string name2 = $"{DefaultNames.OAttributePrefix}{(attr + 1)}";
+ int location = context.AttributeUsage.GetPerPatchAttributeLocation(patchLocation);
+ string name = $"{DefaultNames.PerPatchAttributePrefix}{patchLocation}";
- context.AppendLine($"layout (location = {attr}, index = 0) out vec4 {name};");
- context.AppendLine($"layout (location = {attr}, index = 1) out vec4 {name2};");
+ context.AppendLine($"layout (location = {location}) patch out vec4 {name};");
}
private static bool IsArrayAttributeGlsl(ShaderStage stage, bool isOutAttr)
@@ -660,29 +669,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
}
- private static void DeclareUsedOutputAttributesPerPatch(CodeGenContext context, HashSet<int> attrs)
- {
- foreach (int attr in attrs.Order())
- {
- DeclareOutputAttributePerPatch(context, attr);
- }
- }
-
- private static void DeclareOutputAttributePerPatch(CodeGenContext context, int attr)
- {
- int location = context.Config.GetPerPatchAttributeLocation(attr);
- string name = $"{DefaultNames.PerPatchAttributePrefix}{attr}";
-
- context.AppendLine($"layout (location = {location}) patch out vec4 {name};");
- }
-
private static void AppendHelperFunction(CodeGenContext context, string filename)
{
string code = EmbeddedResources.ReadAllText(filename);
code = code.Replace("\t", CodeGenContext.Tab);
- if (context.Config.GpuAccessor.QueryHostSupportsShaderBallot())
+ if (context.HostCapabilities.SupportsShaderBallot)
{
code = code.Replace("$SUBGROUP_INVOCATION$", "gl_SubGroupInvocationARB");
code = code.Replace("$SUBGROUP_BROADCAST$", "readInvocationARB");