diff --git a/src/Ryujinx.Graphics.GAL/Target.cs b/src/Ryujinx.Graphics.GAL/Target.cs index 1c184981d..531051d02 100644 --- a/src/Ryujinx.Graphics.GAL/Target.cs +++ b/src/Ryujinx.Graphics.GAL/Target.cs @@ -16,19 +16,18 @@ namespace Ryujinx.Graphics.GAL public static class TargetExtensions { - public static bool IsMultisample(this Target target) + extension(Target target) { - return target is Target.Texture2DMultisample or Target.Texture2DMultisampleArray; - } + public bool IsMultisample => target is Target.Texture2DMultisample or Target.Texture2DMultisampleArray; - public static bool HasDepthOrLayers(this Target target) - { - return target is Target.Texture3D or - Target.Texture1DArray or - Target.Texture2DArray or - Target.Texture2DMultisampleArray or - Target.Cubemap or - Target.CubemapArray; + public bool HasDepthOrLayers => + target is + Target.Texture3D or + Target.Texture1DArray or + Target.Texture2DArray or + Target.Texture2DMultisampleArray or + Target.Cubemap or + Target.CubemapArray; } } } diff --git a/src/Ryujinx.Graphics.Gpu/Image/Texture.cs b/src/Ryujinx.Graphics.Gpu/Image/Texture.cs index 9540df548..d7aedc7e4 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/Texture.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/Texture.cs @@ -1251,7 +1251,7 @@ namespace Ryujinx.Graphics.Gpu.Image { result = TextureCompatibility.PropagateViewCompatibility(result, TextureCompatibility.ViewTargetCompatible(Info, info, ref caps)); - bool bothMs = Info.Target.IsMultisample() && info.Target.IsMultisample(); + bool bothMs = Info.Target.IsMultisample && info.Target.IsMultisample; if (bothMs && (Info.SamplesInX != info.SamplesInX || Info.SamplesInY != info.SamplesInY)) { result = TextureViewCompatibility.Incompatible; diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs index f2cbca832..4e073e1da 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureCompatibility.cs @@ -388,7 +388,7 @@ namespace Ryujinx.Graphics.Gpu.Image return stride == rhs.Stride ? TextureViewCompatibility.CopyOnly : TextureViewCompatibility.LayoutIncompatible; } - else if (lhs.Target.IsMultisample() != rhs.Target.IsMultisample() && alignedWidthMatches && lhsAlignedSize.Height == rhsAlignedSize.Height) + else if (lhs.Target.IsMultisample != rhs.Target.IsMultisample && alignedWidthMatches && lhsAlignedSize.Height == rhsAlignedSize.Height) { // Copy between multisample and non-multisample textures with mismatching size is allowed, // as long aligned size matches. diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureGroup.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureGroup.cs index 7f38df129..f92ff327b 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureGroup.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureGroup.cs @@ -139,7 +139,7 @@ namespace Ryujinx.Graphics.Gpu.Image _allOffsets = size.AllOffsets; _sliceSizes = size.SliceSizes; - if (Storage.Target.HasDepthOrLayers() && Storage.Info.GetSlices() > GranularLayerThreshold) + if (Storage.Target.HasDepthOrLayers && Storage.Info.GetSlices() > GranularLayerThreshold) { _hasLayerViews = true; _hasMipViews = true; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index fcd004dd6..295258c74 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -116,13 +116,13 @@ namespace Ryujinx.Graphics.OpenGL.Image { TextureView destinationView = (TextureView)destination; - bool srcIsMultisample = Target.IsMultisample(); - bool dstIsMultisample = destinationView.Target.IsMultisample(); + bool srcIsMultisample = Target.IsMultisample; + bool dstIsMultisample = destinationView.Target.IsMultisample; if (dstIsMultisample != srcIsMultisample && Info.Format.IsDepthOrStencil()) { int layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); - CopyWithBlitForDepthMS(destinationView, 0, firstLayer, layers); + CopyWithBlitForDepthMultisample(destinationView, 0, firstLayer, layers); } else if (!dstIsMultisample && srcIsMultisample) { @@ -172,12 +172,12 @@ namespace Ryujinx.Graphics.OpenGL.Image { TextureView destinationView = (TextureView)destination; - bool srcIsMultisample = Target.IsMultisample(); - bool dstIsMultisample = destinationView.Target.IsMultisample(); + bool srcIsMultisample = Target.IsMultisample; + bool dstIsMultisample = destinationView.Target.IsMultisample; if (dstIsMultisample != srcIsMultisample && Info.Format.IsDepthOrStencil()) { - CopyWithBlitForDepthMS(destinationView, srcLayer, dstLayer, 1); + CopyWithBlitForDepthMultisample(destinationView, srcLayer, dstLayer, 1); } else if (!dstIsMultisample && srcIsMultisample) { @@ -204,7 +204,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } } - private void CopyWithBlitForDepthMS(TextureView destinationView, int srcLayer, int dstLayer, int layers) + private void CopyWithBlitForDepthMultisample(TextureView destinationView, int srcLayer, int dstLayer, int layers) { // This is currently used for multisample <-> non-multisample copies. // We can't do that with compute because it's not possible to write depth textures on compute. @@ -216,9 +216,9 @@ namespace Ryujinx.Graphics.OpenGL.Image Extents2D srcRegion = new(0, 0, Width, Height); Extents2D dstRegion = new(0, 0, destinationView.Width, destinationView.Height); - if (destinationView.Target.IsMultisample()) + if (destinationView.Target.IsMultisample) { - TextureView intermmediate = _renderer.TextureCopy.IntermediatePool.GetOrCreateWithAtLeast( + TextureView intermediate = _renderer.TextureCopy.IntermediatePool.GetOrCreateWithAtLeast( Info.Target, Info.BlockWidth, Info.BlockHeight, @@ -230,8 +230,8 @@ namespace Ryujinx.Graphics.OpenGL.Image 1, 1); - _renderer.TextureCopy.Copy(this, intermmediate, srcRegion, dstRegion, false); - _renderer.TextureCopy.Copy(intermmediate, destinationView, dstRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); + _renderer.TextureCopy.Copy(this, intermediate, srcRegion, dstRegion, false); + _renderer.TextureCopy.Copy(intermediate, destinationView, dstRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); } else { @@ -242,7 +242,7 @@ namespace Ryujinx.Graphics.OpenGL.Image _ => Target, }; - TextureView intermmediate = _renderer.TextureCopy.IntermediatePool.GetOrCreateWithAtLeast( + TextureView intermediate = _renderer.TextureCopy.IntermediatePool.GetOrCreateWithAtLeast( target, Info.BlockWidth, Info.BlockHeight, @@ -254,8 +254,8 @@ namespace Ryujinx.Graphics.OpenGL.Image 1, 1); - _renderer.TextureCopy.Copy(this, intermmediate, srcRegion, srcRegion, false); - _renderer.TextureCopy.Copy(intermmediate, destinationView, srcRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); + _renderer.TextureCopy.Copy(this, intermediate, srcRegion, srcRegion, false); + _renderer.TextureCopy.Copy(intermediate, destinationView, srcRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); } } @@ -305,14 +305,12 @@ namespace Ryujinx.Graphics.OpenGL.Image { return PinnedSpan.UnsafeFromSpan(_renderer.PersistentBuffers.Default.GetTextureData(this, size, layer, level)); } - else - { - nint target = _renderer.PersistentBuffers.Default.GetHostArray(size); - int offset = WriteTo2D(target, layer, level); + nint target = _renderer.PersistentBuffers.Default.GetHostArray(size); - return new PinnedSpan((byte*)target.ToPointer() + offset, size); - } + int offset = WriteTo2D(target, layer, level); + + return new PinnedSpan((byte*)target.ToPointer() + offset, size); } public void CopyTo(BufferRange range, int layer, int level, int stride) diff --git a/src/Ryujinx.Graphics.Shader/AttributeType.cs b/src/Ryujinx.Graphics.Shader/AttributeType.cs index d2d146ecb..4edd03c63 100644 --- a/src/Ryujinx.Graphics.Shader/AttributeType.cs +++ b/src/Ryujinx.Graphics.Shader/AttributeType.cs @@ -19,20 +19,18 @@ namespace Ryujinx.Graphics.Shader static class AttributeTypeExtensions { - public static AggregateType ToAggregateType(this AttributeType type) + extension(AttributeType type) { - return (type & ~AttributeType.AnyPacked) switch + public AggregateType Aggregate => + (type & ~AttributeType.AnyPacked) switch { AttributeType.Float => AggregateType.FP32, AttributeType.Sint => AggregateType.S32, AttributeType.Uint => AggregateType.U32, _ => throw new ArgumentException($"Invalid attribute type \"{type}\"."), }; - } - - public static AggregateType ToAggregateType(this AttributeType type, bool supportsScaledFormats) - { - return (type & ~AttributeType.AnyPacked) switch + + public AggregateType AsAggregate(bool supportsScaledFormats) => (type & ~AttributeType.AnyPacked) switch { AttributeType.Float => AggregateType.FP32, AttributeType.Sint => AggregateType.S32, diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs index e0d7cdc4b..6e30fb03d 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs @@ -123,8 +123,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl tessCw = !tessCw; } - string patchType = context.Definitions.TessPatchType.ToGlsl(); - string spacing = context.Definitions.TessSpacing.ToGlsl(); + string patchType = context.Definitions.TessPatchType.Glsl; + string spacing = context.Definitions.TessSpacing.Glsl; string windingOrder = tessCw ? "cw" : "ccw"; context.AppendLine($"layout ({patchType}, {spacing}, {windingOrder}) in;"); @@ -351,7 +351,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl arrayDecl = "[]"; } - string samplerTypeName = definition.Separate ? definition.Type.ToGlslTextureType() : definition.Type.ToGlslSamplerType(); + string samplerTypeName = definition.Separate ? definition.Type.GlslTextureTypeName : definition.Type.GlslSamplerTypeName; string layout = string.Empty; @@ -379,7 +379,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl arrayDecl = "[]"; } - string imageTypeName = definition.Type.ToGlslImageType(definition.Format.GetComponentType()); + string imageTypeName = definition.Type.GetGlslImageTypeName(definition.Format.GetComponentType()); if (definition.Flags.HasFlag(TextureUsageFlags.ImageCoherent)) { diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs index 32c930557..881ca0d47 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs @@ -54,7 +54,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions texCallBuilder.Append('('); texCallBuilder.Append(imageName); - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int pCount = coordsCount + (isArray ? 1 : 0); @@ -162,7 +162,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions { AstTextureOperation texOp = (AstTextureOperation)operation; - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int coordsIndex = 0; string samplerName = GetSamplerName(context, texOp, ref coordsIndex); @@ -264,7 +264,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions texCall += "(" + samplerName; - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int pCount = coordsCount; @@ -658,7 +658,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions samplerName = $"{samplerName}[{GetSourceExpr(context, texOp.GetSource(srcIndex++), AggregateType.S32)}]"; } - name = $"{texOp.Type.ToGlslSamplerType()}({name}, {samplerName})"; + name = $"{texOp.Type.GlslSamplerTypeName}({name}, {samplerName})"; } return name; diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs index c0a597a10..71860adb2 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs @@ -385,7 +385,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv private static void DeclarePerVertexBlock(CodeGenContext context) { - if (context.Definitions.Stage.IsVtg()) + if (context.Definitions.Stage.IsVtg) { if (context.Definitions.Stage != ShaderStage.Vertex) { diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs index 27b5c21c0..83b037c1c 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs @@ -615,7 +615,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv image = context.AccessChain(imagePointerType, image, textureIndex); } - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int pCount = coordsCount + (isArray ? 1 : 0); @@ -693,7 +693,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv image = context.Load(declaration.ImageType, image); - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int pCount = coordsCount + (isArray ? 1 : 0); @@ -750,7 +750,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv image = context.Load(declaration.ImageType, image); - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int pCount = coordsCount + (isArray ? 1 : 0); @@ -840,7 +840,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv SamplerDeclaration declaration = context.Samplers[texOp.GetTextureSetAndBinding()]; SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex); - int pCount = texOp.Type.GetDimensions(); + int pCount = texOp.Type.Dimensions; SpvInstruction pCoords; @@ -1164,7 +1164,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv SamplerDeclaration declaration = context.Samplers[texOp.GetTextureSetAndBinding()]; SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex); - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int pCount = coordsCount; @@ -1463,7 +1463,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv SamplerType type = context.SamplersTypes[texOp.GetTextureSetAndBinding()]; bool hasLod = !type.HasFlag(SamplerType.Multisample) && type != SamplerType.TextureBuffer; - int dimensions = (type & SamplerType.Mask) == SamplerType.TextureCube ? 2 : type.GetDimensions(); + int dimensions = (type & SamplerType.Mask) == SamplerType.TextureCube ? 2 : type.Dimensions; if (type.HasFlag(SamplerType.Array)) { @@ -1486,7 +1486,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv if (dimensions != 1) { - result = context.CompositeExtract(context.TypeS32(), result, (SpvLiteralInteger)texOp.Index); + result = context.CompositeExtract(context.TypeS32(), result, texOp.Index); } return new OperationResult(AggregateType.S32, result); diff --git a/src/Ryujinx.Graphics.Shader/Decoders/Decoder.cs b/src/Ryujinx.Graphics.Shader/Decoders/Decoder.cs index ac1f24218..45250a463 100644 --- a/src/Ryujinx.Graphics.Shader/Decoders/Decoder.cs +++ b/src/Ryujinx.Graphics.Shader/Decoders/Decoder.cs @@ -457,7 +457,7 @@ namespace Ryujinx.Graphics.Shader.Decoders case AttributeConsts.ClipDistance5: case AttributeConsts.ClipDistance6: case AttributeConsts.ClipDistance7: - if (definitions.Stage.IsVtg()) + if (definitions.Stage.IsVtg) { context.SetClipDistanceWritten((attr - AttributeConsts.ClipDistance0) / 4); } diff --git a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs index e9f930179..2f86f044d 100644 --- a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs +++ b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs @@ -228,7 +228,7 @@ namespace Ryujinx.Graphics.Shader.Instructions sourcesList.Add(context.Copy(GetSrcReg(context, srcC))); } - int coordsCount = type.GetDimensions(); + int coordsCount = type.Dimensions; for (int index = 0; index < coordsCount; index++) { @@ -335,7 +335,7 @@ namespace Ryujinx.Graphics.Shader.Instructions sourcesList.Add(context.Copy(Register(srcC, RegisterType.Gpr))); } - int coordsCount = type.GetDimensions(); + int coordsCount = type.Dimensions; for (int index = 0; index < coordsCount; index++) { @@ -507,7 +507,7 @@ namespace Ryujinx.Graphics.Shader.Instructions sourcesList.Add(context.Copy(GetSrcReg(context, srcC))); } - int coordsCount = type.GetDimensions(); + int coordsCount = type.Dimensions; for (int index = 0; index < coordsCount; index++) { @@ -612,7 +612,7 @@ namespace Ryujinx.Graphics.Shader.Instructions sourcesList.Add(context.Copy(Register(srcC, RegisterType.Gpr))); } - int coordsCount = type.GetDimensions(); + int coordsCount = type.Dimensions; for (int index = 0; index < coordsCount; index++) { diff --git a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs index 19b22e03b..fa0b87317 100644 --- a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs +++ b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs @@ -227,7 +227,7 @@ namespace Ryujinx.Graphics.Shader.Instructions } } - int coordsCount = type.GetDimensions(); + int coordsCount = type.Dimensions; for (int index = 0; index < coordsCount; index++) { @@ -558,7 +558,7 @@ namespace Ryujinx.Graphics.Shader.Instructions if ((flags & TextureFlags.Offset) != 0) { - AddTextureOffset(type.GetDimensions(), 4, 4); + AddTextureOffset(type.Dimensions, 4, 4); } } else if (texsType == TexsType.Tld4s) @@ -583,7 +583,7 @@ namespace Ryujinx.Graphics.Shader.Instructions if (tld4sOp.Aoffi) { - AddTextureOffset(type.GetDimensions(), 8, 6); + AddTextureOffset(type.Dimensions, 8, 6); flags |= TextureFlags.Offset; } @@ -714,7 +714,7 @@ namespace Ryujinx.Graphics.Shader.Instructions flags |= TextureFlags.Bindless; } - int coordsCount = type.GetDimensions(); + int coordsCount = type.Dimensions; for (int index = 0; index < coordsCount; index++) { @@ -847,7 +847,7 @@ namespace Ryujinx.Graphics.Shader.Instructions SamplerType type = ConvertSamplerType(dimensions); - int coordsCount = type.GetDimensions(); + int coordsCount = type.Dimensions; bool isArray = dimensions is TexDim.Array1d or @@ -942,26 +942,6 @@ namespace Ryujinx.Graphics.Shader.Instructions return; } - Operand Ra() - { - if (srcA > RegisterConsts.RegisterZeroIndex) - { - return Const(0); - } - - return context.Copy(Register(srcA++, RegisterType.Gpr)); - } - - Operand Rb() - { - if (srcB > RegisterConsts.RegisterZeroIndex) - { - return Const(0); - } - - return context.Copy(Register(srcB++, RegisterType.Gpr)); - } - TextureFlags flags = TextureFlags.Derivatives; List sourcesList = []; @@ -975,7 +955,7 @@ namespace Ryujinx.Graphics.Shader.Instructions SamplerType type = ConvertSamplerType(dimensions); - int coordsCount = type.GetDimensions(); + int coordsCount = type.Dimensions; for (int index = 0; index < coordsCount; index++) { @@ -1051,6 +1031,28 @@ namespace Ryujinx.Graphics.Shader.Instructions } EmitTextureSample(context, type, flags, imm, componentMask, dests, sources); + + return; + + Operand Ra() + { + if (srcA > RegisterConsts.RegisterZeroIndex) + { + return Const(0); + } + + return context.Copy(Register(srcA++, RegisterType.Gpr)); + } + + Operand Rb() + { + if (srcB > RegisterConsts.RegisterZeroIndex) + { + return Const(0); + } + + return context.Copy(Register(srcB++, RegisterType.Gpr)); + } } private static void EmitTxq( diff --git a/src/Ryujinx.Graphics.Shader/SamplerType.cs b/src/Ryujinx.Graphics.Shader/SamplerType.cs index a693495fa..88449ef66 100644 --- a/src/Ryujinx.Graphics.Shader/SamplerType.cs +++ b/src/Ryujinx.Graphics.Shader/SamplerType.cs @@ -22,9 +22,9 @@ namespace Ryujinx.Graphics.Shader static class SamplerTypeExtensions { - public static int GetDimensions(this SamplerType type) + extension(SamplerType type) { - return (type & SamplerType.Mask) switch + public int Dimensions => (type & SamplerType.Mask) switch { SamplerType.Texture1D => 1, SamplerType.TextureBuffer => 1, @@ -33,127 +33,136 @@ namespace Ryujinx.Graphics.Shader SamplerType.TextureCube => 3, _ => throw new ArgumentException($"Invalid sampler type \"{type}\"."), }; - } - public static string ToShortSamplerType(this SamplerType type) - { - string typeName = (type & SamplerType.Mask) switch + public string ShortTypeName { - SamplerType.Texture1D => "1d", - SamplerType.TextureBuffer => "b", - SamplerType.Texture2D => "2d", - SamplerType.Texture3D => "3d", - SamplerType.TextureCube => "cube", - _ => throw new ArgumentException($"Invalid sampler type \"{type}\"."), - }; + get + { + string typeName = (type & SamplerType.Mask) switch + { + SamplerType.Texture1D => "1d", + SamplerType.TextureBuffer => "b", + SamplerType.Texture2D => "2d", + SamplerType.Texture3D => "3d", + SamplerType.TextureCube => "cube", + _ => throw new ArgumentException($"Invalid sampler type \"{type}\"."), + }; - if ((type & SamplerType.Multisample) != 0) - { - typeName += "ms"; + if ((type & SamplerType.Multisample) != 0) + { + typeName += "ms"; + } + + if ((type & SamplerType.Array) != 0) + { + typeName += "a"; + } + + if ((type & SamplerType.Shadow) != 0) + { + typeName += "s"; + } + + return typeName; + } } - if ((type & SamplerType.Array) != 0) + public string GlslSamplerTypeName { - typeName += "a"; + get + { + string typeName = (type & SamplerType.Mask) switch + { + SamplerType.None => "sampler", + SamplerType.Texture1D => "sampler1D", + SamplerType.TextureBuffer => "samplerBuffer", + SamplerType.Texture2D => "sampler2D", + SamplerType.Texture3D => "sampler3D", + SamplerType.TextureCube => "samplerCube", + _ => throw new ArgumentException($"Invalid sampler type \"{type}\"."), + }; + + if ((type & SamplerType.Multisample) != 0) + { + typeName += "MS"; + } + + if ((type & SamplerType.Array) != 0) + { + typeName += "Array"; + } + + if ((type & SamplerType.Shadow) != 0) + { + typeName += "Shadow"; + } + + return typeName; + } } - if ((type & SamplerType.Shadow) != 0) + public string GlslTextureTypeName { - typeName += "s"; + get + { + string typeName = (type & SamplerType.Mask) switch + { + SamplerType.Texture1D => "texture1D", + SamplerType.TextureBuffer => "textureBuffer", + SamplerType.Texture2D => "texture2D", + SamplerType.Texture3D => "texture3D", + SamplerType.TextureCube => "textureCube", + _ => throw new ArgumentException($"Invalid texture type \"{type}\"."), + }; + + if ((type & SamplerType.Multisample) != 0) + { + typeName += "MS"; + } + + if ((type & SamplerType.Array) != 0) + { + typeName += "Array"; + } + + return typeName; + } } - return typeName; - } - - public static string ToGlslSamplerType(this SamplerType type) - { - string typeName = (type & SamplerType.Mask) switch + public string GetGlslImageTypeName(AggregateType componentType) { - SamplerType.None => "sampler", - SamplerType.Texture1D => "sampler1D", - SamplerType.TextureBuffer => "samplerBuffer", - SamplerType.Texture2D => "sampler2D", - SamplerType.Texture3D => "sampler3D", - SamplerType.TextureCube => "samplerCube", - _ => throw new ArgumentException($"Invalid sampler type \"{type}\"."), - }; + string typeName = (type & SamplerType.Mask) switch + { + SamplerType.Texture1D => "image1D", + SamplerType.TextureBuffer => "imageBuffer", + SamplerType.Texture2D => "image2D", + SamplerType.Texture3D => "image3D", + SamplerType.TextureCube => "imageCube", + _ => throw new ArgumentException($"Invalid sampler type \"{type}\"."), + }; - if ((type & SamplerType.Multisample) != 0) - { - typeName += "MS"; + if ((type & SamplerType.Multisample) != 0) + { + typeName += "MS"; + } + + if ((type & SamplerType.Array) != 0) + { + typeName += "Array"; + } + + switch (componentType) + { + case AggregateType.U32: + typeName = 'u' + typeName; + break; + case AggregateType.S32: + typeName = 'i' + typeName; + break; + } + + return typeName; } - - if ((type & SamplerType.Array) != 0) - { - typeName += "Array"; - } - - if ((type & SamplerType.Shadow) != 0) - { - typeName += "Shadow"; - } - - return typeName; - } - - public static string ToGlslTextureType(this SamplerType type) - { - string typeName = (type & SamplerType.Mask) switch - { - SamplerType.Texture1D => "texture1D", - SamplerType.TextureBuffer => "textureBuffer", - SamplerType.Texture2D => "texture2D", - SamplerType.Texture3D => "texture3D", - SamplerType.TextureCube => "textureCube", - _ => throw new ArgumentException($"Invalid texture type \"{type}\"."), - }; - - if ((type & SamplerType.Multisample) != 0) - { - typeName += "MS"; - } - - if ((type & SamplerType.Array) != 0) - { - typeName += "Array"; - } - - return typeName; - } - - public static string ToGlslImageType(this SamplerType type, AggregateType componentType) - { - string typeName = (type & SamplerType.Mask) switch - { - SamplerType.Texture1D => "image1D", - SamplerType.TextureBuffer => "imageBuffer", - SamplerType.Texture2D => "image2D", - SamplerType.Texture3D => "image3D", - SamplerType.TextureCube => "imageCube", - _ => throw new ArgumentException($"Invalid sampler type \"{type}\"."), - }; - - if ((type & SamplerType.Multisample) != 0) - { - typeName += "MS"; - } - - if ((type & SamplerType.Array) != 0) - { - typeName += "Array"; - } - - switch (componentType) - { - case AggregateType.U32: - typeName = 'u' + typeName; - break; - case AggregateType.S32: - typeName = 'i' + typeName; - break; - } - - return typeName; } } } diff --git a/src/Ryujinx.Graphics.Shader/ShaderStage.cs b/src/Ryujinx.Graphics.Shader/ShaderStage.cs index faea5c357..cbfd1aa0c 100644 --- a/src/Ryujinx.Graphics.Shader/ShaderStage.cs +++ b/src/Ryujinx.Graphics.Shader/ShaderStage.cs @@ -14,27 +14,23 @@ namespace Ryujinx.Graphics.Shader public static class ShaderStageExtensions { - /// - /// Checks if the shader stage supports render scale. - /// - /// Shader stage - /// True if the shader stage supports render scale, false otherwise - public static bool SupportsRenderScale(this ShaderStage stage) + extension(ShaderStage shaderStage) { - return stage is ShaderStage.Vertex or ShaderStage.Fragment or ShaderStage.Compute; - } - - /// - /// Checks if the shader stage is vertex, tessellation or geometry. - /// - /// Shader stage - /// True if the shader stage is vertex, tessellation or geometry, false otherwise - public static bool IsVtg(this ShaderStage stage) - { - return stage is ShaderStage.Vertex or - ShaderStage.TessellationControl or - ShaderStage.TessellationEvaluation or - ShaderStage.Geometry; + /// + /// Checks if the shader stage supports render scale. + /// + public bool SupportsRenderScale => + shaderStage is ShaderStage.Vertex or ShaderStage.Fragment or ShaderStage.Compute; + + /// + /// Checks if the shader stage is vertex, tessellation or geometry. + /// + public bool IsVtg => + shaderStage is ShaderStage.Vertex or + ShaderStage.TessellationControl or + ShaderStage.TessellationEvaluation or + ShaderStage.Geometry; } + } } diff --git a/src/Ryujinx.Graphics.Shader/TessPatchType.cs b/src/Ryujinx.Graphics.Shader/TessPatchType.cs index 76be22fd4..6c4fc1a30 100644 --- a/src/Ryujinx.Graphics.Shader/TessPatchType.cs +++ b/src/Ryujinx.Graphics.Shader/TessPatchType.cs @@ -9,9 +9,9 @@ namespace Ryujinx.Graphics.Shader static class TessPatchTypeExtensions { - public static string ToGlsl(this TessPatchType type) + extension(TessPatchType patchType) { - return type switch + public string Glsl => patchType switch { TessPatchType.Isolines => "isolines", TessPatchType.Quads => "quads", diff --git a/src/Ryujinx.Graphics.Shader/TessSpacing.cs b/src/Ryujinx.Graphics.Shader/TessSpacing.cs index 6035366c1..8d42ccbf1 100644 --- a/src/Ryujinx.Graphics.Shader/TessSpacing.cs +++ b/src/Ryujinx.Graphics.Shader/TessSpacing.cs @@ -9,9 +9,9 @@ namespace Ryujinx.Graphics.Shader static class TessSpacingExtensions { - public static string ToGlsl(this TessSpacing spacing) + extension(TessSpacing spacing) { - return spacing switch + public string Glsl => spacing switch { TessSpacing.FractionalEventSpacing => "fractional_even_spacing", TessSpacing.FractionalOddSpacing => "fractional_odd_spacing", diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs index 1f2f79a2d..c40568a61 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs @@ -39,8 +39,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations // Set any destination variables to zero. string typeName = texOp.Inst.IsImage() - ? texOp.Type.ToGlslImageType(texOp.Format.GetComponentType()) - : texOp.Type.ToGlslTextureType(); + ? texOp.Type.GetGlslImageTypeName(texOp.Format.GetComponentType()) + : texOp.Type.GlslTextureTypeName; gpuAccessor.Log($"Failed to find handle source for bindless access of type \"{typeName}\"."); diff --git a/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs b/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs index 94691a5b4..537059e41 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs @@ -273,7 +273,7 @@ namespace Ryujinx.Graphics.Shader.Translation bool coherent, bool separate) { - var dimensions = type == SamplerType.None ? 0 : type.GetDimensions(); + var dimensions = type == SamplerType.None ? 0 : type.Dimensions; var dict = isImage ? _usedImages : _usedTextures; var usageFlags = TextureUsageFlags.None; @@ -282,7 +282,7 @@ namespace Ryujinx.Graphics.Shader.Translation { usageFlags |= TextureUsageFlags.NeedsScaleValue; - var canScale = _stage.SupportsRenderScale() && arrayLength == 1 && !write && dimensions == 2; + var canScale = _stage.SupportsRenderScale && arrayLength == 1 && !write && dimensions == 2; if (!canScale) { @@ -355,7 +355,7 @@ namespace Ryujinx.Graphics.Shader.Translation if (arrayLength != 1 && type != SamplerType.None) { - prefix += type.ToShortSamplerType(); + prefix += type.ShortTypeName; } if (isImage) @@ -433,8 +433,8 @@ namespace Ryujinx.Graphics.Shader.Translation { selectedMeta.UsageFlags |= TextureUsageFlags.NeedsScaleValue; - var dimensions = type.GetDimensions(); - var canScale = _stage.SupportsRenderScale() && selectedInfo.ArrayLength == 1 && dimensions == 2; + var dimensions = type.Dimensions; + var canScale = _stage.SupportsRenderScale && selectedInfo.ArrayLength == 1 && dimensions == 2; if (!canScale) { diff --git a/src/Ryujinx.Graphics.Shader/Translation/ShaderDefinitions.cs b/src/Ryujinx.Graphics.Shader/Translation/ShaderDefinitions.cs index 656ad6c5e..fbdccd804 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/ShaderDefinitions.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/ShaderDefinitions.cs @@ -293,7 +293,7 @@ namespace Ryujinx.Graphics.Shader.Translation public AggregateType GetFragmentOutputColorType(int location) { - return AggregateType.Vector4 | _graphicsState.FragmentOutputTypes[location].ToAggregateType(); + return AggregateType.Vector4 | _graphicsState.FragmentOutputTypes[location].Aggregate; } public AggregateType GetUserDefinedType(int location, bool isOutput) @@ -307,7 +307,7 @@ namespace Ryujinx.Graphics.Shader.Translation if (Stage == ShaderStage.Vertex && !isOutput) { - type |= _graphicsState.AttributeTypes[location].ToAggregateType(SupportsScaledVertexFormats); + type |= _graphicsState.AttributeTypes[location].AsAggregate(SupportsScaledVertexFormats); } else { diff --git a/src/Ryujinx.Graphics.Shader/Translation/Transforms/TexturePass.cs b/src/Ryujinx.Graphics.Shader/Translation/Transforms/TexturePass.cs index 808692559..2ec00ce2d 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Transforms/TexturePass.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Transforms/TexturePass.cs @@ -53,7 +53,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms (intCoords || isImage) && !isBindless && !isIndexed && - stage.SupportsRenderScale() && + stage.SupportsRenderScale && TypeSupportsScale(texOp.Type)) { int functionId = hfm.GetOrCreateFunctionId(HelperFunctionName.TexelFetchScale); @@ -61,7 +61,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms ? resourceManager.GetTextureDescriptors(includeArrays: false).Length + resourceManager.FindImageDescriptorIndex(texOp.Binding) : resourceManager.FindTextureDescriptorIndex(texOp.Binding); - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int coordsIndex = isBindless ? 1 : 0; for (int index = 0; index < coordsCount; index++) @@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms texOp.Index < 2 && !isBindless && !isIndexed && - stage.SupportsRenderScale() && + stage.SupportsRenderScale && TypeSupportsScale(texOp.Type)) { int functionId = hfm.GetOrCreateFunctionId(HelperFunctionName.TextureSizeUnscale); @@ -168,7 +168,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms return node; } - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int normCoordsCount = (texOp.Type & SamplerType.Mask) == SamplerType.TextureCube ? 2 : coordsCount; @@ -226,7 +226,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms bool isIndexed = resourceManager.IsArrayOfTexturesOrImages(texOp.Binding, isImage: false); - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int coordsIndex = isBindless || isIndexed ? 1 : 0; int normCoordsCount = (texOp.Type & SamplerType.Mask) == SamplerType.TextureCube ? 2 : coordsCount; @@ -315,7 +315,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms bool isMultisample = (texOp.Type & SamplerType.Multisample) != 0; bool isShadow = (texOp.Type & SamplerType.Shadow) != 0; - int coordsCount = texOp.Type.GetDimensions(); + int coordsCount = texOp.Type.Dimensions; int offsetsCount; diff --git a/src/Ryujinx.Graphics.Vulkan/HelperShader.cs b/src/Ryujinx.Graphics.Vulkan/HelperShader.cs index 695046198..36715cab1 100644 --- a/src/Ryujinx.Graphics.Vulkan/HelperShader.cs +++ b/src/Ryujinx.Graphics.Vulkan/HelperShader.cs @@ -407,10 +407,10 @@ namespace Ryujinx.Graphics.Vulkan if (dstIsDepthOrStencil) { - _pipeline.SetProgram(src.Info.Target.IsMultisample() ? _programDepthBlitMs : _programDepthBlit); + _pipeline.SetProgram(src.Info.Target.IsMultisample ? _programDepthBlitMs : _programDepthBlit); _pipeline.SetDepthTest(new DepthTestDescriptor(true, true, CompareOp.Always)); } - else if (src.Info.Target.IsMultisample()) + else if (src.Info.Target.IsMultisample) { _pipeline.SetProgram(_programColorBlitMs); } @@ -567,12 +567,12 @@ namespace Ryujinx.Graphics.Vulkan if (isDepth) { - _pipeline.SetProgram(src.Info.Target.IsMultisample() ? _programDepthBlitMs : _programDepthBlit); + _pipeline.SetProgram(src.Info.Target.IsMultisample ? _programDepthBlitMs : _programDepthBlit); _pipeline.SetDepthTest(new DepthTestDescriptor(true, true, CompareOp.Always)); } else { - _pipeline.SetProgram(src.Info.Target.IsMultisample() ? _programStencilBlitMs : _programStencilBlit); + _pipeline.SetProgram(src.Info.Target.IsMultisample ? _programStencilBlitMs : _programStencilBlit); _pipeline.SetStencilTest(CreateStencilTestDescriptor(true)); } diff --git a/src/Ryujinx.Graphics.Vulkan/TextureStorage.cs b/src/Ryujinx.Graphics.Vulkan/TextureStorage.cs index 3dc605891..e1508aca4 100644 --- a/src/Ryujinx.Graphics.Vulkan/TextureStorage.cs +++ b/src/Ryujinx.Graphics.Vulkan/TextureStorage.cs @@ -77,7 +77,7 @@ namespace Ryujinx.Graphics.Vulkan _device = device; _info = info; - bool isMsImageStorageSupported = gd.Capabilities.SupportsShaderStorageImageMultisample || !info.Target.IsMultisample(); + bool isMsImageStorageSupported = gd.Capabilities.SupportsShaderStorageImageMultisample || !info.Target.IsMultisample; VkFormat format = _gd.FormatCapabilities.ConvertToVkFormat(info.Format, isMsImageStorageSupported); uint levels = (uint)info.Levels; diff --git a/src/Ryujinx.Graphics.Vulkan/TextureView.cs b/src/Ryujinx.Graphics.Vulkan/TextureView.cs index 1cbb7c6e1..2402a0b12 100644 --- a/src/Ryujinx.Graphics.Vulkan/TextureView.cs +++ b/src/Ryujinx.Graphics.Vulkan/TextureView.cs @@ -61,7 +61,7 @@ namespace Ryujinx.Graphics.Vulkan gd.Textures.Add(this); - bool isMsImageStorageSupported = gd.Capabilities.SupportsShaderStorageImageMultisample || !info.Target.IsMultisample(); + bool isMsImageStorageSupported = gd.Capabilities.SupportsShaderStorageImageMultisample || !info.Target.IsMultisample; VkFormat format = _gd.FormatCapabilities.ConvertToVkFormat(info.Format, isMsImageStorageSupported); ImageUsageFlags usage = TextureStorage.GetImageUsage(info.Format, gd.Capabilities, isMsImageStorageSupported, false); @@ -128,7 +128,7 @@ namespace Ryujinx.Graphics.Vulkan ImageUsageFlags shaderUsage = ImageUsageFlags.SampledBit; - if (info.Format.IsImageCompatible() && (_gd.Capabilities.SupportsShaderStorageImageMultisample || !info.Target.IsMultisample())) + if (info.Format.IsImageCompatible() && (_gd.Capabilities.SupportsShaderStorageImageMultisample || !info.Target.IsMultisample)) { shaderUsage |= ImageUsageFlags.StorageBit; } @@ -225,12 +225,12 @@ namespace Ryujinx.Graphics.Vulkan Image srcImage = src.GetImage().Get(cbs).Value; Image dstImage = dst.GetImage().Get(cbs).Value; - if (!dst.Info.Target.IsMultisample() && Info.Target.IsMultisample()) + if (!dst.Info.Target.IsMultisample && Info.Target.IsMultisample) { int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer); _gd.HelperShader.CopyMSToNonMS(_gd, cbs, src, dst, 0, firstLayer, layers); } - else if (dst.Info.Target.IsMultisample() && !Info.Target.IsMultisample()) + else if (dst.Info.Target.IsMultisample && !Info.Target.IsMultisample) { int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer); _gd.HelperShader.CopyNonMSToMS(_gd, cbs, src, dst, 0, firstLayer, layers); @@ -285,11 +285,11 @@ namespace Ryujinx.Graphics.Vulkan Image srcImage = src.GetImage().Get(cbs).Value; Image dstImage = dst.GetImage().Get(cbs).Value; - if (!dst.Info.Target.IsMultisample() && Info.Target.IsMultisample()) + if (!dst.Info.Target.IsMultisample && Info.Target.IsMultisample) { _gd.HelperShader.CopyMSToNonMS(_gd, cbs, src, dst, srcLayer, dstLayer, 1); } - else if (dst.Info.Target.IsMultisample() && !Info.Target.IsMultisample()) + else if (dst.Info.Target.IsMultisample && !Info.Target.IsMultisample) { _gd.HelperShader.CopyNonMSToMS(_gd, cbs, src, dst, srcLayer, dstLayer, 1); }