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/Spirv/Declarations.cs | |
parent | 8edfb2bc7b8507d0ef51f0544eb32a65f0bf54a1 (diff) |
Delete ShaderConfig and organize shader resources/definitions better (#5509)1.1.985
* 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/Spirv/Declarations.cs')
-rw-r--r-- | src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs index b14fead8..f3a083c3 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs @@ -5,7 +5,6 @@ using Spv.Generator; using System; using System.Collections.Generic; using System.Diagnostics; -using System.Numerics; using static Spv.Specification; using SpvInstruction = Spv.Generator.Instruction; @@ -66,12 +65,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv public static void DeclareAll(CodeGenContext context, StructuredProgramInfo info) { - DeclareConstantBuffers(context, context.Config.Properties.ConstantBuffers.Values); - DeclareStorageBuffers(context, context.Config.Properties.StorageBuffers.Values); - DeclareMemories(context, context.Config.Properties.LocalMemories, context.LocalMemories, StorageClass.Private); - DeclareMemories(context, context.Config.Properties.SharedMemories, context.SharedMemories, StorageClass.Workgroup); - 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, context.LocalMemories, StorageClass.Private); + DeclareMemories(context, context.Properties.SharedMemories, context.SharedMemories, StorageClass.Workgroup); + DeclareSamplers(context, context.Properties.Textures.Values); + DeclareImages(context, context.Properties.Images.Values); DeclareInputsAndOutputs(context, info); } @@ -108,7 +107,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv foreach (BufferDefinition buffer in buffers) { - int setIndex = context.Config.Options.TargetApi == TargetApi.Vulkan ? buffer.Set : 0; + int setIndex = context.TargetApi == TargetApi.Vulkan ? buffer.Set : 0; int alignment = buffer.Layout == BufferLayout.Std140 ? 16 : 4; int alignmentMask = alignment - 1; int offset = 0; @@ -181,7 +180,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv { foreach (var sampler in samplers) { - int setIndex = context.Config.Options.TargetApi == TargetApi.Vulkan ? sampler.Set : 0; + int setIndex = context.TargetApi == TargetApi.Vulkan ? sampler.Set : 0; var dim = (sampler.Type & SamplerType.Mask) switch { @@ -220,7 +219,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv { foreach (var image in images) { - int setIndex = context.Config.Options.TargetApi == TargetApi.Vulkan ? image.Set : 0; + int setIndex = context.TargetApi == TargetApi.Vulkan ? image.Set : 0; var dim = GetDim(image.Type); @@ -314,16 +313,29 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv private static void DeclareInputsAndOutputs(CodeGenContext context, StructuredProgramInfo info) { + int firstLocation = int.MaxValue; + + if (context.Definitions.Stage == ShaderStage.Fragment && context.Definitions.DualSourceBlend) + { + foreach (var ioDefinition in info.IoDefinitions) + { + if (ioDefinition.IoVariable == IoVariable.FragmentOutputColor && ioDefinition.Location < firstLocation) + { + firstLocation = ioDefinition.Location; + } + } + } + foreach (var ioDefinition in info.IoDefinitions) { PixelImap iq = PixelImap.Unused; - if (context.Config.Stage == ShaderStage.Fragment) + if (context.Definitions.Stage == ShaderStage.Fragment) { var ioVariable = ioDefinition.IoVariable; if (ioVariable == IoVariable.UserDefined) { - iq = context.Config.ImapTypes[ioDefinition.Location].GetFirstUsedType(); + iq = context.Definitions.ImapTypes[ioDefinition.Location].GetFirstUsedType(); } else { @@ -340,11 +352,17 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv bool isOutput = ioDefinition.StorageKind.IsOutput(); bool isPerPatch = ioDefinition.StorageKind.IsPerPatch(); - DeclareInputOrOutput(context, ioDefinition, isOutput, isPerPatch, iq); + DeclareInputOrOutput(context, ioDefinition, isOutput, isPerPatch, iq, firstLocation); } } - private static void DeclareInputOrOutput(CodeGenContext context, IoDefinition ioDefinition, bool isOutput, bool isPerPatch, PixelImap iq = PixelImap.Unused) + private static void DeclareInputOrOutput( + CodeGenContext context, + IoDefinition ioDefinition, + bool isOutput, + bool isPerPatch, + PixelImap iq = PixelImap.Unused, + int firstLocation = 0) { IoVariable ioVariable = ioDefinition.IoVariable; var storageClass = isOutput ? StorageClass.Output : StorageClass.Input; @@ -355,12 +373,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv if (ioVariable == IoVariable.UserDefined) { - varType = context.Config.GetUserDefinedType(ioDefinition.Location, isOutput); + varType = context.Definitions.GetUserDefinedType(ioDefinition.Location, isOutput); isBuiltIn = false; } else if (ioVariable == IoVariable.FragmentOutputColor) { - varType = context.Config.GetFragmentOutputColorType(ioDefinition.Location); + varType = context.Definitions.GetFragmentOutputColorType(ioDefinition.Location); isBuiltIn = false; } else @@ -374,16 +392,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv } } - bool hasComponent = context.Config.HasPerLocationInputOrOutputComponent(ioVariable, ioDefinition.Location, ioDefinition.Component, isOutput); + bool hasComponent = context.Definitions.HasPerLocationInputOrOutputComponent(ioVariable, ioDefinition.Location, ioDefinition.Component, isOutput); if (hasComponent) { varType &= AggregateType.ElementTypeMask; } - else if (ioVariable == IoVariable.UserDefined && context.Config.HasTransformFeedbackOutputs(isOutput)) + else if (ioVariable == IoVariable.UserDefined && context.Definitions.HasTransformFeedbackOutputs(isOutput)) { varType &= AggregateType.ElementTypeMask; - varType |= context.Config.GetTransformFeedbackOutputComponents(ioDefinition.Location, ioDefinition.Component) switch + varType |= context.Definitions.GetTransformFeedbackOutputComponents(ioDefinition.Location, ioDefinition.Component) switch { 2 => AggregateType.Vector2, 3 => AggregateType.Vector3, @@ -395,20 +413,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv var spvType = context.GetType(varType, IoMap.GetSpirvBuiltInArrayLength(ioVariable)); bool builtInPassthrough = false; - if (!isPerPatch && IoMap.IsPerVertex(ioVariable, context.Config.Stage, isOutput)) + if (!isPerPatch && IoMap.IsPerVertex(ioVariable, context.Definitions.Stage, isOutput)) { - int arraySize = context.Config.Stage == ShaderStage.Geometry ? context.InputVertices : 32; + int arraySize = context.Definitions.Stage == ShaderStage.Geometry ? context.InputVertices : 32; spvType = context.TypeArray(spvType, context.Constant(context.TypeU32(), arraySize)); - if (context.Config.GpPassthrough && context.Config.GpuAccessor.QueryHostSupportsGeometryShaderPassthrough()) + if (context.Definitions.GpPassthrough && context.HostCapabilities.SupportsGeometryShaderPassthrough) { builtInPassthrough = true; } } - if (context.Config.Stage == ShaderStage.TessellationControl && isOutput && !isPerPatch) + if (context.Definitions.Stage == ShaderStage.TessellationControl && isOutput && !isPerPatch) { - spvType = context.TypeArray(spvType, context.Constant(context.TypeU32(), context.Config.ThreadsPerInputPrimitive)); + spvType = context.TypeArray(spvType, context.Constant(context.TypeU32(), context.Definitions.ThreadsPerInputPrimitive)); } var spvPointerType = context.TypePointer(storageClass, spvType); @@ -426,7 +444,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv context.Decorate(spvVar, Decoration.Patch); } - if (context.Config.GpuAccessor.QueryHostReducedPrecision() && ioVariable == IoVariable.Position) + if (context.HostCapabilities.ReducedPrecision && ioVariable == IoVariable.Position) { context.Decorate(spvVar, Decoration.Invariant); } @@ -439,7 +457,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv if (ioVariable == IoVariable.UserDefined) { - int location = context.Config.GetPerPatchAttributeLocation(ioDefinition.Location); + int location = context.AttributeUsage.GetPerPatchAttributeLocation(ioDefinition.Location); context.Decorate(spvVar, Decoration.Location, (LiteralInteger)location); } @@ -455,8 +473,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv if (!isOutput && !isPerPatch && - (context.Config.PassthroughAttributes & (1 << ioDefinition.Location)) != 0 && - context.Config.GpuAccessor.QueryHostSupportsGeometryShaderPassthrough()) + (context.AttributeUsage.PassthroughAttributes & (1 << ioDefinition.Location)) != 0 && + context.HostCapabilities.SupportsGeometryShaderPassthrough) { context.Decorate(spvVar, Decoration.PassthroughNV); } @@ -465,13 +483,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv { int location = ioDefinition.Location; - if (context.Config.Stage == ShaderStage.Fragment && context.Config.GpuAccessor.QueryDualSourceBlendEnable()) + if (context.Definitions.Stage == ShaderStage.Fragment && context.Definitions.DualSourceBlend) { - int firstLocation = BitOperations.TrailingZeroCount(context.Config.UsedOutputAttributes); int index = location - firstLocation; - int mask = 3 << firstLocation; - if ((uint)index < 2 && (context.Config.UsedOutputAttributes & mask) == mask) + if ((uint)index < 2) { context.Decorate(spvVar, Decoration.Location, (LiteralInteger)firstLocation); context.Decorate(spvVar, Decoration.Index, (LiteralInteger)index); @@ -499,7 +515,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv break; } } - else if (context.Config.TryGetTransformFeedbackOutput( + else if (context.Definitions.TryGetTransformFeedbackOutput( ioVariable, ioDefinition.Location, ioDefinition.Component, |