diff options
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/CodeGen/Glsl')
8 files changed, 251 insertions, 233 deletions
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/CodeGenContext.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/CodeGenContext.cs index 551e5cef..7506f72a 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/CodeGenContext.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/CodeGenContext.cs @@ -12,7 +12,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl public StructuredProgramInfo Info { get; } - public ShaderConfig Config { get; } + public AttributeUsage AttributeUsage { get; } + public ShaderDefinitions Definitions { get; } + public ShaderProperties Properties { get; } + public HostCapabilities HostCapabilities { get; } + public ILogger Logger { get; } + public TargetApi TargetApi { get; } public OperandManager OperandManager { get; } @@ -22,10 +27,15 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl private string _indentation; - public CodeGenContext(StructuredProgramInfo info, ShaderConfig config) + public CodeGenContext(StructuredProgramInfo info, CodeGenParameters parameters) { Info = info; - Config = config; + AttributeUsage = parameters.AttributeUsage; + Definitions = parameters.Definitions; + Properties = parameters.Properties; + HostCapabilities = parameters.HostCapabilities; + Logger = parameters.Logger; + TargetApi = parameters.TargetApi; OperandManager = new OperandManager(); 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"); diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs index 0140c1b9..469c4f0a 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs @@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl { private const string MainFunctionName = "main"; - public static string Generate(StructuredProgramInfo info, ShaderConfig config) + public static string Generate(StructuredProgramInfo info, CodeGenParameters parameters) { - CodeGenContext context = new(info, config); + CodeGenContext context = new(info, parameters); Declarations.Declare(context, info); @@ -113,7 +113,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl } }; - bool supportsBarrierDivergence = context.Config.GpuAccessor.QueryHostSupportsShaderBarrierDivergence(); + bool supportsBarrierDivergence = context.HostCapabilities.SupportsShaderBarrierDivergence; bool mayHaveReturned = false; foreach (IAstNode node in visitor.Visit()) @@ -128,7 +128,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl // so skip emitting the barrier for those cases. if (visitor.Block.Type != AstBlockType.Main || mayHaveReturned || !isMainFunction) { - context.Config.GpuAccessor.Log($"Shader has barrier on potentially divergent block, the barrier will be removed."); + context.Logger.Log("Shader has barrier on potentially divergent block, the barrier will be removed."); continue; } diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenBallot.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenBallot.cs index 9a2bfef0..b44759c0 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenBallot.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenBallot.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions string arg = GetSoureExpr(context, operation.GetSource(0), dstType); - if (context.Config.GpuAccessor.QueryHostSupportsShaderBallot()) + if (context.HostCapabilities.SupportsShaderBallot) { return $"unpackUint2x32(ballotARB({arg})).x"; } diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenFSI.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenFSI.cs index a3d68028..1697aa47 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenFSI.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenFSI.cs @@ -4,11 +4,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions { public static string FSIBegin(CodeGenContext context) { - if (context.Config.GpuAccessor.QueryHostSupportsFragmentShaderInterlock()) + if (context.HostCapabilities.SupportsFragmentShaderInterlock) { return "beginInvocationInterlockARB()"; } - else if (context.Config.GpuAccessor.QueryHostSupportsFragmentShaderOrderingIntel()) + else if (context.HostCapabilities.SupportsFragmentShaderOrderingIntel) { return "beginFragmentShaderOrderingINTEL()"; } @@ -18,7 +18,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions public static string FSIEnd(CodeGenContext context) { - if (context.Config.GpuAccessor.QueryHostSupportsFragmentShaderInterlock()) + if (context.HostCapabilities.SupportsFragmentShaderInterlock) { return "endInvocationInterlockARB()"; } diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs index 7e6d8bb5..a1f92d11 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs @@ -84,7 +84,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions indexExpr = Src(AggregateType.S32); } - string imageName = GetImageName(context.Config, texOp, indexExpr); + string imageName = GetImageName(context.Properties, texOp, indexExpr); texCallBuilder.Append('('); texCallBuilder.Append(imageName); @@ -216,7 +216,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions indexExpr = GetSoureExpr(context, texOp.GetSource(0), AggregateType.S32); } - string samplerName = GetSamplerName(context.Config, texOp, indexExpr); + string samplerName = GetSamplerName(context.Properties, texOp, indexExpr); int coordsIndex = isBindless || isIndexed ? 1 : 0; @@ -273,7 +273,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions // 2D Array and Cube shadow samplers with LOD level or bias requires an extension. // If the extension is not supported, just remove the LOD parameter. - if (isArray && isShadow && (is2D || isCube) && !context.Config.GpuAccessor.QueryHostSupportsTextureShadowLod()) + if (isArray && isShadow && (is2D || isCube) && !context.HostCapabilities.SupportsTextureShadowLod) { hasLodBias = false; hasLodLevel = false; @@ -281,7 +281,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions // Cube shadow samplers with LOD level requires an extension. // If the extension is not supported, just remove the LOD level parameter. - if (isShadow && isCube && !context.Config.GpuAccessor.QueryHostSupportsTextureShadowLod()) + if (isShadow && isCube && !context.HostCapabilities.SupportsTextureShadowLod) { hasLodLevel = false; } @@ -342,7 +342,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions indexExpr = Src(AggregateType.S32); } - string samplerName = GetSamplerName(context.Config, texOp, indexExpr); + string samplerName = GetSamplerName(context.Properties, texOp, indexExpr); texCall += "(" + samplerName; @@ -538,7 +538,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions indexExpr = GetSoureExpr(context, texOp.GetSource(0), AggregateType.S32); } - string samplerName = GetSamplerName(context.Config, texOp, indexExpr); + string samplerName = GetSamplerName(context.Properties, texOp, indexExpr); if (texOp.Index == 3) { @@ -546,7 +546,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions } else { - context.Config.Properties.Textures.TryGetValue(texOp.Binding, out TextureDefinition definition); + context.Properties.Textures.TryGetValue(texOp.Binding, out TextureDefinition definition); bool hasLod = !definition.Type.HasFlag(SamplerType.Multisample) && (definition.Type & SamplerType.Mask) != SamplerType.TextureBuffer; string texCall; @@ -593,8 +593,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions int binding = bindingIndex.Value; BufferDefinition buffer = storageKind == StorageKind.ConstantBuffer - ? context.Config.Properties.ConstantBuffers[binding] - : context.Config.Properties.StorageBuffers[binding]; + ? context.Properties.ConstantBuffers[binding] + : context.Properties.StorageBuffers[binding]; if (operation.GetSource(srcIndex++) is not AstOperand fieldIndex || fieldIndex.Type != OperandType.Constant) { @@ -614,8 +614,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions } MemoryDefinition memory = storageKind == StorageKind.LocalMemory - ? context.Config.Properties.LocalMemories[bindingId.Value] - : context.Config.Properties.SharedMemories[bindingId.Value]; + ? context.Properties.LocalMemories[bindingId.Value] + : context.Properties.SharedMemories[bindingId.Value]; varName = memory.Name; varType = memory.Type; @@ -636,7 +636,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions int location = -1; int component = 0; - if (context.Config.HasPerLocationInputOrOutput(ioVariable, isOutput)) + if (context.Definitions.HasPerLocationInputOrOutput(ioVariable, isOutput)) { if (operation.GetSource(srcIndex++) is not AstOperand vecIndex || vecIndex.Type != OperandType.Constant) { @@ -648,16 +648,23 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions if (operation.SourcesCount > srcIndex && operation.GetSource(srcIndex) is AstOperand elemIndex && elemIndex.Type == OperandType.Constant && - context.Config.HasPerLocationInputOrOutputComponent(ioVariable, location, elemIndex.Value, isOutput)) + context.Definitions.HasPerLocationInputOrOutputComponent(ioVariable, location, elemIndex.Value, isOutput)) { component = elemIndex.Value; srcIndex++; } } - (varName, varType) = IoMap.GetGlslVariable(context.Config, ioVariable, location, component, isOutput, isPerPatch); + (varName, varType) = IoMap.GetGlslVariable( + context.Definitions, + context.HostCapabilities, + ioVariable, + location, + component, + isOutput, + isPerPatch); - if (IoMap.IsPerVertexBuiltIn(context.Config.Stage, ioVariable, isOutput)) + if (IoMap.IsPerVertexBuiltIn(context.Definitions.Stage, ioVariable, isOutput)) { // Since those exist both as input and output on geometry and tessellation shaders, // we need the gl_in and gl_out prefixes to disambiguate. @@ -692,7 +699,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions { varName += "." + "xyzw"[elementIndex.Value & 3]; } - else if (srcIndex == firstSrcIndex && context.Config.Stage == ShaderStage.TessellationControl && storageKind == StorageKind.Output) + else if (srcIndex == firstSrcIndex && context.Definitions.Stage == ShaderStage.TessellationControl && storageKind == StorageKind.Output) { // GLSL requires that for tessellation control shader outputs, // that the index expression must be *exactly* "gl_InvocationID", @@ -715,9 +722,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions return varName; } - private static string GetSamplerName(ShaderConfig config, AstTextureOperation texOp, string indexExpr) + private static string GetSamplerName(ShaderProperties resourceDefinitions, AstTextureOperation texOp, string indexExpr) { - string name = config.Properties.Textures[texOp.Binding].Name; + string name = resourceDefinitions.Textures[texOp.Binding].Name; if (texOp.Type.HasFlag(SamplerType.Indexed)) { @@ -727,9 +734,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions return name; } - private static string GetImageName(ShaderConfig config, AstTextureOperation texOp, string indexExpr) + private static string GetImageName(ShaderProperties resourceDefinitions, AstTextureOperation texOp, string indexExpr) { - string name = config.Properties.Images[texOp.Binding].Name; + string name = resourceDefinitions.Images[texOp.Binding].Name; if (texOp.Type.HasFlag(SamplerType.Indexed)) { diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/IoMap.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/IoMap.cs index 3f88d2b3..b5f453ae 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/IoMap.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/IoMap.cs @@ -7,7 +7,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions static class IoMap { public static (string, AggregateType) GetGlslVariable( - ShaderConfig config, + ShaderDefinitions definitions, + HostCapabilities hostCapabilities, IoVariable ioVariable, int location, int component, @@ -25,7 +26,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions IoVariable.DrawIndex => ("gl_DrawIDARB", AggregateType.S32), IoVariable.FogCoord => ("gl_FogFragCoord", AggregateType.FP32), // Deprecated. IoVariable.FragmentCoord => ("gl_FragCoord", AggregateType.Vector4 | AggregateType.FP32), - IoVariable.FragmentOutputColor => GetFragmentOutputColorVariableName(config, location), + IoVariable.FragmentOutputColor => GetFragmentOutputColorVariableName(definitions, location), IoVariable.FragmentOutputDepth => ("gl_FragDepth", AggregateType.FP32), IoVariable.FrontColorDiffuse => ("gl_FrontColor", AggregateType.Vector4 | AggregateType.FP32), // Deprecated. IoVariable.FrontColorSpecular => ("gl_FrontSecondaryColor", AggregateType.Vector4 | AggregateType.FP32), // Deprecated. @@ -38,20 +39,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions IoVariable.PointCoord => ("gl_PointCoord", AggregateType.Vector2 | AggregateType.FP32), IoVariable.PointSize => ("gl_PointSize", AggregateType.FP32), IoVariable.Position => ("gl_Position", AggregateType.Vector4 | AggregateType.FP32), - IoVariable.PrimitiveId => GetPrimitiveIdVariableName(config.Stage, isOutput), - IoVariable.SubgroupEqMask => GetSubgroupMaskVariableName(config, "Eq"), - IoVariable.SubgroupGeMask => GetSubgroupMaskVariableName(config, "Ge"), - IoVariable.SubgroupGtMask => GetSubgroupMaskVariableName(config, "Gt"), - IoVariable.SubgroupLaneId => GetSubgroupInvocationIdVariableName(config), - IoVariable.SubgroupLeMask => GetSubgroupMaskVariableName(config, "Le"), - IoVariable.SubgroupLtMask => GetSubgroupMaskVariableName(config, "Lt"), + IoVariable.PrimitiveId => GetPrimitiveIdVariableName(definitions.Stage, isOutput), + IoVariable.SubgroupEqMask => GetSubgroupMaskVariableName(hostCapabilities.SupportsShaderBallot, "Eq"), + IoVariable.SubgroupGeMask => GetSubgroupMaskVariableName(hostCapabilities.SupportsShaderBallot, "Ge"), + IoVariable.SubgroupGtMask => GetSubgroupMaskVariableName(hostCapabilities.SupportsShaderBallot, "Gt"), + IoVariable.SubgroupLaneId => GetSubgroupInvocationIdVariableName(hostCapabilities.SupportsShaderBallot), + IoVariable.SubgroupLeMask => GetSubgroupMaskVariableName(hostCapabilities.SupportsShaderBallot, "Le"), + IoVariable.SubgroupLtMask => GetSubgroupMaskVariableName(hostCapabilities.SupportsShaderBallot, "Lt"), IoVariable.TessellationCoord => ("gl_TessCoord", AggregateType.Vector3 | AggregateType.FP32), IoVariable.TessellationLevelInner => ("gl_TessLevelInner", AggregateType.Array | AggregateType.FP32), IoVariable.TessellationLevelOuter => ("gl_TessLevelOuter", AggregateType.Array | AggregateType.FP32), IoVariable.TextureCoord => ("gl_TexCoord", AggregateType.Array | AggregateType.Vector4 | AggregateType.FP32), // Deprecated. IoVariable.ThreadId => ("gl_LocalInvocationID", AggregateType.Vector3 | AggregateType.U32), IoVariable.ThreadKill => ("gl_HelperInvocation", AggregateType.Bool), - IoVariable.UserDefined => GetUserDefinedVariableName(config, location, component, isOutput, isPerPatch), + IoVariable.UserDefined => GetUserDefinedVariableName(definitions, location, component, isOutput, isPerPatch), IoVariable.VertexId => ("gl_VertexID", AggregateType.S32), IoVariable.VertexIndex => ("gl_VertexIndex", AggregateType.S32), IoVariable.ViewportIndex => ("gl_ViewportIndex", AggregateType.S32), @@ -86,16 +87,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions return false; } - private static (string, AggregateType) GetFragmentOutputColorVariableName(ShaderConfig config, int location) + private static (string, AggregateType) GetFragmentOutputColorVariableName(ShaderDefinitions definitions, int location) { if (location < 0) { - return (DefaultNames.OAttributePrefix, config.GetFragmentOutputColorType(0)); + return (DefaultNames.OAttributePrefix, definitions.GetFragmentOutputColorType(0)); } string name = DefaultNames.OAttributePrefix + location.ToString(CultureInfo.InvariantCulture); - return (name, config.GetFragmentOutputColorType(location)); + return (name, definitions.GetFragmentOutputColorType(location)); } private static (string, AggregateType) GetPrimitiveIdVariableName(ShaderStage stage, bool isOutput) @@ -104,21 +105,21 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions return (isOutput || stage != ShaderStage.Geometry ? "gl_PrimitiveID" : "gl_PrimitiveIDIn", AggregateType.S32); } - private static (string, AggregateType) GetSubgroupMaskVariableName(ShaderConfig config, string cc) + private static (string, AggregateType) GetSubgroupMaskVariableName(bool supportsShaderBallot, string cc) { - return config.GpuAccessor.QueryHostSupportsShaderBallot() + return supportsShaderBallot ? ($"unpackUint2x32(gl_SubGroup{cc}MaskARB)", AggregateType.Vector2 | AggregateType.U32) : ($"gl_Subgroup{cc}Mask", AggregateType.Vector4 | AggregateType.U32); } - private static (string, AggregateType) GetSubgroupInvocationIdVariableName(ShaderConfig config) + private static (string, AggregateType) GetSubgroupInvocationIdVariableName(bool supportsShaderBallot) { - return config.GpuAccessor.QueryHostSupportsShaderBallot() + return supportsShaderBallot ? ("gl_SubGroupInvocationARB", AggregateType.U32) : ("gl_SubgroupInvocationID", AggregateType.U32); } - private static (string, AggregateType) GetUserDefinedVariableName(ShaderConfig config, int location, int component, bool isOutput, bool isPerPatch) + private static (string, AggregateType) GetUserDefinedVariableName(ShaderDefinitions definitions, int location, int component, bool isOutput, bool isPerPatch) { string name = isPerPatch ? DefaultNames.PerPatchAttributePrefix @@ -126,17 +127,17 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions if (location < 0) { - return (name, config.GetUserDefinedType(0, isOutput)); + return (name, definitions.GetUserDefinedType(0, isOutput)); } name += location.ToString(CultureInfo.InvariantCulture); - if (config.HasPerLocationInputOrOutputComponent(IoVariable.UserDefined, location, component, isOutput)) + if (definitions.HasPerLocationInputOrOutputComponent(IoVariable.UserDefined, location, component, isOutput)) { name += "_" + "xyzw"[component & 3]; } - return (name, config.GetUserDefinedType(location, isOutput)); + return (name, definitions.GetUserDefinedType(location, isOutput)); } } } diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs index 9346341f..53ecc453 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs @@ -68,8 +68,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl } BufferDefinition buffer = operation.StorageKind == StorageKind.ConstantBuffer - ? context.Config.Properties.ConstantBuffers[bindingIndex.Value] - : context.Config.Properties.StorageBuffers[bindingIndex.Value]; + ? context.Properties.ConstantBuffers[bindingIndex.Value] + : context.Properties.StorageBuffers[bindingIndex.Value]; StructureField field = buffer.Type.Fields[fieldIndex.Value]; return field.Type & AggregateType.ElementTypeMask; @@ -82,8 +82,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl } MemoryDefinition memory = operation.StorageKind == StorageKind.LocalMemory - ? context.Config.Properties.LocalMemories[bindingId.Value] - : context.Config.Properties.SharedMemories[bindingId.Value]; + ? context.Properties.LocalMemories[bindingId.Value] + : context.Properties.SharedMemories[bindingId.Value]; return memory.Type & AggregateType.ElementTypeMask; @@ -102,7 +102,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl int location = 0; int component = 0; - if (context.Config.HasPerLocationInputOrOutput(ioVariable, isOutput)) + if (context.Definitions.HasPerLocationInputOrOutput(ioVariable, isOutput)) { if (operation.GetSource(1) is not AstOperand vecIndex || vecIndex.Type != OperandType.Constant) { @@ -114,13 +114,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl if (operation.SourcesCount > 2 && operation.GetSource(2) is AstOperand elemIndex && elemIndex.Type == OperandType.Constant && - context.Config.HasPerLocationInputOrOutputComponent(ioVariable, location, elemIndex.Value, isOutput)) + context.Definitions.HasPerLocationInputOrOutputComponent(ioVariable, location, elemIndex.Value, isOutput)) { component = elemIndex.Value; } } - (_, AggregateType varType) = IoMap.GetGlslVariable(context.Config, ioVariable, location, component, isOutput, isPerPatch); + (_, AggregateType varType) = IoMap.GetGlslVariable( + context.Definitions, + context.HostCapabilities, + ioVariable, + location, + component, + isOutput, + isPerPatch); return varType & AggregateType.ElementTypeMask; } |