diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2023-07-03 14:29:27 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-03 14:29:27 -0300 |
| commit | 1c7a90ef359d9974e5bd257c4d8e9bf526a6966c (patch) | |
| tree | 3ab1644927819b90b0aef78ed6749c6434150490 /src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs | |
| parent | 3b46bb73f781a011705ecbc8a1d3207dfb145829 (diff) | |
Stop identifying shader textures with handle and cbuf, use binding instead (#5266)
* Stop identifying shader textures with handle and cbuf, use binding instead
* Remove now unused code
* Consider image operations as having accurate type information too
I don't know why that was not the case before
* Fix missing unscale on InsertCoordNormalization, stop calling SetUsageFlagsForTextureQuery when not needed
* Shader cache version bump
* Change get texture methods to return descriptors created from ResourceManager state
This is required to ensure that reserved textures and images will not be bound as a guest texture/image
* Fix BindlessElimination.SetHandle inserting coords at the wrong place
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs')
| -rw-r--r-- | src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs | 79 |
1 files changed, 28 insertions, 51 deletions
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs index 94b850e7..2370b49f 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs @@ -75,22 +75,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl 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); - - var textureDescriptors = context.Config.GetTextureDescriptors(); - if (textureDescriptors.Length != 0) - { - DeclareSamplers(context, textureDescriptors); - - context.AppendLine(); - } - - var imageDescriptors = context.Config.GetImageDescriptors(); - if (imageDescriptors.Length != 0) - { - DeclareImages(context, imageDescriptors); - - context.AppendLine(); - } + DeclareSamplers(context, context.Config.Properties.Textures.Values); + DeclareImages(context, context.Config.Properties.Images.Values); if (context.Config.Stage != ShaderStage.Compute) { @@ -369,80 +355,71 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl } } - private static void DeclareSamplers(CodeGenContext context, TextureDescriptor[] descriptors) + private static void DeclareSamplers(CodeGenContext context, IEnumerable<TextureDefinition> definitions) { int arraySize = 0; - foreach (var descriptor in descriptors) + + foreach (var definition in definitions) { - if (descriptor.Type.HasFlag(SamplerType.Indexed)) + string indexExpr = string.Empty; + + if (definition.Type.HasFlag(SamplerType.Indexed)) { if (arraySize == 0) { - arraySize = ShaderConfig.SamplerArraySize; + arraySize = ResourceManager.SamplerArraySize; } else if (--arraySize != 0) { continue; } - } - string indexExpr = NumberFormatter.FormatInt(arraySize); - - string samplerName = OperandManager.GetSamplerName( - context.Config.Stage, - descriptor.CbufSlot, - descriptor.HandleIndex, - descriptor.Type.HasFlag(SamplerType.Indexed), - indexExpr); + indexExpr = $"[{NumberFormatter.FormatInt(arraySize)}]"; + } - string samplerTypeName = descriptor.Type.ToGlslSamplerType(); + string samplerTypeName = definition.Type.ToGlslSamplerType(); string layout = string.Empty; if (context.Config.Options.TargetApi == TargetApi.Vulkan) { - layout = ", set = 2"; + layout = $", set = {definition.Set}"; } - context.AppendLine($"layout (binding = {descriptor.Binding}{layout}) uniform {samplerTypeName} {samplerName};"); + context.AppendLine($"layout (binding = {definition.Binding}{layout}) uniform {samplerTypeName} {definition.Name}{indexExpr};"); } } - private static void DeclareImages(CodeGenContext context, TextureDescriptor[] descriptors) + private static void DeclareImages(CodeGenContext context, IEnumerable<TextureDefinition> definitions) { int arraySize = 0; - foreach (var descriptor in descriptors) + + foreach (var definition in definitions) { - if (descriptor.Type.HasFlag(SamplerType.Indexed)) + string indexExpr = string.Empty; + + if (definition.Type.HasFlag(SamplerType.Indexed)) { if (arraySize == 0) { - arraySize = ShaderConfig.SamplerArraySize; + arraySize = ResourceManager.SamplerArraySize; } else if (--arraySize != 0) { continue; } - } - string indexExpr = NumberFormatter.FormatInt(arraySize); - - string imageName = OperandManager.GetImageName( - context.Config.Stage, - descriptor.CbufSlot, - descriptor.HandleIndex, - descriptor.Format, - descriptor.Type.HasFlag(SamplerType.Indexed), - indexExpr); + indexExpr = $"[{NumberFormatter.FormatInt(arraySize)}]"; + } - string imageTypeName = descriptor.Type.ToGlslImageType(descriptor.Format.GetComponentType()); + string imageTypeName = definition.Type.ToGlslImageType(definition.Format.GetComponentType()); - if (descriptor.Flags.HasFlag(TextureUsageFlags.ImageCoherent)) + if (definition.Flags.HasFlag(TextureUsageFlags.ImageCoherent)) { imageTypeName = "coherent " + imageTypeName; } - string layout = descriptor.Format.ToGlslFormat(); + string layout = definition.Format.ToGlslFormat(); if (!string.IsNullOrEmpty(layout)) { @@ -451,10 +428,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl if (context.Config.Options.TargetApi == TargetApi.Vulkan) { - layout = $", set = 3{layout}"; + layout = $", set = {definition.Set}{layout}"; } - context.AppendLine($"layout (binding = {descriptor.Binding}{layout}) uniform {imageTypeName} {imageName};"); + context.AppendLine($"layout (binding = {definition.Binding}{layout}) uniform {imageTypeName} {definition.Name}{indexExpr};"); } } |
