diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2023-08-13 22:26:42 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-13 22:26:42 -0300 |
| commit | b423197619dd8d9dda1c255a76105bf30e255dae (patch) | |
| tree | e3898b3b1672f022b5de4522b51bd21583043996 /src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions | |
| parent | 8edfb2bc7b8507d0ef51f0544eb32a65f0bf54a1 (diff) | |
Delete ShaderConfig and organize shader resources/definitions better (#5509)
* Move some properties out of ShaderConfig
* Stop using ShaderConfig on backends
* Replace ShaderConfig usages on Translator and passes
* Move remaining properties out of ShaderConfig and delete ShaderConfig
* Remove ResourceManager property from TranslatorContext
* Move Rewriter passes to separate transform pass files
* Fix TransformPasses.RunPass on cases where a node is removed
* Move remaining ClipDistancePrimitivesWritten and UsedFeatures updates to decode stage
* Reduce excessive parameter passing a bit by using structs more
* Remove binding parameter from ShaderProperties methods since it is redundant
* Replace decoder instruction checks with switch statement
* Put GLSL on the same plan as SPIR-V for input/output declaration
* Stop mutating TranslatorContext state when Translate is called
* Pass most of the graphics state using a struct instead of individual query methods
* Auto-format
* Auto-format
* Add backend logging interface
* Auto-format
* Remove unnecessary use of interpolated strings
* Remove more modifications of AttributeUsage after decode
* PR feedback
* gl_Layer is not supported on compute
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions')
4 files changed, 53 insertions, 45 deletions
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)); } } } |
