diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2023-05-21 14:04:21 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-21 14:04:21 -0300 |
| commit | 5626f2ca1c49342b20772224f956147df6957b5a (patch) | |
| tree | 9e60d080754e3686d75cc8606db5967126d2c1b9 /src/Ryujinx.Graphics.GAL | |
| parent | 402f05b8ef013807997589ecc0a8ff50267dcd23 (diff) | |
Replace ShaderBindings with new ResourceLayout structure for Vulkan (#5025)
* Introduce ResourceLayout
* Part 1: Use new ResourceSegments array on UpdateAndBind
* Part 2: Use ResourceLayout to build PipelineLayout
* Delete old code
* XML docs
* Fix shader cache load NRE
* Fix typo
Diffstat (limited to 'src/Ryujinx.Graphics.GAL')
| -rw-r--r-- | src/Ryujinx.Graphics.GAL/ResourceLayout.cs | 179 | ||||
| -rw-r--r-- | src/Ryujinx.Graphics.GAL/ShaderBindings.cs | 24 | ||||
| -rw-r--r-- | src/Ryujinx.Graphics.GAL/ShaderInfo.cs | 7 | ||||
| -rw-r--r-- | src/Ryujinx.Graphics.GAL/ShaderSource.cs | 8 |
4 files changed, 187 insertions, 31 deletions
diff --git a/src/Ryujinx.Graphics.GAL/ResourceLayout.cs b/src/Ryujinx.Graphics.GAL/ResourceLayout.cs new file mode 100644 index 00000000..3cde281f --- /dev/null +++ b/src/Ryujinx.Graphics.GAL/ResourceLayout.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.ObjectModel; + +namespace Ryujinx.Graphics.GAL +{ + public enum ResourceType : byte + { + UniformBuffer, + StorageBuffer, + Texture, + Sampler, + TextureAndSampler, + Image, + BufferTexture, + BufferImage + } + + public enum ResourceAccess : byte + { + None = 0, + Read = 1, + Write = 2, + ReadWrite = Read | Write + } + + [Flags] + public enum ResourceStages : byte + { + None = 0, + Compute = 1 << 0, + Vertex = 1 << 1, + TessellationControl = 1 << 2, + TessellationEvaluation = 1 << 3, + Geometry = 1 << 4, + Fragment = 1 << 5 + } + + public readonly struct ResourceDescriptor : IEquatable<ResourceDescriptor> + { + public int Binding { get; } + public int Count { get; } + public ResourceType Type { get; } + public ResourceStages Stages { get; } + + public ResourceDescriptor(int binding, int count, ResourceType type, ResourceStages stages) + { + Binding = binding; + Count = count; + Type = type; + Stages = stages; + } + + public override int GetHashCode() + { + return HashCode.Combine(Binding, Count, Type, Stages); + } + + public override bool Equals(object obj) + { + return obj is ResourceDescriptor other && Equals(other); + } + + public bool Equals(ResourceDescriptor other) + { + return Binding == other.Binding && Count == other.Count && Type == other.Type && Stages == other.Stages; + } + } + + public readonly struct ResourceUsage : IEquatable<ResourceUsage> + { + public int Binding { get; } + public ResourceType Type { get; } + public ResourceStages Stages { get; } + public ResourceAccess Access { get; } + + public ResourceUsage(int binding, ResourceType type, ResourceStages stages, ResourceAccess access) + { + Binding = binding; + Type = type; + Stages = stages; + Access = access; + } + + public override int GetHashCode() + { + return HashCode.Combine(Binding, Type, Stages, Access); + } + + public override bool Equals(object obj) + { + return obj is ResourceUsage other && Equals(other); + } + + public bool Equals(ResourceUsage other) + { + return Binding == other.Binding && Type == other.Type && Stages == other.Stages && Access == other.Access; + } + } + + public readonly struct ResourceDescriptorCollection + { + public ReadOnlyCollection<ResourceDescriptor> Descriptors { get; } + + public ResourceDescriptorCollection(ReadOnlyCollection<ResourceDescriptor> descriptors) + { + Descriptors = descriptors; + } + + public override int GetHashCode() + { + HashCode hasher = new HashCode(); + + if (Descriptors != null) + { + foreach (var descriptor in Descriptors) + { + hasher.Add(descriptor); + } + } + + return hasher.ToHashCode(); + } + + public override bool Equals(object obj) + { + return obj is ResourceDescriptorCollection other && Equals(other); + } + + public bool Equals(ResourceDescriptorCollection other) + { + if ((Descriptors == null) != (other.Descriptors == null)) + { + return false; + } + + if (Descriptors != null) + { + if (Descriptors.Count != other.Descriptors.Count) + { + return false; + } + + for (int index = 0; index < Descriptors.Count; index++) + { + if (!Descriptors[index].Equals(other.Descriptors[index])) + { + return false; + } + } + } + + return true; + } + } + + public readonly struct ResourceUsageCollection + { + public ReadOnlyCollection<ResourceUsage> Usages { get; } + + public ResourceUsageCollection(ReadOnlyCollection<ResourceUsage> usages) + { + Usages = usages; + } + } + + public readonly struct ResourceLayout + { + public ReadOnlyCollection<ResourceDescriptorCollection> Sets { get; } + public ReadOnlyCollection<ResourceUsageCollection> SetUsages { get; } + + public ResourceLayout( + ReadOnlyCollection<ResourceDescriptorCollection> sets, + ReadOnlyCollection<ResourceUsageCollection> setUsages) + { + Sets = sets; + SetUsages = setUsages; + } + } +} diff --git a/src/Ryujinx.Graphics.GAL/ShaderBindings.cs b/src/Ryujinx.Graphics.GAL/ShaderBindings.cs deleted file mode 100644 index 6ab29382..00000000 --- a/src/Ryujinx.Graphics.GAL/ShaderBindings.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; - -namespace Ryujinx.Graphics.GAL -{ - public readonly struct ShaderBindings - { - public IReadOnlyCollection<int> UniformBufferBindings { get; } - public IReadOnlyCollection<int> StorageBufferBindings { get; } - public IReadOnlyCollection<int> TextureBindings { get; } - public IReadOnlyCollection<int> ImageBindings { get; } - - public ShaderBindings( - IReadOnlyCollection<int> uniformBufferBindings, - IReadOnlyCollection<int> storageBufferBindings, - IReadOnlyCollection<int> textureBindings, - IReadOnlyCollection<int> imageBindings) - { - UniformBufferBindings = uniformBufferBindings; - StorageBufferBindings = storageBufferBindings; - TextureBindings = textureBindings; - ImageBindings = imageBindings; - } - } -} diff --git a/src/Ryujinx.Graphics.GAL/ShaderInfo.cs b/src/Ryujinx.Graphics.GAL/ShaderInfo.cs index b4c87117..643f1bc5 100644 --- a/src/Ryujinx.Graphics.GAL/ShaderInfo.cs +++ b/src/Ryujinx.Graphics.GAL/ShaderInfo.cs @@ -3,19 +3,22 @@ namespace Ryujinx.Graphics.GAL public struct ShaderInfo { public int FragmentOutputMap { get; } + public ResourceLayout ResourceLayout { get; } public ProgramPipelineState? State { get; } public bool FromCache { get; set; } - public ShaderInfo(int fragmentOutputMap, ProgramPipelineState state, bool fromCache = false) + public ShaderInfo(int fragmentOutputMap, ResourceLayout resourceLayout, ProgramPipelineState state, bool fromCache = false) { FragmentOutputMap = fragmentOutputMap; + ResourceLayout = resourceLayout; State = state; FromCache = fromCache; } - public ShaderInfo(int fragmentOutputMap, bool fromCache = false) + public ShaderInfo(int fragmentOutputMap, ResourceLayout resourceLayout, bool fromCache = false) { FragmentOutputMap = fragmentOutputMap; + ResourceLayout = resourceLayout; State = null; FromCache = fromCache; } diff --git a/src/Ryujinx.Graphics.GAL/ShaderSource.cs b/src/Ryujinx.Graphics.GAL/ShaderSource.cs index 91d3a632..773c0a8a 100644 --- a/src/Ryujinx.Graphics.GAL/ShaderSource.cs +++ b/src/Ryujinx.Graphics.GAL/ShaderSource.cs @@ -7,24 +7,22 @@ namespace Ryujinx.Graphics.GAL { public string Code { get; } public byte[] BinaryCode { get; } - public ShaderBindings Bindings { get; } public ShaderStage Stage { get; } public TargetLanguage Language { get; } - public ShaderSource(string code, byte[] binaryCode, ShaderBindings bindings, ShaderStage stage, TargetLanguage language) + public ShaderSource(string code, byte[] binaryCode, ShaderStage stage, TargetLanguage language) { Code = code; BinaryCode = binaryCode; - Bindings = bindings; Stage = stage; Language = language; } - public ShaderSource(string code, ShaderBindings bindings, ShaderStage stage, TargetLanguage language) : this(code, null, bindings, stage, language) + public ShaderSource(string code, ShaderStage stage, TargetLanguage language) : this(code, null, stage, language) { } - public ShaderSource(byte[] binaryCode, ShaderBindings bindings, ShaderStage stage, TargetLanguage language) : this(null, binaryCode, bindings, stage, language) + public ShaderSource(byte[] binaryCode, ShaderStage stage, TargetLanguage language) : this(null, binaryCode, stage, language) { } } |
